prom.c 3.6 KB

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