Home | History | Annotate | Line # | Download | only in fdt
fdtvar.h revision 1.81
      1  1.81   thorpej /* $NetBSD: fdtvar.h,v 1.81 2025/09/06 20:11:30 thorpej Exp $ */
      2   1.1  jmcneill 
      3   1.1  jmcneill /*-
      4   1.1  jmcneill  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
      5   1.1  jmcneill  * All rights reserved.
      6   1.1  jmcneill  *
      7   1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8   1.1  jmcneill  * modification, are permitted provided that the following conditions
      9   1.1  jmcneill  * are met:
     10   1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12   1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15   1.1  jmcneill  *
     16   1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21   1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22   1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23   1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24   1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1  jmcneill  * SUCH DAMAGE.
     27   1.1  jmcneill  */
     28   1.1  jmcneill 
     29  1.62     skrll #ifndef _DEV_FDT_FDTVAR_H_
     30  1.62     skrll #define _DEV_FDT_FDTVAR_H_
     31   1.1  jmcneill 
     32   1.1  jmcneill #include <sys/types.h>
     33   1.1  jmcneill #include <sys/bus.h>
     34  1.19  jmcneill #include <sys/termios.h>
     35   1.1  jmcneill 
     36  1.11  jmcneill #include <dev/clock_subr.h>
     37  1.11  jmcneill 
     38   1.1  jmcneill #include <dev/ofw/openfirm.h>
     39   1.1  jmcneill 
     40  1.81   thorpej #include <dev/fdt/fdt_clock.h>
     41  1.81   thorpej #include <dev/fdt/fdt_dai.h>
     42  1.81   thorpej #include <dev/fdt/fdt_dma.h>
     43  1.81   thorpej #include <dev/fdt/fdt_gpio.h>
     44  1.81   thorpej #include <dev/fdt/fdt_i2c.h>
     45  1.81   thorpej #include <dev/fdt/fdt_intr.h>
     46  1.81   thorpej #include <dev/fdt/fdt_iommu.h>
     47  1.81   thorpej #include <dev/fdt/fdt_mbox.h>
     48  1.81   thorpej #include <dev/fdt/fdt_mmc_pwrseq.h>
     49  1.81   thorpej #include <dev/fdt/fdt_phy.h>
     50  1.81   thorpej #include <dev/fdt/fdt_pinctrl.h>
     51  1.81   thorpej #include <dev/fdt/fdt_power.h>
     52  1.81   thorpej #include <dev/fdt/fdt_powerdomain.h>
     53  1.81   thorpej #include <dev/fdt/fdt_pwm.h>
     54  1.81   thorpej #include <dev/fdt/fdt_regulator.h>
     55  1.81   thorpej #include <dev/fdt/fdt_reset.h>
     56  1.81   thorpej #include <dev/fdt/fdt_spi.h>
     57  1.81   thorpej #include <dev/fdt/fdt_syscon.h>
     58  1.81   thorpej 
     59   1.1  jmcneill struct fdt_attach_args {
     60   1.1  jmcneill 	const char *faa_name;
     61   1.1  jmcneill 	bus_space_tag_t faa_bst;
     62   1.1  jmcneill 	bus_dma_tag_t faa_dmat;
     63   1.1  jmcneill 	int faa_phandle;
     64  1.13  jmcneill 	int faa_quiet;
     65   1.1  jmcneill };
     66   1.1  jmcneill 
     67  1.19  jmcneill struct fdt_console {
     68  1.19  jmcneill 	int	(*match)(int);
     69  1.20  jmcneill 	void	(*consinit)(struct fdt_attach_args *, u_int);
     70  1.19  jmcneill };
     71  1.19  jmcneill 
     72  1.19  jmcneill struct fdt_console_info {
     73  1.19  jmcneill 	const struct fdt_console *ops;
     74  1.19  jmcneill };
     75  1.19  jmcneill 
     76  1.52   hkenken struct fdt_phandle_data {
     77  1.52   hkenken 	int phandle;
     78  1.52   hkenken 	int count;
     79  1.52   hkenken 	const u_int *values;
     80  1.52   hkenken };
     81  1.52   hkenken 
     82  1.19  jmcneill #define	_FDT_CONSOLE_REGISTER(name)	\
     83  1.19  jmcneill 	__link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
     84  1.19  jmcneill 
     85  1.19  jmcneill #define	FDT_CONSOLE(_name, _ops)					\
     86  1.19  jmcneill static const struct fdt_console_info __CONCAT(_name,_consinfo) = {	\
     87  1.19  jmcneill 	.ops = (_ops)							\
     88  1.19  jmcneill };									\
     89  1.19  jmcneill _FDT_CONSOLE_REGISTER(_name)
     90  1.19  jmcneill 
     91  1.55  jmcneill struct fdt_opp_info {
     92  1.55  jmcneill 	const char *	opp_compat;
     93  1.55  jmcneill 	bool		(*opp_supported)(const int, const int);
     94  1.55  jmcneill };
     95  1.55  jmcneill 
     96  1.55  jmcneill #define	_FDT_OPP_REGISTER(name)		\
     97  1.55  jmcneill 	__link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
     98  1.55  jmcneill 
     99  1.55  jmcneill #define	FDT_OPP(_name, _compat, _suppfn)				\
    100  1.55  jmcneill static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = {		\
    101  1.55  jmcneill 	.opp_compat = (_compat),					\
    102  1.55  jmcneill 	.opp_supported = (_suppfn)					\
    103  1.55  jmcneill };									\
    104  1.55  jmcneill _FDT_OPP_REGISTER(_name)
    105  1.55  jmcneill 
    106  1.19  jmcneill TAILQ_HEAD(fdt_conslist, fdt_console_info);
    107  1.19  jmcneill 
    108  1.78     skrll /*
    109  1.78     skrll  * Platform-specific data
    110  1.78     skrll  */
    111  1.78     skrll 
    112  1.78     skrll struct fdt_platform {
    113  1.78     skrll 	const struct pmap_devmap *
    114  1.78     skrll 				(*fp_devmap)(void);
    115  1.78     skrll 	void			(*fp_bootstrap)(void);
    116  1.78     skrll 	int			(*fp_mpstart)(void);
    117  1.78     skrll 	void			(*fp_startup)(void);
    118  1.78     skrll 	void			(*fp_init_attach_args)(struct fdt_attach_args *);
    119  1.78     skrll 	void			(*fp_device_register)(device_t, void *);
    120  1.80  jmcneill 	void			(*fp_device_register_post_config)(device_t, void *);
    121  1.78     skrll 	void			(*fp_reset)(void);
    122  1.78     skrll 	void			(*fp_delay)(u_int);
    123  1.78     skrll 	u_int			(*fp_uart_freq)(void);
    124  1.78     skrll };
    125  1.78     skrll 
    126  1.78     skrll struct fdt_platform_info {
    127  1.78     skrll 	const char *			fpi_compat;
    128  1.78     skrll 	const struct fdt_platform *	fpi_ops;
    129  1.78     skrll };
    130  1.78     skrll 
    131  1.78     skrll #define FDT_PLATFORM_DEFAULT		""
    132  1.78     skrll 
    133  1.78     skrll #define _FDT_PLATFORM_REGISTER(name)	\
    134  1.78     skrll 	__link_set_add_rodata(fdt_platforms, __CONCAT(name,_platinfo));
    135  1.78     skrll 
    136  1.78     skrll #define FDT_PLATFORM(_name, _compat, _ops)				\
    137  1.78     skrll static const struct fdt_platform_info __CONCAT(_name,_platinfo) = {	\
    138  1.78     skrll 	.fpi_compat = (_compat),					\
    139  1.78     skrll 	.fpi_ops = (_ops)						\
    140  1.78     skrll };									\
    141  1.78     skrll _FDT_PLATFORM_REGISTER(_name)
    142  1.78     skrll 
    143  1.78     skrll const struct fdt_platform *
    144  1.78     skrll 		fdt_platform_find(void);
    145  1.78     skrll 
    146  1.78     skrll 
    147  1.60  jmcneill struct fdt_dma_range {
    148  1.60  jmcneill 	paddr_t		dr_sysbase;
    149  1.60  jmcneill 	bus_addr_t	dr_busbase;
    150  1.60  jmcneill 	bus_size_t	dr_len;
    151  1.60  jmcneill };
    152  1.60  jmcneill 
    153  1.72  jmcneill #define	FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO	__BIT(0)
    154  1.72  jmcneill 
    155  1.28     skrll void		fdtbus_set_decoderegprop(bool);
    156  1.28     skrll 
    157   1.2  jmcneill int		fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
    158  1.26  jmcneill int		fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
    159  1.26  jmcneill 		    bus_size_t *);
    160  1.17  jmcneill int		fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
    161  1.60  jmcneill int		fdtbus_get_addr_cells(int);
    162  1.60  jmcneill int		fdtbus_get_size_cells(int);
    163  1.60  jmcneill uint64_t	fdtbus_get_cells(const uint8_t *, int);
    164   1.2  jmcneill int		fdtbus_get_phandle(int, const char *);
    165  1.52   hkenken int		fdtbus_get_phandle_with_data(int, const char *, const char *,
    166  1.52   hkenken 		    int, struct fdt_phandle_data *);
    167   1.3  jmcneill int		fdtbus_get_phandle_from_native(int);
    168  1.74     skrll 
    169  1.11  jmcneill int		fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
    170  1.11  jmcneill 
    171  1.58   thorpej bool		fdtbus_init(const void *);
    172   1.2  jmcneill const void *	fdtbus_get_data(void);
    173   1.2  jmcneill int		fdtbus_phandle2offset(int);
    174   1.2  jmcneill int		fdtbus_offset2phandle(int);
    175   1.8  jmcneill bool		fdtbus_get_path(int, char *, size_t);
    176   1.1  jmcneill 
    177  1.74     skrll const struct fdt_console *
    178  1.74     skrll 		fdtbus_get_console(void);
    179  1.19  jmcneill 
    180  1.10  jmcneill const char *	fdtbus_get_stdout_path(void);
    181  1.10  jmcneill int		fdtbus_get_stdout_phandle(void);
    182  1.10  jmcneill int		fdtbus_get_stdout_speed(void);
    183  1.19  jmcneill tcflag_t	fdtbus_get_stdout_flags(void);
    184  1.10  jmcneill 
    185  1.15  jmcneill bool		fdtbus_status_okay(int);
    186  1.15  jmcneill 
    187  1.23  jmcneill const void *	fdtbus_get_prop(int, const char *, int *);
    188  1.22  jmcneill const char *	fdtbus_get_string(int, const char *);
    189  1.24  jmcneill const char *	fdtbus_get_string_index(int, const char *, u_int);
    190  1.49  jakllsch int		fdtbus_get_index(int, const char *, const char *, u_int *);
    191  1.22  jmcneill 
    192  1.79     skrll void		fdtbus_cpus_md_attach(device_t, device_t, void *);
    193  1.79     skrll 
    194  1.36  jmcneill void		fdt_add_bus(device_t, int, struct fdt_attach_args *);
    195  1.41  jmcneill void		fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
    196  1.74     skrll 		    bool (*)(void *, int), void *);
    197  1.43  jmcneill void		fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
    198  1.36  jmcneill 
    199  1.29    bouyer void		fdt_remove_byhandle(int);
    200  1.29    bouyer void		fdt_remove_bycompat(const char *[]);
    201  1.45  jmcneill int		fdt_find_with_property(const char *, int *);
    202  1.69   thorpej 
    203  1.16  jmcneill int		fdtbus_print(void *, const char *);
    204  1.16  jmcneill 
    205  1.60  jmcneill bus_dma_tag_t	fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
    206  1.60  jmcneill 		    u_int);
    207  1.72  jmcneill bus_space_tag_t	fdtbus_bus_tag_create(int, uint32_t);
    208  1.60  jmcneill 
    209  1.76     skrll 
    210  1.62     skrll #endif /* _DEV_FDT_FDTVAR_H_ */
    211