2 * BK Id: SCCS/s.indirect_pci.c 1.17 09/13/02 11:29:46 mporter
5 * Support for indirect PCI bridges.
7 * Copyright (C) 1998 Gabriel Paubert.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/pci.h>
17 #include <linux/delay.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/bootmem.h>
24 #include <asm/pci-bridge.h>
25 #include <asm/machdep.h>
27 #define cfg_read(val, addr, type, op) *val = op((type)(addr))
28 #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
30 #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
32 indirect_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
34 struct pci_controller *hose = dev->sysdata; \
37 if (ppc_md.pci_exclude_device) \
38 if (ppc_md.pci_exclude_device(dev->bus->number, dev->devfn)) \
39 return PCIBIOS_DEVICE_NOT_FOUND; \
41 if (hose->set_cfg_type) \
42 if (dev->bus->number != hose->first_busno) \
45 out_be32(hose->cfg_addr, \
46 (((offset & 0xfc) | cfg_type) << 24) | (dev->devfn << 16) \
47 | ((dev->bus->number - hose->bus_offset) << 8) | 0x80); \
48 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
49 return PCIBIOS_SUCCESSFUL; \
52 INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
53 INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
54 INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
55 INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
56 INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
57 INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
59 static struct pci_ops indirect_pci_ops =
61 indirect_read_config_byte,
62 indirect_read_config_word,
63 indirect_read_config_dword,
64 indirect_write_config_byte,
65 indirect_write_config_word,
66 indirect_write_config_dword
70 setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
72 hose->ops = &indirect_pci_ops;
73 hose->cfg_addr = (unsigned int *) ioremap(cfg_addr, 4);
74 hose->cfg_data = (unsigned char *) ioremap(cfg_data, 4);