From nobody Mon Feb 9 17:08:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364152856392.48619431145346; Fri, 17 Feb 2017 12:42:32 -0800 (PST) Received: from localhost ([::1]:55795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepMM-0005fO-Ew for importer@patchew.org; Fri, 17 Feb 2017 15:42:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceoyD-0000rz-R9 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:17:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceoyB-0001pJ-M3 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:17:33 -0500 Received: from greensocs.com ([193.104.36.180]:53823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceoyB-0001o7-94 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:17:31 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id AB5F73FE89B; Fri, 17 Feb 2017 21:17:30 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZgUHxo33xBPC; Fri, 17 Feb 2017 21:17:29 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id E28FE3FE876; Fri, 17 Feb 2017 21:17:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487362650; bh=616SRDfPgx8At1ZiqKiK958YgF3ud1nC0VH2/aEpxKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tbqu7slbWdryKWGAZyRxR5iKq/aK4LEo0jQAghs7j0oDMFAQ1X2lqqSqKHJ2PCHaz +fTpMwYhD/IDvw+++jzCY9GXXsUUGPzt8LA150EtMoecAbOXJj3brxzrt/hTH310OE oP+iTkS1QW3BR88fYL66+OpTTrhuTnaZHyR+xpmk= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487362649; bh=616SRDfPgx8At1ZiqKiK958YgF3ud1nC0VH2/aEpxKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H+bFa7AEwiAAbaRT0qwCxVJu3+EcB+vpNsNseRBFl/OROu3krA8RY/prRHLC4yTE4 219EORSxcMyL7WCSBJvSA7fK65q1l+AiMgdPntJyj4td5n64FEjN+HMxPoXOTks6YO 9uFwYjgspXl1jUU5P7sHkY1H92X+cW6nnJuXfy8E= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:17:12 +0100 Message-Id: <1487362633-25018-7-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487362633-25018-1-git-send-email-fred.konrad@greensocs.com> References: <1487362633-25018-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V2 6/7] introduce mmio_interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This introduces mmio_interface object which contains a MemoryRegion and can be hotplugged/hotunplugged. Signed-off-by: KONRAD Frederic V1 -> V2: * Fix the qemu_log format. --- hw/misc/Makefile.objs | 1 + hw/misc/mmio_interface.c | 128 +++++++++++++++++++++++++++++++++++= ++++ include/hw/misc/mmio_interface.h | 49 +++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 hw/misc/mmio_interface.c create mode 100644 include/hw/misc/mmio_interface.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 898e4cc..91580a3 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -55,3 +55,4 @@ obj-$(CONFIG_EDU) +=3D edu.o obj-$(CONFIG_HYPERV_TESTDEV) +=3D hyperv_testdev.o obj-$(CONFIG_AUX) +=3D auxbus.o obj-$(CONFIG_ASPEED_SOC) +=3D aspeed_scu.o aspeed_sdmc.o +obj-y +=3D mmio_interface.o \ No newline at end of file diff --git a/hw/misc/mmio_interface.c b/hw/misc/mmio_interface.c new file mode 100644 index 0000000..6f004d2 --- /dev/null +++ b/hw/misc/mmio_interface.c @@ -0,0 +1,128 @@ +/* + * mmio_interface.c + * + * Copyright (C) 2017 : GreenSocs + * http://www.greensocs.com/ , email: info@greensocs.com + * + * Developed by : + * Frederic Konrad + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option)any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "trace.h" +#include "hw/qdev-properties.h" +#include "hw/misc/mmio_interface.h" +#include "qapi/error.h" + +#ifndef DEBUG_MMIO_INTERFACE +#define DEBUG_MMIO_INTERFACE 0 +#endif + +static uint64_t mmio_interface_counter; + +#define DPRINTF(fmt, ...) do { = \ + if (DEBUG_MMIO_INTERFACE) { = \ + qemu_log("mmio_interface: 0x%" PRIX64 ": " fmt, s->id, ## __VA_ARG= S__);\ + } = \ +} while (0); + +static void mmio_interface_init(Object *obj) +{ + MMIOInterface *s =3D MMIO_INTERFACE(obj); + + if (DEBUG_MMIO_INTERFACE) { + s->id =3D mmio_interface_counter++; + } + + DPRINTF("interface created\n"); + s->host_ptr =3D 0; + s->subregion =3D 0; +} + +static void mmio_interface_realize(DeviceState *dev, Error **errp) +{ + MMIOInterface *s =3D MMIO_INTERFACE(dev); + + DPRINTF("realize from 0x%" PRIX64 " to 0x%" PRIX64 " map host pointer" + " %p\n", s->start, s->end, s->host_ptr); + + if (!s->host_ptr) { + error_setg(errp, "host_ptr property must be set"); + } + + if (!s->subregion) { + error_setg(errp, "subregion property must be set"); + } + + memory_region_init_ram_ptr(&s->ram_mem, OBJECT(s), "ram", + s->end - s->start + 1, s->host_ptr); + memory_region_set_readonly(&s->ram_mem, s->ro); + memory_region_add_subregion(s->subregion, s->start, &s->ram_mem); +} + +static void mmio_interface_unrealize(DeviceState *dev, Error **errp) +{ + MMIOInterface *s =3D MMIO_INTERFACE(dev); + + DPRINTF("unrealize from 0x%" PRIX64 " to 0x%" PRIX64 " map host pointe= r" + " %p\n", s->start, s->end, s->host_ptr); + memory_region_del_subregion(s->subregion, &s->ram_mem); +} + +static void mmio_interface_finalize(Object *obj) +{ + MMIOInterface *s =3D MMIO_INTERFACE(obj); + + DPRINTF("finalize from 0x%" PRIX64 " to 0x%" PRIX64 " map host pointer" + " %p\n", s->start, s->end, s->host_ptr); + object_unparent(OBJECT(&s->ram_mem)); +} + +static Property mmio_interface_properties[] =3D { + DEFINE_PROP_UINT64("start", MMIOInterface, start, 0), + DEFINE_PROP_UINT64("end", MMIOInterface, end, 0), + DEFINE_PROP_PTR("host_ptr", MMIOInterface, host_ptr), + DEFINE_PROP_BOOL("ro", MMIOInterface, ro, false), + DEFINE_PROP_MEMORY_REGION("subregion", MMIOInterface, subregion), + DEFINE_PROP_END_OF_LIST(), +}; + +static void mmio_interface_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D mmio_interface_realize; + dc->unrealize =3D mmio_interface_unrealize; + dc->props =3D mmio_interface_properties; +} + +static const TypeInfo mmio_interface_info =3D { + .name =3D TYPE_MMIO_INTERFACE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(MMIOInterface), + .instance_init =3D mmio_interface_init, + .instance_finalize =3D mmio_interface_finalize, + .class_init =3D mmio_interface_class_init, +}; + +static void mmio_interface_register_types(void) +{ + type_register_static(&mmio_interface_info); +} + +type_init(mmio_interface_register_types) diff --git a/include/hw/misc/mmio_interface.h b/include/hw/misc/mmio_interf= ace.h new file mode 100644 index 0000000..90d34fb --- /dev/null +++ b/include/hw/misc/mmio_interface.h @@ -0,0 +1,49 @@ +/* + * mmio_interface.h + * + * Copyright (C) 2017 : GreenSocs + * http://www.greensocs.com/ , email: info@greensocs.com + * + * Developed by : + * Frederic Konrad + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option)any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + */ + +#ifndef MMIO_INTERFACE_H +#define MMIO_INTERFACE_H + +#include "exec/memory.h" + +#define TYPE_MMIO_INTERFACE "mmio_interface" +#define MMIO_INTERFACE(obj) OBJECT_CHECK(MMIOInterface, (obj), = \ + TYPE_MMIO_INTERFACE) + +typedef struct MMIOInterface { + DeviceState parent_obj; + + MemoryRegion *subregion; + MemoryRegion ram_mem; + uint64_t start; + uint64_t end; + bool ro; + uint64_t id; + void *host_ptr; +} MMIOInterface; + +void mmio_interface_map(MMIOInterface *s); +void mmio_interface_unmap(MMIOInterface *s); + +#endif /* MMIO_INTERFACE_H */ --=20 1.8.3.1