2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999, 2000 MIPS Technologies, Inc. All rights reserved.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * MIPS boards specific PCI support.
21 #include <linux/config.h>
22 #include <linux/types.h>
23 #include <linux/pci.h>
24 #include <linux/kernel.h>
25 #include <linux/init.h>
27 #include <asm/mips-boards/generic.h>
28 #include <asm/gt64120.h>
29 #include <asm/mips-boards/bonito64.h>
30 #ifdef CONFIG_MIPS_MALTA
31 #include <asm/mips-boards/malta.h>
33 #include <asm/mips-boards/msc01_pci.h>
35 #define PCI_ACCESS_READ 0
36 #define PCI_ACCESS_WRITE 1
39 * PCI configuration cycle AD bus definition
42 #define PCI_CFG_TYPE0_REG_SHF 0
43 #define PCI_CFG_TYPE0_FUNC_SHF 8
46 #define PCI_CFG_TYPE1_REG_SHF 0
47 #define PCI_CFG_TYPE1_FUNC_SHF 8
48 #define PCI_CFG_TYPE1_DEV_SHF 11
49 #define PCI_CFG_TYPE1_BUS_SHF 16
51 static int mips_pcibios_config_access(unsigned char access_type
,
53 unsigned int devfn
, int where
,
56 unsigned char busnum
= bus
->number
;
61 switch (mips_revision_corid
) {
62 case MIPS_REVISION_CORID_QED_RM5261
:
63 case MIPS_REVISION_CORID_CORE_LV
:
64 case MIPS_REVISION_CORID_CORE_FPGA
:
65 /* Galileo GT64120 system controller. */
67 if ((busnum
== 0) && (devfn
>= PCI_DEVFN(31, 0)))
68 return -1; /* Because of a bug in the galileo (for slot 31). */
70 /* Clear cause register bits */
71 GT_READ(GT_INTRCAUSE_OFS
, intr
);
72 GT_WRITE(GT_INTRCAUSE_OFS
, intr
&
73 ~(GT_INTRCAUSE_MASABORT0_BIT
|
74 GT_INTRCAUSE_TARABORT0_BIT
));
77 GT_WRITE(GT_PCI0_CFGADDR_OFS
,
78 (busnum
<< GT_PCI0_CFGADDR_BUSNUM_SHF
) |
79 (devfn
<< GT_PCI0_CFGADDR_FUNCTNUM_SHF
) |
80 ((where
/ 4) << GT_PCI0_CFGADDR_REGNUM_SHF
) |
81 GT_PCI0_CFGADDR_CONFIGEN_BIT
);
83 if (access_type
== PCI_ACCESS_WRITE
) {
84 if (busnum
== 0 && devfn
== 0) {
86 * The Galileo system controller is acting
87 * differently than other devices.
89 GT_WRITE(GT_PCI0_CFGDATA_OFS
, *data
);
91 GT_PCI_WRITE(GT_PCI0_CFGDATA_OFS
, *data
);
94 if (busnum
== 0 && devfn
== 0) {
96 * The Galileo system controller is acting
97 * differently than other devices.
99 GT_READ(GT_PCI0_CFGDATA_OFS
, *data
);
101 GT_PCI_READ(GT_PCI0_CFGDATA_OFS
, *data
);
105 /* Check for master or target abort */
106 GT_READ(GT_INTRCAUSE_OFS
, intr
);
108 if (intr
& (GT_INTRCAUSE_MASABORT0_BIT
|
109 GT_INTRCAUSE_TARABORT0_BIT
)) {
113 GT_READ(GT_INTRCAUSE_OFS
, intr
);
114 GT_WRITE(GT_INTRCAUSE_OFS
, intr
&
115 ~(GT_INTRCAUSE_MASABORT0_BIT
|
116 GT_INTRCAUSE_TARABORT0_BIT
));
123 case MIPS_REVISION_CORID_BONITO64
:
124 case MIPS_REVISION_CORID_CORE_20K
:
125 /* Algorithmics Bonito64 system controller. */
127 if ((busnum
== 0) && (PCI_SLOT(devfn
) == 0)) {
131 /* Clear cause register bits */
132 BONITO_PCICMD
|= (BONITO_PCICMD_MABORT_CLR
|
133 BONITO_PCICMD_MTABORT_CLR
);
136 * Setup pattern to be used as PCI "address" for
141 pci_addr
= (u64
) 1 << (PCI_SLOT(devfn
) + 10);
144 pci_addr
= busnum
<< PCI_CFG_TYPE1_BUS_SHF
;
148 PCI_SLOT(devfn
) << PCI_CFG_TYPE1_DEV_SHF
;
151 /* Function (same for Type 0/1) */
152 pci_addr
|= PCI_FUNC(devfn
) << PCI_CFG_TYPE0_FUNC_SHF
;
154 /* Register number (same for Type 0/1) */
155 pci_addr
|= (where
& ~0x3) << PCI_CFG_TYPE0_REG_SHF
;
159 BONITO_PCIMAP_CFG
= pci_addr
>> 16;
162 BONITO_PCIMAP_CFG
= (pci_addr
>> 16) | 0x10000;
165 /* Flush Bonito register block */
166 dummy
= BONITO_PCIMAP_CFG
;
170 if (access_type
== PCI_ACCESS_WRITE
) {
171 *(volatile u32
*) (KSEG1ADDR(BONITO_PCICFG_BASE
+
172 (pci_addr
& 0xffff)))
176 while (BONITO_PCIMSTAT
& 0xF);
180 *) (KSEG1ADDR(BONITO_PCICFG_BASE
+
181 (pci_addr
& 0xffff)));
184 /* Detect Master/Target abort */
185 if (BONITO_PCICMD
& (BONITO_PCICMD_MABORT_CLR
|
186 BONITO_PCICMD_MTABORT_CLR
)) {
190 BONITO_PCICMD
|= (BONITO_PCICMD_MABORT_CLR
|
191 BONITO_PCICMD_MTABORT_CLR
);
197 case MIPS_REVISION_CORID_CORE_MSC
:
198 /* MIPS system controller. */
200 if ((busnum
== 0) && (PCI_SLOT(devfn
) == 0)) {
204 /* Clear status register bits. */
205 MSC_WRITE(MSC01_PCI_INTSTAT
,
206 (MSC01_PCI_INTCFG_MA_BIT
|
207 MSC01_PCI_INTCFG_TA_BIT
));
211 type
= 0; /* Type 0 */
213 type
= 1; /* Type 1 */
215 MSC_WRITE(MSC01_PCI_CFGADDR
,
216 ((busnum
<< MSC01_PCI_CFGADDR_BNUM_SHF
) |
217 (PCI_SLOT(devfn
) << MSC01_PCI_CFGADDR_DNUM_SHF
)
218 | (PCI_FUNC(devfn
) <<
219 MSC01_PCI_CFGADDR_FNUM_SHF
) | ((where
/
221 MSC01_PCI_CFGADDR_RNUM_SHF
)
225 if (access_type
== PCI_ACCESS_WRITE
) {
226 MSC_WRITE(MSC01_PCI_CFGDATA
, *data
);
228 MSC_READ(MSC01_PCI_CFGDATA
, *data
);
231 /* Detect Master/Target abort */
232 MSC_READ(MSC01_PCI_INTSTAT
, intr
);
233 if (intr
& (MSC01_PCI_INTCFG_MA_BIT
|
234 MSC01_PCI_INTCFG_TA_BIT
)) {
238 MSC_READ(MSC01_PCI_INTSTAT
, intr
);
239 MSC_WRITE(MSC01_PCI_INTSTAT
,
240 (MSC01_PCI_INTCFG_MA_BIT
|
241 MSC01_PCI_INTCFG_TA_BIT
));
248 ("Unknown Core card, don't know the system controller.\n");
257 * We can't address 8 and 16 bit words directly. Instead we have to
258 * read/write a 32bit word and mask/modify the data we actually want.
260 static int mips_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
261 int where
, int size
, u32
* val
)
265 if ((size
== 2) && (where
& 1))
266 return PCIBIOS_BAD_REGISTER_NUMBER
;
267 else if ((size
== 4) && (where
& 3))
268 return PCIBIOS_BAD_REGISTER_NUMBER
;
270 if (mips_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
275 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
277 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
281 return PCIBIOS_SUCCESSFUL
;
284 static int mips_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
285 int where
, int size
, u32 val
)
289 if ((size
== 2) && (where
& 1))
290 return PCIBIOS_BAD_REGISTER_NUMBER
;
291 else if ((size
== 4) && (where
& 3))
292 return PCIBIOS_BAD_REGISTER_NUMBER
;
294 if (mips_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
299 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
300 (val
<< ((where
& 3) << 3));
302 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
303 (val
<< ((where
& 3) << 3));
305 if (mips_pcibios_config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
,
309 return PCIBIOS_SUCCESSFUL
;
312 struct pci_ops mips_pci_ops
= {
313 .read
= mips_pcibios_read
,
314 .write
= mips_pcibios_write
317 int mips_pcibios_iack(void)
323 * Determine highest priority pending interrupt by performing
324 * a PCI Interrupt Acknowledge cycle.
326 switch (mips_revision_corid
) {
327 case MIPS_REVISION_CORID_QED_RM5261
:
328 case MIPS_REVISION_CORID_CORE_LV
:
329 case MIPS_REVISION_CORID_CORE_FPGA
:
330 case MIPS_REVISION_CORID_CORE_MSC
:
331 if (mips_revision_corid
== MIPS_REVISION_CORID_CORE_MSC
)
332 MSC_READ(MSC01_PCI_IACK
, irq
);
334 GT_READ(GT_PCI0_IACK_OFS
, irq
);
337 case MIPS_REVISION_CORID_BONITO64
:
338 case MIPS_REVISION_CORID_CORE_20K
:
339 /* The following will generate a PCI IACK cycle on the
340 * Bonito controller. It's a little bit kludgy, but it
341 * was the easiest way to implement it in hardware at
344 BONITO_PCIMAP_CFG
= 0x20000;
346 /* Flush Bonito register block */
347 dummy
= BONITO_PCIMAP_CFG
;
350 irq
= *(volatile u32
*) (KSEG1ADDR(BONITO_PCICFG_BASE
));
353 BONITO_PCIMAP_CFG
= 0;
357 ("Unknown Core card, don't know the system controller.\n");
363 static int __init
pcibios_init(void)
365 #ifdef CONFIG_MIPS_MALTA
366 struct pci_dev
*pdev
;
367 unsigned char reg_val
;
370 printk("PCI: Probing PCI hardware on host bus 0.\n");
371 pci_scan_bus(0, &mips_pci_ops
, NULL
);
373 switch (mips_revision_corid
) {
374 case MIPS_REVISION_CORID_QED_RM5261
:
375 case MIPS_REVISION_CORID_CORE_LV
:
376 case MIPS_REVISION_CORID_CORE_FPGA
:
378 * Due to a bug in the Galileo system controller, we need
379 * to setup the PCI BAR for the Galileo internal registers.
380 * This should be done in the bios/bootprom and will be
381 * fixed in a later revision of YAMON (the MIPS boards
384 GT_WRITE(GT_PCI0_CFGADDR_OFS
, (0 << GT_PCI0_CFGADDR_BUSNUM_SHF
) | /* Local bus */
385 (0 << GT_PCI0_CFGADDR_DEVNUM_SHF
) | /* GT64120 dev */
386 (0 << GT_PCI0_CFGADDR_FUNCTNUM_SHF
) | /* Function 0 */
387 ((0x20 / 4) << GT_PCI0_CFGADDR_REGNUM_SHF
) | /* BAR 4 */
388 GT_PCI0_CFGADDR_CONFIGEN_BIT
);
390 /* Perform the write */
391 GT_WRITE(GT_PCI0_CFGDATA_OFS
, PHYSADDR(MIPS_GT_BASE
));
395 #ifdef CONFIG_MIPS_MALTA
396 pci_for_each_dev(pdev
) {
397 if ((pdev
->vendor
== PCI_VENDOR_ID_INTEL
)
398 && (pdev
->device
== PCI_DEVICE_ID_INTEL_82371AB
)
399 && (PCI_SLOT(pdev
->devfn
) == 0x0a)) {
403 pci_read_config_byte(pdev
, 0x41, ®_val
);
404 pci_write_config_byte(pdev
, 0x41, reg_val
| 0x80);
405 pci_read_config_byte(pdev
, 0x43, ®_val
);
406 pci_write_config_byte(pdev
, 0x43, reg_val
| 0x80);
409 if ((pdev
->vendor
== PCI_VENDOR_ID_INTEL
)
410 && (pdev
->device
== PCI_DEVICE_ID_INTEL_82371AB_0
)
411 && (PCI_SLOT(pdev
->devfn
) == 0x0a)) {
413 * Set top of main memory accessible by ISA or DMA
416 pci_read_config_byte(pdev
, 0x69, ®_val
);
417 pci_write_config_byte(pdev
, 0x69, reg_val
| 0xf0);
422 * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
424 * This should be done in the bios/bootprom and will be fixed in
425 * a later revision of YAMON (the MIPS boards boot prom).
427 /* Entering config state. */
428 SMSC_WRITE(SMSC_CONFIG_ENTER
, SMSC_CONFIG_REG
);
430 /* Activate floppy controller. */
431 SMSC_WRITE(SMSC_CONFIG_DEVNUM
, SMSC_CONFIG_REG
);
432 SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY
, SMSC_DATA_REG
);
433 SMSC_WRITE(SMSC_CONFIG_ACTIVATE
, SMSC_CONFIG_REG
);
434 SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE
, SMSC_DATA_REG
);
436 /* Exit config state. */
437 SMSC_WRITE(SMSC_CONFIG_EXIT
, SMSC_CONFIG_REG
);
443 subsys_initcall(pcibios_init
);
445 int pcibios_enable_device(struct pci_dev
*dev
, int mask
)
447 /* Not needed, since we enable all devices at startup. */
451 void pcibios_align_resource(void *data
, struct resource
*res
,
452 unsigned long size
, unsigned long align
)
456 char *__init
pcibios_setup(char *str
)
458 /* Nothing to do for now. */
463 struct pci_fixup pcibios_fixups
[] = {
468 * Called after each bus is probed, but before its children
471 void __devinit
pcibios_fixup_bus(struct pci_bus
*b
)
473 pci_read_bridge_bases(b
);
476 unsigned int pcibios_assign_all_busses(void)