pci_root.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. /* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */
  62. static DEFINE_MUTEX(acpi_pci_root_lock);
  63. static LIST_HEAD(acpi_pci_roots);
  64. static LIST_HEAD(acpi_pci_drivers);
  65. static DEFINE_MUTEX(osc_lock);
  66. int acpi_pci_register_driver(struct acpi_pci_driver *driver)
  67. {
  68. int n = 0;
  69. struct acpi_pci_root *root;
  70. mutex_lock(&acpi_pci_root_lock);
  71. list_add_tail(&driver->node, &acpi_pci_drivers);
  72. if (driver->add)
  73. list_for_each_entry(root, &acpi_pci_roots, node) {
  74. driver->add(root);
  75. n++;
  76. }
  77. mutex_unlock(&acpi_pci_root_lock);
  78. return n;
  79. }
  80. EXPORT_SYMBOL(acpi_pci_register_driver);
  81. void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
  82. {
  83. struct acpi_pci_root *root;
  84. mutex_lock(&acpi_pci_root_lock);
  85. list_del(&driver->node);
  86. if (driver->remove)
  87. list_for_each_entry(root, &acpi_pci_roots, node)
  88. driver->remove(root);
  89. mutex_unlock(&acpi_pci_root_lock);
  90. }
  91. EXPORT_SYMBOL(acpi_pci_unregister_driver);
  92. acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
  93. {
  94. struct acpi_pci_root *root;
  95. acpi_handle handle = NULL;
  96. mutex_lock(&acpi_pci_root_lock);
  97. list_for_each_entry(root, &acpi_pci_roots, node)
  98. if ((root->segment == (u16) seg) &&
  99. (root->secondary.start == (u16) bus)) {
  100. handle = root->device->handle;
  101. break;
  102. }
  103. mutex_unlock(&acpi_pci_root_lock);
  104. return handle;
  105. }
  106. EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
  107. /**
  108. * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
  109. * @handle - the ACPI CA node in question.
  110. *
  111. * Note: we could make this API take a struct acpi_device * instead, but
  112. * for now, it's more convenient to operate on an acpi_handle.
  113. */
  114. int acpi_is_root_bridge(acpi_handle handle)
  115. {
  116. int ret;
  117. struct acpi_device *device;
  118. ret = acpi_bus_get_device(handle, &device);
  119. if (ret)
  120. return 0;
  121. ret = acpi_match_device_ids(device, root_device_ids);
  122. if (ret)
  123. return 0;
  124. else
  125. return 1;
  126. }
  127. EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
  128. static acpi_status
  129. get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
  130. {
  131. struct resource *res = data;
  132. struct acpi_resource_address64 address;
  133. if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
  134. resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
  135. resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
  136. return AE_OK;
  137. acpi_resource_to_address64(resource, &address);
  138. if ((address.address_length > 0) &&
  139. (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
  140. res->start = address.minimum;
  141. res->end = address.minimum + address.address_length - 1;
  142. }
  143. return AE_OK;
  144. }
  145. static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
  146. struct resource *res)
  147. {
  148. acpi_status status;
  149. res->start = -1;
  150. status =
  151. acpi_walk_resources(handle, METHOD_NAME__CRS,
  152. get_root_bridge_busnr_callback, res);
  153. if (ACPI_FAILURE(status))
  154. return status;
  155. if (res->start == -1)
  156. return AE_ERROR;
  157. return AE_OK;
  158. }
  159. static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
  160. static acpi_status acpi_pci_run_osc(acpi_handle handle,
  161. const u32 *capbuf, u32 *retval)
  162. {
  163. struct acpi_osc_context context = {
  164. .uuid_str = pci_osc_uuid_str,
  165. .rev = 1,
  166. .cap.length = 12,
  167. .cap.pointer = (void *)capbuf,
  168. };
  169. acpi_status status;
  170. status = acpi_run_osc(handle, &context);
  171. if (ACPI_SUCCESS(status)) {
  172. *retval = *((u32 *)(context.ret.pointer + 8));
  173. kfree(context.ret.pointer);
  174. }
  175. return status;
  176. }
  177. static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,
  178. u32 support,
  179. u32 *control)
  180. {
  181. acpi_status status;
  182. u32 result, capbuf[3];
  183. support &= OSC_PCI_SUPPORT_MASKS;
  184. support |= root->osc_support_set;
  185. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  186. capbuf[OSC_SUPPORT_TYPE] = support;
  187. if (control) {
  188. *control &= OSC_PCI_CONTROL_MASKS;
  189. capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
  190. } else {
  191. /* Run _OSC query for all possible controls. */
  192. capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS;
  193. }
  194. status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
  195. if (ACPI_SUCCESS(status)) {
  196. root->osc_support_set = support;
  197. if (control)
  198. *control = result;
  199. }
  200. return status;
  201. }
  202. static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
  203. {
  204. acpi_status status;
  205. acpi_handle tmp;
  206. status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
  207. if (ACPI_FAILURE(status))
  208. return status;
  209. mutex_lock(&osc_lock);
  210. status = acpi_pci_query_osc(root, flags, NULL);
  211. mutex_unlock(&osc_lock);
  212. return status;
  213. }
  214. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
  215. {
  216. struct acpi_pci_root *root;
  217. struct acpi_device *device;
  218. if (acpi_bus_get_device(handle, &device) ||
  219. acpi_match_device_ids(device, root_device_ids))
  220. return NULL;
  221. root = acpi_driver_data(device);
  222. return root;
  223. }
  224. EXPORT_SYMBOL_GPL(acpi_pci_find_root);
  225. struct acpi_handle_node {
  226. struct list_head node;
  227. acpi_handle handle;
  228. };
  229. /**
  230. * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev
  231. * @handle: the handle in question
  232. *
  233. * Given an ACPI CA handle, the desired PCI device is located in the
  234. * list of PCI devices.
  235. *
  236. * If the device is found, its reference count is increased and this
  237. * function returns a pointer to its data structure. The caller must
  238. * decrement the reference count by calling pci_dev_put().
  239. * If no device is found, %NULL is returned.
  240. */
  241. struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
  242. {
  243. int dev, fn;
  244. unsigned long long adr;
  245. acpi_status status;
  246. acpi_handle phandle;
  247. struct pci_bus *pbus;
  248. struct pci_dev *pdev = NULL;
  249. struct acpi_handle_node *node, *tmp;
  250. struct acpi_pci_root *root;
  251. LIST_HEAD(device_list);
  252. /*
  253. * Walk up the ACPI CA namespace until we reach a PCI root bridge.
  254. */
  255. phandle = handle;
  256. while (!acpi_is_root_bridge(phandle)) {
  257. node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL);
  258. if (!node)
  259. goto out;
  260. INIT_LIST_HEAD(&node->node);
  261. node->handle = phandle;
  262. list_add(&node->node, &device_list);
  263. status = acpi_get_parent(phandle, &phandle);
  264. if (ACPI_FAILURE(status))
  265. goto out;
  266. }
  267. root = acpi_pci_find_root(phandle);
  268. if (!root)
  269. goto out;
  270. pbus = root->bus;
  271. /*
  272. * Now, walk back down the PCI device tree until we return to our
  273. * original handle. Assumes that everything between the PCI root
  274. * bridge and the device we're looking for must be a P2P bridge.
  275. */
  276. list_for_each_entry(node, &device_list, node) {
  277. acpi_handle hnd = node->handle;
  278. status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr);
  279. if (ACPI_FAILURE(status))
  280. goto out;
  281. dev = (adr >> 16) & 0xffff;
  282. fn = adr & 0xffff;
  283. pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn));
  284. if (!pdev || hnd == handle)
  285. break;
  286. pbus = pdev->subordinate;
  287. pci_dev_put(pdev);
  288. /*
  289. * This function may be called for a non-PCI device that has a
  290. * PCI parent (eg. a disk under a PCI SATA controller). In that
  291. * case pdev->subordinate will be NULL for the parent.
  292. */
  293. if (!pbus) {
  294. dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n");
  295. pdev = NULL;
  296. break;
  297. }
  298. }
  299. out:
  300. list_for_each_entry_safe(node, tmp, &device_list, node)
  301. kfree(node);
  302. return pdev;
  303. }
  304. EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
  305. /**
  306. * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
  307. * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
  308. * @mask: Mask of _OSC bits to request control of, place to store control mask.
  309. * @req: Mask of _OSC bits the control of is essential to the caller.
  310. *
  311. * Run _OSC query for @mask and if that is successful, compare the returned
  312. * mask of control bits with @req. If all of the @req bits are set in the
  313. * returned mask, run _OSC request for it.
  314. *
  315. * The variable at the @mask address may be modified regardless of whether or
  316. * not the function returns success. On success it will contain the mask of
  317. * _OSC bits the BIOS has granted control of, but its contents are meaningless
  318. * on failure.
  319. **/
  320. acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
  321. {
  322. struct acpi_pci_root *root;
  323. acpi_status status;
  324. u32 ctrl, capbuf[3];
  325. acpi_handle tmp;
  326. if (!mask)
  327. return AE_BAD_PARAMETER;
  328. ctrl = *mask & OSC_PCI_CONTROL_MASKS;
  329. if ((ctrl & req) != req)
  330. return AE_TYPE;
  331. root = acpi_pci_find_root(handle);
  332. if (!root)
  333. return AE_NOT_EXIST;
  334. status = acpi_get_handle(handle, "_OSC", &tmp);
  335. if (ACPI_FAILURE(status))
  336. return status;
  337. mutex_lock(&osc_lock);
  338. *mask = ctrl | root->osc_control_set;
  339. /* No need to evaluate _OSC if the control was already granted. */
  340. if ((root->osc_control_set & ctrl) == ctrl)
  341. goto out;
  342. /* Need to check the available controls bits before requesting them. */
  343. while (*mask) {
  344. status = acpi_pci_query_osc(root, root->osc_support_set, mask);
  345. if (ACPI_FAILURE(status))
  346. goto out;
  347. if (ctrl == *mask)
  348. break;
  349. ctrl = *mask;
  350. }
  351. if ((ctrl & req) != req) {
  352. status = AE_SUPPORT;
  353. goto out;
  354. }
  355. capbuf[OSC_QUERY_TYPE] = 0;
  356. capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
  357. capbuf[OSC_CONTROL_TYPE] = ctrl;
  358. status = acpi_pci_run_osc(handle, capbuf, mask);
  359. if (ACPI_SUCCESS(status))
  360. root->osc_control_set = *mask;
  361. out:
  362. mutex_unlock(&osc_lock);
  363. return status;
  364. }
  365. EXPORT_SYMBOL(acpi_pci_osc_control_set);
  366. static int acpi_pci_root_add(struct acpi_device *device,
  367. const struct acpi_device_id *not_used)
  368. {
  369. unsigned long long segment, bus;
  370. acpi_status status;
  371. int result;
  372. struct acpi_pci_root *root;
  373. acpi_handle handle;
  374. struct acpi_pci_driver *driver;
  375. u32 flags, base_flags;
  376. bool is_osc_granted = false;
  377. root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
  378. if (!root)
  379. return -ENOMEM;
  380. segment = 0;
  381. status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
  382. &segment);
  383. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  384. printk(KERN_ERR PREFIX "can't evaluate _SEG\n");
  385. result = -ENODEV;
  386. goto end;
  387. }
  388. /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
  389. root->secondary.flags = IORESOURCE_BUS;
  390. status = try_get_root_bridge_busnr(device->handle, &root->secondary);
  391. if (ACPI_FAILURE(status)) {
  392. /*
  393. * We need both the start and end of the downstream bus range
  394. * to interpret _CBA (MMCONFIG base address), so it really is
  395. * supposed to be in _CRS. If we don't find it there, all we
  396. * can do is assume [_BBN-0xFF] or [0-0xFF].
  397. */
  398. root->secondary.end = 0xFF;
  399. printk(KERN_WARNING FW_BUG PREFIX
  400. "no secondary bus range in _CRS\n");
  401. status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN,
  402. NULL, &bus);
  403. if (ACPI_SUCCESS(status))
  404. root->secondary.start = bus;
  405. else if (status == AE_NOT_FOUND)
  406. root->secondary.start = 0;
  407. else {
  408. printk(KERN_ERR PREFIX "can't evaluate _BBN\n");
  409. result = -ENODEV;
  410. goto end;
  411. }
  412. }
  413. INIT_LIST_HEAD(&root->node);
  414. root->device = device;
  415. root->segment = segment & 0xFFFF;
  416. strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
  417. strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
  418. device->driver_data = root;
  419. printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n",
  420. acpi_device_name(device), acpi_device_bid(device),
  421. root->segment, &root->secondary);
  422. /*
  423. * PCI Routing Table
  424. * -----------------
  425. * Evaluate and parse _PRT, if exists.
  426. */
  427. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  428. if (ACPI_SUCCESS(status))
  429. result = acpi_pci_irq_add_prt(device->handle, root->segment,
  430. root->secondary.start);
  431. root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle);
  432. /*
  433. * All supported architectures that use ACPI have support for
  434. * PCI domains, so we indicate this in _OSC support capabilities.
  435. */
  436. flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
  437. acpi_pci_osc_support(root, flags);
  438. /* Indicate support for various _OSC capabilities. */
  439. if (pci_ext_cfg_avail())
  440. flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
  441. if (pcie_aspm_support_enabled()) {
  442. flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
  443. OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
  444. }
  445. if (pci_msi_enabled())
  446. flags |= OSC_MSI_SUPPORT;
  447. if (flags != base_flags) {
  448. status = acpi_pci_osc_support(root, flags);
  449. if (ACPI_FAILURE(status)) {
  450. dev_info(&device->dev, "ACPI _OSC support "
  451. "notification failed, disabling PCIe ASPM\n");
  452. pcie_no_aspm();
  453. flags = base_flags;
  454. }
  455. }
  456. if (!pcie_ports_disabled
  457. && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
  458. flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
  459. | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
  460. | OSC_PCI_EXPRESS_PME_CONTROL;
  461. if (pci_aer_available()) {
  462. if (aer_acpi_firmware_first())
  463. dev_dbg(&device->dev,
  464. "PCIe errors handled by BIOS.\n");
  465. else
  466. flags |= OSC_PCI_EXPRESS_AER_CONTROL;
  467. }
  468. dev_info(&device->dev,
  469. "Requesting ACPI _OSC control (0x%02x)\n", flags);
  470. status = acpi_pci_osc_control_set(device->handle, &flags,
  471. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
  472. if (ACPI_SUCCESS(status)) {
  473. is_osc_granted = true;
  474. dev_info(&device->dev,
  475. "ACPI _OSC control (0x%02x) granted\n", flags);
  476. } else {
  477. is_osc_granted = false;
  478. dev_info(&device->dev,
  479. "ACPI _OSC request failed (%s), "
  480. "returned control mask: 0x%02x\n",
  481. acpi_format_exception(status), flags);
  482. }
  483. } else {
  484. dev_info(&device->dev,
  485. "Unable to request _OSC control "
  486. "(_OSC support mask: 0x%02x)\n", flags);
  487. }
  488. /*
  489. * TBD: Need PCI interface for enumeration/configuration of roots.
  490. */
  491. mutex_lock(&acpi_pci_root_lock);
  492. list_add_tail(&root->node, &acpi_pci_roots);
  493. mutex_unlock(&acpi_pci_root_lock);
  494. /*
  495. * Scan the Root Bridge
  496. * --------------------
  497. * Must do this prior to any attempt to bind the root device, as the
  498. * PCI namespace does not get created until this call is made (and
  499. * thus the root bridge's pci_dev does not exist).
  500. */
  501. root->bus = pci_acpi_scan_root(root);
  502. if (!root->bus) {
  503. printk(KERN_ERR PREFIX
  504. "Bus %04x:%02x not present in PCI namespace\n",
  505. root->segment, (unsigned int)root->secondary.start);
  506. result = -ENODEV;
  507. goto out_del_root;
  508. }
  509. /* ASPM setting */
  510. if (is_osc_granted) {
  511. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM)
  512. pcie_clear_aspm(root->bus);
  513. } else {
  514. pr_info("ACPI _OSC control for PCIe not granted, "
  515. "disabling ASPM\n");
  516. pcie_no_aspm();
  517. }
  518. pci_acpi_add_bus_pm_notifier(device, root->bus);
  519. if (device->wakeup.flags.run_wake)
  520. device_set_run_wake(root->bus->bridge, true);
  521. if (system_state != SYSTEM_BOOTING)
  522. pci_assign_unassigned_bus_resources(root->bus);
  523. mutex_lock(&acpi_pci_root_lock);
  524. list_for_each_entry(driver, &acpi_pci_drivers, node)
  525. if (driver->add)
  526. driver->add(root);
  527. mutex_unlock(&acpi_pci_root_lock);
  528. /* need to after hot-added ioapic is registered */
  529. if (system_state != SYSTEM_BOOTING)
  530. pci_enable_bridges(root->bus);
  531. pci_bus_add_devices(root->bus);
  532. return 1;
  533. out_del_root:
  534. mutex_lock(&acpi_pci_root_lock);
  535. list_del(&root->node);
  536. mutex_unlock(&acpi_pci_root_lock);
  537. acpi_pci_irq_del_prt(root->segment, root->secondary.start);
  538. end:
  539. kfree(root);
  540. return result;
  541. }
  542. static void acpi_pci_root_remove(struct acpi_device *device)
  543. {
  544. acpi_status status;
  545. acpi_handle handle;
  546. struct acpi_pci_root *root = acpi_driver_data(device);
  547. struct acpi_pci_driver *driver;
  548. pci_stop_root_bus(root->bus);
  549. mutex_lock(&acpi_pci_root_lock);
  550. list_for_each_entry_reverse(driver, &acpi_pci_drivers, node)
  551. if (driver->remove)
  552. driver->remove(root);
  553. mutex_unlock(&acpi_pci_root_lock);
  554. device_set_run_wake(root->bus->bridge, false);
  555. pci_acpi_remove_bus_pm_notifier(device);
  556. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  557. if (ACPI_SUCCESS(status))
  558. acpi_pci_irq_del_prt(root->segment, root->secondary.start);
  559. pci_remove_root_bus(root->bus);
  560. mutex_lock(&acpi_pci_root_lock);
  561. list_del(&root->node);
  562. mutex_unlock(&acpi_pci_root_lock);
  563. kfree(root);
  564. }
  565. void __init acpi_pci_root_init(void)
  566. {
  567. acpi_hest_init();
  568. if (!acpi_pci_disabled) {
  569. pci_acpi_crs_quirks();
  570. acpi_scan_add_handler(&pci_root_handler);
  571. }
  572. }