From patchwork Tue Jun 21 13:20:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 70562 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2016027qgy; Tue, 21 Jun 2016 06:23:07 -0700 (PDT) X-Received: by 10.36.146.194 with SMTP id l185mr5693056itd.94.1466515383708; Tue, 21 Jun 2016 06:23:03 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x4si3904068itf.104.2016.06.21.06.23.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 06:23:03 -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 1bFLbs-0004QK-H7; Tue, 21 Jun 2016 13:20:56 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFLbr-0004Pr-2v for xen-devel@lists.xen.org; Tue, 21 Jun 2016 13:20:55 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id 8A/7E-14454-63F39675; Tue, 21 Jun 2016 13:20:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTdfUPjP cYNMLY4slHxezODB6HN39mymAMYo1My8pvyKBNeNf8xq2gr2CFX/mfGNpYNzO18XIxSEksIlR YvOJc2wQzmlGiV/9m1i6GDk52AQ0Je58/sQEYosISEtc+3yZEcRmFrjEJPFxCi+ILSwQJdF8b DEziM0ioCrR+WEfWC+vgIvE/IPX2EFsCQE5iZPHJrOC2JwCrhIbL3aBzRQCqpl89AvLBEbuBY wMqxg1ilOLylKLdA2N9ZKKMtMzSnITM3N0DQ1N9HJTi4sT01NzEpOK9ZLzczcxAj1cz8DAuIN x13bPQ4ySHExKorzMyhnhQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR49Wwzw4UEi1LTUyvSMnOA oQaTluDgURLh1QVJ8xYXJOYWZ6ZDpE4xKkqJ8062AUoIgCQySvPg2mDhfYlRVkqYl5GBgUGIp yC1KDezBFX+FaM4B6OSMK8hyHiezLwSuOmvgBYzAS1e1p8OsrgkESEl1cAolpjdl/jMpihuVv q/t6E7+h3eCu/ddbyZyf35bUe2RYdk/l/cPn2Femb1O66LnKv3v/h3bpvM3xz+opus7G2OCzt S7BXz72b+alwkcF03wtphKptan+yJWbYdJtwrVY8WLZN4csqr5ZR5kN2LF5189dJiiRtybE7K T1rj7m+5jsfnoO6Hqd+UWIozEg21mIuKEwHeXcx3agIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1466515253!48144209!1 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 32607 invoked from network); 21 Jun 2016 13:20:53 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-27.messagelabs.com with SMTP; 21 Jun 2016 13:20:53 -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 3C953440; Tue, 21 Jun 2016 06:21:39 -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 742893F246; Tue, 21 Jun 2016 06:20:51 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 21 Jun 2016 14:20:37 +0100 Message-Id: <1466515243-27264-3-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466515243-27264-1-git-send-email-julien.grall@arm.com> References: <1466515243-27264-1-git-send-email-julien.grall@arm.com> Cc: sstabellini@kernel.org, Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v3 2/8] xen/mm: Introduce a bunch of helpers for the typesafes mfn and gfn 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" Those helpers will be useful to do common operations without having to unbox/box manually the GFNs/MFNs. Signed-off-by: Julien Grall --- Cc: Stefano Stabellini Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu Changes in v3: - Use inline functions rather than macros Changes in v2: - Rename min_gfn/max_gfn to gfn_min/gfn_max - Add more helpers for gfn and mfn --- xen/include/xen/mm.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 3cf646a..13f706e 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -50,6 +50,7 @@ #include #include #include +#include #include TYPE_SAFE(unsigned long, mfn); @@ -61,6 +62,26 @@ TYPE_SAFE(unsigned long, mfn); #undef mfn_t #endif +static inline mfn_t mfn_add(mfn_t mfn, unsigned long i) +{ + return _mfn(mfn_x(mfn) + i); +} + +static inline mfn_t mfn_max(mfn_t x, mfn_t y) +{ + return _mfn(max(mfn_x(x), mfn_x(y))); +} + +static inline mfn_t mfn_min(mfn_t x, mfn_t y) +{ + return _mfn(min(mfn_x(x), mfn_x(y))); +} + +static inline bool_t mfn_eq(mfn_t x, mfn_t y) +{ + return mfn_x(x) == mfn_x(y); +} + TYPE_SAFE(unsigned long, gfn); #define PRI_gfn "05lx" #define INVALID_GFN (~0UL) @@ -70,6 +91,26 @@ TYPE_SAFE(unsigned long, gfn); #undef gfn_t #endif +static inline gfn_t gfn_add(gfn_t gfn, unsigned long i) +{ + return _gfn(gfn_x(gfn) + i); +} + +static inline gfn_t gfn_max(gfn_t x, gfn_t y) +{ + return _gfn(max(gfn_x(x), gfn_x(y))); +} + +static inline gfn_t gfn_min(gfn_t x, gfn_t y) +{ + return _gfn(min(gfn_x(x), gfn_x(y))); +} + +static inline bool_t gfn_eq(gfn_t x, gfn_t y) +{ + return gfn_x(x) == gfn_x(y); +} + TYPE_SAFE(unsigned long, pfn); #define PRI_pfn "05lx" #define INVALID_PFN (~0UL)