14 #include <linux/types.h>
15 #include <linux/pci.h>
16 #include <linux/kernel.h>
18 #include <linux/export.h>
27 #define PCI_ACCESS_READ 0
28 #define PCI_ACCESS_WRITE 1
30 #define CFG_SPACE_REG(offset) \
31 (void *)CKSEG1ADDR(LOONGSON_PCICFG_BASE | (offset))
32 #define ID_SEL_BEGIN 11
33 #define MAX_DEV_NUM (31 - ID_SEL_BEGIN)
36 static int loongson_pcibios_config_access(
unsigned char access_type,
38 unsigned int devfn,
int where,
62 switch (access_type) {
77 addr = (1 << (device +
ID_SEL_BEGIN)) | (
function << 8) | reg;
81 addr = (busnum << 16) | (device << 11) | (
function << 8) | reg;
87 LOONGSON_PCICMD_MTABORT_CLR;
122 static int loongson_pcibios_read(
struct pci_bus *
bus,
unsigned int devfn,
127 if ((size == 2) && (where & 1))
129 else if ((size == 4) && (where & 3))
137 *val = (data >> ((where & 3) << 3)) & 0xff;
139 *val = (data >> ((where & 3) << 3)) & 0xffff;
146 static int loongson_pcibios_write(
struct pci_bus *bus,
unsigned int devfn,
147 int where,
int size,
u32 val)
151 if ((size == 2) && (where & 1))
153 else if ((size == 4) && (where & 3))
164 data = (data & ~(0xff << ((where & 3) << 3))) |
165 (val << ((where & 3) << 3));
167 data = (data & ~(0xffff << ((where & 3) << 3))) |
168 (val << ((where & 3) << 3));
179 .read = loongson_pcibios_read,
180 .write = loongson_pcibios_write
195 loongson_pcibios_write(&bus, devfn,
PCI_MSR_ADDR, 4, msr);
211 loongson_pcibios_write(&bus, devfn,
PCI_MSR_ADDR, 4, msr);