pci-acpi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * File: pci-acpi.c
  3. * Purpose: Provide PCI support in ACPI
  4. *
  5. * Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com>
  6. * Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com>
  7. * Copyright (C) 2004 Intel Corp.
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/init.h>
  11. #include <linux/pci.h>
  12. #include <linux/pci_hotplug.h>
  13. #include <linux/module.h>
  14. #include <linux/pci-aspm.h>
  15. #include <linux/pci-acpi.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/pm_qos.h>
  18. #include "pci.h"
  19. /*
  20. * The UUID is defined in the PCI Firmware Specification available here:
  21. * https://www.pcisig.com/members/downloads/pcifw_r3_1_13Dec10.pdf
  22. */
  23. const u8 pci_acpi_dsm_uuid[] = {
  24. 0xd0, 0x37, 0xc9, 0xe5, 0x53, 0x35, 0x7a, 0x4d,
  25. 0x91, 0x17, 0xea, 0x4d, 0x19, 0xc3, 0x43, 0x4d
  26. };
  27. phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
  28. {
  29. acpi_status status = AE_NOT_EXIST;
  30. unsigned long long mcfg_addr;
  31. if (handle)
  32. status = acpi_evaluate_integer(handle, METHOD_NAME__CBA,
  33. NULL, &mcfg_addr);
  34. if (ACPI_FAILURE(status))
  35. return 0;
  36. return (phys_addr_t)mcfg_addr;
  37. }
  38. static acpi_status decode_type0_hpx_record(union acpi_object *record,
  39. struct hotplug_params *hpx)
  40. {
  41. int i;
  42. union acpi_object *fields = record->package.elements;
  43. u32 revision = fields[1].integer.value;
  44. switch (revision) {
  45. case 1:
  46. if (record->package.count != 6)
  47. return AE_ERROR;
  48. for (i = 2; i < 6; i++)
  49. if (fields[i].type != ACPI_TYPE_INTEGER)
  50. return AE_ERROR;
  51. hpx->t0 = &hpx->type0_data;
  52. hpx->t0->revision = revision;
  53. hpx->t0->cache_line_size = fields[2].integer.value;
  54. hpx->t0->latency_timer = fields[3].integer.value;
  55. hpx->t0->enable_serr = fields[4].integer.value;
  56. hpx->t0->enable_perr = fields[5].integer.value;
  57. break;
  58. default:
  59. printk(KERN_WARNING
  60. "%s: Type 0 Revision %d record not supported\n",
  61. __func__, revision);
  62. return AE_ERROR;
  63. }
  64. return AE_OK;
  65. }
  66. static acpi_status decode_type1_hpx_record(union acpi_object *record,
  67. struct hotplug_params *hpx)
  68. {
  69. int i;
  70. union acpi_object *fields = record->package.elements;
  71. u32 revision = fields[1].integer.value;
  72. switch (revision) {
  73. case 1:
  74. if (record->package.count != 5)
  75. return AE_ERROR;
  76. for (i = 2; i < 5; i++)
  77. if (fields[i].type != ACPI_TYPE_INTEGER)
  78. return AE_ERROR;
  79. hpx->t1 = &hpx->type1_data;
  80. hpx->t1->revision = revision;
  81. hpx->t1->max_mem_read = fields[2].integer.value;
  82. hpx->t1->avg_max_split = fields[3].integer.value;
  83. hpx->t1->tot_max_split = fields[4].integer.value;
  84. break;
  85. default:
  86. printk(KERN_WARNING
  87. "%s: Type 1 Revision %d record not supported\n",
  88. __func__, revision);
  89. return AE_ERROR;
  90. }
  91. return AE_OK;
  92. }
  93. static acpi_status decode_type2_hpx_record(union acpi_object *record,
  94. struct hotplug_params *hpx)
  95. {
  96. int i;
  97. union acpi_object *fields = record->package.elements;
  98. u32 revision = fields[1].integer.value;
  99. switch (revision) {
  100. case 1:
  101. if (record->package.count != 18)
  102. return AE_ERROR;
  103. for (i = 2; i < 18; i++)
  104. if (fields[i].type != ACPI_TYPE_INTEGER)
  105. return AE_ERROR;
  106. hpx->t2 = &hpx->type2_data;
  107. hpx->t2->revision = revision;
  108. hpx->t2->unc_err_mask_and = fields[2].integer.value;
  109. hpx->t2->unc_err_mask_or = fields[3].integer.value;
  110. hpx->t2->unc_err_sever_and = fields[4].integer.value;
  111. hpx->t2->unc_err_sever_or = fields[5].integer.value;
  112. hpx->t2->cor_err_mask_and = fields[6].integer.value;
  113. hpx->t2->cor_err_mask_or = fields[7].integer.value;
  114. hpx->t2->adv_err_cap_and = fields[8].integer.value;
  115. hpx->t2->adv_err_cap_or = fields[9].integer.value;
  116. hpx->t2->pci_exp_devctl_and = fields[10].integer.value;
  117. hpx->t2->pci_exp_devctl_or = fields[11].integer.value;
  118. hpx->t2->pci_exp_lnkctl_and = fields[12].integer.value;
  119. hpx->t2->pci_exp_lnkctl_or = fields[13].integer.value;
  120. hpx->t2->sec_unc_err_sever_and = fields[14].integer.value;
  121. hpx->t2->sec_unc_err_sever_or = fields[15].integer.value;
  122. hpx->t2->sec_unc_err_mask_and = fields[16].integer.value;
  123. hpx->t2->sec_unc_err_mask_or = fields[17].integer.value;
  124. break;
  125. default:
  126. printk(KERN_WARNING
  127. "%s: Type 2 Revision %d record not supported\n",
  128. __func__, revision);
  129. return AE_ERROR;
  130. }
  131. return AE_OK;
  132. }
  133. static acpi_status acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx)
  134. {
  135. acpi_status status;
  136. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  137. union acpi_object *package, *record, *fields;
  138. u32 type;
  139. int i;
  140. /* Clear the return buffer with zeros */
  141. memset(hpx, 0, sizeof(struct hotplug_params));
  142. status = acpi_evaluate_object(handle, "_HPX", NULL, &buffer);
  143. if (ACPI_FAILURE(status))
  144. return status;
  145. package = (union acpi_object *)buffer.pointer;
  146. if (package->type != ACPI_TYPE_PACKAGE) {
  147. status = AE_ERROR;
  148. goto exit;
  149. }
  150. for (i = 0; i < package->package.count; i++) {
  151. record = &package->package.elements[i];
  152. if (record->type != ACPI_TYPE_PACKAGE) {
  153. status = AE_ERROR;
  154. goto exit;
  155. }
  156. fields = record->package.elements;
  157. if (fields[0].type != ACPI_TYPE_INTEGER ||
  158. fields[1].type != ACPI_TYPE_INTEGER) {
  159. status = AE_ERROR;
  160. goto exit;
  161. }
  162. type = fields[0].integer.value;
  163. switch (type) {
  164. case 0:
  165. status = decode_type0_hpx_record(record, hpx);
  166. if (ACPI_FAILURE(status))
  167. goto exit;
  168. break;
  169. case 1:
  170. status = decode_type1_hpx_record(record, hpx);
  171. if (ACPI_FAILURE(status))
  172. goto exit;
  173. break;
  174. case 2:
  175. status = decode_type2_hpx_record(record, hpx);
  176. if (ACPI_FAILURE(status))
  177. goto exit;
  178. break;
  179. default:
  180. printk(KERN_ERR "%s: Type %d record not supported\n",
  181. __func__, type);
  182. status = AE_ERROR;
  183. goto exit;
  184. }
  185. }
  186. exit:
  187. kfree(buffer.pointer);
  188. return status;
  189. }
  190. static acpi_status acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  191. {
  192. acpi_status status;
  193. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  194. union acpi_object *package, *fields;
  195. int i;
  196. memset(hpp, 0, sizeof(struct hotplug_params));
  197. status = acpi_evaluate_object(handle, "_HPP", NULL, &buffer);
  198. if (ACPI_FAILURE(status))
  199. return status;
  200. package = (union acpi_object *) buffer.pointer;
  201. if (package->type != ACPI_TYPE_PACKAGE ||
  202. package->package.count != 4) {
  203. status = AE_ERROR;
  204. goto exit;
  205. }
  206. fields = package->package.elements;
  207. for (i = 0; i < 4; i++) {
  208. if (fields[i].type != ACPI_TYPE_INTEGER) {
  209. status = AE_ERROR;
  210. goto exit;
  211. }
  212. }
  213. hpp->t0 = &hpp->type0_data;
  214. hpp->t0->revision = 1;
  215. hpp->t0->cache_line_size = fields[0].integer.value;
  216. hpp->t0->latency_timer = fields[1].integer.value;
  217. hpp->t0->enable_serr = fields[2].integer.value;
  218. hpp->t0->enable_perr = fields[3].integer.value;
  219. exit:
  220. kfree(buffer.pointer);
  221. return status;
  222. }
  223. /* pci_get_hp_params
  224. *
  225. * @dev - the pci_dev for which we want parameters
  226. * @hpp - allocated by the caller
  227. */
  228. int pci_get_hp_params(struct pci_dev *dev, struct hotplug_params *hpp)
  229. {
  230. acpi_status status;
  231. acpi_handle handle, phandle;
  232. struct pci_bus *pbus;
  233. if (acpi_pci_disabled)
  234. return -ENODEV;
  235. handle = NULL;
  236. for (pbus = dev->bus; pbus; pbus = pbus->parent) {
  237. handle = acpi_pci_get_bridge_handle(pbus);
  238. if (handle)
  239. break;
  240. }
  241. /*
  242. * _HPP settings apply to all child buses, until another _HPP is
  243. * encountered. If we don't find an _HPP for the input pci dev,
  244. * look for it in the parent device scope since that would apply to
  245. * this pci dev.
  246. */
  247. while (handle) {
  248. status = acpi_run_hpx(handle, hpp);
  249. if (ACPI_SUCCESS(status))
  250. return 0;
  251. status = acpi_run_hpp(handle, hpp);
  252. if (ACPI_SUCCESS(status))
  253. return 0;
  254. if (acpi_is_root_bridge(handle))
  255. break;
  256. status = acpi_get_parent(handle, &phandle);
  257. if (ACPI_FAILURE(status))
  258. break;
  259. handle = phandle;
  260. }
  261. return -ENODEV;
  262. }
  263. EXPORT_SYMBOL_GPL(pci_get_hp_params);
  264. /**
  265. * pci_acpi_wake_bus - Root bus wakeup notification fork function.
  266. * @work: Work item to handle.
  267. */
  268. static void pci_acpi_wake_bus(struct work_struct *work)
  269. {
  270. struct acpi_device *adev;
  271. struct acpi_pci_root *root;
  272. adev = container_of(work, struct acpi_device, wakeup.context.work);
  273. root = acpi_driver_data(adev);
  274. pci_pme_wakeup_bus(root->bus);
  275. }
  276. /**
  277. * pci_acpi_wake_dev - PCI device wakeup notification work function.
  278. * @handle: ACPI handle of a device the notification is for.
  279. * @work: Work item to handle.
  280. */
  281. static void pci_acpi_wake_dev(struct work_struct *work)
  282. {
  283. struct acpi_device_wakeup_context *context;
  284. struct pci_dev *pci_dev;
  285. context = container_of(work, struct acpi_device_wakeup_context, work);
  286. pci_dev = to_pci_dev(context->dev);
  287. if (pci_dev->pme_poll)
  288. pci_dev->pme_poll = false;
  289. if (pci_dev->current_state == PCI_D3cold) {
  290. pci_wakeup_event(pci_dev);
  291. pm_runtime_resume(&pci_dev->dev);
  292. return;
  293. }
  294. /* Clear PME Status if set. */
  295. if (pci_dev->pme_support)
  296. pci_check_pme_status(pci_dev);
  297. pci_wakeup_event(pci_dev);
  298. pm_runtime_resume(&pci_dev->dev);
  299. pci_pme_wakeup_bus(pci_dev->subordinate);
  300. }
  301. /**
  302. * pci_acpi_add_bus_pm_notifier - Register PM notifier for root PCI bus.
  303. * @dev: PCI root bridge ACPI device.
  304. */
  305. acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev)
  306. {
  307. return acpi_add_pm_notifier(dev, NULL, pci_acpi_wake_bus);
  308. }
  309. /**
  310. * pci_acpi_add_pm_notifier - Register PM notifier for given PCI device.
  311. * @dev: ACPI device to add the notifier for.
  312. * @pci_dev: PCI device to check for the PME status if an event is signaled.
  313. */
  314. acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
  315. struct pci_dev *pci_dev)
  316. {
  317. return acpi_add_pm_notifier(dev, &pci_dev->dev, pci_acpi_wake_dev);
  318. }
  319. /*
  320. * _SxD returns the D-state with the highest power
  321. * (lowest D-state number) supported in the S-state "x".
  322. *
  323. * If the devices does not have a _PRW
  324. * (Power Resources for Wake) supporting system wakeup from "x"
  325. * then the OS is free to choose a lower power (higher number
  326. * D-state) than the return value from _SxD.
  327. *
  328. * But if _PRW is enabled at S-state "x", the OS
  329. * must not choose a power lower than _SxD --
  330. * unless the device has an _SxW method specifying
  331. * the lowest power (highest D-state number) the device
  332. * may enter while still able to wake the system.
  333. *
  334. * ie. depending on global OS policy:
  335. *
  336. * if (_PRW at S-state x)
  337. * choose from highest power _SxD to lowest power _SxW
  338. * else // no _PRW at S-state x
  339. * choose highest power _SxD or any lower power
  340. */
  341. static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
  342. {
  343. int acpi_state, d_max;
  344. if (pdev->no_d3cold)
  345. d_max = ACPI_STATE_D3_HOT;
  346. else
  347. d_max = ACPI_STATE_D3_COLD;
  348. acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL, d_max);
  349. if (acpi_state < 0)
  350. return PCI_POWER_ERROR;
  351. switch (acpi_state) {
  352. case ACPI_STATE_D0:
  353. return PCI_D0;
  354. case ACPI_STATE_D1:
  355. return PCI_D1;
  356. case ACPI_STATE_D2:
  357. return PCI_D2;
  358. case ACPI_STATE_D3_HOT:
  359. return PCI_D3hot;
  360. case ACPI_STATE_D3_COLD:
  361. return PCI_D3cold;
  362. }
  363. return PCI_POWER_ERROR;
  364. }
  365. static bool acpi_pci_power_manageable(struct pci_dev *dev)
  366. {
  367. struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
  368. return adev ? acpi_device_power_manageable(adev) : false;
  369. }
  370. static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
  371. {
  372. struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
  373. static const u8 state_conv[] = {
  374. [PCI_D0] = ACPI_STATE_D0,
  375. [PCI_D1] = ACPI_STATE_D1,
  376. [PCI_D2] = ACPI_STATE_D2,
  377. [PCI_D3hot] = ACPI_STATE_D3_HOT,
  378. [PCI_D3cold] = ACPI_STATE_D3_COLD,
  379. };
  380. int error = -EINVAL;
  381. /* If the ACPI device has _EJ0, ignore the device */
  382. if (!adev || acpi_has_method(adev->handle, "_EJ0"))
  383. return -ENODEV;
  384. switch (state) {
  385. case PCI_D3cold:
  386. if (dev_pm_qos_flags(&dev->dev, PM_QOS_FLAG_NO_POWER_OFF) ==
  387. PM_QOS_FLAGS_ALL) {
  388. error = -EBUSY;
  389. break;
  390. }
  391. case PCI_D0:
  392. case PCI_D1:
  393. case PCI_D2:
  394. case PCI_D3hot:
  395. error = acpi_device_set_power(adev, state_conv[state]);
  396. }
  397. if (!error)
  398. dev_dbg(&dev->dev, "power state changed by ACPI to %s\n",
  399. acpi_power_state_string(state_conv[state]));
  400. return error;
  401. }
  402. static bool acpi_pci_can_wakeup(struct pci_dev *dev)
  403. {
  404. struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
  405. return adev ? acpi_device_can_wakeup(adev) : false;
  406. }
  407. static void acpi_pci_propagate_wakeup_enable(struct pci_bus *bus, bool enable)
  408. {
  409. while (bus->parent) {
  410. if (!acpi_pm_device_sleep_wake(&bus->self->dev, enable))
  411. return;
  412. bus = bus->parent;
  413. }
  414. /* We have reached the root bus. */
  415. if (bus->bridge)
  416. acpi_pm_device_sleep_wake(bus->bridge, enable);
  417. }
  418. static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable)
  419. {
  420. if (acpi_pci_can_wakeup(dev))
  421. return acpi_pm_device_sleep_wake(&dev->dev, enable);
  422. acpi_pci_propagate_wakeup_enable(dev->bus, enable);
  423. return 0;
  424. }
  425. static void acpi_pci_propagate_run_wake(struct pci_bus *bus, bool enable)
  426. {
  427. while (bus->parent) {
  428. struct pci_dev *bridge = bus->self;
  429. if (bridge->pme_interrupt)
  430. return;
  431. if (!acpi_pm_device_run_wake(&bridge->dev, enable))
  432. return;
  433. bus = bus->parent;
  434. }
  435. /* We have reached the root bus. */
  436. if (bus->bridge)
  437. acpi_pm_device_run_wake(bus->bridge, enable);
  438. }
  439. static int acpi_pci_run_wake(struct pci_dev *dev, bool enable)
  440. {
  441. /*
  442. * Per PCI Express Base Specification Revision 2.0 section
  443. * 5.3.3.2 Link Wakeup, platform support is needed for D3cold
  444. * waking up to power on the main link even if there is PME
  445. * support for D3cold
  446. */
  447. if (dev->pme_interrupt && !dev->runtime_d3cold)
  448. return 0;
  449. if (!acpi_pm_device_run_wake(&dev->dev, enable))
  450. return 0;
  451. acpi_pci_propagate_run_wake(dev->bus, enable);
  452. return 0;
  453. }
  454. static bool acpi_pci_need_resume(struct pci_dev *dev)
  455. {
  456. struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
  457. if (!adev || !acpi_device_power_manageable(adev))
  458. return false;
  459. if (device_may_wakeup(&dev->dev) != !!adev->wakeup.prepare_count)
  460. return true;
  461. if (acpi_target_system_state() == ACPI_STATE_S0)
  462. return false;
  463. return !!adev->power.flags.dsw_present;
  464. }
  465. static struct pci_platform_pm_ops acpi_pci_platform_pm = {
  466. .is_manageable = acpi_pci_power_manageable,
  467. .set_state = acpi_pci_set_power_state,
  468. .choose_state = acpi_pci_choose_state,
  469. .sleep_wake = acpi_pci_sleep_wake,
  470. .run_wake = acpi_pci_run_wake,
  471. .need_resume = acpi_pci_need_resume,
  472. };
  473. void acpi_pci_add_bus(struct pci_bus *bus)
  474. {
  475. union acpi_object *obj;
  476. struct pci_host_bridge *bridge;
  477. if (acpi_pci_disabled || !bus->bridge || !ACPI_HANDLE(bus->bridge))
  478. return;
  479. acpi_pci_slot_enumerate(bus);
  480. acpiphp_enumerate_slots(bus);
  481. /*
  482. * For a host bridge, check its _DSM for function 8 and if
  483. * that is available, mark it in pci_host_bridge.
  484. */
  485. if (!pci_is_root_bus(bus))
  486. return;
  487. obj = acpi_evaluate_dsm(ACPI_HANDLE(bus->bridge), pci_acpi_dsm_uuid, 3,
  488. RESET_DELAY_DSM, NULL);
  489. if (!obj)
  490. return;
  491. if (obj->type == ACPI_TYPE_INTEGER && obj->integer.value == 1) {
  492. bridge = pci_find_host_bridge(bus);
  493. bridge->ignore_reset_delay = 1;
  494. }
  495. ACPI_FREE(obj);
  496. }
  497. void acpi_pci_remove_bus(struct pci_bus *bus)
  498. {
  499. if (acpi_pci_disabled || !bus->bridge)
  500. return;
  501. acpiphp_remove_slots(bus);
  502. acpi_pci_slot_remove(bus);
  503. }
  504. /* ACPI bus type */
  505. static struct acpi_device *acpi_pci_find_companion(struct device *dev)
  506. {
  507. struct pci_dev *pci_dev = to_pci_dev(dev);
  508. bool check_children;
  509. u64 addr;
  510. check_children = pci_is_bridge(pci_dev);
  511. /* Please ref to ACPI spec for the syntax of _ADR */
  512. addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
  513. return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
  514. check_children);
  515. }
  516. /**
  517. * pci_acpi_optimize_delay - optimize PCI D3 and D3cold delay from ACPI
  518. * @pdev: the PCI device whose delay is to be updated
  519. * @handle: ACPI handle of this device
  520. *
  521. * Update the d3_delay and d3cold_delay of a PCI device from the ACPI _DSM
  522. * control method of either the device itself or the PCI host bridge.
  523. *
  524. * Function 8, "Reset Delay," applies to the entire hierarchy below a PCI
  525. * host bridge. If it returns one, the OS may assume that all devices in
  526. * the hierarchy have already completed power-on reset delays.
  527. *
  528. * Function 9, "Device Readiness Durations," applies only to the object
  529. * where it is located. It returns delay durations required after various
  530. * events if the device requires less time than the spec requires. Delays
  531. * from this function take precedence over the Reset Delay function.
  532. *
  533. * These _DSM functions are defined by the draft ECN of January 28, 2014,
  534. * titled "ACPI additions for FW latency optimizations."
  535. */
  536. static void pci_acpi_optimize_delay(struct pci_dev *pdev,
  537. acpi_handle handle)
  538. {
  539. struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus);
  540. int value;
  541. union acpi_object *obj, *elements;
  542. if (bridge->ignore_reset_delay)
  543. pdev->d3cold_delay = 0;
  544. obj = acpi_evaluate_dsm(handle, pci_acpi_dsm_uuid, 3,
  545. FUNCTION_DELAY_DSM, NULL);
  546. if (!obj)
  547. return;
  548. if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 5) {
  549. elements = obj->package.elements;
  550. if (elements[0].type == ACPI_TYPE_INTEGER) {
  551. value = (int)elements[0].integer.value / 1000;
  552. if (value < PCI_PM_D3COLD_WAIT)
  553. pdev->d3cold_delay = value;
  554. }
  555. if (elements[3].type == ACPI_TYPE_INTEGER) {
  556. value = (int)elements[3].integer.value / 1000;
  557. if (value < PCI_PM_D3_WAIT)
  558. pdev->d3_delay = value;
  559. }
  560. }
  561. ACPI_FREE(obj);
  562. }
  563. static void pci_acpi_setup(struct device *dev)
  564. {
  565. struct pci_dev *pci_dev = to_pci_dev(dev);
  566. struct acpi_device *adev = ACPI_COMPANION(dev);
  567. if (!adev)
  568. return;
  569. pci_acpi_optimize_delay(pci_dev, adev->handle);
  570. pci_acpi_add_pm_notifier(adev, pci_dev);
  571. if (!adev->wakeup.flags.valid)
  572. return;
  573. device_set_wakeup_capable(dev, true);
  574. acpi_pci_sleep_wake(pci_dev, false);
  575. if (adev->wakeup.flags.run_wake)
  576. device_set_run_wake(dev, true);
  577. }
  578. static void pci_acpi_cleanup(struct device *dev)
  579. {
  580. struct acpi_device *adev = ACPI_COMPANION(dev);
  581. if (!adev)
  582. return;
  583. pci_acpi_remove_pm_notifier(adev);
  584. if (adev->wakeup.flags.valid) {
  585. device_set_wakeup_capable(dev, false);
  586. device_set_run_wake(dev, false);
  587. }
  588. }
  589. static bool pci_acpi_bus_match(struct device *dev)
  590. {
  591. return dev_is_pci(dev);
  592. }
  593. static struct acpi_bus_type acpi_pci_bus = {
  594. .name = "PCI",
  595. .match = pci_acpi_bus_match,
  596. .find_companion = acpi_pci_find_companion,
  597. .setup = pci_acpi_setup,
  598. .cleanup = pci_acpi_cleanup,
  599. };
  600. static int __init acpi_pci_init(void)
  601. {
  602. int ret;
  603. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) {
  604. pr_info("ACPI FADT declares the system doesn't support MSI, so disable it\n");
  605. pci_no_msi();
  606. }
  607. if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
  608. pr_info("ACPI FADT declares the system doesn't support PCIe ASPM, so disable it\n");
  609. pcie_no_aspm();
  610. }
  611. ret = register_acpi_bus_type(&acpi_pci_bus);
  612. if (ret)
  613. return 0;
  614. pci_set_platform_pm(&acpi_pci_platform_pm);
  615. acpi_pci_slot_init();
  616. acpiphp_init();
  617. return 0;
  618. }
  619. arch_initcall(acpi_pci_init);