From patchwork Fri Mar 25 13:48:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 64486 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp183754lbc; Fri, 25 Mar 2016 06:51:57 -0700 (PDT) X-Received: by 10.55.215.83 with SMTP id m80mr17285758qki.84.1458913917189; Fri, 25 Mar 2016 06:51:57 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x189si10797878qhb.21.2016.03.25.06.51.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Mar 2016 06:51:57 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajS8Y-0002VO-UH; Fri, 25 Mar 2016 13:50:50 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajS8X-0002Ta-A2 for xen-devel@lists.xen.org; Fri, 25 Mar 2016 13:50:49 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 69/45-07120-83245F65; Fri, 25 Mar 2016 13:50:48 +0000 X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-3.tower-21.messagelabs.com!1458913846!5381573!1 X-Originating-IP: [209.85.220.51] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54569 invoked from network); 25 Mar 2016 13:50:47 -0000 Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by server-3.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 25 Mar 2016 13:50:47 -0000 Received: by mail-pa0-f51.google.com with SMTP id td3so46702409pab.2 for ; Fri, 25 Mar 2016 06:50:47 -0700 (PDT) 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=G67LBwlLp7ANiJNA0RPVbY1e46w+lwkhPeCs75AmZCQ=; b=B0WbN9yxICSSz7noEL1dKCk+RytToT3D0Xqe4RFVDmhLG5U818OIdV3GE47VLqM4lf Ia6jxXXclDwIpq8ut6uvsg+zsegORzDGDuN+0e9do4uRrp6mzJfSmDIgKWdgwE+fIe46 NSBVSuic6IMDXSR9pKGTLZhiZAOC7sgT+HyYg= 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=G67LBwlLp7ANiJNA0RPVbY1e46w+lwkhPeCs75AmZCQ=; b=KqSLDDeCfhyD6YQw5taZ+KW+yoPCahanmC+cUj+Pu0D7MVdajGmiq6VQX3DTEpDLcL rAwbwHeRoTXua2COh9tCYAClgxkgjrUY7CM9FWf9GJBBVmCTmvxDs8fAyzZQM6/HhVVL d84e02ukVMt2mEFYt2qahY9tG6SRvKF8541Z7iPLFrE98UeS4oQvzoYtsCaX7DxO5C4r 1NVKTrZwY4Mg/E6LhC+oEGGYQQSvJMN2AVAMcLDRGkStnbjIqiz0OWhOTqWHOtr1pu3D JkvNbLfirM+fUE29WzkUkpg5vY4wqoD345qBQ7/mIHJT5CksgTATh7s+cDCvnRyNXU2I 288A== X-Gm-Message-State: AD7BkJK/+aQvUz5lpW/evYjZS1o2KhqDzWuIZnsEjwzKrXfcpZcAPxnJieOGK11WhZDC3oi2 X-Received: by 10.66.190.131 with SMTP id gq3mr21033304pac.42.1458913846285; Fri, 25 Mar 2016 06:50:46 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.2]) by smtp.gmail.com with ESMTPSA id w20sm16744178pfi.31.2016.03.25.06.50.40 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 Mar 2016 06:50:45 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Fri, 25 Mar 2016 21:48:54 +0800 Message-Id: <1458913735-2678-22-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458913735-2678-1-git-send-email-shannon.zhao@linaro.org> References: <1458913735-2678-1-git-send-email-shannon.zhao@linaro.org> Cc: Keir Fraser , Tim Deegan , Ian Jackson , peter.huangpeng@huawei.com, julien.grall@arm.com, stefano.stabellini@citrix.com, shannon.zhao@linaro.org, Jan Beulich , zhaoshenglong@huawei.com Subject: [Xen-devel] [PATCH v7 21/22] xen/arm: Add a hypercall for device mmio mapping X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" It needs to map platform or amba device mmio to Dom0 on ARM. But when booting with ACPI, it can't get the mmio region in Xen due to lack of AML interpreter to parse DSDT table. Therefore, let Dom0 call a hypercall to map mmio region when it adds the devices. Here we add a new map space like the XEN_DOMCTL_memory_mapping to map mmio region for Dom0. Cc: Ian Jackson Cc: Jan Beulich Cc: Keir Fraser Cc: Tim Deegan Signed-off-by: Shannon Zhao --- xen/arch/arm/mm.c | 3 +++ xen/arch/arm/p2m.c | 22 ++++++++++++++++++++++ xen/common/memory.c | 16 ++++++++++++++++ xen/include/asm-arm/p2m.h | 5 +++++ xen/include/public/memory.h | 1 + 5 files changed, 47 insertions(+) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 81f9e2e..0aae6c5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1138,6 +1138,9 @@ int xenmem_add_to_physmap_one( rcu_unlock_domain(od); break; } + case XENMAPSPACE_dev_mmio: + rc = map_dev_mmio_region(d, gpfn, 1, idx); + return rc; default: return -ENOSYS; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 7e5f5d1..0011708 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1270,6 +1271,27 @@ int unmap_mmio_regions(struct domain *d, d->arch.p2m.default_access); } +int map_dev_mmio_region(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn) +{ + int res; + + if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) ) + return 0; + + res = map_mmio_regions(d, start_gfn, nr, mfn); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map [%#lx - %#lx] in Dom%d\n", + start_gfn, start_gfn + nr - 1, d->domain_id); + return res; + } + + return 0; +} + int guest_physmap_add_entry(struct domain *d, unsigned long gpfn, unsigned long mfn, diff --git a/xen/common/memory.c b/xen/common/memory.c index c7fca96..25ff86c 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -980,6 +980,14 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( d == NULL ) return -ESRCH; + /* + * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain + * to map this kind of space to itself. + */ + if ( (xatp.space == XENMAPSPACE_dev_mmio) && + ((d != current->domain) || !is_hardware_domain(d)) ) + return -EACCES; + rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d); if ( rc ) { @@ -1024,6 +1032,14 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( d == NULL ) return -ESRCH; + /* + * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain + * to map this kind of space to itself. + */ + if ( (xatpb.space == XENMAPSPACE_dev_mmio) && + ((d != current->domain) || !is_hardware_domain(d)) ) + return -EACCES; + rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d); if ( rc ) { diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 55626b4..d240d1e 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -154,6 +154,11 @@ int unmap_regions_rw_cache(struct domain *d, unsigned long nr_mfns, unsigned long mfn); +int map_dev_mmio_region(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn); + int guest_physmap_add_entry(struct domain *d, unsigned long gfn, unsigned long mfn, diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index f69e92f..fe52ee1 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -220,6 +220,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); #define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */ #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom, * XENMEM_add_to_physmap_batch only. */ +#define XENMAPSPACE_dev_mmio 5 /* device mmio region */ /* ` } */ /*