Linux-2.6.12-rc2
[linux-2.6/kvm.git] / arch / ppc / boot / common / bootinfo.c
blob9c6e528940e90fc2367b272f58b5eca04c049700
1 /*
2 * arch/ppc/common/bootinfo.c
4 * General bootinfo record utilities
5 * Author: Randy Vinson <rvinson@mvista.com>
7 * 2002 (c) MontaVista Software, Inc. This file is licensed under the terms
8 * of the GNU General Public License version 2. This program is licensed
9 * "as is" without any warranty of any kind, whether express or implied.
12 #include <linux/types.h>
13 #include <linux/string.h>
14 #include <asm/bootinfo.h>
16 #include "nonstdio.h"
18 static struct bi_record * birec = NULL;
20 static struct bi_record *
21 __bootinfo_build(struct bi_record *rec, unsigned long tag, unsigned long size,
22 void *data)
24 /* set the tag */
25 rec->tag = tag;
27 /* if the caller has any data, copy it */
28 if (size)
29 memcpy(rec->data, (char *)data, size);
31 /* set the record size */
32 rec->size = sizeof(struct bi_record) + size;
34 /* advance to the next available space */
35 rec = (struct bi_record *)((unsigned long)rec + rec->size);
37 return rec;
40 void
41 bootinfo_init(struct bi_record *rec)
44 /* save start of birec area */
45 birec = rec;
47 /* create an empty list */
48 rec = __bootinfo_build(rec, BI_FIRST, 0, NULL);
49 (void) __bootinfo_build(rec, BI_LAST, 0, NULL);
53 void
54 bootinfo_append(unsigned long tag, unsigned long size, void * data)
57 struct bi_record *rec = birec;
59 /* paranoia */
60 if ((rec == NULL) || (rec->tag != BI_FIRST))
61 return;
63 /* find the last entry in the list */
64 while (rec->tag != BI_LAST)
65 rec = (struct bi_record *)((ulong)rec + rec->size);
67 /* overlay BI_LAST record with new one and tag on a new BI_LAST */
68 rec = __bootinfo_build(rec, tag, size, data);
69 (void) __bootinfo_build(rec, BI_LAST, 0, NULL);