ofw_raw.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-08-25 GuEe-GUI first version
  9. */
  10. #ifndef __OFW_RAW_H__
  11. #define __OFW_RAW_H__
  12. #include <libfdt/libfdt.h>
  13. #define FDT_SIZE_KB 1024
  14. #define FDT_SIZE_MB (1024 * FDT_SIZE_KB)
  15. #define FDT_SIZE_MAX (2 * FDT_SIZE_MB)
  16. #define FDT_PADDING_SIZE (1 * FDT_SIZE_KB)
  17. typedef uint8_t fdt8_t;
  18. static inline uint8_t fdt8_to_cpu(fdt8_t x)
  19. {
  20. return (uint8_t)x;
  21. }
  22. int fdt_add_subnode_possible(void *fdt, int parentoffset, const char *name);
  23. int fdt_add_mem_rsv_possible(void *fdt, size_t addr, size_t size);
  24. #define fdt_setprop_cstring(fdt, nodeoffset, name, str) \
  25. fdt_setprop((fdt), (nodeoffset), (name), (str), sizeof(str))
  26. #define fdt_prop_cells_ops(ops, fdt, nodeoffset, prop, ...) \
  27. ({ \
  28. int ret = 0; \
  29. uint32_t tmp[] = { __VA_ARGS__ }; \
  30. for (int i = 0; i < sizeof(tmp) / sizeof(tmp[0]); ++i) \
  31. { \
  32. tmp[i] = cpu_to_fdt32(tmp[i]); \
  33. } \
  34. ret += ops(fdt, nodeoffset, prop, tmp, sizeof(tmp)); \
  35. ret; \
  36. })
  37. #define fdt_setprop_cells(fdt, nodeoffset, prop, ...) \
  38. fdt_prop_cells_ops(fdt_setprop, fdt, nodeoffset, prop, __VA_ARGS__)
  39. #define fdt_appendprop_cells(fdt, nodeoffset, prop, ...) \
  40. fdt_prop_cells_ops(fdt_appendprop, fdt, nodeoffset, prop, __VA_ARGS__)
  41. int fdt_setprop_uxx(void *fdt, int nodeoffset, const char *name, uint64_t val, bool is_u64);
  42. int fdt_getprop_u8(void *fdt, int nodeoffset, const char *name, uint8_t *out_value, int *lenp);
  43. int fdt_getprop_s8(void *fdt, int nodeoffset, const char *name, int8_t *out_value, int *lenp);
  44. int fdt_getprop_u16(void *fdt, int nodeoffset, const char *name, uint16_t *out_value, int *lenp);
  45. int fdt_getprop_s16(void *fdt, int nodeoffset, const char *name, int16_t *out_value, int *lenp);
  46. int fdt_getprop_u32(void *fdt, int nodeoffset, const char *name, uint32_t *out_value, int *lenp);
  47. int fdt_getprop_s32(void *fdt, int nodeoffset, const char *name, int32_t *out_value, int *lenp);
  48. int fdt_io_addr_cells(void *fdt, int nodeoffset);
  49. int fdt_io_size_cells(void *fdt, int nodeoffset);
  50. int fdt_install_initrd(void *fdt, char *os_name, size_t initrd_addr, size_t initrd_size);
  51. #endif /* __OFW_RAW_H__ */