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->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 PCI_CFG_OUT(hose->cfg_addr,
50 (0x80000000 | (bus_no << 16)
51 | (devfn << 8) | ((offset & 0xfc) | cfg_type)));
54 * Note: the caller has already checked that offset is
55 * suitably aligned and that len is 1, 2 or 4.
57 cfg_data = hose->cfg_data + (offset & 3);
60 *val = in_8(cfg_data);
63 *val = in_le16(cfg_data);
66 *val = in_le32(cfg_data);
69 return PCIBIOS_SUCCESSFUL;
73 indirect_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
76 struct pci_controller *hose = bus->sysdata;
77 volatile void __iomem *cfg_data;
81 if (ppc_md.pci_exclude_device)
82 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
83 return PCIBIOS_DEVICE_NOT_FOUND;
85 if (hose->set_cfg_type)
86 if (bus->number != hose->first_busno)
89 bus_no = (bus->number == hose->first_busno) ?
90 hose->self_busno : bus->number;
92 PCI_CFG_OUT(hose->cfg_addr,
93 (0x80000000 | (bus_no << 16)
94 | (devfn << 8) | ((offset & 0xfc) | cfg_type)));
97 * Note: the caller has already checked that offset is
98 * suitably aligned and that len is 1, 2 or 4.
100 cfg_data = hose->cfg_data + (offset & 3);
103 out_8(cfg_data, val);
106 out_le16(cfg_data, val);
109 out_le32(cfg_data, val);
112 return PCIBIOS_SUCCESSFUL;
115 static struct pci_ops indirect_pci_ops =
117 indirect_read_config,
118 indirect_write_config
122 setup_indirect_pci_nomap(struct pci_controller* hose, void __iomem * cfg_addr,
123 void __iomem * cfg_data)
125 hose->cfg_addr = cfg_addr;
126 hose->cfg_data = cfg_data;
127 hose->ops = &indirect_pci_ops;
131 setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
133 unsigned long base = cfg_addr & PAGE_MASK;
134 void __iomem *mbase, *addr, *data;
136 mbase = ioremap(base, PAGE_SIZE);
137 addr = mbase + (cfg_addr & ~PAGE_MASK);
138 if ((cfg_data & PAGE_MASK) != base)
139 mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
140 data = mbase + (cfg_data & ~PAGE_MASK);
141 setup_indirect_pci_nomap(hose, addr, data);