Feed the mess through indent.
[linux-2.6/linux-mips.git] / arch / mips / pci / pci-mips.c
blob5abc260bb92793916faaa3cefb7304c2b91a8936
1 /*
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
12 * for more details.
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>
32 #endif
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
41 /* Type 0 */
42 #define PCI_CFG_TYPE0_REG_SHF 0
43 #define PCI_CFG_TYPE0_FUNC_SHF 8
45 /* Type 1 */
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,
52 struct pci_bus *bus,
53 unsigned int devfn, int where,
54 u32 * data)
56 unsigned char busnum = bus->number;
57 unsigned char type;
58 u32 intr, dummy;
59 u64 pci_addr;
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));
76 /* Setup address */
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);
90 } else {
91 GT_PCI_WRITE(GT_PCI0_CFGDATA_OFS, *data);
93 } else {
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);
100 } else {
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)) {
110 /* Error occurred */
112 /* Clear bits */
113 GT_READ(GT_INTRCAUSE_OFS, intr);
114 GT_WRITE(GT_INTRCAUSE_OFS, intr &
115 ~(GT_INTRCAUSE_MASABORT0_BIT |
116 GT_INTRCAUSE_TARABORT0_BIT));
118 return -1;
121 break;
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)) {
128 return -1;
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
137 * Type 0 cycle
139 if (busnum == 0) {
140 /* IDSEL */
141 pci_addr = (u64) 1 << (PCI_SLOT(devfn) + 10);
142 } else {
143 /* Bus number */
144 pci_addr = busnum << PCI_CFG_TYPE1_BUS_SHF;
146 /* Device number */
147 pci_addr |=
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;
157 if (busnum == 0) {
158 /* Type 0 */
159 BONITO_PCIMAP_CFG = pci_addr >> 16;
160 } else {
161 /* Type 1 */
162 BONITO_PCIMAP_CFG = (pci_addr >> 16) | 0x10000;
165 /* Flush Bonito register block */
166 dummy = BONITO_PCIMAP_CFG;
167 iob(); /* sync */
169 /* Perform access */
170 if (access_type == PCI_ACCESS_WRITE) {
171 *(volatile u32 *) (KSEG1ADDR(BONITO_PCICFG_BASE +
172 (pci_addr & 0xffff)))
173 = *(u32 *) data;
175 /* Wait till done */
176 while (BONITO_PCIMSTAT & 0xF);
177 } else {
178 *(u32 *) data =
179 *(volatile u32
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)) {
187 /* Error occurred */
189 /* Clear bits */
190 BONITO_PCICMD |= (BONITO_PCICMD_MABORT_CLR |
191 BONITO_PCICMD_MTABORT_CLR);
193 return -1;
195 break;
197 case MIPS_REVISION_CORID_CORE_MSC:
198 /* MIPS system controller. */
200 if ((busnum == 0) && (PCI_SLOT(devfn) == 0)) {
201 return -1;
204 /* Clear status register bits. */
205 MSC_WRITE(MSC01_PCI_INTSTAT,
206 (MSC01_PCI_INTCFG_MA_BIT |
207 MSC01_PCI_INTCFG_TA_BIT));
209 /* Setup address */
210 if (busnum == 0)
211 type = 0; /* Type 0 */
212 else
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 /
220 4) <<
221 MSC01_PCI_CFGADDR_RNUM_SHF)
222 | (type)));
224 /* Perform access */
225 if (access_type == PCI_ACCESS_WRITE) {
226 MSC_WRITE(MSC01_PCI_CFGDATA, *data);
227 } else {
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)) {
235 /* Error occurred */
237 /* Clear bits */
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));
243 return -1;
245 break;
246 default:
247 printk
248 ("Unknown Core card, don't know the system controller.\n");
249 return -1;
252 return 0;
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)
263 u32 data = 0;
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,
271 &data))
272 return -1;
274 if (size == 1)
275 *val = (data >> ((where & 3) << 3)) & 0xff;
276 else if (size == 2)
277 *val = (data >> ((where & 3) << 3)) & 0xffff;
278 else
279 *val = data;
281 return PCIBIOS_SUCCESSFUL;
284 static int mips_pcibios_write(struct pci_bus *bus, unsigned int devfn,
285 int where, int size, u32 val)
287 u32 data = 0;
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,
295 &data))
296 return -1;
298 if (size == 1)
299 data = (data & ~(0xff << ((where & 3) << 3))) |
300 (val << ((where & 3) << 3));
301 else if (size == 2)
302 data = (data & ~(0xffff << ((where & 3) << 3))) |
303 (val << ((where & 3) << 3));
305 if (mips_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn, where,
306 &data))
307 return -1;
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)
319 int irq;
320 u32 dummy;
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);
333 else
334 GT_READ(GT_PCI0_IACK_OFS, irq);
335 irq &= 0xff;
336 break;
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
342 * the given time.
344 BONITO_PCIMAP_CFG = 0x20000;
346 /* Flush Bonito register block */
347 dummy = BONITO_PCIMAP_CFG;
348 iob(); /* sync */
350 irq = *(volatile u32 *) (KSEG1ADDR(BONITO_PCICFG_BASE));
351 iob(); /* sync */
352 irq &= 0xff;
353 BONITO_PCIMAP_CFG = 0;
354 break;
355 default:
356 printk
357 ("Unknown Core card, don't know the system controller.\n");
358 return -1;
360 return irq;
363 static int __init pcibios_init(void)
365 #ifdef CONFIG_MIPS_MALTA
366 struct pci_dev *pdev;
367 unsigned char reg_val;
368 #endif
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
382 * boot prom).
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));
392 break;
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)) {
401 * IDE Decode enable.
403 pci_read_config_byte(pdev, 0x41, &reg_val);
404 pci_write_config_byte(pdev, 0x41, reg_val | 0x80);
405 pci_read_config_byte(pdev, 0x43, &reg_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
414 * devices to 16 Mb.
416 pci_read_config_byte(pdev, 0x69, &reg_val);
417 pci_write_config_byte(pdev, 0x69, reg_val | 0xf0);
422 * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
423 * Controller.
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);
438 #endif
440 return 0;
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. */
448 return 0;
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. */
460 return str;
463 struct pci_fixup pcibios_fixups[] = {
468 * Called after each bus is probed, but before its children
469 * are examined.
471 void __devinit pcibios_fixup_bus(struct pci_bus *b)
473 pci_read_bridge_bases(b);
476 unsigned int pcibios_assign_all_busses(void)
478 return 1;