blob: e662f987dfa2cb093a25e1684e06c0067e78eb58 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_PCI_H
3#define _ASM_X86_PCI_H
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -07004
5#include <linux/mm.h> /* for struct page */
6#include <linux/types.h>
7#include <linux/slab.h>
8#include <linux/string.h>
Christoph Hellwig84be4562015-05-01 12:46:15 +02009#include <linux/scatterlist.h>
Anshuman Khandual98fa15f2019-03-05 15:42:58 -080010#include <linux/numa.h>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070011#include <asm/io.h>
David Woodhouseae749c72017-04-12 13:25:54 +010012#include <asm/pat.h>
Stefano Stabellini294ee6f2010-10-06 16:12:28 -040013#include <asm/x86_init.h>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070014
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070015#ifdef __KERNEL__
16
17struct pci_sysdata {
18 int domain; /* PCI domain */
19 int node; /* NUMA node */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010020#ifdef CONFIG_ACPI
Rafael J. Wysocki7b199812013-11-11 22:41:56 +010021 struct acpi_device *companion; /* ACPI companion device */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010022#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070023#ifdef CONFIG_X86_64
Joe Perches69bdb7b2008-03-23 01:03:04 -070024 void *iommu; /* IOMMU private data */
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070025#endif
Jake Oshins92016ba2016-02-16 21:56:21 +000026#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
27 void *fwnode; /* IRQ domain for MSI assignment */
28#endif
Keith Busch31618322016-09-13 09:05:40 -060029#if IS_ENABLED(CONFIG_VMD)
30 bool vmd_domain; /* True if in Intel VMD domain */
31#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070032};
33
Thomas Gleixner07156502008-05-12 15:43:37 +020034extern int pci_routeirq;
Ingo Molnar7a9787e2008-10-28 16:26:12 +010035extern int noioapicquirk;
36extern int noioapicreroute;
Thomas Gleixner07156502008-05-12 15:43:37 +020037
Jesse Barnes23b90cf2010-08-17 09:15:24 -070038#ifdef CONFIG_PCI
39
40#ifdef CONFIG_PCI_DOMAINS
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070041static inline int pci_domain_nr(struct pci_bus *bus)
42{
43 struct pci_sysdata *sd = bus->sysdata;
Jake Oshins92016ba2016-02-16 21:56:21 +000044
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070045 return sd->domain;
46}
47
48static inline int pci_proc_domain(struct pci_bus *bus)
49{
50 return pci_domain_nr(bus);
51}
Jesse Barnes23b90cf2010-08-17 09:15:24 -070052#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070053
Jake Oshins92016ba2016-02-16 21:56:21 +000054#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
Keith Busch31618322016-09-13 09:05:40 -060065static 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
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070076/* 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
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070080extern unsigned int pcibios_assign_all_busses(void);
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020081extern int pci_legacy_init(void);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070082#else
Thomas Gleixner9304d162017-03-16 22:50:03 +010083static inline int pcibios_assign_all_busses(void) { return 0; }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070084#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070085
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
Matthieu Castet5bd5a452010-11-16 22:31:26 +010092extern int pcibios_enabled;
Bjorn Helgaas49886cf2014-01-28 16:40:36 -070093void pcibios_scan_root(int bus);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070094
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070095struct 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
David Woodhouseae749c72017-04-12 13:25:54 +0100100#define arch_can_pci_mmap_wc() pat_enabled()
David Woodhouse5c2d5ce2017-04-12 13:26:07 +0100101#define ARCH_GENERIC_PCI_MMAP_RESOURCE
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700102
103#ifdef CONFIG_PCI
Thomas Gleixner376ff032008-01-30 13:30:16 +0100104extern void early_quirks(void);
Thomas Gleixner376ff032008-01-30 13:30:16 +0100105#else
106static inline void early_quirks(void) { }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700107#endif
108
Jeremy Fitzhardingecfb80c92008-12-16 12:17:36 -0800109extern void pci_iommu_alloc(void);
110
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400111#ifdef CONFIG_PCI_MSI
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400112/* implemented in arch/x86/kernel/apic/io_apic. */
Joerg Roedel5afba622012-09-26 12:44:38 +0200113struct msi_desc;
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400114int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
115void native_teardown_msi_irq(unsigned int irq);
DuanZhenzhongac8344c2013-12-04 13:09:16 +0800116void native_restore_msi_irqs(struct pci_dev *dev);
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400117#else
118#define native_setup_msi_irqs NULL
119#define native_teardown_msi_irq NULL
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400120#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700121#endif /* __KERNEL__ */
122
Joerg Roedel67796bf2009-04-02 15:55:55 +0200123#ifdef CONFIG_X86_64
David Howellsa1ce3922012-10-02 18:01:25 +0100124#include <asm/pci_64.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200125#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700126
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700127/* generic pci stuff */
128#include <asm-generic/pci.h>
129
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100130#ifdef CONFIG_NUMA
131/* Returns the node based on pci bus */
Rusty Russell393d68f2008-12-26 22:23:38 +1030132static inline int __pcibus_to_node(const struct pci_bus *bus)
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100133{
Rusty Russell393d68f2008-12-26 22:23:38 +1030134 const struct pci_sysdata *sd = bus->sysdata;
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700135
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100136 return sd->node;
137}
138
Rusty Russell393d68f2008-12-26 22:23:38 +1030139static inline const struct cpumask *
140cpumask_of_pcibus(const struct pci_bus *bus)
141{
David Rientjes7715a1e2009-09-18 03:41:10 -0700142 int node;
143
144 node = __pcibus_to_node(bus);
Anshuman Khandual98fa15f2019-03-05 15:42:58 -0800145 return (node == NUMA_NO_NODE) ? cpu_online_mask :
David Rientjes7715a1e2009-09-18 03:41:10 -0700146 cpumask_of_node(node);
Rusty Russell393d68f2008-12-26 22:23:38 +1030147}
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100148#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700149
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700150struct 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
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700162#endif /* _ASM_X86_PCI_H */