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 (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
39 if (bus->number != hose->first_busno)
40 return PCIBIOS_DEVICE_NOT_FOUND;
42 return PCIBIOS_DEVICE_NOT_FOUND;
45 if (ppc_md.pci_exclude_device)
46 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
47 return PCIBIOS_DEVICE_NOT_FOUND;
49 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
50 if (bus->number != hose->first_busno)
53 bus_no = (bus->number == hose->first_busno) ?
54 hose->self_busno : bus->number;
56 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
57 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
61 PCI_CFG_OUT(hose->cfg_addr,
62 (0x80000000 | (bus_no << 16)
63 | (devfn << 8) | reg | cfg_type));
66 * Note: the caller has already checked that offset is
67 * suitably aligned and that len is 1, 2 or 4.
69 cfg_data = hose->cfg_data + (offset & 3);
72 *val = in_8(cfg_data);
75 *val = in_le16(cfg_data);
78 *val = in_le32(cfg_data);
81 return PCIBIOS_SUCCESSFUL;
85 indirect_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
88 struct pci_controller *hose = bus->sysdata;
89 volatile void __iomem *cfg_data;
93 if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
94 if (bus->number != hose->first_busno)
95 return PCIBIOS_DEVICE_NOT_FOUND;
97 return PCIBIOS_DEVICE_NOT_FOUND;
100 if (ppc_md.pci_exclude_device)
101 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
102 return PCIBIOS_DEVICE_NOT_FOUND;
104 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
105 if (bus->number != hose->first_busno)
108 bus_no = (bus->number == hose->first_busno) ?
109 hose->self_busno : bus->number;
111 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
112 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
116 PCI_CFG_OUT(hose->cfg_addr,
117 (0x80000000 | (bus_no << 16)
118 | (devfn << 8) | reg | cfg_type));
120 /* surpress setting of PCI_PRIMARY_BUS */
121 if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
122 if ((offset == PCI_PRIMARY_BUS) &&
123 (bus->number == hose->first_busno))
127 * Note: the caller has already checked that offset is
128 * suitably aligned and that len is 1, 2 or 4.
130 cfg_data = hose->cfg_data + (offset & 3);
133 out_8(cfg_data, val);
136 out_le16(cfg_data, val);
139 out_le32(cfg_data, val);
142 return PCIBIOS_SUCCESSFUL;
145 static struct pci_ops indirect_pci_ops =
147 indirect_read_config,
148 indirect_write_config
152 setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
154 unsigned long base = cfg_addr & PAGE_MASK;
157 mbase = ioremap(base, PAGE_SIZE);
158 hose->cfg_addr = mbase + (cfg_addr & ~PAGE_MASK);
159 if ((cfg_data & PAGE_MASK) != base)
160 mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
161 hose->cfg_data = mbase + (cfg_data & ~PAGE_MASK);
162 hose->ops = &indirect_pci_ops;