1 #include <linux/string.h>
2 #include <linux/kernel.h>
5 #include <linux/export.h>
7 #include <linux/slab.h>
8 #include <linux/errno.h>
50 if (model && !
strcmp(model,
"SUNW,simba"))
68 static int of_bus_simba_match(
struct device_node *np)
72 if (model && !
strcmp(model,
"SUNW,simba"))
87 int na,
int ns,
int pna)
92 static void of_bus_pci_count_cells(
struct device_node *np,
93 int *addrc,
int *sizec)
102 int na,
int ns,
int pna)
108 if (!((addr[0] ^ range[0]) & 0x03000000))
114 if ((addr[0] & 0x03000000) == 0x03000000 &&
115 (range[0] & 0x03000000) == 0x02000000)
126 memcpy(result, range + na, pna * 4);
129 for (i = 0; i < na - 1; i++)
130 result[pna - 1 - i] +=
134 memcpy(addr, result, pna * 4);
139 static unsigned long of_bus_pci_get_flags(
const u32 *addr,
unsigned long flags)
145 switch((w >> 24) & 0x03) {
169 static int of_bus_fhc_match(
struct device_node *np)
175 #define of_bus_fhc_count_cells of_bus_sbus_count_cells
181 static struct of_bus of_busses[] = {
185 .addr_prop_name =
"assigned-addresses",
186 .match = of_bus_pci_match,
187 .count_cells = of_bus_pci_count_cells,
188 .map = of_bus_pci_map,
189 .get_flags = of_bus_pci_get_flags,
194 .addr_prop_name =
"assigned-addresses",
195 .match = of_bus_simba_match,
196 .count_cells = of_bus_pci_count_cells,
197 .map = of_bus_simba_map,
198 .get_flags = of_bus_pci_get_flags,
203 .addr_prop_name =
"reg",
212 .addr_prop_name =
"reg",
213 .match = of_bus_fhc_match,
221 .addr_prop_name =
"reg",
234 if (!of_busses[i].
match || of_busses[i].
match(np))
235 return &of_busses[i];
244 int na,
int ns,
int pna)
250 if (ranges ==
NULL || rlen == 0) {
254 memset(result, 0, pna * 4);
255 for (i = 0; i < na; i++)
256 result[pna - 1 - i] =
259 memcpy(addr, result, pna * 4);
265 rone = na + pna +
ns;
266 for (; rlen >= rone; rlen -= rone, ranges += rone) {
267 if (!bus->
map(addr, ranges, na, ns, pna))
275 (addr[0] & 0x03000000) == 0x01000000)
312 static int of_resource_verbose;
327 bus = of_match_bus(p_op->
dev.of_node);
331 if (!preg || num_reg == 0)
350 for (index = 0; index < num_reg; index++) {
353 const u32 *
reg = (preg + (index * ((na +
ns) * 4)));
356 struct of_bus *pbus, *dbus;
357 u64 size, result = OF_BAD_ADDR;
362 size = of_read_addr(
reg + na, ns);
367 if (use_1to1_mapping(pp)) {
368 result = of_read_addr(addr, na);
380 result = of_read_addr(addr, dna);
384 pbus = of_match_bus(pp);
387 if (build_one_resource(dp, dbus, pbus, addr,
401 if (of_resource_verbose)
402 printk(
"%s reg[%d] -> %llx\n",
403 op->
dev.of_node->full_name, index,
406 if (result != OF_BAD_ADDR) {
408 result &= 0x0fffffffffffffff
UL;
411 r->end = result + size - 1;
414 r->name = op->
dev.of_node->name;
420 const u32 *imap,
int imlen,
const u32 *imask,
424 unsigned int irq = *irq_p;
430 bus = of_match_bus(pp);
434 if (!reg || !num_reg)
437 imlen /= ((na + 3) * 4);
439 for (i = 0; i < imlen; i++) {
442 for (j = 0; j < na; j++) {
443 if ((reg[j] & imask[j]) != imap[
j])
446 if (imap[na] == irq) {
447 handle = imap[na + 1];
485 if (irq < 1 || irq > 4)
492 bus = (regs->
phys_hi >> 16) & 0xff;
493 devfn = (regs->
phys_hi >> 8) & 0xff;
494 slot = (devfn >> 3) & 0x1f;
511 slot = (slot - 1) << 2;
515 slot = (slot - 2) << 2;
519 ret = (bus | slot | irq);
524 ret = ((irq - 1 + (slot & 3)) & 3) + 1;
530 static int of_irq_verbose;
538 unsigned int orig_irq = irq;
541 if (irq == 0xffffffff)
545 irq = dp->irq_trans->irq_build(dp, irq,
546 dp->irq_trans->
data);
549 printk(
"%s: direct translate %x --> %x\n",
566 const void *imap, *imsk;
573 int this_orig_irq = irq;
575 iret = apply_interrupt_map(dp, pp,
580 printk(
"%s: Apply [%s:%x] imap --> [%s:%x]\n",
581 op->
dev.of_node->full_name,
583 of_node_full_name(iret), irq);
588 if (iret->irq_trans) {
594 unsigned int this_orig_irq = irq;
596 irq = pci_irq_swizzle(dp, pp, irq);
598 printk(
"%s: PCI swizzle [%s] "
600 op->
dev.of_node->full_name,
617 irq = ip->irq_trans->irq_build(op->
dev.of_node, irq,
618 ip->irq_trans->
data);
620 printk(
"%s: Apply IRQ trans [%s] %x --> %x\n",
621 op->
dev.of_node->full_name, ip->
full_name, orig_irq, irq);
629 irq_set_affinity(irq, &numa_mask);
639 const unsigned int *irq;
646 sd = &op->
dev.archdata;
649 op->
dev.of_node =
dp;
667 build_device_resources(op, parent);
668 for (i = 0; i < op->
archdata.num_irqs; i++)
669 op->
archdata.irqs[i] = build_one_device_irq(op, parent, op->
archdata.irqs[i]);
671 op->
dev.parent = parent;
679 printk(
"%s: Could not register of device.\n",
700 static int __init scan_of_devices(
void)
705 parent = scan_one_device(root,
NULL);
709 scan_tree(root->
child, &parent->
dev);
720 of_resource_verbose = 1;
726 __setup(
"of_debug=", of_debug);