blob: 734cc9411b3a516db239b9fad641963ad85bf29e [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PCI_H
2#define _ASM_X86_PCI_H
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -07003
4#include <linux/mm.h> /* for struct page */
5#include <linux/types.h>
6#include <linux/slab.h>
7#include <linux/string.h>
Christoph Hellwig84be4562015-05-01 12:46:15 +02008#include <linux/scatterlist.h>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -07009#include <asm/io.h>
David Woodhouseae749c72017-04-12 13:25:54 +010010#include <asm/pat.h>
Stefano Stabellini294ee6f2010-10-06 16:12:28 -040011#include <asm/x86_init.h>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070012
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070013#ifdef __KERNEL__
14
15struct pci_sysdata {
16 int domain; /* PCI domain */
17 int node; /* NUMA node */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010018#ifdef CONFIG_ACPI
Rafael J. Wysocki7b199812013-11-11 22:41:56 +010019 struct acpi_device *companion; /* ACPI companion device */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010020#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070021#ifdef CONFIG_X86_64
Joe Perches69bdb7b2008-03-23 01:03:04 -070022 void *iommu; /* IOMMU private data */
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070023#endif
Jake Oshins92016ba2016-02-16 21:56:21 +000024#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
25 void *fwnode; /* IRQ domain for MSI assignment */
26#endif
Keith Busch31618322016-09-13 09:05:40 -060027#if IS_ENABLED(CONFIG_VMD)
28 bool vmd_domain; /* True if in Intel VMD domain */
29#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070030};
31
Thomas Gleixner07156502008-05-12 15:43:37 +020032extern int pci_routeirq;
Ingo Molnar7a9787e2008-10-28 16:26:12 +010033extern int noioapicquirk;
34extern int noioapicreroute;
Thomas Gleixner07156502008-05-12 15:43:37 +020035
Jesse Barnes23b90cf2010-08-17 09:15:24 -070036#ifdef CONFIG_PCI
37
38#ifdef CONFIG_PCI_DOMAINS
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070039static inline int pci_domain_nr(struct pci_bus *bus)
40{
41 struct pci_sysdata *sd = bus->sysdata;
Jake Oshins92016ba2016-02-16 21:56:21 +000042
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070043 return sd->domain;
44}
45
46static inline int pci_proc_domain(struct pci_bus *bus)
47{
48 return pci_domain_nr(bus);
49}
Jesse Barnes23b90cf2010-08-17 09:15:24 -070050#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070051
Jake Oshins92016ba2016-02-16 21:56:21 +000052#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
53static 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
Keith Busch31618322016-09-13 09:05:40 -060063static 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
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070074/* 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
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070078extern unsigned int pcibios_assign_all_busses(void);
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020079extern int pci_legacy_init(void);
80# ifdef CONFIG_ACPI
81# define x86_default_pci_init pci_acpi_init
82# else
83# define x86_default_pci_init pci_legacy_init
84# endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070085#else
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020086# define pcibios_assign_all_busses() 0
87# define x86_default_pci_init NULL
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070088#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070089
90extern unsigned long pci_mem_start;
91#define PCIBIOS_MIN_IO 0x1000
92#define PCIBIOS_MIN_MEM (pci_mem_start)
93
94#define PCIBIOS_MIN_CARDBUS_IO 0x4000
95
Matthieu Castet5bd5a452010-11-16 22:31:26 +010096extern int pcibios_enabled;
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070097void pcibios_config_init(void);
Bjorn Helgaas49886cf2014-01-28 16:40:36 -070098void pcibios_scan_root(int bus);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070099
100void pcibios_set_master(struct pci_dev *dev);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700101struct irq_routing_table *pcibios_get_irq_routing_table(void);
102int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
103
104
105#define HAVE_PCI_MMAP
David Woodhouseae749c72017-04-12 13:25:54 +0100106#define arch_can_pci_mmap_wc() pat_enabled()
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700107
108#ifdef CONFIG_PCI
Thomas Gleixner376ff032008-01-30 13:30:16 +0100109extern void early_quirks(void);
Thomas Gleixner376ff032008-01-30 13:30:16 +0100110#else
111static inline void early_quirks(void) { }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700112#endif
113
Jeremy Fitzhardingecfb80c92008-12-16 12:17:36 -0800114extern void pci_iommu_alloc(void);
115
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400116#ifdef CONFIG_PCI_MSI
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400117/* implemented in arch/x86/kernel/apic/io_apic. */
Joerg Roedel5afba622012-09-26 12:44:38 +0200118struct msi_desc;
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400119int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
120void native_teardown_msi_irq(unsigned int irq);
DuanZhenzhongac8344c2013-12-04 13:09:16 +0800121void native_restore_msi_irqs(struct pci_dev *dev);
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400122#else
123#define native_setup_msi_irqs NULL
124#define native_teardown_msi_irq NULL
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400125#endif
Michael Ellerman11df1f02009-01-19 11:31:00 +1100126
Joerg Roedel67796bf2009-04-02 15:55:55 +0200127#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
128
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700129#endif /* __KERNEL__ */
130
Joerg Roedel67796bf2009-04-02 15:55:55 +0200131#ifdef CONFIG_X86_64
David Howellsa1ce3922012-10-02 18:01:25 +0100132#include <asm/pci_64.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200133#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700134
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700135/* generic pci stuff */
136#include <asm-generic/pci.h>
137
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100138#ifdef CONFIG_NUMA
139/* Returns the node based on pci bus */
Rusty Russell393d68f2008-12-26 22:23:38 +1030140static inline int __pcibus_to_node(const struct pci_bus *bus)
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100141{
Rusty Russell393d68f2008-12-26 22:23:38 +1030142 const struct pci_sysdata *sd = bus->sysdata;
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700143
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100144 return sd->node;
145}
146
Rusty Russell393d68f2008-12-26 22:23:38 +1030147static inline const struct cpumask *
148cpumask_of_pcibus(const struct pci_bus *bus)
149{
David Rientjes7715a1e2009-09-18 03:41:10 -0700150 int node;
151
152 node = __pcibus_to_node(bus);
153 return (node == -1) ? cpu_online_mask :
154 cpumask_of_node(node);
Rusty Russell393d68f2008-12-26 22:23:38 +1030155}
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100156#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700157
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700158struct pci_setup_rom {
159 struct setup_data data;
160 uint16_t vendor;
161 uint16_t devid;
162 uint64_t pcilen;
163 unsigned long segment;
164 unsigned long bus;
165 unsigned long device;
166 unsigned long function;
167 uint8_t romdata[0];
168};
169
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700170#endif /* _ASM_X86_PCI_H */