1 #include <linux/kernel.h>
2 #include <linux/init.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 DEFINE_SPINLOCK(nile4_pci_lock
);
19 static int nile4_pcibios_config_access(unsigned char access_type
,
20 struct pci_bus
*bus
, unsigned int devfn
, int where
, u32
*val
)
22 unsigned char busnum
= bus
->number
;
25 if ((busnum
== 0) && (PCI_SLOT(devfn
) > 8))
26 /* The addressing scheme chosen leaves room for just
27 * 8 devices on the first busnum (besides the PCI
28 * controller itself) */
29 return PCIBIOS_DEVICE_NOT_FOUND
;
31 if ((busnum
== 0) && (devfn
== PCI_DEVFN(0, 0))) {
32 /* Access controller registers directly */
33 if (access_type
== PCI_ACCESS_WRITE
) {
34 vrc_pciregs
[(0x200 + where
) >> 2] = *val
;
36 *val
= vrc_pciregs
[(0x200 + where
) >> 2];
38 return PCIBIOS_SUCCESSFUL
;
41 /* Temporarily map PCI Window 1 to config space */
42 mask
= vrc_pciregs
[LO(NILE4_PCIINIT1
)];
43 vrc_pciregs
[LO(NILE4_PCIINIT1
)] = 0x0000001a | (busnum
? 0x200 : 0);
45 /* Clear PCI Error register. This also clears the Error Type
46 * bits in the Control register */
47 vrc_pciregs
[LO(NILE4_PCIERR
)] = 0;
48 vrc_pciregs
[HI(NILE4_PCIERR
)] = 0;
53 KSEG1ADDR(PCI_WINDOW1
) +
54 ((1 << (PCI_SLOT(devfn
) + 15)) | (PCI_FUNC(devfn
) << 8)
57 adr
= KSEG1ADDR(PCI_WINDOW1
) | (busnum
<< 16) | (devfn
<< 8) |
60 if (access_type
== PCI_ACCESS_WRITE
)
65 /* Check for master or target abort */
66 err
= (vrc_pciregs
[HI(NILE4_PCICTRL
)] >> 5) & 0x7;
68 /* Restore PCI Window 1 */
69 vrc_pciregs
[LO(NILE4_PCIINIT1
)] = mask
;
72 return PCIBIOS_DEVICE_NOT_FOUND
;
74 return PCIBIOS_SUCCESSFUL
;
77 static int nile4_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
78 int where
, int size
, u32
*val
)
84 if ((size
== 2) && (where
& 1))
85 return PCIBIOS_BAD_REGISTER_NUMBER
;
86 else if ((size
== 4) && (where
& 3))
87 return PCIBIOS_BAD_REGISTER_NUMBER
;
89 spin_lock_irqsave(&nile4_pci_lock
, flags
);
90 err
= nile4_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
92 spin_unlock_irqrestore(&nile4_pci_lock
, flags
);
98 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
100 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
104 return PCIBIOS_SUCCESSFUL
;
107 static int nile4_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
108 int where
, int size
, u32 val
)
114 if ((size
== 2) && (where
& 1))
115 return PCIBIOS_BAD_REGISTER_NUMBER
;
116 else if ((size
== 4) && (where
& 3))
117 return PCIBIOS_BAD_REGISTER_NUMBER
;
119 spin_lock_irqsave(&nile4_pci_lock
, flags
);
120 err
= nile4_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
122 spin_unlock_irqrestore(&nile4_pci_lock
, flags
);
128 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
129 (val
<< ((where
& 3) << 3));
131 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
132 (val
<< ((where
& 3) << 3));
136 if (nile4_pcibios_config_access
137 (PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
140 return PCIBIOS_SUCCESSFUL
;
143 struct pci_ops nile4_pci_ops
= {
144 .read
= nile4_pcibios_read
,
145 .write
= nile4_pcibios_write
,