5 #include <linux/config.h>
6 #include <linux/kernel.h>
8 #include <linux/delay.h>
9 #include <linux/string.h>
10 #include <linux/init.h>
11 #include <linux/ide.h>
14 #include <asm/pgtable.h>
16 #include <asm/hydra.h>
19 #include <asm/machdep.h>
20 #include <asm/sections.h>
21 #include <asm/pci-bridge.h>
22 #include <asm/open_pic.h>
23 #include <asm/grackle.h>
27 void __iomem *gg2_pci_config_base;
30 * The VLSI Golden Gate II has only 512K of PCI configuration space, so we
31 * limit the bus number to 3 bits
34 int gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off,
37 volatile void __iomem *cfg_data;
38 struct pci_controller *hose = bus->sysdata;
41 return PCIBIOS_DEVICE_NOT_FOUND;
43 * Note: the caller has already checked that off is
44 * suitably aligned and that len is 1, 2 or 4.
46 cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
49 *val = in_8(cfg_data);
52 *val = in_le16(cfg_data);
55 *val = in_le32(cfg_data);
58 return PCIBIOS_SUCCESSFUL;
61 int gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off,
64 volatile void __iomem *cfg_data;
65 struct pci_controller *hose = bus->sysdata;
68 return PCIBIOS_DEVICE_NOT_FOUND;
70 * Note: the caller has already checked that off is
71 * suitably aligned and that len is 1, 2 or 4.
73 cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
79 out_le16(cfg_data, val);
82 out_le32(cfg_data, val);
85 return PCIBIOS_SUCCESSFUL;
88 static struct pci_ops gg2_pci_ops =
95 * Access functions for PCI config space using RTAS calls.
97 int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
100 struct pci_controller *hose = bus->sysdata;
101 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
102 | (((bus->number - hose->first_busno) & 0xff) << 16)
103 | (hose->index << 24);
107 rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
109 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
112 int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
115 struct pci_controller *hose = bus->sysdata;
116 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
117 | (((bus->number - hose->first_busno) & 0xff) << 16)
118 | (hose->index << 24);
121 rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
123 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
126 static struct pci_ops rtas_pci_ops =
132 volatile struct Hydra __iomem *Hydra = NULL;
137 struct device_node *np;
140 np = find_devices("mac-io");
141 if (np == NULL || of_address_to_resource(np, 0, &r))
143 Hydra = ioremap(r.start, r.end-r.start);
144 printk("Hydra Mac I/O at %lx\n", r.start);
145 printk("Hydra Feature_Control was %x",
146 in_le32(&Hydra->Feature_Control));
147 out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN |
148 HYDRA_FC_SCSI_CELL_EN |
149 HYDRA_FC_SCCA_ENABLE |
150 HYDRA_FC_SCCB_ENABLE |
151 HYDRA_FC_ARB_BYPASS |
152 HYDRA_FC_MPIC_ENABLE |
153 HYDRA_FC_SLOW_SCC_PCLK |
154 HYDRA_FC_MPIC_IS_MASTER));
155 printk(", now %x\n", in_le32(&Hydra->Feature_Control));
160 chrp_pcibios_fixup(void)
162 struct pci_dev *dev = NULL;
163 struct device_node *np;
165 /* PCI interrupts are controlled by the OpenPIC */
166 for_each_pci_dev(dev) {
167 np = pci_device_to_OF_node(dev);
168 if ((np != 0) && (np->n_intrs > 0) && (np->intrs[0].line != 0))
169 dev->irq = np->intrs[0].line;
170 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
174 #define PRG_CL_RESET_VALID 0x00010000
177 setup_python(struct pci_controller *hose, struct device_node *dev)
183 if (of_address_to_resource(dev, 0, &r)) {
184 printk(KERN_ERR "No address for Python PCI controller\n");
188 /* Clear the magic go-slow bit */
189 reg = ioremap(r.start + 0xf6000, 0x40);
191 val = in_be32(®[12]);
192 if (val & PRG_CL_RESET_VALID) {
193 out_be32(®[12], val & ~PRG_CL_RESET_VALID);
198 setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010);
201 /* Marvell Discovery II based Pegasos 2 */
202 static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev)
204 struct device_node *root = find_path_device("/");
205 struct device_node *rtas;
208 rtas = of_find_node_by_name (root, "rtas");
210 hose->ops = &rtas_pci_ops;
213 printk ("RTAS supporting Pegasos OF not found, please upgrade"
216 pci_assign_all_buses = 1;
220 chrp_find_bridges(void)
222 struct device_node *dev;
225 struct pci_controller *hose;
227 char *model, *machine;
228 int is_longtrail = 0, is_mot = 0, is_pegasos = 0;
229 struct device_node *root = find_path_device("/");
232 * The PCI host bridge nodes on some machines don't have
233 * properties to adequately identify them, so we have to
234 * look at what sort of machine this is as well.
236 machine = get_property(root, "model", NULL);
237 if (machine != NULL) {
238 is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
239 is_mot = strncmp(machine, "MOT", 3) == 0;
240 if (strncmp(machine, "Pegasos2", 8) == 0)
242 else if (strncmp(machine, "Pegasos", 7) == 0)
245 for (dev = root->child; dev != NULL; dev = dev->sibling) {
246 if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
249 /* The GG2 bridge on the LongTrail doesn't have an address */
250 if (of_address_to_resource(dev, 0, &r) && !is_longtrail) {
251 printk(KERN_WARNING "Can't use %s: no address\n",
255 bus_range = (int *) get_property(dev, "bus-range", &len);
256 if (bus_range == NULL || len < 2 * sizeof(int)) {
257 printk(KERN_WARNING "Can't get bus-range for %s\n",
261 if (bus_range[1] == bus_range[0])
262 printk(KERN_INFO "PCI bus %d", bus_range[0]);
264 printk(KERN_INFO "PCI buses %d..%d",
265 bus_range[0], bus_range[1]);
266 printk(" controlled by %s", dev->type);
268 printk(" at %lx", r.start);
271 hose = pcibios_alloc_controller();
273 printk("Can't allocate PCI controller structure for %s\n",
277 hose->arch_data = dev;
278 hose->first_busno = bus_range[0];
279 hose->last_busno = bus_range[1];
281 model = get_property(dev, "model", NULL);
284 if (device_is_compatible(dev, "IBM,python")) {
285 setup_python(hose, dev);
287 || strncmp(model, "Motorola, Grackle", 17) == 0) {
289 } else if (is_longtrail) {
290 void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
291 hose->ops = &gg2_pci_ops;
293 gg2_pci_config_base = p;
294 } else if (is_pegasos == 1) {
295 setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc);
296 } else if (is_pegasos == 2) {
297 setup_peg2(hose, dev);
299 printk("No methods for %s (model %s), using RTAS\n",
300 dev->full_name, model);
301 hose->ops = &rtas_pci_ops;
304 pci_process_bridge_OF_ranges(hose, dev, index == 0);
306 /* check the first bridge for a property that we can
307 use to set pci_dram_offset */
308 dma = (unsigned int *)
309 get_property(dev, "ibm,dma-ranges", &len);
310 if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
311 pci_dram_offset = dma[2] - dma[3];
312 printk("pci_dram_offset = %lx\n", pci_dram_offset);
316 /* Do not fixup interrupts from OF tree on pegasos */
318 ppc_md.pcibios_fixup = chrp_pcibios_fixup;