From patchwork Mon Sep 15 19:35:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 340 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964952; bh=QAD0DVrcyHhTtscdFiYj1HMTWTfVdOitgoffbroPkIo=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=lttHGbATA4V8N9/nf+CuJCKBhbfR79hlDL6z4bAHdKWKsYwFqeOUj4by/DtlHIlaL udo/MV4VMYvMRarao3AwhT2AxN1HLhkWQGE/250e6b8Ft3b7254+usZbsxrB1WDOYu qvCY8OnLC2pq27pm4Q9Acypg9xL8bjjezi+2ZAX0/dAo1o4PDt2ZwZRAnB/LMRXrjK ErtR7XITHHT5PJ2/+YqcKAtr9FbXxsNHLmNRLIYIaLWW/k4sOPOR+6pZTGtBlnGYhB Ir9OqWw5pCmxNaljyQdnuP/Pu1JXfKIF/SDKZ5VcAzksbkCFCyTkpW9B9y03bYeyGi BcTjsh4DycRMQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9C39467BEA for ; Mon, 15 Sep 2025 13:35:52 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id qOnPWuNUfQIv for ; Mon, 15 Sep 2025 13:35:52 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964952; bh=QAD0DVrcyHhTtscdFiYj1HMTWTfVdOitgoffbroPkIo=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=lttHGbATA4V8N9/nf+CuJCKBhbfR79hlDL6z4bAHdKWKsYwFqeOUj4by/DtlHIlaL udo/MV4VMYvMRarao3AwhT2AxN1HLhkWQGE/250e6b8Ft3b7254+usZbsxrB1WDOYu qvCY8OnLC2pq27pm4Q9Acypg9xL8bjjezi+2ZAX0/dAo1o4PDt2ZwZRAnB/LMRXrjK ErtR7XITHHT5PJ2/+YqcKAtr9FbXxsNHLmNRLIYIaLWW/k4sOPOR+6pZTGtBlnGYhB Ir9OqWw5pCmxNaljyQdnuP/Pu1JXfKIF/SDKZ5VcAzksbkCFCyTkpW9B9y03bYeyGi BcTjsh4DycRMQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 864C667B51 for ; Mon, 15 Sep 2025 13:35:52 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964949; bh=UjcH4TPPnic0V7cTzLOvFsjFWW24TcaRn+czgINHo54=; h=From:To:Cc:Subject:Date:From; b=ayTXNWHvzhq0dA7MLgmCXdjEeCBN203CTomiSJIAHz3rsi6c3NUDVKMQfbA9ttAw2 LdTvVgrlj6mwNyWIM4beATi2UzNTyRFroA5JVNfGAdV3VVZ8M4fLTBINKzNcYE5hoL WQ+EYleA0IDp06/+AHKeExq2P2Q7x7CGVvyLPd/zNbO2kckY08bTpCnFemDokAQxnP ZuaWfrJRqMpyiejFwZrvJSQ0/W29g1MOj1x9ObgTBUN9n2/QjPrPbIppgf7USMatwt E5rPPMD5VwhxIJkuUHHCu+eAcGYiqwGdS3JxJVIuFbcVpGlzniaCBLng3XECyhmZ6P zbPrbtfAcRJOg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C694367B51; Mon, 15 Sep 2025 13:35:49 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id rBBnmzOmvuZV; Mon, 15 Sep 2025 13:35:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964945; bh=WsLlyHJI3gephEhIqMMZpfd39IJwsu21dKge+yUiNis=; h=From:To:Cc:Subject:Date:From; b=ofhPNqX0LJGmpH3M0vocNlI/p1GH7eRXQkinRa12DFH3UHV1WKRMZiq1BYJscf+sn keTE656cPZXyhlQqCJm5aTNMHmvtdjSivkWNyICVJW27OqNHYYW3EFKJLhNXb4/TK+ C1kqccCNJSvbqvbXHh3Lb/ru1xV2ObeK49zpmA0y4Y/QIq3ffyfgrIiM2t4rGmqY03 5/ZIbVE2hZxL4AL8Udl40IQoxM0lCDuQ2l3cmCGxzI0GwtnyPw8781hqOFhc6e9ZLH mrcAD4kLnAh2qd1UdQ/h5xu2jLTdxRUe/TuMf0AU/vJvZCCaigNhEAMRW0MS+JBG7q H789Pdnl21cVg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 192A067B47; Mon, 15 Sep 2025 13:35:45 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 13:35:33 -0600 Message-ID: <20250915193538.2316642-1-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Message-ID-Hash: P22ZOT2H22Z3PHAMTKCKGOKMFOEUV52D X-Message-ID-Hash: P22ZOT2H22Z3PHAMTKCKGOKMFOEUV52D X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 1/3] virtio: Add input-device driver List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a virtio input device driver that supports tablets and mice using the existing mouse uclass. The driver handles absolute and relative coordinates. Mouse buttons are supported (left, right, middle). EV_SYN events are skipped. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/virtio/Kconfig | 13 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_input.c | 369 ++++++++++++++++++++++++++++++++++ 3 files changed, 383 insertions(+) create mode 100644 drivers/virtio/virtio_input.c diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index eb4ff368f12..471f40b85aa 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -110,4 +110,17 @@ config VIRTIO_SCSI A specification for the protocol is available at https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html +config VIRTIO_INPUT + bool "Input device driver for virtio devices" + depends on VIRTIO + select MOUSE + default y + help + This driver provides support for virtio-based input devices such as + tablets, mice and keyboards. It implements the mouse uclass for + tablet and pointer devices. + + A specification for the protocol is available at + https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html + endmenu diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile index f101536a863..9183dd56a79 100644 --- a/drivers/virtio/Makefile +++ b/drivers/virtio/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o obj-$(CONFIG_VIRTIO_FS) += fs.o fs_dir.o fs_file.o fs_compat.o obj-$(CONFIG_VIRTIO_SCSI) += virtio_scsi.o +obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c new file mode 100644 index 00000000000..5edc59b6037 --- /dev/null +++ b/drivers/virtio/virtio_input.c @@ -0,0 +1,369 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * VirtIO Input (tablet) driver for U-Boot + * + * Copyright 2025 Simon Glass + */ + +#define LOG_CATEGORY UCLASS_VIRTIO + +#include +#include +#include +#include +#include +#include +#include +#include + +#define VIRTIO_INPUT_CFG_UNSET 0x00 +#define VIRTIO_INPUT_CFG_ID_NAME 0x01 +#define VIRTIO_INPUT_CFG_ID_SERIAL 0x02 +#define VIRTIO_INPUT_CFG_ID_DEVIDS 0x03 +#define VIRTIO_INPUT_CFG_PROP_BITS 0x10 +#define VIRTIO_INPUT_CFG_EV_BITS 0x11 +#define VIRTIO_INPUT_CFG_ABS_INFO 0x12 + +/* absolute axis information for input devices */ +struct virtio_input_absinfo { + __le32 min; /* minimum value */ + __le32 max; /* maximum value */ + __le32 fuzz; /* fuzz value for noise filtering */ + __le32 flat; /* flat area around center */ + __le32 res; /* resolution in units per mm */ +}; + +/* device identification information */ +struct virtio_input_devids { + __le16 bustype; /* bus type identifier */ + __le16 vendor; /* vendor identifier */ + __le16 product; /* product identifier */ + __le16 version; /* version number */ +}; + +/* configuration space for querying device capabilities */ +struct vinp_config { + __u8 select; /* configuration item to select */ + __u8 subsel; /* sub-selection within item */ + __u8 size; /* size of returned data */ + __u8 reserved[5]; /* padding */ + union { + char string[128]; /* for name/serial strings */ + __u8 bitmap[128]; /* for capability bitmaps */ + struct virtio_input_absinfo abs; /* for absolute axis info */ + struct virtio_input_devids ids; /* for device IDs */ + } u; +}; + +/* input event structure (follows Linux input_event format) */ +struct virtio_input_event { + __le16 type; /* event type (EV_KEY, EV_ABS, EV_SYN, etc.) */ + __le16 code; /* event code (button/axis identifier) */ + __le32 value; /* event value */ +}; + +#define BUF_COUNT 8 +#define BUF_SIZE (16 * sizeof(struct virtio_input_event)) +#define COORD_MAX 0xffff + +/* private data for virtio input device */ +struct virtio_input_priv { + struct virtqueue *event_vq; /* event virtqueue */ + struct virtqueue *status_vq; /* status virtqueue */ + char event_bufs[BUF_COUNT][BUF_SIZE]; /* event buffers */ + bool rx_running; /* true if buffers are set up */ + int abs_x_max; /* maximum X coordinate */ + int abs_y_max; /* maximum Y coordinate */ + int button_state; /* current button state */ + int last_x; /* last X coordinate */ + int last_y; /* last Y coordinate */ +}; + +static int virtio_input_free_buffer(struct udevice *dev, void *buf) +{ + struct virtio_input_priv *priv = dev_get_priv(dev); + struct virtio_sg sg = { buf, BUF_SIZE }; + struct virtio_sg *sgs[] = { &sg }; + + /* put the buffer back to the event ring */ + virtqueue_add(priv->event_vq, sgs, 0, 1); + + return 0; +} + +static int process_event(struct virtio_input_priv *priv, + struct virtio_input_event *vio_event, + struct mouse_event *evt) +{ + u16 type = le16_to_cpu(vio_event->type); + u16 code = le16_to_cpu(vio_event->code); + u32 value = le32_to_cpu(vio_event->value); + + /* skip EV_SYN events immediately */ + if (type == EV_SYN) + return -EAGAIN; + + log_debug("processing event: type=%d code=%d value=%d\n", type, code, + value); + + switch (type) { + case EV_ABS: + if (code == ABS_X) + priv->last_x = value; + else if (code == ABS_Y) + priv->last_y = value; + + /* report motion event */ + evt->type = MOUSE_EV_MOTION; + evt->motion.state = priv->button_state; + evt->motion.x = (priv->last_x * COORD_MAX) / priv->abs_x_max; + evt->motion.y = (priv->last_y * COORD_MAX) / priv->abs_y_max; + evt->motion.xrel = 0; /* Absolute mode */ + evt->motion.yrel = 0; + return 0; + + case EV_KEY: + switch (code) { + case BTN_LEFT: + evt->type = MOUSE_EV_BUTTON; + evt->button.button = BUTTON_LEFT; + evt->button.press_state = value ? BUTTON_PRESSED : + BUTTON_RELEASED; + evt->button.clicks = 1; + evt->button.x = (priv->last_x * COORD_MAX) / + priv->abs_x_max; + evt->button.y = (priv->last_y * COORD_MAX) / + priv->abs_y_max; + + if (evt->button.press_state == BUTTON_PRESSED) + priv->button_state |= BUTTON_LEFT; + else + priv->button_state &= ~BUTTON_LEFT; + return 0; + case BTN_RIGHT: + evt->type = MOUSE_EV_BUTTON; + evt->button.button = BUTTON_RIGHT; + evt->button.press_state = value ? BUTTON_PRESSED : + BUTTON_RELEASED; + evt->button.clicks = 1; + evt->button.x = (priv->last_x * COORD_MAX) / + priv->abs_x_max; + evt->button.y = (priv->last_y * COORD_MAX) / + priv->abs_y_max; + + if (evt->button.press_state == BUTTON_PRESSED) + priv->button_state |= BUTTON_RIGHT; + else + priv->button_state &= ~BUTTON_RIGHT; + return 0; + case BTN_MIDDLE: + evt->type = MOUSE_EV_BUTTON; + evt->button.button = BUTTON_MIDDLE; + evt->button.press_state = value ? BUTTON_PRESSED : + BUTTON_RELEASED; + evt->button.clicks = 1; + evt->button.x = (priv->last_x * COORD_MAX) / + priv->abs_x_max; + evt->button.y = (priv->last_y * COORD_MAX) / + priv->abs_y_max; + + if (evt->button.press_state == BUTTON_PRESSED) + priv->button_state |= BUTTON_MIDDLE; + else + priv->button_state &= ~BUTTON_MIDDLE; + return 0; + } + break; + } + + return -EAGAIN; +} + +static int virtio_input_start(struct udevice *dev) +{ + struct virtio_input_priv *priv = dev_get_priv(dev); + + if (!priv->rx_running) { + struct virtio_sg sg; + struct virtio_sg *sgs[] = { &sg }; + int i; + + /* setup event buffers */ + sg.length = BUF_SIZE; + + /* add all buffers to the event queue */ + for (i = 0; i < BUF_COUNT; i++) { + sg.addr = priv->event_bufs[i]; + virtqueue_add(priv->event_vq, sgs, 0, 1); + } + + virtqueue_kick(priv->event_vq); + + /* setup the event queue only once */ + priv->rx_running = true; + log_debug("VirtIO input buffers initialized\n"); + } + + return 0; +} + +static int virtio_input_get_event(struct udevice *dev, struct mouse_event *evt) +{ + struct virtio_input_priv *priv = dev_get_priv(dev); + struct virtio_input_event *vio_event; + int i, num_events, ret; + void *buf; + uint len; + + /* ensure buffers are setup */ + ret = virtio_input_start(dev); + if (ret) + return ret; + + log_debug("starting\n"); + + /* check for ready buffer */ + buf = virtqueue_get_buf(priv->event_vq, &len); + if (!buf) { + log_debug("No events available\n"); + return -EAGAIN; + } + + log_debug("got buffer back: addr=%p len=%d\n", buf, len); + if (len < sizeof(struct virtio_input_event)) { + log_debug("Invalid event length: %d\n", len); + /* put buffer back */ + virtio_input_free_buffer(dev, buf); + return -EAGAIN; + } + + /* process all events in the buffer */ + num_events = len / sizeof(struct virtio_input_event); + vio_event = (struct virtio_input_event *)buf; + + for (i = 0; i < num_events; i++) { + ret = process_event(priv, &vio_event[i], evt); + if (!ret) { + /* + * found a valid event to return, put buffer back + * Note: this loses any remaining events in the buffer, + * but for input devices this is acceptable + */ + virtio_input_free_buffer(dev, buf); + return 0; + } + /* -EAGAIN means continue to next event */ + } + + /* no useful events found, put buffer back */ + virtio_input_free_buffer(dev, buf); + evt->type = MOUSE_EV_NULL; + + return -EAGAIN; +} + +static int virtio_input_probe(struct udevice *dev) +{ + struct virtio_input_priv *priv = dev_get_priv(dev); + struct virtqueue *vqs[2]; + struct vinp_config cfg; + int ret; + + ret = virtio_find_vqs(dev, 2, vqs); + if (ret) { + log_debug("Failed to find virtqueues: %d\n", ret); + return ret; + } + + priv->event_vq = vqs[0]; + priv->status_vq = vqs[1]; + + /* check what event types this device supports */ + cfg.select = VIRTIO_INPUT_CFG_EV_BITS; + cfg.subsel = EV_KEY; + virtio_cwrite8(dev, offsetof(struct vinp_config, select), cfg.select); + virtio_cwrite8(dev, offsetof(struct vinp_config, subsel), cfg.subsel); + virtio_cread_bytes(dev, offsetof(struct vinp_config, u.bitmap), + cfg.u.bitmap, 16); + log_debug("EV_KEY bitmap: %02x %02x %02x %02x\n", cfg.u.bitmap[0], + cfg.u.bitmap[1], cfg.u.bitmap[2], cfg.u.bitmap[3]); + + cfg.select = VIRTIO_INPUT_CFG_EV_BITS; + cfg.subsel = EV_REL; + virtio_cwrite8(dev, offsetof(struct vinp_config, select), cfg.select); + virtio_cwrite8(dev, offsetof(struct vinp_config, subsel), cfg.subsel); + virtio_cread_bytes(dev, offsetof(struct vinp_config, u.bitmap), + cfg.u.bitmap, 16); + log_debug("EV_REL bitmap: %02x %02x %02x %02x\n", cfg.u.bitmap[0], + cfg.u.bitmap[1], cfg.u.bitmap[2], cfg.u.bitmap[3]); + + /* check if this device supports absolute coordinates (tablet) */ + cfg.select = VIRTIO_INPUT_CFG_EV_BITS; + cfg.subsel = EV_ABS; + virtio_cwrite8(dev, offsetof(struct vinp_config, select), cfg.select); + virtio_cwrite8(dev, offsetof(struct vinp_config, subsel), cfg.subsel); + + /* read the bitmap to see if ABS_X and ABS_Y are supported */ + virtio_cread_bytes(dev, offsetof(struct vinp_config, u.bitmap), + cfg.u.bitmap, 16); + + log_debug("EV_ABS bitmap: %02x %02x %02x %02x\n", cfg.u.bitmap[0], + cfg.u.bitmap[1], cfg.u.bitmap[2], cfg.u.bitmap[3]); + + /* check if ABS_X (0) and ABS_Y (1) bits are set */ + if ((cfg.u.bitmap[0] & (1 << 0)) && + (cfg.u.bitmap[0] & (1 << 1))) { + /* get ABS_X range */ + cfg.select = VIRTIO_INPUT_CFG_ABS_INFO; + cfg.subsel = ABS_X; + virtio_cwrite8(dev, offsetof(struct vinp_config, select), + cfg.select); + virtio_cwrite8(dev, offsetof(struct vinp_config, subsel), + cfg.subsel); + virtio_cread_bytes(dev, offsetof(struct vinp_config, u.abs), + &cfg.u.abs, sizeof(cfg.u.abs)); + priv->abs_x_max = le32_to_cpu(cfg.u.abs.max); + + /* get ABS_Y range */ + cfg.subsel = ABS_Y; + virtio_cwrite8(dev, offsetof(struct vinp_config, subsel), + cfg.subsel); + virtio_cread_bytes(dev, offsetof(struct vinp_config, u.abs), + &cfg.u.abs, sizeof(cfg.u.abs)); + priv->abs_y_max = le32_to_cpu(cfg.u.abs.max); + + log_debug("tablet: X range 0-%d, Y range 0-%d\n", + priv->abs_x_max, priv->abs_y_max); + } else { + /* no absolute coordinates, use default range */ + priv->abs_x_max = 32767; + priv->abs_y_max = 32767; + log_debug("table: No absolute coords, using relative mode\n"); + } + + return 0; +} + +static int virtio_input_bind(struct udevice *dev) +{ + struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(dev->parent); + + /* indicate what driver features we support */ + virtio_driver_features_init(uc_priv, NULL, 0, NULL, 0); + + return 0; +} + +static const struct mouse_ops virtio_input_ops = { + .get_event = virtio_input_get_event, +}; + +U_BOOT_DRIVER(virtio_input) = { + .name = VIRTIO_INPUT_DRV_NAME, + .id = UCLASS_MOUSE, + .bind = virtio_input_bind, + .probe = virtio_input_probe, + .ops = &virtio_input_ops, + .priv_auto = sizeof(struct virtio_input_priv), + .flags = DM_FLAG_ACTIVE_DMA, +}; From patchwork Mon Sep 15 19:35:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 341 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964957; bh=Oit+OY3OoH8rysB/8KmdsxCUgw4Y0LdBP3kCmJrYKbU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=PSYoBPwidtkzJZJv0SCF0nzpRC4dUyaBGZKCr4oULyUsmnGptTmcTo654ECWbqQnn H0ntNUnl8vzixf7BakiU4ygHbb0nsN3XFRG4ALy4msI6Q5b+D6UauJ5Nabw3EfuDMb srDbXdD4W356FihttwladYlzjL4uMj/hA9u2IrLlw0kHZ8ySTlyx5FKYTN3KLPwY1t slFW1x5xYs7Tdzgm9ZiE9g4TkCTFjA8GbDSZbZ+ksn4LM/jNbIEbFWMZbrDzAUR/nw LNM18Gebb4uZ80xjQZ7ZLDFPhn0JLcKynFdAiNeGCh0FU9aCZM9u1O6ImoEE5FmkV/ Rd5HV/wzukJlg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1692667BE9 for ; Mon, 15 Sep 2025 13:35:57 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id iW5JuxVgiHNz for ; Mon, 15 Sep 2025 13:35:57 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964957; bh=Oit+OY3OoH8rysB/8KmdsxCUgw4Y0LdBP3kCmJrYKbU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=PSYoBPwidtkzJZJv0SCF0nzpRC4dUyaBGZKCr4oULyUsmnGptTmcTo654ECWbqQnn H0ntNUnl8vzixf7BakiU4ygHbb0nsN3XFRG4ALy4msI6Q5b+D6UauJ5Nabw3EfuDMb srDbXdD4W356FihttwladYlzjL4uMj/hA9u2IrLlw0kHZ8ySTlyx5FKYTN3KLPwY1t slFW1x5xYs7Tdzgm9ZiE9g4TkCTFjA8GbDSZbZ+ksn4LM/jNbIEbFWMZbrDzAUR/nw LNM18Gebb4uZ80xjQZ7ZLDFPhn0JLcKynFdAiNeGCh0FU9aCZM9u1O6ImoEE5FmkV/ Rd5HV/wzukJlg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0648A67B51 for ; Mon, 15 Sep 2025 13:35:57 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964955; bh=7wqfTGJPEuHtIOZp2zZ5NaeP0iZ2CF7iG2q7NWylxK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kccLXZ7YCDT2oLVmvkQnvHoefKfVXH5sl2nNtWWk0BnvTsJf/Z6t9Kc4PGAmnFvrU UjcZ6BW9aMOXyWcby4tkCLL4o9lOaqsWgYPVPJInaZIvFOBQjLhByoyEKVVHOnGITS 6l7Ct88FPSIYpGPHwQSG4s4MP4gFbhhqwJ0u6YN3H7kS53LX1u/YNpYFtSq9Bh4PD+ efDyhvyk53tFexeKQ0+Qh58X+mn17q58BrqoD1gYlrYrpnETd3A5mTnnq+0x2VtHuv IUyUo4Zh99TwpOdy8NngV8Fo9xgrSoLCxzE8yr1fuKFRR5zxuuOmQ8XM4GPJ1DM/sb 2niLB8zimiYlg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0BF2967BC8; Mon, 15 Sep 2025 13:35:55 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id hlUHCiid0tmc; Mon, 15 Sep 2025 13:35:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964950; bh=KQWJdB9IjCYysvyC19gTwKf5Y8U1fO2C88AwHA+L7cw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9UxKxbksPj8flfm2dAk2Gx5BCFsWeTTyCLGEmLPxDLZAB+d/2Jgyhz5R8Qi8546X QNXsxGGbwEAm+ksqm0ei8R3tROG3TgGhIApWxKL0UGUDsYxYAt1crcwqvXIQLZvXoo 5WzKhaA7jHDAeq5XboDv1tksOBj69IXD1lHxew3+fa+X9j9q7P67Y8Sc6bEmmsi/7a LaaD1DUduX5AlAJH+AfmEnKmI5IkBDbmR1jhjMSLP/M4UqH4OUii7CFZMvAvVVQpX/ uXWQYtJPI4ObDBZDzKr4eHxOhUNwRsz9MVA/ruRNTaWqi2G4pkLvkLFpul93xN2bCk 50GaRAjYYgGNQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1549467B47; Mon, 15 Sep 2025 13:35:50 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 13:35:34 -0600 Message-ID: <20250915193538.2316642-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915193538.2316642-1-sjg@u-boot.org> References: <20250915193538.2316642-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YZXHJ2KJYPQZW2HF4X6V3RVCX556KOL2 X-Message-ID-Hash: YZXHJ2KJYPQZW2HF4X6V3RVCX556KOL2 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 2/3] mouse: Allow selecting the device to use List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Enhance the mouse dump command to support selecting a specific mouse device by number. This allows testing multiple mouse devices when available in the system. Add some documentation while we are here. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/mouse.c | 16 +++++++--- doc/usage/cmd/mouse.rst | 66 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 doc/usage/cmd/mouse.rst diff --git a/cmd/mouse.c b/cmd/mouse.c index 60210b9f868..ee19bb07aea 100644 --- a/cmd/mouse.c +++ b/cmd/mouse.c @@ -18,13 +18,21 @@ static int do_mouse_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct udevice *dev; bool running; int count; + int mouse_dev = 0; int ret; - ret = uclass_first_device_err(UCLASS_MOUSE, &dev); + /* Parse optional device number */ + if (argc > 1) + mouse_dev = dectoul(argv[1], NULL); + + /* Get the specified mouse device */ + ret = uclass_get_device(UCLASS_MOUSE, mouse_dev, &dev); if (ret) { - printf("Mouse not found (err=%d)\n", ret); + printf("Mouse device %d not found (err=%d)\n", mouse_dev, ret); return CMD_RET_FAILURE; } + + printf("Using mouse device %d: %s\n", mouse_dev, dev->name); for (running = true, count = 0; running;) { struct mouse_event evt; @@ -63,7 +71,7 @@ static int do_mouse_dump(struct cmd_tbl *cmdtp, int flag, int argc, } static char mouse_help_text[] = - "dump - Dump input from a mouse"; + "dump [dev] - Dump input from mouse device (default: 0)"; U_BOOT_CMD_WITH_SUBCMDS(mouse, "Mouse input", mouse_help_text, - U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_mouse_dump)); + U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_mouse_dump)); diff --git a/doc/usage/cmd/mouse.rst b/doc/usage/cmd/mouse.rst new file mode 100644 index 00000000000..665980111ae --- /dev/null +++ b/doc/usage/cmd/mouse.rst @@ -0,0 +1,66 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +.. index:: + single: mouse (command) + +mouse command +============= + +Synopsis +-------- + +:: + + mouse dump [dev] + +The mouse command is used to access mouse input devices. + +mouse dump +---------- + +Dump input events from a mouse device in real-time. Events are displayed +until the user presses Ctrl+C to stop. + +dev + Optional device number (default: 0). Use this to select a specific mouse + device when multiple mouse devices are available. + +The command displays: +- Motion events with absolute/relative coordinates and button state +- Button events (left, right, middle) with press/release state and position +- Event count when finished + +Example +------- + +:: + + => mouse dump + Using mouse device 0: xhci_pci.p0.usb_hub.p6.usb_mo + motion: Xrel=-27, Yrel=84, X=0, Y=84, but=0 + motion: Xrel=-78, Yrel=87, X=0, Y=171, but=0 + motion: Xrel=-1, Yrel=87, X=0, Y=258, but=0 + motion: Xrel=76, Yrel=88, X=76, Y=346, but=0 + button: button==0, press=1, clicks=1, X=76, Y=346 + motion: Xrel=76, Yrel=88, X=152, Y=434, but=1 + motion: Xrel=76, Yrel=88, X=228, Y=522, but=1 + motion: Xrel=76, Yrel=88, X=304, Y=610, but=1 + motion: Xrel=76, Yrel=88, X=380, Y=698, but=1 + button: button==0, press=0, clicks=1, X=380, Y=698 + motion: Xrel=76, Yrel=88, X=456, Y=786, but=0 + motion: Xrel=76, Yrel=88, X=532, Y=874, but=0 + motion: Xrel=50, Yrel=88, X=582, Y=962, but=0 + motion: Xrel=-1, Yrel=87, X=581, Y=1049, but=0 + motion: Xrel=76, Yrel=87, X=657, Y=1136, but=0 + motion: Xrel=-104, Yrel=86, X=553, Y=1222, but=0 + motion: Xrel=24, Yrel=86, X=577, Y=1308, but=0 + motion: Xrel=-104, Yrel=85, X=473, Y=1393, but=0 + 18 events received + + => mouse dump 1 + Mouse device 1 not found (err=-19) + +Configuration +------------- + +The mouse command is available when CONFIG_CMD_MOUSE is enabled. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index eeda632b1a0..c03ea7df7c4 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -94,6 +94,7 @@ Shell commands cmd/mbr cmd/md cmd/mmc + cmd/mouse cmd/msr cmd/mtest cmd/mtrr From patchwork Mon Sep 15 19:35:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 342 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964961; bh=qEjysFB1Y0xTdQRaK/2FnhDmPrfGP6M69b9DOKlHAJ8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=V6YZ2dS3Up4Wc9UksS5jcHDiw4LDbfh7rQDstUwWpoqfjL2gLmY88ifpOyxra0d3w ki3BrZCY25LBbYRBs8aN3s9IuYag7owx33mKn6b19osw7crnbLlj3xMtj1cX/8495y 2sno4v60TTEtp9+y6Y/849teOI0kS7rLdpyE+TnrVr0Uw9bsKdgNIluMLXGbcCdqb3 PukhePUI/F5YVhYo+gZie6Qde4uvd7He6CLL2pmpBvf2/rTAR5dYzDLfb9mPzpONHT 9wU4v/zwJyL8VINf9LNeKPAqsa/u2QfPbvMbAzbWz5zpV8sUqN9VAEUO1m5Q+tjChT Q3j4WVH/VmhZg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 743C267B47 for ; Mon, 15 Sep 2025 13:36:01 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id N231yq_e9AKc for ; Mon, 15 Sep 2025 13:36:01 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964961; bh=qEjysFB1Y0xTdQRaK/2FnhDmPrfGP6M69b9DOKlHAJ8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=V6YZ2dS3Up4Wc9UksS5jcHDiw4LDbfh7rQDstUwWpoqfjL2gLmY88ifpOyxra0d3w ki3BrZCY25LBbYRBs8aN3s9IuYag7owx33mKn6b19osw7crnbLlj3xMtj1cX/8495y 2sno4v60TTEtp9+y6Y/849teOI0kS7rLdpyE+TnrVr0Uw9bsKdgNIluMLXGbcCdqb3 PukhePUI/F5YVhYo+gZie6Qde4uvd7He6CLL2pmpBvf2/rTAR5dYzDLfb9mPzpONHT 9wU4v/zwJyL8VINf9LNeKPAqsa/u2QfPbvMbAzbWz5zpV8sUqN9VAEUO1m5Q+tjChT Q3j4WVH/VmhZg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 60DC067B4B for ; Mon, 15 Sep 2025 13:36:01 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964959; bh=Lu2PSXBQlRtOKScfU6PwG1rHscFtDtgokudeWbjyaa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ky4wfMCGqU06cW8ZQKh/zg/8K7Fza/vhpBiYFUSqCmPTJ2qmLtCx9XbSuRxIJgVI+ aS76hi4IV7pKPxvvvuLq7Sa1KQmfZgF59udF8xEgDZNNubjPmAJqhIawAG6d1w9BXD T0qS/dOWswC2c3v7M/ViOZPEMQyyfqbbKHuGYG6Ha7wHeI4ACTWb5vsLOgt6q+xS5O eAI5FrzyIMe7fq8C5LHvlbfXouG2cdEJbjOWW5Dc9rznjUuj6j74m6v5iCF5Jr/o+D h52I1MDm5tdYjfDOkT+lQ/wrV/AOjQJ9VK+Xre3sPfjG1XqElwmKKlES324lYsull0 EMOK1t071Zu8Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 61FF267B47; Mon, 15 Sep 2025 13:35:59 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id qvDgpLCM_EII; Mon, 15 Sep 2025 13:35:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757964955; bh=QB5mD3OsxbyK3yANRz/7pGpX6E6aazheMjW3Ck7Ag/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X+FCuOIGWy/E0Ezpa4+O4Yf3RLDSinACs2HPrgJVxj7PZ16EQBWOvQlF05wkO3mNh 1+0ta0WJ6EkjZoLHdNoGESGtnFgKe6ldrH0F8nTqtMnVTh7/lk6EVAjwO5vCc3EYk8 YHYaNEktV5LKGszDidb4f1HwfRrjBo5pOi67dzFcMum6dTA+cbyYM5kSOM9xExUTsm 60LGi14lzaAmVKkd5RYa/WKTIsnOv7/qN0VB7tYrl4rfeHG/RK3CiBNk5Dd2PiL8mu Sfvb1AdF+fQtMkliECL1eF0yNC+KLpPZ3qdxxwsUGZLbLjbWHNjQZYKMLopk6rQu2+ dlz32l4sIjVSA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BB44267B4B; Mon, 15 Sep 2025 13:35:54 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 13:35:35 -0600 Message-ID: <20250915193538.2316642-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915193538.2316642-1-sjg@u-boot.org> References: <20250915193538.2316642-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6KD7SOG4QMSYC4V3JTYXSVLYI557ML44 X-Message-ID-Hash: 6KD7SOG4QMSYC4V3JTYXSVLYI557ML44 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 3/3] build-qemu: Use the virtio tablet instead of USB for x86 List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Switch the x86 QEMU configuration to use virtio-tablet-pci instead of usb-tablet. This allows testing the new virtio input device driver and does not need 'usb start' to work. The virtio tablet provides the same functionality as USB tablet but integrates with the VirtIO subsystem that U-Boot already supports. Signed-off-by: Simon Glass --- scripts/build-qemu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/build-qemu b/scripts/build-qemu index 62f0bc41fad..cba3a54b9e6 100755 --- a/scripts/build-qemu +++ b/scripts/build-qemu @@ -278,7 +278,8 @@ class BuildQemu: qemu_cmd.extend(['-display', 'default,show-cursor=on']) elif self.args.arch == 'x86': qemu_cmd.extend(['-device', 'qemu-xhci']) - qemu_cmd.extend(['-device', 'usb-kbd', '-device', 'usb-tablet']) + qemu_cmd.extend(['-device', 'usb-kbd']) + qemu_cmd.extend(['-device', 'virtio-tablet-pci']) qemu_cmd.extend(['-display', 'default,show-cursor=on']) if not any(item.startswith('-serial') for item in self.qemu_extra): qemu_cmd.extend(['-serial', 'mon:stdio'])