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 void pcibios_resource_survey(void); 4844de3395SAlex Nixon void pcibios_set_cache_line_size(void); 4982487711SJaswinder Singh Rajput 5082487711SJaswinder Singh Rajput /* pci-pc.c */ 5182487711SJaswinder Singh Rajput 5282487711SJaswinder Singh Rajput extern int pcibios_last_bus; 5382487711SJaswinder Singh Rajput extern struct pci_bus *pci_root_bus; 5482487711SJaswinder Singh Rajput extern struct pci_ops pci_root_ops; 5582487711SJaswinder Singh Rajput 565707b24aSAristeu Rozanski void pcibios_scan_specific_bus(int busn); 575707b24aSAristeu Rozanski 5882487711SJaswinder Singh Rajput /* pci-irq.c */ 5982487711SJaswinder Singh Rajput 6082487711SJaswinder Singh Rajput struct irq_info { 6182487711SJaswinder Singh Rajput u8 bus, devfn; /* Bus, device and function */ 6282487711SJaswinder Singh Rajput struct { 6382487711SJaswinder Singh Rajput u8 link; /* IRQ line ID, chipset dependent, 6482487711SJaswinder Singh Rajput 0 = not routed */ 6582487711SJaswinder Singh Rajput u16 bitmap; /* Available IRQs */ 6682487711SJaswinder Singh Rajput } __attribute__((packed)) irq[4]; 6782487711SJaswinder Singh Rajput u8 slot; /* Slot number, 0=onboard */ 6882487711SJaswinder Singh Rajput u8 rfu; 6982487711SJaswinder Singh Rajput } __attribute__((packed)); 7082487711SJaswinder Singh Rajput 7182487711SJaswinder Singh Rajput struct irq_routing_table { 7282487711SJaswinder Singh Rajput u32 signature; /* PIRQ_SIGNATURE should be here */ 7382487711SJaswinder Singh Rajput u16 version; /* PIRQ_VERSION */ 7482487711SJaswinder Singh Rajput u16 size; /* Table size in bytes */ 7582487711SJaswinder Singh Rajput u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */ 7682487711SJaswinder Singh Rajput u16 exclusive_irqs; /* IRQs devoted exclusively to 7782487711SJaswinder Singh Rajput PCI usage */ 7882487711SJaswinder Singh Rajput u16 rtr_vendor, rtr_device; /* Vendor and device ID of 7982487711SJaswinder Singh Rajput interrupt router */ 8082487711SJaswinder Singh Rajput u32 miniport_data; /* Crap */ 8182487711SJaswinder Singh Rajput u8 rfu[11]; 8282487711SJaswinder Singh Rajput u8 checksum; /* Modulo 256 checksum must give 0 */ 8382487711SJaswinder Singh Rajput struct irq_info slots[0]; 8482487711SJaswinder Singh Rajput } __attribute__((packed)); 8582487711SJaswinder Singh Rajput 8682487711SJaswinder Singh Rajput extern unsigned int pcibios_irq_mask; 8782487711SJaswinder Singh Rajput 88d19f61f0SThomas Gleixner extern raw_spinlock_t pci_config_lock; 8982487711SJaswinder Singh Rajput 9082487711SJaswinder Singh Rajput extern int (*pcibios_enable_irq)(struct pci_dev *dev); 9182487711SJaswinder Singh Rajput extern void (*pcibios_disable_irq)(struct pci_dev *dev); 9282487711SJaswinder Singh Rajput 9382487711SJaswinder Singh Rajput struct pci_raw_ops { 9482487711SJaswinder Singh Rajput int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn, 9582487711SJaswinder Singh Rajput int reg, int len, u32 *val); 9682487711SJaswinder Singh Rajput int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn, 9782487711SJaswinder Singh Rajput int reg, int len, u32 val); 9882487711SJaswinder Singh Rajput }; 9982487711SJaswinder Singh Rajput 10072da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ops; 10172da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ext_ops; 10282487711SJaswinder Singh Rajput 10372da0b07SJan Beulich extern const struct pci_raw_ops pci_direct_conf1; 10482487711SJaswinder Singh Rajput extern bool port_cf9_safe; 10582487711SJaswinder Singh Rajput 10682487711SJaswinder Singh Rajput /* arch_initcall level */ 10782487711SJaswinder Singh Rajput extern int pci_direct_probe(void); 10882487711SJaswinder Singh Rajput extern void pci_direct_init(int type); 10982487711SJaswinder Singh Rajput extern void pci_pcbios_init(void); 11082487711SJaswinder Singh Rajput extern void __init dmi_check_pciprobe(void); 11182487711SJaswinder Singh Rajput extern void __init dmi_check_skip_isa_align(void); 11282487711SJaswinder Singh Rajput 11382487711SJaswinder Singh Rajput /* some common used subsys_initcalls */ 11482487711SJaswinder Singh Rajput extern int __init pci_acpi_init(void); 115ab3b3793SThomas Gleixner extern void __init pcibios_irq_init(void); 11682487711SJaswinder Singh Rajput extern int __init pcibios_init(void); 117b72d0db9SThomas Gleixner extern int pci_legacy_init(void); 1189325a28cSThomas Gleixner extern void pcibios_fixup_irqs(void); 11982487711SJaswinder Singh Rajput 12082487711SJaswinder Singh Rajput /* pci-mmconfig.c */ 12182487711SJaswinder Singh Rajput 12256ddf4d3SBjorn Helgaas /* "PCI MMCONFIG %04x [bus %02x-%02x]" */ 12356ddf4d3SBjorn Helgaas #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2) 12456ddf4d3SBjorn Helgaas 125d215a9c8SBjorn Helgaas struct pci_mmcfg_region { 126ff097dddSBjorn Helgaas struct list_head list; 12756ddf4d3SBjorn Helgaas struct resource res; 128d215a9c8SBjorn Helgaas u64 address; 1293f0f5503SBjorn Helgaas char __iomem *virt; 130d7e6b66fSBjorn Helgaas u16 segment; 131d7e6b66fSBjorn Helgaas u8 start_bus; 132d7e6b66fSBjorn Helgaas u8 end_bus; 13356ddf4d3SBjorn Helgaas char name[PCI_MMCFG_RESOURCE_NAME_LEN]; 134d215a9c8SBjorn Helgaas }; 135d215a9c8SBjorn Helgaas 13682487711SJaswinder Singh Rajput extern int __init pci_mmcfg_arch_init(void); 13782487711SJaswinder Singh Rajput extern void __init pci_mmcfg_arch_free(void); 1389cf0105dSJiang Liu extern int __devinit pci_mmcfg_arch_map(struct pci_mmcfg_region *cfg); 1399cf0105dSJiang Liu extern void pci_mmcfg_arch_unmap(struct pci_mmcfg_region *cfg); 140*9c95111bSJiang Liu extern int __devinit pci_mmconfig_insert(struct device *dev, 141*9c95111bSJiang Liu u16 seg, u8 start, 142*9c95111bSJiang Liu u8 end, phys_addr_t addr); 143*9c95111bSJiang Liu extern int pci_mmconfig_delete(u16 seg, u8 start, u8 end); 144f6e1d8ccSBjorn Helgaas extern struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus); 14582487711SJaswinder Singh Rajput 146ff097dddSBjorn Helgaas extern struct list_head pci_mmcfg_list; 147c4bf2f37SLen Brown 148df5eb1d6SBjorn Helgaas #define PCI_MMCFG_BUS_OFFSET(bus) ((bus) << 20) 149df5eb1d6SBjorn Helgaas 15082487711SJaswinder Singh Rajput /* 15182487711SJaswinder Singh Rajput * AMD Fam10h CPUs are buggy, and cannot access MMIO config space 15282487711SJaswinder Singh Rajput * on their northbrige except through the * %eax register. As such, you MUST 15382487711SJaswinder Singh Rajput * NOT use normal IOMEM accesses, you need to only use the magic mmio-config 15482487711SJaswinder Singh Rajput * accessor functions. 15582487711SJaswinder Singh Rajput * In fact just use pci_config_*, nothing else please. 15682487711SJaswinder Singh Rajput */ 15782487711SJaswinder Singh Rajput static inline unsigned char mmio_config_readb(void __iomem *pos) 15882487711SJaswinder Singh Rajput { 15982487711SJaswinder Singh Rajput u8 val; 16082487711SJaswinder Singh Rajput asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos)); 16182487711SJaswinder Singh Rajput return val; 16282487711SJaswinder Singh Rajput } 16382487711SJaswinder Singh Rajput 16482487711SJaswinder Singh Rajput static inline unsigned short mmio_config_readw(void __iomem *pos) 16582487711SJaswinder Singh Rajput { 16682487711SJaswinder Singh Rajput u16 val; 16782487711SJaswinder Singh Rajput asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos)); 16882487711SJaswinder Singh Rajput return val; 16982487711SJaswinder Singh Rajput } 17082487711SJaswinder Singh Rajput 17182487711SJaswinder Singh Rajput static inline unsigned int mmio_config_readl(void __iomem *pos) 17282487711SJaswinder Singh Rajput { 17382487711SJaswinder Singh Rajput u32 val; 17482487711SJaswinder Singh Rajput asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos)); 17582487711SJaswinder Singh Rajput return val; 17682487711SJaswinder Singh Rajput } 17782487711SJaswinder Singh Rajput 17882487711SJaswinder Singh Rajput static inline void mmio_config_writeb(void __iomem *pos, u8 val) 17982487711SJaswinder Singh Rajput { 18082487711SJaswinder Singh Rajput asm volatile("movb %%al,(%1)" : : "a" (val), "r" (pos) : "memory"); 18182487711SJaswinder Singh Rajput } 18282487711SJaswinder Singh Rajput 18382487711SJaswinder Singh Rajput static inline void mmio_config_writew(void __iomem *pos, u16 val) 18482487711SJaswinder Singh Rajput { 18582487711SJaswinder Singh Rajput asm volatile("movw %%ax,(%1)" : : "a" (val), "r" (pos) : "memory"); 18682487711SJaswinder Singh Rajput } 18782487711SJaswinder Singh Rajput 18882487711SJaswinder Singh Rajput static inline void mmio_config_writel(void __iomem *pos, u32 val) 18982487711SJaswinder Singh Rajput { 19082487711SJaswinder Singh Rajput asm volatile("movl %%eax,(%1)" : : "a" (val), "r" (pos) : "memory"); 19182487711SJaswinder Singh Rajput } 192b72d0db9SThomas Gleixner 193b72d0db9SThomas Gleixner #ifdef CONFIG_PCI 194b72d0db9SThomas Gleixner # ifdef CONFIG_ACPI 195b72d0db9SThomas Gleixner # define x86_default_pci_init pci_acpi_init 196b72d0db9SThomas Gleixner # else 197b72d0db9SThomas Gleixner # define x86_default_pci_init pci_legacy_init 198b72d0db9SThomas Gleixner # endif 199ab3b3793SThomas Gleixner # define x86_default_pci_init_irq pcibios_irq_init 2009325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs pcibios_fixup_irqs 201b72d0db9SThomas Gleixner #else 202b72d0db9SThomas Gleixner # define x86_default_pci_init NULL 203ab3b3793SThomas Gleixner # define x86_default_pci_init_irq NULL 2049325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs NULL 205b72d0db9SThomas Gleixner #endif 206