2 * Support for indirect PCI bridges.
4 * Copyright (C) 1998 Gabriel Paubert.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/pci.h>
14 #include <linux/delay.h>
15 #include <linux/string.h>
16 #include <linux/init.h>
20 #include <asm/pci-bridge.h>
21 #include <asm/machdep.h>
23 #ifdef CONFIG_PPC_INDIRECT_PCI_BE
24 #define PCI_CFG_OUT out_be32
26 #define PCI_CFG_OUT out_le32
30 indirect_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
33 struct pci_controller *hose = bus->sysdata;
34 volatile void __iomem *cfg_data;
38 if (ppc_md.pci_exclude_device)
39 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
40 return PCIBIOS_DEVICE_NOT_FOUND;
42 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
43 if (bus->number != hose->first_busno)
46 bus_no = (bus->number == hose->first_busno) ?
47 hose->self_busno : bus->number;
49 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
50 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
54 PCI_CFG_OUT(hose->cfg_addr,
55 (0x80000000 | (bus_no << 16)
56 | (devfn << 8) | reg | cfg_type));
59 * Note: the caller has already checked that offset is
60 * suitably aligned and that len is 1, 2 or 4.
62 cfg_data = hose->cfg_data + (offset & 3);
65 *val = in_8(cfg_data);
68 *val = in_le16(cfg_data);
71 *val = in_le32(cfg_data);
74 return PCIBIOS_SUCCESSFUL;
78 indirect_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
81 struct pci_controller *hose = bus->sysdata;
82 volatile void __iomem *cfg_data;
86 if (ppc_md.pci_exclude_device)
87 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
88 return PCIBIOS_DEVICE_NOT_FOUND;
90 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
91 if (bus->number != hose->first_busno)
94 bus_no = (bus->number == hose->first_busno) ?
95 hose->self_busno : bus->number;
97 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
98 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
102 PCI_CFG_OUT(hose->cfg_addr,
103 (0x80000000 | (bus_no << 16)
104 | (devfn << 8) | reg | cfg_type));
106 /* surpress setting of PCI_PRIMARY_BUS */
107 if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
108 if ((offset == PCI_PRIMARY_BUS) &&
109 (bus->number == hose->first_busno))
113 * Note: the caller has already checked that offset is
114 * suitably aligned and that len is 1, 2 or 4.
116 cfg_data = hose->cfg_data + (offset & 3);
119 out_8(cfg_data, val);
122 out_le16(cfg_data, val);
125 out_le32(cfg_data, val);
128 return PCIBIOS_SUCCESSFUL;
131 static struct pci_ops indirect_pci_ops =
133 indirect_read_config,
134 indirect_write_config
138 setup_indirect_pci_nomap(struct pci_controller* hose, void __iomem * cfg_addr,
139 void __iomem * cfg_data)
141 hose->cfg_addr = cfg_addr;
142 hose->cfg_data = cfg_data;
143 hose->ops = &indirect_pci_ops;
147 setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
149 unsigned long base = cfg_addr & PAGE_MASK;
150 void __iomem *mbase, *addr, *data;
152 mbase = ioremap(base, PAGE_SIZE);
153 addr = mbase + (cfg_addr & ~PAGE_MASK);
154 if ((cfg_data & PAGE_MASK) != base)
155 mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
156 data = mbase + (cfg_data & ~PAGE_MASK);
157 setup_indirect_pci_nomap(hose, addr, data);