source: mainline/uspace/srv/hid/fb/port/niagara.c@ 40a2af3

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 40a2af3 was 7c014d1, checked in by Martin Decky <martin@…>, 15 years ago

console and framebuffer server rewrite

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2008 Martin Decky
4 * Copyright (c) 2008 Pavel Rimsky
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @file
32 */
33
34#include <sys/types.h>
35#include <errno.h>
36#include <sysinfo.h>
37#include <ddi.h>
38#include <as.h>
39#include <align.h>
40#include "../ctl/serial.h"
41#include "niagara.h"
42
43#define OUTPUT_FIFO_SIZE ((PAGE_SIZE) - 2 * sizeof(uint64_t))
44
45typedef volatile struct {
46 uint64_t read_ptr;
47 uint64_t write_ptr;
48 char data[OUTPUT_FIFO_SIZE];
49} __attribute__((packed)) output_fifo_t;
50
51typedef struct {
52 output_fifo_t *fifo;
53} niagara_t;
54
55static niagara_t niagara;
56
57static void niagara_putc(const char c)
58{
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;
66}
67
68static void niagara_putchar(wchar_t ch)
69{
70 if ((ch >= 0) && (ch < 128))
71 niagara_putc(ch);
72 else
73 niagara_putc('?');
74}
75
76static void niagara_control_puts(const char *str)
77{
78 while (*str)
79 niagara_putc(*(str++));
80}
81
82int niagara_init(void)
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
100 sysarg_t paddr;
101 rc = sysinfo_get_value("niagara.outbuf.address", &paddr);
102 if (rc != EOK)
103 return rc;
104
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,
111 AS_AREA_READ | AS_AREA_WRITE);
112 if (rc != EOK)
113 return rc;
114
115 return serial_init(niagara_putchar, niagara_control_puts);
116}
117
118/** @}
119 */
Note: See TracBrowser for help on using the repository browser.