pinctrl: make a copy of pinmux map
[linux/fpc-iii.git] / arch / powerpc / kernel / io-workarounds.c
blob12d329bcbb9825cbad17618460e22d4c2b0d5cdf
1 /*
2 * Support PCI IO workaround
4 * Copyright (C) 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org>
5 * IBM, Corp.
6 * (C) Copyright 2007-2008 TOSHIBA CORPORATION
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #undef DEBUG
14 #include <linux/kernel.h>
15 #include <linux/sched.h> /* for init_mm */
17 #include <asm/io.h>
18 #include <asm/machdep.h>
19 #include <asm/pgtable.h>
20 #include <asm/ppc-pci.h>
21 #include <asm/io-workarounds.h>
23 #define IOWA_MAX_BUS 8
25 static struct iowa_bus iowa_busses[IOWA_MAX_BUS];
26 static unsigned int iowa_bus_count;
28 static struct iowa_bus *iowa_pci_find(unsigned long vaddr, unsigned long paddr)
30 int i, j;
31 struct resource *res;
32 unsigned long vstart, vend;
34 for (i = 0; i < iowa_bus_count; i++) {
35 struct iowa_bus *bus = &iowa_busses[i];
36 struct pci_controller *phb = bus->phb;
38 if (vaddr) {
39 vstart = (unsigned long)phb->io_base_virt;
40 vend = vstart + phb->pci_io_size - 1;
41 if ((vaddr >= vstart) && (vaddr <= vend))
42 return bus;
45 if (paddr)
46 for (j = 0; j < 3; j++) {
47 res = &phb->mem_resources[j];
48 if (paddr >= res->start && paddr <= res->end)
49 return bus;
53 return NULL;
56 struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR addr)
58 struct iowa_bus *bus;
59 int token;
61 token = PCI_GET_ADDR_TOKEN(addr);
63 if (token && token <= iowa_bus_count)
64 bus = &iowa_busses[token - 1];
65 else {
66 unsigned long vaddr, paddr;
67 pte_t *ptep;
69 vaddr = (unsigned long)PCI_FIX_ADDR(addr);
70 if (vaddr < PHB_IO_BASE || vaddr >= PHB_IO_END)
71 return NULL;
73 ptep = find_linux_pte(init_mm.pgd, vaddr);
74 if (ptep == NULL)
75 paddr = 0;
76 else
77 paddr = pte_pfn(*ptep) << PAGE_SHIFT;
78 bus = iowa_pci_find(vaddr, paddr);
80 if (bus == NULL)
81 return NULL;
84 return bus;
87 struct iowa_bus *iowa_pio_find_bus(unsigned long port)
89 unsigned long vaddr = (unsigned long)pci_io_base + port;
90 return iowa_pci_find(vaddr, 0);
94 #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \
95 static ret iowa_##name at \
96 { \
97 struct iowa_bus *bus; \
98 bus = iowa_##space##_find_bus(aa); \
99 if (bus && bus->ops && bus->ops->name) \
100 return bus->ops->name al; \
101 return __do_##name al; \
104 #define DEF_PCI_AC_NORET(name, at, al, space, aa) \
105 static void iowa_##name at \
107 struct iowa_bus *bus; \
108 bus = iowa_##space##_find_bus(aa); \
109 if (bus && bus->ops && bus->ops->name) { \
110 bus->ops->name al; \
111 return; \
113 __do_##name al; \
116 #include <asm/io-defs.h>
118 #undef DEF_PCI_AC_RET
119 #undef DEF_PCI_AC_NORET
121 static const struct ppc_pci_io __devinitconst iowa_pci_io = {
123 #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) .name = iowa_##name,
124 #define DEF_PCI_AC_NORET(name, at, al, space, aa) .name = iowa_##name,
126 #include <asm/io-defs.h>
128 #undef DEF_PCI_AC_RET
129 #undef DEF_PCI_AC_NORET
133 static void __iomem *iowa_ioremap(phys_addr_t addr, unsigned long size,
134 unsigned long flags, void *caller)
136 struct iowa_bus *bus;
137 void __iomem *res = __ioremap_caller(addr, size, flags, caller);
138 int busno;
140 bus = iowa_pci_find(0, (unsigned long)addr);
141 if (bus != NULL) {
142 busno = bus - iowa_busses;
143 PCI_SET_ADDR_TOKEN(res, busno + 1);
145 return res;
148 /* Enable IO workaround */
149 static void __devinit io_workaround_init(void)
151 static int io_workaround_inited;
153 if (io_workaround_inited)
154 return;
155 ppc_pci_io = iowa_pci_io;
156 ppc_md.ioremap = iowa_ioremap;
157 io_workaround_inited = 1;
160 /* Register new bus to support workaround */
161 void __devinit iowa_register_bus(struct pci_controller *phb,
162 struct ppc_pci_io *ops,
163 int (*initfunc)(struct iowa_bus *, void *), void *data)
165 struct iowa_bus *bus;
166 struct device_node *np = phb->dn;
168 io_workaround_init();
170 if (iowa_bus_count >= IOWA_MAX_BUS) {
171 pr_err("IOWA:Too many pci bridges, "
172 "workarounds disabled for %s\n", np->full_name);
173 return;
176 bus = &iowa_busses[iowa_bus_count];
177 bus->phb = phb;
178 bus->ops = ops;
179 bus->private = data;
181 if (initfunc)
182 if ((*initfunc)(bus, data))
183 return;
185 iowa_bus_count++;
187 pr_debug("IOWA:[%d]Add bus, %s.\n", iowa_bus_count-1, np->full_name);