1 #include <linux/string.h>
2 #include <linux/kernel.h>
6 #include <linux/slab.h>
7 #include <linux/errno.h>
39 static void of_bus_pci_count_cells(
struct device_node *np,
40 int *addrc,
int *sizec)
49 int na,
int ns,
int pna)
55 if ((addr[0] ^ range[0]) & 0x03000000)
63 memcpy(result, range + na, pna * 4);
66 for (i = 0; i < na - 1; i++)
67 result[pna - 1 - i] +=
71 memcpy(addr, result, pna * 4);
76 static unsigned long of_bus_pci_get_flags(
const u32 *addr,
unsigned long flags)
82 switch((w >> 24) & 0x03) {
97 static unsigned long of_bus_sbus_get_flags(
const u32 *addr,
unsigned long flags)
106 static int of_bus_ambapp_match(
struct device_node *np)
112 int *addrc,
int *sizec)
120 static int of_bus_ambapp_map(
u32 *addr,
const u32 *range,
121 int na,
int ns,
int pna)
126 static unsigned long of_bus_ambapp_get_flags(
const u32 *addr,
136 static struct of_bus of_busses[] = {
140 .addr_prop_name =
"assigned-addresses",
141 .match = of_bus_pci_match,
142 .count_cells = of_bus_pci_count_cells,
143 .map = of_bus_pci_map,
144 .get_flags = of_bus_pci_get_flags,
149 .addr_prop_name =
"reg",
153 .get_flags = of_bus_sbus_get_flags,
158 .addr_prop_name =
"reg",
159 .match = of_bus_ambapp_match,
160 .count_cells = of_bus_ambapp_count_cells,
161 .map = of_bus_ambapp_map,
162 .get_flags = of_bus_ambapp_get_flags,
167 .addr_prop_name =
"reg",
180 if (!of_busses[i].
match || of_busses[i].
match(np))
181 return &of_busses[i];
190 int na,
int ns,
int pna)
197 if (ranges ==
NULL || rlen == 0) {
201 memset(result, 0, pna * 4);
202 for (i = 0; i < na; i++)
203 result[pna - 1 - i] =
206 memcpy(addr, result, pna * 4);
212 rone = na + pna +
ns;
213 for (; rlen >= rone; rlen -= rone, ranges += rone) {
214 if (!bus->
map(addr, ranges, na, ns, pna))
242 static int of_resource_verbose;
257 bus = of_match_bus(p_op->
dev.of_node);
261 if (!preg || num_reg == 0)
272 for (index = 0; index < num_reg; index++) {
275 const u32 *
reg = (preg + (index * ((na +
ns) * 4)));
278 struct of_bus *pbus, *dbus;
279 u64 size, result = OF_BAD_ADDR;
284 size = of_read_addr(
reg + na, ns);
290 if (use_1to1_mapping(pp)) {
291 result = of_read_addr(addr, na);
303 result = of_read_addr(addr, dna);
307 pbus = of_match_bus(pp);
310 if (build_one_resource(dp, dbus, pbus, addr,
324 if (of_resource_verbose)
325 printk(
"%s reg[%d] -> %llx\n",
326 op->
dev.of_node->full_name, index,
329 if (result != OF_BAD_ADDR) {
330 r->start = result & 0xffffffff;
331 r->end = result + size - 1;
332 r->flags = flags | ((result >> 32ULL) & 0xffUL);
334 r->name = op->
dev.of_node->name;
349 sd = &op->
dev.archdata;
352 op->
dev.of_node =
dp;
357 for (i = 0; i < op->
archdata.num_irqs; i++)
361 const unsigned int *
irq =
365 op->
archdata.num_irqs = len /
sizeof(
unsigned int);
366 for (i = 0; i < op->
archdata.num_irqs; i++)
374 build_device_resources(op, parent);
376 op->
dev.parent = parent;
384 printk(
"%s: Could not register of device.\n",
405 static int __init scan_of_devices(
void)
410 parent = scan_one_device(root,
NULL);
414 scan_tree(root->
child, &parent->
dev);
425 of_resource_verbose = 1;
429 __setup(
"of_debug=", of_debug);