Home | History | Annotate | Line # | Download | only in fdt
fdtvar.h revision 1.81
      1 /* $NetBSD: fdtvar.h,v 1.81 2025/09/06 20:11:30 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 TAILQ_HEAD(fdt_conslist, fdt_console_info);
    107 
    108 /*
    109  * Platform-specific data
    110  */
    111 
    112 struct fdt_platform {
    113 	const struct pmap_devmap *
    114 				(*fp_devmap)(void);
    115 	void			(*fp_bootstrap)(void);
    116 	int			(*fp_mpstart)(void);
    117 	void			(*fp_startup)(void);
    118 	void			(*fp_init_attach_args)(struct fdt_attach_args *);
    119 	void			(*fp_device_register)(device_t, void *);
    120 	void			(*fp_device_register_post_config)(device_t, void *);
    121 	void			(*fp_reset)(void);
    122 	void			(*fp_delay)(u_int);
    123 	u_int			(*fp_uart_freq)(void);
    124 };
    125 
    126 struct fdt_platform_info {
    127 	const char *			fpi_compat;
    128 	const struct fdt_platform *	fpi_ops;
    129 };
    130 
    131 #define FDT_PLATFORM_DEFAULT		""
    132 
    133 #define _FDT_PLATFORM_REGISTER(name)	\
    134 	__link_set_add_rodata(fdt_platforms, __CONCAT(name,_platinfo));
    135 
    136 #define FDT_PLATFORM(_name, _compat, _ops)				\
    137 static const struct fdt_platform_info __CONCAT(_name,_platinfo) = {	\
    138 	.fpi_compat = (_compat),					\
    139 	.fpi_ops = (_ops)						\
    140 };									\
    141 _FDT_PLATFORM_REGISTER(_name)
    142 
    143 const struct fdt_platform *
    144 		fdt_platform_find(void);
    145 
    146 
    147 struct fdt_dma_range {
    148 	paddr_t		dr_sysbase;
    149 	bus_addr_t	dr_busbase;
    150 	bus_size_t	dr_len;
    151 };
    152 
    153 #define	FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO	__BIT(0)
    154 
    155 void		fdtbus_set_decoderegprop(bool);
    156 
    157 int		fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
    158 int		fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
    159 		    bus_size_t *);
    160 int		fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
    161 int		fdtbus_get_addr_cells(int);
    162 int		fdtbus_get_size_cells(int);
    163 uint64_t	fdtbus_get_cells(const uint8_t *, int);
    164 int		fdtbus_get_phandle(int, const char *);
    165 int		fdtbus_get_phandle_with_data(int, const char *, const char *,
    166 		    int, struct fdt_phandle_data *);
    167 int		fdtbus_get_phandle_from_native(int);
    168 
    169 int		fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
    170 
    171 bool		fdtbus_init(const void *);
    172 const void *	fdtbus_get_data(void);
    173 int		fdtbus_phandle2offset(int);
    174 int		fdtbus_offset2phandle(int);
    175 bool		fdtbus_get_path(int, char *, size_t);
    176 
    177 const struct fdt_console *
    178 		fdtbus_get_console(void);
    179 
    180 const char *	fdtbus_get_stdout_path(void);
    181 int		fdtbus_get_stdout_phandle(void);
    182 int		fdtbus_get_stdout_speed(void);
    183 tcflag_t	fdtbus_get_stdout_flags(void);
    184 
    185 bool		fdtbus_status_okay(int);
    186 
    187 const void *	fdtbus_get_prop(int, const char *, int *);
    188 const char *	fdtbus_get_string(int, const char *);
    189 const char *	fdtbus_get_string_index(int, const char *, u_int);
    190 int		fdtbus_get_index(int, const char *, const char *, u_int *);
    191 
    192 void		fdtbus_cpus_md_attach(device_t, device_t, void *);
    193 
    194 void		fdt_add_bus(device_t, int, struct fdt_attach_args *);
    195 void		fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
    196 		    bool (*)(void *, int), void *);
    197 void		fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
    198 
    199 void		fdt_remove_byhandle(int);
    200 void		fdt_remove_bycompat(const char *[]);
    201 int		fdt_find_with_property(const char *, int *);
    202 
    203 int		fdtbus_print(void *, const char *);
    204 
    205 bus_dma_tag_t	fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
    206 		    u_int);
    207 bus_space_tag_t	fdtbus_bus_tag_create(int, uint32_t);
    208 
    209 
    210 #endif /* _DEV_FDT_FDTVAR_H_ */
    211