From patchwork Fri Jan 29 16:53:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8164981 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAE2A9F440 for ; Fri, 29 Jan 2016 16:54:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20B2420253 for ; Fri, 29 Jan 2016 16:54:35 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 6BCB2200C1 for ; Fri, 29 Jan 2016 16:54:34 +0000 (UTC) Received: from localhost ([::1]:35297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCJd-000273-S7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jan 2016 11:54:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCJL-0001z7-HF for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPCJK-00040P-Hq for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:15 -0500 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:35299) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCJJ-00040E-PM for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:14 -0500 Received: by mail-wm0-x232.google.com with SMTP id r129so76815185wmr.0 for ; Fri, 29 Jan 2016 08:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cUaClOHOsI/mnYVCntu90jCxKDVL9nn7DHGtYXXK/KY=; b=gKsSVT0YIlfkXaJGzrZvCkUVRtNkZxCiOWP02iSRqtC3WlVJSWUQXuyylhCPXEGxSy YGanPRoYGivFFGNpHMZ4joiZl17whp6SMhr2zV4TrlA/GUZi8gpt/PGvbwpiBHLlWJRG TIGIwB5N8l4Fz3e5RkSfxH0IXRU0eYLhnmhto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cUaClOHOsI/mnYVCntu90jCxKDVL9nn7DHGtYXXK/KY=; b=RDj8HANGADHRhfnEU7K/Tz8ktZvmRXmgCl85yexyxcqY0lM7PmPDErdHKsIHuffVIg J8TzbHuzBjl4Dajsm4c8RkxLm6yZhcq9Wtu1D3I0llP8QptmSJJ1zL1YEZnHRNlsiC2J k+kBxjr9TSFQnrWtKP3jC+VnjtiJFSaL9OfIuxHKmPYgXjOuWFvUCxtK/LSHxuRGZp6K m5fcKFfRUtJNoATlIZgFQyu48afZNlFpxm8ihorfGAyj85gaSV8gzbFLdOMWwtdmd/cn xMWSxTMTO/a2o9LdSFg+9WXIufxmI6wzQsfXWmnVQxNM3bixbor0MJn26dWxUncwh97a JpLw== X-Gm-Message-State: AG10YOQGZmbYi6FNozu34Ln7QYWfx1K837kglm0BZWX01rKRI02kC5KmpVUNGSCieD+bhQww X-Received: by 10.194.21.135 with SMTP id v7mr9823113wje.131.1454086453091; Fri, 29 Jan 2016 08:54:13 -0800 (PST) Received: from new-host-12.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id ei9sm16415530wjd.40.2016.01.29.08.54.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 08:54:11 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, alex.williamson@redhat.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, pbonzini@redhat.com, agraf@suse.de Date: Fri, 29 Jan 2016 16:53:47 +0000 Message-Id: <1454086429-4373-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454086429-4373-1-git-send-email-eric.auger@linaro.org> References: <1454086429-4373-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Cc: Bharat.Bhushan@freescale.com, suravee.suthikulpanit@amd.com, christoffer.dall@linaro.org Subject: [Qemu-devel] [RFC v2 6/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.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The platform bus currently is 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 --- hw/core/platform-bus.c | 26 ++++++++++++++++---------- include/hw/platform-bus.h | 7 +++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c index aa55d01..7d0f5e0 100644 --- a/hw/core/platform-bus.c +++ b/hw/core/platform-bus.c @@ -128,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; } @@ -154,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 bd42b83..ee19674 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 region 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 */