xref: /openbmc/linux/arch/x86/include/asm/pci.h (revision 711aab1d)
1 #ifndef _ASM_X86_PCI_H
2 #define _ASM_X86_PCI_H
3 
4 #include <linux/mm.h> /* for struct page */
5 #include <linux/types.h>
6 #include <linux/slab.h>
7 #include <linux/string.h>
8 #include <linux/scatterlist.h>
9 #include <asm/io.h>
10 #include <asm/pat.h>
11 #include <asm/x86_init.h>
12 
13 #ifdef __KERNEL__
14 
15 struct pci_sysdata {
16 	int		domain;		/* PCI domain */
17 	int		node;		/* NUMA node */
18 #ifdef CONFIG_ACPI
19 	struct acpi_device *companion;	/* ACPI companion device */
20 #endif
21 #ifdef CONFIG_X86_64
22 	void		*iommu;		/* IOMMU private data */
23 #endif
24 #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
25 	void		*fwnode;	/* IRQ domain for MSI assignment */
26 #endif
27 #if IS_ENABLED(CONFIG_VMD)
28 	bool vmd_domain;		/* True if in Intel VMD domain */
29 #endif
30 };
31 
32 extern int pci_routeirq;
33 extern int noioapicquirk;
34 extern int noioapicreroute;
35 
36 #ifdef CONFIG_PCI
37 
38 #ifdef CONFIG_PCI_DOMAINS
39 static inline int pci_domain_nr(struct pci_bus *bus)
40 {
41 	struct pci_sysdata *sd = bus->sysdata;
42 
43 	return sd->domain;
44 }
45 
46 static inline int pci_proc_domain(struct pci_bus *bus)
47 {
48 	return pci_domain_nr(bus);
49 }
50 #endif
51 
52 #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
53 static inline void *_pci_root_bus_fwnode(struct pci_bus *bus)
54 {
55 	struct pci_sysdata *sd = bus->sysdata;
56 
57 	return sd->fwnode;
58 }
59 
60 #define pci_root_bus_fwnode	_pci_root_bus_fwnode
61 #endif
62 
63 static inline bool is_vmd(struct pci_bus *bus)
64 {
65 #if IS_ENABLED(CONFIG_VMD)
66 	struct pci_sysdata *sd = bus->sysdata;
67 
68 	return sd->vmd_domain;
69 #else
70 	return false;
71 #endif
72 }
73 
74 /* Can be used to override the logic in pci_scan_bus for skipping
75    already-configured bus numbers - to be used for buggy BIOSes
76    or architectures with incomplete PCI setup by the loader */
77 
78 extern unsigned int pcibios_assign_all_busses(void);
79 extern int pci_legacy_init(void);
80 #else
81 static inline int pcibios_assign_all_busses(void) { return 0; }
82 #endif
83 
84 extern unsigned long pci_mem_start;
85 #define PCIBIOS_MIN_IO		0x1000
86 #define PCIBIOS_MIN_MEM		(pci_mem_start)
87 
88 #define PCIBIOS_MIN_CARDBUS_IO	0x4000
89 
90 extern int pcibios_enabled;
91 void pcibios_config_init(void);
92 void pcibios_scan_root(int bus);
93 
94 void pcibios_set_master(struct pci_dev *dev);
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
100 #define arch_can_pci_mmap_wc()	pat_enabled()
101 #define ARCH_GENERIC_PCI_MMAP_RESOURCE
102 
103 #ifdef CONFIG_PCI
104 extern void early_quirks(void);
105 #else
106 static inline void early_quirks(void) { }
107 #endif
108 
109 extern void pci_iommu_alloc(void);
110 
111 #ifdef CONFIG_PCI_MSI
112 /* implemented in arch/x86/kernel/apic/io_apic. */
113 struct msi_desc;
114 int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
115 void native_teardown_msi_irq(unsigned int irq);
116 void 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 
122 #define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
123 
124 #endif  /* __KERNEL__ */
125 
126 #ifdef CONFIG_X86_64
127 #include <asm/pci_64.h>
128 #endif
129 
130 /* generic pci stuff */
131 #include <asm-generic/pci.h>
132 
133 #ifdef CONFIG_NUMA
134 /* Returns the node based on pci bus */
135 static inline int __pcibus_to_node(const struct pci_bus *bus)
136 {
137 	const struct pci_sysdata *sd = bus->sysdata;
138 
139 	return sd->node;
140 }
141 
142 static inline const struct cpumask *
143 cpumask_of_pcibus(const struct pci_bus *bus)
144 {
145 	int node;
146 
147 	node = __pcibus_to_node(bus);
148 	return (node == -1) ? cpu_online_mask :
149 			      cpumask_of_node(node);
150 }
151 #endif
152 
153 struct pci_setup_rom {
154 	struct setup_data data;
155 	uint16_t vendor;
156 	uint16_t devid;
157 	uint64_t pcilen;
158 	unsigned long segment;
159 	unsigned long bus;
160 	unsigned long device;
161 	unsigned long function;
162 	uint8_t romdata[0];
163 };
164 
165 #endif /* _ASM_X86_PCI_H */
166