pci_root.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/types.h>
  29. #include <linux/mutex.h>
  30. #include <linux/pm.h>
  31. #include <linux/pm_runtime.h>
  32. #include <linux/pci.h>
  33. #include <linux/pci-acpi.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/acpi.h>
  36. #include <linux/slab.h>
  37. #include <acpi/acpi_bus.h>
  38. #include <acpi/acpi_drivers.h>
  39. #include <acpi/apei.h>
  40. #define PREFIX "ACPI: "
  41. #define _COMPONENT ACPI_PCI_COMPONENT
  42. ACPI_MODULE_NAME("pci_root");
  43. #define ACPI_PCI_ROOT_CLASS "pci_bridge"
  44. #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
  45. static int acpi_pci_root_add(struct acpi_device *device,
  46. const struct acpi_device_id *not_used);
  47. static void acpi_pci_root_remove(struct acpi_device *device);
  48. #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \
  49. | OSC_ACTIVE_STATE_PWR_SUPPORT \
  50. | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \
  51. | OSC_MSI_SUPPORT)
  52. static const struct acpi_device_id root_device_ids[] = {
  53. {"PNP0A03", 0},
  54. {"", 0},
  55. };
  56. static struct acpi_scan_handler pci_root_handler = {
  57. .ids = root_device_ids,
  58. .attach = acpi_pci_root_add,
  59. .detach = acpi_pci_root_remove,
  60. };
  61. static DEFINE_MUTEX(osc_lock);
  62. /**
  63. * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
  64. * @handle - the ACPI CA node in question.
  65. *
  66. * Note: we could make this API take a struct acpi_device * instead, but
  67. * for now, it's more convenient to operate on an acpi_handle.
  68. */
  69. int acpi_is_root_bridge(acpi_handle handle)
  70. {
  71. int ret;
  72. struct acpi_device *device;
  73. ret = acpi_bus_get_device(handle, &device);
  74. if (ret)
  75. return 0;
  76. ret = acpi_match_device_ids(device, root_device_ids);
  77. if (ret)
  78. return 0;
  79. else
  80. return 1;
  81. }
  82. EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
  83. static acpi_status
  84. get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
  85. {
  86. struct resource *res = data;
  87. struct acpi_resource_address64 address;
  88. if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
  89. resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
  90. resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
  91. return AE_OK;
  92. acpi_resource_to_address64(resource, &address);
  93. if ((address.address_length > 0) &&
  94. (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
  95. res->start = address.minimum;
  96. res->end = address.minimum + address.address_length - 1;
  97. }
  98. return AE_OK;
  99. }
  100. static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
  101. struct resource *res)
  102. {
  103. acpi_status status;
  104. res->start = -1;
  105. status =
  106. acpi_walk_resources(handle, METHOD_NAME__CRS,
  107. get_root_bridge_busnr_callback, res);
  108. if (ACPI_FAILURE(status))
  109. return status;
  110. if (res->start == -1)
  111. return AE_ERROR;
  112. return AE_OK;
  113. }
  114. static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
  115. static acpi_status acpi_pci_run_osc(acpi_handle handle,
  116. const u32 *capbuf, u32 *retval)
  117. {
  118. struct acpi_osc_context context = {
  119. .uuid_str = pci_osc_uuid_str,
  120. .rev = 1,
  121. .cap.length = 12,
  122. .cap.pointer = (void *)capbuf,
  123. };
  124. acpi_status status;
  125. status = acpi_run_osc(handle, &context);
  126. if (ACPI_SUCCESS(status)) {
  127. *retval = *((u32 *)(context.ret.pointer + 8));
  128. kfree(context.ret.pointer);
  129. }
  130. return status;
  131. }
  132. static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,
  133. u32 support,
  134. u32 *control)
  135. {
  136. acpi_status status;
  137. u32 result, capbuf[3];
  138. support &= OSC_PCI_SUPPORT_MASKS;
  139. support |= root->osc_support_set;
  140. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  141. capbuf[OSC_SUPPORT_TYPE] = support;
  142. if (control) {
  143. *control &= OSC_PCI_CONTROL_MASKS;
  144. capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
  145. } else {
  146. /* Run _OSC query only with existing controls. */
  147. capbuf[OSC_CONTROL_TYPE] = root->osc_control_set;
  148. }
  149. status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
  150. if (ACPI_SUCCESS(status)) {
  151. root->osc_support_set = support;
  152. if (control)
  153. *control = result;
  154. }
  155. return status;
  156. }
  157. static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
  158. {
  159. acpi_status status;
  160. acpi_handle tmp;
  161. status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
  162. if (ACPI_FAILURE(status))
  163. return status;
  164. mutex_lock(&osc_lock);
  165. status = acpi_pci_query_osc(root, flags, NULL);
  166. mutex_unlock(&osc_lock);
  167. return status;
  168. }
  169. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
  170. {
  171. struct acpi_pci_root *root;
  172. struct acpi_device *device;
  173. if (acpi_bus_get_device(handle, &device) ||
  174. acpi_match_device_ids(device, root_device_ids))
  175. return NULL;
  176. root = acpi_driver_data(device);
  177. return root;
  178. }
  179. EXPORT_SYMBOL_GPL(acpi_pci_find_root);
  180. struct acpi_handle_node {
  181. struct list_head node;
  182. acpi_handle handle;
  183. };
  184. /**
  185. * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev
  186. * @handle: the handle in question
  187. *
  188. * Given an ACPI CA handle, the desired PCI device is located in the
  189. * list of PCI devices.
  190. *
  191. * If the device is found, its reference count is increased and this
  192. * function returns a pointer to its data structure. The caller must
  193. * decrement the reference count by calling pci_dev_put().
  194. * If no device is found, %NULL is returned.
  195. */
  196. struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
  197. {
  198. int dev, fn;
  199. unsigned long long adr;
  200. acpi_status status;
  201. acpi_handle phandle;
  202. struct pci_bus *pbus;
  203. struct pci_dev *pdev = NULL;
  204. struct acpi_handle_node *node, *tmp;
  205. struct acpi_pci_root *root;
  206. LIST_HEAD(device_list);
  207. /*
  208. * Walk up the ACPI CA namespace until we reach a PCI root bridge.
  209. */
  210. phandle = handle;
  211. while (!acpi_is_root_bridge(phandle)) {
  212. node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL);
  213. if (!node)
  214. goto out;
  215. INIT_LIST_HEAD(&node->node);
  216. node->handle = phandle;
  217. list_add(&node->node, &device_list);
  218. status = acpi_get_parent(phandle, &phandle);
  219. if (ACPI_FAILURE(status))
  220. goto out;
  221. }
  222. root = acpi_pci_find_root(phandle);
  223. if (!root)
  224. goto out;
  225. pbus = root->bus;
  226. /*
  227. * Now, walk back down the PCI device tree until we return to our
  228. * original handle. Assumes that everything between the PCI root
  229. * bridge and the device we're looking for must be a P2P bridge.
  230. */
  231. list_for_each_entry(node, &device_list, node) {
  232. acpi_handle hnd = node->handle;
  233. status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr);
  234. if (ACPI_FAILURE(status))
  235. goto out;
  236. dev = (adr >> 16) & 0xffff;
  237. fn = adr & 0xffff;
  238. pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn));
  239. if (!pdev || hnd == handle)
  240. break;
  241. pbus = pdev->subordinate;
  242. pci_dev_put(pdev);
  243. /*
  244. * This function may be called for a non-PCI device that has a
  245. * PCI parent (eg. a disk under a PCI SATA controller). In that
  246. * case pdev->subordinate will be NULL for the parent.
  247. */
  248. if (!pbus) {
  249. dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n");
  250. pdev = NULL;
  251. break;
  252. }
  253. }
  254. out:
  255. list_for_each_entry_safe(node, tmp, &device_list, node)
  256. kfree(node);
  257. return pdev;
  258. }
  259. EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
  260. /**
  261. * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
  262. * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
  263. * @mask: Mask of _OSC bits to request control of, place to store control mask.
  264. * @req: Mask of _OSC bits the control of is essential to the caller.
  265. *
  266. * Run _OSC query for @mask and if that is successful, compare the returned
  267. * mask of control bits with @req. If all of the @req bits are set in the
  268. * returned mask, run _OSC request for it.
  269. *
  270. * The variable at the @mask address may be modified regardless of whether or
  271. * not the function returns success. On success it will contain the mask of
  272. * _OSC bits the BIOS has granted control of, but its contents are meaningless
  273. * on failure.
  274. **/
  275. acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
  276. {
  277. struct acpi_pci_root *root;
  278. acpi_status status;
  279. u32 ctrl, capbuf[3];
  280. acpi_handle tmp;
  281. if (!mask)
  282. return AE_BAD_PARAMETER;
  283. ctrl = *mask & OSC_PCI_CONTROL_MASKS;
  284. if ((ctrl & req) != req)
  285. return AE_TYPE;
  286. root = acpi_pci_find_root(handle);
  287. if (!root)
  288. return AE_NOT_EXIST;
  289. status = acpi_get_handle(handle, "_OSC", &tmp);
  290. if (ACPI_FAILURE(status))
  291. return status;
  292. mutex_lock(&osc_lock);
  293. *mask = ctrl | root->osc_control_set;
  294. /* No need to evaluate _OSC if the control was already granted. */
  295. if ((root->osc_control_set & ctrl) == ctrl)
  296. goto out;
  297. /* Need to check the available controls bits before requesting them. */
  298. while (*mask) {
  299. status = acpi_pci_query_osc(root, root->osc_support_set, mask);
  300. if (ACPI_FAILURE(status))
  301. goto out;
  302. if (ctrl == *mask)
  303. break;
  304. ctrl = *mask;
  305. }
  306. if ((ctrl & req) != req) {
  307. status = AE_SUPPORT;
  308. goto out;
  309. }
  310. capbuf[OSC_QUERY_TYPE] = 0;
  311. capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
  312. capbuf[OSC_CONTROL_TYPE] = ctrl;
  313. status = acpi_pci_run_osc(handle, capbuf, mask);
  314. if (ACPI_SUCCESS(status))
  315. root->osc_control_set = *mask;
  316. out:
  317. mutex_unlock(&osc_lock);
  318. return status;
  319. }
  320. EXPORT_SYMBOL(acpi_pci_osc_control_set);
  321. static int acpi_pci_root_add(struct acpi_device *device,
  322. const struct acpi_device_id *not_used)
  323. {
  324. unsigned long long segment, bus;
  325. acpi_status status;
  326. int result;
  327. struct acpi_pci_root *root;
  328. u32 flags, base_flags;
  329. acpi_handle handle = device->handle;
  330. root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
  331. if (!root)
  332. return -ENOMEM;
  333. segment = 0;
  334. status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL,
  335. &segment);
  336. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  337. dev_err(&device->dev, "can't evaluate _SEG\n");
  338. result = -ENODEV;
  339. goto end;
  340. }
  341. /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
  342. root->secondary.flags = IORESOURCE_BUS;
  343. status = try_get_root_bridge_busnr(handle, &root->secondary);
  344. if (ACPI_FAILURE(status)) {
  345. /*
  346. * We need both the start and end of the downstream bus range
  347. * to interpret _CBA (MMCONFIG base address), so it really is
  348. * supposed to be in _CRS. If we don't find it there, all we
  349. * can do is assume [_BBN-0xFF] or [0-0xFF].
  350. */
  351. root->secondary.end = 0xFF;
  352. dev_warn(&device->dev,
  353. FW_BUG "no secondary bus range in _CRS\n");
  354. status = acpi_evaluate_integer(handle, METHOD_NAME__BBN,
  355. NULL, &bus);
  356. if (ACPI_SUCCESS(status))
  357. root->secondary.start = bus;
  358. else if (status == AE_NOT_FOUND)
  359. root->secondary.start = 0;
  360. else {
  361. dev_err(&device->dev, "can't evaluate _BBN\n");
  362. result = -ENODEV;
  363. goto end;
  364. }
  365. }
  366. root->device = device;
  367. root->segment = segment & 0xFFFF;
  368. strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
  369. strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
  370. device->driver_data = root;
  371. pr_info(PREFIX "%s [%s] (domain %04x %pR)\n",
  372. acpi_device_name(device), acpi_device_bid(device),
  373. root->segment, &root->secondary);
  374. root->mcfg_addr = acpi_pci_root_get_mcfg_addr(handle);
  375. /*
  376. * All supported architectures that use ACPI have support for
  377. * PCI domains, so we indicate this in _OSC support capabilities.
  378. */
  379. flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
  380. acpi_pci_osc_support(root, flags);
  381. /*
  382. * TBD: Need PCI interface for enumeration/configuration of roots.
  383. */
  384. /*
  385. * Scan the Root Bridge
  386. * --------------------
  387. * Must do this prior to any attempt to bind the root device, as the
  388. * PCI namespace does not get created until this call is made (and
  389. * thus the root bridge's pci_dev does not exist).
  390. */
  391. root->bus = pci_acpi_scan_root(root);
  392. if (!root->bus) {
  393. dev_err(&device->dev,
  394. "Bus %04x:%02x not present in PCI namespace\n",
  395. root->segment, (unsigned int)root->secondary.start);
  396. result = -ENODEV;
  397. goto end;
  398. }
  399. /* Indicate support for various _OSC capabilities. */
  400. if (pci_ext_cfg_avail())
  401. flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
  402. if (pcie_aspm_support_enabled()) {
  403. flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
  404. OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
  405. }
  406. if (pci_msi_enabled())
  407. flags |= OSC_MSI_SUPPORT;
  408. if (flags != base_flags) {
  409. status = acpi_pci_osc_support(root, flags);
  410. if (ACPI_FAILURE(status)) {
  411. dev_info(&device->dev, "ACPI _OSC support "
  412. "notification failed, disabling PCIe ASPM\n");
  413. pcie_no_aspm();
  414. flags = base_flags;
  415. }
  416. }
  417. if (!pcie_ports_disabled
  418. && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
  419. flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
  420. | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
  421. | OSC_PCI_EXPRESS_PME_CONTROL;
  422. if (pci_aer_available()) {
  423. if (aer_acpi_firmware_first())
  424. dev_dbg(&device->dev,
  425. "PCIe errors handled by BIOS.\n");
  426. else
  427. flags |= OSC_PCI_EXPRESS_AER_CONTROL;
  428. }
  429. dev_info(&device->dev,
  430. "Requesting ACPI _OSC control (0x%02x)\n", flags);
  431. status = acpi_pci_osc_control_set(handle, &flags,
  432. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
  433. if (ACPI_SUCCESS(status)) {
  434. dev_info(&device->dev,
  435. "ACPI _OSC control (0x%02x) granted\n", flags);
  436. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
  437. /*
  438. * We have ASPM control, but the FADT indicates
  439. * that it's unsupported. Clear it.
  440. */
  441. pcie_clear_aspm(root->bus);
  442. }
  443. } else {
  444. dev_info(&device->dev,
  445. "ACPI _OSC request failed (%s), "
  446. "returned control mask: 0x%02x\n",
  447. acpi_format_exception(status), flags);
  448. dev_info(&device->dev,
  449. "ACPI _OSC control for PCIe not granted, disabling ASPM\n");
  450. pcie_no_aspm();
  451. }
  452. } else {
  453. dev_info(&device->dev,
  454. "Unable to request _OSC control "
  455. "(_OSC support mask: 0x%02x)\n", flags);
  456. }
  457. pci_acpi_add_bus_pm_notifier(device, root->bus);
  458. if (device->wakeup.flags.run_wake)
  459. device_set_run_wake(root->bus->bridge, true);
  460. if (system_state != SYSTEM_BOOTING) {
  461. pcibios_resource_survey_bus(root->bus);
  462. pci_assign_unassigned_bus_resources(root->bus);
  463. /* need to after hot-added ioapic is registered */
  464. pci_enable_bridges(root->bus);
  465. }
  466. pci_bus_add_devices(root->bus);
  467. return 1;
  468. end:
  469. kfree(root);
  470. return result;
  471. }
  472. static void acpi_pci_root_remove(struct acpi_device *device)
  473. {
  474. struct acpi_pci_root *root = acpi_driver_data(device);
  475. pci_stop_root_bus(root->bus);
  476. device_set_run_wake(root->bus->bridge, false);
  477. pci_acpi_remove_bus_pm_notifier(device);
  478. pci_remove_root_bus(root->bus);
  479. kfree(root);
  480. }
  481. void __init acpi_pci_root_init(void)
  482. {
  483. acpi_hest_init();
  484. if (!acpi_pci_disabled) {
  485. pci_acpi_crs_quirks();
  486. acpi_scan_add_handler(&pci_root_handler);
  487. }
  488. }
  489. /* Support root bridge hotplug */
  490. static void handle_root_bridge_insertion(acpi_handle handle)
  491. {
  492. struct acpi_device *device;
  493. if (!acpi_bus_get_device(handle, &device)) {
  494. dev_printk(KERN_DEBUG, &device->dev,
  495. "acpi device already exists; ignoring notify\n");
  496. return;
  497. }
  498. if (acpi_bus_scan(handle))
  499. acpi_handle_err(handle, "cannot add bridge to acpi list\n");
  500. }
  501. static void handle_root_bridge_removal(struct acpi_device *device)
  502. {
  503. acpi_status status;
  504. struct acpi_eject_event *ej_event;
  505. ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
  506. if (!ej_event) {
  507. /* Inform firmware the hot-remove operation has error */
  508. (void) acpi_evaluate_hotplug_ost(device->handle,
  509. ACPI_NOTIFY_EJECT_REQUEST,
  510. ACPI_OST_SC_NON_SPECIFIC_FAILURE,
  511. NULL);
  512. return;
  513. }
  514. ej_event->device = device;
  515. ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
  516. status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event);
  517. if (ACPI_FAILURE(status))
  518. kfree(ej_event);
  519. }
  520. static void _handle_hotplug_event_root(struct work_struct *work)
  521. {
  522. struct acpi_pci_root *root;
  523. struct acpi_hp_work *hp_work;
  524. acpi_handle handle;
  525. u32 type;
  526. hp_work = container_of(work, struct acpi_hp_work, work);
  527. handle = hp_work->handle;
  528. type = hp_work->type;
  529. acpi_scan_lock_acquire();
  530. root = acpi_pci_find_root(handle);
  531. switch (type) {
  532. case ACPI_NOTIFY_BUS_CHECK:
  533. /* bus enumerate */
  534. acpi_handle_printk(KERN_DEBUG, handle,
  535. "Bus check notify on %s\n", __func__);
  536. if (!root)
  537. handle_root_bridge_insertion(handle);
  538. break;
  539. case ACPI_NOTIFY_DEVICE_CHECK:
  540. /* device check */
  541. acpi_handle_printk(KERN_DEBUG, handle,
  542. "Device check notify on %s\n", __func__);
  543. if (!root)
  544. handle_root_bridge_insertion(handle);
  545. break;
  546. case ACPI_NOTIFY_EJECT_REQUEST:
  547. /* request device eject */
  548. acpi_handle_printk(KERN_DEBUG, handle,
  549. "Device eject notify on %s\n", __func__);
  550. if (root)
  551. handle_root_bridge_removal(root->device);
  552. break;
  553. default:
  554. acpi_handle_warn(handle,
  555. "notify_handler: unknown event type 0x%x\n",
  556. type);
  557. break;
  558. }
  559. acpi_scan_lock_release();
  560. kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
  561. }
  562. static void handle_hotplug_event_root(acpi_handle handle, u32 type,
  563. void *context)
  564. {
  565. alloc_acpi_hp_work(handle, type, context,
  566. _handle_hotplug_event_root);
  567. }
  568. static acpi_status __init
  569. find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
  570. {
  571. acpi_status status;
  572. int *count = (int *)context;
  573. if (!acpi_is_root_bridge(handle))
  574. return AE_OK;
  575. (*count)++;
  576. status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
  577. handle_hotplug_event_root, NULL);
  578. if (ACPI_FAILURE(status))
  579. acpi_handle_printk(KERN_DEBUG, handle,
  580. "notify handler is not installed, exit status: %u\n",
  581. (unsigned int)status);
  582. else
  583. acpi_handle_printk(KERN_DEBUG, handle,
  584. "notify handler is installed\n");
  585. return AE_OK;
  586. }
  587. void __init acpi_pci_root_hp_init(void)
  588. {
  589. int num = 0;
  590. acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  591. ACPI_UINT32_MAX, find_root_bridges, NULL, &num, NULL);
  592. printk(KERN_DEBUG "Found %d acpi root devices\n", num);
  593. }