00001 /* 00002 * Copyright (c) 2006 Ondrej Palkovsky 00003 * Copyright (c) 2008 Martin Decky 00004 * Copyright (c) 2008 Pavel Rimsky 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * - Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * - The name of the author may not be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00038 #include <async.h> 00039 #include <sysinfo.h> 00040 #include <as.h> 00041 #include <errno.h> 00042 #include <stdio.h> 00043 #include <ddi.h> 00044 00045 #include "serial_console.h" 00046 #include "niagara.h" 00047 00048 #define WIDTH 80 00049 #define HEIGHT 24 00050 00054 static uintptr_t output_buffer_addr; 00055 00056 /* 00057 * Kernel counterpart of the driver reads characters to be printed from here. 00058 * Keep in sync with the definition from 00059 * kernel/arch/sparc64/src/drivers/niagara.c. 00060 */ 00061 #define OUTPUT_BUFFER_SIZE ((PAGE_SIZE) - 2 * 8) 00062 typedef volatile struct { 00063 uint64_t read_ptr; 00064 uint64_t write_ptr; 00065 char data[OUTPUT_BUFFER_SIZE]; 00066 } 00067 __attribute__ ((packed)) 00068 __attribute__ ((aligned(PAGE_SIZE))) 00069 *output_buffer_t; 00070 00071 output_buffer_t output_buffer; 00072 00077 static void niagara_putc(char c) 00078 { 00079 while (output_buffer->write_ptr == 00080 (output_buffer->read_ptr + OUTPUT_BUFFER_SIZE - 1) 00081 % OUTPUT_BUFFER_SIZE) 00082 ; 00083 output_buffer->data[output_buffer->write_ptr] = (uint64_t) c; 00084 output_buffer->write_ptr = 00085 ((output_buffer->write_ptr) + 1) % OUTPUT_BUFFER_SIZE; 00086 } 00087 00091 int niagara_init(void) 00092 { 00093 sysarg_t paddr; 00094 if (sysinfo_get_value("niagara.outbuf.address", &paddr) != EOK) 00095 return -1; 00096 00097 output_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE); 00098 int result = physmem_map((void *) paddr, 00099 (void *) output_buffer_addr, 1, 00100 AS_AREA_READ | AS_AREA_WRITE); 00101 00102 if (result != 0) { 00103 printf("Niagara: uspace driver couldn't map physical memory: %d\n", 00104 result); 00105 } 00106 00107 output_buffer = (output_buffer_t) output_buffer_addr; 00108 00109 serial_console_init(niagara_putc, WIDTH, HEIGHT); 00110 async_set_client_connection(serial_client_connection); 00111 return 0; 00112 } 00113