1 /* $NetBSD: fdtvar.h,v 1.86 2025/09/08 13:06:16 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 35 #include <dev/clock_subr.h> 36 37 #include <dev/ofw/openfirm.h> 38 39 #include <dev/fdt/fdt_clock.h> 40 #include <dev/fdt/fdt_dai.h> 41 #include <dev/fdt/fdt_dma.h> 42 #include <dev/fdt/fdt_gpio.h> 43 #include <dev/fdt/fdt_i2c.h> 44 #include <dev/fdt/fdt_intr.h> 45 #include <dev/fdt/fdt_iommu.h> 46 #include <dev/fdt/fdt_mbox.h> 47 #include <dev/fdt/fdt_mmc_pwrseq.h> 48 #include <dev/fdt/fdt_phy.h> 49 #include <dev/fdt/fdt_pinctrl.h> 50 #include <dev/fdt/fdt_power.h> 51 #include <dev/fdt/fdt_powerdomain.h> 52 #include <dev/fdt/fdt_pwm.h> 53 #include <dev/fdt/fdt_regulator.h> 54 #include <dev/fdt/fdt_reset.h> 55 #include <dev/fdt/fdt_spi.h> 56 #include <dev/fdt/fdt_syscon.h> 57 58 struct fdt_attach_args { 59 const char *faa_name; 60 bus_space_tag_t faa_bst; 61 bus_dma_tag_t faa_dmat; 62 int faa_phandle; 63 int faa_quiet; 64 }; 65 66 struct fdt_phandle_data { 67 int phandle; 68 int count; 69 const u_int *values; 70 }; 71 72 struct fdt_dma_range { 73 paddr_t dr_sysbase; 74 bus_addr_t dr_busbase; 75 bus_size_t dr_len; 76 }; 77 78 #define FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO __BIT(0) 79 80 void fdtbus_set_decoderegprop(bool); 81 82 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *); 83 int fdtbus_get_reg_byname(int, const char *, bus_addr_t *, 84 bus_size_t *); 85 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *); 86 int fdtbus_get_addr_cells(int); 87 int fdtbus_get_size_cells(int); 88 uint64_t fdtbus_get_cells(const uint8_t *, int); 89 int fdtbus_get_phandle(int, const char *); 90 int fdtbus_get_phandle_with_data(int, const char *, const char *, 91 int, struct fdt_phandle_data *); 92 int fdtbus_get_phandle_from_native(int); 93 94 bool fdtbus_init(const void *); 95 const void * fdtbus_get_data(void); 96 97 int fdtbus_phandle2offset(int); 98 int fdtbus_offset2phandle(int); 99 bool fdtbus_get_path(int, char *, size_t); 100 101 bool fdtbus_status_okay(int); 102 103 const void * fdtbus_get_prop(int, const char *, int *); 104 const char * fdtbus_get_string(int, const char *); 105 const char * fdtbus_get_string_index(int, const char *, u_int); 106 int fdtbus_get_index(int, const char *, const char *, u_int *); 107 108 void fdtbus_cpus_md_attach(device_t, device_t, void *); 109 110 void fdt_add_bus(device_t, int, struct fdt_attach_args *); 111 void fdt_add_bus_match(device_t, int, struct fdt_attach_args *, 112 bool (*)(void *, int), void *); 113 void fdt_add_child(device_t, int, struct fdt_attach_args *, u_int); 114 115 void fdt_remove_byhandle(int); 116 void fdt_remove_bycompat(const char *[]); 117 int fdt_find_with_property(const char *, int *); 118 119 int fdtbus_print(void *, const char *); 120 121 bus_dma_tag_t fdtbus_dma_tag_create(int, const struct fdt_dma_range *, 122 u_int); 123 bus_space_tag_t fdtbus_bus_tag_create(int, uint32_t); 124 125 126 #endif /* _DEV_FDT_FDTVAR_H_ */ 127