📄 device.c
字号:
} } if (!found) i2o_device_remove(dev); } /* add new devices, which are new in the LCT */ for (i = 0; i < max; i++) { int found = 0; list_for_each_entry_safe(dev, tmp, &c->devices, list) { if (lct->lct_entry[i].tid == dev->lct_data.tid) { found = 1; break; } } if (!found) i2o_device_add(c, &lct->lct_entry[i]); } up(&c->lct_lock); return 0;};/** * i2o_device_class_show_class_id - Displays class id of I2O device * @cd: class device of which the class id should be displayed * @buf: buffer into which the class id should be printed * * Returns the number of bytes which are printed into the buffer. */static ssize_t i2o_device_class_show_class_id(struct class_device *cd, char *buf){ struct i2o_device *dev = to_i2o_device(cd->dev); sprintf(buf, "%03x\n", dev->lct_data.class_id); return strlen(buf) + 1;};/** * i2o_device_class_show_tid - Displays TID of I2O device * @cd: class device of which the TID should be displayed * @buf: buffer into which the class id should be printed * * Returns the number of bytes which are printed into the buffer. */static ssize_t i2o_device_class_show_tid(struct class_device *cd, char *buf){ struct i2o_device *dev = to_i2o_device(cd->dev); sprintf(buf, "%03x\n", dev->lct_data.tid); return strlen(buf) + 1;};/* I2O device class attributes */static CLASS_DEVICE_ATTR(class_id, S_IRUGO, i2o_device_class_show_class_id, NULL);static CLASS_DEVICE_ATTR(tid, S_IRUGO, i2o_device_class_show_tid, NULL);/** * i2o_device_class_add - Adds attributes to the I2O device * @cd: I2O class device which is added to the I2O device class * * This function get called when a I2O device is added to the class. It * creates the attributes for each device and creates user/parent symlink * if necessary. * * Returns 0 on success or negative error code on failure. */static int i2o_device_class_add(struct class_device *cd){ struct i2o_device *i2o_dev, *tmp; struct i2o_controller *c; i2o_dev = to_i2o_device(cd->dev); c = i2o_dev->iop; class_device_create_file(cd, &class_device_attr_class_id); class_device_create_file(cd, &class_device_attr_tid); /* create user entries for this device */ tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid); if (tmp) sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj, "user"); /* create user entries refering to this device */ list_for_each_entry(tmp, &c->devices, list) if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid) sysfs_create_link(&tmp->device.kobj, &i2o_dev->device.kobj, "user"); /* create parent entries for this device */ tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid); if (tmp) sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj, "parent"); /* create parent entries refering to this device */ list_for_each_entry(tmp, &c->devices, list) if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) sysfs_create_link(&tmp->device.kobj, &i2o_dev->device.kobj, "parent"); return 0;};/* I2O device class interface */static struct class_interface i2o_device_class_interface = { .class = &i2o_device_class, .add = i2o_device_class_add};/* * Run time support routines *//* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET * * This function can be used for all UtilParamsGet/Set operations. * The OperationList is given in oplist-buffer, * and results are returned in reslist-buffer. * Note that the minimum sized reslist is 8 bytes and contains * ResultCount, ErrorInfoSize, BlockStatus and BlockSize. */int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist, int oplen, void *reslist, int reslen){ struct i2o_message __iomem *msg; u32 m; u32 *res32 = (u32 *) reslist; u32 *restmp = (u32 *) reslist; int len = 0; int i = 0; int rc; struct i2o_dma res; struct i2o_controller *c = i2o_dev->iop; struct device *dev = &c->pdev->dev; res.virt = NULL; if (i2o_dma_alloc(dev, &res, reslen, GFP_KERNEL)) return -ENOMEM; m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); if (m == I2O_QUEUE_EMPTY) { i2o_dma_free(dev, &res); return -ETIMEDOUT; } i = 0; writel(cmd << 24 | HOST_TID << 12 | i2o_dev->lct_data.tid, &msg->u.head[1]); writel(0, &msg->body[i++]); writel(0x4C000000 | oplen, &msg->body[i++]); /* OperationList */ memcpy_toio(&msg->body[i], oplist, oplen); i += (oplen / 4 + (oplen % 4 ? 1 : 0)); writel(0xD0000000 | res.len, &msg->body[i++]); /* ResultList */ writel(res.phys, &msg->body[i++]); writel(I2O_MESSAGE_SIZE(i + sizeof(struct i2o_message) / 4) | SGL_OFFSET_5, &msg->u.head[0]); rc = i2o_msg_post_wait_mem(c, m, 10, &res); /* This only looks like a memory leak - don't "fix" it. */ if (rc == -ETIMEDOUT) return rc; memcpy_fromio(reslist, res.virt, res.len); i2o_dma_free(dev, &res); /* Query failed */ if (rc) return rc; /* * Calculate number of bytes of Result LIST * We need to loop through each Result BLOCK and grab the length */ restmp = res32 + 1; len = 1; for (i = 0; i < (res32[0] & 0X0000FFFF); i++) { if (restmp[0] & 0x00FF0000) { /* BlockStatus != SUCCESS */ printk(KERN_WARNING "%s - Error:\n ErrorInfoSize = 0x%02x, " "BlockStatus = 0x%02x, BlockSize = 0x%04x\n", (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET" : "PARAMS_GET", res32[1] >> 24, (res32[1] >> 16) & 0xFF, res32[1] & 0xFFFF); /* * If this is the only request,than we return an error */ if ((res32[0] & 0x0000FFFF) == 1) { return -((res32[1] >> 16) & 0xFF); /* -BlockStatus */ } } len += restmp[0] & 0x0000FFFF; /* Length of res BLOCK */ restmp += restmp[0] & 0x0000FFFF; /* Skip to next BLOCK */ } return (len << 2); /* bytes used by result list */}/* * Query one field group value or a whole scalar group. */int i2o_parm_field_get(struct i2o_device *i2o_dev, int group, int field, void *buf, int buflen){ u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field }; u8 resblk[8 + buflen]; /* 8 bytes for header */ int size; if (field == -1) /* whole group */ opblk[4] = -1; size = i2o_parm_issue(i2o_dev, I2O_CMD_UTIL_PARAMS_GET, opblk, sizeof(opblk), resblk, sizeof(resblk)); memcpy(buf, resblk + 8, buflen); /* cut off header */ if (size > buflen) return buflen; return size;}/* * if oper == I2O_PARAMS_TABLE_GET, get from all rows * if fieldcount == -1 return all fields * ibuf and ibuflen are unused (use NULL, 0) * else return specific fields * ibuf contains fieldindexes * * if oper == I2O_PARAMS_LIST_GET, get from specific rows * if fieldcount == -1 return all fields * ibuf contains rowcount, keyvalues * else return specific fields * fieldcount is # of fieldindexes * ibuf contains fieldindexes, rowcount, keyvalues * * You could also use directly function i2o_issue_params(). */int i2o_parm_table_get(struct i2o_device *dev, int oper, int group, int fieldcount, void *ibuf, int ibuflen, void *resblk, int reslen){ u16 *opblk; int size; size = 10 + ibuflen; if (size % 4) size += 4 - size % 4; opblk = kmalloc(size, GFP_KERNEL); if (opblk == NULL) { printk(KERN_ERR "i2o: no memory for query buffer.\n"); return -ENOMEM; } opblk[0] = 1; /* operation count */ opblk[1] = 0; /* pad */ opblk[2] = oper; opblk[3] = group; opblk[4] = fieldcount; memcpy(opblk + 5, ibuf, ibuflen); /* other params */ size = i2o_parm_issue(dev, I2O_CMD_UTIL_PARAMS_GET, opblk, size, resblk, reslen); kfree(opblk); if (size > reslen) return reslen; return size;}/** * i2o_device_init - Initialize I2O devices * * Registers the I2O device class. * * Returns 0 on success or negative error code on failure. */int i2o_device_init(void){ int rc; rc = class_register(&i2o_device_class); if (rc) return rc; return class_interface_register(&i2o_device_class_interface);};/** * i2o_device_exit - I2O devices exit function * * Unregisters the I2O device class. */void i2o_device_exit(void){ class_interface_register(&i2o_device_class_interface); class_unregister(&i2o_device_class);};EXPORT_SYMBOL(i2o_device_claim);EXPORT_SYMBOL(i2o_device_claim_release);EXPORT_SYMBOL(i2o_parm_field_get);EXPORT_SYMBOL(i2o_parm_table_get);EXPORT_SYMBOL(i2o_parm_issue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -