bootinfo.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <linux/types.h>
  10. #include <linux/string.h>
  11. #include <asm/bootinfo.h>
  12. #include "nonstdio.h"
  13. static struct bi_record * birec = NULL;
  14. static struct bi_record *
  15. __bootinfo_build(struct bi_record *rec, unsigned long tag, unsigned long size,
  16. void *data)
  17. {
  18. /* set the tag */
  19. rec->tag = tag;
  20. /* if the caller has any data, copy it */
  21. if (size)
  22. memcpy(rec->data, (char *)data, size);
  23. /* set the record size */
  24. rec->size = sizeof(struct bi_record) + size;
  25. /* advance to the next available space */
  26. rec = (struct bi_record *)((unsigned long)rec + rec->size);
  27. return rec;
  28. }
  29. void
  30. bootinfo_init(struct bi_record *rec)
  31. {
  32. /* save start of birec area */
  33. birec = rec;
  34. /* create an empty list */
  35. rec = __bootinfo_build(rec, BI_FIRST, 0, NULL);
  36. (void) __bootinfo_build(rec, BI_LAST, 0, NULL);
  37. }
  38. void
  39. bootinfo_append(unsigned long tag, unsigned long size, void * data)
  40. {
  41. struct bi_record *rec = birec;
  42. /* paranoia */
  43. if ((rec == NULL) || (rec->tag != BI_FIRST))
  44. return;
  45. /* find the last entry in the list */
  46. while (rec->tag != BI_LAST)
  47. rec = (struct bi_record *)((ulong)rec + rec->size);
  48. /* overlay BI_LAST record with new one and tag on a new BI_LAST */
  49. rec = __bootinfo_build(rec, tag, size, data);
  50. (void) __bootinfo_build(rec, BI_LAST, 0, NULL);
  51. }