2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * SNI specific PCI support for RM200/RM300.
8 * Copyright (C) 1997 - 2000, 2003 Ralf Baechle <ralf@linux-mips.org>
10 #include <linux/kernel.h>
11 #include <linux/pci.h>
12 #include <linux/types.h>
16 * It seems that on the RM200 only lower 3 bits of the 5 bit PCI device
17 * address are decoded. We therefore manually have to reject attempts at
18 * reading outside this range. Being on the paranoid side we only do this
19 * test for bus 0 and hope forwarding and decoding work properly for any
20 * subordinated busses.
22 * ASIC PCI only supports type 1 config cycles.
24 static int set_config_address(unsigned int busno, unsigned int devfn, int reg)
26 if ((devfn > 255) || (reg > 255))
27 return PCIBIOS_BAD_REGISTER_NUMBER;
29 if (busno == 0 && devfn >= PCI_DEVFN(8, 0))
30 return PCIBIOS_DEVICE_NOT_FOUND;
32 *(volatile u32 *)PCIMT_CONFIG_ADDRESS =
33 ((busno & 0xff) << 16) |
34 ((devfn & 0xff) << 8) |
37 return PCIBIOS_SUCCESSFUL;
40 static int pcimt_read(struct pci_bus *bus, unsigned int devfn, int reg,
45 if ((res = set_config_address(bus->number, devfn, reg)))
50 *val = inb(PCIMT_CONFIG_DATA + (reg & 3));
53 *val = inw(PCIMT_CONFIG_DATA + (reg & 2));
56 *val = inl(PCIMT_CONFIG_DATA);
63 static int pcimt_write(struct pci_bus *bus, unsigned int devfn, int reg,
68 if ((res = set_config_address(bus->number, devfn, reg)))
73 outb (val, PCIMT_CONFIG_DATA + (reg & 3));
76 outw (val, PCIMT_CONFIG_DATA + (reg & 2));
79 outl (val, PCIMT_CONFIG_DATA);
86 struct pci_ops sni_pcimt_ops = {
91 static int pcit_set_config_address(unsigned int busno, unsigned int devfn, int reg)
93 if ((devfn > 255) || (reg > 255) || (busno > 255))
94 return PCIBIOS_BAD_REGISTER_NUMBER;
96 outl ((1 << 31) | ((busno & 0xff) << 16) | ((devfn & 0xff) << 8) | (reg & 0xfc), 0xcf8);
97 return PCIBIOS_SUCCESSFUL;
100 static int pcit_read(struct pci_bus *bus, unsigned int devfn, int reg,
106 * on bus 0 we need to check, whether there is a device answering
107 * for the devfn by doing a config write and checking the result. If
108 * we don't do it, we will get a data bus error
110 if (bus->number == 0) {
111 pcit_set_config_address (0, 0, 0x68);
112 outl (inl (0xcfc) | 0xc0000000, 0xcfc);
113 if ((res = pcit_set_config_address(0, devfn, 0)))
115 outl (0xffffffff, 0xcfc);
116 pcit_set_config_address (0, 0, 0x68);
117 if (inl(0xcfc) & 0x100000)
118 return PCIBIOS_DEVICE_NOT_FOUND;
120 if ((res = pcit_set_config_address(bus->number, devfn, reg)))
125 *val = inb(PCIMT_CONFIG_DATA + (reg & 3));
128 *val = inw(PCIMT_CONFIG_DATA + (reg & 2));
131 *val = inl(PCIMT_CONFIG_DATA);
137 static int pcit_write(struct pci_bus *bus, unsigned int devfn, int reg,
142 if ((res = pcit_set_config_address(bus->number, devfn, reg)))
147 outb (val, PCIMT_CONFIG_DATA + (reg & 3));
150 outw (val, PCIMT_CONFIG_DATA + (reg & 2));
153 outl (val, PCIMT_CONFIG_DATA);
161 struct pci_ops sni_pcit_ops = {