PCI/ACPI: add a helper for retrieving _OSC Control DWORDs
authorVishal Verma <vishal.l.verma@intel.com>
Wed, 13 Apr 2022 07:36:16 +0000 (01:36 -0600)
committerDan Williams <dan.j.williams@intel.com>
Thu, 28 Apr 2022 21:01:54 +0000 (14:01 -0700)
During _OSC negotiation, when the 'Control' DWORD is needed from the
result buffer after running _OSC, a couple of places performed manual
pointer arithmetic to offset into the right spot in the raw buffer.
Add a acpi_osc_ctx_get_pci_control() helper to use the #define'd
DWORD offsets to fetch the DWORDs needed from @acpi_osc_context, and
replace the above instances of the open-coded arithmetic.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed by: Adam Manzanares <a.manzanares@samsung.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20220413073618.291335-2-vishal.l.verma@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/acpi/bus.c
drivers/acpi/pci_root.c
include/linux/acpi.h

index 3e58b613a2c41b599586cd00ac6b6322e59d9290..7658acbbb2bdd284ea61d49abce1274eee39aa23 100644 (file)
@@ -425,7 +425,7 @@ static void acpi_bus_osc_negotiate_usb_control(void)
        }
 
        osc_sb_native_usb4_control =
-               control & ((u32 *)context.ret.pointer)[OSC_CONTROL_DWORD];
+               control &  acpi_osc_ctx_get_pci_control(&context);
 
        acpi_bus_decode_usb_osc("USB4 _OSC: OS supports", control);
        acpi_bus_decode_usb_osc("USB4 _OSC: OS controls",
index 6f9e75d148084b48ba2db9de38dd3209dd274f42..57be89cb3966d51f26c0376ff827979575f7e16a 100644 (file)
@@ -183,7 +183,7 @@ static acpi_status acpi_pci_run_osc(acpi_handle handle,
 
        status = acpi_run_osc(handle, &context);
        if (ACPI_SUCCESS(status)) {
-               *retval = *((u32 *)(context.ret.pointer + 8));
+               *retval = acpi_osc_ctx_get_pci_control(&context);
                kfree(context.ret.pointer);
        }
        return status;
index d7136d13aa442cc6880801af4db19e2d5181d2b7..04e5a038dd57fdb9035a90b5594801b0444945b9 100644 (file)
@@ -608,6 +608,13 @@ extern u32 osc_sb_native_usb4_control;
 #define OSC_PCI_EXPRESS_LTR_CONTROL            0x00000020
 #define OSC_PCI_EXPRESS_DPC_CONTROL            0x00000080
 
+static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
+{
+       u32 *ret = context->ret.pointer;
+
+       return ret[OSC_CONTROL_DWORD];
+}
+
 #define ACPI_GSB_ACCESS_ATTRIB_QUICK           0x00000002
 #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV         0x00000004
 #define ACPI_GSB_ACCESS_ATTRIB_BYTE            0x00000006
@@ -1004,6 +1011,12 @@ static inline int acpi_register_wakeup_handler(int wake_irq,
 static inline void acpi_unregister_wakeup_handler(
        bool (*wakeup)(void *context), void *context) { }
 
+struct acpi_osc_context;
+static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
+{
+       return 0;
+}
+
 #endif /* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC