00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
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
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