11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public
31da177e4SLinus Torvalds * License. See the file "COPYING" in the main directory of this archive
41da177e4SLinus Torvalds * for more details.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (C) 2000, 2001 Keith M Wesolowski
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds #include <linux/kernel.h>
91da177e4SLinus Torvalds #include <linux/pci.h>
101da177e4SLinus Torvalds #include <linux/types.h>
111da177e4SLinus Torvalds #include <asm/ip32/mace.h>
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #if 0
141da177e4SLinus Torvalds # define DPRINTK(args...) printk(args);
151da177e4SLinus Torvalds #else
161da177e4SLinus Torvalds # define DPRINTK(args...)
171da177e4SLinus Torvalds #endif
181da177e4SLinus Torvalds
191da177e4SLinus Torvalds /*
201da177e4SLinus Torvalds * O2 has up to 5 PCI devices connected into the MACE bridge. The device
211da177e4SLinus Torvalds * map looks like this:
221da177e4SLinus Torvalds *
231da177e4SLinus Torvalds * 0 aic7xxx 0
241da177e4SLinus Torvalds * 1 aic7xxx 1
251da177e4SLinus Torvalds * 2 expansion slot
261da177e4SLinus Torvalds * 3 N/C
271da177e4SLinus Torvalds * 4 N/C
281da177e4SLinus Torvalds */
291da177e4SLinus Torvalds
mkaddr(struct pci_bus * bus,unsigned int devfn,unsigned int reg)308cfaf453SGiuseppe Sacco static inline int mkaddr(struct pci_bus *bus, unsigned int devfn,
318cfaf453SGiuseppe Sacco unsigned int reg)
328cfaf453SGiuseppe Sacco {
338cfaf453SGiuseppe Sacco return ((bus->number & 0xff) << 16) |
34378a5459SGiuseppe Sacco ((devfn & 0xff) << 8) |
358cfaf453SGiuseppe Sacco (reg & 0xfc);
368cfaf453SGiuseppe Sacco }
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds
391da177e4SLinus Torvalds static int
mace_pci_read_config(struct pci_bus * bus,unsigned int devfn,int reg,int size,u32 * val)401da177e4SLinus Torvalds mace_pci_read_config(struct pci_bus *bus, unsigned int devfn,
411da177e4SLinus Torvalds int reg, int size, u32 *val)
421da177e4SLinus Torvalds {
43c990081bSThomas Bogendoerfer u32 control = mace->pci.control;
44c990081bSThomas Bogendoerfer
45c990081bSThomas Bogendoerfer /* disable master aborts interrupts during config read */
46c990081bSThomas Bogendoerfer mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT;
478cfaf453SGiuseppe Sacco mace->pci.config_addr = mkaddr(bus, devfn, reg);
481da177e4SLinus Torvalds switch (size) {
491da177e4SLinus Torvalds case 1:
501da177e4SLinus Torvalds *val = mace->pci.config_data.b[(reg & 3) ^ 3];
511da177e4SLinus Torvalds break;
521da177e4SLinus Torvalds case 2:
531da177e4SLinus Torvalds *val = mace->pci.config_data.w[((reg >> 1) & 1) ^ 1];
541da177e4SLinus Torvalds break;
551da177e4SLinus Torvalds case 4:
561da177e4SLinus Torvalds *val = mace->pci.config_data.l;
571da177e4SLinus Torvalds break;
581da177e4SLinus Torvalds }
59c990081bSThomas Bogendoerfer /* ack possible master abort */
60c990081bSThomas Bogendoerfer mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT;
61c990081bSThomas Bogendoerfer mace->pci.control = control;
62*8736595bSThomas Bogendoerfer /*
63*8736595bSThomas Bogendoerfer * someone forgot to set the ultra bit for the onboard
64*8736595bSThomas Bogendoerfer * scsi chips; we fake it here
65*8736595bSThomas Bogendoerfer */
66*8736595bSThomas Bogendoerfer if (bus->number == 0 && reg == 0x40 && size == 4 &&
67*8736595bSThomas Bogendoerfer (devfn == (1 << 3) || devfn == (2 << 3)))
68*8736595bSThomas Bogendoerfer *val |= 0x1000;
691da177e4SLinus Torvalds
701da177e4SLinus Torvalds DPRINTK("read%d: reg=%08x,val=%02x\n", size * 8, reg, *val);
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds return PCIBIOS_SUCCESSFUL;
731da177e4SLinus Torvalds }
741da177e4SLinus Torvalds
751da177e4SLinus Torvalds static int
mace_pci_write_config(struct pci_bus * bus,unsigned int devfn,int reg,int size,u32 val)761da177e4SLinus Torvalds mace_pci_write_config(struct pci_bus *bus, unsigned int devfn,
771da177e4SLinus Torvalds int reg, int size, u32 val)
781da177e4SLinus Torvalds {
798cfaf453SGiuseppe Sacco mace->pci.config_addr = mkaddr(bus, devfn, reg);
801da177e4SLinus Torvalds switch (size) {
811da177e4SLinus Torvalds case 1:
821da177e4SLinus Torvalds mace->pci.config_data.b[(reg & 3) ^ 3] = val;
831da177e4SLinus Torvalds break;
841da177e4SLinus Torvalds case 2:
851da177e4SLinus Torvalds mace->pci.config_data.w[((reg >> 1) & 1) ^ 1] = val;
861da177e4SLinus Torvalds break;
871da177e4SLinus Torvalds case 4:
881da177e4SLinus Torvalds mace->pci.config_data.l = val;
891da177e4SLinus Torvalds break;
901da177e4SLinus Torvalds }
911da177e4SLinus Torvalds
921da177e4SLinus Torvalds DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val);
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds return PCIBIOS_SUCCESSFUL;
951da177e4SLinus Torvalds }
961da177e4SLinus Torvalds
971da177e4SLinus Torvalds struct pci_ops mace_pci_ops = {
981da177e4SLinus Torvalds .read = mace_pci_read_config,
991da177e4SLinus Torvalds .write = mace_pci_write_config,
1001da177e4SLinus Torvalds };
101