1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <asm/bootinfo.h>
6 #include <asm/lasat/lasat.h>
7 #include <asm/gt64120.h>
10 #define PCI_ACCESS_READ 0
11 #define PCI_ACCESS_WRITE 1
15 #define Dprintk(fmt...) printk(fmt)
17 #define Dprintk(fmt...)
20 static int (*lasat_pcibios_config_access
) (unsigned char access_type
,
22 unsigned int devfn
, int where
,
26 * Because of an error/peculiarity in the Galileo chip, we need to swap the
27 * bytes when running bigendian.
29 #define GT_WRITE(ofs, data) \
30 *(volatile u32 *)(LASAT_GT_BASE+ofs) = cpu_to_le32(data)
31 #define GT_READ(ofs, data) \
32 data = le32_to_cpu(*(volatile u32 *)(LASAT_GT_BASE+ofs))
35 static int lasat_pcibios_config_access_100(unsigned char access_type
,
37 unsigned int devfn
, int where
,
40 unsigned char busnum
= bus
->number
;
43 if ((busnum
== 0) && (devfn
>= PCI_DEVFN(31, 0)))
44 return -1; /* Because of a bug in the Galileo (for slot 31). */
46 /* Clear cause register bits */
47 GT_WRITE(GT_INTRCAUSE_OFS
, ~(GT_INTRCAUSE_MASABORT0_BIT
|
48 GT_INTRCAUSE_TARABORT0_BIT
));
51 GT_WRITE(GT_PCI0_CFGADDR_OFS
,
52 (busnum
<< GT_PCI0_CFGADDR_BUSNUM_SHF
) |
53 (devfn
<< GT_PCI0_CFGADDR_FUNCTNUM_SHF
) |
54 ((where
/ 4) << GT_PCI0_CFGADDR_REGNUM_SHF
) |
55 GT_PCI0_CFGADDR_CONFIGEN_BIT
);
57 if (access_type
== PCI_ACCESS_WRITE
) {
58 GT_WRITE(GT_PCI0_CFGDATA_OFS
, *val
);
60 GT_READ(GT_PCI0_CFGDATA_OFS
, *val
);
63 /* Check for master or target abort */
64 GT_READ(GT_INTRCAUSE_OFS
, intr
);
67 (GT_INTRCAUSE_MASABORT0_BIT
| GT_INTRCAUSE_TARABORT0_BIT
)) {
71 GT_WRITE(GT_INTRCAUSE_OFS
, ~(GT_INTRCAUSE_MASABORT0_BIT
|
72 GT_INTRCAUSE_TARABORT0_BIT
));
80 #define LO(reg) (reg / 4)
81 #define HI(reg) (reg / 4 + 1)
83 volatile unsigned long *const vrc_pciregs
= (void *) Vrc5074_BASE
;
85 static int lasat_pcibios_config_access_200(unsigned char access_type
,
87 unsigned int devfn
, int where
,
90 unsigned char busnum
= bus
->number
;
93 if ((busnum
== 0) && (PCI_SLOT(devfn
) > 8))
94 /* The addressing scheme chosen leaves room for just
95 * 8 devices on the first busnum (besides the PCI
96 * controller itself) */
99 if ((busnum
== 0) && (devfn
== PCI_DEVFN(0, 0))) {
100 /* Access controller registers directly */
101 if (access_type
== PCI_ACCESS_WRITE
) {
102 vrc_pciregs
[(0x200 + where
) >> 2] = *val
;
104 *val
= vrc_pciregs
[(0x200 + where
) >> 2];
109 /* Temporarily map PCI Window 1 to config space */
110 mask
= vrc_pciregs
[LO(NILE4_PCIINIT1
)];
111 vrc_pciregs
[LO(NILE4_PCIINIT1
)] =
112 0x0000001a | (busnum
? 0x200 : 0);
114 /* Clear PCI Error register. This also clears the Error Type
115 * bits in the Control register */
116 vrc_pciregs
[LO(NILE4_PCIERR
)] = 0;
117 vrc_pciregs
[HI(NILE4_PCIERR
)] = 0;
122 KSEG1ADDR(PCI_WINDOW1
) +
123 ((1 << (PCI_SLOT(devfn
) + 15)) | (PCI_FUNC(devfn
) << 8)
127 KSEG1ADDR(PCI_WINDOW1
) | (busnum
<< 16) | (devfn
<< 8)
131 printk("PCI config %s: adr %x",
132 access_type
== PCI_ACCESS_WRITE
? "write" : "read", adr
);
135 if (access_type
== PCI_ACCESS_WRITE
) {
142 printk(" value = %x\n", *val
);
145 /* Check for master or target abort */
146 err
= (vrc_pciregs
[HI(NILE4_PCICTRL
)] >> 5) & 0x7;
148 /* Restore PCI Window 1 */
149 vrc_pciregs
[LO(NILE4_PCIINIT1
)] = mask
;
154 printk("\terror %x at adr %x\n", err
,
155 vrc_pciregs
[LO(PCIERR
)]);
163 static int lasat_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
164 int where
, int size
, u32
* val
)
168 if ((size
== 2) && (where
& 1))
169 return PCIBIOS_BAD_REGISTER_NUMBER
;
170 else if ((size
== 4) && (where
& 3))
171 return PCIBIOS_BAD_REGISTER_NUMBER
;
173 if (lasat_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
178 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
180 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
184 return PCIBIOS_SUCCESSFUL
;
187 static int lasat_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
188 int where
, int size
, u32 val
)
192 if ((size
== 2) && (where
& 1))
193 return PCIBIOS_BAD_REGISTER_NUMBER
;
194 else if ((size
== 4) && (where
& 3))
195 return PCIBIOS_BAD_REGISTER_NUMBER
;
197 if (lasat_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
202 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
203 (val
<< ((where
& 3) << 3));
205 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
206 (val
<< ((where
& 3) << 3));
208 if (lasat_pcibios_config_access
209 (PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
212 return PCIBIOS_SUCCESSFUL
;
215 struct pci_ops lasat_pci_ops
= {
216 .read
= lasat_pcibios_read
,
217 .write
= lasat_pcibios_write
,
220 char *__init
pcibios_setup(char *str
)
225 static int __init
pcibios_init(void)
227 switch (mips_machtype
) {
229 lasat_pcibios_config_access
=
230 &lasat_pcibios_config_access_100
;
233 lasat_pcibios_config_access
=
234 &lasat_pcibios_config_access_200
;
237 panic("pcibios_init: mips_machtype incorrect");
240 Dprintk("pcibios_init()\n");
241 pci_scan_bus(0, &lasat_pci_ops
, NULL
);
245 subsys_initcall(pcibios_init
);
247 void __init
pcibios_fixup_bus(struct pci_bus
*b
)
249 Dprintk("pcibios_fixup_bus()\n");
252 int __init
pcibios_enable_device(struct pci_dev
*dev
, int mask
)
254 /* Not needed, since we enable all devices at startup. */
258 void __init
pcibios_align_resource(void *data
, struct resource
*res
,
259 unsigned long size
, unsigned long align
)
263 unsigned __init
int pcibios_assign_all_busses(void)
268 struct pci_fixup pcibios_fixups
[] = {