4 #include <linux/kernel.h>
7 #include <asm/machdep.h>
8 #include <asm/pgtable.h>
9 #include <asm/ppc-pci.h>
11 #include "io-workarounds.h"
13 #define IOWA_MAX_BUS 8
15 static struct iowa_bus iowa_busses
[IOWA_MAX_BUS
];
16 static unsigned int iowa_bus_count
;
18 static struct iowa_bus
*iowa_pci_find(unsigned long vaddr
, unsigned long paddr
)
22 unsigned long vstart
, vend
;
24 for (i
= 0; i
< iowa_bus_count
; i
++) {
25 struct iowa_bus
*bus
= &iowa_busses
[i
];
26 struct pci_controller
*phb
= bus
->phb
;
29 vstart
= (unsigned long)phb
->io_base_virt
;
30 vend
= vstart
+ phb
->pci_io_size
- 1;
31 if ((vaddr
>= vstart
) && (vaddr
<= vend
))
36 for (j
= 0; j
< 3; j
++) {
37 res
= &phb
->mem_resources
[j
];
38 if (paddr
>= res
->start
&& paddr
<= res
->end
)
46 struct iowa_bus
*iowa_mem_find_bus(const PCI_IO_ADDR addr
)
51 token
= PCI_GET_ADDR_TOKEN(addr
);
53 if (token
&& token
<= iowa_bus_count
)
54 bus
= &iowa_busses
[token
- 1];
56 unsigned long vaddr
, paddr
;
59 vaddr
= (unsigned long)PCI_FIX_ADDR(addr
);
60 if (vaddr
< PHB_IO_BASE
|| vaddr
>= PHB_IO_END
)
63 ptep
= find_linux_pte(init_mm
.pgd
, vaddr
);
67 paddr
= pte_pfn(*ptep
) << PAGE_SHIFT
;
68 bus
= iowa_pci_find(vaddr
, paddr
);
77 struct iowa_bus
*iowa_pio_find_bus(unsigned long port
)
79 unsigned long vaddr
= (unsigned long)pci_io_base
+ port
;
80 return iowa_pci_find(vaddr
, 0);
84 #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \
85 static ret iowa_##name at \
87 struct iowa_bus *bus; \
88 bus = iowa_##space##_find_bus(aa); \
89 if (bus && bus->ops && bus->ops->name) \
90 return bus->ops->name al; \
91 return __do_##name al; \
94 #define DEF_PCI_AC_NORET(name, at, al, space, aa) \
95 static void iowa_##name at \
97 struct iowa_bus *bus; \
98 bus = iowa_##space##_find_bus(aa); \
99 if (bus && bus->ops && bus->ops->name) { \
106 #include <asm/io-defs.h>
108 #undef DEF_PCI_AC_RET
109 #undef DEF_PCI_AC_NORET
111 static const struct ppc_pci_io __devinitconst iowa_pci_io
= {
113 #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) .name = iowa_##name,
114 #define DEF_PCI_AC_NORET(name, at, al, space, aa) .name = iowa_##name,
116 #include <asm/io-defs.h>
118 #undef DEF_PCI_AC_RET
119 #undef DEF_PCI_AC_NORET
123 static void __iomem
*iowa_ioremap(phys_addr_t addr
, unsigned long size
,
124 unsigned long flags
, void *caller
)
126 struct iowa_bus
*bus
;
127 void __iomem
*res
= __ioremap_caller(addr
, size
, flags
, caller
);
130 bus
= iowa_pci_find(0, (unsigned long)addr
);
132 busno
= bus
- iowa_busses
;
133 PCI_SET_ADDR_TOKEN(res
, busno
+ 1);
138 void __devinit
iowa_register_bus(struct pci_controller
*phb
,
139 struct ppc_pci_io
*ops
,
140 int (*initfunc
)(struct iowa_bus
*, void *), void *data
)
142 struct iowa_bus
*bus
;
143 struct device_node
*np
= phb
->dn
;
145 if (iowa_bus_count
>= IOWA_MAX_BUS
) {
146 pr_err("IOWA:Too many pci bridges, "
147 "workarounds disabled for %s\n", np
->full_name
);
151 bus
= &iowa_busses
[iowa_bus_count
];
156 if ((*initfunc
)(bus
, data
))
161 pr_debug("IOWA:[%d]Add bus, %s.\n", iowa_bus_count
-1, np
->full_name
);
164 void __devinit
io_workaround_init(void)
166 static int io_workaround_inited
;
168 if (io_workaround_inited
)
170 ppc_pci_io
= iowa_pci_io
;
171 ppc_md
.ioremap
= iowa_ioremap
;
172 io_workaround_inited
= 1;