Changeset 7c014d1 in mainline for uspace/srv/hid/fb/port/niagara.c
- Timestamp:
- 2011-09-09T15:46:21Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c69646f8
- Parents:
- 14a60e3
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/fb/port/niagara.c
r14a60e3 r7c014d1 29 29 */ 30 30 31 /** @defgroup niagarafb32 * @brief userland driver of the Niagara console output33 * @{34 */35 31 /** @file 36 32 */ 37 33 38 #include <async.h> 34 #include <sys/types.h> 35 #include <errno.h> 39 36 #include <sysinfo.h> 37 #include <ddi.h> 40 38 #include <as.h> 41 #include <errno.h> 42 #include <stdio.h> 43 #include <ddi.h> 44 45 #include "serial_console.h" 39 #include <align.h> 40 #include "../ctl/serial.h" 46 41 #include "niagara.h" 47 42 48 #define WIDTH 80 49 #define HEIGHT 24 43 #define OUTPUT_FIFO_SIZE ((PAGE_SIZE) - 2 * sizeof(uint64_t)) 50 44 51 /**52 * Virtual address mapped to the buffer shared with the kernel counterpart.53 */54 static uintptr_t output_buffer_addr;55 56 /*57 * Kernel counterpart of the driver reads characters to be printed from here.58 * Keep in sync with the definition from59 * kernel/arch/sparc64/src/drivers/niagara.c.60 */61 #define OUTPUT_BUFFER_SIZE ((PAGE_SIZE) - 2 * 8)62 45 typedef volatile struct { 63 46 uint64_t read_ptr; 64 47 uint64_t write_ptr; 65 char data[OUTPUT_BUFFER_SIZE]; 66 } 67 __attribute__ ((packed)) 68 __attribute__ ((aligned(PAGE_SIZE))) 69 *output_buffer_t; 48 char data[OUTPUT_FIFO_SIZE]; 49 } __attribute__((packed)) output_fifo_t; 70 50 71 output_buffer_t output_buffer; 51 typedef struct { 52 output_fifo_t *fifo; 53 } niagara_t; 72 54 73 /** 74 * Pushes the character to the Niagara serial. 75 * @param c character to be pushed 76 */ 77 static void niagara_putc(char c) 55 static niagara_t niagara; 56 57 static void niagara_putc(const char c) 78 58 { 79 while ( output_buffer->write_ptr ==80 (output_buffer->read_ptr + OUTPUT_BUFFER_SIZE - 1)81 % OUTPUT_BUFFER_SIZE)82 ;83 output_buffer->data[output_buffer->write_ptr] = (uint64_t)c;84 output_buffer->write_ptr =85 ((output_buffer->write_ptr) + 1) % OUTPUT_BUFFER_SIZE;59 while (niagara.fifo->write_ptr == 60 (niagara.fifo->read_ptr + OUTPUT_FIFO_SIZE - 1) 61 % OUTPUT_FIFO_SIZE); 62 63 niagara.fifo->data[niagara.fifo->write_ptr] = c; 64 niagara.fifo->write_ptr = 65 ((niagara.fifo->write_ptr) + 1) % OUTPUT_FIFO_SIZE; 86 66 } 87 67 88 /** 89 * Initializes the Niagara serial driver. 90 */ 68 static void niagara_putchar(wchar_t ch) 69 { 70 if ((ch >= 0) && (ch < 128)) 71 niagara_putc(ch); 72 else 73 niagara_putc('?'); 74 } 75 76 static void niagara_control_puts(const char *str) 77 { 78 while (*str) 79 niagara_putc(*(str++)); 80 } 81 91 82 int niagara_init(void) 92 83 { 84 sysarg_t present; 85 int rc = sysinfo_get_value("fb", &present); 86 if (rc != EOK) 87 present = false; 88 89 if (!present) 90 return ENOENT; 91 92 sysarg_t kind; 93 rc = sysinfo_get_value("fb.kind", &kind); 94 if (rc != EOK) 95 kind = (sysarg_t) -1; 96 97 if (kind != 5) 98 return EINVAL; 99 93 100 sysarg_t paddr; 94 if (sysinfo_get_value("niagara.outbuf.address", &paddr) != EOK) 95 return -1; 101 rc = sysinfo_get_value("niagara.outbuf.address", &paddr); 102 if (rc != EOK) 103 return rc; 96 104 97 output_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE); 98 int result = physmem_map((void *) paddr, 99 (void *) output_buffer_addr, 1, 105 niagara.fifo = 106 (output_fifo_t *) as_get_mappable_page(sizeof(output_fifo_t)); 107 if (niagara.fifo == NULL) 108 return ENOMEM; 109 110 rc = physmem_map((void *) paddr, (void *) niagara.fifo, 1, 100 111 AS_AREA_READ | AS_AREA_WRITE); 101 102 if (result != 0) { 103 printf("Niagara: uspace driver couldn't map physical memory: %d\n", 104 result); 105 } 106 107 output_buffer = (output_buffer_t) output_buffer_addr; 108 109 serial_console_init(niagara_putc, WIDTH, HEIGHT); 110 async_set_client_connection(serial_client_connection); 111 return 0; 112 if (rc != EOK) 113 return rc; 114 115 return serial_init(niagara_putchar, niagara_control_puts); 112 116 } 113 117 114 /** 115 * @} 118 /** @} 116 119 */ 117
Note:
See TracChangeset
for help on using the changeset viewer.