From nobody Tue Nov 26 10:51:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1708006315; cv=none; d=zohomail.com; s=zohoarc; b=LDy97a2viW5fKkB4yOV/aiTGiMTa/+bjIS93iLqn1AtoeKEL+W7C9n0W0PcBr/KimSnfwcPtY40s/RosMtosjBFQQT9GPP3m2J7wm36sL12+W1vsW01kU+ibJ2INcpXp/JkRTSFniWbeQ10sZq6Jk0OVrHGnrsGho13KQbxdDGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708006315; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KP6i+B6MLL2wkbYjl8abKTqzuoFKsngNSwGHVWde45g=; b=hNeAFdgQ7agR+w2MdyiNZZmPzk/sYHCEpjNaPG6ipD9PqaMlPnKIAfcG85zBQKnlw92M3UcQB86g/3gKS3Xzkh2sAM63ChUTp+6kzhioWSTjtvkoJ2CFW4/lA34AhtdI4zlposaUhdSQEbgYBcohLmIZkWvTsK7sZkfcFHRynvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708006315977926.4727451816198; Thu, 15 Feb 2024 06:11:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1racSM-0008Uc-Gf; Thu, 15 Feb 2024 09:11:18 -0500 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 1racSJ-0008UK-Uz for qemu-devel@nongnu.org; Thu, 15 Feb 2024 09:11:15 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1racSI-0006c8-00 for qemu-devel@nongnu.org; Thu, 15 Feb 2024 09:11:15 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-411fc61a03dso7761705e9.3 for ; Thu, 15 Feb 2024 06:11:11 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id az32-20020a05600c602000b00411bff9f7cbsm2253684wmb.37.2024.02.15.06.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:11:09 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8FD9E5F8AD; Thu, 15 Feb 2024 14:11:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708006270; x=1708611070; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KP6i+B6MLL2wkbYjl8abKTqzuoFKsngNSwGHVWde45g=; b=bjW9z8wYxkFVY3Gic+ETZJaE/lKHuwSOAavGjuqKlAlFl4TQfSi8Via3Nig+5Uho5b ZMS1uI1RACg4elenv5gf9Db0D0aGbtjDepLesNYSCB9zqsn12yWJsJKirG7NtY1i1Qol nV3af81Et3AYprNamjPjs29xTl6C6axK50pd85haV3QTRdbLueoXgrkryDk5EdLpRf6V L6hWgKJNipdLFfVr9xuUK6XXHRzgUtdsrVcDZlFyCSVl3VA6FRK9S7WHKKd+W/QXzEkP ZUNKfaaaOPPnC2sRB2640qiPAqu191kj1diqsgqx+h0r1yugukXfnhtdg+gg0T5XzYHr GLNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708006270; x=1708611070; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KP6i+B6MLL2wkbYjl8abKTqzuoFKsngNSwGHVWde45g=; b=PBQrIzoza9VnUfcZna05HhjfdGb1TFUODuz7ep3kEvdIOvS/+CaQGvyondOzNK3Wkr eU2zJqqvaPsD59ZLsF2hhG9YuaklkW2+iTo7/AytMar3gW79k/f2jzoI1e0grs77BmqY /BZCFKx3SsAzc6BjTYzcHSSsH5ImMCHYOYPXz5FA+cL+HO5yomCcsVqE5NlHXqfSDlJG qB7NQFbrGukD3fJHkGOLFcZ1Y4uC8VB8//dri9L1brY5P1zdUgL7mVnL03zZAxX5NH1b KfF1FvUto+kfK1pjO4Z/ERqysswnWj59z/pk55wC+m1XRpEP3pgtiROjmTVrT0btqoEq DinQ== X-Gm-Message-State: AOJu0Yxed1sOKQIy+QTC2vxF3JQRh60oetrXWTwtqtKAPCwv1Z4UMzhJ SbcBbXbP+Qlw6czRO8DlkgbqTZolQoMoImottQrbJvSKGnE3DipjUIxw7pOB5iU= X-Google-Smtp-Source: AGHT+IFwCFqt3BfoswasiB4f+GEoizh5kQ77j6XhpPdWD+Pvi32vkAPOI+RokET9vClrhgu1GJ1sUA== X-Received: by 2002:a05:600c:384c:b0:412:1954:b9e8 with SMTP id s12-20020a05600c384c00b004121954b9e8mr1382586wmr.3.1708006270244; Thu, 15 Feb 2024 06:11:10 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Manos Pitsidianakis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH] hw/misc: add a user creatable dummy device for debugging Date: Thu, 15 Feb 2024 14:10:55 +0000 Message-Id: <20240215141055.55173-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708006316880100001 This is an experimental patch to allow the creation of unimp regions from the command line. I'm not sure we would ever merge it as generally unimp regions are created by the machine definition and adding your own regions into existing device spaces is likely to break things pretty badly. However what I was looking for was a simple way to test that a Xen XFT test was accessing and trapping where I thought it was without hacking up the machine models themselves. It allows the addition of unimp regions to specific address spaces as in the future we shouldn't rely on sysbus being the default but it's pretty clunky as you need to intuit the full QOM path of the region, e.g.: /qemu-system-aarch64 -machine fby35 --display none \ -serial mon:stdio -d unimp \ --device dummy-device,name=3Ddummy1,offset=3D0x10001000,size=3D0x1000,x= -address-space=3D"/machine/unattached/fsi.opb[0]" Then running info mtree -f shows: ... FlatView #15 AS "fsi.opb", root: fsi.opb Root memory region: fsi.opb 0000000010001000-0000000010001fff (prio 0, i/o): dummy1 0000000080000000-000000008fffffff (prio 0, i/o): fsi.master 00000000a0000000-00000000a00003ff (prio 0, i/o): cfam.config 00000000a0000400-00000000a00007ff (prio 0, i/o): cfam @0000000000000400 00000000a0000800-00000000a0000bff (prio 0, i/o): fsi.slave 00000000a0000c00-00000000a0000fff (prio 0, i/o): fsi.scratchpad 00000000a0001000-00000000a01fffff (prio 0, i/o): cfam @0000000000001000 No need to review this RFC unless you particularly think this would be useful to develop further. Signed-off-by: Alex Benn=C3=A9e Cc: Manos Pitsidianakis Cc: Philippe Mathieu-Daud=C3=A9 --- hw/misc/dummy.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 hw/misc/dummy.c diff --git a/hw/misc/dummy.c b/hw/misc/dummy.c new file mode 100644 index 00000000000..701c3468951 --- /dev/null +++ b/hw/misc/dummy.c @@ -0,0 +1,97 @@ +/* + * user creatable dummy device wrapper + * + * This is a simple wrapper around the unimp device + * + * Copyright (c) 2024 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/address-spaces.h" +#include "hw/misc/unimp.h" + +#define TYPE_DUMMY_DEVICE "dummy-device" + +OBJECT_DECLARE_SIMPLE_TYPE(DummyDeviceState, DUMMY_DEVICE) + +struct DummyDeviceState { + DeviceState parent_obj; + + DeviceState *unimp; + + MemoryRegion *mr; + + char *name; + char *as_name; + uint64_t offset; + uint64_t size; +}; + +static void dummy_realize(DeviceState *dev, Error **errp) +{ + DummyDeviceState *s =3D DUMMY_DEVICE(dev); + + if (s->size =3D=3D 0) { + error_setg(errp, "property 'size' not specified or zero"); + return; + } + + if (s->name =3D=3D NULL) { + error_setg(errp, "property 'name' not specified"); + return; + } + + if (s->as_name =3D=3D NULL) { + s->mr =3D get_system_memory(); + } else { + bool ambiguous =3D false; + /* this needs to be a full path. e.g. /machine/unattached/foo[0] */ + Object *obj =3D object_resolve_path_type(s->as_name, TYPE_MEMORY_R= EGION, &ambiguous); + if (!obj || ambiguous) { + error_setg(errp, "Unable to find %s to locate region", s->as_n= ame); + return; + } + s->mr =3D MEMORY_REGION(obj); + } + + /* + * While this is a test device we don't want to make it too easy + * to shoot yourself in the foot. + */ + s->unimp =3D qdev_new(TYPE_UNIMPLEMENTED_DEVICE); + qdev_prop_set_string(s->unimp, "name", s->name); + qdev_prop_set_uint64(s->unimp, "size", s->size); + sysbus_realize_and_unref(SYS_BUS_DEVICE(s->unimp), &error_fatal); + + /* Now lets map it to memory */ + memory_region_add_subregion_overlap(s->mr, s->offset, &UNIMPLEMENTED_D= EVICE(s->unimp)->iomem, 0); +} + +static Property dummy_properties[] =3D { + DEFINE_PROP_UINT64("offset", DummyDeviceState, offset, 0), + DEFINE_PROP_UINT64("size", DummyDeviceState, size, 0), + DEFINE_PROP_STRING("name", DummyDeviceState, name), + DEFINE_PROP_STRING("x-address-space", DummyDeviceState, as_name), + DEFINE_PROP_END_OF_LIST(), +}; + +static void dummy_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D dummy_realize; + device_class_set_props(dc, dummy_properties); +} + +static const TypeInfo dummy_devices[] =3D { + { + .name =3D TYPE_DUMMY_DEVICE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(DummyDeviceState), + .class_init =3D dummy_class_init, + } +}; + +DEFINE_TYPES(dummy_devices) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index e4ef1da5a53..309314e2398 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -5,7 +5,7 @@ system_ss.add(when: 'CONFIG_ISA_DEBUG', if_true: files('deb= ugexit.c')) system_ss.add(when: 'CONFIG_ISA_TESTDEV', if_true: files('pc-testdev.c')) system_ss.add(when: 'CONFIG_PCA9552', if_true: files('pca9552.c')) system_ss.add(when: 'CONFIG_PCI_TESTDEV', if_true: files('pci-testdev.c')) -system_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) +system_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c', 'dummy.c')) system_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) system_ss.add(when: 'CONFIG_LED', if_true: files('led.c')) system_ss.add(when: 'CONFIG_PVPANIC_COMMON', if_true: files('pvpanic.c')) --=20 2.39.2