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

Merge remote-tracking branch 'linux-pm/acpi-scan' into review-hans

+154 -79
+1 -1
drivers/acpi/ec.c
··· 1627 1627 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); 1628 1628 1629 1629 /* Reprobe devices depending on the EC */ 1630 - acpi_walk_dep_device_list(ec->handle); 1630 + acpi_dev_clear_dependencies(device); 1631 1631 1632 1632 acpi_handle_debug(ec->handle, "enumerated.\n"); 1633 1633 return 0;
+1 -1
drivers/acpi/pmic/intel_pmic_chtdc_ti.c
··· 117 117 return err; 118 118 119 119 /* Re-enumerate devices depending on PMIC */ 120 - acpi_walk_dep_device_list(ACPI_HANDLE(pdev->dev.parent)); 120 + acpi_dev_clear_dependencies(ACPI_COMPANION(pdev->dev.parent)); 121 121 return 0; 122 122 } 123 123
+114 -50
drivers/acpi/scan.c
··· 47 47 */ 48 48 static u64 spcr_uart_addr; 49 49 50 - struct acpi_dep_data { 51 - struct list_head node; 52 - acpi_handle supplier; 53 - acpi_handle consumer; 54 - }; 55 - 56 50 void acpi_scan_lock_acquire(void) 57 51 { 58 52 mutex_lock(&acpi_scan_lock); ··· 1665 1671 device_initialize(&device->dev); 1666 1672 dev_set_uevent_suppress(&device->dev, true); 1667 1673 acpi_init_coherency(device); 1668 - /* Assume there are unmet deps to start with. */ 1669 - device->dep_unmet = 1; 1674 + } 1675 + 1676 + static void acpi_scan_dep_init(struct acpi_device *adev) 1677 + { 1678 + struct acpi_dep_data *dep; 1679 + 1680 + mutex_lock(&acpi_dep_list_lock); 1681 + 1682 + list_for_each_entry(dep, &acpi_dep_list, node) { 1683 + if (dep->consumer == adev->handle) 1684 + adev->dep_unmet++; 1685 + } 1686 + 1687 + mutex_unlock(&acpi_dep_list_lock); 1670 1688 } 1671 1689 1672 1690 void acpi_device_add_finalize(struct acpi_device *device) ··· 1694 1688 } 1695 1689 1696 1690 static int acpi_add_single_object(struct acpi_device **child, 1697 - acpi_handle handle, int type) 1691 + acpi_handle handle, int type, bool dep_init) 1698 1692 { 1699 1693 struct acpi_device *device; 1700 1694 int result; ··· 1709 1703 * acpi_bus_get_status() and use its quirk handling. Note that 1710 1704 * this must be done before the get power-/wakeup_dev-flags calls. 1711 1705 */ 1712 - if (type == ACPI_BUS_TYPE_DEVICE || type == ACPI_BUS_TYPE_PROCESSOR) 1706 + if (type == ACPI_BUS_TYPE_DEVICE || type == ACPI_BUS_TYPE_PROCESSOR) { 1707 + if (dep_init) 1708 + acpi_scan_dep_init(device); 1709 + 1713 1710 acpi_scan_init_status(device); 1711 + } 1714 1712 1715 1713 acpi_bus_get_power_flags(device); 1716 1714 acpi_bus_get_wakeup_device_flags(device); ··· 1896 1886 return count; 1897 1887 } 1898 1888 1899 - static void acpi_scan_dep_init(struct acpi_device *adev) 1900 - { 1901 - struct acpi_dep_data *dep; 1902 - 1903 - adev->dep_unmet = 0; 1904 - 1905 - mutex_lock(&acpi_dep_list_lock); 1906 - 1907 - list_for_each_entry(dep, &acpi_dep_list, node) { 1908 - if (dep->consumer == adev->handle) 1909 - adev->dep_unmet++; 1910 - } 1911 - 1912 - mutex_unlock(&acpi_dep_list_lock); 1913 - } 1914 - 1915 1889 static bool acpi_bus_scan_second_pass; 1916 1890 1917 1891 static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep, ··· 1943 1949 return AE_OK; 1944 1950 } 1945 1951 1946 - acpi_add_single_object(&device, handle, type); 1947 - if (!device) 1948 - return AE_CTRL_DEPTH; 1949 - 1950 - acpi_scan_init_hotplug(device); 1951 1952 /* 1952 1953 * If check_dep is true at this point, the device has no dependencies, 1953 1954 * or the creation of the device object would have been postponed above. 1954 1955 */ 1955 - if (check_dep) 1956 - device->dep_unmet = 0; 1957 - else 1958 - acpi_scan_dep_init(device); 1956 + acpi_add_single_object(&device, handle, type, !check_dep); 1957 + if (!device) 1958 + return AE_CTRL_DEPTH; 1959 + 1960 + acpi_scan_init_hotplug(device); 1959 1961 1960 1962 out: 1961 1963 if (!*adev_p) ··· 2101 2111 device->handler->hotplug.notify_online(device); 2102 2112 } 2103 2113 2104 - void acpi_walk_dep_device_list(acpi_handle handle) 2114 + static int acpi_dev_get_first_consumer_dev_cb(struct acpi_dep_data *dep, void *data) 2115 + { 2116 + struct acpi_device *adev; 2117 + 2118 + adev = acpi_bus_get_acpi_device(dep->consumer); 2119 + if (!adev) 2120 + /* If we don't find an adev then we want to continue parsing */ 2121 + return 0; 2122 + 2123 + *(struct acpi_device **)data = adev; 2124 + 2125 + return 1; 2126 + } 2127 + 2128 + static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data) 2129 + { 2130 + struct acpi_device *adev; 2131 + 2132 + acpi_bus_get_device(dep->consumer, &adev); 2133 + 2134 + if (adev) { 2135 + adev->dep_unmet--; 2136 + if (!adev->dep_unmet) 2137 + acpi_bus_attach(adev, true); 2138 + } 2139 + 2140 + list_del(&dep->node); 2141 + kfree(dep); 2142 + 2143 + return 0; 2144 + } 2145 + 2146 + /** 2147 + * acpi_walk_dep_device_list - Apply a callback to every entry in acpi_dep_list 2148 + * @handle: The ACPI handle of the supplier device 2149 + * @callback: Pointer to the callback function to apply 2150 + * @data: Pointer to some data to pass to the callback 2151 + * 2152 + * The return value of the callback determines this function's behaviour. If 0 2153 + * is returned we continue to iterate over acpi_dep_list. If a positive value 2154 + * is returned then the loop is broken but this function returns 0. If a 2155 + * negative value is returned by the callback then the loop is broken and that 2156 + * value is returned as the final error. 2157 + */ 2158 + int acpi_walk_dep_device_list(acpi_handle handle, 2159 + int (*callback)(struct acpi_dep_data *, void *), 2160 + void *data) 2105 2161 { 2106 2162 struct acpi_dep_data *dep, *tmp; 2107 - struct acpi_device *adev; 2163 + int ret = 0; 2108 2164 2109 2165 mutex_lock(&acpi_dep_list_lock); 2110 2166 list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) { 2111 2167 if (dep->supplier == handle) { 2112 - acpi_bus_get_device(dep->consumer, &adev); 2113 - 2114 - if (adev) { 2115 - adev->dep_unmet--; 2116 - if (!adev->dep_unmet) 2117 - acpi_bus_attach(adev, true); 2118 - } 2119 - 2120 - list_del(&dep->node); 2121 - kfree(dep); 2168 + ret = callback(dep, data); 2169 + if (ret) 2170 + break; 2122 2171 } 2123 2172 } 2124 2173 mutex_unlock(&acpi_dep_list_lock); 2174 + 2175 + return ret > 0 ? 0 : ret; 2125 2176 } 2126 2177 EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list); 2178 + 2179 + /** 2180 + * acpi_dev_clear_dependencies - Inform consumers that the device is now active 2181 + * @supplier: Pointer to the supplier &struct acpi_device 2182 + * 2183 + * Clear dependencies on the given device. 2184 + */ 2185 + void acpi_dev_clear_dependencies(struct acpi_device *supplier) 2186 + { 2187 + acpi_walk_dep_device_list(supplier->handle, acpi_scan_clear_dep, NULL); 2188 + } 2189 + EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies); 2190 + 2191 + /** 2192 + * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier 2193 + * @supplier: Pointer to the dependee device 2194 + * 2195 + * Returns the first &struct acpi_device which declares itself dependent on 2196 + * @supplier via the _DEP buffer, parsed from the acpi_dep_list. 2197 + * 2198 + * The caller is responsible for putting the reference to adev when it is no 2199 + * longer needed. 2200 + */ 2201 + struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier) 2202 + { 2203 + struct acpi_device *adev = NULL; 2204 + 2205 + acpi_walk_dep_device_list(supplier->handle, 2206 + acpi_dev_get_first_consumer_dev_cb, &adev); 2207 + 2208 + return adev; 2209 + } 2210 + EXPORT_SYMBOL_GPL(acpi_dev_get_first_consumer_dev); 2127 2211 2128 2212 /** 2129 2213 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope. ··· 2287 2223 struct acpi_device *device = NULL; 2288 2224 int result; 2289 2225 2290 - result = acpi_add_single_object(&device, NULL, type); 2226 + result = acpi_add_single_object(&device, NULL, type, false); 2291 2227 if (result) 2292 2228 return result; 2293 2229 ··· 2307 2243 struct acpi_device *device = NULL; 2308 2244 2309 2245 result = acpi_add_single_object(&device, NULL, 2310 - ACPI_BUS_TYPE_POWER_BUTTON); 2246 + ACPI_BUS_TYPE_POWER_BUTTON, false); 2311 2247 if (result) 2312 2248 return result; 2313 2249 ··· 2323 2259 struct acpi_device *device = NULL; 2324 2260 2325 2261 result = acpi_add_single_object(&device, NULL, 2326 - ACPI_BUS_TYPE_SLEEP_BUTTON); 2262 + ACPI_BUS_TYPE_SLEEP_BUTTON, false); 2327 2263 if (result) 2328 2264 return result; 2329 2265
+5 -5
drivers/gpio/gpiolib-acpi.c
··· 1284 1284 void acpi_gpiochip_add(struct gpio_chip *chip) 1285 1285 { 1286 1286 struct acpi_gpio_chip *acpi_gpio; 1287 - acpi_handle handle; 1287 + struct acpi_device *adev; 1288 1288 acpi_status status; 1289 1289 1290 1290 if (!chip || !chip->parent) 1291 1291 return; 1292 1292 1293 - handle = ACPI_HANDLE(chip->parent); 1294 - if (!handle) 1293 + adev = ACPI_COMPANION(chip->parent); 1294 + if (!adev) 1295 1295 return; 1296 1296 1297 1297 acpi_gpio = kzalloc(sizeof(*acpi_gpio), GFP_KERNEL); ··· 1305 1305 INIT_LIST_HEAD(&acpi_gpio->events); 1306 1306 INIT_LIST_HEAD(&acpi_gpio->deferred_req_irqs_list_entry); 1307 1307 1308 - status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); 1308 + status = acpi_attach_data(adev->handle, acpi_gpio_chip_dh, acpi_gpio); 1309 1309 if (ACPI_FAILURE(status)) { 1310 1310 dev_err(chip->parent, "Failed to attach ACPI GPIO chip\n"); 1311 1311 kfree(acpi_gpio); ··· 1314 1314 1315 1315 acpi_gpiochip_request_regions(acpi_gpio); 1316 1316 acpi_gpiochip_scan_gpios(acpi_gpio); 1317 - acpi_walk_dep_device_list(handle); 1317 + acpi_dev_clear_dependencies(adev); 1318 1318 } 1319 1319 1320 1320 void acpi_gpiochip_remove(struct gpio_chip *chip)
+4 -4
drivers/i2c/i2c-core-acpi.c
··· 259 259 */ 260 260 void i2c_acpi_register_devices(struct i2c_adapter *adap) 261 261 { 262 + struct acpi_device *adev; 262 263 acpi_status status; 263 - acpi_handle handle; 264 264 265 265 if (!has_acpi_companion(&adap->dev)) 266 266 return; ··· 275 275 if (!adap->dev.parent) 276 276 return; 277 277 278 - handle = ACPI_HANDLE(adap->dev.parent); 279 - if (!handle) 278 + adev = ACPI_COMPANION(adap->dev.parent); 279 + if (!adev) 280 280 return; 281 281 282 - acpi_walk_dep_device_list(handle); 282 + acpi_dev_clear_dependencies(adev); 283 283 } 284 284 285 285 static const struct acpi_device_id i2c_acpi_force_400khz_device_ids[] = {
+3 -3
drivers/platform/surface/aggregator/core.c
··· 621 621 622 622 static int ssam_serial_hub_probe(struct serdev_device *serdev) 623 623 { 624 + struct acpi_device *ssh = ACPI_COMPANION(&serdev->dev); 624 625 struct ssam_controller *ctrl; 625 - acpi_handle *ssh = ACPI_HANDLE(&serdev->dev); 626 626 acpi_status astatus; 627 627 int status; 628 628 ··· 652 652 if (status) 653 653 goto err_devopen; 654 654 655 - astatus = ssam_serdev_setup_via_acpi(ssh, serdev); 655 + astatus = ssam_serdev_setup_via_acpi(ssh->handle, serdev); 656 656 if (ACPI_FAILURE(astatus)) { 657 657 status = -ENXIO; 658 658 goto err_devinit; ··· 706 706 * For now let's thus default power/wakeup to false. 707 707 */ 708 708 device_set_wakeup_capable(&serdev->dev, true); 709 - acpi_walk_dep_device_list(ssh); 709 + acpi_dev_clear_dependencies(ssh); 710 710 711 711 return 0; 712 712
+11 -11
drivers/platform/surface/surface3_power.c
··· 446 446 447 447 static int mshw0011_install_space_handler(struct i2c_client *client) 448 448 { 449 - acpi_handle handle; 449 + struct acpi_device *adev; 450 450 struct mshw0011_handler_data *data; 451 451 acpi_status status; 452 452 453 - handle = ACPI_HANDLE(&client->dev); 454 - if (!handle) 453 + adev = ACPI_COMPANION(&client->dev); 454 + if (!adev) 455 455 return -ENODEV; 456 456 457 457 data = kzalloc(sizeof(struct mshw0011_handler_data), ··· 460 460 return -ENOMEM; 461 461 462 462 data->client = client; 463 - status = acpi_bus_attach_private_data(handle, (void *)data); 463 + status = acpi_bus_attach_private_data(adev->handle, (void *)data); 464 464 if (ACPI_FAILURE(status)) { 465 465 kfree(data); 466 466 return -ENOMEM; 467 467 } 468 468 469 - status = acpi_install_address_space_handler(handle, 470 - ACPI_ADR_SPACE_GSBUS, 471 - &mshw0011_space_handler, 472 - NULL, 473 - data); 469 + status = acpi_install_address_space_handler(adev->handle, 470 + ACPI_ADR_SPACE_GSBUS, 471 + &mshw0011_space_handler, 472 + NULL, 473 + data); 474 474 if (ACPI_FAILURE(status)) { 475 475 dev_err(&client->dev, "Error installing i2c space handler\n"); 476 - acpi_bus_detach_private_data(handle); 476 + acpi_bus_detach_private_data(adev->handle); 477 477 kfree(data); 478 478 return -ENOMEM; 479 479 } 480 480 481 - acpi_walk_dep_device_list(handle); 481 + acpi_dev_clear_dependencies(adev); 482 482 return 0; 483 483 } 484 484
+4 -3
drivers/platform/surface/surface_acpi_notify.c
··· 798 798 799 799 static int san_probe(struct platform_device *pdev) 800 800 { 801 - acpi_handle san = ACPI_HANDLE(&pdev->dev); 801 + struct acpi_device *san = ACPI_COMPANION(&pdev->dev); 802 802 struct ssam_controller *ctrl; 803 803 struct san_data *data; 804 804 acpi_status astatus; ··· 821 821 822 822 platform_set_drvdata(pdev, data); 823 823 824 - astatus = acpi_install_address_space_handler(san, ACPI_ADR_SPACE_GSBUS, 824 + astatus = acpi_install_address_space_handler(san->handle, 825 + ACPI_ADR_SPACE_GSBUS, 825 826 &san_opreg_handler, NULL, 826 827 &data->info); 827 828 if (ACPI_FAILURE(astatus)) ··· 836 835 if (status) 837 836 goto err_install_dev; 838 837 839 - acpi_walk_dep_device_list(san); 838 + acpi_dev_clear_dependencies(san); 840 839 return 0; 841 840 842 841 err_install_dev:
+8
include/acpi/acpi_bus.h
··· 280 280 struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */ 281 281 }; 282 282 283 + struct acpi_dep_data { 284 + struct list_head node; 285 + acpi_handle supplier; 286 + acpi_handle consumer; 287 + }; 288 + 283 289 /* Performance Management */ 284 290 285 291 struct acpi_device_perf_flags { ··· 691 685 692 686 bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); 693 687 688 + void acpi_dev_clear_dependencies(struct acpi_device *supplier); 689 + struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier); 694 690 struct acpi_device * 695 691 acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); 696 692 struct acpi_device *
+3 -1
include/linux/acpi.h
··· 666 666 const struct device_driver *drv); 667 667 int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); 668 668 int acpi_device_modalias(struct device *, char *, int); 669 - void acpi_walk_dep_device_list(acpi_handle handle); 669 + int acpi_walk_dep_device_list(acpi_handle handle, 670 + int (*callback)(struct acpi_dep_data *, void *), 671 + void *data); 670 672 671 673 struct platform_device *acpi_create_platform_device(struct acpi_device *, 672 674 struct property_entry *);