fdt_helper.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: BSD-2-Clause
  2. /*
  3. * fdt_helper.h - Flat Device Tree parsing helper routines
  4. * Implement helper routines to parse FDT nodes on top of
  5. * libfdt for OpenSBI usage
  6. *
  7. * Copyright (C) 2020 Bin Meng <bmeng.cn@gmail.com>
  8. */
  9. #ifndef __FDT_HELPER_H__
  10. #define __FDT_HELPER_H__
  11. #include <sbi/sbi_types.h>
  12. #include <sbi/sbi_scratch.h>
  13. struct fdt_match {
  14. const char *compatible;
  15. const void *data;
  16. };
  17. #define FDT_MAX_PHANDLE_ARGS 16
  18. struct fdt_phandle_args {
  19. int node_offset;
  20. int args_count;
  21. u32 args[FDT_MAX_PHANDLE_ARGS];
  22. };
  23. struct platform_uart_data {
  24. unsigned long addr;
  25. unsigned long freq;
  26. unsigned long baud;
  27. unsigned long reg_shift;
  28. unsigned long reg_io_width;
  29. unsigned long reg_offset;
  30. };
  31. const struct fdt_match *fdt_match_node(void *fdt, int nodeoff,
  32. const struct fdt_match *match_table);
  33. int fdt_find_match(void *fdt, int startoff,
  34. const struct fdt_match *match_table,
  35. const struct fdt_match **out_match);
  36. int fdt_parse_phandle_with_args(void *fdt, int nodeoff,
  37. const char *prop, const char *cells_prop,
  38. int index, struct fdt_phandle_args *out_args);
  39. int fdt_get_node_addr_size(void *fdt, int node, int index,
  40. uint64_t *addr, uint64_t *size);
  41. bool fdt_node_is_enabled(void *fdt, int nodeoff);
  42. int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
  43. int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid);
  44. int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
  45. int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
  46. struct platform_uart_data *uart);
  47. int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset,
  48. struct platform_uart_data *uart);
  49. int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
  50. struct platform_uart_data *uart);
  51. int fdt_parse_uart_node(void *fdt, int nodeoffset,
  52. struct platform_uart_data *uart);
  53. int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
  54. const char *compatible);
  55. int fdt_parse_xlnx_uartlite_node(void *fdt, int nodeoffset,
  56. struct platform_uart_data *uart);
  57. struct aplic_data;
  58. int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic);
  59. struct imsic_data;
  60. bool fdt_check_imsic_mlevel(void *fdt);
  61. int fdt_parse_imsic_node(void *fdt, int nodeoff, struct imsic_data *imsic);
  62. struct plic_data;
  63. int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);
  64. int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat);
  65. int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
  66. unsigned long *out_addr1, unsigned long *out_size1,
  67. unsigned long *out_addr2, unsigned long *out_size2,
  68. u32 *out_first_hartid, u32 *out_hart_count);
  69. int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,
  70. unsigned long *plmt_size, u32 *hart_count);
  71. int fdt_parse_compat_addr(void *fdt, uint64_t *addr,
  72. const char *compatible);
  73. static inline void *fdt_get_address(void)
  74. {
  75. return sbi_scratch_thishart_arg1_ptr();
  76. }
  77. #endif /* __FDT_HELPER_H__ */