xref: /openbmc/linux/arch/x86/include/asm/pci.h (revision 3098f5eb)
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 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_scan_root(int bus);
92 
93 struct irq_routing_table *pcibios_get_irq_routing_table(void);
94 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
95 
96 
97 #define HAVE_PCI_MMAP
98 #define arch_can_pci_mmap_wc()	pat_enabled()
99 #define ARCH_GENERIC_PCI_MMAP_RESOURCE
100 
101 #ifdef CONFIG_PCI
102 extern void early_quirks(void);
103 #else
104 static inline void early_quirks(void) { }
105 #endif
106 
107 extern void pci_iommu_alloc(void);
108 
109 #ifdef CONFIG_PCI_MSI
110 /* implemented in arch/x86/kernel/apic/io_apic. */
111 struct msi_desc;
112 int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
113 void native_teardown_msi_irq(unsigned int irq);
114 void native_restore_msi_irqs(struct pci_dev *dev);
115 #else
116 #define native_setup_msi_irqs		NULL
117 #define native_teardown_msi_irq		NULL
118 #endif
119 
120 /* generic pci stuff */
121 #include <asm-generic/pci.h>
122 
123 #ifdef CONFIG_NUMA
124 /* Returns the node based on pci bus */
125 static inline int __pcibus_to_node(const struct pci_bus *bus)
126 {
127 	const struct pci_sysdata *sd = bus->sysdata;
128 
129 	return sd->node;
130 }
131 
132 static inline const struct cpumask *
133 cpumask_of_pcibus(const struct pci_bus *bus)
134 {
135 	int node;
136 
137 	node = __pcibus_to_node(bus);
138 	return (node == NUMA_NO_NODE) ? cpu_online_mask :
139 			      cpumask_of_node(node);
140 }
141 #endif
142 
143 struct pci_setup_rom {
144 	struct setup_data data;
145 	uint16_t vendor;
146 	uint16_t devid;
147 	uint64_t pcilen;
148 	unsigned long segment;
149 	unsigned long bus;
150 	unsigned long device;
151 	unsigned long function;
152 	uint8_t romdata[0];
153 };
154 
155 #endif /* _ASM_X86_PCI_H */
156