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