|
@@ -51,7 +51,7 @@ DECLARE_GLOBAL_DATA_PTR;
|
|
u32 fdt_getprop_u32_default(const void *fdt, const char *path,
|
|
u32 fdt_getprop_u32_default(const void *fdt, const char *path,
|
|
const char *prop, const u32 dflt)
|
|
const char *prop, const u32 dflt)
|
|
{
|
|
{
|
|
- const u32 *val;
|
|
|
|
|
|
+ const fdt32_t *val;
|
|
int off;
|
|
int off;
|
|
|
|
|
|
off = fdt_path_offset(fdt, path);
|
|
off = fdt_path_offset(fdt, path);
|
|
@@ -85,7 +85,7 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
|
|
if (nodeoff < 0)
|
|
if (nodeoff < 0)
|
|
return nodeoff;
|
|
return nodeoff;
|
|
|
|
|
|
- if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL))
|
|
|
|
|
|
+ if ((!create) && (fdt_get_property(fdt, nodeoff, prop, NULL) == NULL))
|
|
return 0; /* create flag not set; so exit quietly */
|
|
return 0; /* create flag not set; so exit quietly */
|
|
|
|
|
|
return fdt_setprop(fdt, nodeoff, prop, val, len);
|
|
return fdt_setprop(fdt, nodeoff, prop, val, len);
|
|
@@ -149,7 +149,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
|
|
{
|
|
{
|
|
int nodeoffset;
|
|
int nodeoffset;
|
|
int err, j, total;
|
|
int err, j, total;
|
|
- u32 tmp;
|
|
|
|
|
|
+ fdt32_t tmp;
|
|
const char *path;
|
|
const char *path;
|
|
uint64_t addr, size;
|
|
uint64_t addr, size;
|
|
|
|
|
|
@@ -188,7 +188,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
|
|
|
|
|
|
path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
|
|
path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
|
|
if ((path == NULL) || force) {
|
|
if ((path == NULL) || force) {
|
|
- tmp = __cpu_to_be32(initrd_start);
|
|
|
|
|
|
+ tmp = cpu_to_fdt32(initrd_start);
|
|
err = fdt_setprop(fdt, nodeoffset,
|
|
err = fdt_setprop(fdt, nodeoffset,
|
|
"linux,initrd-start", &tmp, sizeof(tmp));
|
|
"linux,initrd-start", &tmp, sizeof(tmp));
|
|
if (err < 0) {
|
|
if (err < 0) {
|
|
@@ -197,7 +197,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
|
|
fdt_strerror(err));
|
|
fdt_strerror(err));
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
- tmp = __cpu_to_be32(initrd_end);
|
|
|
|
|
|
+ tmp = cpu_to_fdt32(initrd_end);
|
|
err = fdt_setprop(fdt, nodeoffset,
|
|
err = fdt_setprop(fdt, nodeoffset,
|
|
"linux,initrd-end", &tmp, sizeof(tmp));
|
|
"linux,initrd-end", &tmp, sizeof(tmp));
|
|
if (err < 0) {
|
|
if (err < 0) {
|
|
@@ -300,8 +300,8 @@ void do_fixup_by_path(void *fdt, const char *path, const char *prop,
|
|
void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
|
|
void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
|
|
u32 val, int create)
|
|
u32 val, int create)
|
|
{
|
|
{
|
|
- val = cpu_to_fdt32(val);
|
|
|
|
- do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create);
|
|
|
|
|
|
+ fdt32_t tmp = cpu_to_fdt32(val);
|
|
|
|
+ do_fixup_by_path(fdt, path, prop, &tmp, sizeof(tmp), create);
|
|
}
|
|
}
|
|
|
|
|
|
void do_fixup_by_prop(void *fdt,
|
|
void do_fixup_by_prop(void *fdt,
|
|
@@ -319,7 +319,7 @@ void do_fixup_by_prop(void *fdt,
|
|
#endif
|
|
#endif
|
|
off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen);
|
|
off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen);
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
- if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
|
|
|
|
|
|
+ if (create || (fdt_get_property(fdt, off, prop, NULL) != NULL))
|
|
fdt_setprop(fdt, off, prop, val, len);
|
|
fdt_setprop(fdt, off, prop, val, len);
|
|
off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen);
|
|
off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen);
|
|
}
|
|
}
|
|
@@ -329,8 +329,8 @@ void do_fixup_by_prop_u32(void *fdt,
|
|
const char *pname, const void *pval, int plen,
|
|
const char *pname, const void *pval, int plen,
|
|
const char *prop, u32 val, int create)
|
|
const char *prop, u32 val, int create)
|
|
{
|
|
{
|
|
- val = cpu_to_fdt32(val);
|
|
|
|
- do_fixup_by_prop(fdt, pname, pval, plen, prop, &val, 4, create);
|
|
|
|
|
|
+ fdt32_t tmp = cpu_to_fdt32(val);
|
|
|
|
+ do_fixup_by_prop(fdt, pname, pval, plen, prop, &tmp, 4, create);
|
|
}
|
|
}
|
|
|
|
|
|
void do_fixup_by_compat(void *fdt, const char *compat,
|
|
void do_fixup_by_compat(void *fdt, const char *compat,
|
|
@@ -346,7 +346,7 @@ void do_fixup_by_compat(void *fdt, const char *compat,
|
|
#endif
|
|
#endif
|
|
off = fdt_node_offset_by_compatible(fdt, -1, compat);
|
|
off = fdt_node_offset_by_compatible(fdt, -1, compat);
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
- if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
|
|
|
|
|
|
+ if (create || (fdt_get_property(fdt, off, prop, NULL) != NULL))
|
|
fdt_setprop(fdt, off, prop, val, len);
|
|
fdt_setprop(fdt, off, prop, val, len);
|
|
off = fdt_node_offset_by_compatible(fdt, off, compat);
|
|
off = fdt_node_offset_by_compatible(fdt, off, compat);
|
|
}
|
|
}
|
|
@@ -355,8 +355,8 @@ void do_fixup_by_compat(void *fdt, const char *compat,
|
|
void do_fixup_by_compat_u32(void *fdt, const char *compat,
|
|
void do_fixup_by_compat_u32(void *fdt, const char *compat,
|
|
const char *prop, u32 val, int create)
|
|
const char *prop, u32 val, int create)
|
|
{
|
|
{
|
|
- val = cpu_to_fdt32(val);
|
|
|
|
- do_fixup_by_compat(fdt, compat, prop, &val, 4, create);
|
|
|
|
|
|
+ fdt32_t tmp = cpu_to_fdt32(val);
|
|
|
|
+ do_fixup_by_compat(fdt, compat, prop, &tmp, 4, create);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -366,7 +366,7 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
|
|
*/
|
|
*/
|
|
static int get_cells_len(void *blob, char *nr_cells_name)
|
|
static int get_cells_len(void *blob, char *nr_cells_name)
|
|
{
|
|
{
|
|
- const u32 *cell;
|
|
|
|
|
|
+ const fdt32_t *cell;
|
|
|
|
|
|
cell = fdt_getprop(blob, 0, nr_cells_name, NULL);
|
|
cell = fdt_getprop(blob, 0, nr_cells_name, NULL);
|
|
if (cell && fdt32_to_cpu(*cell) == 2)
|
|
if (cell && fdt32_to_cpu(*cell) == 2)
|
|
@@ -387,13 +387,21 @@ static void write_cell(u8 *addr, u64 val, int size)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#define MEMORY_BANKS_MAX 4
|
|
int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
|
|
int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
|
|
{
|
|
{
|
|
int err, nodeoffset;
|
|
int err, nodeoffset;
|
|
int addr_cell_len, size_cell_len, len;
|
|
int addr_cell_len, size_cell_len, len;
|
|
- u8 tmp[banks * 16]; /* Up to 64-bit address + 64-bit size */
|
|
|
|
|
|
+ u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */
|
|
int bank;
|
|
int bank;
|
|
|
|
|
|
|
|
+ if (banks > MEMORY_BANKS_MAX) {
|
|
|
|
+ printf("%s: num banks %d exceeds hardcoded limit %d."
|
|
|
|
+ " Recompile with higher MEMORY_BANKS_MAX?\n",
|
|
|
|
+ __FUNCTION__, banks, MEMORY_BANKS_MAX);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
err = fdt_check_header(blob);
|
|
err = fdt_check_header(blob);
|
|
if (err < 0) {
|
|
if (err < 0) {
|
|
printf("%s: %s\n", __FUNCTION__, fdt_strerror(err));
|
|
printf("%s: %s\n", __FUNCTION__, fdt_strerror(err));
|
|
@@ -902,11 +910,11 @@ void fdt_del_node_and_alias(void *blob, const char *alias)
|
|
}
|
|
}
|
|
|
|
|
|
/* Helper to read a big number; size is in cells (not bytes) */
|
|
/* Helper to read a big number; size is in cells (not bytes) */
|
|
-static inline u64 of_read_number(const __be32 *cell, int size)
|
|
|
|
|
|
+static inline u64 of_read_number(const fdt32_t *cell, int size)
|
|
{
|
|
{
|
|
u64 r = 0;
|
|
u64 r = 0;
|
|
while (size--)
|
|
while (size--)
|
|
- r = (r << 32) | be32_to_cpu(*(cell++));
|
|
|
|
|
|
+ r = (r << 32) | fdt32_to_cpu(*(cell++));
|
|
return r;
|
|
return r;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -920,7 +928,7 @@ static inline u64 of_read_number(const __be32 *cell, int size)
|
|
|
|
|
|
/* Debug utility */
|
|
/* Debug utility */
|
|
#ifdef DEBUG
|
|
#ifdef DEBUG
|
|
-static void of_dump_addr(const char *s, const u32 *addr, int na)
|
|
|
|
|
|
+static void of_dump_addr(const char *s, const fdt32_t *addr, int na)
|
|
{
|
|
{
|
|
printf("%s", s);
|
|
printf("%s", s);
|
|
while(na--)
|
|
while(na--)
|
|
@@ -928,7 +936,7 @@ static void of_dump_addr(const char *s, const u32 *addr, int na)
|
|
printf("\n");
|
|
printf("\n");
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
-static void of_dump_addr(const char *s, const u32 *addr, int na) { }
|
|
|
|
|
|
+static void of_dump_addr(const char *s, const fdt32_t *addr, int na) { }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
/* Callbacks for bus specific translators */
|
|
/* Callbacks for bus specific translators */
|
|
@@ -937,21 +945,21 @@ struct of_bus {
|
|
const char *addresses;
|
|
const char *addresses;
|
|
void (*count_cells)(void *blob, int parentoffset,
|
|
void (*count_cells)(void *blob, int parentoffset,
|
|
int *addrc, int *sizec);
|
|
int *addrc, int *sizec);
|
|
- u64 (*map)(u32 *addr, const u32 *range,
|
|
|
|
|
|
+ u64 (*map)(fdt32_t *addr, const fdt32_t *range,
|
|
int na, int ns, int pna);
|
|
int na, int ns, int pna);
|
|
- int (*translate)(u32 *addr, u64 offset, int na);
|
|
|
|
|
|
+ int (*translate)(fdt32_t *addr, u64 offset, int na);
|
|
};
|
|
};
|
|
|
|
|
|
/* Default translator (generic bus) */
|
|
/* Default translator (generic bus) */
|
|
static void of_bus_default_count_cells(void *blob, int parentoffset,
|
|
static void of_bus_default_count_cells(void *blob, int parentoffset,
|
|
int *addrc, int *sizec)
|
|
int *addrc, int *sizec)
|
|
{
|
|
{
|
|
- const u32 *prop;
|
|
|
|
|
|
+ const fdt32_t *prop;
|
|
|
|
|
|
if (addrc) {
|
|
if (addrc) {
|
|
prop = fdt_getprop(blob, parentoffset, "#address-cells", NULL);
|
|
prop = fdt_getprop(blob, parentoffset, "#address-cells", NULL);
|
|
if (prop)
|
|
if (prop)
|
|
- *addrc = be32_to_cpup((u32 *)prop);
|
|
|
|
|
|
+ *addrc = be32_to_cpup(prop);
|
|
else
|
|
else
|
|
*addrc = 2;
|
|
*addrc = 2;
|
|
}
|
|
}
|
|
@@ -959,13 +967,13 @@ static void of_bus_default_count_cells(void *blob, int parentoffset,
|
|
if (sizec) {
|
|
if (sizec) {
|
|
prop = fdt_getprop(blob, parentoffset, "#size-cells", NULL);
|
|
prop = fdt_getprop(blob, parentoffset, "#size-cells", NULL);
|
|
if (prop)
|
|
if (prop)
|
|
- *sizec = be32_to_cpup((u32 *)prop);
|
|
|
|
|
|
+ *sizec = be32_to_cpup(prop);
|
|
else
|
|
else
|
|
*sizec = 1;
|
|
*sizec = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static u64 of_bus_default_map(u32 *addr, const u32 *range,
|
|
|
|
|
|
+static u64 of_bus_default_map(fdt32_t *addr, const fdt32_t *range,
|
|
int na, int ns, int pna)
|
|
int na, int ns, int pna)
|
|
{
|
|
{
|
|
u64 cp, s, da;
|
|
u64 cp, s, da;
|
|
@@ -982,14 +990,14 @@ static u64 of_bus_default_map(u32 *addr, const u32 *range,
|
|
return da - cp;
|
|
return da - cp;
|
|
}
|
|
}
|
|
|
|
|
|
-static int of_bus_default_translate(u32 *addr, u64 offset, int na)
|
|
|
|
|
|
+static int of_bus_default_translate(fdt32_t *addr, u64 offset, int na)
|
|
{
|
|
{
|
|
u64 a = of_read_number(addr, na);
|
|
u64 a = of_read_number(addr, na);
|
|
memset(addr, 0, na * 4);
|
|
memset(addr, 0, na * 4);
|
|
a += offset;
|
|
a += offset;
|
|
if (na > 1)
|
|
if (na > 1)
|
|
- addr[na - 2] = a >> 32;
|
|
|
|
- addr[na - 1] = a & 0xffffffffu;
|
|
|
|
|
|
+ addr[na - 2] = cpu_to_fdt32(a >> 32);
|
|
|
|
+ addr[na - 1] = cpu_to_fdt32(a & 0xffffffffu);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1007,10 +1015,10 @@ static struct of_bus of_busses[] = {
|
|
};
|
|
};
|
|
|
|
|
|
static int of_translate_one(void * blob, int parent, struct of_bus *bus,
|
|
static int of_translate_one(void * blob, int parent, struct of_bus *bus,
|
|
- struct of_bus *pbus, u32 *addr,
|
|
|
|
|
|
+ struct of_bus *pbus, fdt32_t *addr,
|
|
int na, int ns, int pna, const char *rprop)
|
|
int na, int ns, int pna, const char *rprop)
|
|
{
|
|
{
|
|
- const u32 *ranges;
|
|
|
|
|
|
+ const fdt32_t *ranges;
|
|
int rlen;
|
|
int rlen;
|
|
int rone;
|
|
int rone;
|
|
u64 offset = OF_BAD_ADDR;
|
|
u64 offset = OF_BAD_ADDR;
|
|
@@ -1027,7 +1035,7 @@ static int of_translate_one(void * blob, int parent, struct of_bus *bus,
|
|
* to translate addresses that aren't supposed to be translated in
|
|
* to translate addresses that aren't supposed to be translated in
|
|
* the first place. --BenH.
|
|
* the first place. --BenH.
|
|
*/
|
|
*/
|
|
- ranges = (u32 *)fdt_getprop(blob, parent, rprop, &rlen);
|
|
|
|
|
|
+ ranges = fdt_getprop(blob, parent, rprop, &rlen);
|
|
if (ranges == NULL || rlen == 0) {
|
|
if (ranges == NULL || rlen == 0) {
|
|
offset = of_read_number(addr, na);
|
|
offset = of_read_number(addr, na);
|
|
memset(addr, 0, pna * 4);
|
|
memset(addr, 0, pna * 4);
|
|
@@ -1069,12 +1077,12 @@ static int of_translate_one(void * blob, int parent, struct of_bus *bus,
|
|
* that can be mapped to a cpu physical address). This is not really specified
|
|
* that can be mapped to a cpu physical address). This is not really specified
|
|
* that way, but this is traditionally the way IBM at least do things
|
|
* that way, but this is traditionally the way IBM at least do things
|
|
*/
|
|
*/
|
|
-u64 __of_translate_address(void *blob, int node_offset, const u32 *in_addr,
|
|
|
|
- const char *rprop)
|
|
|
|
|
|
+static u64 __of_translate_address(void *blob, int node_offset, const fdt32_t *in_addr,
|
|
|
|
+ const char *rprop)
|
|
{
|
|
{
|
|
int parent;
|
|
int parent;
|
|
struct of_bus *bus, *pbus;
|
|
struct of_bus *bus, *pbus;
|
|
- u32 addr[OF_MAX_ADDR_CELLS];
|
|
|
|
|
|
+ fdt32_t addr[OF_MAX_ADDR_CELLS];
|
|
int na, ns, pna, pns;
|
|
int na, ns, pna, pns;
|
|
u64 result = OF_BAD_ADDR;
|
|
u64 result = OF_BAD_ADDR;
|
|
|
|
|
|
@@ -1142,7 +1150,7 @@ u64 __of_translate_address(void *blob, int node_offset, const u32 *in_addr,
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
-u64 fdt_translate_address(void *blob, int node_offset, const u32 *in_addr)
|
|
|
|
|
|
+u64 fdt_translate_address(void *blob, int node_offset, const fdt32_t *in_addr)
|
|
{
|
|
{
|
|
return __of_translate_address(blob, node_offset, in_addr, "ranges");
|
|
return __of_translate_address(blob, node_offset, in_addr, "ranges");
|
|
}
|
|
}
|
|
@@ -1161,7 +1169,7 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat,
|
|
{
|
|
{
|
|
int len, off = fdt_node_offset_by_compatible(blob, -1, compat);
|
|
int len, off = fdt_node_offset_by_compatible(blob, -1, compat);
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
while (off != -FDT_ERR_NOTFOUND) {
|
|
- u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len);
|
|
|
|
|
|
+ const fdt32_t *reg = fdt_getprop(blob, off, "reg", &len);
|
|
if (reg) {
|
|
if (reg) {
|
|
if (compat_off == fdt_translate_address(blob, off, reg))
|
|
if (compat_off == fdt_translate_address(blob, off, reg))
|
|
return off;
|
|
return off;
|
|
@@ -1355,7 +1363,7 @@ err_size:
|
|
int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr)
|
|
int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr)
|
|
{
|
|
{
|
|
const char *path;
|
|
const char *path;
|
|
- const u32 *reg;
|
|
|
|
|
|
+ const fdt32_t *reg;
|
|
int node, len;
|
|
int node, len;
|
|
u64 dt_addr;
|
|
u64 dt_addr;
|
|
|
|
|
|
@@ -1397,11 +1405,11 @@ u64 fdt_get_base_address(void *fdt, int node)
|
|
{
|
|
{
|
|
int size;
|
|
int size;
|
|
u32 naddr;
|
|
u32 naddr;
|
|
- const u32 *prop;
|
|
|
|
|
|
+ const fdt32_t *prop;
|
|
|
|
|
|
prop = fdt_getprop(fdt, node, "#address-cells", &size);
|
|
prop = fdt_getprop(fdt, node, "#address-cells", &size);
|
|
if (prop && size == 4)
|
|
if (prop && size == 4)
|
|
- naddr = *prop;
|
|
|
|
|
|
+ naddr = be32_to_cpup(prop);
|
|
else
|
|
else
|
|
naddr = 2;
|
|
naddr = 2;
|
|
|
|
|