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