Merge branches 'acpi-pm', 'acpi-soc', 'acpi-tables' and 'acpi-resource'
[platform/kernel/linux-starfive.git] / drivers / acpi / bus.c
index 906ad81..4ea6062 100644 (file)
@@ -298,7 +298,7 @@ EXPORT_SYMBOL_GPL(osc_cpc_flexible_adr_space_confirmed);
 bool osc_sb_native_usb4_support_confirmed;
 EXPORT_SYMBOL_GPL(osc_sb_native_usb4_support_confirmed);
 
-bool osc_sb_cppc_not_supported;
+bool osc_sb_cppc2_support_acked;
 
 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
 static void acpi_bus_osc_negotiate_platform_control(void)
@@ -358,11 +358,6 @@ static void acpi_bus_osc_negotiate_platform_control(void)
                return;
        }
 
-#ifdef CONFIG_ACPI_CPPC_LIB
-       osc_sb_cppc_not_supported = !(capbuf_ret[OSC_SUPPORT_DWORD] &
-                       (OSC_SB_CPC_SUPPORT | OSC_SB_CPCV2_SUPPORT));
-#endif
-
        /*
         * Now run _OSC again with query flag clear and with the caps
         * supported by both the OS and the platform.
@@ -376,6 +371,10 @@ static void acpi_bus_osc_negotiate_platform_control(void)
 
        capbuf_ret = context.ret.pointer;
        if (context.ret.length > OSC_SUPPORT_DWORD) {
+#ifdef CONFIG_ACPI_CPPC_LIB
+               osc_sb_cppc2_support_acked = capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_CPCV2_SUPPORT;
+#endif
+
                osc_sb_apei_support_acked =
                        capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
                osc_pc_lpi_support_confirmed =
@@ -465,7 +464,6 @@ out_free:
 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
 {
        struct acpi_device *adev;
-       struct acpi_driver *driver;
        u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
        bool hotplug_event = false;
 
@@ -517,10 +515,13 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
        if (!adev)
                goto err;
 
-       driver = adev->driver;
-       if (driver && driver->ops.notify &&
-           (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
-               driver->ops.notify(adev, type);
+       if (adev->dev.driver) {
+               struct acpi_driver *driver = to_acpi_driver(adev->dev.driver);
+
+               if (driver && driver->ops.notify &&
+                   (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
+                       driver->ops.notify(adev, type);
+       }
 
        if (!hotplug_event) {
                acpi_bus_put_acpi_device(adev);
@@ -539,8 +540,9 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
 static void acpi_notify_device(acpi_handle handle, u32 event, void *data)
 {
        struct acpi_device *device = data;
+       struct acpi_driver *acpi_drv = to_acpi_driver(device->dev.driver);
 
-       device->driver->ops.notify(device, event);
+       acpi_drv->ops.notify(device, event);
 }
 
 static void acpi_notify_device_fixed(void *data)
@@ -1033,8 +1035,6 @@ static int acpi_device_probe(struct device *dev)
        if (ret)
                return ret;
 
-       acpi_dev->driver = acpi_drv;
-
        pr_debug("Driver [%s] successfully bound to device [%s]\n",
                 acpi_drv->name, acpi_dev->pnp.bus_id);
 
@@ -1044,7 +1044,6 @@ static int acpi_device_probe(struct device *dev)
                        if (acpi_drv->ops.remove)
                                acpi_drv->ops.remove(acpi_dev);
 
-                       acpi_dev->driver = NULL;
                        acpi_dev->driver_data = NULL;
                        return ret;
                }
@@ -1060,15 +1059,14 @@ static int acpi_device_probe(struct device *dev)
 static void acpi_device_remove(struct device *dev)
 {
        struct acpi_device *acpi_dev = to_acpi_device(dev);
-       struct acpi_driver *acpi_drv = acpi_dev->driver;
+       struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
+
+       if (acpi_drv->ops.notify)
+               acpi_device_remove_notify_handler(acpi_dev);
+
+       if (acpi_drv->ops.remove)
+               acpi_drv->ops.remove(acpi_dev);
 
-       if (acpi_drv) {
-               if (acpi_drv->ops.notify)
-                       acpi_device_remove_notify_handler(acpi_dev);
-               if (acpi_drv->ops.remove)
-                       acpi_drv->ops.remove(acpi_dev);
-       }
-       acpi_dev->driver = NULL;
        acpi_dev->driver_data = NULL;
 
        put_device(dev);
@@ -1102,6 +1100,7 @@ static int acpi_dev_for_one_check(struct device *dev, void *context)
 
        return adwc->fn(to_acpi_device(dev), adwc->data);
 }
+EXPORT_SYMBOL_GPL(acpi_dev_for_each_child);
 
 int acpi_dev_for_each_child(struct acpi_device *adev,
                            int (*fn)(struct acpi_device *, void *), void *data)
@@ -1114,6 +1113,18 @@ int acpi_dev_for_each_child(struct acpi_device *adev,
        return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check);
 }
 
+int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
+                                   int (*fn)(struct acpi_device *, void *),
+                                   void *data)
+{
+       struct acpi_dev_walk_context adwc = {
+               .fn = fn,
+               .data = data,
+       };
+
+       return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check);
+}
+
 /* --------------------------------------------------------------------------
                              Initialization/Cleanup
    -------------------------------------------------------------------------- */