Subversion Repositories HelenOS

Rev

Rev 3862 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2005 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup sparc64
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch/console.h>
  36. #include <arch/types.h>
  37.  
  38. #include <arch/drivers/scr.h>
  39. #include <arch/drivers/kbd.h>
  40.  
  41. #include <arch/drivers/sgcn.h>
  42.  
  43. #if defined (SUN4U)
  44.     #ifdef CONFIG_Z8530
  45.     #include <genarch/kbd/z8530.h>
  46.     #endif
  47.     #ifdef CONFIG_NS16550
  48.     #include <genarch/kbd/ns16550.h>
  49.     #endif
  50. #elif defined (SUN4V)
  51.     #include <arch/drivers/niagara.h>
  52. #endif
  53.  
  54. #include <console/chardev.h>
  55. #include <console/console.h>
  56. #include <arch/asm.h>
  57. #include <arch/register.h>
  58. #include <proc/thread.h>
  59. #include <arch/mm/tlb.h>
  60. #include <genarch/ofw/ofw_tree.h>
  61. #include <arch.h>
  62. #include <panic.h>
  63. #include <func.h>
  64. #include <print.h>
  65.  
  66. #define KEYBOARD_POLL_PAUSE 50000   /* 50ms */
  67.  
  68. #if defined (SUN4U)
  69.  
  70. /**
  71.  * Initialize kernel console to use framebuffer and keyboard directly.
  72.  * Called on UltraSPARC machines with standard keyboard and framebuffer.
  73.  *
  74.  * @param aliases   the "/aliases" OBP node
  75.  */
  76. static void standard_console_init(ofw_tree_node_t *aliases)
  77. {
  78.     stdin = NULL;
  79.  
  80.     ofw_tree_property_t *prop;
  81.     ofw_tree_node_t *screen;
  82.     ofw_tree_node_t *keyboard;
  83.    
  84.     prop = ofw_tree_getprop(aliases, "screen");
  85.     if (!prop)
  86.         panic("Can't find property \"screen\".\n");
  87.     if (!prop->value)
  88.         panic("Can't find screen alias.\n");
  89.     screen = ofw_tree_lookup(prop->value);
  90.     if (!screen)
  91.         panic("Can't find %s\n", prop->value);
  92.  
  93.     scr_init(screen);
  94.  
  95.     prop = ofw_tree_getprop(aliases, "keyboard");
  96.     if (!prop)
  97.         panic("Can't find property \"keyboard\".\n");
  98.     if (!prop->value)
  99.         panic("Can't find keyboard alias.\n");
  100.     keyboard = ofw_tree_lookup(prop->value);
  101.     if (!keyboard)
  102.         panic("Can't find %s\n", prop->value);
  103.  
  104.     kbd_init(keyboard);
  105. }
  106.  
  107. /** Initilize I/O on the Serengeti machine. */
  108. static void serengeti_init(void)
  109. {
  110.     sgcn_init();
  111. }
  112.  
  113. #endif
  114.  
  115. /**
  116.  * Initialize input/output. Auto-detects the type of machine
  117.  * and calls the appropriate I/O init routine.
  118.  */
  119. void standalone_sparc64_console_init(void)
  120. {
  121. #if defined (SUN4U)
  122.     ofw_tree_node_t *aliases;
  123.     ofw_tree_property_t *prop;
  124.    
  125.     aliases = ofw_tree_lookup("/aliases");
  126.     if (!aliases)
  127.         panic("Can't find /aliases.\n");
  128.    
  129.     /* "def-cn" = "default console" */
  130.     prop = ofw_tree_getprop(aliases, "def-cn");
  131.    
  132.     if ((!prop) || (!prop->value) || (strcmp(prop->value, "/sgcn") != 0)) {
  133.         standard_console_init(aliases);
  134.     } else {
  135.         serengeti_init();
  136.     }
  137. #elif defined (SUN4V)
  138.     niagara_init();
  139. #endif
  140. }
  141.  
  142.  
  143. /** Kernel thread for polling keyboard.
  144.  *
  145.  * @param arg Ignored.
  146.  */
  147. void kkbdpoll(void *arg)
  148. {
  149.     thread_detach(THREAD);
  150.  
  151. #ifdef CONFIG_Z8530
  152.     if (kbd_type == KBD_Z8530) {
  153.         /*
  154.          * The z8530 driver is interrupt-driven.
  155.          */
  156.         return;
  157.     }
  158. #endif
  159.  
  160. #ifdef CONFIG_NS16550
  161. #ifdef CONFIG_NS16550_INTERRUPT_DRIVEN
  162.     if (kbd_type == KBD_NS16550) {
  163.         /*
  164.          * The ns16550 driver is interrupt-driven.
  165.          */
  166.         return;
  167.     }
  168. #endif
  169. #endif
  170.     while (1) {
  171. #ifdef CONFIG_NS16550
  172. #ifndef CONFIG_NS16550_INTERRUPT_DRIVEN
  173.         if (kbd_type == KBD_NS16550)
  174.             ns16550_poll();
  175. #endif
  176. #endif
  177. #ifdef CONFIG_SGCN
  178.         if (kbd_type == KBD_SGCN)
  179.             sgcn_poll();
  180. #endif
  181. #ifdef SUN4V
  182.         if (kbd_type == KBD_SUN4V)
  183.             niagara_poll();
  184. #endif
  185.         thread_usleep(KEYBOARD_POLL_PAUSE);
  186.     }
  187. }
  188.  
  189. /** Acquire console back for kernel
  190.  *
  191.  */
  192. void arch_grab_console(void)
  193. {
  194.     scr_redraw();
  195.     switch (kbd_type) {
  196. #ifdef CONFIG_Z8530
  197.     case KBD_Z8530:
  198.         z8530_grab();
  199.         break;
  200. #endif
  201. #ifdef CONFIG_NS16550
  202.     case KBD_NS16550:
  203.         ns16550_grab();
  204.         break;
  205. #endif
  206. #ifdef CONFIG_SGCN
  207.     case KBD_SGCN:
  208.         sgcn_grab();
  209.         break;
  210. #endif
  211. #ifdef SUN4V
  212.     case KBD_SUN4V:
  213.         niagara_grab();
  214.         break;
  215. #endif
  216.     default:
  217.         break;
  218.     }
  219. }
  220.  
  221. /** Return console to userspace
  222.  *
  223.  */
  224. void arch_release_console(void)
  225. {
  226.     switch (kbd_type) {
  227. #ifdef CONFIG_Z8530
  228.     case KBD_Z8530:
  229.         z8530_release();
  230.         break;
  231. #endif
  232. #ifdef CONFIG_NS16550
  233.     case KBD_NS16550:
  234.         ns16550_release();
  235.         break;
  236. #endif
  237. #ifdef CONFIG_SGCN
  238.     case KBD_SGCN:
  239.         sgcn_release();
  240.         break;
  241. #endif
  242. #ifdef SUN4V
  243.     case KBD_SUN4V:
  244.         niagara_release();
  245.         break;
  246. #endif
  247.     default:
  248.         break;
  249.     }
  250. }
  251.  
  252. /** @}
  253.  */
  254.