pci_root.c 18 KB

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