fdtvar.h revision 1.84 1 /* $NetBSD: fdtvar.h,v 1.84 2025/09/06 21:24:05 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_dma_range {
92 paddr_t dr_sysbase;
93 bus_addr_t dr_busbase;
94 bus_size_t dr_len;
95 };
96
97 #define FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO __BIT(0)
98
99 void fdtbus_set_decoderegprop(bool);
100
101 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
102 int fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
103 bus_size_t *);
104 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
105 int fdtbus_get_addr_cells(int);
106 int fdtbus_get_size_cells(int);
107 uint64_t fdtbus_get_cells(const uint8_t *, int);
108 int fdtbus_get_phandle(int, const char *);
109 int fdtbus_get_phandle_with_data(int, const char *, const char *,
110 int, struct fdt_phandle_data *);
111 int fdtbus_get_phandle_from_native(int);
112
113 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
114
115 bool fdtbus_init(const void *);
116 const void * fdtbus_get_data(void);
117 int fdtbus_phandle2offset(int);
118 int fdtbus_offset2phandle(int);
119 bool fdtbus_get_path(int, char *, size_t);
120
121 const struct fdt_console *
122 fdtbus_get_console(void);
123
124 const char * fdtbus_get_stdout_path(void);
125 int fdtbus_get_stdout_phandle(void);
126 int fdtbus_get_stdout_speed(void);
127 tcflag_t fdtbus_get_stdout_flags(void);
128
129 bool fdtbus_status_okay(int);
130
131 const void * fdtbus_get_prop(int, const char *, int *);
132 const char * fdtbus_get_string(int, const char *);
133 const char * fdtbus_get_string_index(int, const char *, u_int);
134 int fdtbus_get_index(int, const char *, const char *, u_int *);
135
136 void fdtbus_cpus_md_attach(device_t, device_t, void *);
137
138 void fdt_add_bus(device_t, int, struct fdt_attach_args *);
139 void fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
140 bool (*)(void *, int), void *);
141 void fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
142
143 void fdt_remove_byhandle(int);
144 void fdt_remove_bycompat(const char *[]);
145 int fdt_find_with_property(const char *, int *);
146
147 int fdtbus_print(void *, const char *);
148
149 bus_dma_tag_t fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
150 u_int);
151 bus_space_tag_t fdtbus_bus_tag_create(int, uint32_t);
152
153
154 #endif /* _DEV_FDT_FDTVAR_H_ */
155