prom.c 3.6 KB

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