2008-04-08 10:01:02 +04:00
|
|
|
/*
|
|
|
|
* QEMU Baum Braille Device
|
|
|
|
*
|
2016-10-23 22:54:31 +03:00
|
|
|
* Copyright (c) 2008, 2010-2011, 2016 Samuel Thibault
|
2008-04-08 10:01:02 +04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-01-29 20:49:54 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2008-04-08 10:01:02 +04:00
|
|
|
#include "qemu-common.h"
|
2013-04-08 18:55:25 +04:00
|
|
|
#include "sysemu/char.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2013-02-03 23:21:00 +04:00
|
|
|
#include "hw/usb.h"
|
2008-04-08 10:01:02 +04:00
|
|
|
#include <brlapi.h>
|
|
|
|
#include <brlapi_constants.h>
|
|
|
|
#include <brlapi_keycodes.h>
|
|
|
|
#ifdef CONFIG_SDL
|
2009-06-13 15:19:11 +04:00
|
|
|
#include <SDL_syswm.h>
|
2008-04-08 10:01:02 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
printf(fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ESC 0x1B
|
|
|
|
|
|
|
|
#define BAUM_REQ_DisplayData 0x01
|
|
|
|
#define BAUM_REQ_GetVersionNumber 0x05
|
|
|
|
#define BAUM_REQ_GetKeys 0x08
|
|
|
|
#define BAUM_REQ_SetMode 0x12
|
|
|
|
#define BAUM_REQ_SetProtocol 0x15
|
|
|
|
#define BAUM_REQ_GetDeviceIdentity 0x84
|
|
|
|
#define BAUM_REQ_GetSerialNumber 0x8A
|
|
|
|
|
|
|
|
#define BAUM_RSP_CellCount 0x01
|
|
|
|
#define BAUM_RSP_VersionNumber 0x05
|
|
|
|
#define BAUM_RSP_ModeSetting 0x11
|
|
|
|
#define BAUM_RSP_CommunicationChannel 0x16
|
|
|
|
#define BAUM_RSP_PowerdownSignal 0x17
|
|
|
|
#define BAUM_RSP_HorizontalSensors 0x20
|
|
|
|
#define BAUM_RSP_VerticalSensors 0x21
|
|
|
|
#define BAUM_RSP_RoutingKeys 0x22
|
|
|
|
#define BAUM_RSP_Switches 0x23
|
|
|
|
#define BAUM_RSP_TopKeys 0x24
|
|
|
|
#define BAUM_RSP_HorizontalSensor 0x25
|
|
|
|
#define BAUM_RSP_VerticalSensor 0x26
|
|
|
|
#define BAUM_RSP_RoutingKey 0x27
|
|
|
|
#define BAUM_RSP_FrontKeys6 0x28
|
|
|
|
#define BAUM_RSP_BackKeys6 0x29
|
|
|
|
#define BAUM_RSP_CommandKeys 0x2B
|
|
|
|
#define BAUM_RSP_FrontKeys10 0x2C
|
|
|
|
#define BAUM_RSP_BackKeys10 0x2D
|
|
|
|
#define BAUM_RSP_EntryKeys 0x33
|
|
|
|
#define BAUM_RSP_JoyStick 0x34
|
|
|
|
#define BAUM_RSP_ErrorCode 0x40
|
|
|
|
#define BAUM_RSP_InfoBlock 0x42
|
|
|
|
#define BAUM_RSP_DeviceIdentity 0x84
|
|
|
|
#define BAUM_RSP_SerialNumber 0x8A
|
|
|
|
#define BAUM_RSP_BluetoothName 0x8C
|
|
|
|
|
|
|
|
#define BAUM_TL1 0x01
|
|
|
|
#define BAUM_TL2 0x02
|
|
|
|
#define BAUM_TL3 0x04
|
|
|
|
#define BAUM_TR1 0x08
|
|
|
|
#define BAUM_TR2 0x10
|
|
|
|
#define BAUM_TR3 0x20
|
|
|
|
|
|
|
|
#define BUF_SIZE 256
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
CharDriverState *chr;
|
|
|
|
|
|
|
|
brlapi_handle_t *brlapi;
|
|
|
|
int brlapi_fd;
|
2009-06-13 17:19:25 +04:00
|
|
|
unsigned int x, y;
|
2016-10-23 22:54:32 +03:00
|
|
|
bool deferred_init;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
|
|
|
uint8_t in_buf[BUF_SIZE];
|
|
|
|
uint8_t in_buf_used;
|
|
|
|
uint8_t out_buf[BUF_SIZE];
|
|
|
|
uint8_t out_buf_used, out_buf_ptr;
|
|
|
|
|
|
|
|
QEMUTimer *cellCount_timer;
|
|
|
|
} BaumDriverState;
|
|
|
|
|
|
|
|
/* Let's assume NABCC by default */
|
2016-10-23 22:54:31 +03:00
|
|
|
enum way {
|
|
|
|
DOTS2ASCII,
|
|
|
|
ASCII2DOTS
|
|
|
|
};
|
|
|
|
static const uint8_t nabcc_translation[2][256] = {
|
2008-04-08 10:01:02 +04:00
|
|
|
#ifndef BRLAPI_DOTS
|
|
|
|
#define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \
|
|
|
|
((d1?BRLAPI_DOT1:0)|\
|
|
|
|
(d2?BRLAPI_DOT2:0)|\
|
|
|
|
(d3?BRLAPI_DOT3:0)|\
|
|
|
|
(d4?BRLAPI_DOT4:0)|\
|
|
|
|
(d5?BRLAPI_DOT5:0)|\
|
|
|
|
(d6?BRLAPI_DOT6:0)|\
|
|
|
|
(d7?BRLAPI_DOT7:0)|\
|
|
|
|
(d8?BRLAPI_DOT8:0))
|
|
|
|
#endif
|
2016-10-23 22:54:31 +03:00
|
|
|
#define DO(dots, ascii) \
|
|
|
|
[DOTS2ASCII][dots] = ascii, \
|
|
|
|
[ASCII2DOTS][ascii] = dots
|
|
|
|
DO(0, ' '),
|
|
|
|
DO(BRLAPI_DOTS(1, 0, 0, 0, 0, 0, 0, 0), 'a'),
|
|
|
|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1, 0, 1, 0), '^'),
|
|
|
|
DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 0, 0, 0), '~'),
|
|
|
|
DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 1, 0), '['),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 1, 0), ']'),
|
|
|
|
DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 0, 0), '{'),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 0, 0), '}'),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 1, 1, 1, 1, 0, 0), '='),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 1, 0, 0), '<'),
|
|
|
|
DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 0, 0, 0), '>'),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 1, 0, 0), '$'),
|
|
|
|
DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 1, 0, 0), '%'),
|
|
|
|
DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 1, 0), '@'),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 0, 0), '|'),
|
|
|
|
DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 1, 0), '\\'),
|
|
|
|
DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'),
|
2008-04-08 10:01:02 +04:00
|
|
|
};
|
|
|
|
|
2016-10-23 22:54:32 +03:00
|
|
|
/* The guest OS has started discussing with us, finish initializing BrlAPI */
|
|
|
|
static int baum_deferred_init(BaumDriverState *baum)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_SDL)
|
|
|
|
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
|
|
|
SDL_SysWMinfo info;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
int tty;
|
|
|
|
|
|
|
|
if (baum->deferred_init) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) {
|
|
|
|
brlapi_perror("baum: brlapi__getDisplaySize");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_SDL)
|
|
|
|
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
SDL_VERSION(&info.version);
|
|
|
|
if (SDL_GetWMInfo(&info)) {
|
|
|
|
tty = info.info.x11.wmwindow;
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
tty = BRLAPI_TTY_DEFAULT;
|
|
|
|
#if defined(CONFIG_SDL)
|
|
|
|
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
|
|
|
|
brlapi_perror("baum: brlapi__enterTtyMode");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
baum->deferred_init = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-08 10:01:02 +04:00
|
|
|
/* The serial port can receive more of our data */
|
|
|
|
static void baum_accept_input(struct CharDriverState *chr)
|
|
|
|
{
|
|
|
|
BaumDriverState *baum = chr->opaque;
|
|
|
|
int room, first;
|
|
|
|
|
|
|
|
if (!baum->out_buf_used)
|
|
|
|
return;
|
2011-08-15 20:17:31 +04:00
|
|
|
room = qemu_chr_be_can_write(chr);
|
2008-04-08 10:01:02 +04:00
|
|
|
if (!room)
|
|
|
|
return;
|
|
|
|
if (room > baum->out_buf_used)
|
|
|
|
room = baum->out_buf_used;
|
|
|
|
|
|
|
|
first = BUF_SIZE - baum->out_buf_ptr;
|
|
|
|
if (room > first) {
|
2011-08-15 20:17:30 +04:00
|
|
|
qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, first);
|
2008-04-08 10:01:02 +04:00
|
|
|
baum->out_buf_ptr = 0;
|
|
|
|
baum->out_buf_used -= first;
|
|
|
|
room -= first;
|
|
|
|
}
|
2011-08-15 20:17:30 +04:00
|
|
|
qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, room);
|
2008-04-08 10:01:02 +04:00
|
|
|
baum->out_buf_ptr += room;
|
|
|
|
baum->out_buf_used -= room;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to send a packet */
|
|
|
|
static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
|
|
|
|
int room;
|
|
|
|
*cur++ = ESC;
|
|
|
|
while (len--)
|
|
|
|
if ((*cur++ = *buf++) == ESC)
|
|
|
|
*cur++ = ESC;
|
2011-08-15 20:17:31 +04:00
|
|
|
room = qemu_chr_be_can_write(baum->chr);
|
2008-04-08 10:01:02 +04:00
|
|
|
len = cur - io_buf;
|
|
|
|
if (len <= room) {
|
|
|
|
/* Fits */
|
2011-08-15 20:17:30 +04:00
|
|
|
qemu_chr_be_write(baum->chr, io_buf, len);
|
2008-04-08 10:01:02 +04:00
|
|
|
} else {
|
|
|
|
int first;
|
|
|
|
uint8_t out;
|
|
|
|
/* Can't fit all, send what can be, and store the rest. */
|
2011-08-15 20:17:30 +04:00
|
|
|
qemu_chr_be_write(baum->chr, io_buf, room);
|
2008-04-08 10:01:02 +04:00
|
|
|
len -= room;
|
|
|
|
cur = io_buf + room;
|
|
|
|
if (len > BUF_SIZE - baum->out_buf_used) {
|
|
|
|
/* Can't even store it, drop the previous data... */
|
|
|
|
assert(len <= BUF_SIZE);
|
|
|
|
baum->out_buf_used = 0;
|
|
|
|
baum->out_buf_ptr = 0;
|
|
|
|
}
|
|
|
|
out = baum->out_buf_ptr;
|
|
|
|
baum->out_buf_used += len;
|
|
|
|
first = BUF_SIZE - baum->out_buf_ptr;
|
|
|
|
if (len > first) {
|
|
|
|
memcpy(baum->out_buf + out, cur, first);
|
|
|
|
out = 0;
|
|
|
|
len -= first;
|
|
|
|
cur += first;
|
|
|
|
}
|
|
|
|
memcpy(baum->out_buf + out, cur, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when the other end seems to have a wrong idea of our display size */
|
|
|
|
static void baum_cellCount_timer_cb(void *opaque)
|
|
|
|
{
|
|
|
|
BaumDriverState *baum = opaque;
|
|
|
|
uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
|
|
|
|
DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
|
|
|
|
baum_write_packet(baum, cell_count, sizeof(cell_count));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to interpret a whole incoming packet */
|
|
|
|
static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
const uint8_t *cur = buf;
|
|
|
|
uint8_t req = 0;
|
|
|
|
|
|
|
|
if (!len--)
|
|
|
|
return 0;
|
|
|
|
if (*cur++ != ESC) {
|
|
|
|
while (*cur != ESC) {
|
|
|
|
if (!len--)
|
|
|
|
return 0;
|
|
|
|
cur++;
|
|
|
|
}
|
2015-08-30 18:12:13 +03:00
|
|
|
DPRINTF("Dropped %td bytes!\n", cur - buf);
|
2008-04-08 10:01:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define EAT(c) do {\
|
|
|
|
if (!len--) \
|
|
|
|
return 0; \
|
|
|
|
if ((c = *cur++) == ESC) { \
|
|
|
|
if (!len--) \
|
|
|
|
return 0; \
|
|
|
|
if (*cur++ != ESC) { \
|
|
|
|
DPRINTF("Broken packet %#2x, tossing\n", req); \
|
2013-08-21 19:02:39 +04:00
|
|
|
if (timer_pending(baum->cellCount_timer)) { \
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(baum->cellCount_timer); \
|
2013-08-21 19:02:39 +04:00
|
|
|
baum_cellCount_timer_cb(baum); \
|
2008-04-08 10:01:02 +04:00
|
|
|
} \
|
|
|
|
return (cur - 2 - buf); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
EAT(req);
|
|
|
|
switch (req) {
|
|
|
|
case BAUM_REQ_DisplayData:
|
|
|
|
{
|
|
|
|
uint8_t cells[baum->x * baum->y], c;
|
|
|
|
uint8_t text[baum->x * baum->y];
|
|
|
|
uint8_t zero[baum->x * baum->y];
|
|
|
|
int cursor = BRLAPI_CURSOR_OFF;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Allow 100ms to complete the DisplayData packet */
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_mod(baum->cellCount_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
2016-03-21 19:02:30 +03:00
|
|
|
NANOSECONDS_PER_SECOND / 10);
|
2008-04-08 10:01:02 +04:00
|
|
|
for (i = 0; i < baum->x * baum->y ; i++) {
|
|
|
|
EAT(c);
|
|
|
|
cells[i] = c;
|
|
|
|
if ((c & (BRLAPI_DOT7|BRLAPI_DOT8))
|
|
|
|
== (BRLAPI_DOT7|BRLAPI_DOT8)) {
|
|
|
|
cursor = i + 1;
|
|
|
|
c &= ~(BRLAPI_DOT7|BRLAPI_DOT8);
|
|
|
|
}
|
2016-10-23 22:54:31 +03:00
|
|
|
c = nabcc_translation[DOTS2ASCII][c];
|
|
|
|
if (!c) {
|
2008-04-08 10:01:02 +04:00
|
|
|
c = '?';
|
2016-10-23 22:54:31 +03:00
|
|
|
}
|
2008-04-08 10:01:02 +04:00
|
|
|
text[i] = c;
|
|
|
|
}
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(baum->cellCount_timer);
|
2008-04-08 10:01:02 +04:00
|
|
|
|
|
|
|
memset(zero, 0, sizeof(zero));
|
|
|
|
|
|
|
|
brlapi_writeArguments_t wa = {
|
|
|
|
.displayNumber = BRLAPI_DISPLAY_DEFAULT,
|
|
|
|
.regionBegin = 1,
|
|
|
|
.regionSize = baum->x * baum->y,
|
2009-06-13 17:19:25 +04:00
|
|
|
.text = (char *)text,
|
2008-04-08 10:01:02 +04:00
|
|
|
.textSize = baum->x * baum->y,
|
|
|
|
.andMask = zero,
|
|
|
|
.orMask = cells,
|
|
|
|
.cursor = cursor,
|
2009-06-13 17:19:25 +04:00
|
|
|
.charset = (char *)"ISO-8859-1",
|
2008-04-08 10:01:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (brlapi__write(baum->brlapi, &wa) == -1)
|
|
|
|
brlapi_perror("baum brlapi_write");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_SetMode:
|
|
|
|
{
|
|
|
|
uint8_t mode, setting;
|
|
|
|
DPRINTF("SetMode\n");
|
|
|
|
EAT(mode);
|
|
|
|
EAT(setting);
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_SetProtocol:
|
|
|
|
{
|
|
|
|
uint8_t protocol;
|
|
|
|
DPRINTF("SetProtocol\n");
|
|
|
|
EAT(protocol);
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_GetDeviceIdentity:
|
|
|
|
{
|
|
|
|
uint8_t identity[17] = { BAUM_RSP_DeviceIdentity,
|
|
|
|
'B','a','u','m',' ','V','a','r','i','o' };
|
|
|
|
DPRINTF("GetDeviceIdentity\n");
|
|
|
|
identity[11] = '0' + baum->x / 10;
|
|
|
|
identity[12] = '0' + baum->x % 10;
|
|
|
|
baum_write_packet(baum, identity, sizeof(identity));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_GetVersionNumber:
|
|
|
|
{
|
|
|
|
uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */
|
|
|
|
DPRINTF("GetVersionNumber\n");
|
|
|
|
baum_write_packet(baum, version, sizeof(version));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_GetSerialNumber:
|
|
|
|
{
|
|
|
|
uint8_t serial[] = { BAUM_RSP_SerialNumber,
|
|
|
|
'0','0','0','0','0','0','0','0' };
|
|
|
|
DPRINTF("GetSerialNumber\n");
|
|
|
|
baum_write_packet(baum, serial, sizeof(serial));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BAUM_REQ_GetKeys:
|
|
|
|
{
|
|
|
|
DPRINTF("Get%0#2x\n", req);
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
DPRINTF("unrecognized request %0#2x\n", req);
|
|
|
|
do
|
|
|
|
if (!len--)
|
|
|
|
return 0;
|
|
|
|
while (*cur++ != ESC);
|
|
|
|
cur--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return cur - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The other end is writing some data. Store it and try to interpret */
|
|
|
|
static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
BaumDriverState *baum = chr->opaque;
|
|
|
|
int tocopy, cur, eaten, orig_len = len;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
if (!baum->brlapi)
|
|
|
|
return len;
|
2016-10-23 22:54:32 +03:00
|
|
|
if (!baum_deferred_init(baum))
|
|
|
|
return len;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
|
|
|
while (len) {
|
|
|
|
/* Complete our buffer as much as possible */
|
|
|
|
tocopy = len;
|
|
|
|
if (tocopy > BUF_SIZE - baum->in_buf_used)
|
|
|
|
tocopy = BUF_SIZE - baum->in_buf_used;
|
|
|
|
|
|
|
|
memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy);
|
|
|
|
baum->in_buf_used += tocopy;
|
|
|
|
buf += tocopy;
|
|
|
|
len -= tocopy;
|
|
|
|
|
|
|
|
/* Interpret it as much as possible */
|
|
|
|
cur = 0;
|
|
|
|
while (cur < baum->in_buf_used &&
|
|
|
|
(eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur)))
|
|
|
|
cur += eaten;
|
|
|
|
|
|
|
|
/* Shift the remainder */
|
|
|
|
if (cur) {
|
|
|
|
memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur);
|
|
|
|
baum->in_buf_used -= cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And continue if any data left */
|
|
|
|
}
|
|
|
|
return orig_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the key code to the other end */
|
|
|
|
static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
|
|
|
|
uint8_t packet[] = { type, value };
|
|
|
|
DPRINTF("writing key %x %x\n", type, value);
|
|
|
|
baum_write_packet(baum, packet, sizeof(packet));
|
|
|
|
}
|
|
|
|
|
2016-10-23 22:54:31 +03:00
|
|
|
static void baum_send_key2(BaumDriverState *baum, uint8_t type, uint8_t value,
|
|
|
|
uint8_t value2) {
|
|
|
|
uint8_t packet[] = { type, value, value2 };
|
|
|
|
DPRINTF("writing key %x %x\n", type, value);
|
|
|
|
baum_write_packet(baum, packet, sizeof(packet));
|
|
|
|
}
|
|
|
|
|
2008-04-08 10:01:02 +04:00
|
|
|
/* We got some data on the BrlAPI socket */
|
|
|
|
static void baum_chr_read(void *opaque)
|
|
|
|
{
|
|
|
|
BaumDriverState *baum = opaque;
|
|
|
|
brlapi_keyCode_t code;
|
|
|
|
int ret;
|
|
|
|
if (!baum->brlapi)
|
|
|
|
return;
|
2016-10-23 22:54:32 +03:00
|
|
|
if (!baum_deferred_init(baum))
|
|
|
|
return;
|
2008-04-08 10:01:02 +04:00
|
|
|
while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
|
|
|
|
DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
|
|
|
|
/* Emulate */
|
|
|
|
switch (code & BRLAPI_KEY_TYPE_MASK) {
|
|
|
|
case BRLAPI_KEY_TYPE_CMD:
|
|
|
|
switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
|
|
|
|
case BRLAPI_KEY_CMD_ROUTE:
|
|
|
|
baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1);
|
|
|
|
baum_send_key(baum, BAUM_RSP_RoutingKey, 0);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
switch (code & BRLAPI_KEY_CMD_ARG_MASK) {
|
|
|
|
case BRLAPI_KEY_CMD_FWINLT:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_FWINRT:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_LNUP:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_LNDN:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_TOP:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_BOT:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_TOP_LEFT:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_BOT_LEFT:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_HOME:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_CMD_PREFMENU:
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1);
|
|
|
|
baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BRLAPI_KEY_TYPE_SYM:
|
2016-10-23 22:54:31 +03:00
|
|
|
{
|
|
|
|
brlapi_keyCode_t keysym = code & BRLAPI_KEY_CODE_MASK;
|
|
|
|
if (keysym < 0x100) {
|
|
|
|
uint8_t dots = nabcc_translation[ASCII2DOTS][keysym];
|
|
|
|
if (dots) {
|
|
|
|
baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, dots);
|
|
|
|
baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-04-08 10:01:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) {
|
|
|
|
brlapi_perror("baum: brlapi_readKey");
|
|
|
|
brlapi__closeConnection(baum->brlapi);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(baum->brlapi);
|
2008-04-08 10:01:02 +04:00
|
|
|
baum->brlapi = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 12:53:02 +03:00
|
|
|
static void baum_free(struct CharDriverState *chr)
|
2010-03-28 22:39:42 +04:00
|
|
|
{
|
|
|
|
BaumDriverState *baum = chr->opaque;
|
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_free(baum->cellCount_timer);
|
2010-03-28 22:39:42 +04:00
|
|
|
if (baum->brlapi) {
|
|
|
|
brlapi__closeConnection(baum->brlapi);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(baum->brlapi);
|
2010-03-28 22:39:42 +04:00
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(baum);
|
2010-03-28 22:39:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-29 16:31:26 +03:00
|
|
|
static CharDriverState *chr_baum_init(const char *id,
|
|
|
|
ChardevBackend *backend,
|
|
|
|
ChardevReturn *ret,
|
2016-10-22 13:09:43 +03:00
|
|
|
bool *be_opened,
|
2015-09-29 16:31:26 +03:00
|
|
|
Error **errp)
|
2008-04-08 10:01:02 +04:00
|
|
|
{
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-18 01:48:37 +03:00
|
|
|
ChardevCommon *common = backend->u.braille.data;
|
2008-04-08 10:01:02 +04:00
|
|
|
BaumDriverState *baum;
|
|
|
|
CharDriverState *chr;
|
|
|
|
brlapi_handle_t *handle;
|
|
|
|
|
qemu-char: add logfile facility to all chardev backends
Typically a UNIX guest OS will log boot messages to a serial
port in addition to any graphical console. An admin user
may also wish to use the serial port for an interactive
console. A virtualization management system may wish to
collect system boot messages by logging the serial port,
but also wish to allow admins interactive access.
Currently providing such a feature forces the mgmt app
to either provide 2 separate serial ports, one for
logging boot messages and one for interactive console
login, or to proxy all output via a separate service
that can multiplex the two needs onto one serial port.
While both are valid approaches, they each have their
own downsides. The former causes confusion and extra
setup work for VM admins creating disk images. The latter
places an extra burden to re-implement much of the QEMU
chardev backends logic in libvirt or even higher level
mgmt apps and adds extra hops in the data transfer path.
A simpler approach that is satisfactory for many use
cases is to allow the QEMU chardev backends to have a
"logfile" property associated with them.
$QEMU -chardev socket,host=localhost,port=9000,\
server=on,nowait,id-charserial0,\
logfile=/var/log/libvirt/qemu/test-serial0.log
-device isa-serial,chardev=charserial0,id=serial0
This patch introduces a 'ChardevCommon' struct which
is setup as a base for all the ChardevBackend types.
Ideally this would be registered directly as a base
against ChardevBackend, rather than each type, but
the QAPI generator doesn't allow that since the
ChardevBackend is a non-discriminated union. The
ChardevCommon struct provides the optional 'logfile'
parameter, as well as 'logappend' which controls
whether QEMU truncates or appends (default truncate).
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1452516281-27519-1-git-send-email-berrange@redhat.com>
[Call qemu_chr_parse_common if cd->parse is NULL. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-01-11 15:44:41 +03:00
|
|
|
chr = qemu_chr_alloc(common, errp);
|
|
|
|
if (!chr) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
baum = g_malloc0(sizeof(BaumDriverState));
|
qemu-char: add logfile facility to all chardev backends
Typically a UNIX guest OS will log boot messages to a serial
port in addition to any graphical console. An admin user
may also wish to use the serial port for an interactive
console. A virtualization management system may wish to
collect system boot messages by logging the serial port,
but also wish to allow admins interactive access.
Currently providing such a feature forces the mgmt app
to either provide 2 separate serial ports, one for
logging boot messages and one for interactive console
login, or to proxy all output via a separate service
that can multiplex the two needs onto one serial port.
While both are valid approaches, they each have their
own downsides. The former causes confusion and extra
setup work for VM admins creating disk images. The latter
places an extra burden to re-implement much of the QEMU
chardev backends logic in libvirt or even higher level
mgmt apps and adds extra hops in the data transfer path.
A simpler approach that is satisfactory for many use
cases is to allow the QEMU chardev backends to have a
"logfile" property associated with them.
$QEMU -chardev socket,host=localhost,port=9000,\
server=on,nowait,id-charserial0,\
logfile=/var/log/libvirt/qemu/test-serial0.log
-device isa-serial,chardev=charserial0,id=serial0
This patch introduces a 'ChardevCommon' struct which
is setup as a base for all the ChardevBackend types.
Ideally this would be registered directly as a base
against ChardevBackend, rather than each type, but
the QAPI generator doesn't allow that since the
ChardevBackend is a non-discriminated union. The
ChardevCommon struct provides the optional 'logfile'
parameter, as well as 'logappend' which controls
whether QEMU truncates or appends (default truncate).
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1452516281-27519-1-git-send-email-berrange@redhat.com>
[Call qemu_chr_parse_common if cd->parse is NULL. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-01-11 15:44:41 +03:00
|
|
|
baum->chr = chr;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
|
|
|
chr->opaque = baum;
|
|
|
|
chr->chr_write = baum_write;
|
|
|
|
chr->chr_accept_input = baum_accept_input;
|
2016-10-22 12:53:02 +03:00
|
|
|
chr->chr_free = baum_free;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
handle = g_malloc0(brlapi_getHandleSize());
|
2008-04-08 10:01:02 +04:00
|
|
|
baum->brlapi = handle;
|
|
|
|
|
|
|
|
baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL);
|
|
|
|
if (baum->brlapi_fd == -1) {
|
2015-09-29 16:31:26 +03:00
|
|
|
error_setg(errp, "brlapi__openConnection: %s",
|
|
|
|
brlapi_strerror(brlapi_error_location()));
|
2008-04-08 10:01:02 +04:00
|
|
|
goto fail_handle;
|
|
|
|
}
|
2016-10-23 22:54:32 +03:00
|
|
|
baum->deferred_init = 0;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);
|
2008-04-08 10:01:02 +04:00
|
|
|
|
|
|
|
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
|
|
|
|
|
Revert "qemu-char: Print strerror message on failure" and deps
The commit's purpose is laudable:
The only way for chardev drivers to communicate an error was to
return a NULL pointer, which resulted in an error message that
said _that_ something went wrong, but not _why_.
It attempts to achieve it by changing the interface to return 0/-errno
and update qemu_chr_open_opts() to use strerror() to display a more
helpful error message. Unfortunately, it has serious flaws:
1. Backends "socket" and "udp" return bogus error codes, because
qemu_chr_open_socket() and qemu_chr_open_udp() assume that
unix_listen_opts(), unix_connect_opts(), inet_listen_opts(),
inet_connect_opts() and inet_dgram_opts() fail with errno set
appropriately. That assumption is wrong, and the commit turns
unspecific error messages into misleading error messages. For
instance:
$ qemu-system-x86_64 -nodefaults -vnc :0 -chardev socket,id=bar,host=xxx
inet_connect: host and/or port not specified
chardev: opening backend "socket" failed: No such file or directory
ENOENT is what happens to be in my errno when the backend returns
-errno. Let's put ERANGE there just for giggles:
$ qemu-system-x86_64 -nodefaults -vnc :0 -chardev socket,id=bar,host=xxx -drive if=none,iops=99999999999999999999
inet_connect: host and/or port not specified
chardev: opening backend "socket" failed: Numerical result out of range
Worse: when errno happens to be zero, return -errno erroneously
signals success, and qemu_chr_new_from_opts() dies dereferencing
uninitialized chr. I observe this with "-serial unix:".
2. All qemu_chr_open_opts() knows about the error is an errno error
code. That's simply not enough for a decent message. For instance,
when inet_dgram() can't resolve the parameter host, which errno code
should it use? What if it can't resolve parameter localaddr?
Clue: many backends already report errors in their open methods.
Let's revert the flawed commit along with its dependencies, and fix up
the silent error paths instead.
This reverts commit 6e1db57b2ac9025c2443c665a0d9e78748637b26.
Conflicts:
console.c
hw/baum.c
qemu-char.c
This reverts commit aad04cd024f0c59f0b96f032cde2e24eb3abba6d.
The parts of commit db418a0a "Add stdio char device on windows" that
depend on the reverted change fixed up.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-07 18:09:08 +04:00
|
|
|
return chr;
|
2008-04-08 10:01:02 +04:00
|
|
|
|
2009-02-06 03:49:42 +03:00
|
|
|
fail_handle:
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(handle);
|
|
|
|
g_free(chr);
|
|
|
|
g_free(baum);
|
Revert "qemu-char: Print strerror message on failure" and deps
The commit's purpose is laudable:
The only way for chardev drivers to communicate an error was to
return a NULL pointer, which resulted in an error message that
said _that_ something went wrong, but not _why_.
It attempts to achieve it by changing the interface to return 0/-errno
and update qemu_chr_open_opts() to use strerror() to display a more
helpful error message. Unfortunately, it has serious flaws:
1. Backends "socket" and "udp" return bogus error codes, because
qemu_chr_open_socket() and qemu_chr_open_udp() assume that
unix_listen_opts(), unix_connect_opts(), inet_listen_opts(),
inet_connect_opts() and inet_dgram_opts() fail with errno set
appropriately. That assumption is wrong, and the commit turns
unspecific error messages into misleading error messages. For
instance:
$ qemu-system-x86_64 -nodefaults -vnc :0 -chardev socket,id=bar,host=xxx
inet_connect: host and/or port not specified
chardev: opening backend "socket" failed: No such file or directory
ENOENT is what happens to be in my errno when the backend returns
-errno. Let's put ERANGE there just for giggles:
$ qemu-system-x86_64 -nodefaults -vnc :0 -chardev socket,id=bar,host=xxx -drive if=none,iops=99999999999999999999
inet_connect: host and/or port not specified
chardev: opening backend "socket" failed: Numerical result out of range
Worse: when errno happens to be zero, return -errno erroneously
signals success, and qemu_chr_new_from_opts() dies dereferencing
uninitialized chr. I observe this with "-serial unix:".
2. All qemu_chr_open_opts() knows about the error is an errno error
code. That's simply not enough for a decent message. For instance,
when inet_dgram() can't resolve the parameter host, which errno code
should it use? What if it can't resolve parameter localaddr?
Clue: many backends already report errors in their open methods.
Let's revert the flawed commit along with its dependencies, and fix up
the silent error paths instead.
This reverts commit 6e1db57b2ac9025c2443c665a0d9e78748637b26.
Conflicts:
console.c
hw/baum.c
qemu-char.c
This reverts commit aad04cd024f0c59f0b96f032cde2e24eb3abba6d.
The parts of commit db418a0a "Add stdio char device on windows" that
depend on the reverted change fixed up.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-07 18:09:08 +04:00
|
|
|
return NULL;
|
2008-04-08 10:01:02 +04:00
|
|
|
}
|
2013-03-05 21:51:30 +04:00
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
2015-09-29 15:55:59 +03:00
|
|
|
register_char_driver("braille", CHARDEV_BACKEND_KIND_BRAILLE, NULL,
|
2015-09-29 16:31:26 +03:00
|
|
|
chr_baum_init);
|
2013-03-05 21:51:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|