From patchwork Mon Oct 17 19:38:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9380449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9F7760487 for ; Mon, 17 Oct 2016 20:02:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAA7D28EB7 for ; Mon, 17 Oct 2016 20:02:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF69E2916D; Mon, 17 Oct 2016 20:02:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 64B9F28EB7 for ; Mon, 17 Oct 2016 20:02:33 +0000 (UTC) Received: from localhost ([::1]:35610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwE7E-00057a-JI for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 16:02:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDkU-0001SR-Nk for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:39:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwDkT-0007wL-NX for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:39:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwDkO-0007sr-OG; Mon, 17 Oct 2016 15:38:56 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB8E580F63; Mon, 17 Oct 2016 19:38:55 +0000 (UTC) Received: from localhost.redhat.com (vpn1-5-170.ams2.redhat.com [10.36.5.170]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9HJcVFY009529; Mon, 17 Oct 2016 15:38:52 -0400 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, peter.maydell@linaro.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, pranav.sawargaonkar@gmail.com Date: Mon, 17 Oct 2016 19:38:27 +0000 Message-Id: <1476733110-14293-6-git-send-email-eric.auger@redhat.com> In-Reply-To: <1476733110-14293-1-git-send-email-eric.auger@redhat.com> References: <1476733110-14293-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Oct 2016 19:38:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v5 5/8] hw: platform-bus: Enable to map any memory region onto the platform-bus 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: diana.craciun@freescale.com, Bharat.Bhushan@freescale.com, drjones@redhat.com, christoffer.dall@linaro.org, fkan@apm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The platform bus is currently used to map dynamically instantiable platform device MMIO regions. The platform bus also can be seen as a pool of free guest physical addresses. We would like to use that pool to allocate a contiguous reserved IOVA region usable for MSI message address IOMMU mapping. This patch introduces platform_bus_map_region which enables to map any memory region onto the platform bus. Signed-off-by: Eric Auger Reviewed-by: Peter Maydell --- v2 -> v3: include qapi/error.h --- hw/core/platform-bus.c | 27 +++++++++++++++++---------- include/hw/platform-bus.h | 7 +++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c index 329ac67..3fb6f6f 100644 --- a/hw/core/platform-bus.c +++ b/hw/core/platform-bus.c @@ -24,6 +24,7 @@ #include "exec/address-spaces.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "qapi/error.h" /* @@ -127,16 +128,14 @@ static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev, sysbus_connect_irq(sbdev, n, pbus->irqs[irqn]); } -static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, - int n) +void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr) { - MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n); - uint64_t size = memory_region_size(sbdev_mr); + uint64_t size = memory_region_size(mr); uint64_t alignment = (1ULL << (63 - clz64(size + size - 1))); uint64_t off; bool found_region = false; - if (memory_region_is_mapped(sbdev_mr)) { + if (memory_region_is_mapped(mr)) { /* Region is already mapped, nothing to do */ return; } @@ -153,13 +152,21 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, } if (!found_region) { - error_report("Platform Bus: Can not fit MMIO region of size %"PRIx64, - size); - exit(1); + error_setg(&error_fatal, + "Platform Bus: Can not fit region %s of size %"PRIx64, + mr->name, size); } - /* Map the device's region into our Platform Bus MMIO space */ - memory_region_add_subregion(&pbus->mmio, off, sbdev_mr); + /* Map the region into our Platform Bus MMIO space */ + memory_region_add_subregion(&pbus->mmio, off, mr); +} + +static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, + int n) +{ + MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n); + + platform_bus_map_region(pbus, sbdev_mr); } /* diff --git a/include/hw/platform-bus.h b/include/hw/platform-bus.h index a00775c..6d3a664 100644 --- a/include/hw/platform-bus.h +++ b/include/hw/platform-bus.h @@ -54,4 +54,11 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus, SysBusDevice *sbdev, hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus, SysBusDevice *sbdev, int n); +/** + * platform_bus_map_region: map a MemoryRegion into the platform bus + * @pbus: platform bus handle + * @mr: memory region handle + */ +void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr); + #endif /* HW_PLATFORM_BUS_H */