init.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_stdin, prom_stdout;
  18. int prom_chosen_node;
  19. /* You must call prom_init() before you attempt to use any of the
  20. * routines in the prom library. It returns 0 on success, 1 on
  21. * failure. It gets passed the pointer to the PROM vector.
  22. */
  23. extern void prom_cif_init(void *, void *);
  24. void __init prom_init(void *cif_handler, void *cif_stack)
  25. {
  26. char buffer[80], *p;
  27. int ints[3];
  28. int node;
  29. int i = 0;
  30. int bufadjust;
  31. prom_vers = PROM_P1275;
  32. prom_cif_init(cif_handler, cif_stack);
  33. prom_chosen_node = prom_finddevice(prom_chosen_path);
  34. if (!prom_chosen_node || prom_chosen_node == -1)
  35. prom_halt();
  36. prom_stdin = prom_getint(prom_chosen_node, "stdin");
  37. prom_stdout = prom_getint(prom_chosen_node, "stdout");
  38. node = prom_finddevice("/openprom");
  39. if (!node || node == -1)
  40. prom_halt();
  41. prom_getstring(node, "version", buffer, sizeof (buffer));
  42. prom_printf("\n");
  43. if (strncmp(buffer, "OBP ", 4))
  44. goto strange_version;
  45. /*
  46. * Version field is expected to be 'OBP xx.yy.zz date...'
  47. * However, Sun can't stick to this format very well, so
  48. * we need to check for 'OBP xx.yy.zz date...' and adjust
  49. * accordingly. -spot
  50. */
  51. if (strncmp(buffer, "OBP ", 5))
  52. bufadjust = 4;
  53. else
  54. bufadjust = 5;
  55. p = buffer + bufadjust;
  56. while (p && isdigit(*p) && i < 3) {
  57. ints[i++] = simple_strtoul(p, NULL, 0);
  58. if ((p = strchr(p, '.')) != NULL)
  59. p++;
  60. }
  61. if (i != 3)
  62. goto strange_version;
  63. prom_rev = ints[1];
  64. prom_prev = (ints[0] << 16) | (ints[1] << 8) | ints[2];
  65. printk("PROMLIB: Sun IEEE Boot Prom %s\n", buffer + bufadjust);
  66. printk("PROMLIB: Root node compatible: %s\n", prom_root_compatible);
  67. /* Initialization successful. */
  68. return;
  69. strange_version:
  70. prom_printf ("Strange OBP version `%s'.\n", buffer);
  71. prom_halt ();
  72. }