pci_root.c 17 KB

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