1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
4 #include <asm/bootinfo.h>
6 #include <asm/lasat/lasat.h>
9 #define PCI_ACCESS_READ 0
10 #define PCI_ACCESS_WRITE 1
12 #define LO(reg) (reg / 4)
13 #define HI(reg) (reg / 4 + 1)
15 volatile unsigned long *const vrc_pciregs
= (void *) Vrc5074_BASE
;
17 static int nile4_pcibios_config_access(unsigned char access_type
,
18 struct pci_bus
*bus
, unsigned int devfn
, int where
, u32
*val
)
20 unsigned char busnum
= bus
->number
;
23 if ((busnum
== 0) && (PCI_SLOT(devfn
) > 8))
24 /* The addressing scheme chosen leaves room for just
25 * 8 devices on the first busnum (besides the PCI
26 * controller itself) */
27 return PCIBIOS_DEVICE_NOT_FOUND
;
29 if ((busnum
== 0) && (devfn
== PCI_DEVFN(0, 0))) {
30 /* Access controller registers directly */
31 if (access_type
== PCI_ACCESS_WRITE
) {
32 vrc_pciregs
[(0x200 + where
) >> 2] = *val
;
34 *val
= vrc_pciregs
[(0x200 + where
) >> 2];
36 return PCIBIOS_SUCCESSFUL
;
39 /* Temporarily map PCI Window 1 to config space */
40 mask
= vrc_pciregs
[LO(NILE4_PCIINIT1
)];
41 vrc_pciregs
[LO(NILE4_PCIINIT1
)] = 0x0000001a | (busnum
? 0x200 : 0);
43 /* Clear PCI Error register. This also clears the Error Type
44 * bits in the Control register */
45 vrc_pciregs
[LO(NILE4_PCIERR
)] = 0;
46 vrc_pciregs
[HI(NILE4_PCIERR
)] = 0;
51 KSEG1ADDR(PCI_WINDOW1
) +
52 ((1 << (PCI_SLOT(devfn
) + 15)) | (PCI_FUNC(devfn
) << 8)
55 adr
= KSEG1ADDR(PCI_WINDOW1
) | (busnum
<< 16) | (devfn
<< 8) |
58 if (access_type
== PCI_ACCESS_WRITE
)
63 /* Check for master or target abort */
64 err
= (vrc_pciregs
[HI(NILE4_PCICTRL
)] >> 5) & 0x7;
66 /* Restore PCI Window 1 */
67 vrc_pciregs
[LO(NILE4_PCIINIT1
)] = mask
;
70 return PCIBIOS_DEVICE_NOT_FOUND
;
72 return PCIBIOS_SUCCESSFUL
;
75 static int nile4_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
76 int where
, int size
, u32
*val
)
81 if ((size
== 2) && (where
& 1))
82 return PCIBIOS_BAD_REGISTER_NUMBER
;
83 else if ((size
== 4) && (where
& 3))
84 return PCIBIOS_BAD_REGISTER_NUMBER
;
86 err
= nile4_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
92 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
94 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
98 return PCIBIOS_SUCCESSFUL
;
101 static int nile4_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
102 int where
, int size
, u32 val
)
107 if ((size
== 2) && (where
& 1))
108 return PCIBIOS_BAD_REGISTER_NUMBER
;
109 else if ((size
== 4) && (where
& 3))
110 return PCIBIOS_BAD_REGISTER_NUMBER
;
112 err
= nile4_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
118 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
119 (val
<< ((where
& 3) << 3));
121 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
122 (val
<< ((where
& 3) << 3));
126 if (nile4_pcibios_config_access
127 (PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
130 return PCIBIOS_SUCCESSFUL
;
133 struct pci_ops nile4_pci_ops
= {
134 .read
= nile4_pcibios_read
,
135 .write
= nile4_pcibios_write
,