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

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

allow compositor and console to coexist side-by-side, use the input server as a poor man's seat arbitrator

  • kernel console notifies both about the release and grab events
  • input server arbitrates the seat selection between kernel console and any number of user space UIs (currently the console server and the compositor server)
  • input port yield and reclaim methods have been removed (they are used only on Ski and Niagara, both already need a more generic mechanism for the kernel/user space cooperation)
  • console and compositor server keep track of the kernel console via the input arbitration
  • move the waiting for a character device from init and terminal widget to getterm
  • Property mode set to 100644
File size: 3.8 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 * @{
[b6a088f]33 */
[eeb643d]34/** @file
[b6a088f]35 * @brief Niagara console keyboard port driver.
[eeb643d]36 */
37
38#include <as.h>
39#include <ddi.h>
40#include <async.h>
41#include <sysinfo.h>
42#include <stdio.h>
43#include <thread.h>
[3e6a98c5]44#include <stdbool.h>
[d9fae235]45#include <errno.h>
[b6a088f]46#include "../kbd_port.h"
47#include "../kbd.h"
[eeb643d]48
[9be360ee]49static int niagara_port_init(kbd_dev_t *);
[b1bdc7a4]50static void niagara_port_write(uint8_t data);
51
52kbd_port_ops_t niagara_port = {
53 .init = niagara_port_init,
54 .write = niagara_port_write
55};
56
[9be360ee]57static kbd_dev_t *kbd_dev;
58
[d9fae235]59#define POLL_INTERVAL 10000
[eeb643d]60
[86018c1]61/*
62 * Kernel counterpart of the driver pushes characters (it has read) here.
63 * Keep in sync with the definition from
64 * kernel/arch/sparc64/src/drivers/niagara.c.
65 */
[d9fae235]66#define INPUT_BUFFER_SIZE ((PAGE_SIZE) - 2 * 8)
67
[86018c1]68typedef volatile struct {
69 uint64_t write_ptr;
70 uint64_t read_ptr;
71 char data[INPUT_BUFFER_SIZE];
[bf9cb2f]72} __attribute__((packed)) __attribute__((aligned(PAGE_SIZE))) *input_buffer_t;
[86018c1]73
[8e33e1d]74/* virtual address of the shared buffer */
[bf9cb2f]75static input_buffer_t input_buffer = (input_buffer_t) AS_AREA_ANY;
[86018c1]76
[b473611]77static void niagara_thread_impl(void *arg);
[eeb643d]78
79/**
[8e33e1d]80 * Initializes the Niagara driver.
[bf9cb2f]81 * Maps the shared buffer and creates the polling thread.
[eeb643d]82 */
[9be360ee]83static int niagara_port_init(kbd_dev_t *kdev)
[eeb643d]84{
[9be360ee]85 kbd_dev = kdev;
86
[d9fae235]87 sysarg_t paddr;
88 if (sysinfo_get_value("niagara.inbuf.address", &paddr) != EOK)
89 return -1;
90
[8442d10]91 int rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE,
92 (void *) &input_buffer);
[d9fae235]93 if (rc != 0) {
[86018c1]94 printf("Niagara: uspace driver couldn't map physical memory: %d\n",
[d9fae235]95 rc);
96 return rc;
[86018c1]97 }
[d9fae235]98
[eeb643d]99 thread_id_t tid;
100 rc = thread_create(niagara_thread_impl, NULL, "kbd_poll", &tid);
[d9fae235]101 if (rc != 0)
[eeb643d]102 return rc;
[d9fae235]103
[eeb643d]104 return 0;
105}
106
[b1bdc7a4]107static void niagara_port_write(uint8_t data)
[eeb643d]108{
109 (void) data;
110}
111
112/**
[8e33e1d]113 * Called regularly by the polling thread. Reads codes of all the
[ce3efa0]114 * pressed keys from the buffer.
[eeb643d]115 */
116static void niagara_key_pressed(void)
117{
118 char c;
119
[86018c1]120 while (input_buffer->read_ptr != input_buffer->write_ptr) {
121 c = input_buffer->data[input_buffer->read_ptr];
122 input_buffer->read_ptr =
[1875a0c]123 ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
124 kbd_push_data(kbd_dev, c);
[eeb643d]125 }
126}
127
128/**
[336d2f52]129 * Thread to poll Niagara console for keypresses.
[eeb643d]130 */
[b473611]131static void niagara_thread_impl(void *arg)
[eeb643d]132{
133 (void) arg;
134
135 while (1) {
[593e023]136 niagara_key_pressed();
[eeb643d]137 usleep(POLL_INTERVAL);
138 }
139}
140/** @}
141 */
Note: See TracBrowser for help on using the repository browser.