source: mainline/uspace/srv/hid/input/port/niagara.c@ f7cbc6f

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

Remove the two-phase way of creating virtual memory areas (first asking for a mappable address and then mapping it) which was prone to race conditions when two or more calls to as_get_mappable_page() and as_area_create() were interleaved. This for example caused the e1k driver to randomly fail.

The memory area related syscalls and IPC calls have all been altered to accept a special value (void *) -1, representing a demand to atomically search for a mappable address space "hole" and map to it.

Individual changes:

  • IPC_M_SHARE_OUT: the destination address space area is supplied by the kernel, the callee only specifies the lower bound

(the address is returned to the callee via a pointer in an IPC reply argument)

  • IPC_M_SHARE_IN: the destination address space ares is supplied by the kernel, the callee only specifies the lower bound

(the address is returned to the caller as usual via an IPC argument)

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