1.1 --- a/pkg/devices/input/src/server/input-keypad-server.cc Sun Jun 11 15:42:11 2023 +0200
1.2 +++ b/pkg/devices/input/src/server/input-keypad-server.cc Sun Jun 18 00:19:36 2023 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Provide access to keypad events on the configured device.
1.6 *
1.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -21,123 +21,16 @@
1.13
1.14 #include <l4/devices/dataspace.h>
1.15 #include <l4/devices/keypad-loader.h>
1.16 -#include "input-event-client.h"
1.17 +
1.18 #include "input-event-server.h"
1.19 -#include "input-event-ops.h"
1.20 #include "input-keypad-client.h"
1.21
1.22 -#include <l4/cxx/ipc_stream>
1.23 -#include <l4/re/dataspace>
1.24 -#include <l4/re/env>
1.25 #include <l4/re/event>
1.26 -#include <l4/re/util/br_manager>
1.27 -#include <l4/re/util/cap_alloc>
1.28 -#include <l4/re/util/object_registry>
1.29 -#include <l4/sys/capability>
1.30 -#include <l4/sys/icu>
1.31 -#include <l4/sys/kip.h>
1.32 -#include <l4/sys/types.h>
1.33 -#include <l4/util/util.h>
1.34 -
1.35 -#include <stdio.h>
1.36 -
1.37 -/* Extract a fpage from the message buffers. Provide a Snd_fpage reference for
1.38 - modification. */
1.39 -
1.40 -static
1.41 -void get_fpage(L4::Ipc::Iostream &ios, L4::Ipc::Snd_item &fpage)
1.42 -{
1.43 - l4_msgtag_t tag = ios.tag();
1.44 -
1.45 - if (!tag.items())
1.46 - return;
1.47 -
1.48 - /* Extract the fpage details directly since the stream operator doesn't seem
1.49 - to work. */
1.50 -
1.51 - l4_msg_regs_t *m = l4_utcb_mr_u(l4_utcb());
1.52 - l4_umword_t b = m->mr[tag.words()], d = m->mr[tag.words() + 1];
1.53 - fpage = L4::Ipc::Snd_item(b, d);
1.54 -}
1.55 -
1.56 -/* Handle invocations. */
1.57 -
1.58 -int
1.59 -Input_event_server::dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
1.60 -{
1.61 - l4_msgtag_t tag;
1.62 - l4_umword_t op;
1.63 - unsigned irqnum;
1.64 - L4::Ipc::Snd_fpage fpage;
1.65 -
1.66 - (void) obj;
1.67 - ios >> tag;
1.68 -
1.69 - switch (tag.label())
1.70 - {
1.71 - case L4::Meta::Protocol:
1.72 - return L4::Util::handle_meta_request<Input_event_interface>(ios);
1.73
1.74 - case L4RE_PROTO_EVENT:
1.75 - ios >> op;
1.76 - switch (op)
1.77 - {
1.78 - /* Reset the buffer state and return the buffer memory capability. */
1.79 -
1.80 - case Input_event_op_get_buffer:
1.81 - _events.reset();
1.82 - ios << _mem;
1.83 - return L4_EOK;
1.84 -
1.85 - default:
1.86 - return -L4_EINVAL;
1.87 - }
1.88 -
1.89 - case L4_PROTO_IRQ:
1.90 - ios >> op;
1.91 - switch (op)
1.92 - {
1.93 - /* Just obtain the interrupt capability. */
1.94 -
1.95 - case Input_event_op_bind:
1.96 - ios >> irqnum;
1.97 - get_fpage(ios, fpage);
1.98 -
1.99 - if (!fpage.cap_received())
1.100 - return -L4_EINVAL;
1.101 +#include <ipc/cap_alloc.h>
1.102 +#include <ipc/server.h>
1.103
1.104 - _irq = server_iface()->rcv_cap<L4::Irq>(0);
1.105 - return server_iface()->realloc_rcv_cap(0);
1.106 -
1.107 - default:
1.108 - return -L4_EINVAL;
1.109 - }
1.110 -
1.111 - default:
1.112 - return -L4_EBADPROTO;
1.113 - }
1.114 -}
1.115 -
1.116 -
1.117 -
1.118 -/* Event sending methods. */
1.119 -
1.120 -void
1.121 -Input_event_server::send_event(int type, int code, int value)
1.122 -{
1.123 - L4Re::Event_buffer::Event event;
1.124 -
1.125 - event.time = l4_kip_clock(l4re_kip());
1.126 - event.payload.stream_id = 0;
1.127 - event.payload.type = type;
1.128 - event.payload.code = code;
1.129 - event.payload.value = value;
1.130 -
1.131 - /* Queue the event and trigger the interrupt. */
1.132 -
1.133 - _events.put(event);
1.134 - _irq->trigger();
1.135 -}
1.136 +#include "input_server.h"
1.137
1.138
1.139
1.140 @@ -150,43 +43,44 @@
1.141
1.142
1.143
1.144 -static L4Re::Util::Registry_server<L4Re::Util::Br_manager_hooks> server;
1.145 -
1.146 -
1.147 -
1.148 int main(void)
1.149 {
1.150 - // Load the keypad details from the configured library.
1.151 + /* Load the keypad details from the configured library. */
1.152
1.153 - Keypad *keypad = load_keypad();
1.154 + Keypad_generic *keypad = load_keypad();
1.155 Input_keypad_client client(keypad);
1.156 void *buffer;
1.157
1.158 - // Memory allocation capability for the event data.
1.159 + /* Memory allocation capability for the event data. */
1.160
1.161 - L4::Cap<L4Re::Dataspace> mem = allocate_data(L4_PAGESIZE, &buffer);
1.162 - if (!mem.is_valid()) return 1;
1.163 + l4re_ds_t mem = allocate_data(L4_PAGESIZE, &buffer);
1.164 +
1.165 + if (l4_is_invalid_cap(mem))
1.166 + return 1;
1.167
1.168 /* Obtain a capability for the interrupt. */
1.169
1.170 - L4::Cap<L4::Irq> irq = L4Re::Util::cap_alloc.alloc<L4::Irq>();
1.171 - if (!irq.is_valid()) return 1;
1.172 + l4_cap_idx_t irq = ipc_cap_alloc();
1.173
1.174 - // Event buffer for the data.
1.175 + if (l4_is_invalid_cap(irq))
1.176 + return 1;
1.177 +
1.178 + /* Event buffer for the data. */
1.179
1.180 L4Re::Event_buffer events(buffer, L4_PAGESIZE);
1.181
1.182 - // Initialise and register a server object.
1.183 + /* Initialise and register a server object. */
1.184
1.185 - Input_event_server server_obj(mem, events);
1.186 - server.registry()->register_obj(&server_obj, "ev");
1.187 + Input_event_server obj(mem, events);
1.188 +
1.189 + /* Attach the event handler and wait for events. */
1.190
1.191 - // Attach the event handler and wait for events.
1.192 + client.attach(handler, (void *) &obj);
1.193
1.194 - client.attach(handler, (void *) &server_obj);
1.195 + /* Bind and start the IPC server loop. */
1.196
1.197 - // Enter the IPC server loop.
1.198 + if (ipc_server_loop_for(Input, &obj, "ev"))
1.199 + return 1;
1.200
1.201 - server.loop();
1.202 return 0;
1.203 }