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 
10 #ifndef __FDT_HELPER_H__
11 #define __FDT_HELPER_H__
12 
13 #include <sbi/sbi_types.h>
14 
15 struct fdt_match {
16 	const char *compatible;
17 	void *data;
18 };
19 
20 struct platform_uart_data {
21 	unsigned long addr;
22 	unsigned long freq;
23 	unsigned long baud;
24 	unsigned long reg_shift;
25 	unsigned long reg_io_width;
26 };
27 
28 const struct fdt_match *fdt_match_node(void *fdt, int nodeoff,
29 				       const struct fdt_match *match_table);
30 
31 int fdt_find_match(void *fdt, int startoff,
32 		   const struct fdt_match *match_table,
33 		   const struct fdt_match **out_match);
34 
35 int fdt_get_node_addr_size(void *fdt, int node, unsigned long *addr,
36 			   unsigned long *size);
37 
38 int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
39 
40 int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid);
41 
42 int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset,
43 			       struct platform_uart_data *uart);
44 
45 int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
46 			       struct platform_uart_data *uart);
47 
48 int fdt_parse_uart8250_node(void *fdt, int nodeoffset,
49 			    struct platform_uart_data *uart);
50 
51 int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
52 		       const char *compatible);
53 
54 struct plic_data;
55 
56 int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);
57 
58 int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat);
59 
60 struct clint_data;
61 
62 int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,
63 			 struct clint_data *clint);
64 
65 int fdt_parse_compat_addr(void *fdt, unsigned long *addr,
66 			  const char *compatible);
67 
68 #endif /* __FDT_HELPER_H__ */
69