From patchwork Mon Oct 30 11:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 739250 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1069600wrt; Mon, 30 Oct 2023 04:49:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1xdOQJWjkH2NbCu/fsBmSRdp5PQ6QAa3FrUaWBL67XWAz3oOXQLgFeudBqTbTGltfozI/ X-Received: by 2002:a05:6808:159c:b0:3ae:349:7c03 with SMTP id t28-20020a056808159c00b003ae03497c03mr12360761oiw.27.1698666566662; Mon, 30 Oct 2023 04:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698666566; cv=none; d=google.com; s=arc-20160816; b=L+FIhb9ZB5J7g8j/O+68Alx7nGyMn/GMrd8haxsmEL1hYGVpJUUtKnnrrB+QvnC0Im Msuu4wD3Ahq+wZmUxPUuOemM9m52srxbE/i/JJcN9xPzDt0nPL10KDAtSHdGMZzZuK82 K2BVSejW3z41kD9OO8RhwLgizthWTlNl/zD0hH/dRYmwuZ3/syGc/AgFQYhYu1nKWYQn 84N5jI/KHkT4jym9FCvOd5jrurqvN+wd2M5P8EF/bppETTrcs68Q2W49RjHRImAdmJS0 HvxjrWFnVs5K1/3g38HMxNEWnMyiZMiMyYOgsQa7HLVZjOnmDL5SjlSgfIVfjTpxYU6y 1r/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O90ie1atxSZ2cUPAqsKjlZB5/Uff17Peypjb2gXw96c=; fh=yUeHCMY0O7AHgYs4WRBJtcSGK81/h+/8SdmYaglLfmk=; b=fbf+LdfRHic/Ij0hhfLqDTsHmNJa6GrAe0EJT5jRDhTVsSm/8CBXA5wKdgbLlfw9Z9 Y1rAe0TDX4bHdB6pmtPcdUBgsZXdQE/is2Rlvw6AiUro8a16p33Dz5SeeD64O1ms2VVR 6mc/AdFNTpnnikRCS4C0OlrnqKZe5j/4OaXXl3x1++8HKs33dIZYgMvG0C2piJUAUbvO U6nFGpV7+VklTw14z0iwBxZLUyZKNRx1lkqVcnIJI4mT43LOo8IO+dN5KDDuJla+tx+o HZiX0gaRiVfsd91d+aQ4Wiu16LWJT6z1UJtQoMx3EeyMt9OqG9GKBnbAWwQxUhvpKEB2 c5rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g5Indu2F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bt5-20020ad455c5000000b0066d1b4ce85bsi5563230qvb.532.2023.10.30.04.49.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 04:49:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g5Indu2F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxQkk-0007yR-CK; Mon, 30 Oct 2023 07:48:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxQke-0007tH-FP for qemu-devel@nongnu.org; Mon, 30 Oct 2023 07:48:12 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxQka-0007IQ-42 for qemu-devel@nongnu.org; Mon, 30 Oct 2023 07:48:12 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-407da05f05aso33342675e9.3 for ; Mon, 30 Oct 2023 04:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698666486; x=1699271286; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O90ie1atxSZ2cUPAqsKjlZB5/Uff17Peypjb2gXw96c=; b=g5Indu2F2rMHDrpc3FL6HaETtNZFlBHRBn2NKBNGLUMF/yuuXtuaQ7ka0whZWHxgHR hB7Ky2+EEYSklIogXFgV4kMY+nOPMNiVIZCCNvTzJAJSakc7wqQIVUJfRRu19qHZaQhi oBUTnCkZQNBX73AXl0KtnQ1j1MnOA7gQfUXvH2sdsjBqL18hkob88FjrDcK52dI3k7lu IE9gXW5CX5cPIuvz4gjrfCEEo6aPFCivM2eQi+fLhRa9L5OK30Yi2vN3QA1U2FtKq74M tkLJGXnMNugwbWawPs0sWmA+D/DP6XuccwV+DbKK7BKdkcJKzdeZjbSLWoSu4g/rLCi0 jD4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698666486; x=1699271286; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O90ie1atxSZ2cUPAqsKjlZB5/Uff17Peypjb2gXw96c=; b=NQf5AeTI1i6gsF+nLuCmRR2K7O5hRZbni+3fhTcbniwTmGqXJOjGBSLCj8Pmv+EfHn yUPXpELDd1AEpDZPwE5WbQyW7nWkVs+PMKLVZK7gvZFxSu7YKqLF8MwIptSY7UFA9lzO p4hrAEEU1hMgQjatY2FHfgp2hSu1yxk4to4wwQFjrkANkrQTOEK5ssiAX92myZeIYg9S YfFuEeHtEoU/idVojOZS7xpU/Sv1aD6+kH7jsRimaw03tr0iNw0XkbwZB6yYgLrIIx2A oDI/1LxraqVTfqzQH3WMitivkH+zY3JgPwS1lU3/wMZN14JTHZUmzc+tbYn/SglUQ4r/ uUvQ== X-Gm-Message-State: AOJu0Yw+WVLTIXpmxXaEHEZbtsdZv5htPKXI6S8xeAa6FkELHRMMSMuM WqEZ7xFZDF9QD0Q2Zv+kO9dQ8A== X-Received: by 2002:adf:ec52:0:b0:32d:a405:b6b7 with SMTP id w18-20020adfec52000000b0032da405b6b7mr7479988wrn.32.1698666486672; Mon, 30 Oct 2023 04:48:06 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id az30-20020adfe19e000000b0032f7d7ec4adsm5262268wrb.92.2023.10.30.04.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 04:48:06 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Kevin Wolf Subject: [PATCH v2 5/6] hw/input/stellaris_input: Convert to qdev Date: Mon, 30 Oct 2023 11:48:01 +0000 Message-Id: <20231030114802.3671871-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030114802.3671871-1-peter.maydell@linaro.org> References: <20231030114802.3671871-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Convert the hw/input/stellaris_input device to qdev. The interface uses an array property for the board to specify the keycodes to use, so the s->keycodes memory is now allocated by the array-property machinery. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- v1->v2: drop private/public comment lines --- include/hw/input/stellaris_gamepad.h | 22 ++++++++- hw/arm/stellaris.c | 26 +++++++--- hw/input/stellaris_gamepad.c | 73 +++++++++++++++++++--------- 3 files changed, 89 insertions(+), 32 deletions(-) diff --git a/include/hw/input/stellaris_gamepad.h b/include/hw/input/stellaris_gamepad.h index 23cfd3c95f3..6140b889a28 100644 --- a/include/hw/input/stellaris_gamepad.h +++ b/include/hw/input/stellaris_gamepad.h @@ -11,8 +11,26 @@ #ifndef HW_INPUT_STELLARIS_GAMEPAD_H #define HW_INPUT_STELLARIS_GAMEPAD_H +#include "hw/sysbus.h" +#include "qom/object.h" -/* stellaris_gamepad.c */ -void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode); +/* + * QEMU interface: + * + QOM array property "keycodes": uint32_t QEMU keycodes to handle + * + unnamed GPIO outputs: one per keycode, in the same order as the + * "keycodes" array property entries; asserted when key is down + */ + +#define TYPE_STELLARIS_GAMEPAD "stellaris-gamepad" +OBJECT_DECLARE_SIMPLE_TYPE(StellarisGamepad, STELLARIS_GAMEPAD) + +struct StellarisGamepad { + SysBusDevice parent_obj; + uint32_t num_buttons; + qemu_irq *irqs; + uint32_t *keycodes; + uint8_t *pressed; + int extension; +}; #endif diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index 96585dd7106..707b0dae375 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -31,6 +31,7 @@ #include "hw/timer/stellaris-gptm.h" #include "hw/qdev-clock.h" #include "qom/object.h" +#include "qapi/qmp/qlist.h" #define GPIO_A 0 #define GPIO_B 1 @@ -1274,16 +1275,27 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) sysbus_connect_irq(SYS_BUS_DEVICE(enet), 0, qdev_get_gpio_in(nvic, 42)); } if (board->peripherals & BP_GAMEPAD) { - qemu_irq gpad_irq[5]; + QList *gpad_keycode_list = qlist_new(); static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d }; + DeviceState *gpad; - gpad_irq[0] = qemu_irq_invert(gpio_in[GPIO_E][0]); /* up */ - gpad_irq[1] = qemu_irq_invert(gpio_in[GPIO_E][1]); /* down */ - gpad_irq[2] = qemu_irq_invert(gpio_in[GPIO_E][2]); /* left */ - gpad_irq[3] = qemu_irq_invert(gpio_in[GPIO_E][3]); /* right */ - gpad_irq[4] = qemu_irq_invert(gpio_in[GPIO_F][1]); /* select */ + gpad = qdev_new(TYPE_STELLARIS_GAMEPAD); + for (i = 0; i < ARRAY_SIZE(gpad_keycode); i++) { + qlist_append_int(gpad_keycode_list, gpad_keycode[i]); + } + qdev_prop_set_array(gpad, "keycodes", gpad_keycode_list); + sysbus_realize_and_unref(SYS_BUS_DEVICE(gpad), &error_fatal); - stellaris_gamepad_init(5, gpad_irq, gpad_keycode); + qdev_connect_gpio_out(gpad, 0, + qemu_irq_invert(gpio_in[GPIO_E][0])); /* up */ + qdev_connect_gpio_out(gpad, 1, + qemu_irq_invert(gpio_in[GPIO_E][1])); /* down */ + qdev_connect_gpio_out(gpad, 2, + qemu_irq_invert(gpio_in[GPIO_E][2])); /* left */ + qdev_connect_gpio_out(gpad, 3, + qemu_irq_invert(gpio_in[GPIO_E][3])); /* right */ + qdev_connect_gpio_out(gpad, 4, + qemu_irq_invert(gpio_in[GPIO_F][1])); /* select */ } for (i = 0; i < 7; i++) { if (board->dc4 & (1 << i)) { diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index 82ddc47a26d..6ccf0e80adc 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -8,19 +8,13 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/input/stellaris_gamepad.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "ui/console.h" -typedef struct { - uint32_t num_buttons; - int extension; - qemu_irq *irqs; - uint32_t *keycodes; - uint8_t *pressed; -} StellarisGamepad; - static void stellaris_gamepad_put_key(void * opaque, int keycode) { StellarisGamepad *s = (StellarisGamepad *)opaque; @@ -57,22 +51,55 @@ static const VMStateDescription vmstate_stellaris_gamepad = { } }; -/* Returns an array of 5 output slots. */ -void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode) +static void stellaris_gamepad_realize(DeviceState *dev, Error **errp) { - StellarisGamepad *s; - int i; + StellarisGamepad *s = STELLARIS_GAMEPAD(dev); - s = g_new0(StellarisGamepad, 1); - s->irqs = g_new0(qemu_irq, n); - s->keycodes = g_new0(uint32_t, n); - s->pressed = g_new0(uint8_t, n); - for (i = 0; i < n; i++) { - s->irqs[i] = irq[i]; - s->keycodes[i] = keycode[i]; + if (s->num_buttons == 0) { + error_setg(errp, "keycodes property array must be set"); + return; } - s->num_buttons = n; - qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s); - vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, - &vmstate_stellaris_gamepad, s); + + s->irqs = g_new0(qemu_irq, s->num_buttons); + s->pressed = g_new0(uint8_t, s->num_buttons); + qdev_init_gpio_out(dev, s->irqs, s->num_buttons); + qemu_add_kbd_event_handler(stellaris_gamepad_put_key, dev); } + +static void stellaris_gamepad_reset_enter(Object *obj, ResetType type) +{ + StellarisGamepad *s = STELLARIS_GAMEPAD(obj); + + memset(s->pressed, 0, s->num_buttons * sizeof(uint8_t)); +} + +static Property stellaris_gamepad_properties[] = { + DEFINE_PROP_ARRAY("keycodes", StellarisGamepad, num_buttons, + keycodes, qdev_prop_uint32, uint32_t), + DEFINE_PROP_END_OF_LIST(), +}; + +static void stellaris_gamepad_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + + rc->phases.enter = stellaris_gamepad_reset_enter; + dc->realize = stellaris_gamepad_realize; + dc->vmsd = &vmstate_stellaris_gamepad; + device_class_set_props(dc, stellaris_gamepad_properties); +} + +static const TypeInfo stellaris_gamepad_info = { + .name = TYPE_STELLARIS_GAMEPAD, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(StellarisGamepad), + .class_init = stellaris_gamepad_class_init, +}; + +static void stellaris_gamepad_register_types(void) +{ + type_register_static(&stellaris_gamepad_info); +} + +type_init(stellaris_gamepad_register_types);