source: mainline/uspace/srv/hid/kbd/port/niagara.c@ 9256ad29

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9256ad29 was b473611, checked in by Jakub Jermar <jakub@…>, 16 years ago

Merge the sparc branch.
Both sun4u and sun4v appear to work.
HM cleanup is pending.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2008 Pavel Rimsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kbd_port
30 * @ingroup kbd
31 * @{
32 */
33/** @file
34 * @brief Niagara console keyboard port driver.
35 */
36
37#include <as.h>
38#include <ddi.h>
39#include <async.h>
40#include <kbd.h>
41#include <kbd_port.h>
42#include <sysinfo.h>
43#include <stdio.h>
44#include <thread.h>
45#include <bool.h>
46
47#define POLL_INTERVAL 10000
48
49/**
50 * Virtual address mapped to the buffer shared with the kernel counterpart.
51 */
52static uintptr_t input_buffer_addr;
53
54/*
55 * Kernel counterpart of the driver pushes characters (it has read) here.
56 * Keep in sync with the definition from
57 * kernel/arch/sparc64/src/drivers/niagara.c.
58 */
59#define INPUT_BUFFER_SIZE ((PAGE_SIZE) - 2 * 8)
60typedef volatile struct {
61 uint64_t write_ptr;
62 uint64_t read_ptr;
63 char data[INPUT_BUFFER_SIZE];
64}
65 __attribute__ ((packed))
66 __attribute__ ((aligned(PAGE_SIZE)))
67 *input_buffer_t;
68
69/* virtual address of the shared buffer */
70input_buffer_t input_buffer;
71
72static volatile bool polling_disabled = false;
73static void niagara_thread_impl(void *arg);
74
75/**
76 * Initializes the Niagara driver.
77 * Maps the shared buffer and creates the polling thread.
78 */
79int kbd_port_init(void)
80{
81 input_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
82 int result = physmem_map(
83 (void *) sysinfo_value("niagara.inbuf.address"),
84 (void *) input_buffer_addr,
85 1, AS_AREA_READ | AS_AREA_WRITE);
86
87 if (result != 0) {
88 printf("Niagara: uspace driver couldn't map physical memory: %d\n",
89 result);
90 }
91
92 input_buffer = (input_buffer_t) input_buffer_addr;
93
94 thread_id_t tid;
95 int rc;
96
97 rc = thread_create(niagara_thread_impl, NULL, "kbd_poll", &tid);
98 if (rc != 0) {
99 return rc;
100 }
101 return 0;
102}
103
104void kbd_port_yield(void)
105{
106 polling_disabled = true;
107}
108
109void kbd_port_reclaim(void)
110{
111 polling_disabled = false;
112}
113
114void kbd_port_write(uint8_t data)
115{
116 (void) data;
117}
118
119/**
120 * Called regularly by the polling thread. Reads codes of all the
121 * pressed keys from the buffer.
122 */
123static void niagara_key_pressed(void)
124{
125 char c;
126
127 while (input_buffer->read_ptr != input_buffer->write_ptr) {
128 c = input_buffer->data[input_buffer->read_ptr];
129 input_buffer->read_ptr =
130 ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
131 kbd_push_scancode(c);
132 }
133}
134
135/**
136 * Thread to poll SGCN for keypresses.
137 */
138static void niagara_thread_impl(void *arg)
139{
140 (void) arg;
141
142 while (1) {
143 if (polling_disabled == false)
144 niagara_key_pressed();
145 usleep(POLL_INTERVAL);
146 }
147}
148/** @}
149 */
Note: See TracBrowser for help on using the repository browser.