init.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* $Id: init.c,v 1.10 1999/09/21 14:35:59 davem Exp $
  2. * init.c: Initialize internal variables used by the PROM
  3. * library functions.
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/string.h>
  11. #include <linux/ctype.h>
  12. #include <asm/openprom.h>
  13. #include <asm/oplib.h>
  14. enum prom_major_version prom_vers;
  15. unsigned int prom_rev, prom_prev;
  16. /* The root node of the prom device tree. */
  17. int prom_root_node;
  18. int prom_stdin, prom_stdout;
  19. int prom_chosen_node;
  20. /* You must call prom_init() before you attempt to use any of the
  21. * routines in the prom library. It returns 0 on success, 1 on
  22. * failure. It gets passed the pointer to the PROM vector.
  23. */
  24. extern void prom_meminit(void);
  25. extern void prom_cif_init(void *, void *);
  26. void __init prom_init(void *cif_handler, void *cif_stack)
  27. {
  28. char buffer[80], *p;
  29. int ints[3];
  30. int node;
  31. int i = 0;
  32. int bufadjust;
  33. prom_vers = PROM_P1275;
  34. prom_cif_init(cif_handler, cif_stack);
  35. prom_root_node = prom_getsibling(0);
  36. if((prom_root_node == 0) || (prom_root_node == -1))
  37. prom_halt();
  38. prom_chosen_node = prom_finddevice("/chosen");
  39. if (!prom_chosen_node || prom_chosen_node == -1)
  40. prom_halt();
  41. prom_stdin = prom_getint (prom_chosen_node, "stdin");
  42. prom_stdout = prom_getint (prom_chosen_node, "stdout");
  43. node = prom_finddevice("/openprom");
  44. if (!node || node == -1)
  45. prom_halt();
  46. prom_getstring (node, "version", buffer, sizeof (buffer));
  47. prom_printf ("\n");
  48. if (strncmp (buffer, "OBP ", 4))
  49. goto strange_version;
  50. /*
  51. * Version field is expected to be 'OBP xx.yy.zz date...'
  52. * However, Sun can't stick to this format very well, so
  53. * we need to check for 'OBP xx.yy.zz date...' and adjust
  54. * accordingly. -spot
  55. */
  56. if (strncmp (buffer, "OBP ", 5))
  57. bufadjust = 4;
  58. else
  59. bufadjust = 5;
  60. p = buffer + bufadjust;
  61. while (p && isdigit(*p) && i < 3) {
  62. ints[i++] = simple_strtoul(p, NULL, 0);
  63. if ((p = strchr(p, '.')) != NULL)
  64. p++;
  65. }
  66. if (i != 3)
  67. goto strange_version;
  68. prom_rev = ints[1];
  69. prom_prev = (ints[0] << 16) | (ints[1] << 8) | ints[2];
  70. printk ("PROMLIB: Sun IEEE Boot Prom %s\n", buffer + bufadjust);
  71. prom_meminit();
  72. /* Initialization successful. */
  73. return;
  74. strange_version:
  75. prom_printf ("Strange OBP version `%s'.\n", buffer);
  76. prom_halt ();
  77. }