diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-08-21 13:47:02 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-09-21 10:29:41 +0200 |
commit | bcdce02d9bc8150e1d191ed5ca9da45b7604964a (patch) | |
tree | 3b2faf509db7672ee1fc98857736470be97e7ed8 /freebsd/sys/dev/fdt | |
parent | Update to FreeBSD head 2018-04-01 (diff) | |
download | rtems-libbsd-bcdce02d9bc8150e1d191ed5ca9da45b7604964a.tar.bz2 |
Update to FreeBSD head 2018-06-01
Git mirror commit fb63610a69b0eb7f69a201ba05c4c1a7a2739cf9.
Update #3472.
Diffstat (limited to 'freebsd/sys/dev/fdt')
-rw-r--r-- | freebsd/sys/dev/fdt/fdt_common.c | 206 | ||||
-rw-r--r-- | freebsd/sys/dev/fdt/fdt_common.h | 9 |
2 files changed, 46 insertions, 169 deletions
diff --git a/freebsd/sys/dev/fdt/fdt_common.c b/freebsd/sys/dev/fdt/fdt_common.c index de4a44b9..ff32dc0a 100644 --- a/freebsd/sys/dev/fdt/fdt_common.c +++ b/freebsd/sys/dev/fdt/fdt_common.c @@ -61,7 +61,6 @@ __FBSDID("$FreeBSD$"); #endif #define FDT_COMPAT_LEN 255 -#define FDT_TYPE_LEN 64 #define FDT_REG_CELLS 4 #define FDT_RANGES_SIZE 48 @@ -74,8 +73,6 @@ vm_offset_t fdt_immr_size; struct fdt_ic_list fdt_ic_list_head = SLIST_HEAD_INITIALIZER(fdt_ic_list_head); -static int fdt_is_compatible(phandle_t, const char *); - static int fdt_get_range_by_busaddr(phandle_t node, u_long addr, u_long *base, u_long *size) @@ -218,7 +215,7 @@ fdt_immr_addr(vm_offset_t immr_va) * Try to access the SOC node directly i.e. through /aliases/. */ if ((node = OF_finddevice("soc")) != -1) - if (fdt_is_compatible(node, "simple-bus")) + if (ofw_bus_node_is_compatible(node, "simple-bus")) goto moveon; /* * Find the node the long way. @@ -239,45 +236,6 @@ moveon: return (r); } -/* - * This routine is an early-usage version of the ofw_bus_is_compatible() when - * the ofw_bus I/F is not available (like early console routines and similar). - * Note the buffer has to be on the stack since malloc() is usually not - * available in such cases either. - */ -static int -fdt_is_compatible(phandle_t node, const char *compatstr) -{ - char buf[FDT_COMPAT_LEN]; - char *compat; - int len, onelen, l, rv; - - if ((len = OF_getproplen(node, "compatible")) <= 0) - return (0); - - compat = (char *)&buf; - bzero(compat, FDT_COMPAT_LEN); - - if (OF_getprop(node, "compatible", compat, FDT_COMPAT_LEN) < 0) - return (0); - - onelen = strlen(compatstr); - rv = 0; - while (len > 0) { - if (strncasecmp(compat, compatstr, onelen) == 0) { - /* Found it. */ - rv = 1; - break; - } - /* Slide to the next sub-string. */ - l = strlen(compat) + 1; - compat += l; - len -= l; - } - - return (rv); -} - int fdt_is_compatible_strict(phandle_t node, const char *compatible) { @@ -306,7 +264,7 @@ fdt_find_compatible(phandle_t start, const char *compat, int strict) * matching 'compatible' property. */ for (child = OF_child(start); child != 0; child = OF_peer(child)) - if (fdt_is_compatible(child, compat)) { + if (ofw_bus_node_is_compatible(child, compat)) { if (strict) if (!fdt_is_compatible_strict(child, compat)) continue; @@ -325,7 +283,7 @@ fdt_depth_search_compatible(phandle_t start, const char *compat, int strict) * matching 'compatible' property. */ for (node = OF_child(start); node != 0; node = OF_peer(node)) { - if (fdt_is_compatible(node, compat) && + if (ofw_bus_node_is_compatible(node, compat) && (strict == 0 || fdt_is_compatible_strict(node, compat))) { return (node); } @@ -337,46 +295,6 @@ fdt_depth_search_compatible(phandle_t start, const char *compat, int strict) } int -fdt_is_enabled(phandle_t node) -{ - char *stat; - int ena, len; - - len = OF_getprop_alloc(node, "status", sizeof(char), - (void **)&stat); - - if (len <= 0) - /* It is OK if no 'status' property. */ - return (1); - - /* Anything other than 'okay' means disabled. */ - ena = 0; - if (strncmp((char *)stat, "okay", len) == 0) - ena = 1; - - OF_prop_free(stat); - return (ena); -} - -int -fdt_is_type(phandle_t node, const char *typestr) -{ - char type[FDT_TYPE_LEN]; - - if (OF_getproplen(node, "device_type") <= 0) - return (0); - - if (OF_getprop(node, "device_type", type, FDT_TYPE_LEN) < 0) - return (0); - - if (strncasecmp(type, typestr, FDT_TYPE_LEN) == 0) - /* This fits. */ - return (1); - - return (0); -} - -int fdt_parent_addr_cells(phandle_t node) { pcell_t addr_cells; @@ -389,19 +307,6 @@ fdt_parent_addr_cells(phandle_t node) return ((int)fdt32_to_cpu(addr_cells)); } -int -fdt_pm_is_enabled(phandle_t node) -{ - int ret; - - ret = 1; - -#if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY) - ret = fdt_pm(node); -#endif - return (ret); -} - u_long fdt_data_get(void *data, int cells) { @@ -477,59 +382,6 @@ fdt_regsize(phandle_t node, u_long *base, u_long *size) } int -fdt_reg_to_rl(phandle_t node, struct resource_list *rl) -{ - u_long end, count, start; - pcell_t *reg, *regptr; - pcell_t addr_cells, size_cells; - int tuple_size, tuples; - int i, rv; - long busaddr, bussize; - - if (fdt_addrsize_cells(OF_parent(node), &addr_cells, &size_cells) != 0) - return (ENXIO); - if (fdt_get_range(OF_parent(node), 0, &busaddr, &bussize)) { - busaddr = 0; - bussize = 0; - } - - tuple_size = sizeof(pcell_t) * (addr_cells + size_cells); - tuples = OF_getprop_alloc(node, "reg", tuple_size, (void **)®); - debugf("addr_cells = %d, size_cells = %d\n", addr_cells, size_cells); - debugf("tuples = %d, tuple size = %d\n", tuples, tuple_size); - if (tuples <= 0) - /* No 'reg' property in this node. */ - return (0); - - regptr = reg; - for (i = 0; i < tuples; i++) { - - rv = fdt_data_to_res(reg, addr_cells, size_cells, &start, - &count); - if (rv != 0) { - resource_list_free(rl); - goto out; - } - reg += addr_cells + size_cells; - - /* Calculate address range relative to base. */ - start += busaddr; - end = start + count - 1; - - debugf("reg addr start = %lx, end = %lx, count = %lx\n", start, - end, count); - - resource_list_add(rl, SYS_RES_MEMORY, i, start, end, - count); - } - rv = 0; - -out: - OF_prop_free(regptr); - return (rv); -} - -int fdt_get_phyaddr(phandle_t node, device_t dev, int *phy_addr, void **phy_sc) { phandle_t phy_node; @@ -650,6 +502,47 @@ out: } int +fdt_get_reserved_mem(struct mem_region *reserved, int *mreserved) +{ + pcell_t reg[FDT_REG_CELLS]; + phandle_t child, root; + int addr_cells, size_cells; + int i, rv; + + root = OF_finddevice("/reserved-memory"); + if (root == -1) { + return (ENXIO); + } + + if ((rv = fdt_addrsize_cells(root, &addr_cells, &size_cells)) != 0) + return (rv); + + if (addr_cells + size_cells > FDT_REG_CELLS) + panic("Too many address and size cells %d %d", addr_cells, + size_cells); + + i = 0; + for (child = OF_child(root); child != 0; child = OF_peer(child)) { + if (!OF_hasprop(child, "no-map")) + continue; + + rv = OF_getprop(child, "reg", reg, sizeof(reg)); + if (rv <= 0) + /* XXX: Does a no-map of a dynamic range make sense? */ + continue; + + fdt_data_to_res(reg, addr_cells, size_cells, + (u_long *)&reserved[i].mr_start, + (u_long *)&reserved[i].mr_size); + i++; + } + + *mreserved = i; + + return (0); +} + +int fdt_get_mem_regions(struct mem_region *mr, int *mrcnt, uint64_t *memsize) { pcell_t reg[FDT_REG_CELLS * FDT_MEM_REGIONS]; @@ -715,17 +608,6 @@ out: } int -fdt_get_unit(device_t dev) -{ - const char * name; - - name = ofw_bus_get_name(dev); - name = strchr(name, '@') + 1; - - return (strtol(name,NULL,0)); -} - -int fdt_get_chosen_bootargs(char *bootargs, size_t max_size) { phandle_t chosen; diff --git a/freebsd/sys/dev/fdt/fdt_common.h b/freebsd/sys/dev/fdt/fdt_common.h index 91522df5..3bf4df41 100644 --- a/freebsd/sys/dev/fdt/fdt_common.h +++ b/freebsd/sys/dev/fdt/fdt_common.h @@ -39,7 +39,7 @@ #include <contrib/libfdt/libfdt_env.h> #include <dev/ofw/ofw_bus.h> -#define FDT_MEM_REGIONS 8 +#define FDT_MEM_REGIONS 16 #define DI_MAX_INTR_NUM 32 @@ -85,19 +85,14 @@ int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *); phandle_t fdt_find_compatible(phandle_t, const char *, int); phandle_t fdt_depth_search_compatible(phandle_t, const char *, int); int fdt_get_mem_regions(struct mem_region *, int *, uint64_t *); +int fdt_get_reserved_mem(struct mem_region *, int *); int fdt_get_reserved_regions(struct mem_region *, int *); int fdt_get_phyaddr(phandle_t, device_t, int *, void **); int fdt_get_range(phandle_t, int, u_long *, u_long *); int fdt_immr_addr(vm_offset_t); int fdt_regsize(phandle_t, u_long *, u_long *); int fdt_is_compatible_strict(phandle_t, const char *); -int fdt_is_enabled(phandle_t); -int fdt_pm_is_enabled(phandle_t); -int fdt_is_type(phandle_t, const char *); int fdt_parent_addr_cells(phandle_t); -int fdt_reg_to_rl(phandle_t, struct resource_list *); -int fdt_pm(phandle_t); -int fdt_get_unit(device_t); int fdt_get_chosen_bootargs(char *bootargs, size_t max_size); #endif /* _FDT_COMMON_H_ */ |