bootinfo.c 1.6 KB

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