1 #include <linux/types.h>
3 #include <linux/kernel.h>
5 #include <asm/mips-boards/bonito64.h>
9 #define PCI_ACCESS_READ 0
10 #define PCI_ACCESS_WRITE 1
12 #define HT1LO_PCICFG_BASE 0x1a000000
13 #define HT1LO_PCICFG_BASE_TP1 0x1b000000
15 static int loongson3_pci_config_access(unsigned char access_type
,
16 struct pci_bus
*bus
, unsigned int devfn
,
19 unsigned char busnum
= bus
->number
;
22 int device
= PCI_SLOT(devfn
);
23 int function
= PCI_FUNC(devfn
);
26 addr
= (busnum
<< 16) | (device
<< 11) | (function
<< 8) | reg
;
29 return PCIBIOS_DEVICE_NOT_FOUND
;
30 addrp
= (void *)(TO_UNCAC(HT1LO_PCICFG_BASE
) | (addr
& 0xffff));
34 addrp
= (void *)(TO_UNCAC(HT1LO_PCICFG_BASE_TP1
) | (addr
));
38 if (access_type
== PCI_ACCESS_WRITE
)
42 if (*data
== 0xffffffff) {
44 return PCIBIOS_DEVICE_NOT_FOUND
;
47 return PCIBIOS_SUCCESSFUL
;
50 static int loongson3_pci_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
51 int where
, int size
, u32
*val
)
54 int ret
= loongson3_pci_config_access(PCI_ACCESS_READ
,
55 bus
, devfn
, where
, &data
);
57 if (ret
!= PCIBIOS_SUCCESSFUL
)
61 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
63 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
67 return PCIBIOS_SUCCESSFUL
;
70 static int loongson3_pci_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
71 int where
, int size
, u32 val
)
79 ret
= loongson3_pci_config_access(PCI_ACCESS_READ
,
80 bus
, devfn
, where
, &data
);
81 if (ret
!= PCIBIOS_SUCCESSFUL
)
85 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
86 (val
<< ((where
& 3) << 3));
88 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
89 (val
<< ((where
& 3) << 3));
92 ret
= loongson3_pci_config_access(PCI_ACCESS_WRITE
,
93 bus
, devfn
, where
, &data
);
98 struct pci_ops loongson_pci_ops
= {
99 .read
= loongson3_pci_pcibios_read
,
100 .write
= loongson3_pci_pcibios_write