Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * arch/ppc/common/bootinfo.c |
| 3 | * |
| 4 | * General bootinfo record utilities |
| 5 | * Author: Randy Vinson <rvinson@mvista.com> |
| 6 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <asm/bootinfo.h> |
| 15 | |
| 16 | #include "nonstdio.h" |
| 17 | |
| 18 | static struct bi_record * birec = NULL; |
| 19 | |
| 20 | static struct bi_record * |
| 21 | __bootinfo_build(struct bi_record *rec, unsigned long tag, unsigned long size, |
| 22 | void *data) |
| 23 | { |
| 24 | /* set the tag */ |
| 25 | rec->tag = tag; |
| 26 | |
| 27 | /* if the caller has any data, copy it */ |
| 28 | if (size) |
| 29 | memcpy(rec->data, (char *)data, size); |
| 30 | |
| 31 | /* set the record size */ |
| 32 | rec->size = sizeof(struct bi_record) + size; |
| 33 | |
| 34 | /* advance to the next available space */ |
| 35 | rec = (struct bi_record *)((unsigned long)rec + rec->size); |
| 36 | |
| 37 | return rec; |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | bootinfo_init(struct bi_record *rec) |
| 42 | { |
| 43 | |
| 44 | /* save start of birec area */ |
| 45 | birec = rec; |
| 46 | |
| 47 | /* create an empty list */ |
| 48 | rec = __bootinfo_build(rec, BI_FIRST, 0, NULL); |
| 49 | (void) __bootinfo_build(rec, BI_LAST, 0, NULL); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | bootinfo_append(unsigned long tag, unsigned long size, void * data) |
| 55 | { |
| 56 | |
| 57 | struct bi_record *rec = birec; |
| 58 | |
| 59 | /* paranoia */ |
| 60 | if ((rec == NULL) || (rec->tag != BI_FIRST)) |
| 61 | return; |
| 62 | |
| 63 | /* find the last entry in the list */ |
| 64 | while (rec->tag != BI_LAST) |
| 65 | rec = (struct bi_record *)((ulong)rec + rec->size); |
| 66 | |
| 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); |
| 70 | } |