pci_root.c 18 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/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. int *clear_aspm)
  368. {
  369. u32 support, control, requested;
  370. acpi_status status;
  371. struct acpi_device *device = root->device;
  372. acpi_handle handle = device->handle;
  373. /*
  374. * Apple always return failure on _OSC calls when _OSI("Darwin") has
  375. * been called successfully. We know the feature set supported by the
  376. * platform, so avoid calling _OSC at all
  377. */
  378. if (dmi_match(DMI_SYS_VENDOR, "Apple Inc.")) {
  379. root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL;
  380. decode_osc_control(root, "OS assumes control of",
  381. root->osc_control_set);
  382. return;
  383. }
  384. /*
  385. * All supported architectures that use ACPI have support for
  386. * PCI domains, so we indicate this in _OSC support capabilities.
  387. */
  388. support = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
  389. if (pci_ext_cfg_avail())
  390. support |= OSC_PCI_EXT_CONFIG_SUPPORT;
  391. if (pcie_aspm_support_enabled())
  392. support |= OSC_PCI_ASPM_SUPPORT | OSC_PCI_CLOCK_PM_SUPPORT;
  393. if (pci_msi_enabled())
  394. support |= OSC_PCI_MSI_SUPPORT;
  395. decode_osc_support(root, "OS supports", support);
  396. status = acpi_pci_osc_support(root, support);
  397. if (ACPI_FAILURE(status)) {
  398. dev_info(&device->dev, "_OSC failed (%s); disabling ASPM\n",
  399. acpi_format_exception(status));
  400. *no_aspm = 1;
  401. return;
  402. }
  403. if (pcie_ports_disabled) {
  404. dev_info(&device->dev, "PCIe port services disabled; not requesting _OSC control\n");
  405. return;
  406. }
  407. if ((support & ACPI_PCIE_REQ_SUPPORT) != ACPI_PCIE_REQ_SUPPORT) {
  408. decode_osc_support(root, "not requesting OS control; OS requires",
  409. ACPI_PCIE_REQ_SUPPORT);
  410. return;
  411. }
  412. control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL
  413. | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
  414. | OSC_PCI_EXPRESS_PME_CONTROL;
  415. if (pci_aer_available()) {
  416. if (aer_acpi_firmware_first())
  417. dev_info(&device->dev,
  418. "PCIe AER handled by firmware\n");
  419. else
  420. control |= OSC_PCI_EXPRESS_AER_CONTROL;
  421. }
  422. requested = control;
  423. status = acpi_pci_osc_control_set(handle, &control,
  424. OSC_PCI_EXPRESS_CAPABILITY_CONTROL);
  425. if (ACPI_SUCCESS(status)) {
  426. decode_osc_control(root, "OS now controls", control);
  427. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
  428. /*
  429. * We have ASPM control, but the FADT indicates
  430. * that it's unsupported. Clear it.
  431. */
  432. *clear_aspm = 1;
  433. }
  434. } else {
  435. decode_osc_control(root, "OS requested", requested);
  436. decode_osc_control(root, "platform willing to grant", control);
  437. dev_info(&device->dev, "_OSC failed (%s); disabling ASPM\n",
  438. acpi_format_exception(status));
  439. /*
  440. * We want to disable ASPM here, but aspm_disabled
  441. * needs to remain in its state from boot so that we
  442. * properly handle PCIe 1.1 devices. So we set this
  443. * flag here, to defer the action until after the ACPI
  444. * root scan.
  445. */
  446. *no_aspm = 1;
  447. }
  448. }
  449. static int acpi_pci_root_add(struct acpi_device *device,
  450. const struct acpi_device_id *not_used)
  451. {
  452. unsigned long long segment, bus;
  453. acpi_status status;
  454. int result;
  455. struct acpi_pci_root *root;
  456. acpi_handle handle = device->handle;
  457. int no_aspm = 0, clear_aspm = 0;
  458. bool hotadd = system_state != SYSTEM_BOOTING;
  459. root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
  460. if (!root)
  461. return -ENOMEM;
  462. segment = 0;
  463. status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL,
  464. &segment);
  465. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  466. dev_err(&device->dev, "can't evaluate _SEG\n");
  467. result = -ENODEV;
  468. goto end;
  469. }
  470. /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
  471. root->secondary.flags = IORESOURCE_BUS;
  472. status = try_get_root_bridge_busnr(handle, &root->secondary);
  473. if (ACPI_FAILURE(status)) {
  474. /*
  475. * We need both the start and end of the downstream bus range
  476. * to interpret _CBA (MMCONFIG base address), so it really is
  477. * supposed to be in _CRS. If we don't find it there, all we
  478. * can do is assume [_BBN-0xFF] or [0-0xFF].
  479. */
  480. root->secondary.end = 0xFF;
  481. dev_warn(&device->dev,
  482. FW_BUG "no secondary bus range in _CRS\n");
  483. status = acpi_evaluate_integer(handle, METHOD_NAME__BBN,
  484. NULL, &bus);
  485. if (ACPI_SUCCESS(status))
  486. root->secondary.start = bus;
  487. else if (status == AE_NOT_FOUND)
  488. root->secondary.start = 0;
  489. else {
  490. dev_err(&device->dev, "can't evaluate _BBN\n");
  491. result = -ENODEV;
  492. goto end;
  493. }
  494. }
  495. root->device = device;
  496. root->segment = segment & 0xFFFF;
  497. strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
  498. strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
  499. device->driver_data = root;
  500. if (hotadd && dmar_device_add(handle)) {
  501. result = -ENXIO;
  502. goto end;
  503. }
  504. pr_info(PREFIX "%s [%s] (domain %04x %pR)\n",
  505. acpi_device_name(device), acpi_device_bid(device),
  506. root->segment, &root->secondary);
  507. root->mcfg_addr = acpi_pci_root_get_mcfg_addr(handle);
  508. negotiate_os_control(root, &no_aspm, &clear_aspm);
  509. /*
  510. * TBD: Need PCI interface for enumeration/configuration of roots.
  511. */
  512. /*
  513. * Scan the Root Bridge
  514. * --------------------
  515. * Must do this prior to any attempt to bind the root device, as the
  516. * PCI namespace does not get created until this call is made (and
  517. * thus the root bridge's pci_dev does not exist).
  518. */
  519. root->bus = pci_acpi_scan_root(root);
  520. if (!root->bus) {
  521. dev_err(&device->dev,
  522. "Bus %04x:%02x not present in PCI namespace\n",
  523. root->segment, (unsigned int)root->secondary.start);
  524. device->driver_data = NULL;
  525. result = -ENODEV;
  526. goto remove_dmar;
  527. }
  528. if (clear_aspm) {
  529. dev_info(&device->dev, "Disabling ASPM (FADT indicates it is unsupported)\n");
  530. pcie_clear_aspm(root->bus);
  531. }
  532. if (no_aspm)
  533. pcie_no_aspm();
  534. pci_acpi_add_bus_pm_notifier(device);
  535. if (device->wakeup.flags.run_wake)
  536. device_set_run_wake(root->bus->bridge, true);
  537. if (hotadd) {
  538. pcibios_resource_survey_bus(root->bus);
  539. pci_assign_unassigned_root_bus_resources(root->bus);
  540. acpi_ioapic_add(root);
  541. }
  542. pci_lock_rescan_remove();
  543. pci_bus_add_devices(root->bus);
  544. pci_unlock_rescan_remove();
  545. return 1;
  546. remove_dmar:
  547. if (hotadd)
  548. dmar_device_remove(handle);
  549. end:
  550. kfree(root);
  551. return result;
  552. }
  553. static void acpi_pci_root_remove(struct acpi_device *device)
  554. {
  555. struct acpi_pci_root *root = acpi_driver_data(device);
  556. pci_lock_rescan_remove();
  557. pci_stop_root_bus(root->bus);
  558. WARN_ON(acpi_ioapic_remove(root));
  559. device_set_run_wake(root->bus->bridge, false);
  560. pci_acpi_remove_bus_pm_notifier(device);
  561. pci_remove_root_bus(root->bus);
  562. dmar_device_remove(device->handle);
  563. pci_unlock_rescan_remove();
  564. kfree(root);
  565. }
  566. void __init acpi_pci_root_init(void)
  567. {
  568. acpi_hest_init();
  569. if (acpi_pci_disabled)
  570. return;
  571. pci_acpi_crs_quirks();
  572. acpi_scan_add_handler_with_hotplug(&pci_root_handler, "pci_root");
  573. }