pci_root.c 18 KB

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