182487711SJaswinder Singh Rajput /* 282487711SJaswinder Singh Rajput * Low-Level PCI Access for i386 machines. 382487711SJaswinder Singh Rajput * 482487711SJaswinder Singh Rajput * (c) 1999 Martin Mares <mj@ucw.cz> 582487711SJaswinder Singh Rajput */ 682487711SJaswinder Singh Rajput 782487711SJaswinder Singh Rajput #undef DEBUG 882487711SJaswinder Singh Rajput 982487711SJaswinder Singh Rajput #ifdef DEBUG 1082487711SJaswinder Singh Rajput #define DBG(x...) printk(x) 1182487711SJaswinder Singh Rajput #else 1282487711SJaswinder Singh Rajput #define DBG(x...) 1382487711SJaswinder Singh Rajput #endif 1482487711SJaswinder Singh Rajput 1582487711SJaswinder Singh Rajput #define PCI_PROBE_BIOS 0x0001 1682487711SJaswinder Singh Rajput #define PCI_PROBE_CONF1 0x0002 1782487711SJaswinder Singh Rajput #define PCI_PROBE_CONF2 0x0004 1882487711SJaswinder Singh Rajput #define PCI_PROBE_MMCONF 0x0008 1982487711SJaswinder Singh Rajput #define PCI_PROBE_MASK 0x000f 2082487711SJaswinder Singh Rajput #define PCI_PROBE_NOEARLY 0x0010 2182487711SJaswinder Singh Rajput 2282487711SJaswinder Singh Rajput #define PCI_NO_CHECKS 0x0400 2382487711SJaswinder Singh Rajput #define PCI_USE_PIRQ_MASK 0x0800 2482487711SJaswinder Singh Rajput #define PCI_ASSIGN_ROMS 0x1000 2582487711SJaswinder Singh Rajput #define PCI_BIOS_IRQ_SCAN 0x2000 2682487711SJaswinder Singh Rajput #define PCI_ASSIGN_ALL_BUSSES 0x4000 2782487711SJaswinder Singh Rajput #define PCI_CAN_SKIP_ISA_ALIGN 0x8000 28236e946bSLinus Torvalds #define PCI_USE__CRS 0x10000 2982487711SJaswinder Singh Rajput #define PCI_CHECK_ENABLE_AMD_MMCONF 0x20000 3082487711SJaswinder Singh Rajput #define PCI_HAS_IO_ECS 0x40000 3182487711SJaswinder Singh Rajput #define PCI_NOASSIGN_ROMS 0x80000 327bc5e3f2SBjorn Helgaas #define PCI_ROOT_NO_CRS 0x100000 337bd1c365SMike Habeck #define PCI_NOASSIGN_BARS 0x200000 3482487711SJaswinder Singh Rajput 3582487711SJaswinder Singh Rajput extern unsigned int pci_probe; 3682487711SJaswinder Singh Rajput extern unsigned long pirq_table_addr; 3782487711SJaswinder Singh Rajput 3882487711SJaswinder Singh Rajput enum pci_bf_sort_state { 3982487711SJaswinder Singh Rajput pci_bf_sort_default, 4082487711SJaswinder Singh Rajput pci_force_nobf, 4182487711SJaswinder Singh Rajput pci_force_bf, 4282487711SJaswinder Singh Rajput pci_dmi_bf, 4382487711SJaswinder Singh Rajput }; 4482487711SJaswinder Singh Rajput 4582487711SJaswinder Singh Rajput /* pci-i386.c */ 4682487711SJaswinder Singh Rajput 4782487711SJaswinder Singh Rajput extern unsigned int pcibios_max_latency; 4882487711SJaswinder Singh Rajput 4982487711SJaswinder Singh Rajput void pcibios_resource_survey(void); 5044de3395SAlex Nixon void pcibios_set_cache_line_size(void); 5182487711SJaswinder Singh Rajput 5282487711SJaswinder Singh Rajput /* pci-pc.c */ 5382487711SJaswinder Singh Rajput 5482487711SJaswinder Singh Rajput extern int pcibios_last_bus; 5582487711SJaswinder Singh Rajput extern struct pci_bus *pci_root_bus; 5682487711SJaswinder Singh Rajput extern struct pci_ops pci_root_ops; 5782487711SJaswinder Singh Rajput 585707b24aSAristeu Rozanski void pcibios_scan_specific_bus(int busn); 595707b24aSAristeu Rozanski 6082487711SJaswinder Singh Rajput /* pci-irq.c */ 6182487711SJaswinder Singh Rajput 6282487711SJaswinder Singh Rajput struct irq_info { 6382487711SJaswinder Singh Rajput u8 bus, devfn; /* Bus, device and function */ 6482487711SJaswinder Singh Rajput struct { 6582487711SJaswinder Singh Rajput u8 link; /* IRQ line ID, chipset dependent, 6682487711SJaswinder Singh Rajput 0 = not routed */ 6782487711SJaswinder Singh Rajput u16 bitmap; /* Available IRQs */ 6882487711SJaswinder Singh Rajput } __attribute__((packed)) irq[4]; 6982487711SJaswinder Singh Rajput u8 slot; /* Slot number, 0=onboard */ 7082487711SJaswinder Singh Rajput u8 rfu; 7182487711SJaswinder Singh Rajput } __attribute__((packed)); 7282487711SJaswinder Singh Rajput 7382487711SJaswinder Singh Rajput struct irq_routing_table { 7482487711SJaswinder Singh Rajput u32 signature; /* PIRQ_SIGNATURE should be here */ 7582487711SJaswinder Singh Rajput u16 version; /* PIRQ_VERSION */ 7682487711SJaswinder Singh Rajput u16 size; /* Table size in bytes */ 7782487711SJaswinder Singh Rajput u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */ 7882487711SJaswinder Singh Rajput u16 exclusive_irqs; /* IRQs devoted exclusively to 7982487711SJaswinder Singh Rajput PCI usage */ 8082487711SJaswinder Singh Rajput u16 rtr_vendor, rtr_device; /* Vendor and device ID of 8182487711SJaswinder Singh Rajput interrupt router */ 8282487711SJaswinder Singh Rajput u32 miniport_data; /* Crap */ 8382487711SJaswinder Singh Rajput u8 rfu[11]; 8482487711SJaswinder Singh Rajput u8 checksum; /* Modulo 256 checksum must give 0 */ 8582487711SJaswinder Singh Rajput struct irq_info slots[0]; 8682487711SJaswinder Singh Rajput } __attribute__((packed)); 8782487711SJaswinder Singh Rajput 8882487711SJaswinder Singh Rajput extern unsigned int pcibios_irq_mask; 8982487711SJaswinder Singh Rajput 90d19f61f0SThomas Gleixner extern raw_spinlock_t pci_config_lock; 9182487711SJaswinder Singh Rajput 9282487711SJaswinder Singh Rajput extern int (*pcibios_enable_irq)(struct pci_dev *dev); 9382487711SJaswinder Singh Rajput extern void (*pcibios_disable_irq)(struct pci_dev *dev); 9482487711SJaswinder Singh Rajput 9582487711SJaswinder Singh Rajput struct pci_raw_ops { 9682487711SJaswinder Singh Rajput int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn, 9782487711SJaswinder Singh Rajput int reg, int len, u32 *val); 9882487711SJaswinder Singh Rajput int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn, 9982487711SJaswinder Singh Rajput int reg, int len, u32 val); 10082487711SJaswinder Singh Rajput }; 10182487711SJaswinder Singh Rajput 102*72da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ops; 103*72da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ext_ops; 10482487711SJaswinder Singh Rajput 105*72da0b07SJan Beulich extern const struct pci_raw_ops pci_direct_conf1; 10682487711SJaswinder Singh Rajput extern bool port_cf9_safe; 10782487711SJaswinder Singh Rajput 10882487711SJaswinder Singh Rajput /* arch_initcall level */ 10982487711SJaswinder Singh Rajput extern int pci_direct_probe(void); 11082487711SJaswinder Singh Rajput extern void pci_direct_init(int type); 11182487711SJaswinder Singh Rajput extern void pci_pcbios_init(void); 11282487711SJaswinder Singh Rajput extern void __init dmi_check_pciprobe(void); 11382487711SJaswinder Singh Rajput extern void __init dmi_check_skip_isa_align(void); 11482487711SJaswinder Singh Rajput 11582487711SJaswinder Singh Rajput /* some common used subsys_initcalls */ 11682487711SJaswinder Singh Rajput extern int __init pci_acpi_init(void); 117ab3b3793SThomas Gleixner extern void __init pcibios_irq_init(void); 11882487711SJaswinder Singh Rajput extern int __init pcibios_init(void); 119b72d0db9SThomas Gleixner extern int pci_legacy_init(void); 1209325a28cSThomas Gleixner extern void pcibios_fixup_irqs(void); 12182487711SJaswinder Singh Rajput 12282487711SJaswinder Singh Rajput /* pci-mmconfig.c */ 12382487711SJaswinder Singh Rajput 12456ddf4d3SBjorn Helgaas /* "PCI MMCONFIG %04x [bus %02x-%02x]" */ 12556ddf4d3SBjorn Helgaas #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2) 12656ddf4d3SBjorn Helgaas 127d215a9c8SBjorn Helgaas struct pci_mmcfg_region { 128ff097dddSBjorn Helgaas struct list_head list; 12956ddf4d3SBjorn Helgaas struct resource res; 130d215a9c8SBjorn Helgaas u64 address; 1313f0f5503SBjorn Helgaas char __iomem *virt; 132d7e6b66fSBjorn Helgaas u16 segment; 133d7e6b66fSBjorn Helgaas u8 start_bus; 134d7e6b66fSBjorn Helgaas u8 end_bus; 13556ddf4d3SBjorn Helgaas char name[PCI_MMCFG_RESOURCE_NAME_LEN]; 136d215a9c8SBjorn Helgaas }; 137d215a9c8SBjorn Helgaas 13882487711SJaswinder Singh Rajput extern int __init pci_mmcfg_arch_init(void); 13982487711SJaswinder Singh Rajput extern void __init pci_mmcfg_arch_free(void); 140f6e1d8ccSBjorn Helgaas extern struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus); 14182487711SJaswinder Singh Rajput 142ff097dddSBjorn Helgaas extern struct list_head pci_mmcfg_list; 143c4bf2f37SLen Brown 144df5eb1d6SBjorn Helgaas #define PCI_MMCFG_BUS_OFFSET(bus) ((bus) << 20) 145df5eb1d6SBjorn Helgaas 14682487711SJaswinder Singh Rajput /* 14782487711SJaswinder Singh Rajput * AMD Fam10h CPUs are buggy, and cannot access MMIO config space 14882487711SJaswinder Singh Rajput * on their northbrige except through the * %eax register. As such, you MUST 14982487711SJaswinder Singh Rajput * NOT use normal IOMEM accesses, you need to only use the magic mmio-config 15082487711SJaswinder Singh Rajput * accessor functions. 15182487711SJaswinder Singh Rajput * In fact just use pci_config_*, nothing else please. 15282487711SJaswinder Singh Rajput */ 15382487711SJaswinder Singh Rajput static inline unsigned char mmio_config_readb(void __iomem *pos) 15482487711SJaswinder Singh Rajput { 15582487711SJaswinder Singh Rajput u8 val; 15682487711SJaswinder Singh Rajput asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos)); 15782487711SJaswinder Singh Rajput return val; 15882487711SJaswinder Singh Rajput } 15982487711SJaswinder Singh Rajput 16082487711SJaswinder Singh Rajput static inline unsigned short mmio_config_readw(void __iomem *pos) 16182487711SJaswinder Singh Rajput { 16282487711SJaswinder Singh Rajput u16 val; 16382487711SJaswinder Singh Rajput asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos)); 16482487711SJaswinder Singh Rajput return val; 16582487711SJaswinder Singh Rajput } 16682487711SJaswinder Singh Rajput 16782487711SJaswinder Singh Rajput static inline unsigned int mmio_config_readl(void __iomem *pos) 16882487711SJaswinder Singh Rajput { 16982487711SJaswinder Singh Rajput u32 val; 17082487711SJaswinder Singh Rajput asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos)); 17182487711SJaswinder Singh Rajput return val; 17282487711SJaswinder Singh Rajput } 17382487711SJaswinder Singh Rajput 17482487711SJaswinder Singh Rajput static inline void mmio_config_writeb(void __iomem *pos, u8 val) 17582487711SJaswinder Singh Rajput { 17682487711SJaswinder Singh Rajput asm volatile("movb %%al,(%1)" : : "a" (val), "r" (pos) : "memory"); 17782487711SJaswinder Singh Rajput } 17882487711SJaswinder Singh Rajput 17982487711SJaswinder Singh Rajput static inline void mmio_config_writew(void __iomem *pos, u16 val) 18082487711SJaswinder Singh Rajput { 18182487711SJaswinder Singh Rajput asm volatile("movw %%ax,(%1)" : : "a" (val), "r" (pos) : "memory"); 18282487711SJaswinder Singh Rajput } 18382487711SJaswinder Singh Rajput 18482487711SJaswinder Singh Rajput static inline void mmio_config_writel(void __iomem *pos, u32 val) 18582487711SJaswinder Singh Rajput { 18682487711SJaswinder Singh Rajput asm volatile("movl %%eax,(%1)" : : "a" (val), "r" (pos) : "memory"); 18782487711SJaswinder Singh Rajput } 188b72d0db9SThomas Gleixner 189b72d0db9SThomas Gleixner #ifdef CONFIG_PCI 190b72d0db9SThomas Gleixner # ifdef CONFIG_ACPI 191b72d0db9SThomas Gleixner # define x86_default_pci_init pci_acpi_init 192b72d0db9SThomas Gleixner # else 193b72d0db9SThomas Gleixner # define x86_default_pci_init pci_legacy_init 194b72d0db9SThomas Gleixner # endif 195ab3b3793SThomas Gleixner # define x86_default_pci_init_irq pcibios_irq_init 1969325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs pcibios_fixup_irqs 197b72d0db9SThomas Gleixner #else 198b72d0db9SThomas Gleixner # define x86_default_pci_init NULL 199ab3b3793SThomas Gleixner # define x86_default_pci_init_irq NULL 2009325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs NULL 201b72d0db9SThomas Gleixner #endif 202