3 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/pci_regs.h>
6 #include <linux/module.h>
7 #include <linux/ioport.h>
8 #include <linux/etherdevice.h>
10 #include <asm/pci-bridge.h>
13 #define DBG(fmt...) do { printk(fmt); } while(0)
15 #define DBG(fmt...) do { } while(0)
24 /* Max address size we deal with */
25 #define OF_MAX_ADDR_CELLS 4
26 #define OF_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
29 static struct of_bus *of_match_bus(struct device_node *np);
30 static int __of_address_to_resource(struct device_node *dev,
31 const u32 *addrp, u64 size, unsigned int flags,
37 static void of_dump_addr(const char *s, const u32 *addr, int na)
41 printk(" %08x", *(addr++));
45 static void of_dump_addr(const char *s, const u32 *addr, int na) { }
49 /* Callbacks for bus specific translators */
52 const char *addresses;
53 int (*match)(struct device_node *parent);
54 void (*count_cells)(struct device_node *child,
55 int *addrc, int *sizec);
56 u64 (*map)(u32 *addr, const u32 *range,
57 int na, int ns, int pna);
58 int (*translate)(u32 *addr, u64 offset, int na);
59 unsigned int (*get_flags)(const u32 *addr);
64 * Default translator (generic bus)
67 static void of_bus_default_count_cells(struct device_node *dev,
68 int *addrc, int *sizec)
71 *addrc = of_n_addr_cells(dev);
73 *sizec = of_n_size_cells(dev);
76 static u64 of_bus_default_map(u32 *addr, const u32 *range,
77 int na, int ns, int pna)
81 cp = of_read_number(range, na);
82 s = of_read_number(range + na + pna, ns);
83 da = of_read_number(addr, na);
85 DBG("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
88 if (da < cp || da >= (cp + s))
93 static int of_bus_default_translate(u32 *addr, u64 offset, int na)
95 u64 a = of_read_number(addr, na);
96 memset(addr, 0, na * 4);
99 addr[na - 2] = a >> 32;
100 addr[na - 1] = a & 0xffffffffu;
105 static unsigned int of_bus_default_get_flags(const u32 *addr)
107 return IORESOURCE_MEM;
113 * PCI bus specific translator
116 static int of_bus_pci_match(struct device_node *np)
118 /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
119 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
122 static void of_bus_pci_count_cells(struct device_node *np,
123 int *addrc, int *sizec)
131 static unsigned int of_bus_pci_get_flags(const u32 *addr)
133 unsigned int flags = 0;
136 switch((w >> 24) & 0x03) {
138 flags |= IORESOURCE_IO;
140 case 0x02: /* 32 bits */
141 case 0x03: /* 64 bits */
142 flags |= IORESOURCE_MEM;
146 flags |= IORESOURCE_PREFETCH;
150 static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
155 af = of_bus_pci_get_flags(addr);
156 rf = of_bus_pci_get_flags(range);
158 /* Check address type match */
159 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
162 /* Read address values, skipping high cell */
163 cp = of_read_number(range + 1, na - 1);
164 s = of_read_number(range + na + pna, ns);
165 da = of_read_number(addr + 1, na - 1);
167 DBG("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
169 if (da < cp || da >= (cp + s))
174 static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
176 return of_bus_default_translate(addr + 1, offset, na - 1);
179 const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
184 struct device_node *parent;
186 int onesize, i, na, ns;
188 /* Get parent & match bus type */
189 parent = of_get_parent(dev);
192 bus = of_match_bus(parent);
193 if (strcmp(bus->name, "pci")) {
197 bus->count_cells(dev, &na, &ns);
199 if (!OF_CHECK_COUNTS(na, ns))
202 /* Get "reg" or "assigned-addresses" property */
203 prop = of_get_property(dev, bus->addresses, &psize);
209 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
210 if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
212 *size = of_read_number(prop + na, ns);
214 *flags = bus->get_flags(prop);
219 EXPORT_SYMBOL(of_get_pci_address);
221 int of_pci_address_to_resource(struct device_node *dev, int bar,
228 addrp = of_get_pci_address(dev, bar, &size, &flags);
231 return __of_address_to_resource(dev, addrp, size, flags, r);
233 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
235 static u8 of_irq_pci_swizzle(u8 slot, u8 pin)
237 return (((pin - 1) + slot) % 4) + 1;
240 int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
242 struct device_node *dn, *ppnode;
243 struct pci_dev *ppdev;
249 /* Check if we have a device node, if yes, fallback to standard OF
252 dn = pci_device_to_OF_node(pdev);
254 rc = of_irq_map_one(dn, 0, out_irq);
259 /* Ok, we don't, time to have fun. Let's start by building up an
260 * interrupt spec. we assume #interrupt-cells is 1, which is standard
261 * for PCI. If you do different, then don't use that routine.
263 rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin);
270 /* Now we walk up the PCI tree */
273 /* Get the pci_dev of our parent */
274 ppdev = pdev->bus->self;
276 /* Ouch, it's a host bridge... */
279 ppnode = pci_bus_to_OF_node(pdev->bus);
281 struct pci_controller *host;
282 host = pci_bus_to_host(pdev->bus);
283 ppnode = host ? host->dn : NULL;
285 /* No node for host bridge ? give up */
289 /* We found a P2P bridge, check if it has a node */
290 ppnode = pci_device_to_OF_node(ppdev);
292 /* Ok, we have found a parent with a device-node, hand over to
293 * the OF parsing code.
294 * We build a unit address from the linux device to be used for
295 * resolution. Note that we use the linux bus number which may
296 * not match your firmware bus numbering.
297 * Fortunately, in most cases, interrupt-map-mask doesn't include
298 * the bus number as part of the matching.
299 * You should still be careful about that though if you intend
300 * to rely on this function (you ship a firmware that doesn't
301 * create device nodes for all PCI devices).
306 /* We can only get here if we hit a P2P bridge with no node,
307 * let's do standard swizzling and try again
309 lspec = of_irq_pci_swizzle(PCI_SLOT(pdev->devfn), lspec);
313 laddr[0] = (pdev->bus->number << 16)
314 | (pdev->devfn << 8);
315 laddr[1] = laddr[2] = 0;
316 return of_irq_map_raw(ppnode, &lspec, 1, laddr, out_irq);
318 EXPORT_SYMBOL_GPL(of_irq_map_pci);
319 #endif /* CONFIG_PCI */
322 * ISA bus specific translator
325 static int of_bus_isa_match(struct device_node *np)
327 return !strcmp(np->name, "isa");
330 static void of_bus_isa_count_cells(struct device_node *child,
331 int *addrc, int *sizec)
339 static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
343 /* Check address type match */
344 if ((addr[0] ^ range[0]) & 0x00000001)
347 /* Read address values, skipping high cell */
348 cp = of_read_number(range + 1, na - 1);
349 s = of_read_number(range + na + pna, ns);
350 da = of_read_number(addr + 1, na - 1);
352 DBG("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
354 if (da < cp || da >= (cp + s))
359 static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
361 return of_bus_default_translate(addr + 1, offset, na - 1);
364 static unsigned int of_bus_isa_get_flags(const u32 *addr)
366 unsigned int flags = 0;
370 flags |= IORESOURCE_IO;
372 flags |= IORESOURCE_MEM;
378 * Array of bus specific translators
381 static struct of_bus of_busses[] = {
386 .addresses = "assigned-addresses",
387 .match = of_bus_pci_match,
388 .count_cells = of_bus_pci_count_cells,
389 .map = of_bus_pci_map,
390 .translate = of_bus_pci_translate,
391 .get_flags = of_bus_pci_get_flags,
393 #endif /* CONFIG_PCI */
398 .match = of_bus_isa_match,
399 .count_cells = of_bus_isa_count_cells,
400 .map = of_bus_isa_map,
401 .translate = of_bus_isa_translate,
402 .get_flags = of_bus_isa_get_flags,
409 .count_cells = of_bus_default_count_cells,
410 .map = of_bus_default_map,
411 .translate = of_bus_default_translate,
412 .get_flags = of_bus_default_get_flags,
416 static struct of_bus *of_match_bus(struct device_node *np)
420 for (i = 0; i < ARRAY_SIZE(of_busses); i ++)
421 if (!of_busses[i].match || of_busses[i].match(np))
422 return &of_busses[i];
427 static int of_translate_one(struct device_node *parent, struct of_bus *bus,
428 struct of_bus *pbus, u32 *addr,
429 int na, int ns, int pna, const char *rprop)
434 u64 offset = OF_BAD_ADDR;
436 /* Normally, an absence of a "ranges" property means we are
437 * crossing a non-translatable boundary, and thus the addresses
438 * below the current not cannot be converted to CPU physical ones.
439 * Unfortunately, while this is very clear in the spec, it's not
440 * what Apple understood, and they do have things like /uni-n or
441 * /ht nodes with no "ranges" property and a lot of perfectly
442 * useable mapped devices below them. Thus we treat the absence of
443 * "ranges" as equivalent to an empty "ranges" property which means
444 * a 1:1 translation at that level. It's up to the caller not to try
445 * to translate addresses that aren't supposed to be translated in
446 * the first place. --BenH.
448 ranges = of_get_property(parent, rprop, &rlen);
449 if (ranges == NULL || rlen == 0) {
450 offset = of_read_number(addr, na);
451 memset(addr, 0, pna * 4);
452 DBG("OF: no ranges, 1:1 translation\n");
456 DBG("OF: walking ranges...\n");
458 /* Now walk through the ranges */
460 rone = na + pna + ns;
461 for (; rlen >= rone; rlen -= rone, ranges += rone) {
462 offset = bus->map(addr, ranges, na, ns, pna);
463 if (offset != OF_BAD_ADDR)
466 if (offset == OF_BAD_ADDR) {
467 DBG("OF: not found !\n");
470 memcpy(addr, ranges + na, 4 * pna);
473 of_dump_addr("OF: parent translation for:", addr, pna);
474 DBG("OF: with offset: "PRu64"\n", offset);
476 /* Translate it into parent bus space */
477 return pbus->translate(addr, offset, pna);
482 * Translate an address from the device-tree into a CPU physical address,
483 * this walks up the tree and applies the various bus mappings on the
486 * Note: We consider that crossing any level with #size-cells == 0 to mean
487 * that translation is impossible (that is we are not dealing with a value
488 * that can be mapped to a cpu physical address). This is not really specified
489 * that way, but this is traditionally the way IBM at least do things
491 u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
494 struct device_node *parent = NULL;
495 struct of_bus *bus, *pbus;
496 u32 addr[OF_MAX_ADDR_CELLS];
497 int na, ns, pna, pns;
498 u64 result = OF_BAD_ADDR;
500 DBG("OF: ** translation for device %s **\n", dev->full_name);
502 /* Increase refcount at current level */
505 /* Get parent & match bus type */
506 parent = of_get_parent(dev);
509 bus = of_match_bus(parent);
511 /* Cound address cells & copy address locally */
512 bus->count_cells(dev, &na, &ns);
513 if (!OF_CHECK_COUNTS(na, ns)) {
514 printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
518 memcpy(addr, in_addr, na * 4);
520 DBG("OF: bus is %s (na=%d, ns=%d) on %s\n",
521 bus->name, na, ns, parent->full_name);
522 of_dump_addr("OF: translating address:", addr, na);
526 /* Switch to parent bus */
529 parent = of_get_parent(dev);
531 /* If root, we have finished */
532 if (parent == NULL) {
533 DBG("OF: reached root node\n");
534 result = of_read_number(addr, na);
538 /* Get new parent bus and counts */
539 pbus = of_match_bus(parent);
540 pbus->count_cells(dev, &pna, &pns);
541 if (!OF_CHECK_COUNTS(pna, pns)) {
542 printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
547 DBG("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
548 pbus->name, pna, pns, parent->full_name);
550 /* Apply bus translation */
551 if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
554 /* Complete the move up one level */
559 of_dump_addr("OF: one level translation:", addr, na);
568 u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
570 return __of_translate_address(dev, in_addr, "ranges");
572 EXPORT_SYMBOL(of_translate_address);
574 u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
576 return __of_translate_address(dev, in_addr, "dma-ranges");
578 EXPORT_SYMBOL(of_translate_dma_address);
580 const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
585 struct device_node *parent;
587 int onesize, i, na, ns;
589 /* Get parent & match bus type */
590 parent = of_get_parent(dev);
593 bus = of_match_bus(parent);
594 bus->count_cells(dev, &na, &ns);
596 if (!OF_CHECK_COUNTS(na, ns))
599 /* Get "reg" or "assigned-addresses" property */
600 prop = of_get_property(dev, bus->addresses, &psize);
606 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
609 *size = of_read_number(prop + na, ns);
611 *flags = bus->get_flags(prop);
616 EXPORT_SYMBOL(of_get_address);
618 static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
619 u64 size, unsigned int flags,
624 if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
626 taddr = of_translate_address(dev, addrp);
627 if (taddr == OF_BAD_ADDR)
629 memset(r, 0, sizeof(struct resource));
630 if (flags & IORESOURCE_IO) {
632 port = pci_address_to_pio(taddr);
633 if (port == (unsigned long)-1)
636 r->end = port + size - 1;
639 r->end = taddr + size - 1;
646 int of_address_to_resource(struct device_node *dev, int index,
653 addrp = of_get_address(dev, index, &size, &flags);
656 return __of_address_to_resource(dev, addrp, size, flags, r);
658 EXPORT_SYMBOL_GPL(of_address_to_resource);
660 void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
661 unsigned long *busno, unsigned long *phys, unsigned long *size)
663 const u32 *dma_window;
665 const unsigned char *prop;
667 dma_window = dma_window_prop;
669 /* busno is always one cell */
670 *busno = *(dma_window++);
672 prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
674 prop = of_get_property(dn, "#address-cells", NULL);
676 cells = prop ? *(u32 *)prop : of_n_addr_cells(dn);
677 *phys = of_read_number(dma_window, cells);
681 prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
682 cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
683 *size = of_read_number(dma_window, cells);
690 static unsigned int of_irq_workarounds;
691 static struct device_node *of_irq_dflt_pic;
693 static struct device_node *of_irq_find_parent(struct device_node *child)
695 struct device_node *p;
698 if (!of_node_get(child))
702 parp = of_get_property(child, "interrupt-parent", NULL);
704 p = of_get_parent(child);
706 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
707 p = of_node_get(of_irq_dflt_pic);
709 p = of_find_node_by_phandle(*parp);
713 } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
718 /* This doesn't need to be called if you don't have any special workaround
721 void of_irq_map_init(unsigned int flags)
723 of_irq_workarounds = flags;
725 /* OldWorld, don't bother looking at other things */
726 if (flags & OF_IMAP_OLDWORLD_MAC)
729 /* If we don't have phandles, let's try to locate a default interrupt
730 * controller (happens when booting with BootX). We do a first match
731 * here, hopefully, that only ever happens on machines with one
734 if (flags & OF_IMAP_NO_PHANDLE) {
735 struct device_node *np;
737 for(np = NULL; (np = of_find_all_nodes(np)) != NULL;) {
738 if (of_get_property(np, "interrupt-controller", NULL)
741 /* Skip /chosen/interrupt-controller */
742 if (strcmp(np->name, "chosen") == 0)
744 /* It seems like at least one person on this planet wants
745 * to use BootX on a machine with an AppleKiwi controller
746 * which happens to pretend to be an interrupt
749 if (strcmp(np->name, "AppleKiwi") == 0)
751 /* I think we found one ! */
752 of_irq_dflt_pic = np;
759 int of_irq_map_raw(struct device_node *parent, const u32 *intspec, u32 ointsize,
760 const u32 *addr, struct of_irq *out_irq)
762 struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL;
763 const u32 *tmp, *imap, *imask;
764 u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0;
765 int imaplen, match, i;
767 DBG("of_irq_map_raw: par=%s,intspec=[0x%08x 0x%08x...],ointsize=%d\n",
768 parent->full_name, intspec[0], intspec[1], ointsize);
770 ipar = of_node_get(parent);
772 /* First get the #interrupt-cells property of the current cursor
773 * that tells us how to interpret the passed-in intspec. If there
774 * is none, we are nice and just walk up the tree
777 tmp = of_get_property(ipar, "#interrupt-cells", NULL);
783 ipar = of_irq_find_parent(ipar);
787 DBG(" -> no parent found !\n");
791 DBG("of_irq_map_raw: ipar=%s, size=%d\n", ipar->full_name, intsize);
793 if (ointsize != intsize)
796 /* Look for this #address-cells. We have to implement the old linux
797 * trick of looking for the parent here as some device-trees rely on it
799 old = of_node_get(ipar);
801 tmp = of_get_property(old, "#address-cells", NULL);
802 tnode = of_get_parent(old);
805 } while(old && tmp == NULL);
808 addrsize = (tmp == NULL) ? 2 : *tmp;
810 DBG(" -> addrsize=%d\n", addrsize);
812 /* Now start the actual "proper" walk of the interrupt tree */
813 while (ipar != NULL) {
814 /* Now check if cursor is an interrupt-controller and if it is
817 if (of_get_property(ipar, "interrupt-controller", NULL) !=
819 DBG(" -> got it !\n");
820 memcpy(out_irq->specifier, intspec,
821 intsize * sizeof(u32));
822 out_irq->size = intsize;
823 out_irq->controller = ipar;
828 /* Now look for an interrupt-map */
829 imap = of_get_property(ipar, "interrupt-map", &imaplen);
830 /* No interrupt map, check for an interrupt parent */
832 DBG(" -> no map, getting parent\n");
833 newpar = of_irq_find_parent(ipar);
836 imaplen /= sizeof(u32);
838 /* Look for a mask */
839 imask = of_get_property(ipar, "interrupt-map-mask", NULL);
841 /* If we were passed no "reg" property and we attempt to parse
842 * an interrupt-map, then #address-cells must be 0.
845 if (addr == NULL && addrsize != 0) {
846 DBG(" -> no reg passed in when needed !\n");
850 /* Parse interrupt-map */
852 while (imaplen > (addrsize + intsize + 1) && !match) {
853 /* Compare specifiers */
855 for (i = 0; i < addrsize && match; ++i) {
856 u32 mask = imask ? imask[i] : 0xffffffffu;
857 match = ((addr[i] ^ imap[i]) & mask) == 0;
859 for (; i < (addrsize + intsize) && match; ++i) {
860 u32 mask = imask ? imask[i] : 0xffffffffu;
862 ((intspec[i-addrsize] ^ imap[i]) & mask) == 0;
864 imap += addrsize + intsize;
865 imaplen -= addrsize + intsize;
867 DBG(" -> match=%d (imaplen=%d)\n", match, imaplen);
869 /* Get the interrupt parent */
870 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
871 newpar = of_node_get(of_irq_dflt_pic);
873 newpar = of_find_node_by_phandle((phandle)*imap);
877 /* Check if not found */
878 if (newpar == NULL) {
879 DBG(" -> imap parent not found !\n");
883 /* Get #interrupt-cells and #address-cells of new
886 tmp = of_get_property(newpar, "#interrupt-cells", NULL);
888 DBG(" -> parent lacks #interrupt-cells !\n");
892 tmp = of_get_property(newpar, "#address-cells", NULL);
893 newaddrsize = (tmp == NULL) ? 0 : *tmp;
895 DBG(" -> newintsize=%d, newaddrsize=%d\n",
896 newintsize, newaddrsize);
898 /* Check for malformed properties */
899 if (imaplen < (newaddrsize + newintsize))
902 imap += newaddrsize + newintsize;
903 imaplen -= newaddrsize + newintsize;
905 DBG(" -> imaplen=%d\n", imaplen);
911 old = of_node_get(newpar);
912 addrsize = newaddrsize;
913 intsize = newintsize;
914 intspec = imap - intsize;
915 addr = intspec - addrsize;
918 /* Iterate again with new parent */
919 DBG(" -> new parent: %s\n", newpar ? newpar->full_name : "<>");
931 EXPORT_SYMBOL_GPL(of_irq_map_raw);
933 #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
934 static int of_irq_map_oldworld(struct device_node *device, int index,
935 struct of_irq *out_irq)
937 const u32 *ints = NULL;
941 * Old machines just have a list of interrupt numbers
942 * and no interrupt-controller nodes. We also have dodgy
943 * cases where the APPL,interrupts property is completely
944 * missing behind pci-pci bridges and we have to get it
945 * from the parent (the bridge itself, as apple just wired
946 * everything together on these)
949 ints = of_get_property(device, "AAPL,interrupts", &intlen);
952 device = device->parent;
953 if (device && strcmp(device->type, "pci") != 0)
958 intlen /= sizeof(u32);
963 out_irq->controller = NULL;
964 out_irq->specifier[0] = ints[index];
969 #else /* defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) */
970 static int of_irq_map_oldworld(struct device_node *device, int index,
971 struct of_irq *out_irq)
975 #endif /* !(defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)) */
977 int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq)
979 struct device_node *p;
980 const u32 *intspec, *tmp, *addr;
984 DBG("of_irq_map_one: dev=%s, index=%d\n", device->full_name, index);
986 /* OldWorld mac stuff is "special", handle out of line */
987 if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
988 return of_irq_map_oldworld(device, index, out_irq);
990 /* Get the interrupts property */
991 intspec = of_get_property(device, "interrupts", &intlen);
994 intlen /= sizeof(u32);
996 /* Get the reg property (if any) */
997 addr = of_get_property(device, "reg", NULL);
999 /* Look for the interrupt parent. */
1000 p = of_irq_find_parent(device);
1004 /* Get size of interrupt specifier */
1005 tmp = of_get_property(p, "#interrupt-cells", NULL);
1012 DBG(" intsize=%d intlen=%d\n", intsize, intlen);
1015 if ((index + 1) * intsize > intlen)
1018 /* Get new specifier and map it */
1019 res = of_irq_map_raw(p, intspec + index * intsize, intsize,
1024 EXPORT_SYMBOL_GPL(of_irq_map_one);
1027 * Search the device tree for the best MAC address to use. 'mac-address' is
1028 * checked first, because that is supposed to contain to "most recent" MAC
1029 * address. If that isn't set, then 'local-mac-address' is checked next,
1030 * because that is the default address. If that isn't set, then the obsolete
1031 * 'address' is checked, just in case we're using an old device tree.
1033 * Note that the 'address' property is supposed to contain a virtual address of
1034 * the register set, but some DTS files have redefined that property to be the
1037 * All-zero MAC addresses are rejected, because those could be properties that
1038 * exist in the device tree, but were not set by U-Boot. For example, the
1039 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
1040 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
1041 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
1044 const void *of_get_mac_address(struct device_node *np)
1046 struct property *pp;
1048 pp = of_find_property(np, "mac-address", NULL);
1049 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1052 pp = of_find_property(np, "local-mac-address", NULL);
1053 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1056 pp = of_find_property(np, "address", NULL);
1057 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1062 EXPORT_SYMBOL(of_get_mac_address);
1064 int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
1066 int irq = irq_of_parse_and_map(dev, index);
1068 /* Only dereference the resource if both the
1069 * resource and the irq are valid. */
1070 if (r && irq != NO_IRQ) {
1071 r->start = r->end = irq;
1072 r->flags = IORESOURCE_IRQ;
1077 EXPORT_SYMBOL_GPL(of_irq_to_resource);
1079 void __iomem *of_iomap(struct device_node *np, int index)
1081 struct resource res;
1083 if (of_address_to_resource(np, index, &res))
1086 return ioremap(res.start, 1 + res.end - res.start);
1088 EXPORT_SYMBOL(of_iomap);