Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2000, 2001 Keith M Wesolowski |
| 7 | */ |
| 8 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/pci.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <asm/pci.h> |
| 12 | #include <asm/ip32/mace.h> |
| 13 | |
| 14 | #if 0 |
| 15 | # define DPRINTK(args...) printk(args); |
| 16 | #else |
| 17 | # define DPRINTK(args...) |
| 18 | #endif |
| 19 | |
| 20 | /* |
| 21 | * O2 has up to 5 PCI devices connected into the MACE bridge. The device |
| 22 | * map looks like this: |
| 23 | * |
| 24 | * 0 aic7xxx 0 |
| 25 | * 1 aic7xxx 1 |
| 26 | * 2 expansion slot |
| 27 | * 3 N/C |
| 28 | * 4 N/C |
| 29 | */ |
| 30 | |
Giuseppe Sacco | 8cfaf453 | 2007-10-04 23:09:12 +0200 | [diff] [blame] | 31 | static inline int mkaddr(struct pci_bus *bus, unsigned int devfn, |
| 32 | unsigned int reg) |
| 33 | { |
| 34 | return ((bus->number & 0xff) << 16) | |
Giuseppe Sacco | 378a545 | 2007-10-06 19:55:03 +0200 | [diff] [blame] | 35 | ((devfn & 0xff) << 8) | |
Giuseppe Sacco | 8cfaf453 | 2007-10-04 23:09:12 +0200 | [diff] [blame] | 36 | (reg & 0xfc); |
| 37 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | static int |
| 41 | mace_pci_read_config(struct pci_bus *bus, unsigned int devfn, |
| 42 | int reg, int size, u32 *val) |
| 43 | { |
Thomas Bogendoerfer | c990081 | 2008-01-05 12:13:11 +0100 | [diff] [blame] | 44 | u32 control = mace->pci.control; |
| 45 | |
| 46 | /* disable master aborts interrupts during config read */ |
| 47 | mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT; |
Giuseppe Sacco | 8cfaf453 | 2007-10-04 23:09:12 +0200 | [diff] [blame] | 48 | mace->pci.config_addr = mkaddr(bus, devfn, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | switch (size) { |
| 50 | case 1: |
| 51 | *val = mace->pci.config_data.b[(reg & 3) ^ 3]; |
| 52 | break; |
| 53 | case 2: |
| 54 | *val = mace->pci.config_data.w[((reg >> 1) & 1) ^ 1]; |
| 55 | break; |
| 56 | case 4: |
| 57 | *val = mace->pci.config_data.l; |
| 58 | break; |
| 59 | } |
Thomas Bogendoerfer | c990081 | 2008-01-05 12:13:11 +0100 | [diff] [blame] | 60 | /* ack possible master abort */ |
| 61 | mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT; |
| 62 | mace->pci.control = control; |
Thomas Bogendoerfer | 8736595 | 2008-07-02 21:06:03 +0200 | [diff] [blame] | 63 | /* |
| 64 | * someone forgot to set the ultra bit for the onboard |
| 65 | * scsi chips; we fake it here |
| 66 | */ |
| 67 | if (bus->number == 0 && reg == 0x40 && size == 4 && |
| 68 | (devfn == (1 << 3) || devfn == (2 << 3))) |
| 69 | *val |= 0x1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | DPRINTK("read%d: reg=%08x,val=%02x\n", size * 8, reg, *val); |
| 72 | |
| 73 | return PCIBIOS_SUCCESSFUL; |
| 74 | } |
| 75 | |
| 76 | static int |
| 77 | mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, |
| 78 | int reg, int size, u32 val) |
| 79 | { |
Giuseppe Sacco | 8cfaf453 | 2007-10-04 23:09:12 +0200 | [diff] [blame] | 80 | mace->pci.config_addr = mkaddr(bus, devfn, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | switch (size) { |
| 82 | case 1: |
| 83 | mace->pci.config_data.b[(reg & 3) ^ 3] = val; |
| 84 | break; |
| 85 | case 2: |
| 86 | mace->pci.config_data.w[((reg >> 1) & 1) ^ 1] = val; |
| 87 | break; |
| 88 | case 4: |
| 89 | mace->pci.config_data.l = val; |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val); |
| 94 | |
| 95 | return PCIBIOS_SUCCESSFUL; |
| 96 | } |
| 97 | |
| 98 | struct pci_ops mace_pci_ops = { |
| 99 | .read = mace_pci_read_config, |
| 100 | .write = mace_pci_write_config, |
| 101 | }; |