1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
4 #include <linux/kernel.h>
6 #include <asm/mips-boards/bonito64.h>
10 #define PCI_ACCESS_READ 0
11 #define PCI_ACCESS_WRITE 1
13 #define HT1LO_PCICFG_BASE 0x1a000000
14 #define HT1LO_PCICFG_BASE_TP1 0x1b000000
16 static int loongson3_pci_config_access(unsigned char access_type,
17 struct pci_bus *bus, unsigned int devfn,
20 unsigned char busnum = bus->number;
23 int device = PCI_SLOT(devfn);
24 int function = PCI_FUNC(devfn);
27 addr = (busnum << 16) | (device << 11) | (function << 8) | reg;
30 return PCIBIOS_DEVICE_NOT_FOUND;
31 addrp = (void *)(TO_UNCAC(HT1LO_PCICFG_BASE) | (addr & 0xffff));
35 addrp = (void *)(TO_UNCAC(HT1LO_PCICFG_BASE_TP1) | (addr));
39 if (access_type == PCI_ACCESS_WRITE)
43 if (*data == 0xffffffff) {
45 return PCIBIOS_DEVICE_NOT_FOUND;
48 return PCIBIOS_SUCCESSFUL;
51 static int loongson3_pci_pcibios_read(struct pci_bus *bus, unsigned int devfn,
52 int where, int size, u32 *val)
55 int ret = loongson3_pci_config_access(PCI_ACCESS_READ,
56 bus, devfn, where, &data);
58 if (ret != PCIBIOS_SUCCESSFUL)
62 *val = (data >> ((where & 3) << 3)) & 0xff;
64 *val = (data >> ((where & 3) << 3)) & 0xffff;
68 return PCIBIOS_SUCCESSFUL;
71 static int loongson3_pci_pcibios_write(struct pci_bus *bus, unsigned int devfn,
72 int where, int size, u32 val)
80 ret = loongson3_pci_config_access(PCI_ACCESS_READ,
81 bus, devfn, where, &data);
82 if (ret != PCIBIOS_SUCCESSFUL)
86 data = (data & ~(0xff << ((where & 3) << 3))) |
87 (val << ((where & 3) << 3));
89 data = (data & ~(0xffff << ((where & 3) << 3))) |
90 (val << ((where & 3) << 3));
93 ret = loongson3_pci_config_access(PCI_ACCESS_WRITE,
94 bus, devfn, where, &data);
99 struct pci_ops loongson_pci_ops = {
100 .read = loongson3_pci_pcibios_read,
101 .write = loongson3_pci_pcibios_write