Lines Matching +full:broken +full:- +full:prefetch +full:- +full:cmd
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
6 * David Mosberger-Tang
8 * Copyright 1997 -- 2000 Martin Mares <mj@ucw.cz>
69 unsigned int delay = dev->d3hot_delay; in pci_dev_d3_sleep()
70 int err = -EOPNOTSUPP; in pci_dev_d3_sleep()
77 if (err == -EOPNOTSUPP) in pci_dev_d3_sleep()
98 * pci=hpmmiosize=nnM overrides non-prefetchable MMIO size,
109 /* PCIe MPS/MRRS strategy; can be overridden by kernel command-line param */
126 * measured in 32-bit words, not bytes.
171 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
182 max = bus->busn_res.end; in pci_bus_max_busnr()
183 list_for_each_entry(tmp, &bus->children, node) { in pci_bus_max_busnr()
193 * pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS
205 return -EIO; in pci_status_get_and_clear_errors()
218 struct resource *res = &pdev->resource[bar]; in pci_ioremap_bar()
223 if (res->flags & IORESOURCE_UNSET || !(res->flags & IORESOURCE_MEM)) { in pci_ioremap_bar()
227 return ioremap(res->start, resource_size(res)); in pci_ioremap_bar()
247 * pci_dev_str_match_path - test if a path string matches a device
258 * A path for a device can be obtained using 'lspci -t'. Using a path
275 wpath = kmemdup_nul(path, *endptr - path, GFP_ATOMIC); in pci_dev_str_match_path()
277 return -ENOMEM; in pci_dev_str_match_path()
285 ret = -EINVAL; in pci_dev_str_match_path()
289 if (dev->devfn != PCI_DEVFN(slot, func)) { in pci_dev_str_match_path()
315 ret = -EINVAL; in pci_dev_str_match_path()
320 ret = (seg == pci_domain_nr(dev->bus) && in pci_dev_str_match_path()
321 bus == dev->bus->number && in pci_dev_str_match_path()
322 dev->devfn == PCI_DEVFN(slot, func)); in pci_dev_str_match_path()
330 * pci_dev_str_match - test if a string matches a device
347 * through the use of 'lspci -t'.
352 * in-kernel code that uses PCI_ANY_ID which is ~0; this is for
374 return -EINVAL; in pci_dev_str_match()
382 if ((!vendor || vendor == dev->vendor) && in pci_dev_str_match()
383 (!device || device == dev->device) && in pci_dev_str_match()
385 subsystem_vendor == dev->subsystem_vendor) && in pci_dev_str_match()
387 subsystem_device == dev->subsystem_device)) in pci_dev_str_match()
417 while ((*ttl)--) { in __pci_find_next_cap_ttl()
443 return __pci_find_next_cap(dev->bus, dev->devfn, in pci_find_next_capability()
469 * pci_find_capability - query for devices' capabilities
484 * %PCI_CAP_ID_PCIX PCI-X
491 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type); in pci_find_capability()
493 pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap); in pci_find_capability()
500 * pci_bus_find_capability - query for devices' capabilities
528 * pci_find_next_ext_capability - Find an extended capability
536 * vendor-specific capability, and this provides a way to find them all.
545 ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; in pci_find_next_ext_capability()
547 if (dev->cfg_size <= PCI_CFG_SPACE_SIZE) in pci_find_next_ext_capability()
563 while (ttl-- > 0) { in pci_find_next_ext_capability()
580 * pci_find_ext_capability - Find an extended capability
600 * pci_get_dsn - Read and return the 8-byte Device Serial Number
643 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos, in __pci_find_next_ht_cap()
653 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, in __pci_find_next_ht_cap()
661 * pci_find_next_ht_capability - query a device's Hypertransport capabilities
670 * NB. To be 100% safe against broken PCI devices, the caller should take
680 * pci_find_ht_capability - query a device's Hypertransport capabilities
694 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type); in pci_find_ht_capability()
703 * pci_find_parent_resource - return resource region of parent bus of given
714 const struct pci_bus *bus = dev->bus; in pci_find_parent_resource()
727 if (r->flags & IORESOURCE_PREFETCH && in pci_find_parent_resource()
728 !(res->flags & IORESOURCE_PREFETCH)) in pci_find_parent_resource()
733 * be both a positively-decoded aperture and a in pci_find_parent_resource()
734 * subtractively-decoded region that contain the BAR. in pci_find_parent_resource()
735 * We want the positively-decoded one, so this depends in pci_find_parent_resource()
747 * pci_find_resource - Return matching PCI device resource
760 struct resource *r = &dev->resource[i]; in pci_find_resource()
762 if (r->start && resource_contains(r, res)) in pci_find_resource()
771 * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
786 msleep((1 << (i - 1)) * 100); in pci_wait_for_pending()
799 * pci_request_acs - ask for ACS to be enabled if supported
809 * pci_disable_acs_redir - disable ACS redirect capabilities
850 pos = dev->acs_cap; in pci_disable_acs_redir()
867 * pci_std_enable_acs - enable ACS on devices using standard ACS capabilities
876 pos = dev->acs_cap; in pci_std_enable_acs()
896 if (dev->external_facing || dev->untrusted) in pci_std_enable_acs()
903 * pci_enable_acs - enable ACS if hardware support it
928 * pci_restore_bars - restore a device's BAR values (e.g. after wake-up)
946 if (!ops->is_manageable || !ops->set_state || !ops->get_state || in pci_set_platform_pm()
947 !ops->choose_state || !ops->set_wakeup || !ops->need_resume) in pci_set_platform_pm()
948 return -EINVAL; in pci_set_platform_pm()
955 return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false; in platform_pci_power_manageable()
961 return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS; in platform_pci_set_power_state()
966 return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN; in platform_pci_get_power_state()
971 if (pci_platform_pm && pci_platform_pm->refresh_state) in platform_pci_refresh_power_state()
972 pci_platform_pm->refresh_state(dev); in platform_pci_refresh_power_state()
978 pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR; in platform_pci_choose_state()
984 pci_platform_pm->set_wakeup(dev, enable) : -ENODEV; in platform_pci_set_wakeup()
989 return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false; in platform_pci_need_resume()
994 if (pci_platform_pm && pci_platform_pm->bridge_d3) in platform_pci_bridge_d3()
995 return pci_platform_pm->bridge_d3(dev); in platform_pci_bridge_d3()
1000 * pci_raw_set_power_state - Use PCI PM registers to set the power state of
1006 * -EINVAL if the requested state is invalid.
1007 * -EIO if device does not support PCI PM or its PM capabilities register has a
1018 if (dev->current_state == state) in pci_raw_set_power_state()
1021 if (!dev->pm_cap) in pci_raw_set_power_state()
1022 return -EIO; in pci_raw_set_power_state()
1025 return -EINVAL; in pci_raw_set_power_state()
1029 * we're already in a low-power state, we can only go deeper. E.g., in pci_raw_set_power_state()
1033 if (state != PCI_D0 && dev->current_state <= PCI_D3cold in pci_raw_set_power_state()
1034 && dev->current_state > state) { in pci_raw_set_power_state()
1036 pci_power_name(dev->current_state), in pci_raw_set_power_state()
1038 return -EINVAL; in pci_raw_set_power_state()
1042 if ((state == PCI_D1 && !dev->d1_support) in pci_raw_set_power_state()
1043 || (state == PCI_D2 && !dev->d2_support)) in pci_raw_set_power_state()
1044 return -EIO; in pci_raw_set_power_state()
1046 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); in pci_raw_set_power_state()
1049 pci_power_name(dev->current_state), in pci_raw_set_power_state()
1051 return -EIO; in pci_raw_set_power_state()
1059 switch (dev->current_state) { in pci_raw_set_power_state()
1068 case PCI_UNKNOWN: /* Boot-up */ in pci_raw_set_power_state()
1079 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); in pci_raw_set_power_state()
1085 if (state == PCI_D3hot || dev->current_state == PCI_D3hot) in pci_raw_set_power_state()
1087 else if (state == PCI_D2 || dev->current_state == PCI_D2) in pci_raw_set_power_state()
1090 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); in pci_raw_set_power_state()
1091 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); in pci_raw_set_power_state()
1092 if (dev->current_state != state) in pci_raw_set_power_state()
1094 pci_power_name(dev->current_state), in pci_raw_set_power_state()
1113 if (dev->bus->self) in pci_raw_set_power_state()
1114 pcie_aspm_pm_state_change(dev->bus->self); in pci_raw_set_power_state()
1120 * pci_update_current_state - Read power state of given device and cache it
1135 dev->current_state = PCI_D3cold; in pci_update_current_state()
1136 } else if (dev->pm_cap) { in pci_update_current_state()
1139 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); in pci_update_current_state()
1140 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); in pci_update_current_state()
1142 dev->current_state = state; in pci_update_current_state()
1147 * pci_refresh_power_state - Refresh the given device's power state data
1158 pci_update_current_state(dev, dev->current_state); in pci_refresh_power_state()
1162 * pci_platform_power_transition - Use platform to change device power state
1175 error = -ENODEV; in pci_platform_power_transition()
1177 if (error && !dev->pm_cap) /* Fall back to PCI_D0 */ in pci_platform_power_transition()
1178 dev->current_state = PCI_D0; in pci_platform_power_transition()
1185 * pci_wakeup - Wake up a PCI device
1192 pm_request_resume(&pci_dev->dev); in pci_wakeup()
1197 * pci_wakeup_bus - Walk given bus and wake up devices on it
1219 * Wait for the device to return a non-CRS completion. Read the in pci_dev_wait()
1227 delay - 1, reset_type); in pci_dev_wait()
1228 return -ENOTTY; in pci_dev_wait()
1233 delay - 1, reset_type); in pci_dev_wait()
1241 pci_info(dev, "ready %dms after %s\n", delay - 1, in pci_dev_wait()
1248 * pci_power_up - Put the given device into D0
1260 if (dev->runtime_d3cold) { in pci_power_up()
1266 pci_wakeup_bus(dev->subordinate); in pci_power_up()
1273 * __pci_dev_set_current_state - Set current state of a PCI device
1281 dev->current_state = state; in __pci_dev_set_current_state()
1286 * pci_bus_set_current_state - Walk given bus and set current state of devices
1297 * pci_set_power_state - Set the power state of a PCI device
1305 * -EINVAL if the requested state is invalid.
1306 * -EIO if device does not support PCI PM or its PM capabilities register has a
1333 if (dev->current_state == state) in pci_set_power_state()
1343 if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) in pci_set_power_state()
1358 pci_bus_set_current_state(dev->subordinate, PCI_D3cold); in pci_set_power_state()
1365 * pci_choose_state - Choose the power state of a PCI device
1377 if (!dev->pm_cap) in pci_choose_state()
1389 /* REVISIT both freeze and pre-thaw "should" use D0 */ in pci_choose_state()
1409 hlist_for_each_entry(tmp, &pci_dev->saved_cap_space, next) { in _pci_find_saved_cap()
1410 if (tmp->cap.cap_extended == extended && tmp->cap.cap_nr == cap) in _pci_find_saved_cap()
1438 return -ENOMEM; in pci_save_pcie_state()
1441 cap = (u16 *)&save_state->cap.data[0]; in pci_save_pcie_state()
1463 cap = (u16 *)&save_state->cap.data[0]; in pci_restore_pcie_state()
1485 return -ENOMEM; in pci_save_pcix_state()
1489 (u16 *)save_state->cap.data); in pci_save_pcix_state()
1504 cap = (u16 *)&save_state->cap.data[0]; in pci_restore_pcix_state()
1528 cap = (u16 *)&save_state->cap.data[0]; in pci_save_ltr_state()
1544 cap = (u16 *)&save_state->cap.data[0]; in pci_restore_ltr_state()
1550 * pci_save_state - save the PCI configuration space of a device before
1559 pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]); in pci_save_state()
1561 i * 4, dev->saved_config_space[i]); in pci_save_state()
1563 dev->state_saved = true; in pci_save_state()
1593 if (retry-- <= 0) in pci_restore_config_dword()
1610 for (index = end; index >= start; index--) in pci_restore_config_space_range()
1612 pdev->saved_config_space[index], in pci_restore_config_space_range()
1618 if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) { in pci_restore_config_space()
1623 } else if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { in pci_restore_config_space()
1627 * Force rewriting of prefetch registers to avoid S3 resume in pci_restore_config_space()
1657 res = pdev->resource + bar_idx; in pci_restore_rebar_state()
1658 size = ilog2(resource_size(res)) - 20; in pci_restore_rebar_state()
1666 * pci_restore_state - Restore the saved state of a PCI device
1671 if (!dev->state_saved) in pci_restore_state()
1700 dev->state_saved = false; in pci_restore_state()
1710 * pci_store_saved_state - Allocate and return an opaque struct containing
1723 if (!dev->state_saved) in pci_store_saved_state()
1728 hlist_for_each_entry(tmp, &dev->saved_cap_space, next) in pci_store_saved_state()
1729 size += sizeof(struct pci_cap_saved_data) + tmp->cap.size; in pci_store_saved_state()
1735 memcpy(state->config_space, dev->saved_config_space, in pci_store_saved_state()
1736 sizeof(state->config_space)); in pci_store_saved_state()
1738 cap = state->cap; in pci_store_saved_state()
1739 hlist_for_each_entry(tmp, &dev->saved_cap_space, next) { in pci_store_saved_state()
1740 size_t len = sizeof(struct pci_cap_saved_data) + tmp->cap.size; in pci_store_saved_state()
1741 memcpy(cap, &tmp->cap, len); in pci_store_saved_state()
1751 * pci_load_saved_state - Reload the provided save state into struct pci_dev.
1760 dev->state_saved = false; in pci_load_saved_state()
1765 memcpy(dev->saved_config_space, state->config_space, in pci_load_saved_state()
1766 sizeof(state->config_space)); in pci_load_saved_state()
1768 cap = state->cap; in pci_load_saved_state()
1769 while (cap->size) { in pci_load_saved_state()
1772 tmp = _pci_find_saved_cap(dev, cap->cap_nr, cap->cap_extended); in pci_load_saved_state()
1773 if (!tmp || tmp->cap.size != cap->size) in pci_load_saved_state()
1774 return -EINVAL; in pci_load_saved_state()
1776 memcpy(tmp->cap.data, cap->data, tmp->cap.size); in pci_load_saved_state()
1778 sizeof(struct pci_cap_saved_data) + cap->size); in pci_load_saved_state()
1781 dev->state_saved = true; in pci_load_saved_state()
1787 * pci_load_and_free_saved_state - Reload the save state pointed to by state,
1811 u16 cmd; in do_pci_enable_device() local
1815 if (err < 0 && err != -EIO) in do_pci_enable_device()
1827 if (dev->msi_enabled || dev->msix_enabled) in do_pci_enable_device()
1832 pci_read_config_word(dev, PCI_COMMAND, &cmd); in do_pci_enable_device()
1833 if (cmd & PCI_COMMAND_INTX_DISABLE) in do_pci_enable_device()
1835 cmd & ~PCI_COMMAND_INTX_DISABLE); in do_pci_enable_device()
1842 * pci_reenable_device - Resume abandoned device
1851 return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1); in pci_reenable_device()
1866 if (!dev->is_busmaster) in pci_enable_bridge()
1890 pci_update_current_state(dev, dev->current_state); in pci_enable_device_flags()
1892 if (atomic_inc_return(&dev->enable_cnt) > 1) in pci_enable_device_flags()
1901 if (dev->resource[i].flags & flags) in pci_enable_device_flags()
1904 if (dev->resource[i].flags & flags) in pci_enable_device_flags()
1909 atomic_dec(&dev->enable_cnt); in pci_enable_device_flags()
1914 * pci_enable_device_io - Initialize a device for use with IO space
1917 * Initialize device before it's used by a driver. Ask low-level code
1928 * pci_enable_device_mem - Initialize a device for use with Memory space
1931 * Initialize device before it's used by a driver. Ask low-level code
1942 * pci_enable_device - Initialize device before it's used by a driver.
1945 * Initialize device before it's used by a driver. Ask low-level code
1959 * Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X
1960 * on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so
1979 if (dev->msi_enabled) in pcim_release()
1981 if (dev->msix_enabled) in pcim_release()
1985 if (this->region_mask & (1 << i)) in pcim_release()
1988 if (this->mwi) in pcim_release()
1991 if (this->restore_intx) in pcim_release()
1992 pci_intx(dev, this->orig_intx); in pcim_release()
1994 if (this->enabled && !this->pinned) in pcim_release()
2002 dr = devres_find(&pdev->dev, pcim_release, NULL, NULL); in get_pci_dr()
2009 return devres_get(&pdev->dev, new_dr, NULL, NULL); in get_pci_dr()
2015 return devres_find(&pdev->dev, pcim_release, NULL, NULL); in find_pci_dr()
2020 * pcim_enable_device - Managed pci_enable_device()
2032 return -ENOMEM; in pcim_enable_device()
2033 if (dr->enabled) in pcim_enable_device()
2038 pdev->is_managed = 1; in pcim_enable_device()
2039 dr->enabled = 1; in pcim_enable_device()
2046 * pcim_pin_device - Pin managed PCI device
2058 WARN_ON(!dr || !dr->enabled); in pcim_pin_device()
2060 dr->pinned = 1; in pcim_pin_device()
2065 * pcibios_add_device - provide arch specific hooks when adding device dev
2078 * pcibios_release_device - provide arch specific hooks when releasing
2089 * pcibios_disable_device - disable arch specific PCI resources for device dev
2099 * pcibios_penalize_isa_irq - penalize an ISA IRQ
2103 * Permits the platform to provide architecture-specific functionality when
2123 * pci_disable_enabled_device - Disable device without updating enable_cnt
2136 * pci_disable_device - Disable PCI device after use
2140 * anymore. This only involves disabling PCI bus-mastering, if active.
2151 dr->enabled = 0; in pci_disable_device()
2153 dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, in pci_disable_device()
2154 "disabling already-disabled device"); in pci_disable_device()
2156 if (atomic_dec_return(&dev->enable_cnt) != 0) in pci_disable_device()
2161 dev->is_busmaster = 0; in pci_disable_device()
2166 * pcibios_set_pcie_reset_state - set reset state for device dev
2176 return -EINVAL; in pcibios_set_pcie_reset_state()
2180 * pci_set_pcie_reset_state - set reset state for device dev
2201 * pcie_clear_root_pme_status - Clear root port PME interrupt status.
2210 * pci_check_pme_status - Check if given device has generated PME.
2223 if (!dev->pm_cap) in pci_check_pme_status()
2226 pmcsr_pos = dev->pm_cap + PCI_PM_CTRL; in pci_check_pme_status()
2245 * pci_pme_wakeup - Wake up a PCI device if its PME Status bit is set.
2254 if (pme_poll_reset && dev->pme_poll) in pci_pme_wakeup()
2255 dev->pme_poll = false; in pci_pme_wakeup()
2259 pm_request_resume(&dev->dev); in pci_pme_wakeup()
2265 * pci_pme_wakeup_bus - Walk given bus and wake up devices on it, if necessary.
2276 * pci_pme_capable - check the capability of PCI device to generate PME#
2282 if (!dev->pm_cap) in pci_pme_capable()
2285 return !!(dev->pme_support & (1 << state)); in pci_pme_capable()
2295 if (pme_dev->dev->pme_poll) { in pci_pme_list_scan()
2298 bridge = pme_dev->dev->bus->self; in pci_pme_list_scan()
2304 if (bridge && bridge->current_state != PCI_D0) in pci_pme_list_scan()
2310 if (pme_dev->dev->current_state == PCI_D3cold) in pci_pme_list_scan()
2313 pci_pme_wakeup(pme_dev->dev, NULL); in pci_pme_list_scan()
2315 list_del(&pme_dev->list); in pci_pme_list_scan()
2329 if (!dev->pme_support) in __pci_pme_active()
2332 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); in __pci_pme_active()
2338 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); in __pci_pme_active()
2342 * pci_pme_restore - Restore PME configuration after config space restore.
2349 if (!dev->pme_support) in pci_pme_restore()
2352 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); in pci_pme_restore()
2353 if (dev->wakeup_prepared) { in pci_pme_restore()
2360 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); in pci_pme_restore()
2364 * pci_pme_active - enable or disable PCI device's PME# function
2386 * Although PCIe uses in-band PME message instead of PME# line in pci_pme_active()
2395 if (dev->pme_poll) { in pci_pme_active()
2404 pme_dev->dev = dev; in pci_pme_active()
2406 list_add(&pme_dev->list, &pci_pme_list); in pci_pme_active()
2415 if (pme_dev->dev == dev) { in pci_pme_active()
2416 list_del(&pme_dev->list); in pci_pme_active()
2430 * __pci_enable_wake - enable PCI device as wakeup event source
2436 * When such events involves platform-specific hooks, those hooks are
2444 * -EINVAL is returned if device is not supposed to wake up the system
2446 * the native mechanism fail to enable the generation of wake-up events
2453 * Bridges that are not power-manageable directly only signal in __pci_enable_wake()
2456 * power-manageable may signal wakeup for themselves (for example, in __pci_enable_wake()
2463 if (!!enable == !!dev->wakeup_prepared) in __pci_enable_wake()
2469 * enable. To disable wake-up we call the platform first, for symmetry. in __pci_enable_wake()
2490 dev->wakeup_prepared = true; in __pci_enable_wake()
2494 dev->wakeup_prepared = false; in __pci_enable_wake()
2501 * pci_enable_wake - change wakeup settings for a PCI device
2511 if (enable && !device_may_wakeup(&pci_dev->dev)) in pci_enable_wake()
2512 return -EINVAL; in pci_enable_wake()
2519 * pci_wake_from_d3 - enable/disable device to wake up from D3_hot or D3_cold
2521 * @enable: True to enable wake-up event generation; false to disable
2524 * and this function allows them to set that up cleanly - pci_enable_wake()
2525 * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI
2530 * D3_hot and D3_cold and the platform is unable to enable wake-up power for it.
2541 * pci_target_state - find an appropriate low power state for a given PCI dev
2575 if (!dev->pm_cap) in pci_target_state()
2579 * If the device is in D3cold even though it's not power-manageable by in pci_target_state()
2580 * the platform, it may have been powered down by non-standard means. in pci_target_state()
2583 if (dev->current_state == PCI_D3cold) in pci_target_state()
2586 if (wakeup && dev->pme_support) { in pci_target_state()
2593 while (state && !(dev->pme_support & (1 << state))) in pci_target_state()
2594 state--; in pci_target_state()
2598 else if (dev->pme_support & 1) in pci_target_state()
2606 * pci_prepare_to_sleep - prepare PCI device for system-wide transition
2616 bool wakeup = device_may_wakeup(&dev->dev); in pci_prepare_to_sleep()
2621 return -EIO; in pci_prepare_to_sleep()
2635 * pci_back_from_sleep - turn PCI device on during system-wide transition
2639 * Disable device's system wake-up capability and put it into D0.
2649 * pci_finish_runtime_suspend - Carry out PCI-specific part of runtime suspend.
2652 * Prepare @dev to generate wake-up events at run time and put it into a low
2660 target_state = pci_target_state(dev, device_can_wakeup(&dev->dev)); in pci_finish_runtime_suspend()
2662 return -EIO; in pci_finish_runtime_suspend()
2664 dev->runtime_d3cold = target_state == PCI_D3cold; in pci_finish_runtime_suspend()
2672 dev->runtime_d3cold = false; in pci_finish_runtime_suspend()
2679 * pci_dev_run_wake - Check if device can generate run-time wake-up events.
2682 * Return true if the device itself is capable of generating wake-up events
2684 * PME and one of its upstream bridges can generate wake-up events.
2688 struct pci_bus *bus = dev->bus; in pci_dev_run_wake()
2690 if (!dev->pme_support) in pci_dev_run_wake()
2693 /* PME-capable in principle, but not from the target power state */ in pci_dev_run_wake()
2697 if (device_can_wakeup(&dev->dev)) in pci_dev_run_wake()
2700 while (bus->parent) { in pci_dev_run_wake()
2701 struct pci_dev *bridge = bus->self; in pci_dev_run_wake()
2703 if (device_can_wakeup(&bridge->dev)) in pci_dev_run_wake()
2706 bus = bus->parent; in pci_dev_run_wake()
2710 if (bus->bridge) in pci_dev_run_wake()
2711 return device_can_wakeup(bus->bridge); in pci_dev_run_wake()
2718 * pci_dev_need_resume - Check if it is necessary to resume the device.
2721 * Return 'true' if the device is not runtime-suspended or it has to be
2724 * (system-wide) transition.
2728 struct device *dev = &pci_dev->dev; in pci_dev_need_resume()
2741 return target_state != pci_dev->current_state && in pci_dev_need_resume()
2743 pci_dev->current_state != PCI_D3hot; in pci_dev_need_resume()
2747 * pci_dev_adjust_pme - Adjust PME setting for a suspended device.
2759 struct device *dev = &pci_dev->dev; in pci_dev_adjust_pme()
2761 spin_lock_irq(&dev->power.lock); in pci_dev_adjust_pme()
2764 pci_dev->current_state < PCI_D3cold) in pci_dev_adjust_pme()
2767 spin_unlock_irq(&dev->power.lock); in pci_dev_adjust_pme()
2771 * pci_dev_complete_resume - Finalize resume from system sleep for a device.
2774 * If the device is runtime suspended and wakeup-capable, enable PME for it as
2780 struct device *dev = &pci_dev->dev; in pci_dev_complete_resume()
2785 spin_lock_irq(&dev->power.lock); in pci_dev_complete_resume()
2787 if (pm_runtime_suspended(dev) && pci_dev->current_state < PCI_D3cold) in pci_dev_complete_resume()
2790 spin_unlock_irq(&dev->power.lock); in pci_dev_complete_resume()
2795 struct device *dev = &pdev->dev; in pci_config_pm_runtime_get()
2796 struct device *parent = dev->parent; in pci_config_pm_runtime_get()
2802 * pdev->current_state is set to PCI_D3cold during suspending, in pci_config_pm_runtime_get()
2811 if (pdev->current_state == PCI_D3cold) in pci_config_pm_runtime_get()
2817 struct device *dev = &pdev->dev; in pci_config_pm_runtime_put()
2818 struct device *parent = dev->parent; in pci_config_pm_runtime_put()
2834 .ident = "X299 DESIGNARE EX-CF",
2837 DMI_MATCH(DMI_BOARD_NAME, "X299 DESIGNARE EX-CF"),
2857 * pci_bridge_d3_possible - Is it possible to put the bridge into D3
2877 * may not be put into D3 by the OS (Thunderbolt on non-Macs). in pci_bridge_d3_possible()
2879 if (bridge->is_hotplug_bridge && !pciehp_is_native(bridge)) in pci_bridge_d3_possible()
2886 if (bridge->is_thunderbolt) in pci_bridge_d3_possible()
2898 if (bridge->is_hotplug_bridge) in pci_bridge_d3_possible()
2921 dev->no_d3cold || !dev->d3cold_allowed || in pci_dev_check_d3cold()
2924 (device_may_wakeup(&dev->dev) && in pci_dev_check_d3cold()
2936 * pci_bridge_d3_update - Update bridge D3 capabilities
2945 bool remove = !device_is_registered(&dev->dev); in pci_bridge_d3_update()
2957 if (remove && bridge->bridge_d3) in pci_bridge_d3_update()
2977 if (d3cold_ok && !bridge->bridge_d3) in pci_bridge_d3_update()
2978 pci_walk_bus(bridge->subordinate, pci_dev_check_d3cold, in pci_bridge_d3_update()
2981 if (bridge->bridge_d3 != d3cold_ok) { in pci_bridge_d3_update()
2982 bridge->bridge_d3 = d3cold_ok; in pci_bridge_d3_update()
2989 * pci_d3cold_enable - Enable D3cold for device
2998 if (dev->no_d3cold) { in pci_d3cold_enable()
2999 dev->no_d3cold = false; in pci_d3cold_enable()
3006 * pci_d3cold_disable - Disable D3cold for device
3015 if (!dev->no_d3cold) { in pci_d3cold_disable()
3016 dev->no_d3cold = true; in pci_d3cold_disable()
3023 * pci_pm_init - Initialize PM functions of given PCI device
3032 pm_runtime_forbid(&dev->dev); in pci_pm_init()
3033 pm_runtime_set_active(&dev->dev); in pci_pm_init()
3034 pm_runtime_enable(&dev->dev); in pci_pm_init()
3035 device_enable_async_suspend(&dev->dev); in pci_pm_init()
3036 dev->wakeup_prepared = false; in pci_pm_init()
3038 dev->pm_cap = 0; in pci_pm_init()
3039 dev->pme_support = 0; in pci_pm_init()
3054 dev->pm_cap = pm; in pci_pm_init()
3055 dev->d3hot_delay = PCI_PM_D3HOT_WAIT; in pci_pm_init()
3056 dev->d3cold_delay = PCI_PM_D3COLD_WAIT; in pci_pm_init()
3057 dev->bridge_d3 = pci_bridge_d3_possible(dev); in pci_pm_init()
3058 dev->d3cold_allowed = true; in pci_pm_init()
3060 dev->d1_support = false; in pci_pm_init()
3061 dev->d2_support = false; in pci_pm_init()
3064 dev->d1_support = true; in pci_pm_init()
3066 dev->d2_support = true; in pci_pm_init()
3068 if (dev->d1_support || dev->d2_support) in pci_pm_init()
3070 dev->d1_support ? " D1" : "", in pci_pm_init()
3071 dev->d2_support ? " D2" : ""); in pci_pm_init()
3082 dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT; in pci_pm_init()
3083 dev->pme_poll = true; in pci_pm_init()
3085 * Make device's PM flags reflect the wake-up capability, but in pci_pm_init()
3088 device_set_wakeup_capable(&dev->dev, true); in pci_pm_init()
3095 dev->imm_ready = 1; in pci_pm_init()
3125 return &dev->resource[bei]; in pci_ea_get_resource()
3129 return &dev->resource[PCI_IOV_RESOURCES + in pci_ea_get_resource()
3130 bei - PCI_EA_BEI_VF_BAR0]; in pci_ea_get_resource()
3133 return &dev->resource[PCI_ROM_RESOURCE]; in pci_ea_get_resource()
3191 /* Read Base MSBs (if 64-bit entry) */ in pci_ea_read()
3200 /* entry starts above 32-bit boundary, can't use */ in pci_ea_read()
3210 /* Read MaxOffset MSBs (if 64-bit entry) */ in pci_ea_read()
3232 if (ent_size != ent_offset - offset) { in pci_ea_read()
3234 ent_size, ent_offset - offset); in pci_ea_read()
3238 res->name = pci_name(dev); in pci_ea_read()
3239 res->start = start; in pci_ea_read()
3240 res->end = end; in pci_ea_read()
3241 res->flags = flags; in pci_ea_read()
3251 bei - PCI_EA_BEI_VF_BAR0, res, prop); in pci_ea_read()
3274 pci_bus_read_config_byte(dev->bus, dev->devfn, ea + PCI_EA_NUM_ENT, in pci_ea_init()
3281 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) in pci_ea_init()
3292 hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space); in pci_add_saved_cap()
3296 * _pci_add_cap_save_buffer - allocate buffer for saving given
3319 return -ENOMEM; in _pci_add_cap_save_buffer()
3321 save_state->cap.cap_nr = cap; in _pci_add_cap_save_buffer()
3322 save_state->cap.cap_extended = extended; in _pci_add_cap_save_buffer()
3323 save_state->cap.size = size; in _pci_add_cap_save_buffer()
3340 * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities
3354 pci_err(dev, "unable to preallocate PCI-X save buffer\n"); in pci_allocate_cap_save_buffers()
3369 hlist_for_each_entry_safe(tmp, n, &dev->saved_cap_space, next) in pci_free_cap_save_buffers()
3374 * pci_configure_ari - enable or disable ARI forwarding
3385 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) in pci_configure_ari()
3388 bridge = dev->bus->self; in pci_configure_ari()
3399 bridge->ari_enabled = 1; in pci_configure_ari()
3403 bridge->ari_enabled = 0; in pci_configure_ari()
3412 pos = pdev->acs_cap; in pci_acs_flags_enabled()
3419 * capability field can therefore be assumed as hard-wired enabled. in pci_acs_flags_enabled()
3429 * pci_acs_enabled - test ACS against required flags for a given device
3439 * opportunity for peer-to-peer access. We therefore return 'true'
3453 * Conventional PCI and PCI-X devices never support ACS, either in pci_acs_enabled()
3462 * PCI/X-to-PCIe bridges are not specifically mentioned by the spec, in pci_acs_enabled()
3464 * handle them as we would a non-PCIe device. in pci_acs_enabled()
3478 * implement ACS in order to indicate their peer-to-peer capabilities, in pci_acs_enabled()
3479 * regardless of whether they are single- or multi-function devices. in pci_acs_enabled()
3486 * implemented by the remaining PCIe types to indicate peer-to-peer in pci_acs_enabled()
3495 if (!pdev->multifunction) in pci_acs_enabled()
3509 * pci_acs_path_enable - test ACS flags from start to end in a hierarchy
3528 if (pci_is_root_bus(pdev->bus)) in pci_acs_path_enabled()
3531 parent = pdev->bus->self; in pci_acs_path_enabled()
3538 * pci_acs_init - Initialize ACS if hardware supports it
3543 dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); in pci_acs_init()
3555 * pci_rebar_find_pos - find position of resize ctrl reg for BAR
3560 * Returns -ENOTSUPP if resizable BARs are not supported at all.
3561 * Returns -ENOENT if no ctrl register for the BAR could be found.
3570 return -ENOTSUPP; in pci_rebar_find_pos()
3585 return -ENOENT; in pci_rebar_find_pos()
3589 * pci_rebar_get_possible_sizes - get possible sizes for BAR
3609 if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f && in pci_rebar_get_possible_sizes()
3617 * pci_rebar_get_current_size - get the current size of a BAR
3638 * pci_rebar_set_size - set a new size for a BAR
3663 * pci_enable_atomic_ops_to_root - enable AtomicOp requests to root port
3672 * the requested completion capabilities (32-bit, 64-bit and/or 128-bit
3677 struct pci_bus *bus = dev->bus; in pci_enable_atomic_ops_to_root()
3682 return -EINVAL; in pci_enable_atomic_ops_to_root()
3688 * completers, and no peer-to-peer. in pci_enable_atomic_ops_to_root()
3697 return -EINVAL; in pci_enable_atomic_ops_to_root()
3700 while (bus->parent) { in pci_enable_atomic_ops_to_root()
3701 bridge = bus->self; in pci_enable_atomic_ops_to_root()
3710 return -EINVAL; in pci_enable_atomic_ops_to_root()
3716 return -EINVAL; in pci_enable_atomic_ops_to_root()
3725 return -EINVAL; in pci_enable_atomic_ops_to_root()
3728 bus = bus->parent; in pci_enable_atomic_ops_to_root()
3738 * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
3743 * required by section 9.1 of the PCI-to-PCI bridge specification for devices
3744 * behind bridges on add-in cards. For devices with ARI enabled, the slot
3752 if (pci_ari_enabled(dev->bus)) in pci_swizzle_interrupt_pin()
3755 slot = PCI_SLOT(dev->devfn); in pci_swizzle_interrupt_pin()
3757 return (((pin - 1) + slot) % 4) + 1; in pci_swizzle_interrupt_pin()
3764 pin = dev->pin; in pci_get_interrupt_pin()
3766 return -1; in pci_get_interrupt_pin()
3768 while (!pci_is_root_bus(dev->bus)) { in pci_get_interrupt_pin()
3770 dev = dev->bus->self; in pci_get_interrupt_pin()
3777 * pci_common_swizzle - swizzle INTx all the way to root bridge
3781 * Perform INTx swizzling for a device. This traverses through all PCI-to-PCI
3788 while (!pci_is_root_bus(dev->bus)) { in pci_common_swizzle()
3790 dev = dev->bus->self; in pci_common_swizzle()
3793 return PCI_SLOT(dev->devfn); in pci_common_swizzle()
3798 * pci_release_region - Release a PCI bar
3822 dr->region_mask &= ~(1 << bar); in pci_release_region()
3827 * __pci_request_region - Reserved PCI I/O and memory resource
3866 dr->region_mask |= 1 << bar; in __pci_request_region()
3872 &pdev->resource[bar]); in __pci_request_region()
3873 return -EBUSY; in __pci_request_region()
3877 * pci_request_region - Reserve PCI I/O and memory resource
3897 * pci_release_selected_regions - Release selected PCI I/O and memory resources
3926 while (--i >= 0) in __pci_request_selected_regions()
3930 return -EBUSY; in __pci_request_selected_regions()
3935 * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
3956 * pci_release_regions - Release reserved PCI I/O and memory resources
3967 pci_release_selected_regions(pdev, (1 << PCI_STD_NUM_BARS) - 1); in pci_release_regions()
3972 * pci_request_regions - Reserve PCI I/O and memory resources
3987 ((1 << PCI_STD_NUM_BARS) - 1), res_name); in pci_request_regions()
3992 * pci_request_regions_exclusive - Reserve PCI I/O and memory resources
4009 ((1 << PCI_STD_NUM_BARS) - 1), res_name); in pci_request_regions_exclusive()
4025 return -EINVAL; in pci_register_io_range()
4029 return -ENOMEM; in pci_register_io_range()
4031 range->fwnode = fwnode; in pci_register_io_range()
4032 range->size = size; in pci_register_io_range()
4033 range->hw_start = addr; in pci_register_io_range()
4034 range->flags = LOGIC_PIO_CPU_MMIO; in pci_register_io_range()
4041 if (ret == -EEXIST) in pci_register_io_range()
4069 return (unsigned long)-1; in pci_address_to_pio()
4076 * pci_remap_iospace - Remap the memory mapped I/O space
4088 unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start; in pci_remap_iospace()
4090 if (!(res->flags & IORESOURCE_IO)) in pci_remap_iospace()
4091 return -EINVAL; in pci_remap_iospace()
4093 if (res->end > IO_SPACE_LIMIT) in pci_remap_iospace()
4094 return -EINVAL; in pci_remap_iospace()
4104 return -ENODEV; in pci_remap_iospace()
4110 * pci_unmap_iospace - Unmap the memory mapped I/O space
4120 unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start; in pci_unmap_iospace()
4135 * devm_pci_remap_iospace - Managed pci_remap_iospace()
4151 return -ENOMEM; in devm_pci_remap_iospace()
4166 * devm_pci_remap_cfgspace - Managed pci_remap_cfgspace()
4196 * devm_pci_remap_cfg_resource - check, request region and ioremap cfg resource
4210 * base = devm_pci_remap_cfg_resource(&pdev->dev, res);
4225 return IOMEM_ERR_PTR(-EINVAL); in devm_pci_remap_cfg_resource()
4229 name = res->name ?: dev_name(dev); in devm_pci_remap_cfg_resource()
4231 if (!devm_request_mem_region(dev, res->start, size, name)) { in devm_pci_remap_cfg_resource()
4233 return IOMEM_ERR_PTR(-EBUSY); in devm_pci_remap_cfg_resource()
4236 dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size); in devm_pci_remap_cfg_resource()
4239 devm_release_mem_region(dev, res->start, size); in devm_pci_remap_cfg_resource()
4240 dest_ptr = IOMEM_ERR_PTR(-ENOMEM); in devm_pci_remap_cfg_resource()
4249 u16 old_cmd, cmd; in __pci_set_master() local
4253 cmd = old_cmd | PCI_COMMAND_MASTER; in __pci_set_master()
4255 cmd = old_cmd & ~PCI_COMMAND_MASTER; in __pci_set_master()
4256 if (cmd != old_cmd) { in __pci_set_master()
4259 pci_write_config_word(dev, PCI_COMMAND, cmd); in __pci_set_master()
4261 dev->is_busmaster = enable; in __pci_set_master()
4265 * pcibios_setup - process "pci=" kernel boot arguments
4277 * pcibios_set_master - enable PCI bus-mastering for device dev
4280 * Enables PCI bus-mastering for the device. This is the default
4304 * pci_set_master - enables bus-mastering for device dev
4307 * Enables bus-mastering on the device and calls pcibios_set_master()
4318 * pci_clear_master - disables bus-mastering for device dev
4328 * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
4333 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
4335 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
4342 return -EINVAL; in pci_set_cacheline_size()
4361 return -EINVAL; in pci_set_cacheline_size()
4366 * pci_set_mwi - enables memory-write-invalidate PCI transaction
4369 * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
4371 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
4379 u16 cmd; in pci_set_mwi()
4385 pci_read_config_word(dev, PCI_COMMAND, &cmd); in pci_set_mwi()
4386 if (!(cmd & PCI_COMMAND_INVALIDATE)) { in pci_set_mwi()
4387 pci_dbg(dev, "enabling Mem-Wr-Inval\n"); in pci_set_mwi()
4388 cmd |= PCI_COMMAND_INVALIDATE; in pci_set_mwi()
4389 pci_write_config_word(dev, PCI_COMMAND, cmd); in pci_set_mwi()
4397 * pcim_set_mwi - a device-managed pci_set_mwi()
4402 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
4410 return -ENOMEM; in pcim_set_mwi()
4412 dr->mwi = 1; in pcim_set_mwi()
4418 * pci_try_set_mwi - enables memory-write-invalidate PCI transaction
4421 * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
4424 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
4437 * pci_clear_mwi - disables Memory-Write-Invalidate for device dev
4440 * Disables PCI Memory-Write-Invalidate transaction on the device
4445 u16 cmd; in pci_clear_mwi() local
4447 pci_read_config_word(dev, PCI_COMMAND, &cmd); in pci_clear_mwi()
4448 if (cmd & PCI_COMMAND_INVALIDATE) { in pci_clear_mwi()
4449 cmd &= ~PCI_COMMAND_INVALIDATE; in pci_clear_mwi()
4450 pci_write_config_word(dev, PCI_COMMAND, cmd); in pci_clear_mwi()
4457 * pci_intx - enables/disables PCI INTx for device dev
4480 if (dr && !dr->restore_intx) { in pci_intx()
4481 dr->restore_intx = 1; in pci_intx()
4482 dr->orig_intx = !enable; in pci_intx()
4490 struct pci_bus *bus = dev->bus; in pci_check_and_set_intx_mask()
4506 bus->ops->read(bus, dev->devfn, PCI_COMMAND, 4, &cmd_status_dword); in pci_check_and_set_intx_mask()
4525 bus->ops->write(bus, dev->devfn, PCI_COMMAND, 2, newcmd); in pci_check_and_set_intx_mask()
4534 * pci_check_and_mask_intx - mask INTx on pending interrupt
4547 * pci_check_and_unmask_intx - unmask INTx if no interrupt is pending
4561 * pci_wait_for_pending_transaction - wait for pending transaction
4577 * pcie_has_flr - check if a device supports function level resets
4587 if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) in pcie_has_flr()
4596 * pcie_flr - initiate a PCIe function level reset
4610 if (dev->imm_ready) in pcie_flr()
4631 return -ENOTTY; in pci_af_flr()
4633 if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) in pci_af_flr()
4634 return -ENOTTY; in pci_af_flr()
4638 return -ENOTTY; in pci_af_flr()
4644 * Wait for Transaction Pending bit to clear. A word-aligned test in pci_af_flr()
4654 if (dev->imm_ready) in pci_af_flr()
4669 * pci_pm_reset - Put device into PCI_D3 and back into PCI_D0.
4675 * PCI_D0. If that's the case and the device is not in a low-power state
4679 * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms
4687 if (!dev->pm_cap || dev->dev_flags & PCI_DEV_FLAGS_NO_PM_RESET) in pci_pm_reset()
4688 return -ENOTTY; in pci_pm_reset()
4690 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &csr); in pci_pm_reset()
4692 return -ENOTTY; in pci_pm_reset()
4697 if (dev->current_state != PCI_D0) in pci_pm_reset()
4698 return -EINVAL; in pci_pm_reset()
4702 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); in pci_pm_reset()
4707 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); in pci_pm_reset()
4710 return pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS); in pci_pm_reset()
4714 * pcie_wait_for_link_delay - Wait until link is active or inactive
4732 if (!pdev->link_active_reporting) { in pcie_wait_for_link_delay()
4756 timeout -= 10; in pcie_wait_for_link_delay()
4765 * pcie_wait_for_link - Wait until link is active or inactive
4789 list_for_each_entry(pdev, &bus->devices, bus_list) { in pci_bus_max_d3cold_delay()
4790 if (pdev->d3cold_delay < min_delay) in pci_bus_max_d3cold_delay()
4791 min_delay = pdev->d3cold_delay; in pci_bus_max_d3cold_delay()
4792 if (pdev->d3cold_delay > max_delay) in pci_bus_max_d3cold_delay()
4793 max_delay = pdev->d3cold_delay; in pci_bus_max_d3cold_delay()
4800 * pci_bridge_wait_for_secondary_bus - Wait for secondary bus to be accessible
4818 if (!pci_is_bridge(dev) || !dev->bridge_d3) in pci_bridge_wait_for_secondary_bus()
4825 * For any hot-added devices the access delay is handled in pciehp in pci_bridge_wait_for_secondary_bus()
4829 if (!dev->subordinate || list_empty(&dev->subordinate->devices)) { in pci_bridge_wait_for_secondary_bus()
4835 delay = pci_bus_max_d3cold_delay(dev->subordinate); in pci_bridge_wait_for_secondary_bus()
4841 child = list_first_entry(&dev->subordinate->devices, struct pci_dev, in pci_bridge_wait_for_secondary_bus()
4846 * Conventional PCI and PCI-X we need to wait Tpvrh + Trhfa before in pci_bridge_wait_for_secondary_bus()
4865 * device that did not respond is a broken device. There is in pci_bridge_wait_for_secondary_bus()
4917 * be re-initialized. PCIe has some ways to shorten this, in pci_reset_secondary_bus()
4929 * pci_bridge_secondary_bus_reset - Reset the secondary bus on a PCI bridge.
4933 * Devices on the secondary bus are left in power-on state.
4947 if (pci_is_root_bus(dev->bus) || dev->subordinate || in pci_parent_bus_reset()
4948 !dev->bus->self || dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) in pci_parent_bus_reset()
4949 return -ENOTTY; in pci_parent_bus_reset()
4951 list_for_each_entry(pdev, &dev->bus->devices, bus_list) in pci_parent_bus_reset()
4953 return -ENOTTY; in pci_parent_bus_reset()
4958 return pci_bridge_secondary_bus_reset(dev->bus->self); in pci_parent_bus_reset()
4963 int rc = -ENOTTY; in pci_reset_hotplug_slot()
4965 if (!hotplug || !try_module_get(hotplug->owner)) in pci_reset_hotplug_slot()
4968 if (hotplug->ops->reset_slot) in pci_reset_hotplug_slot()
4969 rc = hotplug->ops->reset_slot(hotplug, probe); in pci_reset_hotplug_slot()
4971 module_put(hotplug->owner); in pci_reset_hotplug_slot()
4978 if (dev->multifunction || dev->subordinate || !dev->slot || in pci_dev_reset_slot_function()
4979 dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) in pci_dev_reset_slot_function()
4980 return -ENOTTY; in pci_dev_reset_slot_function()
4982 return pci_reset_hotplug_slot(dev->slot->hotplug, probe); in pci_dev_reset_slot_function()
4988 device_lock(&dev->dev); in pci_dev_lock()
4995 if (device_trylock(&dev->dev)) { in pci_dev_trylock()
4998 device_unlock(&dev->dev); in pci_dev_trylock()
5007 device_unlock(&dev->dev); in pci_dev_unlock()
5013 dev->driver ? dev->driver->err_handler : NULL; in pci_dev_save_and_disable()
5016 * dev->driver->err_handler->reset_prepare() is protected against in pci_dev_save_and_disable()
5017 * races with ->remove() by the device lock, which must be held by in pci_dev_save_and_disable()
5020 if (err_handler && err_handler->reset_prepare) in pci_dev_save_and_disable()
5021 err_handler->reset_prepare(dev); in pci_dev_save_and_disable()
5024 * Wake-up device prior to save. PM registers default to D0 after in pci_dev_save_and_disable()
5026 * to a non-D0 state anyway. in pci_dev_save_and_disable()
5033 * INTx-disable which is set. This not only disables MMIO and I/O port in pci_dev_save_and_disable()
5035 * DMA from the device including MSI/MSI-X interrupts. For PCI 2.3 in pci_dev_save_and_disable()
5036 * compliant devices, INTx-disable prevents legacy interrupts. in pci_dev_save_and_disable()
5044 dev->driver ? dev->driver->err_handler : NULL; in pci_dev_restore()
5049 * dev->driver->err_handler->reset_done() is protected against in pci_dev_restore()
5050 * races with ->remove() by the device lock, which must be held by in pci_dev_restore()
5053 if (err_handler && err_handler->reset_done) in pci_dev_restore()
5054 err_handler->reset_done(dev); in pci_dev_restore()
5058 * __pci_reset_function_locked - reset a PCI device function while holding
5084 * A reset method returns -ENOTTY if it doesn't support this device in __pci_reset_function_locked()
5089 * reset mechanisms might be broken on the device. in __pci_reset_function_locked()
5092 if (rc != -ENOTTY) in __pci_reset_function_locked()
5096 if (rc != -ENOTTY) in __pci_reset_function_locked()
5100 if (rc != -ENOTTY) in __pci_reset_function_locked()
5103 if (rc != -ENOTTY) in __pci_reset_function_locked()
5106 if (rc != -ENOTTY) in __pci_reset_function_locked()
5113 * pci_probe_reset_function - check whether the device can be safely reset
5130 if (rc != -ENOTTY) in pci_probe_reset_function()
5135 if (rc != -ENOTTY) in pci_probe_reset_function()
5138 if (rc != -ENOTTY) in pci_probe_reset_function()
5141 if (rc != -ENOTTY) in pci_probe_reset_function()
5148 * pci_reset_function - quiesce and reset a PCI device function
5167 if (!dev->reset_fn) in pci_reset_function()
5168 return -ENOTTY; in pci_reset_function()
5183 * pci_reset_function_locked - quiesce and reset a PCI device function
5203 if (!dev->reset_fn) in pci_reset_function_locked()
5204 return -ENOTTY; in pci_reset_function_locked()
5217 * pci_try_reset_function - quiesce and reset a PCI device function
5220 * Same as above, except return -EAGAIN if unable to lock device.
5226 if (!dev->reset_fn) in pci_try_reset_function()
5227 return -ENOTTY; in pci_try_reset_function()
5230 return -EAGAIN; in pci_try_reset_function()
5247 if (bus->self && (bus->self->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)) in pci_bus_resetable()
5250 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_resetable()
5251 if (dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET || in pci_bus_resetable()
5252 (dev->subordinate && !pci_bus_resetable(dev->subordinate))) in pci_bus_resetable()
5264 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_lock()
5266 if (dev->subordinate) in pci_bus_lock()
5267 pci_bus_lock(dev->subordinate); in pci_bus_lock()
5276 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_unlock()
5277 if (dev->subordinate) in pci_bus_unlock()
5278 pci_bus_unlock(dev->subordinate); in pci_bus_unlock()
5288 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_trylock()
5291 if (dev->subordinate) { in pci_bus_trylock()
5292 if (!pci_bus_trylock(dev->subordinate)) { in pci_bus_trylock()
5301 list_for_each_entry_continue_reverse(dev, &bus->devices, bus_list) { in pci_bus_trylock()
5302 if (dev->subordinate) in pci_bus_trylock()
5303 pci_bus_unlock(dev->subordinate); in pci_bus_trylock()
5314 if (slot->bus->self && in pci_slot_resetable()
5315 (slot->bus->self->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)) in pci_slot_resetable()
5318 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_resetable()
5319 if (!dev->slot || dev->slot != slot) in pci_slot_resetable()
5321 if (dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET || in pci_slot_resetable()
5322 (dev->subordinate && !pci_bus_resetable(dev->subordinate))) in pci_slot_resetable()
5334 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_lock()
5335 if (!dev->slot || dev->slot != slot) in pci_slot_lock()
5338 if (dev->subordinate) in pci_slot_lock()
5339 pci_bus_lock(dev->subordinate); in pci_slot_lock()
5348 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_unlock()
5349 if (!dev->slot || dev->slot != slot) in pci_slot_unlock()
5351 if (dev->subordinate) in pci_slot_unlock()
5352 pci_bus_unlock(dev->subordinate); in pci_slot_unlock()
5362 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_trylock()
5363 if (!dev->slot || dev->slot != slot) in pci_slot_trylock()
5367 if (dev->subordinate) { in pci_slot_trylock()
5368 if (!pci_bus_trylock(dev->subordinate)) { in pci_slot_trylock()
5378 &slot->bus->devices, bus_list) { in pci_slot_trylock()
5379 if (!dev->slot || dev->slot != slot) in pci_slot_trylock()
5381 if (dev->subordinate) in pci_slot_trylock()
5382 pci_bus_unlock(dev->subordinate); in pci_slot_trylock()
5396 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_save_and_disable_locked()
5398 if (dev->subordinate) in pci_bus_save_and_disable_locked()
5399 pci_bus_save_and_disable_locked(dev->subordinate); in pci_bus_save_and_disable_locked()
5412 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_restore_locked()
5414 if (dev->subordinate) in pci_bus_restore_locked()
5415 pci_bus_restore_locked(dev->subordinate); in pci_bus_restore_locked()
5427 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_save_and_disable_locked()
5428 if (!dev->slot || dev->slot != slot) in pci_slot_save_and_disable_locked()
5431 if (dev->subordinate) in pci_slot_save_and_disable_locked()
5432 pci_bus_save_and_disable_locked(dev->subordinate); in pci_slot_save_and_disable_locked()
5445 list_for_each_entry(dev, &slot->bus->devices, bus_list) { in pci_slot_restore_locked()
5446 if (!dev->slot || dev->slot != slot) in pci_slot_restore_locked()
5449 if (dev->subordinate) in pci_slot_restore_locked()
5450 pci_bus_restore_locked(dev->subordinate); in pci_slot_restore_locked()
5459 return -ENOTTY; in pci_slot_reset()
5466 rc = pci_reset_hotplug_slot(slot->hotplug, probe); in pci_slot_reset()
5475 * pci_probe_reset_slot - probe whether a PCI slot can be reset
5487 * __pci_reset_slot - Try to reset a PCI slot
5499 * Same as above except return -EAGAIN if the slot cannot be locked
5512 rc = pci_reset_hotplug_slot(slot->hotplug, 0); in __pci_reset_slot()
5516 rc = -EAGAIN; in __pci_reset_slot()
5525 if (!bus->self || !pci_bus_resetable(bus)) in pci_bus_reset()
5526 return -ENOTTY; in pci_bus_reset()
5535 ret = pci_bridge_secondary_bus_reset(bus->self); in pci_bus_reset()
5543 * pci_bus_error_reset - reset the bridge's subordinate bus
5552 struct pci_bus *bus = bridge->subordinate; in pci_bus_error_reset()
5556 return -ENOTTY; in pci_bus_error_reset()
5559 if (list_empty(&bus->slots)) in pci_bus_error_reset()
5562 list_for_each_entry(slot, &bus->slots, list) in pci_bus_error_reset()
5566 list_for_each_entry(slot, &bus->slots, list) in pci_bus_error_reset()
5574 return pci_bus_reset(bridge->subordinate, 0); in pci_bus_error_reset()
5578 * pci_probe_reset_bus - probe whether a PCI bus can be reset
5590 * __pci_reset_bus - Try to reset a PCI bus
5593 * Same as above except return -EAGAIN if the bus cannot be locked
5606 rc = pci_bridge_secondary_bus_reset(bus->self); in __pci_reset_bus()
5610 rc = -EAGAIN; in __pci_reset_bus()
5616 * pci_reset_bus - Try to reset a PCI bus
5619 * Same as above except return -EAGAIN if the bus cannot be locked
5623 return (!pci_probe_reset_slot(pdev->slot)) ? in pci_reset_bus()
5624 __pci_reset_slot(pdev->slot) : __pci_reset_bus(pdev->bus); in pci_reset_bus()
5629 * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
5642 return -EINVAL; in pcix_get_max_mmrbc()
5645 return -EINVAL; in pcix_get_max_mmrbc()
5652 * pcix_get_mmrbc - get PCI-X maximum memory read byte count
5661 u16 cmd; in pcix_get_mmrbc() local
5665 return -EINVAL; in pcix_get_mmrbc()
5667 if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd)) in pcix_get_mmrbc()
5668 return -EINVAL; in pcix_get_mmrbc()
5670 return 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2); in pcix_get_mmrbc()
5675 * pcix_set_mmrbc - set PCI-X maximum memory read byte count
5687 u16 cmd; in pcix_set_mmrbc() local
5690 return -EINVAL; in pcix_set_mmrbc()
5692 v = ffs(mmrbc) - 10; in pcix_set_mmrbc()
5696 return -EINVAL; in pcix_set_mmrbc()
5699 return -EINVAL; in pcix_set_mmrbc()
5702 return -E2BIG; in pcix_set_mmrbc()
5704 if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd)) in pcix_set_mmrbc()
5705 return -EINVAL; in pcix_set_mmrbc()
5707 o = (cmd & PCI_X_CMD_MAX_READ) >> 2; in pcix_set_mmrbc()
5709 if (v > o && (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MMRBC)) in pcix_set_mmrbc()
5710 return -EIO; in pcix_set_mmrbc()
5712 cmd &= ~PCI_X_CMD_MAX_READ; in pcix_set_mmrbc()
5713 cmd |= v << 2; in pcix_set_mmrbc()
5714 if (pci_write_config_word(dev, cap + PCI_X_CMD, cmd)) in pcix_set_mmrbc()
5715 return -EIO; in pcix_set_mmrbc()
5722 * pcie_get_readrq - get PCI Express read request size
5738 * pcie_set_readrq - set PCI Express maximum memory read request
5751 return -EINVAL; in pcie_set_readrq()
5765 v = (ffs(rq) - 8) << 12; in pcie_set_readrq()
5775 * pcie_get_mps - get PCI Express maximum payload size
5791 * pcie_set_mps - set PCI Express maximum payload size
5804 return -EINVAL; in pcie_set_mps()
5806 v = ffs(mps) - 8; in pcie_set_mps()
5807 if (v > dev->pcie_mpss) in pcie_set_mps()
5808 return -EINVAL; in pcie_set_mps()
5819 * pcie_bandwidth_available - determine minimum link settings of a PCIe
5877 * pcie_get_speed_cap - query for the PCI device's link speed capability
5898 /* PCIe r3.0-compliant */ in pcie_get_speed_cap()
5913 * pcie_get_width_cap - query for the PCI device's link width capability
5932 * pcie_bandwidth_capable - calculate a PCI device's link bandwidth capability
5954 * __pcie_print_link_status - Report the PCI device's link speed and width
5987 * pcie_print_link_status - Report the PCI device's link speed and width
5999 * pci_select_bars - Make BAR mask from the type of resource
6033 * pci_set_vga_state - set VGA decode state on device and parents if requested
6045 u16 cmd; in pci_set_vga_state() local
6056 pci_read_config_word(dev, PCI_COMMAND, &cmd); in pci_set_vga_state()
6058 cmd |= command_bits; in pci_set_vga_state()
6060 cmd &= ~command_bits; in pci_set_vga_state()
6061 pci_write_config_word(dev, PCI_COMMAND, cmd); in pci_set_vga_state()
6067 bus = dev->bus; in pci_set_vga_state()
6069 bridge = bus->self; in pci_set_vga_state()
6072 &cmd); in pci_set_vga_state()
6074 cmd |= PCI_BRIDGE_CTL_VGA; in pci_set_vga_state()
6076 cmd &= ~PCI_BRIDGE_CTL_VGA; in pci_set_vga_state()
6078 cmd); in pci_set_vga_state()
6080 bus = bus->parent; in pci_set_vga_state()
6093 adev = ACPI_COMPANION(&pdev->dev); in pci_pr3_present()
6097 return adev->power.flags.power_resources && in pci_pr3_present()
6098 acpi_has_method(adev->handle, "_PR3"); in pci_pr3_present()
6104 * pci_add_dma_alias - Add a DMA devfn alias for a device
6109 * This helper encodes an 8-bit devfn as a bit number in dma_alias_mask
6110 * which is used to program permissible bus-devfn source addresses for DMA
6113 * from their logical bus-devfn. Examples include device quirks where the
6114 * device simply uses the wrong devfn, as well as non-transparent bridges
6127 nr_devfns = min(nr_devfns, (unsigned) MAX_NR_DEVFNS - devfn_from); in pci_add_dma_alias()
6128 devfn_to = devfn_from + nr_devfns - 1; in pci_add_dma_alias()
6130 if (!dev->dma_alias_mask) in pci_add_dma_alias()
6131 dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL); in pci_add_dma_alias()
6132 if (!dev->dma_alias_mask) { in pci_add_dma_alias()
6137 bitmap_set(dev->dma_alias_mask, devfn_from, nr_devfns); in pci_add_dma_alias()
6150 return (dev1->dma_alias_mask && in pci_devs_are_dma_aliases()
6151 test_bit(dev2->devfn, dev1->dma_alias_mask)) || in pci_devs_are_dma_aliases()
6152 (dev2->dma_alias_mask && in pci_devs_are_dma_aliases()
6153 test_bit(dev1->devfn, dev2->dma_alias_mask)) || in pci_devs_are_dma_aliases()
6164 return pci_bus_read_dev_vendor_id(pdev->bus, pdev->devfn, &v, 0); in pci_device_is_present()
6170 struct pci_dev *bridge = dev->bus->self; in pci_ignore_hotplug()
6172 dev->ignore_hotplug = 1; in pci_ignore_hotplug()
6175 bridge->ignore_hotplug = 1; in pci_ignore_hotplug()
6180 * pci_real_dma_dev - Get PCI DMA device for PCI device
6183 * Permits the platform to provide architecture-specific functionality to
6200 * Arches that don't want to expose struct resource to userland as-is in
6207 *start = rsrc->start; in pci_resource_to_user()
6208 *end = rsrc->end; in pci_resource_to_user()
6215 * pci_specified_resource_alignment - get resource alignment specified by user.
6279 struct resource *r = &dev->resource[bar]; in pci_request_resource_alignment()
6282 if (!(r->flags & IORESOURCE_MEM)) in pci_request_resource_alignment()
6285 if (r->flags & IORESOURCE_PCI_FIXED) { in pci_request_resource_alignment()
6312 * set r->start to the desired alignment. By itself this in pci_request_resource_alignment()
6327 r->start = 0; in pci_request_resource_alignment()
6328 r->end = align - 1; in pci_request_resource_alignment()
6330 r->flags &= ~IORESOURCE_SIZEALIGN; in pci_request_resource_alignment()
6331 r->flags |= IORESOURCE_STARTALIGN; in pci_request_resource_alignment()
6332 r->start = align; in pci_request_resource_alignment()
6333 r->end = r->start + size - 1; in pci_request_resource_alignment()
6335 r->flags |= IORESOURCE_UNSET; in pci_request_resource_alignment()
6342 * Later on, the kernel will assign page-aligned memory resource back
6354 * VF BARs are read-only zero according to SR-IOV spec r1.1, sec in pci_reassigndev_resource_alignment()
6356 * described by the VF BARx register in the PF's SR-IOV capability. in pci_reassigndev_resource_alignment()
6359 if (dev->is_virtfn) in pci_reassigndev_resource_alignment()
6367 if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL && in pci_reassigndev_resource_alignment()
6368 (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) { in pci_reassigndev_resource_alignment()
6385 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { in pci_reassigndev_resource_alignment()
6387 r = &dev->resource[i]; in pci_reassigndev_resource_alignment()
6388 if (!(r->flags & IORESOURCE_MEM)) in pci_reassigndev_resource_alignment()
6390 r->flags |= IORESOURCE_UNSET; in pci_reassigndev_resource_alignment()
6391 r->end = resource_size(r) - 1; in pci_reassigndev_resource_alignment()
6392 r->start = 0; in pci_reassigndev_resource_alignment()
6412 if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) { in resource_alignment_show()
6413 buf[count - 1] = '\n'; in resource_alignment_show()
6426 return -ENOMEM; in resource_alignment_store()
6452 static atomic_t __domain_nr = ATOMIC_INIT(-1);
6461 static int use_dt_domains = -1; in of_pci_bus_find_domain_nr()
6462 int domain = -1; in of_pci_bus_find_domain_nr()
6465 domain = of_get_pci_domain_nr(parent->of_node); in of_pci_bus_find_domain_nr()
6490 * invalidating the domain value (domain = -1) and printing a in of_pci_bus_find_domain_nr()
6500 pr_err("Node %pOF has ", parent->of_node); in of_pci_bus_find_domain_nr()
6501 pr_err("Inconsistent \"linux,pci-domain\" property in DT\n"); in of_pci_bus_find_domain_nr()
6502 domain = -1; in of_pci_bus_find_domain_nr()
6516 * pci_ext_cfg_avail - can we access extended PCI config space?