From patchwork Tue Jun 28 16:17:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 71117 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1681838qgy; Tue, 28 Jun 2016 09:20:02 -0700 (PDT) X-Received: by 10.36.111.72 with SMTP id x69mr4252966itb.71.1467130794710; Tue, 28 Jun 2016 09:19:54 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id r74si5142247itb.26.2016.06.28.09.19.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 09:19:54 -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; 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 1bHvi1-0007Km-CG; Tue, 28 Jun 2016 16:17:57 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bHvi0-0007IZ-Qf for xen-devel@lists.xen.org; Tue, 28 Jun 2016 16:17:56 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id B0/7B-16470-433A2775; Tue, 28 Jun 2016 16:17:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTdd4cVG 4wc9HEhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ajtovsBVO0K05ufMrcwLhdsouRk0NIYCOj xLXZzl2MXED2aUaJz2u+MoEk2AQ0Je58/gRmiwhIS1z7fJkRxGYWcJB48/EeC4gtLBAmcWfZL LYuRg4OFgFVidctWiAmr4CrxPJOVZAKCQE5iZPHJrOC2JxA4S1TfrJBrHWRuHDiBssERu4FjA yrGDWKU4vKUot0Dc31kooy0zNKchMzc3QNDYz1clOLixPTU3MSk4r1kvNzNzECfcsABDsYX57 2PMQoycGkJMr7rbcoXIgvKT+lMiOxOCO+qDQntfgQowwHh5IEr+wioJxgUWp6akVaZg4wyGDS Ehw8SiK8riBp3uKCxNzizHSI1ClGRSlx3t0LgRICIImM0jy4NlhgX2KUlRLmZQQ6RIinILUoN 7MEVf4VozgHo5Iwrx/IeJ7MvBK46a+AFjMBLWatzgdZXJKIkJJqYDwnNMUzbrJ5AFNzZL3odk tLS+9AEZsF5qJhjrd+VCzos0yurNA0aS2eclYp4b8f89e3c4WF+ruNZ1lcMuTd9WlqeaKko7C Yu+9FAWepGUodSj/T9EJvODvsfftr06pTkxb+qCs/ZG5dvrgyfs2D6f9+vz/SaPhY9eLjeVan Z6fUf1jek6K9Q4mlOCPRUIu5qDgRAARqGCBnAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1467130669!47102581!5 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55474 invoked from network); 28 Jun 2016 16:17:55 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-10.tower-31.messagelabs.com with SMTP; 28 Jun 2016 16:17:55 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 16AB82F; Tue, 28 Jun 2016 09:18:47 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.215.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 325EE3F21A; Tue, 28 Jun 2016 09:17:54 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 28 Jun 2016 17:17:21 +0100 Message-Id: <1467130643-23868-16-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467130643-23868-1-git-send-email-julien.grall@arm.com> References: <1467130643-23868-1-git-send-email-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v5 15/17] xen/arm: p2m: Introduce helpers to insert and remove 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" More the half of the arguments of INSERT and REMOVE are the same for each callers. Simplify the callers of apply_p2m_changes by adding new helpers which will fill common arguments with default values. Signed-off-by: Julien Grall --- Changes in v5: - Add missing Signed-off-by Changes in v4: - Patch added --- xen/arch/arm/p2m.c | 70 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 0fdd11f..a5b584b 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1158,17 +1158,40 @@ out: return rc; } +static inline int p2m_insert_mapping(struct domain *d, + gfn_t start_gfn, + unsigned long nr, + mfn_t mfn, + int mattr, p2m_type_t t) +{ + return apply_p2m_changes(d, INSERT, + pfn_to_paddr(gfn_x(start_gfn)), + pfn_to_paddr(gfn_x(start_gfn) + nr), + pfn_to_paddr(mfn_x(mfn)), + mattr, 0, t, d->arch.p2m.default_access); +} + +static inline int p2m_remove_mapping(struct domain *d, + gfn_t start_gfn, + unsigned long nr, + mfn_t mfn) +{ + return apply_p2m_changes(d, REMOVE, + pfn_to_paddr(gfn_x(start_gfn)), + pfn_to_paddr(gfn_x(start_gfn) + nr), + pfn_to_paddr(mfn_x(mfn)), + /* arguments below not used when removing mapping */ + MATTR_MEM, 0, p2m_invalid, + d->arch.p2m.default_access); +} + int map_regions_rw_cache(struct domain *d, gfn_t gfn, unsigned long nr, mfn_t mfn) { - return apply_p2m_changes(d, INSERT, - pfn_to_paddr(gfn_x(gfn)), - pfn_to_paddr(gfn_x(gfn) + nr), - pfn_to_paddr(mfn_x(mfn)), - MATTR_MEM, 0, p2m_mmio_direct, - d->arch.p2m.default_access); + return p2m_insert_mapping(d, gfn, nr, mfn, + MATTR_MEM, p2m_mmio_direct); } int unmap_regions_rw_cache(struct domain *d, @@ -1176,12 +1199,7 @@ int unmap_regions_rw_cache(struct domain *d, unsigned long nr, mfn_t mfn) { - return apply_p2m_changes(d, REMOVE, - pfn_to_paddr(gfn_x(gfn)), - pfn_to_paddr(gfn_x(gfn) + nr), - pfn_to_paddr(mfn_x(mfn)), - MATTR_MEM, 0, p2m_invalid, - d->arch.p2m.default_access); + return p2m_remove_mapping(d, gfn, nr, mfn); } int map_mmio_regions(struct domain *d, @@ -1189,12 +1207,8 @@ int map_mmio_regions(struct domain *d, unsigned long nr, mfn_t mfn) { - return apply_p2m_changes(d, INSERT, - pfn_to_paddr(gfn_x(start_gfn)), - pfn_to_paddr(gfn_x(start_gfn) + nr), - pfn_to_paddr(mfn_x(mfn)), - MATTR_DEV, 0, p2m_mmio_direct, - d->arch.p2m.default_access); + return p2m_insert_mapping(d, start_gfn, nr, mfn, + MATTR_MEM, p2m_mmio_direct); } int unmap_mmio_regions(struct domain *d, @@ -1202,12 +1216,7 @@ int unmap_mmio_regions(struct domain *d, unsigned long nr, mfn_t mfn) { - return apply_p2m_changes(d, REMOVE, - pfn_to_paddr(gfn_x(start_gfn)), - pfn_to_paddr(gfn_x(start_gfn) + nr), - pfn_to_paddr(mfn_x(mfn)), - MATTR_DEV, 0, p2m_invalid, - d->arch.p2m.default_access); + return p2m_remove_mapping(d, start_gfn, nr, mfn); } int map_dev_mmio_region(struct domain *d, @@ -1237,22 +1246,15 @@ int guest_physmap_add_entry(struct domain *d, unsigned long page_order, p2m_type_t t) { - return apply_p2m_changes(d, INSERT, - pfn_to_paddr(gfn_x(gfn)), - pfn_to_paddr(gfn_x(gfn) + (1 << page_order)), - pfn_to_paddr(mfn_x(mfn)), MATTR_MEM, 0, t, - d->arch.p2m.default_access); + return p2m_insert_mapping(d, gfn, (1 << page_order), mfn, + MATTR_MEM, t); } void guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned int page_order) { - apply_p2m_changes(d, REMOVE, - pfn_to_paddr(gfn_x(gfn)), - pfn_to_paddr(gfn_x(gfn) + (1<arch.p2m.default_access); + p2m_remove_mapping(d, gfn, (1 << page_order), mfn); } int p2m_alloc_table(struct domain *d)