base.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Procedures for creating, accessing and interpreting the device tree.
  3. *
  4. * Paul Mackerras August 1996.
  5. * Copyright (C) 1996-2005 Paul Mackerras.
  6. *
  7. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  8. * {engebret|bergner}@us.ibm.com
  9. *
  10. * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
  11. *
  12. * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/of.h>
  21. int of_n_addr_cells(struct device_node *np)
  22. {
  23. const int *ip;
  24. do {
  25. if (np->parent)
  26. np = np->parent;
  27. ip = of_get_property(np, "#address-cells", NULL);
  28. if (ip)
  29. return *ip;
  30. } while (np->parent);
  31. /* No #address-cells property for the root node */
  32. return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
  33. }
  34. EXPORT_SYMBOL(of_n_addr_cells);
  35. int of_n_size_cells(struct device_node *np)
  36. {
  37. const int *ip;
  38. do {
  39. if (np->parent)
  40. np = np->parent;
  41. ip = of_get_property(np, "#size-cells", NULL);
  42. if (ip)
  43. return *ip;
  44. } while (np->parent);
  45. /* No #size-cells property for the root node */
  46. return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
  47. }
  48. EXPORT_SYMBOL(of_n_size_cells);
  49. /*
  50. * Find a property with a given name for a given node
  51. * and return the value.
  52. */
  53. const void *of_get_property(const struct device_node *np, const char *name,
  54. int *lenp)
  55. {
  56. struct property *pp = of_find_property(np, name, lenp);
  57. return pp ? pp->value : NULL;
  58. }
  59. EXPORT_SYMBOL(of_get_property);