lpi_base.start = addr;
lpi_base.end = addr + size - 1;
ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL,
- NULL, 0, false);
+ NULL, 0, 0);
if (ret) {
debug("%s: failed to add reserved memory\n", __func__);
return ret;
pmp_mem.start = addr;
pmp_mem.end = addr + size - 1;
err = fdtdec_add_reserved_memory(dst, basename, &pmp_mem,
- NULL, 0, &phandle, false);
+ NULL, 0, &phandle, 0);
if (err < 0 && err != -FDT_ERR_EXISTS) {
log_err("failed to add reserved memory: %d\n", err);
return err;
int err;
err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
- NULL, NULL);
+ NULL, NULL, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
}
err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
- "framebuffer", NULL, 0);
+ "framebuffer", NULL, 0, 0);
if (err < 0) {
printf("failed to set carveout for %s: %d\n", node, err);
return err;
int err;
err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
- NULL, NULL);
+ NULL, NULL, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
}
err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
- "framebuffer", NULL, 0);
+ "framebuffer", NULL, 0, 0);
if (err < 0) {
printf("failed to set carveout for %s: %d\n", node, err);
return err;
int err;
err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
- NULL, NULL);
+ NULL, NULL, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
}
err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
- "framebuffer", NULL, 0);
+ "framebuffer", NULL, 0, 0);
if (err < 0) {
printf("failed to set carveout for %s: %d\n", node, err);
return err;
return fdt_setprop_u32(blob, node, "phandle", phandle);
}
+/* add "no-map" property */
+#define FDTDEC_RESERVED_MEMORY_NO_MAP (1 << 0)
+
/**
* fdtdec_add_reserved_memory() - add or find a reserved-memory node
*
* uint32_t phandle;
*
* fdtdec_add_reserved_memory(fdt, "framebuffer", &fb, NULL, 0, &phandle,
- * false);
+ * 0);
*
* This results in the following subnode being added to the top-level
* /reserved-memory node:
* @param count number of compatible strings for the carveout region
* @param phandlep return location for the phandle of the carveout region
* can be NULL if no phandle should be added
- * @param no_map add "no-map" property if true
+ * @param flags bitmask of flags to set for the carveout region
* @return 0 on success or a negative error code on failure
*/
int fdtdec_add_reserved_memory(void *blob, const char *basename,
const struct fdt_memory *carveout,
const char **compatibles, unsigned int count,
- uint32_t *phandlep, bool no_map);
+ uint32_t *phandlep, unsigned long flags);
/**
* fdtdec_get_carveout() - reads a carveout from an FDT
* @param carveout return location for the carveout information
* @param name return location for the carveout name
* @param compatiblesp return location for compatible strings
- * @param countp return location for the number of compatible strings
+ * @param countp return location for the number of compatible strings
+ * @param flags return location for the flags of the carveout
* @return 0 on success or a negative error code on failure
*/
int fdtdec_get_carveout(const void *blob, const char *node,
const char *prop_name, unsigned int index,
struct fdt_memory *carveout, const char **name,
- const char ***compatiblesp, unsigned int *countp);
+ const char ***compatiblesp, unsigned int *countp,
+ unsigned long *flags);
/**
* fdtdec_set_carveout() - sets a carveout region for a given node
* };
*
* fdtdec_set_carveout(fdt, node, "memory-region", 0, "framebuffer", NULL,
- * 0, &fb);
+ * 0, &fb, 0);
*
* dc@54200000 is a display controller and was set up by the bootloader to
* scan out the framebuffer specified by "fb". This would cause the following
* @param name base name of the reserved-memory node to create
* @param compatibles compatible strings to set for the carveout
* @param count number of compatible strings
+ * @param flags bitmask of flags to set for the carveout
* @return 0 on success or a negative error code on failure
*/
int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
unsigned int index, const struct fdt_memory *carveout,
const char *name, const char **compatibles,
- unsigned int count);
+ unsigned int count, unsigned long flags);
/**
* Set up the device tree ready for use
int fdtdec_add_reserved_memory(void *blob, const char *basename,
const struct fdt_memory *carveout,
const char **compatibles, unsigned int count,
- uint32_t *phandlep, bool no_map)
+ uint32_t *phandlep, unsigned long flags)
{
fdt32_t cells[4] = {}, *ptr = cells;
uint32_t upper, lower, phandle;
if (node < 0)
return node;
+ if (flags & FDTDEC_RESERVED_MEMORY_NO_MAP) {
+ err = fdt_setprop(blob, node, "no-map", NULL, 0);
+ if (err < 0)
+ return err;
+ }
+
if (phandlep) {
err = fdt_generate_phandle(blob, &phandle);
if (err < 0)
if (err < 0)
return err;
- if (no_map) {
- err = fdt_setprop(blob, node, "no-map", NULL, 0);
- if (err < 0)
- return err;
- }
-
if (compatibles && count > 0) {
size_t length = 0, len = 0;
unsigned int i;
int fdtdec_get_carveout(const void *blob, const char *node,
const char *prop_name, unsigned int index,
struct fdt_memory *carveout, const char **name,
- const char ***compatiblesp, unsigned int *countp)
+ const char ***compatiblesp, unsigned int *countp,
+ unsigned long *flags)
{
const fdt32_t *prop;
uint32_t phandle;
carveout->end = carveout->start + size - 1;
+ if (flags) {
+ *flags = 0;
+
+ if (fdtdec_get_bool(blob, offset, "no-map"))
+ *flags |= FDTDEC_RESERVED_MEMORY_NO_MAP;
+ }
+
return 0;
}
int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
unsigned int index, const struct fdt_memory *carveout,
const char *name, const char **compatibles,
- unsigned int count)
+ unsigned int count, unsigned long flags)
{
uint32_t phandle;
int err, offset, len;
void *prop;
err = fdtdec_add_reserved_memory(blob, name, carveout, compatibles,
- count, &phandle, false);
+ count, &phandle, flags);
if (err < 0) {
debug("failed to add reserved memory: %d\n", err);
return err;
CHECK(fdt_setprop(fdt, offset, "reg", cells, (na + ns) * sizeof(*cells)));
return fdtdec_set_carveout(fdt, name, "memory-region", 0, &carveout,
- "framebuffer", NULL, 0);
+ "framebuffer", NULL, 0, 0);
}
static int check_fdt_carveout(void *fdt, uint32_t address_cells,
&expected.end, address_cells, size_cells);
CHECK(fdtdec_get_carveout(fdt, name, "memory-region", 0, &carveout,
- NULL, NULL, NULL));
+ NULL, NULL, NULL, NULL));
if ((carveout.start != expected.start) ||
(carveout.end != expected.end)) {
.start = res.start,
.end = res.end,
};
+ unsigned long flags = FDTDEC_RESERVED_MEMORY_NO_MAP;
char *oldname, *nodename, *tmp;
oldname = strdup(name);
nodename,
&carveout,
NULL, 0,
- NULL, true);
+ NULL, flags);
free(oldname);
if (ret < 0)
resv.start = 0x1000;
resv.end = 0x2000;
ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 2,
- &resv, "test_resv1", NULL, 0));
+ &resv, "test_resv1", NULL, 0, 0));
resv.start = 0x10000;
resv.end = 0x20000;
ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 1,
- &resv, "test_resv2", NULL, 0));
+ &resv, "test_resv2", NULL, 0, 0));
resv.start = 0x100000;
resv.end = 0x200000;
ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 0,
- &resv, "test_resv3", NULL, 0));
+ &resv, "test_resv3", NULL, 0, 0));
offset = fdt_path_offset(blob, "/a-test");
ut_assert(offset > 0);
fdt_addr_t addr;
fdt_size_t size;
void *blob;
+ unsigned long flags = FDTDEC_RESERVED_MEMORY_NO_MAP;
int blob_sz, parent, subnode;
uint32_t phandle, phandle1;
resv.start = 0x1000;
resv.end = 0x1fff;
ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region", &resv,
- NULL, 0, &phandle, false));
+ NULL, 0, &phandle, 0));
/* Test /reserve-memory and its subnode should exist */
parent = fdt_path_offset(blob, "/reserved-memory");
resv.start = 0x2000;
resv.end = 0x2fff;
ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1", &resv,
- NULL, 0, &phandle1, true));
+ NULL, 0, &phandle1, flags));
subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
ut_assert(subnode > 0);
resv.start = 0x1000;
resv.end = 0x1fff;
ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2", &resv,
- NULL, 0, &phandle1, false));
+ NULL, 0, &phandle1, 0));
subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2");
ut_assert(subnode < 0);