usb/acpi: To bind usb hub ports with acpi when not attached usb devices.
v2 cover usb/acpi: To bind usb hub ports with acpi when not attached usb devices.
Based on the Matthew Garrett's patch set.
[PATCH V2 1/4] ACPI: Fix up _PLD methods
[PATCH V2 2/4] ACPI: Add _PLD support
[PATCH V2 3/4] usb: Bind devices to ACPI devices when possible [PATCH V2 4/4] usb: Set device removable state based on ACPI USB data
Add usb hub ports' platform_data to store acpi_handle. When a usb hub is found, getting all ports' acpi handle and check port's connect type through acpi method "_UPC" and "_PLD". When a usb device is found, set it's removalbe depending on the port's connect type.
[PATCH V2 1/4] usb: add struct usb_hub_port to store port related [PATCH V2 2/4] usb: move struct usb_device->children to struct [PATCH V2 3/4] usb/acpi: add the support of usb hub ports' acpi [PATCH V2 4/4] usb/acpi: add usb check for the connect type of usb
drivers/staging/usbip/usbip_common.c | 2 +- drivers/usb/core/devices.c | 3 +- drivers/usb/core/hub.c | 145 ++++++++++++++++++++++++---------- drivers/usb/core/usb-acpi.c | 104 +++++++++++++++++-------- drivers/usb/core/usb.h | 10 +++ drivers/usb/host/r8a66597-hcd.c | 3 +- include/linux/usb.h | 11 ++- 7 files changed, 199 insertions(+), 79 deletions(-)
A message that is not in the archive (sent off-list or not yet received): 1333099617-11019-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v2 1/4 usb: add struct usb_hub_port to store port related members.
Add struct usb_hub_port pointer port_data in the struct usb_hub and allocate struct usb_hub_port perspectively for each ports to store private data.
--- drivers/usb/core/hub.c | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-)
drivers/usb/core/hub.c +16 -13
@@ -37,6 +37,10 @@#endif #endif +struct usb_hub_port { +void *port_owner; +}; +struct usb_hub {struct device *intfdev;/* the "interface" device */ struct usb_device *hdev;
@@ -79,7 +83,7 @@ struct usb_hub {u8 indicator[USB_MAXCHILDREN ];struct delayed_work leds;struct delayed_work init_work; -void **port_owners; +struct usb_hub_port *port_data; };static inline int hub_is_superspeed (struct usb_device *hdev)
@@ -1021,8 +1025,9 @@ static int hub_configure(struct usb_hub *hub,dev_info (hub_dev,"%d port%s detected\n" , hdev->maxchild, (hdev->maxchild ==1 ) ?"" :"s" ); - hub->port_owners =kzalloc (hdev->maxchild *sizeof (void *),GFP_KERNEL ); -if (!hub->port_owners) { + hub->port_data =kzalloc (hdev->maxchild *sizeof (struct usb_hub_port ), +GFP_KERNEL ); +if (!hub->port_data) { ret = -ENOMEM ; goto fail; }
@@ -1275,7 +1280,7 @@ static void hub_disconnect(struct usb_interface *intf) highspeed_hubs--;usb_free_urb (hub->urb); -kfree (hub->port_owners); +kfree (hub->port_data);kfree (hub->descriptor);kfree (hub->status);kfree (hub->buffer);
@@ -1413,7 +1418,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,/* This assumes that devices not managed by the hub driver * will always have maxchild equal to 0. */ - *ppowner = &(hdev_to_hub (hdev)->port_owners[port1 -1 ]); + *ppowner = &(hdev_to_hub (hdev)->port_data[port1 -1 ].port_owner);return 0 ; }
@@ -1448,16 +1453,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)void usb_hub_release_all_ports (struct usb_device *hdev,void *owner) { +struct usb_hub *hub =hdev_to_hub (hdev);int n; -void **powner; - n =find_port_owner (hdev,1 , &powner); -if (n ==0 ) { -for (; n < hdev->maxchild; (++n, ++powner)) { -if (*powner == owner) - *powner =NULL ; - } +for (n =0 ; n < hdev->maxchild; n++) { +if (hub->port_data[n].port_owner == owner) + hub->port_data[n].port_owner =NULL ; } + }/* The caller must hold udev's lock */
@@ -1468,7 +1471,7 @@ bool usb_device_is_owned(struct usb_device *udev)if (udev->state ==USB_STATE_NOTATTACHED || !udev->parent)return false; hub =hdev_to_hub (udev->parent); -return !!hub->port_owners[udev->portnum -1 ]; +return !!hub->port_data[udev->portnum -1 ].port_owner; }
Signature · 6 lines
1.7.6.rc2.8.g28eb -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/4 usb/acpi: add the support of usb hub ports' acpi binding without attached devices.
In reply to a message not in the archiveThe usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch adds the member platform_data in the struct usb_hub_port and gets the hub port's acpi_handle and store it in the port's platform_data to resolve no attached device no binding problem. The acpi method "_UPC" and "_PLD" can be accessed without attached device.
--- drivers/usb/core/hub.c | 20 ++++++++++++++++++++ drivers/usb/core/usb-acpi.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/usb/core/usb.h | 6 ++++++ 3 files changed, 62 insertions(+), 1 deletions(-)
drivers/usb/core/hub.c +20 -0
@@ -40,6 +40,7 @@struct usb_hub_port {void *port_owner;struct usb_device *child; +unsigned long platform_data; };struct usb_hub {
@@ -1237,6 +1238,7 @@ static int hub_configure(struct usb_hub *hub,if (hub->has_indicators && blinkenlights) hub->indicator [0 ] =INDICATOR_CYCLE ; +usb_acpi_bind_hub_ports (hdev);hub_activate (hub,HUB_INIT );return 0 ;
@@ -4168,3 +4170,21 @@ struct usb_device *usb_get_hub_child_device(struct usb_device *hdev, }EXPORT_SYMBOL_GPL (usb_get_hub_child_device); +void usb_set_hub_port_platform_data (struct usb_device *hdev,int port1, +unsigned long data) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (!hub || port1 > hdev->maxchild || port1 <1 ) +return ; + hub->port_data[port1 -1 ].platform_data = data; +} + +unsigned long usb_get_hub_port_platform_data (struct usb_device *hdev,int port1) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (!hub || port1 > hdev->maxchild || port1 <1 ) +return 0 ; +return hub->port_data[port1 -1 ].platform_data; +}
drivers/usb/core/usb-acpi.c +36 -1
@@ -82,7 +82,16 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)if (!parent_handle)return -ENODEV ; - *handle =acpi_get_child (parent_handle, udev->portnum); +/** +* The root hub's acpi handle is got from acpi method. +* Other device's acpi handle can be got from the usb hub +* port's platform_data. +*/ +if (!udev->parent) + *handle =acpi_get_child (parent_handle, udev->portnum); +else + *handle = (acpi_handle )usb_get_hub_port_platform_data ( + udev->parent, udev->portnum);if (!*handle)return -ENODEV ;
@@ -105,6 +114,32 @@ static struct acpi_bus_type usb_acpi_bus = { .find_device = usb_acpi_find_device, }; +int usb_acpi_bind_hub_ports (struct usb_device *hdev) +{ +acpi_handle hub_handle =NULL ; +acpi_handle port_handle =NULL ; +struct device *dev = &hdev->dev; +int i; + + hub_handle =DEVICE_ACPI_HANDLE (dev); +if (!hub_handle) +return -ENODEV ; + +/** +* The usb hub port is not a device in the usb subsystem but it is a device +* in the acpi table. Store its acpi handle in the platform data of usb +* hub port. +*/ +for (i =1 ; i <= hdev->maxchild; i++) { + port_handle =acpi_get_child (hub_handle, i); +if (!port_handle) +continue ; +usb_set_hub_port_platform_data (hdev, i, + (unsigned long )port_handle); + } +return 0 ; +} +int usb_acpi_register (void ) {return register_acpi_bus_type (&usb_acpi_bus);
drivers/usb/core/usb.h +6 -0
@@ -154,11 +154,17 @@ extern void usb_notify_add_device(struct usb_device *udev);extern void usb_notify_remove_device (struct usb_device *udev);extern void usb_notify_add_bus (struct usb_bus *ubus);extern void usb_notify_remove_bus (struct usb_bus *ubus); +extern unsigned long usb_get_hub_port_platform_data (struct usb_device *hdev, +int port1); +extern void usb_set_hub_port_platform_data (struct usb_device *hdev, +int port1,unsigned long data);#ifdef CONFIG_ACPI extern int usb_acpi_register (void );extern void usb_acpi_unregister (void ); +extern int usb_acpi_bind_hub_ports (struct usb_device *hdev);#else static inline int usb_acpi_register (void ) {return 0 ; };static inline void usb_acpi_unregister (void ) { }; +static inline int usb_acpi_bind_hub_ports (struct usb_device *dev) {return 0 ; };#endif
Signature · 6 lines
1.7.6.rc2.8.g28eb -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 2/4 usb: move struct usb_device->children to struct usb_hub_port->child
In reply to Lan TianyuMove child's pointer to the struct usb_hub_port since the child device is directly associated with the port. Provide usb_get_hub_child_device() to get child's pointer.
--- drivers/staging/usbip/usbip_common.c | 2 +- drivers/usb/core/devices.c | 3 +- drivers/usb/core/hub.c | 75 +++++++++++++++++++++------------- drivers/usb/host/r8a66597-hcd.c | 3 +- include/linux/usb.h | 4 +- 5 files changed, 54 insertions(+), 33 deletions(-)
drivers/staging/usbip/usbip_common.c +1 -1
@@ -158,7 +158,7 @@ static void usbip_dump_usb_device(struct usb_device *udev) udev->have_langid, udev->string_langid);dev_dbg (dev,"maxchild %d, children %p\n" , - udev->maxchild, udev->children); + udev->maxchild,usb_get_hub_child_device (udev, udev->devnum)); }static void usbip_dump_request_type (__u8 rt)
drivers/usb/core/devices.c +2 -1
@@ -590,7 +590,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,/* Now look at all of this device's children. */ for (chix =0 ; chix < usbdev->maxchild; chix++) { -struct usb_device *childdev = usbdev->children[chix]; +struct usb_device *childdev = +usb_get_hub_child_device (usbdev, chix +1 );if (childdev) {usb_lock_device (childdev);
drivers/usb/core/hub.c +47 -28
208 lines not on this page · raw message
drivers/usb/host/r8a66597-hcd.c +2 -1
@@ -2040,7 +2040,8 @@ static void collect_usb_address_map(struct usb_device *udev, unsigned long *map) map[udev->devnum/32 ] |= (1 << (udev->devnum %32 ));for (chix =0 ; chix < udev->maxchild; chix++) { -struct usb_device *childdev = udev->children[chix]; +struct usb_device *childdev = +usb_get_hub_child_device (udev, chix +1 );if (childdev)collect_usb_address_map (childdev, map);
include/linux/usb.h +2 -2
@@ -428,7 +428,6 @@ enum usb_device_removable {* access from userspace * @usbfs_dentry: usbfs dentry entry for the device * @maxchild: number of ports if hub -* @children: child devices - USB devices that are attached to this hub * @quirks: quirks of the whole device * @urbnum: number of URBs submitted for the whole device * @active_duration: total time device is not suspended
@@ -501,7 +500,6 @@ struct usb_device {#endif int maxchild; -struct usb_device *children[USB_MAXCHILDREN ];u32 quirks;atomic_t urbnum;
@@ -527,6 +525,8 @@ static inline struct usb_device *interface_to_usbdev(struct usb_interface *intf)extern struct usb_device *usb_get_dev (struct usb_device *dev);extern void usb_put_dev (struct usb_device *dev); +extern struct usb_device *usb_get_hub_child_device (struct usb_device *hdev, +int port1);/* USB device locking */ #define usb_lock_device (udev) device_lock(&(udev)->dev)
Signature · 1 line
1.7.6.rc2.8.g28eb
Re: [PATCH V2 2/4] usb: move struct usb_device->children to struct usb_hub_port->child
drivers/staging/usbip/usbip_common.c static void usbip_dump_usb_device(struct usb_device *udev) · line 161
Quoted 12 lines · Lan Tianyu
Move child's pointer to the struct
usb_hub_portsince the child device is directly associated with the port. Provideusb_get_hub_child_device()to get child's pointer.drivers/staging/usbip/usbip_common.c +1
-1@@ -158,7 +158,7 @@ static void usbip_dump_usb_device(struct usb_device *udev) udev->have_langid, udev->string_langid);dev_dbg (dev,"maxchild %d, children %p\n" , - udev->maxchild, udev->children); + udev->maxchild,usb_get_hub_child_device (udev, udev->devnum));
This changes the meaning of the statement; it will print the address of the first child rather than the address of the array of children. You might as well get rid of the whole "children %p" part.
Quoted 5 lines
drivers/usb/core/hub.c +0
-0@@ -1477,12 +1479,15 @@ bool usb_device_is_owned(struct usb_device *udev)
drivers/usb/core/hub.c bool usb_device_is_owned(struct usb_device *udev) · line 1485
Quoted 10 lines
drivers/usb/core/hub.c +2
-4static void recursively_mark_NOTATTACHED (struct usb_device *udev) { +struct usb_hub *hub =hdev_to_hub (udev);int i; -for (i =0 ; i < udev->maxchild; ++i) { -if (udev->children[i]) -recursively_mark_NOTATTACHED (udev->children[i]); - } +if (hub)
You don't need this test. If hub is NULL then udev->maxchild will be 0, so the following loop will be skipped.
Quoted 10 lines
drivers/usb/core/hub.c +5
-0+for (i =0 ; i < udev->maxchild; ++i) { +if (hub->port_data[i].child) +recursively_mark_NOTATTACHED ( + hub->port_data[i].child); + }if (udev->state ==USB_STATE_SUSPENDED ) udev->active_duration -= jiffies; udev->state =USB_STATE_NOTATTACHED ;
drivers/usb/core/hub.c void usb_disconnect(struct usb_device **pdev) · line 1668
Quoted 8 lines
drivers/usb/core/hub.c +1
-4@@ -1659,10 +1665,11 @@ void usb_disconnect(struct usb_device **pdev)usb_lock_device (udev);/* Free up all the children before we remove this device */ -for (i =0 ; i <USB_MAXCHILDREN ; i++) { -if (udev->children[i]) -usb_disconnect (&udev->children[i]); - } +if (hub)
The same is true here.
drivers/usb/core/hub.c void usb_disconnect(struct usb_device **pdev) · line 1672
Quoted 4 lines
drivers/usb/core/hub.c +4
-0+for (i =0 ; i < udev->maxchild; i++) { +if (hub->port_data[i].child) +usb_disconnect (&hub->port_data[i].child); + }
Alan Stern
PATCH v2 4/4 usb/acpi: add usb check for the connect type of usb port
In reply to Lan TianyuCheck the connect type of usb port when getting the usb port's acpi_handle and store result into connect_type in the struct usb_hub_port.
Accoding to ACPI Spec 9.13. PLD indicates whether usb port is user visible and _UPC indicates whether it is connectable. If the port was visible and connectable, it could be freely connected and disconnected with USB devices. If no visible and connectable, a usb device is directly hard-wired to the port. If no visible and no connectable, the port would be not used.
When a device was found on the port, if the connect_type was hot-plug, then the device would be removable. If the connect_type was hard-wired, the device would be non-removable.
--- drivers/usb/core/hub.c | 21 +++++++++++++ drivers/usb/core/usb-acpi.c | 67 ++++++++++++++++++++++-------------------- drivers/usb/core/usb.h | 4 ++ include/linux/usb.h | 7 ++++ 4 files changed, 67 insertions(+), 32 deletions(-)
drivers/usb/core/hub.c +21 -0
@@ -41,6 +41,7 @@ struct usb_hub_port {void *port_owner;struct usb_device *child;unsigned long platform_data; +enum usb_port_connect_type connect_type; };struct usb_hub {
@@ -4188,3 +4189,23 @@ unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev, int port1)return 0 ;return hub->port_data[port1 -1 ].platform_data; } + +void usb_set_hub_port_connect_type (struct usb_device *hdev,int port1, +enum usb_port_connect_type type) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (!hub || port1 > hdev->maxchild || port1 <1 ) +return ; + hub->port_data[port1 -1 ].connect_type = type; +} + +enum usb_port_connect_type +usb_get_hub_port_connect_type (struct usb_device *hdev,int port1) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (!hub || port1 > hdev->maxchild || port1 <1 ) +return USB_PORT_CONNECT_TYPE_UNKNOWN ; +return hub->port_data[port1 -1 ].connect_type; +}
drivers/usb/core/usb-acpi.c +35 -32
113 lines not on this page · raw message
drivers/usb/core/usb.h +4 -0
@@ -158,6 +158,10 @@ extern unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev, int port1);extern void usb_set_hub_port_platform_data (struct usb_device *hdev,int port1,unsigned long data); +extern enum usb_port_connect_type +usb_get_hub_port_connect_type (struct usb_device *hdev,int port1); +extern void usb_set_hub_port_connect_type (struct usb_device *hdev,int port1, +enum usb_port_connect_type type);#ifdef CONFIG_ACPI extern int usb_acpi_register (void );
include/linux/usb.h +7 -0
@@ -382,6 +382,13 @@ enum usb_device_removable { USB_DEVICE_FIXED, }; +enum usb_port_connect_type { +USB_PORT_CONNECT_TYPE_UNKNOWN =0 , +USB_PORT_CONNECT_TYPE_HOT_PLUG , +USB_PORT_CONNECT_TYPE_HARD_WIRED , +USB_PORT_NOT_USED , +}; +/** * struct usb_device - kernel's representation of a USB device * @devnum: device number; address on a USB bus
Signature · 1 line
1.7.6.rc2.8.g28eb