Lines Matching full:device

3  * Device probing and sysfs code.
11 #include <linux/device.h>
192 static const struct ieee1394_device_id *unit_match(struct device *dev, in unit_match()
208 static bool is_fw_unit(const struct device *dev);
210 static int fw_unit_match(struct device *dev, struct device_driver *drv) in fw_unit_match()
216 static int fw_unit_probe(struct device *dev) in fw_unit_probe()
224 static void fw_unit_remove(struct device *dev) in fw_unit_remove()
243 static int fw_unit_uevent(const struct device *dev, struct kobj_uevent_env *env) in fw_unit_uevent()
264 int fw_device_enable_phys_dma(struct fw_device *device) in fw_device_enable_phys_dma() argument
266 int generation = device->generation; in fw_device_enable_phys_dma()
268 /* device->node_id, accessed below, must not be older than generation */ in fw_device_enable_phys_dma()
271 return device->card->driver->enable_phys_dma(device->card, in fw_device_enable_phys_dma()
272 device->node_id, in fw_device_enable_phys_dma()
282 static ssize_t show_immediate(struct device *dev, in show_immediate()
331 static ssize_t show_text_leaf(struct device *dev, in show_text_leaf()
410 static void init_fw_attribute_group(struct device *dev, in init_fw_attribute_group()
434 static ssize_t modalias_show(struct device *dev, in modalias_show()
446 static ssize_t rom_index_show(struct device *dev, in rom_index_show()
449 struct fw_device *device = fw_device(dev->parent); in rom_index_show() local
452 return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom); in rom_index_show()
461 static ssize_t config_rom_show(struct device *dev, in config_rom_show()
464 struct fw_device *device = fw_device(dev); in config_rom_show() local
468 length = device->config_rom_length * 4; in config_rom_show()
469 memcpy(buf, device->config_rom, length); in config_rom_show()
475 static ssize_t guid_show(struct device *dev, in guid_show()
478 struct fw_device *device = fw_device(dev); in guid_show() local
482 ret = sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]); in guid_show()
488 static ssize_t is_local_show(struct device *dev, in is_local_show()
491 struct fw_device *device = fw_device(dev); in is_local_show() local
493 return sprintf(buf, "%u\n", device->is_local); in is_local_show()
518 static ssize_t units_show(struct device *dev, in units_show()
521 struct fw_device *device = fw_device(dev); in units_show() local
526 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in units_show()
550 static int read_rom(struct fw_device *device, in read_rom() argument
556 /* device->node_id, accessed below, must not be older than generation */ in read_rom()
560 rcode = fw_run_transaction(device->card, in read_rom()
561 TCODE_READ_QUADLET_REQUEST, device->node_id, in read_rom()
562 generation, device->max_speed, offset, data, 4); in read_rom()
582 static int read_config_rom(struct fw_device *device, int generation) in read_config_rom() argument
584 struct fw_card *card = device->card; in read_config_rom()
598 device->max_speed = SCODE_100; in read_config_rom()
602 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
619 device->max_speed = device->node->max_speed; in read_config_rom()
630 if ((rom[2] & 0x7) < device->max_speed || in read_config_rom()
631 device->max_speed == SCODE_BETA || in read_config_rom()
636 if (device->max_speed == SCODE_BETA) in read_config_rom()
637 device->max_speed = card->link_speed; in read_config_rom()
639 while (device->max_speed > SCODE_100) { in read_config_rom()
640 if (read_rom(device, generation, 0, &dummy) == in read_config_rom()
643 device->max_speed--; in read_config_rom()
672 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
696 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
723 old_rom = device->config_rom; in read_config_rom()
731 device->config_rom = new_rom; in read_config_rom()
732 device->config_rom_length = length; in read_config_rom()
737 device->max_rec = rom[2] >> 12 & 0xf; in read_config_rom()
738 device->cmc = rom[2] >> 30 & 1; in read_config_rom()
739 device->irmc = rom[2] >> 31 & 1; in read_config_rom()
746 static void fw_unit_release(struct device *dev) in fw_unit_release()
759 static bool is_fw_unit(const struct device *dev) in is_fw_unit()
764 static void create_units(struct fw_device *device) in create_units() argument
771 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in create_units()
785 unit->device.bus = &fw_bus_type; in create_units()
786 unit->device.type = &fw_unit_type; in create_units()
787 unit->device.parent = &device->device; in create_units()
788 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); in create_units()
793 init_fw_attribute_group(&unit->device, in create_units()
797 fw_device_get(device); in create_units()
798 if (device_register(&unit->device) < 0) { in create_units()
799 put_device(&unit->device); in create_units()
805 static int shutdown_unit(struct device *device, void *data) in shutdown_unit() argument
807 device_unregister(device); in shutdown_unit()
825 struct fw_device *device; in fw_device_get_by_devt() local
828 device = idr_find(&fw_device_idr, MINOR(devt)); in fw_device_get_by_devt()
829 if (device) in fw_device_get_by_devt()
830 fw_device_get(device); in fw_device_get_by_devt()
833 return device; in fw_device_get_by_devt()
839 static void fw_schedule_device_work(struct fw_device *device, in fw_schedule_device_work() argument
842 queue_delayed_work(fw_workqueue, &device->work, delay); in fw_schedule_device_work()
847 * rom. It shouldn't be necessary to tweak these; if the device
863 struct fw_device *device = in fw_device_shutdown() local
865 int minor = MINOR(device->device.devt); in fw_device_shutdown()
868 device->card->reset_jiffies + SHUTDOWN_DELAY) in fw_device_shutdown()
869 && !list_empty(&device->card->link)) { in fw_device_shutdown()
870 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_shutdown()
874 if (atomic_cmpxchg(&device->state, in fw_device_shutdown()
879 fw_device_cdev_remove(device); in fw_device_shutdown()
880 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_shutdown()
881 device_unregister(&device->device); in fw_device_shutdown()
887 fw_device_put(device); in fw_device_shutdown()
890 static void fw_device_release(struct device *dev) in fw_device_release()
892 struct fw_device *device = fw_device(dev); in fw_device_release() local
893 struct fw_card *card = device->card; in fw_device_release()
902 device->node->data = NULL; in fw_device_release()
905 fw_node_put(device->node); in fw_device_release()
906 kfree(device->config_rom); in fw_device_release()
907 kfree(device); in fw_device_release()
915 static bool is_fw_device(const struct device *dev) in is_fw_device()
920 static int update_unit(struct device *dev, void *data) in update_unit()
936 struct fw_device *device = in fw_device_update() local
939 fw_device_cdev_update(device); in fw_device_update()
940 device_for_each_child(&device->device, NULL, update_unit); in fw_device_update()
944 * If a device was pending for deletion because its node went away but its
946 * device, revive the existing fw_device.
949 static int lookup_existing_device(struct device *dev, void *data) in lookup_existing_device()
979 fw_notice(card, "rediscovered device %s\n", dev_name(dev)); in lookup_existing_device()
998 static void set_broadcast_channel(struct fw_device *device, int generation) in set_broadcast_channel() argument
1000 struct fw_card *card = device->card; in set_broadcast_channel()
1014 if (!device->irmc || device->max_rec < 8) in set_broadcast_channel()
1021 if (device->bc_implemented == BC_UNKNOWN) { in set_broadcast_channel()
1023 device->node_id, generation, device->max_speed, in set_broadcast_channel()
1029 device->bc_implemented = BC_IMPLEMENTED; in set_broadcast_channel()
1034 device->bc_implemented = BC_UNIMPLEMENTED; in set_broadcast_channel()
1038 if (device->bc_implemented == BC_IMPLEMENTED) { in set_broadcast_channel()
1042 device->node_id, generation, device->max_speed, in set_broadcast_channel()
1048 int fw_device_set_broadcast_channel(struct device *dev, void *gen) in fw_device_set_broadcast_channel()
1058 struct fw_device *device = in fw_device_init() local
1060 struct fw_card *card = device->card; in fw_device_init()
1061 struct device *revived_dev; in fw_device_init()
1067 * device. in fw_device_init()
1070 ret = read_config_rom(device, device->generation); in fw_device_init()
1072 if (device->config_rom_retries < MAX_RETRIES && in fw_device_init()
1073 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_init()
1074 device->config_rom_retries++; in fw_device_init()
1075 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_init()
1077 if (device->node->link_on) in fw_device_init()
1079 device->node_id, in fw_device_init()
1081 if (device->node == card->root_node) in fw_device_init()
1083 fw_device_release(&device->device); in fw_device_init()
1088 revived_dev = device_find_child(card->device, in fw_device_init()
1089 device, lookup_existing_device); in fw_device_init()
1092 fw_device_release(&device->device); in fw_device_init()
1097 device_initialize(&device->device); in fw_device_init()
1099 fw_device_get(device); in fw_device_init()
1101 minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, in fw_device_init()
1108 device->device.bus = &fw_bus_type; in fw_device_init()
1109 device->device.type = &fw_device_type; in fw_device_init()
1110 device->device.parent = card->device; in fw_device_init()
1111 device->device.devt = MKDEV(fw_cdev_major, minor); in fw_device_init()
1112 dev_set_name(&device->device, "fw%d", minor); in fw_device_init()
1114 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < in fw_device_init()
1117 init_fw_attribute_group(&device->device, in fw_device_init()
1119 &device->attribute_group); in fw_device_init()
1121 if (device_add(&device->device)) { in fw_device_init()
1122 fw_err(card, "failed to add device\n"); in fw_device_init()
1126 create_units(device); in fw_device_init()
1129 * Transition the device to running state. If it got pulled in fw_device_init()
1131 * have to shut down the device again here. Normally, though, in fw_device_init()
1137 if (atomic_cmpxchg(&device->state, in fw_device_init()
1140 device->workfn = fw_device_shutdown; in fw_device_init()
1141 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_init()
1143 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", in fw_device_init()
1144 dev_name(&device->device), in fw_device_init()
1145 device->config_rom[3], device->config_rom[4], in fw_device_init()
1146 1 << device->max_speed); in fw_device_init()
1147 device->config_rom_retries = 0; in fw_device_init()
1149 set_broadcast_channel(device, device->generation); in fw_device_init()
1151 add_device_randomness(&device->config_rom[3], 8); in fw_device_init()
1160 if (device->node == card->root_node) in fw_device_init()
1170 fw_device_put(device); /* fw_device_idr's reference */ in fw_device_init()
1172 put_device(&device->device); /* our reference */ in fw_device_init()
1176 static int reread_config_rom(struct fw_device *device, int generation, in reread_config_rom() argument
1183 rcode = read_rom(device, generation, i, &q); in reread_config_rom()
1191 if (q != device->config_rom[i]) { in reread_config_rom()
1203 struct fw_device *device = in fw_device_refresh() local
1205 struct fw_card *card = device->card; in fw_device_refresh()
1206 int ret, node_id = device->node_id; in fw_device_refresh()
1209 ret = reread_config_rom(device, device->generation, &changed); in fw_device_refresh()
1214 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1220 device->config_rom_retries = 0; in fw_device_refresh()
1228 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_refresh()
1230 ret = read_config_rom(device, device->generation); in fw_device_refresh()
1234 fw_device_cdev_update(device); in fw_device_refresh()
1235 create_units(device); in fw_device_refresh()
1238 kobject_uevent(&device->device.kobj, KOBJ_CHANGE); in fw_device_refresh()
1240 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1245 fw_notice(card, "refreshed device %s\n", dev_name(&device->device)); in fw_device_refresh()
1246 device->config_rom_retries = 0; in fw_device_refresh()
1250 if (device->config_rom_retries < MAX_RETRIES && in fw_device_refresh()
1251 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_refresh()
1252 device->config_rom_retries++; in fw_device_refresh()
1253 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_refresh()
1257 fw_notice(card, "giving up on refresh of device %s: %s\n", in fw_device_refresh()
1258 dev_name(&device->device), fw_rcode_string(ret)); in fw_device_refresh()
1260 atomic_set(&device->state, FW_DEVICE_GONE); in fw_device_refresh()
1261 device->workfn = fw_device_shutdown; in fw_device_refresh()
1262 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_refresh()
1270 struct fw_device *device = container_of(to_delayed_work(work), in fw_device_workfn() local
1272 device->workfn(work); in fw_device_workfn()
1277 struct fw_device *device; in fw_node_event() local
1288 device = kzalloc(sizeof(*device), GFP_ATOMIC); in fw_node_event()
1289 if (device == NULL) in fw_node_event()
1293 * Do minimal initialization of the device here, the in fw_node_event()
1298 * You can basically just check device->state and in fw_node_event()
1302 atomic_set(&device->state, FW_DEVICE_INITIALIZING); in fw_node_event()
1303 device->card = fw_card_get(card); in fw_node_event()
1304 device->node = fw_node_get(node); in fw_node_event()
1305 device->node_id = node->node_id; in fw_node_event()
1306 device->generation = card->generation; in fw_node_event()
1307 device->is_local = node == card->local_node; in fw_node_event()
1308 mutex_init(&device->client_list_mutex); in fw_node_event()
1309 INIT_LIST_HEAD(&device->client_list); in fw_node_event()
1312 * Set the node data to point back to this device so in fw_node_event()
1314 * and generation for the device. in fw_node_event()
1316 node->data = device; in fw_node_event()
1324 device->workfn = fw_device_init; in fw_node_event()
1325 INIT_DELAYED_WORK(&device->work, fw_device_workfn); in fw_node_event()
1326 fw_schedule_device_work(device, INITIAL_DELAY); in fw_node_event()
1331 device = node->data; in fw_node_event()
1332 if (device == NULL) in fw_node_event()
1335 device->node_id = node->node_id; in fw_node_event()
1337 device->generation = card->generation; in fw_node_event()
1338 if (atomic_cmpxchg(&device->state, in fw_node_event()
1341 device->workfn = fw_device_refresh; in fw_node_event()
1342 fw_schedule_device_work(device, in fw_node_event()
1343 device->is_local ? 0 : INITIAL_DELAY); in fw_node_event()
1348 device = node->data; in fw_node_event()
1349 if (device == NULL) in fw_node_event()
1352 device->node_id = node->node_id; in fw_node_event()
1354 device->generation = card->generation; in fw_node_event()
1355 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { in fw_node_event()
1356 device->workfn = fw_device_update; in fw_node_event()
1357 fw_schedule_device_work(device, 0); in fw_node_event()
1367 * Destroy the device associated with the node. There in fw_node_event()
1368 * are two cases here: either the device is fully in fw_node_event()
1372 * initialized we can reuse device->work to schedule a in fw_node_event()
1375 * the device in shutdown state to have that code fail in fw_node_event()
1376 * to create the device. in fw_node_event()
1378 device = node->data; in fw_node_event()
1379 if (atomic_xchg(&device->state, in fw_node_event()
1381 device->workfn = fw_device_shutdown; in fw_node_event()
1382 fw_schedule_device_work(device, in fw_node_event()
1390 #include "device-attribute-test.c"