fdtvar.h revision 1.83 1 /* $NetBSD: fdtvar.h,v 1.83 2025/09/06 21:11:06 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #ifndef _DEV_FDT_FDTVAR_H_
30 #define _DEV_FDT_FDTVAR_H_
31
32 #include <sys/types.h>
33 #include <sys/bus.h>
34 #include <sys/termios.h>
35
36 #include <dev/clock_subr.h>
37
38 #include <dev/ofw/openfirm.h>
39
40 #include <dev/fdt/fdt_clock.h>
41 #include <dev/fdt/fdt_dai.h>
42 #include <dev/fdt/fdt_dma.h>
43 #include <dev/fdt/fdt_gpio.h>
44 #include <dev/fdt/fdt_i2c.h>
45 #include <dev/fdt/fdt_intr.h>
46 #include <dev/fdt/fdt_iommu.h>
47 #include <dev/fdt/fdt_mbox.h>
48 #include <dev/fdt/fdt_mmc_pwrseq.h>
49 #include <dev/fdt/fdt_phy.h>
50 #include <dev/fdt/fdt_pinctrl.h>
51 #include <dev/fdt/fdt_power.h>
52 #include <dev/fdt/fdt_powerdomain.h>
53 #include <dev/fdt/fdt_pwm.h>
54 #include <dev/fdt/fdt_regulator.h>
55 #include <dev/fdt/fdt_reset.h>
56 #include <dev/fdt/fdt_spi.h>
57 #include <dev/fdt/fdt_syscon.h>
58
59 struct fdt_attach_args {
60 const char *faa_name;
61 bus_space_tag_t faa_bst;
62 bus_dma_tag_t faa_dmat;
63 int faa_phandle;
64 int faa_quiet;
65 };
66
67 struct fdt_console {
68 int (*match)(int);
69 void (*consinit)(struct fdt_attach_args *, u_int);
70 };
71
72 struct fdt_console_info {
73 const struct fdt_console *ops;
74 };
75
76 struct fdt_phandle_data {
77 int phandle;
78 int count;
79 const u_int *values;
80 };
81
82 #define _FDT_CONSOLE_REGISTER(name) \
83 __link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
84
85 #define FDT_CONSOLE(_name, _ops) \
86 static const struct fdt_console_info __CONCAT(_name,_consinfo) = { \
87 .ops = (_ops) \
88 }; \
89 _FDT_CONSOLE_REGISTER(_name)
90
91 struct fdt_opp_info {
92 const char * opp_compat;
93 bool (*opp_supported)(const int, const int);
94 };
95
96 #define _FDT_OPP_REGISTER(name) \
97 __link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
98
99 #define FDT_OPP(_name, _compat, _suppfn) \
100 static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = { \
101 .opp_compat = (_compat), \
102 .opp_supported = (_suppfn) \
103 }; \
104 _FDT_OPP_REGISTER(_name)
105
106 struct fdt_dma_range {
107 paddr_t dr_sysbase;
108 bus_addr_t dr_busbase;
109 bus_size_t dr_len;
110 };
111
112 #define FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO __BIT(0)
113
114 void fdtbus_set_decoderegprop(bool);
115
116 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
117 int fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
118 bus_size_t *);
119 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
120 int fdtbus_get_addr_cells(int);
121 int fdtbus_get_size_cells(int);
122 uint64_t fdtbus_get_cells(const uint8_t *, int);
123 int fdtbus_get_phandle(int, const char *);
124 int fdtbus_get_phandle_with_data(int, const char *, const char *,
125 int, struct fdt_phandle_data *);
126 int fdtbus_get_phandle_from_native(int);
127
128 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
129
130 bool fdtbus_init(const void *);
131 const void * fdtbus_get_data(void);
132 int fdtbus_phandle2offset(int);
133 int fdtbus_offset2phandle(int);
134 bool fdtbus_get_path(int, char *, size_t);
135
136 const struct fdt_console *
137 fdtbus_get_console(void);
138
139 const char * fdtbus_get_stdout_path(void);
140 int fdtbus_get_stdout_phandle(void);
141 int fdtbus_get_stdout_speed(void);
142 tcflag_t fdtbus_get_stdout_flags(void);
143
144 bool fdtbus_status_okay(int);
145
146 const void * fdtbus_get_prop(int, const char *, int *);
147 const char * fdtbus_get_string(int, const char *);
148 const char * fdtbus_get_string_index(int, const char *, u_int);
149 int fdtbus_get_index(int, const char *, const char *, u_int *);
150
151 void fdtbus_cpus_md_attach(device_t, device_t, void *);
152
153 void fdt_add_bus(device_t, int, struct fdt_attach_args *);
154 void fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
155 bool (*)(void *, int), void *);
156 void fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
157
158 void fdt_remove_byhandle(int);
159 void fdt_remove_bycompat(const char *[]);
160 int fdt_find_with_property(const char *, int *);
161
162 int fdtbus_print(void *, const char *);
163
164 bus_dma_tag_t fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
165 u_int);
166 bus_space_tag_t fdtbus_bus_tag_create(int, uint32_t);
167
168
169 #endif /* _DEV_FDT_FDTVAR_H_ */
170