Lines Matching +full:rom +full:- +full:val

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2005-2006 Kristian Hoegsberg <[email protected]>
14 #include <linux/firewire-constants.h>
37 ci->p = p + 1; in fw_csr_iterator_init()
38 ci->end = ci->p + (p[0] >> 16); in fw_csr_iterator_init()
44 *key = *ci->p >> 24; in fw_csr_iterator_next()
45 *value = *ci->p & 0xffffff; in fw_csr_iterator_next()
47 return ci->p++ < ci->end; in fw_csr_iterator_next()
61 return ci.p - 1 + value; in search_directory()
76 return ci.p - 1 + value; in search_leaf()
90 return -EINVAL; in textual_leaf_to_string()
94 return -ENODATA; in textual_leaf_to_string()
98 return -ENODATA; in textual_leaf_to_string()
101 quadlets -= 2; in textual_leaf_to_string()
102 for (i = 0; i < quadlets * 4 && i < size - 1; i++) { in textual_leaf_to_string()
103 c = block[i / 4] >> (24 - 8 * (i % 4)); in textual_leaf_to_string()
114 * fw_csr_string() - reads a string from the configuration ROM
121 * @key. The string is zero-terminated. An overlong string is silently truncated such that it
130 return -ENOENT; in fw_csr_string()
154 const u32 *root_directory = &fw_parent_device(unit)->config_rom[ROOT_DIR_OFFSET]; in get_modalias_ids()
161 // Legacy layout of configuration ROM described in Annex 1 of 'Configuration ROM for AV/C in get_modalias_ids()
165 directories[1] = unit->directory; in get_modalias_ids()
168 directories[2] = unit->directory; in get_modalias_ids()
179 if (id[0] == id_table->vendor_id) in match_ids()
181 if (id[1] == id_table->model_id) in match_ids()
183 if (id[2] == id_table->specifier_id) in match_ids()
185 if (id[3] == id_table->version) in match_ids()
188 return (match & id_table->match_flags) == id_table->match_flags; in match_ids()
195 container_of_const(drv, struct fw_driver, driver)->id_table; in unit_match()
200 for (; id_table->match_flags != 0; id_table++) in unit_match()
218 container_of(dev->driver, struct fw_driver, driver); in fw_unit_probe()
220 return driver->probe(fw_unit(dev), unit_match(dev, dev->driver)); in fw_unit_probe()
226 container_of(dev->driver, struct fw_driver, driver); in fw_unit_remove()
228 driver->remove(fw_unit(dev)); in fw_unit_remove()
250 return -ENOMEM; in fw_unit_uevent()
265 int generation = device->generation; in fw_device_enable_phys_dma()
267 /* device->node_id, accessed below, must not be older than generation */ in fw_device_enable_phys_dma()
270 return device->card->driver->enable_phys_dma(device->card, in fw_device_enable_phys_dma()
271 device->node_id, in fw_device_enable_phys_dma()
288 int i, value = -1; in show_immediate()
293 directories[0] = fw_unit(dev)->directory; in show_immediate()
295 const u32 *root_directory = fw_device(dev)->config_rom + ROOT_DIR_OFFSET; in show_immediate()
301 // Legacy layout of configuration ROM described in Annex 1 of in show_immediate()
302 // 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394 Trading in show_immediate()
310 int key, val; in show_immediate() local
313 while (fw_csr_iterator_next(&ci, &key, &val)) { in show_immediate()
314 if (attr->key == key) in show_immediate()
315 value = val; in show_immediate()
320 return -ENOENT; in show_immediate()
337 int i, ret = -ENOENT; in show_text_leaf()
342 directories[0] = fw_unit(dev)->directory; in show_text_leaf()
344 const u32 *root_directory = fw_device(dev)->config_rom + ROOT_DIR_OFFSET; in show_text_leaf()
350 // Legacy layout of configuration ROM described in Annex 1 of in show_text_leaf()
351 // 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394 in show_text_leaf()
360 bufsize = PAGE_SIZE - 1; in show_text_leaf()
367 int result = fw_csr_string(directories[i], attr->key, buf, bufsize); in show_text_leaf()
371 } else if (i == 0 && attr->key == CSR_VENDOR) { in show_text_leaf()
372 // Sony DVMC-DA1 has configuration ROM such that the descriptor leaf entry in show_text_leaf()
375 result = fw_csr_string(directories[i], CSR_DIRECTORY | attr->key, buf, in show_text_leaf()
386 while (ret > 0 && isspace(buf[ret - 1])) in show_text_leaf()
387 ret--; in show_text_leaf()
416 group->attrs[j] = &attrs[j].attr; in init_fw_attribute_group()
420 if (attr->show(dev, attr, NULL) < 0) in init_fw_attribute_group()
422 group->attrs[j++] = &attr->attr; in init_fw_attribute_group()
425 group->attrs[j] = NULL; in init_fw_attribute_group()
426 group->groups[0] = &group->group; in init_fw_attribute_group()
427 group->groups[1] = NULL; in init_fw_attribute_group()
428 group->group.attrs = group->attrs; in init_fw_attribute_group()
429 dev->groups = (const struct attribute_group **) group->groups; in init_fw_attribute_group()
447 struct fw_device *device = fw_device(dev->parent); in rom_index_show()
450 return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom); in rom_index_show()
467 length = device->config_rom_length * 4; in config_rom_show()
468 memcpy(buf, device->config_rom, length); in config_rom_show()
480 return sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]); in guid_show()
488 return sysfs_emit(buf, "%u\n", device->is_local); in is_local_show()
522 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in units_show()
526 i += units_sprintf(&buf[i], ci.p + value - 1); in units_show()
527 if (i >= PAGE_SIZE - (8 + 1 + 8 + 1)) in units_show()
532 buf[i - 1] = '\n'; in units_show()
551 /* device->node_id, accessed below, must not be older than generation */ in read_rom()
555 rcode = fw_run_transaction(device->card, in read_rom()
556 TCODE_READ_QUADLET_REQUEST, device->node_id, in read_rom()
557 generation, device->max_speed, offset, data, 4); in read_rom()
568 #define MAX_CONFIG_ROM_SIZE ((CSR_CONFIG_ROM_END - CSR_CONFIG_ROM) / sizeof(u32))
572 * the config ROM. We do all this with a cached bus generation. If the bus
575 * are reading the ROM may have changed the ROM during the reset.
580 struct fw_card *card = device->card; in read_config_rom()
582 u32 *rom, *stack; in read_config_rom() local
586 rom = kmalloc(sizeof(*rom) * MAX_CONFIG_ROM_SIZE + in read_config_rom()
588 if (rom == NULL) in read_config_rom()
589 return -ENOMEM; in read_config_rom()
591 stack = &rom[MAX_CONFIG_ROM_SIZE]; in read_config_rom()
592 memset(rom, 0, sizeof(*rom) * MAX_CONFIG_ROM_SIZE); in read_config_rom()
594 device->max_speed = SCODE_100; in read_config_rom()
598 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
604 * rom to indicate that they are booting (for example, in read_config_rom()
609 if (i == 0 && rom[i] == 0) { in read_config_rom()
615 device->max_speed = device->node->max_speed; in read_config_rom()
619 * - devices with link speed less than PHY speed, in read_config_rom()
620 * - devices with 1394b PHY (unless only connected to 1394a PHYs), in read_config_rom()
621 * - all devices if there are 1394b repeaters. in read_config_rom()
624 * 1394-1995 nodes do not have the field. in read_config_rom()
626 if ((rom[2] & 0x7) < device->max_speed || in read_config_rom()
627 device->max_speed == SCODE_BETA || in read_config_rom()
628 card->beta_repeaters_present) { in read_config_rom()
632 if (device->max_speed == SCODE_BETA) in read_config_rom()
633 device->max_speed = card->link_speed; in read_config_rom()
635 while (device->max_speed > SCODE_100) { in read_config_rom()
639 device->max_speed--; in read_config_rom()
644 * Now parse the config rom. The config rom is a recursive in read_config_rom()
656 * lower 24 bits is the offset into the config rom, in read_config_rom()
660 key = stack[--sp]; in read_config_rom()
663 ret = -ENXIO; in read_config_rom()
668 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
671 end = i + (rom[i] >> 16) + 1; in read_config_rom()
674 * This block extends outside the config ROM which is in read_config_rom()
678 fw_err(card, "skipped invalid ROM block %x at %llx\n", in read_config_rom()
679 rom[i], in read_config_rom()
681 rom[i] = 0; in read_config_rom()
692 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
696 if ((key >> 30) != 3 || (rom[i] >> 30) < 2) in read_config_rom()
699 * Offset points outside the ROM. May be a firmware in read_config_rom()
700 * bug or an Extended ROM entry (IEEE 1212-2001 clause in read_config_rom()
703 * the ROM don't have to check offsets all the time. in read_config_rom()
705 if (i + (rom[i] & 0xffffff) >= MAX_CONFIG_ROM_SIZE) { in read_config_rom()
707 "skipped unsupported ROM entry %x at %llx\n", in read_config_rom()
708 rom[i], in read_config_rom()
710 rom[i] = 0; in read_config_rom()
713 stack[sp++] = i + rom[i]; in read_config_rom()
719 old_rom = device->config_rom; in read_config_rom()
720 new_rom = kmemdup(rom, length * 4, GFP_KERNEL); in read_config_rom()
722 ret = -ENOMEM; in read_config_rom()
727 device->config_rom = new_rom; in read_config_rom()
728 device->config_rom_length = length; in read_config_rom()
733 device->max_rec = rom[2] >> 12 & 0xf; in read_config_rom()
734 device->cmc = rom[2] >> 30 & 1; in read_config_rom()
735 device->irmc = rom[2] >> 31 & 1; in read_config_rom()
737 kfree(rom); in read_config_rom()
757 return dev->type == &fw_unit_type; in is_fw_unit()
767 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in create_units()
780 unit->directory = ci.p + value - 1; in create_units()
781 unit->device.bus = &fw_bus_type; in create_units()
782 unit->device.type = &fw_unit_type; in create_units()
783 unit->device.parent = &device->device; in create_units()
784 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); in create_units()
786 BUILD_BUG_ON(ARRAY_SIZE(unit->attribute_group.attrs) < in create_units()
789 init_fw_attribute_group(&unit->device, in create_units()
791 &unit->attribute_group); in create_units()
794 if (device_register(&unit->device) < 0) { in create_units()
795 put_device(&unit->device); in create_units()
810 * - serializes accesses to fw_device.config_rom/.config_rom_length and
835 queue_delayed_work(fw_workqueue, &device->work, delay); in fw_schedule_device_work()
840 * rom. It shouldn't be necessary to tweak these; if the device
841 * doesn't respond to a config rom read within 10 seconds, it's not
860 device->card->reset_jiffies + SHUTDOWN_DELAY) in fw_device_shutdown()
861 && !list_empty(&device->card->link)) { in fw_device_shutdown()
866 if (atomic_cmpxchg(&device->state, in fw_device_shutdown()
872 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_shutdown()
873 device_unregister(&device->device); in fw_device_shutdown()
875 xa_erase(&fw_device_xa, MINOR(device->device.devt)); in fw_device_shutdown()
883 struct fw_card *card = device->card; in fw_device_release()
890 scoped_guard(spinlock_irqsave, &card->lock) in fw_device_release()
891 device->node->data = NULL; in fw_device_release()
893 fw_node_put(device->node); in fw_device_release()
894 kfree(device->config_rom); in fw_device_release()
905 return dev->type == &fw_device_type; in is_fw_device()
911 struct fw_driver *driver = (struct fw_driver *)dev->driver; in update_unit()
913 if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) { in update_unit()
915 driver->update(unit); in update_unit()
928 device_for_each_child(&device->device, NULL, update_unit); in fw_device_update()
935 struct fw_card *card = device->card; in set_broadcast_channel()
939 if (!card->broadcast_channel_allocated) in set_broadcast_channel()
949 if (!device->irmc || device->max_rec < 8) in set_broadcast_channel()
953 * Some 1394-1995 nodes crash if this 1394a-2000 register is written. in set_broadcast_channel()
956 if (device->bc_implemented == BC_UNKNOWN) { in set_broadcast_channel()
958 device->node_id, generation, device->max_speed, in set_broadcast_channel()
964 device->bc_implemented = BC_IMPLEMENTED; in set_broadcast_channel()
969 device->bc_implemented = BC_UNIMPLEMENTED; in set_broadcast_channel()
973 if (device->bc_implemented == BC_IMPLEMENTED) { in set_broadcast_channel()
977 device->node_id, generation, device->max_speed, in set_broadcast_channel()
1000 return !memcmp(old->config_rom, config_rom, 6 * 4); in compare_configuration_rom()
1007 struct fw_card *card = device->card; in fw_device_init()
1013 * All failure paths here set node->data to NULL, so that we in fw_device_init()
1018 ret = read_config_rom(device, device->generation); in fw_device_init()
1020 if (device->config_rom_retries < MAX_RETRIES && in fw_device_init()
1021 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_init()
1022 device->config_rom_retries++; in fw_device_init()
1025 if (device->node->link_on) in fw_device_init()
1026 fw_notice(card, "giving up on node %x: reading config rom failed: %s\n", in fw_device_init()
1027 device->node_id, in fw_device_init()
1029 if (device->node == card->root_node) in fw_device_init()
1031 fw_device_release(&device->device); in fw_device_init()
1042 found = device_find_child(card->device, device->config_rom, in fw_device_init()
1048 if (atomic_cmpxchg(&reused->state, in fw_device_init()
1052 scoped_guard(spinlock_irq, &card->lock) { in fw_device_init()
1053 struct fw_node *current_node = device->node; in fw_device_init()
1054 struct fw_node *obsolete_node = reused->node; in fw_device_init()
1056 device->node = obsolete_node; in fw_device_init()
1057 device->node->data = device; in fw_device_init()
1058 reused->node = current_node; in fw_device_init()
1059 reused->node->data = reused; in fw_device_init()
1061 reused->max_speed = device->max_speed; in fw_device_init()
1062 reused->node_id = current_node->node_id; in fw_device_init()
1064 reused->generation = card->generation; in fw_device_init()
1065 reused->config_rom_retries = 0; in fw_device_init()
1069 reused->workfn = fw_device_update; in fw_device_init()
1072 if (current_node == card->root_node) in fw_device_init()
1077 fw_device_release(&device->device); in fw_device_init()
1085 device_initialize(&device->device); in fw_device_init()
1094 device->device.bus = &fw_bus_type; in fw_device_init()
1095 device->device.type = &fw_device_type; in fw_device_init()
1096 device->device.parent = card->device; in fw_device_init()
1097 device->device.devt = MKDEV(fw_cdev_major, minor); in fw_device_init()
1098 dev_set_name(&device->device, "fw%d", minor); in fw_device_init()
1100 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < in fw_device_init()
1103 init_fw_attribute_group(&device->device, in fw_device_init()
1105 &device->attribute_group); in fw_device_init()
1107 if (device_add(&device->device)) { in fw_device_init()
1123 if (atomic_cmpxchg(&device->state, in fw_device_init()
1126 device->workfn = fw_device_shutdown; in fw_device_init()
1130 dev_name(&device->device), in fw_device_init()
1131 device->config_rom[3], device->config_rom[4], in fw_device_init()
1132 1 << device->max_speed); in fw_device_init()
1133 device->config_rom_retries = 0; in fw_device_init()
1135 set_broadcast_channel(device, device->generation); in fw_device_init()
1137 add_device_randomness(&device->config_rom[3], 8); in fw_device_init()
1142 * root node config rom. If this races with a bus reset we in fw_device_init()
1143 * just end up running the IRM work a couple of extra times - in fw_device_init()
1146 if (device->node == card->root_node) in fw_device_init()
1156 put_device(&device->device); /* our reference */ in fw_device_init()
1175 if (q != device->config_rom[i]) { in reread_config_rom()
1189 struct fw_card *card = device->card; in fw_device_refresh()
1190 int ret, node_id = device->node_id; in fw_device_refresh()
1193 ret = reread_config_rom(device, device->generation, &changed); in fw_device_refresh()
1198 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1204 device->config_rom_retries = 0; in fw_device_refresh()
1212 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_refresh()
1214 ret = read_config_rom(device, device->generation); in fw_device_refresh()
1221 /* Userspace may want to re-read attributes. */ in fw_device_refresh()
1222 kobject_uevent(&device->device.kobj, KOBJ_CHANGE); in fw_device_refresh()
1224 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1229 fw_notice(card, "refreshed device %s\n", dev_name(&device->device)); in fw_device_refresh()
1230 device->config_rom_retries = 0; in fw_device_refresh()
1234 if (device->config_rom_retries < MAX_RETRIES && in fw_device_refresh()
1235 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_refresh()
1236 device->config_rom_retries++; in fw_device_refresh()
1242 dev_name(&device->device), fw_rcode_string(ret)); in fw_device_refresh()
1244 atomic_set(&device->state, FW_DEVICE_GONE); in fw_device_refresh()
1245 device->workfn = fw_device_shutdown; in fw_device_refresh()
1248 if (node_id == card->root_node->node_id) in fw_device_refresh()
1256 device->workfn(work); in fw_device_workfn()
1268 * send L=0 but have an up-and-running link; others send L=1 in fw_node_event()
1282 * You can basically just check device->state and in fw_node_event()
1284 * card->lock. in fw_node_event()
1286 atomic_set(&device->state, FW_DEVICE_INITIALIZING); in fw_node_event()
1287 device->card = fw_card_get(card); in fw_node_event()
1288 device->node = fw_node_get(node); in fw_node_event()
1289 device->node_id = node->node_id; in fw_node_event()
1290 device->generation = card->generation; in fw_node_event()
1291 device->is_local = node == card->local_node; in fw_node_event()
1292 mutex_init(&device->client_list_mutex); in fw_node_event()
1293 INIT_LIST_HEAD(&device->client_list); in fw_node_event()
1300 node->data = device; in fw_node_event()
1305 * power-up after getting plugged in. We schedule the in fw_node_event()
1306 * first config rom scan half a second after bus reset. in fw_node_event()
1308 device->workfn = fw_device_init; in fw_node_event()
1309 INIT_DELAYED_WORK(&device->work, fw_device_workfn); in fw_node_event()
1315 device = node->data; in fw_node_event()
1319 device->node_id = node->node_id; in fw_node_event()
1321 device->generation = card->generation; in fw_node_event()
1322 if (atomic_cmpxchg(&device->state, in fw_node_event()
1325 device->workfn = fw_device_refresh; in fw_node_event()
1327 device->is_local ? 0 : INITIAL_DELAY); in fw_node_event()
1332 device = node->data; in fw_node_event()
1336 device->node_id = node->node_id; in fw_node_event()
1338 device->generation = card->generation; in fw_node_event()
1339 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { in fw_node_event()
1340 device->workfn = fw_device_update; in fw_node_event()
1347 if (!node->data) in fw_node_event()
1354 * process of reading its config rom in fw_node_event()
1356 * initialized we can reuse device->work to schedule a in fw_node_event()
1358 * scheduled to read it's config rom, and we just put in fw_node_event()
1362 device = node->data; in fw_node_event()
1363 if (atomic_xchg(&device->state, in fw_node_event()
1365 device->workfn = fw_device_shutdown; in fw_node_event()
1367 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY); in fw_node_event()
1374 #include "device-attribute-test.c"