blob: f6e22c271efab5c4e27b59db0626ed852407ac25 [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 -0700107extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
Joe Perches69bdb7b2008-03-23 01:03:04 -0700108 enum pci_mmap_state mmap_state,
109 int write_combine);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700110
111
112#ifdef CONFIG_PCI
Thomas Gleixner376ff032008-01-30 13:30:16 +0100113extern void early_quirks(void);
Thomas Gleixner376ff032008-01-30 13:30:16 +0100114#else
115static inline void early_quirks(void) { }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700116#endif
117
Jeremy Fitzhardingecfb80c92008-12-16 12:17:36 -0800118extern void pci_iommu_alloc(void);
119
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400120#ifdef CONFIG_PCI_MSI
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400121/* implemented in arch/x86/kernel/apic/io_apic. */
Joerg Roedel5afba622012-09-26 12:44:38 +0200122struct msi_desc;
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400123int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
124void native_teardown_msi_irq(unsigned int irq);
DuanZhenzhongac8344c2013-12-04 13:09:16 +0800125void native_restore_msi_irqs(struct pci_dev *dev);
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400126#else
127#define native_setup_msi_irqs NULL
128#define native_teardown_msi_irq NULL
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400129#endif
Michael Ellerman11df1f02009-01-19 11:31:00 +1100130
Joerg Roedel67796bf2009-04-02 15:55:55 +0200131#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
132
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700133#endif /* __KERNEL__ */
134
Joerg Roedel67796bf2009-04-02 15:55:55 +0200135#ifdef CONFIG_X86_64
David Howellsa1ce3922012-10-02 18:01:25 +0100136#include <asm/pci_64.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200137#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700138
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700139/* generic pci stuff */
140#include <asm-generic/pci.h>
141
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100142#ifdef CONFIG_NUMA
143/* Returns the node based on pci bus */
Rusty Russell393d68f2008-12-26 22:23:38 +1030144static inline int __pcibus_to_node(const struct pci_bus *bus)
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100145{
Rusty Russell393d68f2008-12-26 22:23:38 +1030146 const struct pci_sysdata *sd = bus->sysdata;
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700147
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100148 return sd->node;
149}
150
Rusty Russell393d68f2008-12-26 22:23:38 +1030151static inline const struct cpumask *
152cpumask_of_pcibus(const struct pci_bus *bus)
153{
David Rientjes7715a1e2009-09-18 03:41:10 -0700154 int node;
155
156 node = __pcibus_to_node(bus);
157 return (node == -1) ? cpu_online_mask :
158 cpumask_of_node(node);
Rusty Russell393d68f2008-12-26 22:23:38 +1030159}
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100160#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700161
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700162struct pci_setup_rom {
163 struct setup_data data;
164 uint16_t vendor;
165 uint16_t devid;
166 uint64_t pcilen;
167 unsigned long segment;
168 unsigned long bus;
169 unsigned long device;
170 unsigned long function;
171 uint8_t romdata[0];
172};
173
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700174#endif /* _ASM_X86_PCI_H */