prom.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Prom access routines for the sun3x */
  2. #include <linux/types.h>
  3. #include <linux/kernel.h>
  4. #include <linux/tty.h>
  5. #include <linux/console.h>
  6. #include <linux/init.h>
  7. #include <linux/mm.h>
  8. #include <linux/string.h>
  9. #include <asm/page.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/bootinfo.h>
  12. #include <asm/setup.h>
  13. #include <asm/traps.h>
  14. #include <asm/sun3xprom.h>
  15. #include <asm/idprom.h>
  16. #include <asm/segment.h>
  17. #include <asm/sun3ints.h>
  18. #include <asm/openprom.h>
  19. #include <asm/machines.h>
  20. void (*sun3x_putchar)(int);
  21. int (*sun3x_getchar)(void);
  22. int (*sun3x_mayget)(void);
  23. int (*sun3x_mayput)(int);
  24. void (*sun3x_prom_reboot)(void);
  25. e_vector sun3x_prom_abort;
  26. struct linux_romvec *romvec;
  27. /* prom vector table */
  28. e_vector *sun3x_prom_vbr;
  29. /* Handle returning to the prom */
  30. void sun3x_halt(void)
  31. {
  32. unsigned long flags;
  33. /* Disable interrupts while we mess with things */
  34. local_irq_save(flags);
  35. /* Restore prom vbr */
  36. asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
  37. /* Restore prom NMI clock */
  38. // sun3x_disable_intreg(5);
  39. sun3_enable_irq(7);
  40. /* Let 'er rip */
  41. asm volatile ("trap #14");
  42. /* Restore everything */
  43. sun3_disable_irq(7);
  44. sun3_enable_irq(5);
  45. asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
  46. local_irq_restore(flags);
  47. }
  48. void sun3x_reboot(void)
  49. {
  50. /* This never returns, don't bother saving things */
  51. local_irq_disable();
  52. /* Restore prom vbr */
  53. asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
  54. /* Restore prom NMI clock */
  55. sun3_disable_irq(5);
  56. sun3_enable_irq(7);
  57. /* Let 'er rip */
  58. (*romvec->pv_reboot)("vmlinux");
  59. }
  60. static void sun3x_prom_write(struct console *co, const char *s,
  61. unsigned int count)
  62. {
  63. while (count--) {
  64. if (*s == '\n')
  65. sun3x_putchar('\r');
  66. sun3x_putchar(*s++);
  67. }
  68. }
  69. /* debug console - write-only */
  70. static struct console sun3x_debug = {
  71. .name = "debug",
  72. .write = sun3x_prom_write,
  73. .flags = CON_PRINTBUFFER,
  74. .index = -1,
  75. };
  76. void __init sun3x_prom_init(void)
  77. {
  78. /* Read the vector table */
  79. sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
  80. sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
  81. sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
  82. sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
  83. sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
  84. sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
  85. romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
  86. idprom_init();
  87. if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
  88. printk("Warning: machine reports strange type %02x\n",
  89. idprom->id_machtype);
  90. printk("Pretending it's a 3/80, but very afraid...\n");
  91. idprom->id_machtype = SM_SUN3X | SM_3_80;
  92. }
  93. /* point trap #14 at abort.
  94. * XXX this is futile since we restore the vbr first - oops
  95. */
  96. vectors[VEC_TRAP14] = sun3x_prom_abort;
  97. }
  98. static int __init sun3x_debug_setup(char *arg)
  99. {
  100. /* If debug=prom was specified, start the debug console */
  101. if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
  102. register_console(&sun3x_debug);
  103. return 0;
  104. }
  105. early_param("debug", sun3x_debug_setup);
  106. /* some prom functions to export */
  107. int prom_getintdefault(int node, char *property, int deflt)
  108. {
  109. return deflt;
  110. }
  111. int prom_getbool (int node, char *prop)
  112. {
  113. return 1;
  114. }
  115. void prom_printf(char *fmt, ...)
  116. {
  117. }
  118. void prom_halt (void)
  119. {
  120. sun3x_halt();
  121. }
  122. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  123. * format type. 'num_bytes' is the number of bytes that your idbuf
  124. * has space for. Returns 0xff on error.
  125. */
  126. unsigned char
  127. prom_get_idprom(char *idbuf, int num_bytes)
  128. {
  129. int i;
  130. /* make a copy of the idprom structure */
  131. for (i = 0; i < num_bytes; i++)
  132. idbuf[i] = ((char *)SUN3X_IDPROM)[i];
  133. return idbuf[0];
  134. }