blob: 662963681ea6c3f7d9235c246734844592579755 [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>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070010#include <asm/io.h>
David Woodhouseae749c72017-04-12 13:25:54 +010011#include <asm/pat.h>
Stefano Stabellini294ee6f2010-10-06 16:12:28 -040012#include <asm/x86_init.h>
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070013
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070014#ifdef __KERNEL__
15
16struct pci_sysdata {
17 int domain; /* PCI domain */
18 int node; /* NUMA node */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010019#ifdef CONFIG_ACPI
Rafael J. Wysocki7b199812013-11-11 22:41:56 +010020 struct acpi_device *companion; /* ACPI companion device */
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +010021#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070022#ifdef CONFIG_X86_64
Joe Perches69bdb7b2008-03-23 01:03:04 -070023 void *iommu; /* IOMMU private data */
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070024#endif
Jake Oshins92016ba2016-02-16 21:56:21 +000025#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
26 void *fwnode; /* IRQ domain for MSI assignment */
27#endif
Keith Busch31618322016-09-13 09:05:40 -060028#if IS_ENABLED(CONFIG_VMD)
29 bool vmd_domain; /* True if in Intel VMD domain */
30#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070031};
32
Thomas Gleixner07156502008-05-12 15:43:37 +020033extern int pci_routeirq;
Ingo Molnar7a9787e2008-10-28 16:26:12 +010034extern int noioapicquirk;
35extern int noioapicreroute;
Thomas Gleixner07156502008-05-12 15:43:37 +020036
Jesse Barnes23b90cf2010-08-17 09:15:24 -070037#ifdef CONFIG_PCI
38
39#ifdef CONFIG_PCI_DOMAINS
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070040static inline int pci_domain_nr(struct pci_bus *bus)
41{
42 struct pci_sysdata *sd = bus->sysdata;
Jake Oshins92016ba2016-02-16 21:56:21 +000043
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070044 return sd->domain;
45}
46
47static inline int pci_proc_domain(struct pci_bus *bus)
48{
49 return pci_domain_nr(bus);
50}
Jesse Barnes23b90cf2010-08-17 09:15:24 -070051#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070052
Jake Oshins92016ba2016-02-16 21:56:21 +000053#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
54static inline void *_pci_root_bus_fwnode(struct pci_bus *bus)
55{
56 struct pci_sysdata *sd = bus->sysdata;
57
58 return sd->fwnode;
59}
60
61#define pci_root_bus_fwnode _pci_root_bus_fwnode
62#endif
63
Keith Busch31618322016-09-13 09:05:40 -060064static inline bool is_vmd(struct pci_bus *bus)
65{
66#if IS_ENABLED(CONFIG_VMD)
67 struct pci_sysdata *sd = bus->sysdata;
68
69 return sd->vmd_domain;
70#else
71 return false;
72#endif
73}
74
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070075/* Can be used to override the logic in pci_scan_bus for skipping
76 already-configured bus numbers - to be used for buggy BIOSes
77 or architectures with incomplete PCI setup by the loader */
78
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070079extern unsigned int pcibios_assign_all_busses(void);
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020080extern int pci_legacy_init(void);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070081#else
Thomas Gleixner9304d162017-03-16 22:50:03 +010082static inline int pcibios_assign_all_busses(void) { return 0; }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070083#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070084
85extern unsigned long pci_mem_start;
86#define PCIBIOS_MIN_IO 0x1000
87#define PCIBIOS_MIN_MEM (pci_mem_start)
88
89#define PCIBIOS_MIN_CARDBUS_IO 0x4000
90
Matthieu Castet5bd5a452010-11-16 22:31:26 +010091extern int pcibios_enabled;
Bjorn Helgaas49886cf2014-01-28 16:40:36 -070092void pcibios_scan_root(int bus);
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070093
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -070094struct irq_routing_table *pcibios_get_irq_routing_table(void);
95int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
96
97
98#define HAVE_PCI_MMAP
David Woodhouseae749c72017-04-12 13:25:54 +010099#define arch_can_pci_mmap_wc() pat_enabled()
David Woodhouse5c2d5ce2017-04-12 13:26:07 +0100100#define ARCH_GENERIC_PCI_MMAP_RESOURCE
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700101
102#ifdef CONFIG_PCI
Thomas Gleixner376ff032008-01-30 13:30:16 +0100103extern void early_quirks(void);
Thomas Gleixner376ff032008-01-30 13:30:16 +0100104#else
105static inline void early_quirks(void) { }
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700106#endif
107
Jeremy Fitzhardingecfb80c92008-12-16 12:17:36 -0800108extern void pci_iommu_alloc(void);
109
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400110#ifdef CONFIG_PCI_MSI
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400111/* implemented in arch/x86/kernel/apic/io_apic. */
Joerg Roedel5afba622012-09-26 12:44:38 +0200112struct msi_desc;
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400113int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
114void native_teardown_msi_irq(unsigned int irq);
DuanZhenzhongac8344c2013-12-04 13:09:16 +0800115void native_restore_msi_irqs(struct pci_dev *dev);
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400116#else
117#define native_setup_msi_irqs NULL
118#define native_teardown_msi_irq NULL
Stefano Stabellini294ee6f2010-10-06 16:12:28 -0400119#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700120#endif /* __KERNEL__ */
121
Joerg Roedel67796bf2009-04-02 15:55:55 +0200122#ifdef CONFIG_X86_64
David Howellsa1ce3922012-10-02 18:01:25 +0100123#include <asm/pci_64.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200124#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700125
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700126/* generic pci stuff */
127#include <asm-generic/pci.h>
128
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100129#ifdef CONFIG_NUMA
130/* Returns the node based on pci bus */
Rusty Russell393d68f2008-12-26 22:23:38 +1030131static inline int __pcibus_to_node(const struct pci_bus *bus)
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100132{
Rusty Russell393d68f2008-12-26 22:23:38 +1030133 const struct pci_sysdata *sd = bus->sysdata;
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700134
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100135 return sd->node;
136}
137
Rusty Russell393d68f2008-12-26 22:23:38 +1030138static inline const struct cpumask *
139cpumask_of_pcibus(const struct pci_bus *bus)
140{
David Rientjes7715a1e2009-09-18 03:41:10 -0700141 int node;
142
143 node = __pcibus_to_node(bus);
144 return (node == -1) ? cpu_online_mask :
145 cpumask_of_node(node);
Rusty Russell393d68f2008-12-26 22:23:38 +1030146}
Thomas Gleixnerb4ea9292008-01-30 13:30:38 +0100147#endif
Greg Kroah-Hartmanf3e6f162007-10-12 14:07:23 -0700148
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700149struct pci_setup_rom {
150 struct setup_data data;
151 uint16_t vendor;
152 uint16_t devid;
153 uint64_t pcilen;
154 unsigned long segment;
155 unsigned long bus;
156 unsigned long device;
157 unsigned long function;
158 uint8_t romdata[0];
159};
160
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700161#endif /* _ASM_X86_PCI_H */