fdtdec.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * See file CREDITS for list of people who contributed to this
  4. * project.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. /*
  22. * This file contains convenience functions for decoding useful and
  23. * enlightening information from FDTs. It is intended to be used by device
  24. * drivers and board-specific code within U-Boot. It aims to reduce the
  25. * amount of FDT munging required within U-Boot itself, so that driver code
  26. * changes to support FDT are minimized.
  27. */
  28. #include <libfdt.h>
  29. /*
  30. * A typedef for a physical address. Note that fdt data is always big
  31. * endian even on a litle endian machine.
  32. */
  33. #ifdef CONFIG_PHYS_64BIT
  34. typedef u64 fdt_addr_t;
  35. #define FDT_ADDR_T_NONE (-1ULL)
  36. #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
  37. #else
  38. typedef u32 fdt_addr_t;
  39. #define FDT_ADDR_T_NONE (-1U)
  40. #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
  41. #endif
  42. /* Information obtained about memory from the FDT */
  43. struct fdt_memory {
  44. fdt_addr_t start;
  45. fdt_addr_t end;
  46. };
  47. /**
  48. * Compat types that we know about and for which we might have drivers.
  49. * Each is named COMPAT_<dir>_<filename> where <dir> is the directory
  50. * within drivers.
  51. */
  52. enum fdt_compat_id {
  53. COMPAT_UNKNOWN,
  54. COMPAT_COUNT,
  55. };
  56. /**
  57. * Find the next numbered alias for a peripheral. This is used to enumerate
  58. * all the peripherals of a certain type.
  59. *
  60. * Do the first call with *upto = 0. Assuming /aliases/<name>0 exists then
  61. * this function will return a pointer to the node the alias points to, and
  62. * then update *upto to 1. Next time you call this function, the next node
  63. * will be returned.
  64. *
  65. * All nodes returned will match the compatible ID, as it is assumed that
  66. * all peripherals use the same driver.
  67. *
  68. * @param blob FDT blob to use
  69. * @param name Root name of alias to search for
  70. * @param id Compatible ID to look for
  71. * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
  72. */
  73. int fdtdec_next_alias(const void *blob, const char *name,
  74. enum fdt_compat_id id, int *upto);
  75. /**
  76. * Look up an address property in a node and return it as an address.
  77. * The property must hold either one address with no trailing data or
  78. * one address with a length. This is only tested on 32-bit machines.
  79. *
  80. * @param blob FDT blob
  81. * @param node node to examine
  82. * @param prop_name name of property to find
  83. * @return address, if found, or FDT_ADDR_T_NONE if not
  84. */
  85. fdt_addr_t fdtdec_get_addr(const void *blob, int node,
  86. const char *prop_name);
  87. /**
  88. * Look up a 32-bit integer property in a node and return it. The property
  89. * must have at least 4 bytes of data. The value of the first cell is
  90. * returned.
  91. *
  92. * @param blob FDT blob
  93. * @param node node to examine
  94. * @param prop_name name of property to find
  95. * @param default_val default value to return if the property is not found
  96. * @return integer value, if found, or default_val if not
  97. */
  98. s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
  99. s32 default_val);
  100. /**
  101. * Checks whether a node is enabled.
  102. * This looks for a 'status' property. If this exists, then returns 1 if
  103. * the status is 'ok' and 0 otherwise. If there is no status property,
  104. * it returns the default value.
  105. *
  106. * @param blob FDT blob
  107. * @param node node to examine
  108. * @param default_val default value to return if no 'status' property exists
  109. * @return integer value 0/1, if found, or default_val if not
  110. */
  111. int fdtdec_get_is_enabled(const void *blob, int node, int default_val);
  112. /**
  113. * Checks whether we have a valid fdt available to control U-Boot, and panic
  114. * if not.
  115. */
  116. int fdtdec_check_fdt(void);