xref: /freebsd/sys/dev/fdt/fdt_common.h (revision 4f52dfbb8d6c4d446500c5b097e3806ec219fbd4)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2009-2010 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * This software was developed by Semihalf under sponsorship from
8  * the FreeBSD Foundation.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef _FDT_COMMON_H_
35 #define _FDT_COMMON_H_
36 
37 #include <sys/sysctl.h>
38 #include <sys/slicer.h>
39 #include <contrib/libfdt/libfdt_env.h>
40 #include <dev/ofw/ofw_bus.h>
41 
42 #define FDT_MEM_REGIONS	8
43 
44 #define DI_MAX_INTR_NUM	32
45 
46 struct fdt_sense_level {
47 	enum intr_trigger	trig;
48 	enum intr_polarity	pol;
49 };
50 
51 #if defined(__arm__) && !defined(INTRNG)
52 typedef int (*fdt_pic_decode_t)(phandle_t, pcell_t *, int *, int *, int *);
53 extern fdt_pic_decode_t fdt_pic_table[];
54 #endif
55 
56 #if defined(__arm__) || defined(__powerpc__)
57 typedef void (*fdt_fixup_t)(phandle_t);
58 struct fdt_fixup_entry {
59 	char		*model;
60 	fdt_fixup_t	handler;
61 };
62 extern struct fdt_fixup_entry fdt_fixup_table[];
63 #endif
64 
65 extern SLIST_HEAD(fdt_ic_list, fdt_ic) fdt_ic_list_head;
66 struct fdt_ic {
67 	SLIST_ENTRY(fdt_ic)	fdt_ics;
68 	ihandle_t		iph;
69 	device_t		dev;
70 };
71 
72 extern vm_paddr_t fdt_immr_pa;
73 extern vm_offset_t fdt_immr_va;
74 extern vm_offset_t fdt_immr_size;
75 
76 #if defined(FDT_DTB_STATIC)
77 extern u_char fdt_static_dtb;
78 #endif
79 
80 SYSCTL_DECL(_hw_fdt);
81 
82 int fdt_addrsize_cells(phandle_t, int *, int *);
83 u_long fdt_data_get(void *, int);
84 int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *);
85 phandle_t fdt_find_compatible(phandle_t, const char *, int);
86 phandle_t fdt_depth_search_compatible(phandle_t, const char *, int);
87 int fdt_get_mem_regions(struct mem_region *, int *, uint64_t *);
88 int fdt_get_reserved_regions(struct mem_region *, int *);
89 int fdt_get_phyaddr(phandle_t, device_t, int *, void **);
90 int fdt_get_range(phandle_t, int, u_long *, u_long *);
91 int fdt_immr_addr(vm_offset_t);
92 int fdt_regsize(phandle_t, u_long *, u_long *);
93 int fdt_is_compatible_strict(phandle_t, const char *);
94 int fdt_parent_addr_cells(phandle_t);
95 int fdt_get_chosen_bootargs(char *bootargs, size_t max_size);
96 
97 #endif /* _FDT_COMMON_H_ */
98