pci_root.c 18 KB

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