powerpc: Replace find_linux_pte with find_linux_pte_or_hugepte
[deliverable/linux.git] / arch / powerpc / kernel / io-workarounds.c
CommitLineData
014da7ff 1/*
7cfb62a2
IK
2 * Support PCI IO workaround
3 *
014da7ff
BH
4 * Copyright (C) 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org>
5 * IBM, Corp.
7cfb62a2 6 * (C) Copyright 2007-2008 TOSHIBA CORPORATION
014da7ff
BH
7 *
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.
11 */
12#undef DEBUG
13
14#include <linux/kernel.h>
333a1518 15#include <linux/sched.h> /* for init_mm */
7cfb62a2 16
014da7ff
BH
17#include <asm/io.h>
18#include <asm/machdep.h>
7cfb62a2 19#include <asm/pgtable.h>
014da7ff 20#include <asm/ppc-pci.h>
3cc30d07 21#include <asm/io-workarounds.h>
014da7ff 22
7cfb62a2 23#define IOWA_MAX_BUS 8
014da7ff 24
7cfb62a2
IK
25static struct iowa_bus iowa_busses[IOWA_MAX_BUS];
26static unsigned int iowa_bus_count;
014da7ff 27
7cfb62a2
IK
28static struct iowa_bus *iowa_pci_find(unsigned long vaddr, unsigned long paddr)
29{
30 int i, j;
31 struct resource *res;
32 unsigned long vstart, vend;
014da7ff 33
7cfb62a2
IK
34 for (i = 0; i < iowa_bus_count; i++) {
35 struct iowa_bus *bus = &iowa_busses[i];
36 struct pci_controller *phb = bus->phb;
014da7ff 37
7cfb62a2
IK
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;
43 }
44
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;
50 }
014da7ff 51 }
7cfb62a2 52
014da7ff
BH
53 return NULL;
54}
55
7cfb62a2 56struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR addr)
014da7ff 57{
12bc9f6f 58 unsigned hugepage_shift;
7cfb62a2 59 struct iowa_bus *bus;
014da7ff
BH
60 int token;
61
014da7ff
BH
62 token = PCI_GET_ADDR_TOKEN(addr);
63
7cfb62a2
IK
64 if (token && token <= iowa_bus_count)
65 bus = &iowa_busses[token - 1];
014da7ff
BH
66 else {
67 unsigned long vaddr, paddr;
68 pte_t *ptep;
69
014da7ff 70 vaddr = (unsigned long)PCI_FIX_ADDR(addr);
7cfb62a2
IK
71 if (vaddr < PHB_IO_BASE || vaddr >= PHB_IO_END)
72 return NULL;
014da7ff 73
12bc9f6f
AK
74 ptep = find_linux_pte_or_hugepte(init_mm.pgd, vaddr,
75 &hugepage_shift);
014da7ff
BH
76 if (ptep == NULL)
77 paddr = 0;
12bc9f6f
AK
78 else {
79 /*
80 * we don't have hugepages backing iomem
81 */
82 WARN_ON(hugepage_shift);
014da7ff 83 paddr = pte_pfn(*ptep) << PAGE_SHIFT;
12bc9f6f 84 }
7cfb62a2 85 bus = iowa_pci_find(vaddr, paddr);
014da7ff 86
014da7ff 87 if (bus == NULL)
7cfb62a2 88 return NULL;
014da7ff
BH
89 }
90
7cfb62a2 91 return bus;
014da7ff
BH
92}
93
7cfb62a2 94struct iowa_bus *iowa_pio_find_bus(unsigned long port)
014da7ff 95{
7cfb62a2
IK
96 unsigned long vaddr = (unsigned long)pci_io_base + port;
97 return iowa_pci_find(vaddr, 0);
014da7ff
BH
98}
99
014da7ff 100
7cfb62a2
IK
101#define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \
102static ret iowa_##name at \
103{ \
104 struct iowa_bus *bus; \
105 bus = iowa_##space##_find_bus(aa); \
106 if (bus && bus->ops && bus->ops->name) \
107 return bus->ops->name al; \
108 return __do_##name al; \
014da7ff
BH
109}
110
7cfb62a2
IK
111#define DEF_PCI_AC_NORET(name, at, al, space, aa) \
112static void iowa_##name at \
113{ \
114 struct iowa_bus *bus; \
115 bus = iowa_##space##_find_bus(aa); \
116 if (bus && bus->ops && bus->ops->name) { \
117 bus->ops->name al; \
118 return; \
119 } \
120 __do_##name al; \
014da7ff
BH
121}
122
7cfb62a2 123#include <asm/io-defs.h>
014da7ff 124
7cfb62a2
IK
125#undef DEF_PCI_AC_RET
126#undef DEF_PCI_AC_NORET
014da7ff 127
cad5cef6 128static const struct ppc_pci_io iowa_pci_io = {
014da7ff 129
7cfb62a2
IK
130#define DEF_PCI_AC_RET(name, ret, at, al, space, aa) .name = iowa_##name,
131#define DEF_PCI_AC_NORET(name, at, al, space, aa) .name = iowa_##name,
014da7ff 132
7cfb62a2 133#include <asm/io-defs.h>
014da7ff 134
7cfb62a2
IK
135#undef DEF_PCI_AC_RET
136#undef DEF_PCI_AC_NORET
014da7ff 137
7cfb62a2 138};
014da7ff 139
b36ac9e8 140static void __iomem *iowa_ioremap(phys_addr_t addr, unsigned long size,
1cdab55d 141 unsigned long flags, void *caller)
014da7ff 142{
7cfb62a2 143 struct iowa_bus *bus;
1cdab55d 144 void __iomem *res = __ioremap_caller(addr, size, flags, caller);
014da7ff
BH
145 int busno;
146
b36ac9e8 147 bus = iowa_pci_find(0, (unsigned long)addr);
014da7ff 148 if (bus != NULL) {
7cfb62a2 149 busno = bus - iowa_busses;
014da7ff
BH
150 PCI_SET_ADDR_TOKEN(res, busno + 1);
151 }
014da7ff
BH
152 return res;
153}
154
d1109b75 155/* Enable IO workaround */
cad5cef6 156static void io_workaround_init(void)
d1109b75
ME
157{
158 static int io_workaround_inited;
159
160 if (io_workaround_inited)
161 return;
162 ppc_pci_io = iowa_pci_io;
163 ppc_md.ioremap = iowa_ioremap;
164 io_workaround_inited = 1;
165}
166
167/* Register new bus to support workaround */
cad5cef6
GKH
168void iowa_register_bus(struct pci_controller *phb, struct ppc_pci_io *ops,
169 int (*initfunc)(struct iowa_bus *, void *), void *data)
014da7ff 170{
7cfb62a2 171 struct iowa_bus *bus;
44ef3390 172 struct device_node *np = phb->dn;
014da7ff 173
d1109b75
ME
174 io_workaround_init();
175
7cfb62a2
IK
176 if (iowa_bus_count >= IOWA_MAX_BUS) {
177 pr_err("IOWA:Too many pci bridges, "
178 "workarounds disabled for %s\n", np->full_name);
014da7ff
BH
179 return;
180 }
181
7cfb62a2
IK
182 bus = &iowa_busses[iowa_bus_count];
183 bus->phb = phb;
184 bus->ops = ops;
69b12368 185 bus->private = data;
014da7ff 186
7cfb62a2
IK
187 if (initfunc)
188 if ((*initfunc)(bus, data))
189 return;
014da7ff 190
7cfb62a2 191 iowa_bus_count++;
014da7ff 192
7cfb62a2 193 pr_debug("IOWA:[%d]Add bus, %s.\n", iowa_bus_count-1, np->full_name);
014da7ff
BH
194}
195
This page took 0.487033 seconds and 5 git commands to generate.