dtc: Merge refs and labels into single "markers" list (v2)

Currently, every 'data' object, used to represent property values, has
two lists of fixup structures - one for labels and one for references.
Sometimes we want to look at them separately, but other times we need
to consider both types of fixup.

I'm planning to implement string references, where a full path rather
than a phandle is substituted into a property value.  Adding yet
another list of fixups for that would start to get silly.  So, this
patch merges the "refs" and "labels" lists into a single list of
"markers", each of which has a type field indicating if it represents
a label or a phandle reference.  String references or any other new
type of in-data marker will then just need a new type value - merging
data blocks and other common manipulations will just work.

While I was at it I made some cleanups to the handling of fixups which
simplify things further.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2007-11-22 14:39:23 +11:00 committed by Jon Loeliger
parent b16a2bd89d
commit dc941774e2
6 changed files with 97 additions and 132 deletions

View file

@ -61,7 +61,7 @@ static void write_propval_string(FILE *f, struct data val)
char *str = val.val;
int i;
int newchunk = 1;
struct fixup *l = val.labels;
struct marker *m = val.markers;
assert(str[val.len-1] == '\0');
@ -69,10 +69,12 @@ static void write_propval_string(FILE *f, struct data val)
char c = str[i];
if (newchunk) {
while (l && (l->offset <= i)) {
assert(l->offset == i);
fprintf(f, "%s: ", l->ref);
l = l->next;
while (m && (m->offset <= i)) {
if (m->type == LABEL) {
assert(m->offset == i);
fprintf(f, "%s: ", m->ref);
}
m = m->next;
}
fprintf(f, "\"");
newchunk = 0;
@ -120,10 +122,9 @@ static void write_propval_string(FILE *f, struct data val)
fprintf(f, "\"");
/* Wrap up any labels at the end of the value */
while (l) {
assert (l->offset == val.len);
fprintf(f, " %s:", l->ref);
l = l->next;
for_each_marker_of_type(m, LABEL) {
assert (m->offset == val.len);
fprintf(f, " %s:", m->ref);
}
}
@ -131,14 +132,16 @@ static void write_propval_cells(FILE *f, struct data val)
{
void *propend = val.val + val.len;
cell_t *cp = (cell_t *)val.val;
struct fixup *l = val.labels;
struct marker *m = val.markers;
fprintf(f, "<");
for (;;) {
while (l && (l->offset <= ((char *)cp - val.val))) {
assert(l->offset == ((char *)cp - val.val));
fprintf(f, "%s: ", l->ref);
l = l->next;
while (m && (m->offset <= ((char *)cp - val.val))) {
if (m->type == LABEL) {
assert(m->offset == ((char *)cp - val.val));
fprintf(f, "%s: ", m->ref);
}
m = m->next;
}
fprintf(f, "0x%x", be32_to_cpu(*cp++));
@ -148,10 +151,9 @@ static void write_propval_cells(FILE *f, struct data val)
}
/* Wrap up any labels at the end of the value */
while (l) {
assert (l->offset == val.len);
fprintf(f, " %s:", l->ref);
l = l->next;
for_each_marker_of_type(m, LABEL) {
assert (m->offset == val.len);
fprintf(f, " %s:", m->ref);
}
fprintf(f, ">");
}
@ -160,13 +162,14 @@ static void write_propval_bytes(FILE *f, struct data val)
{
void *propend = val.val + val.len;
char *bp = val.val;
struct fixup *l = val.labels;
struct marker *m = val.markers;
fprintf(f, "[");
for (;;) {
while (l && (l->offset == (bp-val.val))) {
fprintf(f, "%s: ", l->ref);
l = l->next;
while (m && (m->offset == (bp-val.val))) {
if (m->type == LABEL)
fprintf(f, "%s: ", m->ref);
m = m->next;
}
fprintf(f, "%02hhx", *bp++);
@ -176,10 +179,9 @@ static void write_propval_bytes(FILE *f, struct data val)
}
/* Wrap up any labels at the end of the value */
while (l) {
assert (l->offset == val.len);
fprintf(f, " %s:", l->ref);
l = l->next;
for_each_marker_of_type(m, LABEL) {
assert (m->offset == val.len);
fprintf(f, " %s:", m->ref);
}
fprintf(f, "]");
}
@ -188,7 +190,7 @@ static void write_propval(FILE *f, struct property *prop)
{
int len = prop->val.len;
char *p = prop->val.val;
struct fixup *l;
struct marker *m = prop->val.markers;
int nnotstring = 0, nnul = 0;
int nnotstringlbl = 0, nnotcelllbl = 0;
int i;
@ -205,10 +207,10 @@ static void write_propval(FILE *f, struct property *prop)
nnul++;
}
for (l = prop->val.labels; l; l = l->next) {
if ((l->offset > 0) && (prop->val.val[l->offset - 1] != '\0'))
for_each_marker_of_type(m, LABEL) {
if ((m->offset > 0) && (prop->val.val[m->offset - 1] != '\0'))
nnotstringlbl++;
if ((l->offset % sizeof(cell_t)) != 0)
if ((m->offset % sizeof(cell_t)) != 0)
nnotcelllbl++;
}