prom.c 3.7 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/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. extern char m68k_debug_device[];
  61. static void sun3x_prom_write(struct console *co, const char *s,
  62. unsigned int count)
  63. {
  64. while (count--) {
  65. if (*s == '\n')
  66. sun3x_putchar('\r');
  67. sun3x_putchar(*s++);
  68. }
  69. }
  70. /* debug console - write-only */
  71. static struct console sun3x_debug = {
  72. .name = "debug",
  73. .write = sun3x_prom_write,
  74. .flags = CON_PRINTBUFFER,
  75. .index = -1,
  76. };
  77. void sun3x_prom_init(void)
  78. {
  79. /* Read the vector table */
  80. sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
  81. sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
  82. sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
  83. sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
  84. sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
  85. sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
  86. romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
  87. idprom_init();
  88. if(!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
  89. printk("Warning: machine reports strange type %02x\n",
  90. idprom->id_machtype);
  91. printk("Pretending it's a 3/80, but very afraid...\n");
  92. idprom->id_machtype = SM_SUN3X | SM_3_80;
  93. }
  94. /* point trap #14 at abort.
  95. * XXX this is futile since we restore the vbr first - oops
  96. */
  97. vectors[VEC_TRAP14] = sun3x_prom_abort;
  98. /* If debug=prom was specified, start the debug console */
  99. if (!strcmp(m68k_debug_device, "prom"))
  100. register_console(&sun3x_debug);
  101. }
  102. /* some prom functions to export */
  103. int prom_getintdefault(int node, char *property, int deflt)
  104. {
  105. return deflt;
  106. }
  107. int prom_getbool (int node, char *prop)
  108. {
  109. return 1;
  110. }
  111. void prom_printf(char *fmt, ...)
  112. {
  113. }
  114. void prom_halt (void)
  115. {
  116. sun3x_halt();
  117. }
  118. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  119. * format type. 'num_bytes' is the number of bytes that your idbuf
  120. * has space for. Returns 0xff on error.
  121. */
  122. unsigned char
  123. prom_get_idprom(char *idbuf, int num_bytes)
  124. {
  125. int i;
  126. /* make a copy of the idprom structure */
  127. for(i = 0; i < num_bytes; i++)
  128. idbuf[i] = ((char *)SUN3X_IDPROM)[i];
  129. return idbuf[0];
  130. }