console.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <arch/console.h>
00036 #include <arch/types.h>
00037 #include <typedefs.h>
00038 #include <genarch/fb/fb.h>
00039 #include <arch/drivers/fb.h>
00040 #include <arch/drivers/i8042.h>
00041 #include <genarch/i8042/i8042.h>
00042 #include <genarch/ofw/ofw.h>
00043 #include <console/chardev.h>
00044 #include <console/console.h>
00045 #include <arch/asm.h>
00046 #include <arch/register.h>
00047 #include <proc/thread.h>
00048 #include <synch/mutex.h>
00049 #include <arch/mm/tlb.h>
00050 
00051 #define KEYBOARD_POLL_PAUSE     50000   /* 50ms */
00052 
00053 static void ofw_sparc64_putchar(chardev_t *d, const char ch);
00054 static char ofw_sparc64_getchar(chardev_t *d);
00055 static void ofw_sparc64_suspend(chardev_t *d);
00056 static void ofw_sparc64_resume(chardev_t *d);
00057 
00058 mutex_t canwork;
00059 
00060 static volatile int ofw_console_active;
00061 
00062 static chardev_t ofw_sparc64_console;
00063 static chardev_operations_t ofw_sparc64_console_ops = {
00064         .write = ofw_sparc64_putchar,
00065         .read = ofw_sparc64_getchar,
00066         .resume = ofw_sparc64_resume,
00067         .suspend = ofw_sparc64_suspend
00068 };
00069 
00071 void ofw_sparc64_console_init(void)
00072 {
00073         chardev_initialize("ofw_sparc64_console", &ofw_sparc64_console, &ofw_sparc64_console_ops);
00074         stdin = &ofw_sparc64_console;
00075         stdout = &ofw_sparc64_console;
00076         mutex_initialize(&canwork);
00077         ofw_console_active = 1;
00078 }
00079 
00081 void standalone_sparc64_console_init(void)
00082 {
00083         ofw_console_active = 0;
00084         stdin = NULL;
00085 
00086         kbd_init();
00087         fb_init(FB_PHYS_ADDRESS, FB_X_RES, FB_Y_RES, FB_COLOR_DEPTH, FB_X_RES * FB_COLOR_DEPTH / 8);
00088 }
00089 
00095 void ofw_sparc64_putchar(chardev_t *d, const char ch)
00096 {
00097         pstate_reg_t pstate;
00098 
00099         /*
00100          * 32-bit OpenFirmware depends on PSTATE.AM bit set.
00101          */     
00102         pstate.value = pstate_read();
00103         pstate.am = true;
00104         pstate_write(pstate.value);
00105 
00106         if (ch == '\n')
00107                 ofw_putchar('\r');
00108         ofw_putchar(ch);
00109         
00110         pstate.am = false;
00111         pstate_write(pstate.value);
00112 }
00113 
00121 char ofw_sparc64_getchar(chardev_t *d)
00122 {
00123         char ch;
00124         pstate_reg_t pstate;
00125 
00126         /*
00127          * 32-bit OpenFirmware depends on PSTATE.AM bit set.
00128          */     
00129         pstate.value = pstate_read();
00130         pstate.am = true;
00131         pstate_write(pstate.value);
00132 
00133         ch = ofw_getchar();
00134         
00135         pstate.am = false;
00136         pstate_write(pstate.value);
00137         
00138         return ch;
00139 }
00140 
00141 void ofw_sparc64_suspend(chardev_t *d)
00142 {
00143         mutex_lock(&canwork);
00144 }
00145 
00146 void ofw_sparc64_resume(chardev_t *d)
00147 {
00148         mutex_unlock(&canwork);
00149 }
00150 
00155 void kofwinput(void *arg)
00156 {
00157 
00158         while (ofw_console_active) {
00159                 char ch = 0;
00160                 
00161                 mutex_lock(&canwork);
00162                 mutex_unlock(&canwork);
00163                 
00164                 ch = ofw_sparc64_getchar(NULL);
00165                 if (ch) {
00166                         if (ch == '\r')
00167                                 ch = '\n';
00168                         chardev_push_character(&ofw_sparc64_console, ch);
00169                 }
00170                 thread_usleep(KEYBOARD_POLL_PAUSE);
00171         }
00172 }
00173 
00178 void kkbdpoll(void *arg)
00179 {
00180         while (1) {
00181                 i8042_poll();           
00182                 thread_usleep(KEYBOARD_POLL_PAUSE);
00183         }
00184 }
00185 

Generated on Sun Jun 18 17:37:25 2006 for HelenOS Kernel (sparc64) by  doxygen 1.4.6