1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_PCI_H
3#define _ASM_X86_PCI_H
4
5#include <linux/mm.h> /* for struct page */
6#include <linux/types.h>
7#include <linux/slab.h>
8#include <linux/string.h>
9#include <linux/scatterlist.h>
10#include <linux/numa.h>
11#include <asm/io.h>
12#include <asm/pat.h>
13#include <asm/x86_init.h>
14
15#ifdef __KERNEL__
16
17struct pci_sysdata {
18 int domain; /* PCI domain */
19 int node; /* NUMA node */
20#ifdef CONFIG_ACPI
21 struct acpi_device *companion; /* ACPI companion device */
22#endif
23#ifdef CONFIG_X86_64
24 void *iommu; /* IOMMU private data */
25#endif
26#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
27 void *fwnode; /* IRQ domain for MSI assignment */
28#endif
29#if IS_ENABLED(CONFIG_VMD)
30 bool vmd_domain; /* True if in Intel VMD domain */
31#endif
32};
33
34extern int pci_routeirq;
35extern int noioapicquirk;
36extern int noioapicreroute;
37
38#ifdef CONFIG_PCI
39
40#ifdef CONFIG_PCI_DOMAINS
41static inline int pci_domain_nr(struct pci_bus *bus)
42{
43 struct pci_sysdata *sd = bus->sysdata;
44
45 return sd->domain;
46}
47
48static inline int pci_proc_domain(struct pci_bus *bus)
49{
50 return pci_domain_nr(bus);
51}
52#endif
53
54#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
55static 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
65static 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
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
80extern unsigned int pcibios_assign_all_busses(void);
81extern int pci_legacy_init(void);
82#else
83static inline int pcibios_assign_all_busses(void) { return 0; }
84#endif
85
86extern 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
92extern int pcibios_enabled;
93void pcibios_scan_root(int bus);
94
95struct irq_routing_table *pcibios_get_irq_routing_table(void);
96int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
97
98
99#define HAVE_PCI_MMAP
100#define arch_can_pci_mmap_wc() pat_enabled()
101#define ARCH_GENERIC_PCI_MMAP_RESOURCE
102
103#ifdef CONFIG_PCI
104extern void early_quirks(void);
105#else
106static inline void early_quirks(void) { }
107#endif
108
109extern void pci_iommu_alloc(void);
110
111#ifdef CONFIG_PCI_MSI
112/* implemented in arch/x86/kernel/apic/io_apic. */
113struct msi_desc;
114int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
115void native_teardown_msi_irq(unsigned int irq);
116void native_restore_msi_irqs(struct pci_dev *dev);
117#else
118#define native_setup_msi_irqs NULL
119#define native_teardown_msi_irq NULL
120#endif
121#endif /* __KERNEL__ */
122
123#ifdef CONFIG_X86_64
124#include <asm/pci_64.h>
125#endif
126
127/* generic pci stuff */
128#include <asm-generic/pci.h>
129
130#ifdef CONFIG_NUMA
131/* Returns the node based on pci bus */
132static inline int __pcibus_to_node(const struct pci_bus *bus)
133{
134 const struct pci_sysdata *sd = bus->sysdata;
135
136 return sd->node;
137}
138
139static inline const struct cpumask *
140cpumask_of_pcibus(const struct pci_bus *bus)
141{
142 int node;
143
144 node = __pcibus_to_node(bus);
145 return (node == NUMA_NO_NODE) ? cpu_online_mask :
146 cpumask_of_node(node);
147}
148#endif
149
150struct 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
162#endif /* _ASM_X86_PCI_H */
163