Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

greybus: manifest: Use interface descriptor instead of module descriptor to get information

A module can have more than one interfaces and we get hotplug events or
manifests for interfaces, not modules. Details like version, vendor,
product id, etc. can be different for different interfaces within the
same module and so shall be fetched from interface descriptor instead of
module descriptor.

So what we have been doing for module descriptors until now must be done
for interface descriptors. There can only be one interface descriptor in
the manifest. Module descriptor isn't used anymore and probably most of
its fields can be removed now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>

authored by

Viresh Kumar and committed by
Greg Kroah-Hartman
a93db2d1 bb97ea81

+35 -37
+9 -12
drivers/staging/greybus/greybus_manifest.h
··· 1 1 /* 2 - * Greybus module manifest definition 2 + * Greybus manifest definition 3 3 * 4 4 * See "Greybus Application Protocol" document (version 0.1) for 5 5 * details on these values and structures. ··· 94 94 }; 95 95 96 96 /* 97 - * An interface descriptor simply defines a module-unique id for 98 - * each interface present on a module. Its sole purpose is to allow 99 - * CPort descriptors to specify which interface they are associated 100 - * with. Normally there's only one interface, with id 0. The 101 - * second one must have id 1, and so on consecutively. 102 - * 103 - * The largest CPort id associated with an interface (defined by a 104 - * CPort descriptor in the manifest) is used to determine how to 105 - * encode the device id and module number in UniPro packets 106 - * that use the interface. 97 + * An interface descriptor describes information about an interface as a whole, 98 + * *not* the functions within it. 107 99 */ 108 100 struct greybus_descriptor_interface { 109 - __u8 id; /* module-relative id (0..) */ 101 + __le16 vendor; 102 + __le16 product; 103 + __le16 version; // TODO - remove after Dec demo. 104 + __u8 vendor_stringid; 105 + __u8 product_stringid; 106 + __le64 unique_id; 110 107 }; 111 108 112 109 /*
+1 -1
drivers/staging/greybus/interface.c
··· 197 197 /** 198 198 * gb_add_interface 199 199 * 200 - * Pass in a buffer that _should_ contain a Greybus module manifest 200 + * Pass in a buffer that _should_ contain a Greybus manifest 201 201 * and register a greybus device structure with the kernel core. 202 202 */ 203 203 void gb_add_interface(struct greybus_host_device *hd, u8 interface_id, u8 *data,
+1 -1
drivers/staging/greybus/interface.h
··· 19 19 struct list_head manifest_descs; 20 20 u8 interface_id; /* Physical location within the Endo */ 21 21 22 - /* Information taken from the manifest module descriptor */ 22 + /* Information taken from the manifest descriptor */ 23 23 u16 vendor; 24 24 u16 product; 25 25 char *vendor_string;
+23 -22
drivers/staging/greybus/manifest.c
··· 1 1 /* 2 - * Greybus module manifest parsing 2 + * Greybus manifest parsing 3 3 * 4 4 * Copyright 2014-2015 Google Inc. 5 5 * Copyright 2014-2015 Linaro Ltd. ··· 40 40 * We scan the manifest once to identify where all the descriptors 41 41 * are. The result is a list of these manifest_desc structures. We 42 42 * then pick through them for what we're looking for (starting with 43 - * the module descriptor). As each is processed we remove it from 43 + * the interface descriptor). As each is processed we remove it from 44 44 * the list. When we're done the list should (probably) be empty. 45 45 */ 46 46 struct manifest_desc { ··· 107 107 expected_size += desc->string.length; 108 108 break; 109 109 case GREYBUS_TYPE_INTERFACE: 110 + expected_size += sizeof(struct greybus_descriptor_interface); 110 111 break; 111 112 case GREYBUS_TYPE_BUNDLE: 112 113 expected_size += sizeof(struct greybus_descriptor_bundle); ··· 283 282 return count; 284 283 } 285 284 286 - static bool gb_manifest_parse_module(struct gb_interface *intf, 287 - struct manifest_desc *module_desc) 285 + static bool gb_manifest_parse_interface(struct gb_interface *intf, 286 + struct manifest_desc *interface_desc) 288 287 { 289 - struct greybus_descriptor_module *desc_module = module_desc->data; 288 + struct greybus_descriptor_interface *desc_intf = interface_desc->data; 290 289 291 290 /* Handle the strings first--they can fail */ 292 - intf->vendor_string = gb_string_get(intf, desc_module->vendor_stringid); 291 + intf->vendor_string = gb_string_get(intf, desc_intf->vendor_stringid); 293 292 if (IS_ERR(intf->vendor_string)) 294 293 return false; 295 294 296 295 intf->product_string = gb_string_get(intf, 297 - desc_module->product_stringid); 296 + desc_intf->product_stringid); 298 297 if (IS_ERR(intf->product_string)) { 299 298 goto out_free_vendor_string; 300 299 } 301 300 302 - intf->vendor = le16_to_cpu(desc_module->vendor); 303 - intf->product = le16_to_cpu(desc_module->product); 304 - intf->unique_id = le64_to_cpu(desc_module->unique_id); 301 + intf->vendor = le16_to_cpu(desc_intf->vendor); 302 + intf->product = le16_to_cpu(desc_intf->product); 303 + intf->unique_id = le64_to_cpu(desc_intf->unique_id); 305 304 306 - /* Release the module descriptor, now that we're done with it */ 307 - release_manifest_descriptor(module_desc); 305 + /* Release the interface descriptor, now that we're done with it */ 306 + release_manifest_descriptor(interface_desc); 308 307 309 308 /* An interface must have at least one bundle descriptor */ 310 309 if (!gb_manifest_parse_bundles(intf)) { ··· 324 323 } 325 324 326 325 /* 327 - * Parse a buffer containing a module manifest. 326 + * Parse a buffer containing a Interface manifest. 328 327 * 329 328 * If we find anything wrong with the content/format of the buffer 330 329 * we reject it. ··· 336 335 * the descriptors it contains, keeping track for each its type 337 336 * and the location size of its data in the buffer. 338 337 * 339 - * Next we scan the descriptors, looking for a module descriptor; 338 + * Next we scan the descriptors, looking for a interface descriptor; 340 339 * there must be exactly one of those. When found, we record the 341 340 * information it contains, and then remove that descriptor (and any 342 341 * string descriptors it refers to) from further consideration. ··· 352 351 struct greybus_manifest_header *header; 353 352 struct greybus_descriptor *desc; 354 353 struct manifest_desc *descriptor; 355 - struct manifest_desc *module_desc = NULL; 354 + struct manifest_desc *interface_desc = NULL; 356 355 u16 manifest_size; 357 356 u32 found = 0; 358 357 bool result; ··· 400 399 size -= desc_size; 401 400 } 402 401 403 - /* There must be a single module descriptor */ 402 + /* There must be a single interface descriptor */ 404 403 list_for_each_entry(descriptor, &intf->manifest_descs, links) { 405 - if (descriptor->type == GREYBUS_TYPE_MODULE) 404 + if (descriptor->type == GREYBUS_TYPE_INTERFACE) 406 405 if (!found++) 407 - module_desc = descriptor; 406 + interface_desc = descriptor; 408 407 } 409 408 if (found != 1) { 410 - pr_err("manifest must have 1 module descriptor (%u found)\n", 409 + pr_err("manifest must have 1 interface descriptor (%u found)\n", 411 410 found); 412 411 result = false; 413 412 goto out; 414 413 } 415 414 416 - /* Parse the module manifest, starting with the module descriptor */ 417 - result = gb_manifest_parse_module(intf, module_desc); 415 + /* Parse the manifest, starting with the interface descriptor */ 416 + result = gb_manifest_parse_interface(intf, interface_desc); 418 417 419 418 /* 420 419 * We really should have no remaining descriptors, but we 421 420 * don't know what newer format manifests might leave. 422 421 */ 423 422 if (result && !list_empty(&intf->manifest_descs)) 424 - pr_info("excess descriptors in module manifest\n"); 423 + pr_info("excess descriptors in interface manifest\n"); 425 424 out: 426 425 release_manifest_descriptors(intf); 427 426
+1 -1
drivers/staging/greybus/manifest.h
··· 1 1 /* 2 - * Greybus module manifest parsing 2 + * Greybus manifest parsing 3 3 * 4 4 * Copyright 2014 Google Inc. 5 5 * Copyright 2014 Linaro Ltd.