From patchwork Mon Sep 11 04:38:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946591 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 989396035D for ; Mon, 11 Sep 2017 04:41:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EB15289DE for ; Mon, 11 Sep 2017 04:41:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 835E928AD7; Mon, 11 Sep 2017 04:41:53 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 229C4289DE for ; Mon, 11 Sep 2017 04:41:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVo-0002eH-Pl; Mon, 11 Sep 2017 04:39:56 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVm-0002aU-QQ for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:54 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 99/0C-03610-A9316B95; Mon, 11 Sep 2017 04:39:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsXS1tYhojtTeFu kwbrTShZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8byR4+YCj5JV8z/co25gXGGeBcjF4eQwHRG ieaGTpYuRk4OCQFeiSPLZrB2MXIA2QESGxZmQtT0MkpMXDiNEaSGTUBfYsXjg6wgtoiAtMS1z 5cZQYqYBU4xSazfN5kFpFlYIFTi7ERBkBoWAVWJ5vP7mUFsXgE7ialrrjFB7JKX2NV2EWwOJ1 D84Mt3YDVCArYSC04vYJ3AyLuAkWEVo0ZxalFZapGukbleUlFmekZJbmJmjq6hgZlebmpxcWJ 6ak5iUrFecn7uJkZgODAAwQ7GxWsDDzFKcjApifK+O74lUogvKT+lMiOxOCO+qDQntfgQowwH h5IEr4rQtkghwaLU9NSKtMwcYGDCpCU4eJREeKNA0rzFBYm5xZnpEKlTjLocHTfv/mESYsnLz 0uVEueVAykSACnKKM2DGwGLkkuMslLCvIxARwnxFKQW5WaWoMq/YhTnYFQS5o0AmcKTmVcCt+ kV0BFMQEfwXNoCckRJIkJKqoHR6uT2D68Fb5WeTomM/CgWzye1dcGZrCOlRv+1fgg+z/NYbsJ 9oFMu18XuaC+v++6mDZXJq895mf3l+O209aVZx7nLFSdW3F8dXWdkpidS08OwZZpjxbGAytcL Q6PKsnfMvbrCXmGqwrLVBtu45cQdan4lCuXpd7HbfDwhb5nef5hzxu3DpV+UWIozEg21mIuKE wEdE0IejQIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!26 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51407 invoked from network); 11 Sep 2017 04:39:53 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:39:53 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:39:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078563" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:39:50 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:12 +0800 Message-Id: <20170911043820.14617-32-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Wei Liu , Andrew Cooper , Ian Jackson , Jan Beulich , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC XEN PATCH v3 31/39] tools/libacpi: add callback to translate GPA to GVA 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" X-Virus-Scanned: ClamAV using ClamSMTP The location of ACPI blobs passed from device modeil is offered in guest physical address. libacpi needs to convert the guest physical address to guest virtual address before it can access those ACPI blobs. Signed-off-by: Haozhong Zhang --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Ian Jackson Cc: Wei Liu --- tools/firmware/hvmloader/util.c | 6 ++++++ tools/firmware/hvmloader/util.h | 1 + tools/libacpi/libacpi.h | 1 + tools/libxl/libxl_x86_acpi.c | 10 ++++++++++ 4 files changed, 18 insertions(+) diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index c2218d9fcb..2f8a4654b0 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -871,6 +871,11 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v) return virt_to_phys(v); } +static void *acpi_p2v(struct acpi_ctxt *ctxt, unsigned long p) +{ + return phys_to_virt(p); +} + static void *acpi_mem_alloc(struct acpi_ctxt *ctxt, uint32_t size, uint32_t align) { @@ -989,6 +994,7 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, ctxt.mem_ops.alloc = acpi_mem_alloc; ctxt.mem_ops.free = acpi_mem_free; ctxt.mem_ops.v2p = acpi_v2p; + ctxt.mem_ops.p2v = acpi_p2v; ctxt.min_alloc_byte_align = 16; diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index 2ef854eb8f..e9fe6c6e79 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -200,6 +200,7 @@ xen_pfn_t mem_hole_alloc(uint32_t nr_mfns); /* Allocate memory in a reserved region below 4GB. */ void *mem_alloc(uint32_t size, uint32_t align); #define virt_to_phys(v) ((unsigned long)(v)) +#define phys_to_virt(v) ((void *)(p)) /* Allocate memory in a scratch region */ void *scratch_alloc(uint32_t size, uint32_t align); diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h index 157f63f7bc..f5a1c384bc 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -51,6 +51,7 @@ struct acpi_ctxt { void *(*alloc)(struct acpi_ctxt *ctxt, uint32_t size, uint32_t align); void (*free)(struct acpi_ctxt *ctxt, void *v, uint32_t size); unsigned long (*v2p)(struct acpi_ctxt *ctxt, void *v); + void *(*p2v)(struct acpi_ctxt *ctxt, unsigned long p); } mem_ops; uint32_t min_alloc_byte_align; /* minimum alignment used by mem_ops.alloc */ diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c index 3b79b2179b..b14136949c 100644 --- a/tools/libxl/libxl_x86_acpi.c +++ b/tools/libxl/libxl_x86_acpi.c @@ -52,6 +52,15 @@ static unsigned long virt_to_phys(struct acpi_ctxt *ctxt, void *v) libxl_ctxt->alloc_base_paddr); } +static void *phys_to_virt(struct acpi_ctxt *ctxt, unsigned long p) +{ + struct libxl_acpi_ctxt *libxl_ctxt = + CONTAINER_OF(ctxt, struct libxl_acpi_ctxt, c); + + return (void *)((p - libxl_ctxt->alloc_base_paddr) + + libxl_ctxt->alloc_base_vaddr); +} + static void *mem_alloc(struct acpi_ctxt *ctxt, uint32_t size, uint32_t align) { @@ -181,6 +190,7 @@ int libxl__dom_load_acpi(libxl__gc *gc, libxl_ctxt.c.mem_ops.alloc = mem_alloc; libxl_ctxt.c.mem_ops.v2p = virt_to_phys; + libxl_ctxt.c.mem_ops.p2v = phys_to_virt; libxl_ctxt.c.mem_ops.free = acpi_mem_free; libxl_ctxt.c.min_alloc_byte_align = 16;