pci_root.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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/spinlock.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. static LIST_HEAD(acpi_pci_roots);
  68. static struct acpi_pci_driver *sub_driver;
  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. struct acpi_pci_driver **pptr = &sub_driver;
  75. while (*pptr)
  76. pptr = &(*pptr)->next;
  77. *pptr = driver;
  78. if (!driver->add)
  79. return 0;
  80. list_for_each_entry(root, &acpi_pci_roots, node) {
  81. driver->add(root->device->handle);
  82. n++;
  83. }
  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. struct acpi_pci_driver **pptr = &sub_driver;
  91. while (*pptr) {
  92. if (*pptr == driver)
  93. break;
  94. pptr = &(*pptr)->next;
  95. }
  96. BUG_ON(!*pptr);
  97. *pptr = (*pptr)->next;
  98. if (!driver->remove)
  99. return;
  100. list_for_each_entry(root, &acpi_pci_roots, node)
  101. driver->remove(root->device->handle);
  102. }
  103. EXPORT_SYMBOL(acpi_pci_unregister_driver);
  104. acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
  105. {
  106. struct acpi_pci_root *root;
  107. list_for_each_entry(root, &acpi_pci_roots, node)
  108. if ((root->segment == (u16) seg) &&
  109. (root->secondary.start == (u16) bus))
  110. return root->device->handle;
  111. return NULL;
  112. }
  113. EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
  114. /**
  115. * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
  116. * @handle - the ACPI CA node in question.
  117. *
  118. * Note: we could make this API take a struct acpi_device * instead, but
  119. * for now, it's more convenient to operate on an acpi_handle.
  120. */
  121. int acpi_is_root_bridge(acpi_handle handle)
  122. {
  123. int ret;
  124. struct acpi_device *device;
  125. ret = acpi_bus_get_device(handle, &device);
  126. if (ret)
  127. return 0;
  128. ret = acpi_match_device_ids(device, root_device_ids);
  129. if (ret)
  130. return 0;
  131. else
  132. return 1;
  133. }
  134. EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
  135. static acpi_status
  136. get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
  137. {
  138. struct resource *res = data;
  139. struct acpi_resource_address64 address;
  140. if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
  141. resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
  142. resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
  143. return AE_OK;
  144. acpi_resource_to_address64(resource, &address);
  145. if ((address.address_length > 0) &&
  146. (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
  147. res->start = address.minimum;
  148. res->end = address.minimum + address.address_length - 1;
  149. }
  150. return AE_OK;
  151. }
  152. static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
  153. struct resource *res)
  154. {
  155. acpi_status status;
  156. res->start = -1;
  157. status =
  158. acpi_walk_resources(handle, METHOD_NAME__CRS,
  159. get_root_bridge_busnr_callback, res);
  160. if (ACPI_FAILURE(status))
  161. return status;
  162. if (res->start == -1)
  163. return AE_ERROR;
  164. return AE_OK;
  165. }
  166. static void acpi_pci_bridge_scan(struct acpi_device *device)
  167. {
  168. int status;
  169. struct acpi_device *child = NULL;
  170. if (device->flags.bus_address)
  171. if (device->parent && device->parent->ops.bind) {
  172. status = device->parent->ops.bind(device);
  173. if (!status) {
  174. list_for_each_entry(child, &device->children, node)
  175. acpi_pci_bridge_scan(child);
  176. }
  177. }
  178. }
  179. static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
  180. static acpi_status acpi_pci_run_osc(acpi_handle handle,
  181. const u32 *capbuf, u32 *retval)
  182. {
  183. struct acpi_osc_context context = {
  184. .uuid_str = pci_osc_uuid_str,
  185. .rev = 1,
  186. .cap.length = 12,
  187. .cap.pointer = (void *)capbuf,
  188. };
  189. acpi_status status;
  190. status = acpi_run_osc(handle, &context);
  191. if (ACPI_SUCCESS(status)) {
  192. *retval = *((u32 *)(context.ret.pointer + 8));
  193. kfree(context.ret.pointer);
  194. }
  195. return status;
  196. }
  197. static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,
  198. u32 support,
  199. u32 *control)
  200. {
  201. acpi_status status;
  202. u32 result, capbuf[3];
  203. support &= OSC_PCI_SUPPORT_MASKS;
  204. support |= root->osc_support_set;
  205. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  206. capbuf[OSC_SUPPORT_TYPE] = support;
  207. if (control) {
  208. *control &= OSC_PCI_CONTROL_MASKS;
  209. capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
  210. } else {
  211. /* Run _OSC query for all possible controls. */
  212. capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS;
  213. }
  214. status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
  215. if (ACPI_SUCCESS(status)) {
  216. root->osc_support_set = support;
  217. if (control)
  218. *control = result;
  219. }
  220. return status;
  221. }
  222. static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
  223. {
  224. acpi_status status;
  225. acpi_handle tmp;
  226. status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
  227. if (ACPI_FAILURE(status))
  228. return status;
  229. mutex_lock(&osc_lock);
  230. status = acpi_pci_query_osc(root, flags, NULL);
  231. mutex_unlock(&osc_lock);
  232. return status;
  233. }
  234. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
  235. {
  236. struct acpi_pci_root *root;
  237. list_for_each_entry(root, &acpi_pci_roots, node) {
  238. if (root->device->handle == handle)
  239. return root;
  240. }
  241. return NULL;
  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, NULL, &bus);
  419. if (ACPI_SUCCESS(status))
  420. root->secondary.start = bus;
  421. else if (status == AE_NOT_FOUND)
  422. root->secondary.start = 0;
  423. else {
  424. printk(KERN_ERR PREFIX "can't evaluate _BBN\n");
  425. result = -ENODEV;
  426. goto end;
  427. }
  428. }
  429. INIT_LIST_HEAD(&root->node);
  430. root->device = device;
  431. root->segment = segment & 0xFFFF;
  432. strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
  433. strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
  434. device->driver_data = root;
  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. /*
  442. * TBD: Need PCI interface for enumeration/configuration of roots.
  443. */
  444. /* TBD: Locking */
  445. list_add_tail(&root->node, &acpi_pci_roots);
  446. printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n",
  447. acpi_device_name(device), acpi_device_bid(device),
  448. root->segment, &root->secondary);
  449. /*
  450. * Scan the Root Bridge
  451. * --------------------
  452. * Must do this prior to any attempt to bind the root device, as the
  453. * PCI namespace does not get created until this call is made (and
  454. * thus the root bridge's pci_dev does not exist).
  455. */
  456. root->bus = pci_acpi_scan_root(root);
  457. if (!root->bus) {
  458. printk(KERN_ERR PREFIX
  459. "Bus %04x:%02x not present in PCI namespace\n",
  460. root->segment, (unsigned int)root->secondary.start);
  461. result = -ENODEV;
  462. goto end;
  463. }
  464. /*
  465. * Attach ACPI-PCI Context
  466. * -----------------------
  467. * Thus binding the ACPI and PCI devices.
  468. */
  469. result = acpi_pci_bind_root(device);
  470. if (result)
  471. goto end;
  472. /*
  473. * PCI Routing Table
  474. * -----------------
  475. * Evaluate and parse _PRT, if exists.
  476. */
  477. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  478. if (ACPI_SUCCESS(status))
  479. result = acpi_pci_irq_add_prt(device->handle, root->bus);
  480. /*
  481. * Scan and bind all _ADR-Based Devices
  482. */
  483. list_for_each_entry(child, &device->children, node)
  484. acpi_pci_bridge_scan(child);
  485. /* Indicate support for various _OSC capabilities. */
  486. if (pci_ext_cfg_avail(root->bus->self))
  487. flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
  488. if (pcie_aspm_support_enabled())
  489. flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
  490. OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
  491. if (pci_msi_enabled())
  492. flags |= OSC_MSI_SUPPORT;
  493. if (flags != base_flags)
  494. acpi_pci_osc_support(root, flags);
  495. if (!pcie_ports_disabled
  496. && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
  497. flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
  498. | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
  499. | OSC_PCI_EXPRESS_PME_CONTROL;
  500. if (pci_aer_available()) {
  501. if (aer_acpi_firmware_first())
  502. dev_dbg(root->bus->bridge,
  503. "PCIe errors handled by BIOS.\n");
  504. else
  505. flags |= OSC_PCI_EXPRESS_AER_CONTROL;
  506. }
  507. dev_info(root->bus->bridge,
  508. "Requesting ACPI _OSC control (0x%02x)\n", flags);
  509. status = acpi_pci_osc_control_set(device->handle, &flags,
  510. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
  511. if (ACPI_SUCCESS(status)) {
  512. dev_info(root->bus->bridge,
  513. "ACPI _OSC control (0x%02x) granted\n", flags);
  514. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
  515. /*
  516. * We have ASPM control, but the FADT indicates
  517. * that it's unsupported. Clear it.
  518. */
  519. pcie_clear_aspm(root->bus);
  520. }
  521. } else {
  522. dev_info(root->bus->bridge,
  523. "ACPI _OSC request failed (%s), "
  524. "returned control mask: 0x%02x\n",
  525. acpi_format_exception(status), flags);
  526. pr_info("ACPI _OSC control for PCIe not granted, "
  527. "disabling ASPM\n");
  528. pcie_no_aspm();
  529. }
  530. } else {
  531. dev_info(root->bus->bridge,
  532. "Unable to request _OSC control "
  533. "(_OSC support mask: 0x%02x)\n", flags);
  534. }
  535. pci_acpi_add_bus_pm_notifier(device, root->bus);
  536. if (device->wakeup.flags.run_wake)
  537. device_set_run_wake(root->bus->bridge, true);
  538. return 0;
  539. end:
  540. if (!list_empty(&root->node))
  541. list_del(&root->node);
  542. kfree(root);
  543. return result;
  544. }
  545. static int acpi_pci_root_start(struct acpi_device *device)
  546. {
  547. struct acpi_pci_root *root = acpi_driver_data(device);
  548. pci_bus_add_devices(root->bus);
  549. return 0;
  550. }
  551. static int acpi_pci_root_remove(struct acpi_device *device, int type)
  552. {
  553. struct acpi_pci_root *root = acpi_driver_data(device);
  554. device_set_run_wake(root->bus->bridge, false);
  555. pci_acpi_remove_bus_pm_notifier(device);
  556. kfree(root);
  557. return 0;
  558. }
  559. static int __init acpi_pci_root_init(void)
  560. {
  561. acpi_hest_init();
  562. if (acpi_pci_disabled)
  563. return 0;
  564. pci_acpi_crs_quirks();
  565. if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
  566. return -ENODEV;
  567. return 0;
  568. }
  569. subsys_initcall(acpi_pci_root_init);