fdt_addresses.c 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * libfdt - Flat Device Tree manipulation
  3. * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
  4. * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
  5. */
  6. #include <libfdt_env.h>
  7. #ifndef USE_HOSTCC
  8. #include <fdt.h>
  9. #include <libfdt.h>
  10. #else
  11. #include "fdt_host.h"
  12. #endif
  13. #include "libfdt_internal.h"
  14. int fdt_address_cells(const void *fdt, int nodeoffset)
  15. {
  16. const fdt32_t *ac;
  17. int val;
  18. int len;
  19. ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
  20. if (!ac)
  21. return 2;
  22. if (len != sizeof(*ac))
  23. return -FDT_ERR_BADNCELLS;
  24. val = fdt32_to_cpu(*ac);
  25. if ((val <= 0) || (val > FDT_MAX_NCELLS))
  26. return -FDT_ERR_BADNCELLS;
  27. return val;
  28. }
  29. int fdt_size_cells(const void *fdt, int nodeoffset)
  30. {
  31. const fdt32_t *sc;
  32. int val;
  33. int len;
  34. sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
  35. if (!sc)
  36. return 2;
  37. if (len != sizeof(*sc))
  38. return -FDT_ERR_BADNCELLS;
  39. val = fdt32_to_cpu(*sc);
  40. if ((val < 0) || (val > FDT_MAX_NCELLS))
  41. return -FDT_ERR_BADNCELLS;
  42. return val;
  43. }