1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 282487711SJaswinder Singh Rajput /* 382487711SJaswinder Singh Rajput * Low-Level PCI Access for i386 machines. 482487711SJaswinder Singh Rajput * 582487711SJaswinder Singh Rajput * (c) 1999 Martin Mares <mj@ucw.cz> 682487711SJaswinder Singh Rajput */ 782487711SJaswinder Singh Rajput 85520b7e7SIngo Molnar #include <linux/ioport.h> 95520b7e7SIngo Molnar 1082487711SJaswinder Singh Rajput #undef DEBUG 1182487711SJaswinder Singh Rajput 1282487711SJaswinder Singh Rajput #ifdef DEBUG 13c767a54bSJoe Perches #define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__) 1482487711SJaswinder Singh Rajput #else 15c767a54bSJoe Perches #define DBG(fmt, ...) \ 16c767a54bSJoe Perches do { \ 17c767a54bSJoe Perches if (0) \ 18c767a54bSJoe Perches printk(fmt, ##__VA_ARGS__); \ 19c767a54bSJoe Perches } while (0) 2082487711SJaswinder Singh Rajput #endif 2182487711SJaswinder Singh Rajput 2282487711SJaswinder Singh Rajput #define PCI_PROBE_BIOS 0x0001 2382487711SJaswinder Singh Rajput #define PCI_PROBE_CONF1 0x0002 2482487711SJaswinder Singh Rajput #define PCI_PROBE_CONF2 0x0004 2582487711SJaswinder Singh Rajput #define PCI_PROBE_MMCONF 0x0008 2682487711SJaswinder Singh Rajput #define PCI_PROBE_MASK 0x000f 2782487711SJaswinder Singh Rajput #define PCI_PROBE_NOEARLY 0x0010 2882487711SJaswinder Singh Rajput 2982487711SJaswinder Singh Rajput #define PCI_NO_CHECKS 0x0400 3082487711SJaswinder Singh Rajput #define PCI_USE_PIRQ_MASK 0x0800 3182487711SJaswinder Singh Rajput #define PCI_ASSIGN_ROMS 0x1000 3282487711SJaswinder Singh Rajput #define PCI_BIOS_IRQ_SCAN 0x2000 3382487711SJaswinder Singh Rajput #define PCI_ASSIGN_ALL_BUSSES 0x4000 3482487711SJaswinder Singh Rajput #define PCI_CAN_SKIP_ISA_ALIGN 0x8000 35236e946bSLinus Torvalds #define PCI_USE__CRS 0x10000 3682487711SJaswinder Singh Rajput #define PCI_CHECK_ENABLE_AMD_MMCONF 0x20000 3782487711SJaswinder Singh Rajput #define PCI_HAS_IO_ECS 0x40000 3882487711SJaswinder Singh Rajput #define PCI_NOASSIGN_ROMS 0x80000 397bc5e3f2SBjorn Helgaas #define PCI_ROOT_NO_CRS 0x100000 407bd1c365SMike Habeck #define PCI_NOASSIGN_BARS 0x200000 41f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= #define PCI_BIG_ROOT_WINDOW 0x400000 4282487711SJaswinder Singh Rajput 4382487711SJaswinder Singh Rajput extern unsigned int pci_probe; 4482487711SJaswinder Singh Rajput extern unsigned long pirq_table_addr; 4582487711SJaswinder Singh Rajput 4682487711SJaswinder Singh Rajput enum pci_bf_sort_state { 4782487711SJaswinder Singh Rajput pci_bf_sort_default, 4882487711SJaswinder Singh Rajput pci_force_nobf, 4982487711SJaswinder Singh Rajput pci_force_bf, 5082487711SJaswinder Singh Rajput pci_dmi_bf, 5182487711SJaswinder Singh Rajput }; 5282487711SJaswinder Singh Rajput 5382487711SJaswinder Singh Rajput /* pci-i386.c */ 5482487711SJaswinder Singh Rajput 5582487711SJaswinder Singh Rajput void pcibios_resource_survey(void); 5644de3395SAlex Nixon void pcibios_set_cache_line_size(void); 5782487711SJaswinder Singh Rajput 5882487711SJaswinder Singh Rajput /* pci-pc.c */ 5982487711SJaswinder Singh Rajput 6082487711SJaswinder Singh Rajput extern int pcibios_last_bus; 6182487711SJaswinder Singh Rajput extern struct pci_ops pci_root_ops; 6282487711SJaswinder Singh Rajput 635707b24aSAristeu Rozanski void pcibios_scan_specific_bus(int busn); 645707b24aSAristeu Rozanski 6582487711SJaswinder Singh Rajput /* pci-irq.c */ 6682487711SJaswinder Singh Rajput 6782487711SJaswinder Singh Rajput struct irq_info { 6882487711SJaswinder Singh Rajput u8 bus, devfn; /* Bus, device and function */ 6982487711SJaswinder Singh Rajput struct { 7082487711SJaswinder Singh Rajput u8 link; /* IRQ line ID, chipset dependent, 7182487711SJaswinder Singh Rajput 0 = not routed */ 7282487711SJaswinder Singh Rajput u16 bitmap; /* Available IRQs */ 7382487711SJaswinder Singh Rajput } __attribute__((packed)) irq[4]; 7482487711SJaswinder Singh Rajput u8 slot; /* Slot number, 0=onboard */ 7582487711SJaswinder Singh Rajput u8 rfu; 7682487711SJaswinder Singh Rajput } __attribute__((packed)); 7782487711SJaswinder Singh Rajput 7882487711SJaswinder Singh Rajput struct irq_routing_table { 7982487711SJaswinder Singh Rajput u32 signature; /* PIRQ_SIGNATURE should be here */ 8082487711SJaswinder Singh Rajput u16 version; /* PIRQ_VERSION */ 8182487711SJaswinder Singh Rajput u16 size; /* Table size in bytes */ 8282487711SJaswinder Singh Rajput u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */ 8382487711SJaswinder Singh Rajput u16 exclusive_irqs; /* IRQs devoted exclusively to 8482487711SJaswinder Singh Rajput PCI usage */ 8582487711SJaswinder Singh Rajput u16 rtr_vendor, rtr_device; /* Vendor and device ID of 8682487711SJaswinder Singh Rajput interrupt router */ 8782487711SJaswinder Singh Rajput u32 miniport_data; /* Crap */ 8882487711SJaswinder Singh Rajput u8 rfu[11]; 8982487711SJaswinder Singh Rajput u8 checksum; /* Modulo 256 checksum must give 0 */ 9082487711SJaswinder Singh Rajput struct irq_info slots[0]; 9182487711SJaswinder Singh Rajput } __attribute__((packed)); 9282487711SJaswinder Singh Rajput 9382487711SJaswinder Singh Rajput extern unsigned int pcibios_irq_mask; 9482487711SJaswinder Singh Rajput 95d19f61f0SThomas Gleixner extern raw_spinlock_t pci_config_lock; 9682487711SJaswinder Singh Rajput 9782487711SJaswinder Singh Rajput extern int (*pcibios_enable_irq)(struct pci_dev *dev); 9882487711SJaswinder Singh Rajput extern void (*pcibios_disable_irq)(struct pci_dev *dev); 9982487711SJaswinder Singh Rajput 1006c777e87SBjorn Helgaas extern bool mp_should_keep_irq(struct device *dev); 1016c777e87SBjorn Helgaas 10282487711SJaswinder Singh Rajput struct pci_raw_ops { 10382487711SJaswinder Singh Rajput int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn, 10482487711SJaswinder Singh Rajput int reg, int len, u32 *val); 10582487711SJaswinder Singh Rajput int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn, 10682487711SJaswinder Singh Rajput int reg, int len, u32 val); 10782487711SJaswinder Singh Rajput }; 10882487711SJaswinder Singh Rajput 10972da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ops; 11072da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ext_ops; 11182487711SJaswinder Singh Rajput 112c0fa4078SJiang Liu extern const struct pci_raw_ops pci_mmcfg; 11372da0b07SJan Beulich extern const struct pci_raw_ops pci_direct_conf1; 11482487711SJaswinder Singh Rajput extern bool port_cf9_safe; 11582487711SJaswinder Singh Rajput 11682487711SJaswinder Singh Rajput /* arch_initcall level */ 11782487711SJaswinder Singh Rajput extern int pci_direct_probe(void); 11882487711SJaswinder Singh Rajput extern void pci_direct_init(int type); 11982487711SJaswinder Singh Rajput extern void pci_pcbios_init(void); 12082487711SJaswinder Singh Rajput extern void __init dmi_check_pciprobe(void); 12182487711SJaswinder Singh Rajput extern void __init dmi_check_skip_isa_align(void); 12282487711SJaswinder Singh Rajput 12382487711SJaswinder Singh Rajput /* some common used subsys_initcalls */ 124*5d32a665SSinan Kaya #ifdef CONFIG_PCI 12582487711SJaswinder Singh Rajput extern int __init pci_acpi_init(void); 126*5d32a665SSinan Kaya #else 127*5d32a665SSinan Kaya static inline int __init pci_acpi_init(void) 128*5d32a665SSinan Kaya { 129*5d32a665SSinan Kaya return -EINVAL; 130*5d32a665SSinan Kaya } 131*5d32a665SSinan Kaya #endif 132ab3b3793SThomas Gleixner extern void __init pcibios_irq_init(void); 13382487711SJaswinder Singh Rajput extern int __init pcibios_init(void); 134b72d0db9SThomas Gleixner extern int pci_legacy_init(void); 1359325a28cSThomas Gleixner extern void pcibios_fixup_irqs(void); 13682487711SJaswinder Singh Rajput 13782487711SJaswinder Singh Rajput /* pci-mmconfig.c */ 13882487711SJaswinder Singh Rajput 13956ddf4d3SBjorn Helgaas /* "PCI MMCONFIG %04x [bus %02x-%02x]" */ 14056ddf4d3SBjorn Helgaas #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2) 14156ddf4d3SBjorn Helgaas 142d215a9c8SBjorn Helgaas struct pci_mmcfg_region { 143ff097dddSBjorn Helgaas struct list_head list; 14456ddf4d3SBjorn Helgaas struct resource res; 145d215a9c8SBjorn Helgaas u64 address; 1463f0f5503SBjorn Helgaas char __iomem *virt; 147d7e6b66fSBjorn Helgaas u16 segment; 148d7e6b66fSBjorn Helgaas u8 start_bus; 149d7e6b66fSBjorn Helgaas u8 end_bus; 15056ddf4d3SBjorn Helgaas char name[PCI_MMCFG_RESOURCE_NAME_LEN]; 151d215a9c8SBjorn Helgaas }; 152d215a9c8SBjorn Helgaas 15382487711SJaswinder Singh Rajput extern int __init pci_mmcfg_arch_init(void); 15482487711SJaswinder Singh Rajput extern void __init pci_mmcfg_arch_free(void); 155a18e3690SGreg Kroah-Hartman extern int pci_mmcfg_arch_map(struct pci_mmcfg_region *cfg); 1569cf0105dSJiang Liu extern void pci_mmcfg_arch_unmap(struct pci_mmcfg_region *cfg); 157a18e3690SGreg Kroah-Hartman extern int pci_mmconfig_insert(struct device *dev, u16 seg, u8 start, u8 end, 158a18e3690SGreg Kroah-Hartman phys_addr_t addr); 1599c95111bSJiang Liu extern int pci_mmconfig_delete(u16 seg, u8 start, u8 end); 160f6e1d8ccSBjorn Helgaas extern struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus); 1616fa4a94eSOtavio Pontes extern struct pci_mmcfg_region *__init pci_mmconfig_add(int segment, int start, 1626fa4a94eSOtavio Pontes int end, u64 addr); 16382487711SJaswinder Singh Rajput 164ff097dddSBjorn Helgaas extern struct list_head pci_mmcfg_list; 165c4bf2f37SLen Brown 166df5eb1d6SBjorn Helgaas #define PCI_MMCFG_BUS_OFFSET(bus) ((bus) << 20) 167df5eb1d6SBjorn Helgaas 16882487711SJaswinder Singh Rajput /* 16921461775STomasz Nowicki * On AMD Fam10h CPUs, all PCI MMIO configuration space accesses must use 17021461775STomasz Nowicki * %eax. No other source or target registers may be used. The following 17121461775STomasz Nowicki * mmio_config_* accessors enforce this. See "BIOS and Kernel Developer's 17221461775STomasz Nowicki * Guide (BKDG) For AMD Family 10h Processors", rev. 3.48, sec 2.11.1, 17321461775STomasz Nowicki * "MMIO Configuration Coding Requirements". 17482487711SJaswinder Singh Rajput */ 17582487711SJaswinder Singh Rajput static inline unsigned char mmio_config_readb(void __iomem *pos) 17682487711SJaswinder Singh Rajput { 17782487711SJaswinder Singh Rajput u8 val; 17882487711SJaswinder Singh Rajput asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos)); 17982487711SJaswinder Singh Rajput return val; 18082487711SJaswinder Singh Rajput } 18182487711SJaswinder Singh Rajput 18282487711SJaswinder Singh Rajput static inline unsigned short mmio_config_readw(void __iomem *pos) 18382487711SJaswinder Singh Rajput { 18482487711SJaswinder Singh Rajput u16 val; 18582487711SJaswinder Singh Rajput asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos)); 18682487711SJaswinder Singh Rajput return val; 18782487711SJaswinder Singh Rajput } 18882487711SJaswinder Singh Rajput 18982487711SJaswinder Singh Rajput static inline unsigned int mmio_config_readl(void __iomem *pos) 19082487711SJaswinder Singh Rajput { 19182487711SJaswinder Singh Rajput u32 val; 19282487711SJaswinder Singh Rajput asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos)); 19382487711SJaswinder Singh Rajput return val; 19482487711SJaswinder Singh Rajput } 19582487711SJaswinder Singh Rajput 19682487711SJaswinder Singh Rajput static inline void mmio_config_writeb(void __iomem *pos, u8 val) 19782487711SJaswinder Singh Rajput { 19882487711SJaswinder Singh Rajput asm volatile("movb %%al,(%1)" : : "a" (val), "r" (pos) : "memory"); 19982487711SJaswinder Singh Rajput } 20082487711SJaswinder Singh Rajput 20182487711SJaswinder Singh Rajput static inline void mmio_config_writew(void __iomem *pos, u16 val) 20282487711SJaswinder Singh Rajput { 20382487711SJaswinder Singh Rajput asm volatile("movw %%ax,(%1)" : : "a" (val), "r" (pos) : "memory"); 20482487711SJaswinder Singh Rajput } 20582487711SJaswinder Singh Rajput 20682487711SJaswinder Singh Rajput static inline void mmio_config_writel(void __iomem *pos, u32 val) 20782487711SJaswinder Singh Rajput { 20882487711SJaswinder Singh Rajput asm volatile("movl %%eax,(%1)" : : "a" (val), "r" (pos) : "memory"); 20982487711SJaswinder Singh Rajput } 210b72d0db9SThomas Gleixner 211b72d0db9SThomas Gleixner #ifdef CONFIG_PCI 212b72d0db9SThomas Gleixner # ifdef CONFIG_ACPI 213b72d0db9SThomas Gleixner # define x86_default_pci_init pci_acpi_init 214b72d0db9SThomas Gleixner # else 215b72d0db9SThomas Gleixner # define x86_default_pci_init pci_legacy_init 216b72d0db9SThomas Gleixner # endif 217ab3b3793SThomas Gleixner # define x86_default_pci_init_irq pcibios_irq_init 2189325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs pcibios_fixup_irqs 219b72d0db9SThomas Gleixner #else 220b72d0db9SThomas Gleixner # define x86_default_pci_init NULL 221ab3b3793SThomas Gleixner # define x86_default_pci_init_irq NULL 2229325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs NULL 223b72d0db9SThomas Gleixner #endif 224