if (block[1] != 0 || block[2] != 0) /* unknown language/character set */ return -ENODATA;
block += 3;
quadlets -= 2; for (i = 0; i < quadlets * 4 && i < size - 1; i++) {
c = block[i / 4] >> (24 - 8 * (i % 4)); if (c == '\0') break;
buf[i] = c;
}
buf[i] = '\0';
return i;
}
/** * fw_csr_string() - reads a string from the configuration ROM * @directory: e.g. root directory or unit directory * @key: the key of the preceding directory entry * @buf: where to put the string * @size: size of @buf, in bytes * * The string is taken from a minimal ASCII text descriptor leaf just after the entry with the * @key. The string is zero-terminated. An overlong string is silently truncated such that it * and the zero byte fit into @size. * * Returns strlen(buf) or a negative error code.
*/ int fw_csr_string(const u32 *directory, int key, char *buf, size_t size)
{ const u32 *leaf = search_leaf(directory, key); if (!leaf) return -ENOENT;
// Legacy layout of configuration ROM described in Annex 1 of 'Configuration ROM for AV/C // Devices 1.0 (December 12, 2000, 1394 Trading Association, TA Document 1999027)'.
vendor_directory = search_directory(root_directory, CSR_VENDOR); if (!vendor_directory) {
directories[1] = unit->directory;
} else {
directories[1] = vendor_directory;
directories[2] = unit->directory;
}
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i)
get_ids(directories[i], id);
}
staticbool match_ids(conststruct ieee1394_device_id *id_table, int *id)
{ int match = 0;
if (id[0] == id_table->vendor_id)
match |= IEEE1394_MATCH_VENDOR_ID; if (id[1] == id_table->model_id)
match |= IEEE1394_MATCH_MODEL_ID; if (id[2] == id_table->specifier_id)
match |= IEEE1394_MATCH_SPECIFIER_ID; if (id[3] == id_table->version)
match |= IEEE1394_MATCH_VERSION;
if (!vendor_directory) {
directories[0] = root_directory;
} else { // Legacy layout of configuration ROM described in Annex 1 of // 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394 Trading // Association, TA Document 1999027)'.
directories[0] = vendor_directory;
directories[1] = root_directory;
}
}
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) { int key, val;
fw_csr_iterator_init(&ci, directories[i]); while (fw_csr_iterator_next(&ci, &key, &val)) { if (attr->key == key)
value = val;
}
}
if (value < 0) return -ENOENT;
// Note that this function is also called by init_fw_attribute_group() with NULL pointer. return buf ? sysfs_emit(buf, "0x%06x\n", value) : 0;
}
if (!vendor_directory) {
directories[0] = root_directory;
} else { // Legacy layout of configuration ROM described in Annex 1 of // 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394 // Trading Association, TA Document 1999027)'.
directories[0] = root_directory;
directories[1] = vendor_directory;
}
}
// Note that this function is also called by init_fw_attribute_group() with NULL pointer. if (buf) {
bufsize = PAGE_SIZE - 1;
} else {
buf = dummy_buf;
bufsize = 1;
}
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) { int result = fw_csr_string(directories[i], attr->key, buf, bufsize); // Detected. if (result >= 0) {
ret = result;
} elseif (i == 0 && attr->key == CSR_VENDOR) { // Sony DVMC-DA1 has configuration ROM such that the descriptor leaf entry // in the root directory follows to the directory entry for vendor ID // instead of the immediate value for vendor ID.
result = fw_csr_string(directories[i], CSR_DIRECTORY | attr->key, buf,
bufsize); if (result >= 0)
ret = result;
}
}
staticint read_rom(struct fw_device *device, int generation, int index, u32 *data)
{
u64 offset = (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4; int i, rcode;
/* device->node_id, accessed below, must not be older than generation */
smp_rmb();
for (i = 10; i < 100; i += 10) {
rcode = fw_run_transaction(device->card,
TCODE_READ_QUADLET_REQUEST, device->node_id,
generation, device->max_speed, offset, data, 4); if (rcode != RCODE_BUSY) break;
msleep(i);
}
be32_to_cpus(data);
return rcode;
}
// By quadlet unit. #define MAX_CONFIG_ROM_SIZE ((CSR_CONFIG_ROM_END - CSR_CONFIG_ROM) / sizeof(u32))
/* * Read the bus info block, perform a speed probe, and read all of the rest of * the config ROM. We do all this with a cached bus generation. If the bus * generation changes under us, read_config_rom will fail and get retried. * It's better to start all over in this case because the node from which we * are reading the ROM may have changed the ROM during the reset. * Returns either a result code or a negative error code.
*/ staticint read_config_rom(struct fw_device *device, int generation)
{ struct fw_card *card = device->card; const u32 *old_rom, *new_rom;
u32 *rom, *stack;
u32 sp, key; int i, end, length, ret;
rom = kmalloc(sizeof(*rom) * MAX_CONFIG_ROM_SIZE + sizeof(*stack) * MAX_CONFIG_ROM_SIZE, GFP_KERNEL); if (rom == NULL) return -ENOMEM;
/* First read the bus info block. */ for (i = 0; i < 5; i++) {
ret = read_rom(device, generation, i, &rom[i]); if (ret != RCODE_COMPLETE) goto out; /* * As per IEEE1212 7.2, during initialization, devices can * reply with a 0 for the first quadlet of the config * rom to indicate that they are booting (for example, * if the firmware is on the disk of a external * harddisk). In that case we just fail, and the * retry mechanism will try again later.
*/ if (i == 0 && rom[i] == 0) {
ret = RCODE_BUSY; goto out;
}
}
device->max_speed = device->node->max_speed;
/* * Determine the speed of * - devices with link speed less than PHY speed, * - devices with 1394b PHY (unless only connected to 1394a PHYs), * - all devices if there are 1394b repeaters. * Note, we cannot use the bus info block's link_spd as starting point * because some buggy firmwares set it lower than necessary and because * 1394-1995 nodes do not have the field.
*/ if ((rom[2] & 0x7) < device->max_speed ||
device->max_speed == SCODE_BETA ||
card->beta_repeaters_present) {
u32 dummy;
/* for S1600 and S3200 */ if (device->max_speed == SCODE_BETA)
device->max_speed = card->link_speed;
while (device->max_speed > SCODE_100) { if (read_rom(device, generation, 0, &dummy) ==
RCODE_COMPLETE) break;
device->max_speed--;
}
}
/* * Now parse the config rom. The config rom is a recursive * directory structure so we parse it using a stack of * references to the blocks that make up the structure. We * push a reference to the root directory on the stack to * start things off.
*/
length = i;
sp = 0;
stack[sp++] = 0xc0000005; while (sp > 0) { /* * Pop the next block reference of the stack. The * lower 24 bits is the offset into the config rom, * the upper 8 bits are the type of the reference the * block.
*/
key = stack[--sp];
i = key & 0xffffff; if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) {
ret = -ENXIO; goto out;
}
/* Read header quadlet for the block to get the length. */
ret = read_rom(device, generation, i, &rom[i]); if (ret != RCODE_COMPLETE) goto out;
end = i + (rom[i] >> 16) + 1; if (end > MAX_CONFIG_ROM_SIZE) { /* * This block extends outside the config ROM which is * a firmware bug. Ignore this whole block, i.e. * simply set a fake block length of 0.
*/
fw_err(card, "skipped invalid ROM block %x at %llx\n",
rom[i],
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
rom[i] = 0;
end = i;
}
i++;
/* * Now read in the block. If this is a directory * block, check the entries as we read them to see if * it references another block, and push it in that case.
*/ for (; i < end; i++) {
ret = read_rom(device, generation, i, &rom[i]); if (ret != RCODE_COMPLETE) goto out;
if ((key >> 30) != 3 || (rom[i] >> 30) < 2) continue; /* * Offset points outside the ROM. May be a firmware * bug or an Extended ROM entry (IEEE 1212-2001 clause * 7.7.18). Simply overwrite this pointer here by a * fake immediate entry so that later iterators over * the ROM don't have to check offsets all the time.
*/ if (i + (rom[i] & 0xffffff) >= MAX_CONFIG_ROM_SIZE) {
fw_err(card, "skipped unsupported ROM entry %x at %llx\n",
rom[i],
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
rom[i] = 0; continue;
}
stack[sp++] = i + rom[i];
} if (length < i)
length = i;
}
i = 0;
fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); while (fw_csr_iterator_next(&ci, &key, &value)) { if (key != (CSR_UNIT | CSR_DIRECTORY)) continue;
/* * Get the address of the unit directory and try to * match the drivers id_tables against it.
*/
unit = kzalloc(sizeof(*unit), GFP_KERNEL); if (unit == NULL) continue;
/* * These defines control the retry behavior for reading the config * rom. It shouldn't be necessary to tweak these; if the device * doesn't respond to a config rom read within 10 seconds, it's not * going to respond at all. As for the initial delay, a lot of * devices will be able to respond within half a second after bus * reset. On the other hand, it's not really worth being more * aggressive than that, since it scales pretty well; if 10 devices * are plugged in, they're all getting read within one second.
*/
/* * Take the card lock so we don't set this to NULL while a * FW_NODE_UPDATED callback is being handled or while the * bus manager work looks at this node.
*/
scoped_guard(spinlock_irqsave, &card->lock)
device->node->data = NULL;
staticvoid set_broadcast_channel(struct fw_device *device, int generation)
{ struct fw_card *card = device->card;
__be32 data; int rcode;
if (!card->broadcast_channel_allocated) return;
/* * The Broadcast_Channel Valid bit is required by nodes which want to * transmit on this channel. Such transmissions are practically * exclusive to IP over 1394 (RFC 2734). IP capable nodes are required * to be IRM capable and have a max_rec of 8 or more. We use this fact * to narrow down to which nodes we send Broadcast_Channel updates.
*/ if (!device->irmc || device->max_rec < 8) return;
/* * Some 1394-1995 nodes crash if this 1394a-2000 register is written. * Perform a read test first.
*/ if (device->bc_implemented == BC_UNKNOWN) {
rcode = fw_run_transaction(card, TCODE_READ_QUADLET_REQUEST,
device->node_id, generation, device->max_speed,
CSR_REGISTER_BASE + CSR_BROADCAST_CHANNEL,
&data, 4); switch (rcode) { case RCODE_COMPLETE: if (data & cpu_to_be32(1 << 31)) {
device->bc_implemented = BC_IMPLEMENTED; break;
}
fallthrough; /* to case address error */ case RCODE_ADDRESS_ERROR:
device->bc_implemented = BC_UNIMPLEMENTED;
}
}
/* * All failure paths here set node->data to NULL, so that we * don't try to do device_for_each_child() on a kfree()'d * device.
*/
ret = read_config_rom(device, device->generation); if (ret != RCODE_COMPLETE) { if (device->config_rom_retries < MAX_RETRIES &&
atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
device->config_rom_retries++;
fw_schedule_device_work(device, RETRY_DELAY);
} else { if (device->node->link_on)
fw_notice(card, "giving up on node %x: reading config rom failed: %s\n",
device->node_id,
fw_rcode_string(ret)); if (device->node == card->root_node)
fw_schedule_bm_work(card, 0);
fw_device_release(&device->device);
} return;
}
// If a device was pending for deletion because its node went away but its bus info block // and root directory header matches that of a newly discovered device, revive the // existing fw_device. The newly allocated fw_device becomes obsolete instead. // // serialize config_rom access.
scoped_guard(rwsem_read, &fw_device_rwsem) {
found = device_find_child(card->device, device->config_rom,
compare_configuration_rom);
} if (found) { struct fw_device *reused = fw_device(found);
// The index of allocated entry is used for minor identifier of device node.
ret = xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), GFP_KERNEL); if (ret < 0) goto error;
if (device_add(&device->device)) {
fw_err(card, "failed to add device\n"); goto error_with_cdev;
}
create_units(device);
/* * Transition the device to running state. If it got pulled * out from under us while we did the initialization work, we * have to shut down the device again here. Normally, though, * fw_node_event will be responsible for shutting it down when * necessary. We have to use the atomic cmpxchg here to avoid * racing with the FW_NODE_DESTROYED case in * fw_node_event().
*/ if (atomic_cmpxchg(&device->state,
FW_DEVICE_INITIALIZING,
FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
device->workfn = fw_device_shutdown;
fw_schedule_device_work(device, SHUTDOWN_DELAY);
} else {
fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
dev_name(&device->device),
device->config_rom[3], device->config_rom[4],
1 << device->max_speed);
device->config_rom_retries = 0;
/* * Reschedule the IRM work if we just finished reading the * root node config rom. If this races with a bus reset we * just end up running the IRM work a couple of extra times - * pretty harmless.
*/ if (device->node == card->root_node)
fw_schedule_bm_work(card, 0);
return;
error_with_cdev:
xa_erase(&fw_device_xa, minor);
error:
fw_device_put(device); // fw_device_xa's reference.
/* Reread and compare bus info block and header of root directory */ staticint reread_config_rom(struct fw_device *device, int generation, bool *changed)
{
u32 q; int i, rcode;
for (i = 0; i < 6; i++) {
rcode = read_rom(device, generation, i, &q); if (rcode != RCODE_COMPLETE) return rcode;
if (i == 0 && q == 0) /* inaccessible (see read_config_rom); retry later */ return RCODE_BUSY;
/* * Something changed. We keep things simple and don't investigate * further. We just destroy all previous units and create new ones.
*/
device_for_each_child(&device->device, NULL, shutdown_unit);
ret = read_config_rom(device, device->generation); if (ret != RCODE_COMPLETE) goto failed_config_rom;
switch (event) { case FW_NODE_CREATED: /* * Attempt to scan the node, regardless whether its self ID has * the L (link active) flag set or not. Some broken devices * send L=0 but have an up-and-running link; others send L=1 * without actually having a link.
*/
create:
device = kzalloc(sizeof(*device), GFP_ATOMIC); if (device == NULL) break;
/* * Do minimal initialization of the device here, the * rest will happen in fw_device_init(). * * Attention: A lot of things, even fw_device_get(), * cannot be done before fw_device_init() finished! * You can basically just check device->state and * schedule work until then, but only while holding * card->lock.
*/
atomic_set(&device->state, FW_DEVICE_INITIALIZING);
device->card = fw_card_get(card);
device->node = fw_node_get(node);
device->node_id = node->node_id;
device->generation = card->generation;
device->is_local = node == card->local_node;
mutex_init(&device->client_list_mutex);
INIT_LIST_HEAD(&device->client_list);
/* * Set the node data to point back to this device so * FW_NODE_UPDATED callbacks can update the node_id * and generation for the device.
*/
node->data = device;
/* * Many devices are slow to respond after bus resets, * especially if they are bus powered and go through * power-up after getting plugged in. We schedule the * first config rom scan half a second after bus reset.
*/
device->workfn = fw_device_init;
INIT_DELAYED_WORK(&device->work, fw_device_workfn);
fw_schedule_device_work(device, INITIAL_DELAY); break;
case FW_NODE_INITIATED_RESET: case FW_NODE_LINK_ON:
device = node->data; if (device == NULL) goto create;
case FW_NODE_DESTROYED: case FW_NODE_LINK_OFF: if (!node->data) break;
/* * Destroy the device associated with the node. There * are two cases here: either the device is fully * initialized (FW_DEVICE_RUNNING) or we're in the * process of reading its config rom * (FW_DEVICE_INITIALIZING). If it is fully * initialized we can reuse device->work to schedule a * full fw_device_shutdown(). If not, there's work * scheduled to read it's config rom, and we just put * the device in shutdown state to have that code fail * to create the device.
*/
device = node->data; if (atomic_xchg(&device->state,
FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
device->workfn = fw_device_shutdown;
fw_schedule_device_work(device,
list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
} break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.