ACPI: Fix up _PLD methods
Subsystems (3)
PATCH 1/4 ACPI: Fix up _PLD methods
_PLD is defined as returning a package of buffers, but many implementations simply return a buffer. Fix this up.
(Original patch by Bob Moore <[email protected]>)
--- drivers/acpi/acpica/nsrepair.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/acpica/nsrepair.c +12 -3
@@ -151,9 +151,18 @@ acpi_ns_repair_object(struct acpi_predefined_data *data, } }if (expected_btypes &ACPI_RTYPE_PACKAGE ) { - status =acpi_ns_convert_to_package (return_object, &new_object); -if (ACPI_SUCCESS (status)) { - goto object_repaired; +if (return_object->common.type ==ACPI_TYPE_BUFFER ) { + status =acpi_ns_repair_package_list (data, &return_object); +if (ACPI_SUCCESS (status)) { + *return_object_ptr = return_object; + data->flags |=ACPI_OBJECT_REPAIRED ; +return (AE_OK ); + } + }else { + status =acpi_ns_convert_to_package (return_object, &new_object); +if (ACPI_SUCCESS (status)) { + goto object_repaired; + } } }
Signature · 1 line
1.7.9.3
PATCH 2/4 ACPI: Add _PLD support
Add a simple helper function to allow drivers to obtain the physical device location data.
--- drivers/acpi/utils.c | 29 +++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
drivers/acpi/utils.c +29 -0
@@ -382,3 +382,32 @@ acpi_evaluate_reference(acpi_handle handle, }EXPORT_SYMBOL (acpi_evaluate_reference); + +acpi_status +acpi_get_physical_device_location (acpi_handle handle,struct acpi_pld *pld) +{ +acpi_status status; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *output; + + status =acpi_evaluate_object (handle,"_PLD" ,NULL , &buffer); + +if (ACPI_FAILURE (status)) +return status; + + output = buffer.pointer; + +if (!output || output->type !=ACPI_TYPE_PACKAGE + || !output->package.count + || output->package.elements[0 ].type !=ACPI_TYPE_BUFFER + || output->package.elements[0 ].buffer.length >sizeof (*pld)) { + status =AE_TYPE ; + goto out; + } + +memcpy (pld, output->package.elements[0 ].buffer.pointer, + output->package.elements[0 ].buffer.length); +out: +kfree (buffer.pointer); +return status; +}
include/acpi/acpi_bus.h +31 -0
@@ -51,6 +51,37 @@ acpi_evaluate_reference(acpi_handle handle,struct acpi_object_list *arguments, struct acpi_handle_list *list); +struct acpi_pld { +unsigned int revision:7 ;/* 0 */ +unsigned int ignore_colour:1 ;/* 7 */ +unsigned int colour:24 ;/* 8 */ +unsigned int width:16 ;/* 32 */ +unsigned int height:16 ;/* 48 */ +unsigned int user_visible:1 ;/* 64 */ +unsigned int dock:1 ;/* 65 */ +unsigned int lid:1 ;/* 66 */ +unsigned int panel:3 ;/* 67 */ +unsigned int vertical_pos:2 ;/* 70 */ +unsigned int horizontal_pos:2 ;/* 72 */ +unsigned int shape:4 ;/* 74 */ +unsigned int group_orientation:1 ;/* 78 */ +unsigned int group_token:8 ;/* 79 */ +unsigned int group_position:8 ;/* 87 */ +unsigned int bay:1 ;/* 95 */ +unsigned int ejectable:1 ;/* 96 */ +unsigned int ospm_eject_required:1 ;/* 97 */ +unsigned int cabinet_number:8 ;/* 98 */ +unsigned int card_cage_number:8 ;/* 106 */ +unsigned int reference:1 ;/* 114 */ +unsigned int rotation:4 ;/* 115 */ +unsigned int order:5 ;/* 119 */ +unsigned int reserved:4 ;/* 124 */ +unsigned int vertical_offset:16 ;/* 128 */ +unsigned int horizontal_offset:16 ;/* 144 */ +}; + +acpi_status +acpi_get_physical_device_location (acpi_handle handle,struct acpi_pld *pld);#ifdef CONFIG_ACPI #include <linux/proc_fs.h>
Signature · 1 line
1.7.9.3
PATCH 3/4 usb: Bind devices to ACPI devices when possible
In reply to Matthew GarrettBuilt-in USB devices will typically have a representation in the system ACPI tables. Add support for binding the two together so the USB code can make use of the associated methods.
--- drivers/usb/core/Makefile | 1 + drivers/usb/core/usb-acpi.c | 53 +++++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 6 +++++ drivers/usb/core/usb.h | 7 ++++++ 4 files changed, 67 insertions(+) create mode 100644 drivers/usb/core/usb-acpi.c
drivers/usb/core/Makefile +1 -0
@@ -10,5 +10,6 @@ usbcore-y += devio.o notify.o generic.o quirks.o devices.o usbcore-$(CONFIG_PCI) += hcd-pci.o usbcore-$(CONFIG_USB_DEVICEFS) += inode.o +usbcore-$(CONFIG_ACPI) += usb-acpi.o obj-$(CONFIG_USB) += usbcore.o
drivers/usb/core/usb-acpi.c new file +53 -0
53 lines not on this page · raw message
drivers/usb/core/usb.c +6 -0
@@ -1015,6 +1015,9 @@ static int __init usb_init(void)if (retval) goto out; + retval =usb_acpi_register (); +if (retval) + goto acpi_register_failed; retval =bus_register (&usb_bus_type);if (retval) goto bus_register_failed;
@@ -1054,6 +1057,8 @@ major_init_failed: bus_notifier_failed:bus_unregister (&usb_bus_type); bus_register_failed: +usb_acpi_unregister (); +acpi_register_failed:usb_debugfs_cleanup (); out:return retval;
@@ -1076,6 +1081,7 @@ static void __exit usb_exit(void)usb_hub_cleanup ();bus_unregister_notifier (&usb_bus_type, &usb_bus_nb);bus_unregister (&usb_bus_type); +usb_acpi_unregister ();usb_debugfs_cleanup (); }
drivers/usb/core/usb.h +7 -0
@@ -155,3 +155,10 @@ 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); +#ifdef CONFIG_ACPI +extern int usb_acpi_register (void ); +extern void usb_acpi_unregister (void ); +#else +static inline int usb_acpi_register (void ) {return 0 ; }; +static inline void usb_acpi_unregister (void ) { }; +#endif
Signature · 1 line
1.7.9.3
Re: [PATCH 3/4] usb: Bind devices to ACPI devices when possible
Quoted 16 lines · Matthew Garrett
Built-in USB devices will typically have a representation in the system ACPI tables. Add support for binding the two together so the USB code can make use of the associated methods.
drivers/usb/core/usb-acpi.c new file +12
-0+static int usb_acpi_find_device (struct device *dev,acpi_handle *handle) +{ +struct usb_device *udev =to_usb_device (dev); +struct device *parent = dev->parent; +acpi_handle *parent_handle =DEVICE_ACPI_HANDLE (parent); + +if (!parent_handle) +return -ENODEV ; + + *handle =acpi_get_child (parent_handle, udev->portnum); + +if (!*handle)
drivers/usb/core/usb-acpi.c line 43
Quoted 10 lines
drivers/usb/core/usb-acpi.c new file +10
-0+return -ENODEV ; + +return 0 ; +} + +static struct acpi_bus_type usb_acpi_bus = { + .bus = &usb_bus_type, + .find_bridge =NULL , + .find_device = usb_acpi_find_device, +};
I don't understand exactly how this is supposed to work. Does this mean that the ACPI core will call usb_acpi_find_device() for every ACPI device whose underlying real device is registered on the usb_bus_type? If so, when does this call take place?
Or does it work some other way?
Bear in mind that USB devices aren't the only things registered with usb_bus_type. We also register device structures representing USB interfaces and endpoints. Hence the to_usb_device() call above might not always do what you want.
Alan Stern
A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.44L0.1203121631230.1216-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org
Re: [PATCH 3/4] usb: Bind devices to ACPI devices when possible
Quoted 25 lines · Alan Stern
Quoted 23 lines · Matthew Garrett
Built-in USB devices will typically have a representation in the system ACPI tables. Add support for binding the two together so the USB code can make use of the associated methods.
drivers/usb/core/usb-acpi.c new file +19
-0+static int usb_acpi_find_device (struct device *dev,acpi_handle *handle) +{ +struct usb_device *udev =to_usb_device (dev); +struct device *parent = dev->parent; +acpi_handle *parent_handle =DEVICE_ACPI_HANDLE (parent); + +if (!parent_handle) +return -ENODEV ; + + *handle =acpi_get_child (parent_handle, udev->portnum); + +if (!*handle) +return -ENODEV ; + +return 0 ; +} + +static struct acpi_bus_type usb_acpi_bus = { + .bus = &usb_bus_type,
Quoted 8 lines
drivers/usb/core/usb-acpi.c line 43
Quoted 3 lines
drivers/usb/core/usb-acpi.c new file +3
-0+ .find_bridge = NULL, + .find_device = usb_acpi_find_device, +};I don't understand exactly how this is supposed to work. Does this mean that the ACPI core will call
usb_acpi_find_device()for every ACPI device whose underlying real device is registered on theusb_bus_type? If so, when does this call take place?
Kind of? platform_notify gets called whenever a device is registered, and on ACPi systems that'll be acpi_platform_notify. It'll take the registered device and, if there are glue functions for that bus type, pass it to the callback functions. The idea is that we have two disparate device trees, the Linux one and the ACPI one. This just gives us an opportunity to glue some of the devices together.
Quoted 6 lines
Or does it work some other way?
Bear in mind that USB devices aren't the only things registered with
usb_bus_type. We also register device structures representing USB interfaces and endpoints. Hence theto_usb_device()call above might not always do what you want.
Ugh. Is there any clean way to distinguish from the device structure? If not, the easiest would seem to be to just add another bus type structure, even if the members are identical.
Signature · 5 lines
Matthew Garrett | [email protected] -- 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
Re: [PATCH 3/4] usb: Bind devices to ACPI devices when possible
Quoted 11 lines · Matthew Garrett
Quoted 10 lines
drivers/usb/core/usb-acpi.c line 43
Quoted 5 lines
drivers/usb/core/usb-acpi.c new file +5
-0+static struct acpi_bus_type usb_acpi_bus = { + .bus = &usb_bus_type, + .find_bridge =NULL , + .find_device = usb_acpi_find_device, +};I don't understand exactly how this is supposed to work. Does this mean that the ACPI core will call
usb_acpi_find_device()for every ACPI device whose underlying real device is registered on theusb_bus_type? If so, when does this call take place?
Quoted 6 lines
Kind of?
platform_notifygets called whenever a device is registered, and on ACPi systems that'll beacpi_platform_notify. It'll take the registered device and, if there are glue functions for that bus type, pass it to the callback functions. The idea is that we have two disparate device trees, the Linux one and the ACPI one. This just gives us an opportunity to glue some of the devices together.
Ah, okay.
Quoted 8 lines
Quoted 4 lines
Bear in mind that USB devices aren't the only things registered with
usb_bus_type. We also register device structures representing USB interfaces and endpoints. Hence theto_usb_device()call above might not always do what you want.Ugh. Is there any clean way to distinguish from the device structure? If not, the easiest would seem to be to just add another bus type structure, even if the members are identical.
Easy; just call is_usb_device() (defined in core/usb.h).
Alan Stern
A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.44L0.1203121702000.1216-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org
Re: [PATCH 3/4] usb: Bind devices to ACPI devices when possible
Quoted 6 lines · Alan Stern
Quoted 3 lines · Matthew Garrett
Ugh. Is there any clean way to distinguish from the device structure? If not, the easiest would seem to be to just add another bus type structure, even if the members are identical.
Easy; just call
is_usb_device()(defined incore/usb.h).
Ah, thanks - I'll add that and repost.
Signature · 5 lines
Matthew Garrett | [email protected] -- 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 4/4 usb: Set device removable state based on ACPI USB data
In reply to Matthew GarrettACPI offers two methods that allow us to infer whether or not a USB port is removable. The _PLD method gives us information on whether the port is "user visible" or not. If that's not present then we can fall back to the _UPC method which tells us whether or not a port is connectable.
--- drivers/usb/core/usb-acpi.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/usb/core/usb-acpi.c +56 -0
@@ -19,6 +19,53 @@#include "usb.h" +static int usb_acpi_check_upc (struct usb_device *udev,acpi_handle handle) +{ +acpi_status status; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *upc; +int ret =0 ; + + status =acpi_evaluate_object (handle,"_UPC" ,NULL , &buffer); + +if (ACPI_FAILURE (status)) +return -ENODEV ; + + upc = buffer.pointer; + +if (!upc || (upc->type !=ACPI_TYPE_PACKAGE ) || upc->package.count !=4 ) { + ret = -EINVAL ; + goto out; + } + +if (upc->package.elements[0 ].integer.value) + udev->removable =USB_DEVICE_REMOVABLE ; +else + udev->removable =USB_DEVICE_FIXED ; + +out: +kfree (upc); +return ret; +} + +static int usb_acpi_check_pld (struct usb_device *udev,acpi_handle handle) +{ +acpi_status status; +struct acpi_pld pld; + + status =acpi_get_physical_device_location (handle, &pld); + +if (ACPI_FAILURE (status)) +return -ENODEV ; + +if (pld.user_visible) + udev->removable =USB_DEVICE_REMOVABLE ; +else + udev->removable =USB_DEVICE_FIXED ; + +return 0 ; +} +static int usb_acpi_find_device (struct device *dev,acpi_handle *handle) {struct usb_device *udev =to_usb_device (dev);
@@ -33,6 +80,15 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)if (!*handle)return -ENODEV ; +/* +* PLD will tell us whether a port is removable to the user or +* not. If we don't get an answer from PLD (it's not present +* or it's malformed) then try to infer it from UPC. If a +* device isn't connectable then it's probably not removable. +*/ +if (usb_acpi_check_pld (udev, *handle) !=0 ) +usb_acpi_check_upc (udev, *handle); +return 0 ; }
Signature · 1 line
1.7.9.3
Quoted 9 lines · Matthew Garrett
_PLDis defined as returning a package of buffers, but many implementations simply return a buffer. Fix this up.(Original patch by Bob Moore <[email protected]>)
Signed-off-by Matthew Garrett <[email protected]>--- drivers/acpi/acpica/nsrepair.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
I think this series depends on your previous USB core patch, right? If so, I'd be glad to take all of these through the USB tree if I get an ack from Len for the acpi portions.
Otherwise, feel free to take them through the acpi tree, they look good to me:
Quoted 6 lines · Greg KH
Quoted 5 lines · Matthew Garrett
_PLDis defined as returning a package of buffers, but many implementations simply return a buffer. Fix this up.(Original patch by Bob Moore <[email protected]>)
Quoted 8 lines
Quoted 4 lines
Signed-off-by Matthew Garrett <[email protected]>--- drivers/acpi/acpica/nsrepair.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)I think this series depends on your previous USB core patch, right? If so, I'd be glad to take all of these through the USB tree if I get an ack from Len for the acpi portions.
They do, so probably best for you to take them as long as Len approves.
Signature · 1 line
Matthew Garrett | [email protected]