init.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_cif_init(void *, void *);
  25. void __init prom_init(void *cif_handler, void *cif_stack)
  26. {
  27. char buffer[80], *p;
  28. int ints[3];
  29. int node;
  30. int i = 0;
  31. int bufadjust;
  32. prom_vers = PROM_P1275;
  33. prom_cif_init(cif_handler, cif_stack);
  34. prom_root_node = prom_getsibling(0);
  35. if((prom_root_node == 0) || (prom_root_node == -1))
  36. prom_halt();
  37. prom_chosen_node = prom_finddevice(prom_chosen_path);
  38. if (!prom_chosen_node || prom_chosen_node == -1)
  39. prom_halt();
  40. prom_stdin = prom_getint (prom_chosen_node, "stdin");
  41. prom_stdout = prom_getint (prom_chosen_node, "stdout");
  42. node = prom_finddevice("/openprom");
  43. if (!node || node == -1)
  44. prom_halt();
  45. prom_getstring (node, "version", buffer, sizeof (buffer));
  46. prom_printf ("\n");
  47. if (strncmp (buffer, "OBP ", 4))
  48. goto strange_version;
  49. /*
  50. * Version field is expected to be 'OBP xx.yy.zz date...'
  51. * However, Sun can't stick to this format very well, so
  52. * we need to check for 'OBP xx.yy.zz date...' and adjust
  53. * accordingly. -spot
  54. */
  55. if (strncmp (buffer, "OBP ", 5))
  56. bufadjust = 4;
  57. else
  58. bufadjust = 5;
  59. p = buffer + bufadjust;
  60. while (p && isdigit(*p) && i < 3) {
  61. ints[i++] = simple_strtoul(p, NULL, 0);
  62. if ((p = strchr(p, '.')) != NULL)
  63. p++;
  64. }
  65. if (i != 3)
  66. goto strange_version;
  67. prom_rev = ints[1];
  68. prom_prev = (ints[0] << 16) | (ints[1] << 8) | ints[2];
  69. printk ("PROMLIB: Sun IEEE Boot Prom %s\n", buffer + bufadjust);
  70. /* Initialization successful. */
  71. return;
  72. strange_version:
  73. prom_printf ("Strange OBP version `%s'.\n", buffer);
  74. prom_halt ();
  75. }