1*fb9aa6f1SThomas Gleixner #include <linux/kernel.h> 2*fb9aa6f1SThomas Gleixner #include <linux/pci.h> 3*fb9aa6f1SThomas Gleixner #include <asm/pci-direct.h> 4*fb9aa6f1SThomas Gleixner #include <asm/io.h> 5*fb9aa6f1SThomas Gleixner #include "pci.h" 6*fb9aa6f1SThomas Gleixner 7*fb9aa6f1SThomas Gleixner /* Direct PCI access. This is used for PCI accesses in early boot before 8*fb9aa6f1SThomas Gleixner the PCI subsystem works. */ 9*fb9aa6f1SThomas Gleixner 10*fb9aa6f1SThomas Gleixner #define PDprintk(x...) 11*fb9aa6f1SThomas Gleixner 12*fb9aa6f1SThomas Gleixner u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset) 13*fb9aa6f1SThomas Gleixner { 14*fb9aa6f1SThomas Gleixner u32 v; 15*fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 16*fb9aa6f1SThomas Gleixner v = inl(0xcfc); 17*fb9aa6f1SThomas Gleixner if (v != 0xffffffff) 18*fb9aa6f1SThomas Gleixner PDprintk("%x reading 4 from %x: %x\n", slot, offset, v); 19*fb9aa6f1SThomas Gleixner return v; 20*fb9aa6f1SThomas Gleixner } 21*fb9aa6f1SThomas Gleixner 22*fb9aa6f1SThomas Gleixner u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset) 23*fb9aa6f1SThomas Gleixner { 24*fb9aa6f1SThomas Gleixner u8 v; 25*fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 26*fb9aa6f1SThomas Gleixner v = inb(0xcfc + (offset&3)); 27*fb9aa6f1SThomas Gleixner PDprintk("%x reading 1 from %x: %x\n", slot, offset, v); 28*fb9aa6f1SThomas Gleixner return v; 29*fb9aa6f1SThomas Gleixner } 30*fb9aa6f1SThomas Gleixner 31*fb9aa6f1SThomas Gleixner u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset) 32*fb9aa6f1SThomas Gleixner { 33*fb9aa6f1SThomas Gleixner u16 v; 34*fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 35*fb9aa6f1SThomas Gleixner v = inw(0xcfc + (offset&2)); 36*fb9aa6f1SThomas Gleixner PDprintk("%x reading 2 from %x: %x\n", slot, offset, v); 37*fb9aa6f1SThomas Gleixner return v; 38*fb9aa6f1SThomas Gleixner } 39*fb9aa6f1SThomas Gleixner 40*fb9aa6f1SThomas Gleixner void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, 41*fb9aa6f1SThomas Gleixner u32 val) 42*fb9aa6f1SThomas Gleixner { 43*fb9aa6f1SThomas Gleixner PDprintk("%x writing to %x: %x\n", slot, offset, val); 44*fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 45*fb9aa6f1SThomas Gleixner outl(val, 0xcfc); 46*fb9aa6f1SThomas Gleixner } 47*fb9aa6f1SThomas Gleixner 48*fb9aa6f1SThomas Gleixner void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val) 49*fb9aa6f1SThomas Gleixner { 50*fb9aa6f1SThomas Gleixner PDprintk("%x writing to %x: %x\n", slot, offset, val); 51*fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 52*fb9aa6f1SThomas Gleixner outb(val, 0xcfc); 53*fb9aa6f1SThomas Gleixner } 54*fb9aa6f1SThomas Gleixner 55*fb9aa6f1SThomas Gleixner int early_pci_allowed(void) 56*fb9aa6f1SThomas Gleixner { 57*fb9aa6f1SThomas Gleixner return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) == 58*fb9aa6f1SThomas Gleixner PCI_PROBE_CONF1; 59*fb9aa6f1SThomas Gleixner } 60