Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_PCI_H |
| 3 | #define _ASM_X86_PCI_H |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 4 | |
| 5 | #include <linux/mm.h> /* for struct page */ |
| 6 | #include <linux/types.h> |
| 7 | #include <linux/slab.h> |
| 8 | #include <linux/string.h> |
Christoph Hellwig | 84be456 | 2015-05-01 12:46:15 +0200 | [diff] [blame] | 9 | #include <linux/scatterlist.h> |
Anshuman Khandual | 98fa15f | 2019-03-05 15:42:58 -0800 | [diff] [blame] | 10 | #include <linux/numa.h> |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 11 | #include <asm/io.h> |
David Woodhouse | ae749c7 | 2017-04-12 13:25:54 +0100 | [diff] [blame] | 12 | #include <asm/pat.h> |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 13 | #include <asm/x86_init.h> |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 14 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 15 | #ifdef __KERNEL__ |
| 16 | |
| 17 | struct pci_sysdata { |
| 18 | int domain; /* PCI domain */ |
| 19 | int node; /* NUMA node */ |
Rafael J. Wysocki | 6c0cc95 | 2013-01-09 22:33:37 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_ACPI |
Rafael J. Wysocki | 7b19981 | 2013-11-11 22:41:56 +0100 | [diff] [blame] | 21 | struct acpi_device *companion; /* ACPI companion device */ |
Rafael J. Wysocki | 6c0cc95 | 2013-01-09 22:33:37 +0100 | [diff] [blame] | 22 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 23 | #ifdef CONFIG_X86_64 |
Joe Perches | 69bdb7b | 2008-03-23 01:03:04 -0700 | [diff] [blame] | 24 | void *iommu; /* IOMMU private data */ |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 25 | #endif |
Jake Oshins | 92016ba | 2016-02-16 21:56:21 +0000 | [diff] [blame] | 26 | #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN |
| 27 | void *fwnode; /* IRQ domain for MSI assignment */ |
| 28 | #endif |
Keith Busch | 3161832 | 2016-09-13 09:05:40 -0600 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_VMD) |
| 30 | bool vmd_domain; /* True if in Intel VMD domain */ |
| 31 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Thomas Gleixner | 0715650 | 2008-05-12 15:43:37 +0200 | [diff] [blame] | 34 | extern int pci_routeirq; |
Ingo Molnar | 7a9787e | 2008-10-28 16:26:12 +0100 | [diff] [blame] | 35 | extern int noioapicquirk; |
| 36 | extern int noioapicreroute; |
Thomas Gleixner | 0715650 | 2008-05-12 15:43:37 +0200 | [diff] [blame] | 37 | |
Jesse Barnes | 23b90cf | 2010-08-17 09:15:24 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_PCI |
| 39 | |
| 40 | #ifdef CONFIG_PCI_DOMAINS |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 41 | static inline int pci_domain_nr(struct pci_bus *bus) |
| 42 | { |
| 43 | struct pci_sysdata *sd = bus->sysdata; |
Jake Oshins | 92016ba | 2016-02-16 21:56:21 +0000 | [diff] [blame] | 44 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 45 | return sd->domain; |
| 46 | } |
| 47 | |
| 48 | static inline int pci_proc_domain(struct pci_bus *bus) |
| 49 | { |
| 50 | return pci_domain_nr(bus); |
| 51 | } |
Jesse Barnes | 23b90cf | 2010-08-17 09:15:24 -0700 | [diff] [blame] | 52 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 53 | |
Jake Oshins | 92016ba | 2016-02-16 21:56:21 +0000 | [diff] [blame] | 54 | #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN |
| 55 | static inline void *_pci_root_bus_fwnode(struct pci_bus *bus) |
| 56 | { |
| 57 | struct pci_sysdata *sd = bus->sysdata; |
| 58 | |
| 59 | return sd->fwnode; |
| 60 | } |
| 61 | |
| 62 | #define pci_root_bus_fwnode _pci_root_bus_fwnode |
| 63 | #endif |
| 64 | |
Keith Busch | 3161832 | 2016-09-13 09:05:40 -0600 | [diff] [blame] | 65 | static inline bool is_vmd(struct pci_bus *bus) |
| 66 | { |
| 67 | #if IS_ENABLED(CONFIG_VMD) |
| 68 | struct pci_sysdata *sd = bus->sysdata; |
| 69 | |
| 70 | return sd->vmd_domain; |
| 71 | #else |
| 72 | return false; |
| 73 | #endif |
| 74 | } |
| 75 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 76 | /* Can be used to override the logic in pci_scan_bus for skipping |
| 77 | already-configured bus numbers - to be used for buggy BIOSes |
| 78 | or architectures with incomplete PCI setup by the loader */ |
| 79 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 80 | extern unsigned int pcibios_assign_all_busses(void); |
Thomas Gleixner | b72d0db | 2009-08-29 16:24:51 +0200 | [diff] [blame] | 81 | extern int pci_legacy_init(void); |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 82 | #else |
Thomas Gleixner | 9304d16 | 2017-03-16 22:50:03 +0100 | [diff] [blame] | 83 | static inline int pcibios_assign_all_busses(void) { return 0; } |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 84 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 85 | |
| 86 | extern unsigned long pci_mem_start; |
| 87 | #define PCIBIOS_MIN_IO 0x1000 |
| 88 | #define PCIBIOS_MIN_MEM (pci_mem_start) |
| 89 | |
| 90 | #define PCIBIOS_MIN_CARDBUS_IO 0x4000 |
| 91 | |
Matthieu Castet | 5bd5a45 | 2010-11-16 22:31:26 +0100 | [diff] [blame] | 92 | extern int pcibios_enabled; |
Bjorn Helgaas | 49886cf | 2014-01-28 16:40:36 -0700 | [diff] [blame] | 93 | void pcibios_scan_root(int bus); |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 94 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 95 | struct irq_routing_table *pcibios_get_irq_routing_table(void); |
| 96 | int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); |
| 97 | |
| 98 | |
| 99 | #define HAVE_PCI_MMAP |
David Woodhouse | ae749c7 | 2017-04-12 13:25:54 +0100 | [diff] [blame] | 100 | #define arch_can_pci_mmap_wc() pat_enabled() |
David Woodhouse | 5c2d5ce | 2017-04-12 13:26:07 +0100 | [diff] [blame] | 101 | #define ARCH_GENERIC_PCI_MMAP_RESOURCE |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_PCI |
Thomas Gleixner | 376ff03 | 2008-01-30 13:30:16 +0100 | [diff] [blame] | 104 | extern void early_quirks(void); |
Thomas Gleixner | 376ff03 | 2008-01-30 13:30:16 +0100 | [diff] [blame] | 105 | #else |
| 106 | static inline void early_quirks(void) { } |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 107 | #endif |
| 108 | |
Jeremy Fitzhardinge | cfb80c9 | 2008-12-16 12:17:36 -0800 | [diff] [blame] | 109 | extern void pci_iommu_alloc(void); |
| 110 | |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 111 | #ifdef CONFIG_PCI_MSI |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 112 | /* implemented in arch/x86/kernel/apic/io_apic. */ |
Joerg Roedel | 5afba62 | 2012-09-26 12:44:38 +0200 | [diff] [blame] | 113 | struct msi_desc; |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 114 | int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); |
| 115 | void native_teardown_msi_irq(unsigned int irq); |
DuanZhenzhong | ac8344c | 2013-12-04 13:09:16 +0800 | [diff] [blame] | 116 | void native_restore_msi_irqs(struct pci_dev *dev); |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 117 | #else |
| 118 | #define native_setup_msi_irqs NULL |
| 119 | #define native_teardown_msi_irq NULL |
Stefano Stabellini | 294ee6f | 2010-10-06 16:12:28 -0400 | [diff] [blame] | 120 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 121 | #endif /* __KERNEL__ */ |
| 122 | |
Joerg Roedel | 67796bf | 2009-04-02 15:55:55 +0200 | [diff] [blame] | 123 | #ifdef CONFIG_X86_64 |
David Howells | a1ce392 | 2012-10-02 18:01:25 +0100 | [diff] [blame] | 124 | #include <asm/pci_64.h> |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 125 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 126 | |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 127 | /* generic pci stuff */ |
| 128 | #include <asm-generic/pci.h> |
| 129 | |
Thomas Gleixner | b4ea929 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 130 | #ifdef CONFIG_NUMA |
| 131 | /* Returns the node based on pci bus */ |
Rusty Russell | 393d68f | 2008-12-26 22:23:38 +1030 | [diff] [blame] | 132 | static inline int __pcibus_to_node(const struct pci_bus *bus) |
Thomas Gleixner | b4ea929 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 133 | { |
Rusty Russell | 393d68f | 2008-12-26 22:23:38 +1030 | [diff] [blame] | 134 | const struct pci_sysdata *sd = bus->sysdata; |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 135 | |
Thomas Gleixner | b4ea929 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 136 | return sd->node; |
| 137 | } |
| 138 | |
Rusty Russell | 393d68f | 2008-12-26 22:23:38 +1030 | [diff] [blame] | 139 | static inline const struct cpumask * |
| 140 | cpumask_of_pcibus(const struct pci_bus *bus) |
| 141 | { |
David Rientjes | 7715a1e | 2009-09-18 03:41:10 -0700 | [diff] [blame] | 142 | int node; |
| 143 | |
| 144 | node = __pcibus_to_node(bus); |
Anshuman Khandual | 98fa15f | 2019-03-05 15:42:58 -0800 | [diff] [blame] | 145 | return (node == NUMA_NO_NODE) ? cpu_online_mask : |
David Rientjes | 7715a1e | 2009-09-18 03:41:10 -0700 | [diff] [blame] | 146 | cpumask_of_node(node); |
Rusty Russell | 393d68f | 2008-12-26 22:23:38 +1030 | [diff] [blame] | 147 | } |
Thomas Gleixner | b4ea929 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 148 | #endif |
Greg Kroah-Hartman | f3e6f16 | 2007-10-12 14:07:23 -0700 | [diff] [blame] | 149 | |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 150 | struct pci_setup_rom { |
| 151 | struct setup_data data; |
| 152 | uint16_t vendor; |
| 153 | uint16_t devid; |
| 154 | uint64_t pcilen; |
| 155 | unsigned long segment; |
| 156 | unsigned long bus; |
| 157 | unsigned long device; |
| 158 | unsigned long function; |
| 159 | uint8_t romdata[0]; |
| 160 | }; |
| 161 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 162 | #endif /* _ASM_X86_PCI_H */ |