/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_FDT_HEADER #define VAS_EBOOT_FDT_HEADER 1 #include #include /* Space required when preparing the /chosen node after boot has been called. */ #define VAS_EBOOT_EFI_LINUX_FDT_EXTRA_SPACE 0x400 #define FDT_MAGIC 0xD00DFEED typedef struct { VasEBoot_uint32_t magic; VasEBoot_uint32_t totalsize; VasEBoot_uint32_t off_dt_struct; VasEBoot_uint32_t off_dt_strings; VasEBoot_uint32_t off_mem_rsvmap; VasEBoot_uint32_t version; VasEBoot_uint32_t last_comp_version; VasEBoot_uint32_t boot_cpuid_phys; VasEBoot_uint32_t size_dt_strings; VasEBoot_uint32_t size_dt_struct; } VasEBoot_fdt_header_t; struct VasEBoot_fdt_empty_tree { VasEBoot_fdt_header_t header; VasEBoot_uint64_t empty_rsvmap[2]; struct { VasEBoot_uint32_t node_start; VasEBoot_uint8_t name[1]; VasEBoot_uint32_t node_end; VasEBoot_uint32_t tree_end; } empty_node; }; #define VAS_EBOOT_FDT_EMPTY_TREE_SZ sizeof (struct VasEBoot_fdt_empty_tree) /* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff fields, plus the property value, plus padding if needed. */ #define VasEBoot_fdt_prop_entry_size(prop_len) \ (3 * sizeof(VasEBoot_uint32_t) + ALIGN_UP(prop_len, sizeof(VasEBoot_uint32_t))) #define VasEBoot_fdt_get_header(fdt, field) \ VasEBoot_be_to_cpu32(((const VasEBoot_fdt_header_t *)(fdt))->field) #define VasEBoot_fdt_set_header(fdt, field, value) \ ((VasEBoot_fdt_header_t *)(fdt))->field = VasEBoot_cpu_to_be32(value) #define VasEBoot_fdt_get_magic(fdt) \ VasEBoot_fdt_get_header(fdt, magic) #define VasEBoot_fdt_set_magic(fdt, value) \ VasEBoot_fdt_set_header(fdt, magic, value) #define VasEBoot_fdt_get_totalsize(fdt) \ VasEBoot_fdt_get_header(fdt, totalsize) #define VasEBoot_fdt_set_totalsize(fdt, value) \ VasEBoot_fdt_set_header(fdt, totalsize, value) #define VasEBoot_fdt_get_off_dt_struct(fdt) \ VasEBoot_fdt_get_header(fdt, off_dt_struct) #define VasEBoot_fdt_set_off_dt_struct(fdt, value) \ VasEBoot_fdt_set_header(fdt, off_dt_struct, value) #define VasEBoot_fdt_get_off_dt_strings(fdt) \ VasEBoot_fdt_get_header(fdt, off_dt_strings) #define VasEBoot_fdt_set_off_dt_strings(fdt, value) \ VasEBoot_fdt_set_header(fdt, off_dt_strings, value) #define VasEBoot_fdt_get_off_mem_rsvmap(fdt) \ VasEBoot_fdt_get_header(fdt, off_mem_rsvmap) #define VasEBoot_fdt_set_off_mem_rsvmap(fdt, value) \ VasEBoot_fdt_set_header(fdt, off_mem_rsvmap, value) #define VasEBoot_fdt_get_version(fdt) \ VasEBoot_fdt_get_header(fdt, version) #define VasEBoot_fdt_set_version(fdt, value) \ VasEBoot_fdt_set_header(fdt, version, value) #define VasEBoot_fdt_get_last_comp_version(fdt) \ VasEBoot_fdt_get_header(fdt, last_comp_version) #define VasEBoot_fdt_set_last_comp_version(fdt, value) \ VasEBoot_fdt_set_header(fdt, last_comp_version, value) #define VasEBoot_fdt_get_boot_cpuid_phys(fdt) \ VasEBoot_fdt_get_header(fdt, boot_cpuid_phys) #define VasEBoot_fdt_set_boot_cpuid_phys(fdt, value) \ VasEBoot_fdt_set_header(fdt, boot_cpuid_phys, value) #define VasEBoot_fdt_get_size_dt_strings(fdt) \ VasEBoot_fdt_get_header(fdt, size_dt_strings) #define VasEBoot_fdt_set_size_dt_strings(fdt, value) \ VasEBoot_fdt_set_header(fdt, size_dt_strings, value) #define VasEBoot_fdt_get_size_dt_struct(fdt) \ VasEBoot_fdt_get_header(fdt, size_dt_struct) #define VasEBoot_fdt_set_size_dt_struct(fdt, value) \ VasEBoot_fdt_set_header(fdt, size_dt_struct, value) int EXPORT_FUNC(VasEBoot_fdt_create_empty_tree) (void *fdt, unsigned int size); int EXPORT_FUNC(VasEBoot_fdt_check_header) (const void *fdt, unsigned int size); int EXPORT_FUNC(VasEBoot_fdt_check_header_nosize) (const void *fdt); int EXPORT_FUNC(VasEBoot_fdt_find_subnode) (const void *fdt, unsigned int parentoffset, const char *name); int EXPORT_FUNC(VasEBoot_fdt_first_node) (const void *fdt, unsigned int parentoffset); int EXPORT_FUNC(VasEBoot_fdt_next_node) (const void *fdt, unsigned int currentoffset); int EXPORT_FUNC(VasEBoot_fdt_add_subnode) (void *fdt, unsigned int parentoffset, const char *name); const char * EXPORT_FUNC(VasEBoot_fdt_get_nodename) (const void *fdt, unsigned int nodeoffset); const void *EXPORT_FUNC(VasEBoot_fdt_get_prop) (const void *fdt, unsigned int nodeoffset, const char *name, VasEBoot_uint32_t *len); int EXPORT_FUNC(VasEBoot_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const char *name, const void *val, VasEBoot_uint32_t len); #define VasEBoot_fdt_set_prop32(fdt, nodeoffset, name, val) \ ({ \ VasEBoot_uint32_t _val = VasEBoot_cpu_to_be32(val); \ VasEBoot_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 4); \ }) #define VasEBoot_fdt_set_prop64(fdt, nodeoffset, name, val) \ ({ \ VasEBoot_uint64_t _val = VasEBoot_cpu_to_be64(val); \ VasEBoot_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 8); \ }) /* Setup "reg" property for * #address-cells = <0x2> * #size-cells = <0x2> */ #define VasEBoot_fdt_set_reg64(fdt, nodeoffset, addr, size) \ ({ \ VasEBoot_uint64_t reg_64[2]; \ reg_64[0] = VasEBoot_cpu_to_be64(addr); \ reg_64[1] = VasEBoot_cpu_to_be64(size); \ VasEBoot_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ }) #endif /* ! VAS_EBOOT_FDT_HEADER */