prom_parse.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. #undef DEBUG
  2. #include <linux/kernel.h>
  3. #include <linux/string.h>
  4. #include <linux/pci_regs.h>
  5. #include <linux/module.h>
  6. #include <linux/ioport.h>
  7. #include <linux/etherdevice.h>
  8. #include <asm/prom.h>
  9. #include <asm/pci-bridge.h>
  10. #define PRu64 "%llx"
  11. /* Max address size we deal with */
  12. #define OF_MAX_ADDR_CELLS 4
  13. #define OF_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
  14. (ns) > 0)
  15. static struct of_bus *of_match_bus(struct device_node *np);
  16. static int __of_address_to_resource(struct device_node *dev,
  17. const u32 *addrp, u64 size, unsigned int flags,
  18. struct resource *r);
  19. /* Debug utility */
  20. #ifdef DEBUG
  21. static void of_dump_addr(const char *s, const u32 *addr, int na)
  22. {
  23. printk(KERN_INFO "%s", s);
  24. while (na--)
  25. printk(KERN_INFO " %08x", *(addr++));
  26. printk(KERN_INFO "\n");
  27. }
  28. #else
  29. static void of_dump_addr(const char *s, const u32 *addr, int na) { }
  30. #endif
  31. /* Callbacks for bus specific translators */
  32. struct of_bus {
  33. const char *name;
  34. const char *addresses;
  35. int (*match)(struct device_node *parent);
  36. void (*count_cells)(struct device_node *child,
  37. int *addrc, int *sizec);
  38. u64 (*map)(u32 *addr, const u32 *range,
  39. int na, int ns, int pna);
  40. int (*translate)(u32 *addr, u64 offset, int na);
  41. unsigned int (*get_flags)(const u32 *addr);
  42. };
  43. /*
  44. * Default translator (generic bus)
  45. */
  46. static void of_bus_default_count_cells(struct device_node *dev,
  47. int *addrc, int *sizec)
  48. {
  49. if (addrc)
  50. *addrc = of_n_addr_cells(dev);
  51. if (sizec)
  52. *sizec = of_n_size_cells(dev);
  53. }
  54. static u64 of_bus_default_map(u32 *addr, const u32 *range,
  55. int na, int ns, int pna)
  56. {
  57. u64 cp, s, da;
  58. cp = of_read_number(range, na);
  59. s = of_read_number(range + na + pna, ns);
  60. da = of_read_number(addr, na);
  61. pr_debug("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
  62. cp, s, da);
  63. if (da < cp || da >= (cp + s))
  64. return OF_BAD_ADDR;
  65. return da - cp;
  66. }
  67. static int of_bus_default_translate(u32 *addr, u64 offset, int na)
  68. {
  69. u64 a = of_read_number(addr, na);
  70. memset(addr, 0, na * 4);
  71. a += offset;
  72. if (na > 1)
  73. addr[na - 2] = a >> 32;
  74. addr[na - 1] = a & 0xffffffffu;
  75. return 0;
  76. }
  77. static unsigned int of_bus_default_get_flags(const u32 *addr)
  78. {
  79. return IORESOURCE_MEM;
  80. }
  81. #ifdef CONFIG_PCI
  82. /*
  83. * PCI bus specific translator
  84. */
  85. static int of_bus_pci_match(struct device_node *np)
  86. {
  87. /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
  88. return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
  89. }
  90. static void of_bus_pci_count_cells(struct device_node *np,
  91. int *addrc, int *sizec)
  92. {
  93. if (addrc)
  94. *addrc = 3;
  95. if (sizec)
  96. *sizec = 2;
  97. }
  98. static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
  99. {
  100. u64 cp, s, da;
  101. /* Check address type match */
  102. if ((addr[0] ^ range[0]) & 0x03000000)
  103. return OF_BAD_ADDR;
  104. /* Read address values, skipping high cell */
  105. cp = of_read_number(range + 1, na - 1);
  106. s = of_read_number(range + na + pna, ns);
  107. da = of_read_number(addr + 1, na - 1);
  108. pr_debug("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
  109. if (da < cp || da >= (cp + s))
  110. return OF_BAD_ADDR;
  111. return da - cp;
  112. }
  113. static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
  114. {
  115. return of_bus_default_translate(addr + 1, offset, na - 1);
  116. }
  117. static unsigned int of_bus_pci_get_flags(const u32 *addr)
  118. {
  119. unsigned int flags = 0;
  120. u32 w = addr[0];
  121. switch ((w >> 24) & 0x03) {
  122. case 0x01:
  123. flags |= IORESOURCE_IO;
  124. break;
  125. case 0x02: /* 32 bits */
  126. case 0x03: /* 64 bits */
  127. flags |= IORESOURCE_MEM;
  128. break;
  129. }
  130. if (w & 0x40000000)
  131. flags |= IORESOURCE_PREFETCH;
  132. return flags;
  133. }
  134. const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
  135. unsigned int *flags)
  136. {
  137. const u32 *prop;
  138. unsigned int psize;
  139. struct device_node *parent;
  140. struct of_bus *bus;
  141. int onesize, i, na, ns;
  142. /* Get parent & match bus type */
  143. parent = of_get_parent(dev);
  144. if (parent == NULL)
  145. return NULL;
  146. bus = of_match_bus(parent);
  147. if (strcmp(bus->name, "pci")) {
  148. of_node_put(parent);
  149. return NULL;
  150. }
  151. bus->count_cells(dev, &na, &ns);
  152. of_node_put(parent);
  153. if (!OF_CHECK_COUNTS(na, ns))
  154. return NULL;
  155. /* Get "reg" or "assigned-addresses" property */
  156. prop = of_get_property(dev, bus->addresses, &psize);
  157. if (prop == NULL)
  158. return NULL;
  159. psize /= 4;
  160. onesize = na + ns;
  161. for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
  162. if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
  163. if (size)
  164. *size = of_read_number(prop + na, ns);
  165. if (flags)
  166. *flags = bus->get_flags(prop);
  167. return prop;
  168. }
  169. return NULL;
  170. }
  171. EXPORT_SYMBOL(of_get_pci_address);
  172. int of_pci_address_to_resource(struct device_node *dev, int bar,
  173. struct resource *r)
  174. {
  175. const u32 *addrp;
  176. u64 size;
  177. unsigned int flags;
  178. addrp = of_get_pci_address(dev, bar, &size, &flags);
  179. if (addrp == NULL)
  180. return -EINVAL;
  181. return __of_address_to_resource(dev, addrp, size, flags, r);
  182. }
  183. EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
  184. static u8 of_irq_pci_swizzle(u8 slot, u8 pin)
  185. {
  186. return (((pin - 1) + slot) % 4) + 1;
  187. }
  188. int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq)
  189. {
  190. struct device_node *dn, *ppnode;
  191. struct pci_dev *ppdev;
  192. u32 lspec;
  193. u32 laddr[3];
  194. u8 pin;
  195. int rc;
  196. /* Check if we have a device node, if yes, fallback to standard OF
  197. * parsing
  198. */
  199. dn = pci_device_to_OF_node(pdev);
  200. if (dn)
  201. return of_irq_map_one(dn, 0, out_irq);
  202. /* Ok, we don't, time to have fun. Let's start by building up an
  203. * interrupt spec. we assume #interrupt-cells is 1, which is standard
  204. * for PCI. If you do different, then don't use that routine.
  205. */
  206. rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin);
  207. if (rc != 0)
  208. return rc;
  209. /* No pin, exit */
  210. if (pin == 0)
  211. return -ENODEV;
  212. /* Now we walk up the PCI tree */
  213. lspec = pin;
  214. for (;;) {
  215. /* Get the pci_dev of our parent */
  216. ppdev = pdev->bus->self;
  217. /* Ouch, it's a host bridge... */
  218. if (ppdev == NULL) {
  219. struct pci_controller *host;
  220. host = pci_bus_to_host(pdev->bus);
  221. ppnode = host ? host->dn : NULL;
  222. /* No node for host bridge ? give up */
  223. if (ppnode == NULL)
  224. return -EINVAL;
  225. } else
  226. /* We found a P2P bridge, check if it has a node */
  227. ppnode = pci_device_to_OF_node(ppdev);
  228. /* Ok, we have found a parent with a device-node, hand over to
  229. * the OF parsing code.
  230. * We build a unit address from the linux device to be used for
  231. * resolution. Note that we use the linux bus number which may
  232. * not match your firmware bus numbering.
  233. * Fortunately, in most cases, interrupt-map-mask doesn't
  234. * include the bus number as part of the matching.
  235. * You should still be careful about that though if you intend
  236. * to rely on this function (you ship a firmware that doesn't
  237. * create device nodes for all PCI devices).
  238. */
  239. if (ppnode)
  240. break;
  241. /* We can only get here if we hit a P2P bridge with no node,
  242. * let's do standard swizzling and try again
  243. */
  244. lspec = of_irq_pci_swizzle(PCI_SLOT(pdev->devfn), lspec);
  245. pdev = ppdev;
  246. }
  247. laddr[0] = (pdev->bus->number << 16)
  248. | (pdev->devfn << 8);
  249. laddr[1] = laddr[2] = 0;
  250. return of_irq_map_raw(ppnode, &lspec, 1, laddr, out_irq);
  251. }
  252. EXPORT_SYMBOL_GPL(of_irq_map_pci);
  253. #endif /* CONFIG_PCI */
  254. /*
  255. * ISA bus specific translator
  256. */
  257. static int of_bus_isa_match(struct device_node *np)
  258. {
  259. return !strcmp(np->name, "isa");
  260. }
  261. static void of_bus_isa_count_cells(struct device_node *child,
  262. int *addrc, int *sizec)
  263. {
  264. if (addrc)
  265. *addrc = 2;
  266. if (sizec)
  267. *sizec = 1;
  268. }
  269. static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
  270. {
  271. u64 cp, s, da;
  272. /* Check address type match */
  273. if ((addr[0] ^ range[0]) & 0x00000001)
  274. return OF_BAD_ADDR;
  275. /* Read address values, skipping high cell */
  276. cp = of_read_number(range + 1, na - 1);
  277. s = of_read_number(range + na + pna, ns);
  278. da = of_read_number(addr + 1, na - 1);
  279. pr_debug("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da);
  280. if (da < cp || da >= (cp + s))
  281. return OF_BAD_ADDR;
  282. return da - cp;
  283. }
  284. static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
  285. {
  286. return of_bus_default_translate(addr + 1, offset, na - 1);
  287. }
  288. static unsigned int of_bus_isa_get_flags(const u32 *addr)
  289. {
  290. unsigned int flags = 0;
  291. u32 w = addr[0];
  292. if (w & 1)
  293. flags |= IORESOURCE_IO;
  294. else
  295. flags |= IORESOURCE_MEM;
  296. return flags;
  297. }
  298. /*
  299. * Array of bus specific translators
  300. */
  301. static struct of_bus of_busses[] = {
  302. #ifdef CONFIG_PCI
  303. /* PCI */
  304. {
  305. .name = "pci",
  306. .addresses = "assigned-addresses",
  307. .match = of_bus_pci_match,
  308. .count_cells = of_bus_pci_count_cells,
  309. .map = of_bus_pci_map,
  310. .translate = of_bus_pci_translate,
  311. .get_flags = of_bus_pci_get_flags,
  312. },
  313. #endif /* CONFIG_PCI */
  314. /* ISA */
  315. {
  316. .name = "isa",
  317. .addresses = "reg",
  318. .match = of_bus_isa_match,
  319. .count_cells = of_bus_isa_count_cells,
  320. .map = of_bus_isa_map,
  321. .translate = of_bus_isa_translate,
  322. .get_flags = of_bus_isa_get_flags,
  323. },
  324. /* Default */
  325. {
  326. .name = "default",
  327. .addresses = "reg",
  328. .match = NULL,
  329. .count_cells = of_bus_default_count_cells,
  330. .map = of_bus_default_map,
  331. .translate = of_bus_default_translate,
  332. .get_flags = of_bus_default_get_flags,
  333. },
  334. };
  335. static struct of_bus *of_match_bus(struct device_node *np)
  336. {
  337. int i;
  338. for (i = 0; i < ARRAY_SIZE(of_busses); i++)
  339. if (!of_busses[i].match || of_busses[i].match(np))
  340. return &of_busses[i];
  341. BUG();
  342. return NULL;
  343. }
  344. static int of_translate_one(struct device_node *parent, struct of_bus *bus,
  345. struct of_bus *pbus, u32 *addr,
  346. int na, int ns, int pna)
  347. {
  348. const u32 *ranges;
  349. unsigned int rlen;
  350. int rone;
  351. u64 offset = OF_BAD_ADDR;
  352. /* Normally, an absence of a "ranges" property means we are
  353. * crossing a non-translatable boundary, and thus the addresses
  354. * below the current not cannot be converted to CPU physical ones.
  355. * Unfortunately, while this is very clear in the spec, it's not
  356. * what Apple understood, and they do have things like /uni-n or
  357. * /ht nodes with no "ranges" property and a lot of perfectly
  358. * useable mapped devices below them. Thus we treat the absence of
  359. * "ranges" as equivalent to an empty "ranges" property which means
  360. * a 1:1 translation at that level. It's up to the caller not to try
  361. * to translate addresses that aren't supposed to be translated in
  362. * the first place. --BenH.
  363. */
  364. ranges = of_get_property(parent, "ranges", (int *) &rlen);
  365. if (ranges == NULL || rlen == 0) {
  366. offset = of_read_number(addr, na);
  367. memset(addr, 0, pna * 4);
  368. pr_debug("OF: no ranges, 1:1 translation\n");
  369. goto finish;
  370. }
  371. pr_debug("OF: walking ranges...\n");
  372. /* Now walk through the ranges */
  373. rlen /= 4;
  374. rone = na + pna + ns;
  375. for (; rlen >= rone; rlen -= rone, ranges += rone) {
  376. offset = bus->map(addr, ranges, na, ns, pna);
  377. if (offset != OF_BAD_ADDR)
  378. break;
  379. }
  380. if (offset == OF_BAD_ADDR) {
  381. pr_debug("OF: not found !\n");
  382. return 1;
  383. }
  384. memcpy(addr, ranges + na, 4 * pna);
  385. finish:
  386. of_dump_addr("OF: parent translation for:", addr, pna);
  387. pr_debug("OF: with offset: "PRu64"\n", offset);
  388. /* Translate it into parent bus space */
  389. return pbus->translate(addr, offset, pna);
  390. }
  391. /*
  392. * Translate an address from the device-tree into a CPU physical address,
  393. * this walks up the tree and applies the various bus mappings on the
  394. * way.
  395. *
  396. * Note: We consider that crossing any level with #size-cells == 0 to mean
  397. * that translation is impossible (that is we are not dealing with a value
  398. * that can be mapped to a cpu physical address). This is not really specified
  399. * that way, but this is traditionally the way IBM at least do things
  400. */
  401. u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
  402. {
  403. struct device_node *parent = NULL;
  404. struct of_bus *bus, *pbus;
  405. u32 addr[OF_MAX_ADDR_CELLS];
  406. int na, ns, pna, pns;
  407. u64 result = OF_BAD_ADDR;
  408. pr_debug("OF: ** translation for device %s **\n", dev->full_name);
  409. /* Increase refcount at current level */
  410. of_node_get(dev);
  411. /* Get parent & match bus type */
  412. parent = of_get_parent(dev);
  413. if (parent == NULL)
  414. goto bail;
  415. bus = of_match_bus(parent);
  416. /* Cound address cells & copy address locally */
  417. bus->count_cells(dev, &na, &ns);
  418. if (!OF_CHECK_COUNTS(na, ns)) {
  419. printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
  420. dev->full_name);
  421. goto bail;
  422. }
  423. memcpy(addr, in_addr, na * 4);
  424. pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
  425. bus->name, na, ns, parent->full_name);
  426. of_dump_addr("OF: translating address:", addr, na);
  427. /* Translate */
  428. for (;;) {
  429. /* Switch to parent bus */
  430. of_node_put(dev);
  431. dev = parent;
  432. parent = of_get_parent(dev);
  433. /* If root, we have finished */
  434. if (parent == NULL) {
  435. pr_debug("OF: reached root node\n");
  436. result = of_read_number(addr, na);
  437. break;
  438. }
  439. /* Get new parent bus and counts */
  440. pbus = of_match_bus(parent);
  441. pbus->count_cells(dev, &pna, &pns);
  442. if (!OF_CHECK_COUNTS(pna, pns)) {
  443. printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
  444. dev->full_name);
  445. break;
  446. }
  447. pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
  448. pbus->name, pna, pns, parent->full_name);
  449. /* Apply bus translation */
  450. if (of_translate_one(dev, bus, pbus, addr, na, ns, pna))
  451. break;
  452. /* Complete the move up one level */
  453. na = pna;
  454. ns = pns;
  455. bus = pbus;
  456. of_dump_addr("OF: one level translation:", addr, na);
  457. }
  458. bail:
  459. of_node_put(parent);
  460. of_node_put(dev);
  461. return result;
  462. }
  463. EXPORT_SYMBOL(of_translate_address);
  464. const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
  465. unsigned int *flags)
  466. {
  467. const u32 *prop;
  468. unsigned int psize;
  469. struct device_node *parent;
  470. struct of_bus *bus;
  471. int onesize, i, na, ns;
  472. /* Get parent & match bus type */
  473. parent = of_get_parent(dev);
  474. if (parent == NULL)
  475. return NULL;
  476. bus = of_match_bus(parent);
  477. bus->count_cells(dev, &na, &ns);
  478. of_node_put(parent);
  479. if (!OF_CHECK_COUNTS(na, ns))
  480. return NULL;
  481. /* Get "reg" or "assigned-addresses" property */
  482. prop = of_get_property(dev, bus->addresses, (int *) &psize);
  483. if (prop == NULL)
  484. return NULL;
  485. psize /= 4;
  486. onesize = na + ns;
  487. for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
  488. if (i == index) {
  489. if (size)
  490. *size = of_read_number(prop + na, ns);
  491. if (flags)
  492. *flags = bus->get_flags(prop);
  493. return prop;
  494. }
  495. return NULL;
  496. }
  497. EXPORT_SYMBOL(of_get_address);
  498. static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
  499. u64 size, unsigned int flags,
  500. struct resource *r)
  501. {
  502. u64 taddr;
  503. if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
  504. return -EINVAL;
  505. taddr = of_translate_address(dev, addrp);
  506. if (taddr == OF_BAD_ADDR)
  507. return -EINVAL;
  508. memset(r, 0, sizeof(struct resource));
  509. if (flags & IORESOURCE_IO) {
  510. unsigned long port;
  511. port = -1; /* pci_address_to_pio(taddr); */
  512. if (port == (unsigned long)-1)
  513. return -EINVAL;
  514. r->start = port;
  515. r->end = port + size - 1;
  516. } else {
  517. r->start = taddr;
  518. r->end = taddr + size - 1;
  519. }
  520. r->flags = flags;
  521. r->name = dev->name;
  522. return 0;
  523. }
  524. int of_address_to_resource(struct device_node *dev, int index,
  525. struct resource *r)
  526. {
  527. const u32 *addrp;
  528. u64 size;
  529. unsigned int flags;
  530. addrp = of_get_address(dev, index, &size, &flags);
  531. if (addrp == NULL)
  532. return -EINVAL;
  533. return __of_address_to_resource(dev, addrp, size, flags, r);
  534. }
  535. EXPORT_SYMBOL_GPL(of_address_to_resource);
  536. void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
  537. unsigned long *busno, unsigned long *phys, unsigned long *size)
  538. {
  539. const u32 *dma_window;
  540. u32 cells;
  541. const unsigned char *prop;
  542. dma_window = dma_window_prop;
  543. /* busno is always one cell */
  544. *busno = *(dma_window++);
  545. prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
  546. if (!prop)
  547. prop = of_get_property(dn, "#address-cells", NULL);
  548. cells = prop ? *(u32 *)prop : of_n_addr_cells(dn);
  549. *phys = of_read_number(dma_window, cells);
  550. dma_window += cells;
  551. prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
  552. cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
  553. *size = of_read_number(dma_window, cells);
  554. }
  555. /**
  556. * Search the device tree for the best MAC address to use. 'mac-address' is
  557. * checked first, because that is supposed to contain to "most recent" MAC
  558. * address. If that isn't set, then 'local-mac-address' is checked next,
  559. * because that is the default address. If that isn't set, then the obsolete
  560. * 'address' is checked, just in case we're using an old device tree.
  561. *
  562. * Note that the 'address' property is supposed to contain a virtual address of
  563. * the register set, but some DTS files have redefined that property to be the
  564. * MAC address.
  565. *
  566. * All-zero MAC addresses are rejected, because those could be properties that
  567. * exist in the device tree, but were not set by U-Boot. For example, the
  568. * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
  569. * addresses. Some older U-Boots only initialized 'local-mac-address'. In
  570. * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
  571. * but is all zeros.
  572. */
  573. const void *of_get_mac_address(struct device_node *np)
  574. {
  575. struct property *pp;
  576. pp = of_find_property(np, "mac-address", NULL);
  577. if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
  578. return pp->value;
  579. pp = of_find_property(np, "local-mac-address", NULL);
  580. if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
  581. return pp->value;
  582. pp = of_find_property(np, "address", NULL);
  583. if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
  584. return pp->value;
  585. return NULL;
  586. }
  587. EXPORT_SYMBOL(of_get_mac_address);