x86: use generic per-device dma coherent allocator
[pandora-kernel.git] / arch / ppc / boot / common / bootinfo.c
1 /*
2  * General bootinfo record utilities
3  * Author: Randy Vinson <rvinson@mvista.com>
4  *
5  * 2002 (c) MontaVista Software, Inc. This file is licensed under the terms
6  * of the GNU General Public License version 2. This program is licensed
7  * "as is" without any warranty of any kind, whether express or implied.
8  */
9
10 #include <linux/types.h>
11 #include <linux/string.h>
12 #include <asm/bootinfo.h>
13
14 #include "nonstdio.h"
15
16 static struct bi_record * birec = NULL;
17
18 static struct bi_record *
19 __bootinfo_build(struct bi_record *rec, unsigned long tag, unsigned long size,
20                  void *data)
21 {
22         /* set the tag */
23         rec->tag = tag;
24
25         /* if the caller has any data, copy it */
26         if (size)
27                 memcpy(rec->data, (char *)data, size);
28
29         /* set the record size */
30         rec->size = sizeof(struct bi_record) + size;
31
32         /* advance to the next available space */
33         rec = (struct bi_record *)((unsigned long)rec + rec->size);
34
35         return rec;
36 }
37
38 void
39 bootinfo_init(struct bi_record *rec)
40 {
41
42         /* save start of birec area */
43         birec = rec;
44
45         /* create an empty list */
46         rec = __bootinfo_build(rec, BI_FIRST, 0, NULL);
47         (void) __bootinfo_build(rec, BI_LAST, 0, NULL);
48
49 }
50
51 void
52 bootinfo_append(unsigned long tag, unsigned long size, void * data)
53 {
54
55         struct bi_record *rec = birec;
56
57         /* paranoia */
58         if ((rec == NULL) || (rec->tag != BI_FIRST))
59                 return;
60
61         /* find the last entry in the list */
62         while (rec->tag != BI_LAST)
63                 rec = (struct bi_record *)((ulong)rec + rec->size);
64
65         /* overlay BI_LAST record with new one and tag on a new BI_LAST */
66         rec = __bootinfo_build(rec, tag, size, data);
67         (void) __bootinfo_build(rec, BI_LAST, 0, NULL);
68 }