1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2009-2010 The FreeBSD Foundation 5 * 6 * This software was developed by Semihalf under sponsorship from 7 * the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef _FDT_COMMON_H_ 32 #define _FDT_COMMON_H_ 33 34 #include <sys/sysctl.h> 35 #include <sys/slicer.h> 36 #include <sys/socket.h> 37 #include <contrib/libfdt/libfdt_env.h> 38 #include <dev/ofw/ofw_bus.h> 39 #include <net/ethernet.h> 40 #include <net/if.h> 41 42 #define FDT_MEM_REGIONS 64 43 44 #define DI_MAX_INTR_NUM 32 45 46 struct fdt_sense_level { 47 enum intr_trigger trig; 48 enum intr_polarity pol; 49 }; 50 51 #if defined(__arm__) && !defined(INTRNG) 52 typedef int (*fdt_pic_decode_t)(phandle_t, pcell_t *, int *, int *, int *); 53 extern fdt_pic_decode_t fdt_pic_table[]; 54 #endif 55 56 #if defined(__arm__) || defined(__powerpc__) 57 typedef void (*fdt_fixup_t)(phandle_t); 58 struct fdt_fixup_entry { 59 char *model; 60 fdt_fixup_t handler; 61 }; 62 extern struct fdt_fixup_entry fdt_fixup_table[]; 63 #endif 64 65 #if defined(FDT_DTB_STATIC) 66 extern u_char fdt_static_dtb; 67 #endif 68 69 SYSCTL_DECL(_hw_fdt); 70 71 typedef void (*fdt_mem_region_cb)(const struct mem_region *, void *); 72 73 int fdt_addrsize_cells(phandle_t, int *, int *); 74 u_long fdt_data_get(const void *, int); 75 int fdt_data_to_res(const pcell_t *, int, int, u_long *, u_long *); 76 void fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr); 77 phandle_t fdt_find_compatible(phandle_t, const char *, int); 78 phandle_t fdt_depth_search_compatible(phandle_t, const char *, int); 79 int fdt_foreach_mem_region(fdt_mem_region_cb, void *); 80 int fdt_foreach_reserved_mem(fdt_mem_region_cb, void *); 81 int fdt_foreach_reserved_region(fdt_mem_region_cb, void *); 82 int fdt_get_phyaddr(phandle_t, device_t, int *, void **); 83 int fdt_get_range(phandle_t, int, u_long *, u_long *); 84 int fdt_immr_addr(vm_offset_t); 85 int fdt_regsize(phandle_t, u_long *, u_long *); 86 int fdt_is_compatible_strict(phandle_t, const char *); 87 int fdt_parent_addr_cells(phandle_t); 88 int fdt_get_chosen_bootargs(char *bootargs, size_t max_size); 89 90 #endif /* _FDT_COMMON_H_ */ 91