source: mainline/uspace/srv/hid/output/port/niagara.c@ 7af0cc5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7af0cc5 was 8442d10, checked in by Martin Decky <martin@…>, 12 years ago

improve the API of physmem_map(), dmamem_map() and dmamem_map_anonymous()
the "constraint" argument of dmamem_map_anonymous() should be used to specify bits disallowed in the physical frame address

  • Property mode set to 100644
File size: 3.0 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 <str.h>
41#include "../ctl/serial.h"
42#include "niagara.h"
43
44#define OUTPUT_FIFO_SIZE ((PAGE_SIZE) - 2 * sizeof(uint64_t))
45
46typedef volatile struct {
47 uint64_t read_ptr;
48 uint64_t write_ptr;
49 char data[OUTPUT_FIFO_SIZE];
50} __attribute__((packed)) output_fifo_t;
51
52typedef struct {
53 output_fifo_t *fifo;
54} niagara_t;
55
56static niagara_t niagara;
57
58static void niagara_putc(const char c)
59{
60 while (niagara.fifo->write_ptr ==
61 (niagara.fifo->read_ptr + OUTPUT_FIFO_SIZE - 1)
62 % OUTPUT_FIFO_SIZE);
63
64 niagara.fifo->data[niagara.fifo->write_ptr] = c;
65 niagara.fifo->write_ptr =
66 ((niagara.fifo->write_ptr) + 1) % OUTPUT_FIFO_SIZE;
67}
68
69static void niagara_putchar(wchar_t ch)
70{
71 if (ascii_check(ch))
72 niagara_putc(ch);
73 else
74 niagara_putc('?');
75}
76
77static void niagara_control_puts(const char *str)
78{
79 while (*str)
80 niagara_putc(*(str++));
81}
82
83int niagara_init(void)
84{
85 sysarg_t present;
86 int rc = sysinfo_get_value("fb", &present);
87 if (rc != EOK)
88 present = false;
89
90 if (!present)
91 return ENOENT;
92
93 sysarg_t kind;
94 rc = sysinfo_get_value("fb.kind", &kind);
95 if (rc != EOK)
96 kind = (sysarg_t) -1;
97
98 if (kind != 5)
99 return EINVAL;
100
101 sysarg_t paddr;
102 rc = sysinfo_get_value("niagara.outbuf.address", &paddr);
103 if (rc != EOK)
104 return rc;
105
106 rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE,
107 (void *) &niagara.fifo);
108 if (rc != EOK)
109 return rc;
110
111 return serial_init(niagara_putchar, niagara_control_puts);
112}
113
114/** @}
115 */
Note: See TracBrowser for help on using the repository browser.