pci_root.c 19 KB

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