From nobody Tue Feb 10 17:31:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489968982229307.8347940116249; Sun, 19 Mar 2017 17:16:22 -0700 (PDT) Received: from localhost ([::1]:58649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpkzk-00073i-SP for importer@patchew.org; Sun, 19 Mar 2017 20:16:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpkwd-00051m-DB for qemu-devel@nongnu.org; Sun, 19 Mar 2017 20:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpkwc-0004up-1y for qemu-devel@nongnu.org; Sun, 19 Mar 2017 20:13:07 -0400 Received: from mga03.intel.com ([134.134.136.65]:51743) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpkwb-0004uJ-O0 for qemu-devel@nongnu.org; Sun, 19 Mar 2017 20:13:05 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2017 17:13:05 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.153]) by fmsmga006.fm.intel.com with ESMTP; 19 Mar 2017 17:13:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489968785; x=1521504785; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ZkG9XEfNFConRl5HDkM+Yp9IINl4yhwE99RfjmrL4FU=; b=lXdkfPwJyTrFEYwc80V2PIczebjueOUdAOtqHo8P8mpYMoFDEWn0AwRQ 8IBBKIAvmOrQx7zskM27u2YW+Nm6GQ==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,191,1486454400"; d="scan'208";a="78799151" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 20 Mar 2017 08:12:42 +0800 Message-Id: <20170320001249.25521-4-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170320001249.25521-1-haozhong.zhang@intel.com> References: <20170320001249.25521-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [RFC QEMU PATCH v2 03/10] xen-hvm: support copying ACPI to guest memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Stefano Stabellini , xen-devel@lists.xenproject.org, Anthony Perard , Konrad Rzeszutek Wilk , Dan Williams Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Haozhong Zhang --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: xen-devel@lists.xenproject.org --- include/hw/xen/xen.h | 18 ++++++++ xen-hvm-stub.c | 6 +++ xen-hvm.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 137 insertions(+) diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index 09c2ce5170..d67cdd8c7d 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -47,4 +47,22 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t le= ngth); =20 void xen_register_framebuffer(struct MemoryRegion *mr); =20 +/* + * Copy an ACPI blob from QEMU to HVM guest. + * + * Parameters: + * name: a unique name of the data blob; for XEN_DM_ACPI_BLOB_TYPE_NS= DEV, + * name should be less then 4 characters + * blob: the ACPI blob to be copied + * length: the length in bytes of the ACPI blob + * type: the type of content in the ACPI blob + * + * Return: + * 0 on success; a non-zero error code on failures. + */ +#define XEN_DM_ACPI_BLOB_TYPE_TABLE 0 /* ACPI table */ +#define XEN_DM_ACPI_BLOB_TYPE_NSDEV 1 /* AML of ACPI namespace device */ +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type); + #endif /* QEMU_HW_XEN_H */ diff --git a/xen-hvm-stub.c b/xen-hvm-stub.c index c5003251cb..a6c018505c 100644 --- a/xen-hvm-stub.c +++ b/xen-hvm-stub.c @@ -61,3 +61,9 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ra= m_memory) void qmp_xen_set_global_dirty_log(bool enable, Error **errp) { } + +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type) +{ + return -1; +} diff --git a/xen-hvm.c b/xen-hvm.c index c42c958a0a..4ddc47e5f1 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -1252,6 +1252,20 @@ static int dm_acpi_buf_init(XenIOState *state) return 0; } =20 +static ram_addr_t dm_acpi_buf_alloc(size_t length) +{ + ram_addr_t addr; + + if (dm_acpi_buf->length - dm_acpi_buf->used < length) { + return 0; + } + + addr =3D dm_acpi_buf->base + dm_acpi_buf->used; + dm_acpi_buf->used +=3D length; + + return addr; +} + static int xen_dm_acpi_required(PCMachineState *pcms) { return 0; @@ -1486,3 +1500,102 @@ void qmp_xen_set_global_dirty_log(bool enable, Erro= r **errp) memory_global_dirty_log_stop(); } } + +static int xs_write_dm_acpi_blob_entry(const char *name, + const char *entry, const char *valu= e) +{ + XenIOState *state =3D container_of(dm_acpi_buf, XenIOState, dm_acpi_bu= f); + char path[80]; + + snprintf(path, sizeof(path), + "/local/domain/%d"HVM_XS_DM_ACPI_ROOT"/%s/%s", + xen_domid, name, entry); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -EIO; + } + + return 0; +} + +static size_t xen_memcpy_to_guest(ram_addr_t gpa, + const void *buf, size_t length) +{ + size_t copied =3D 0, size; + ram_addr_t s, e, offset, cur =3D gpa; + xen_pfn_t cur_pfn; + void *page; + + if (!buf || !length) { + return 0; + } + + s =3D gpa & TARGET_PAGE_MASK; + e =3D gpa + length; + if (e < s) { + return 0; + } + + while (cur < e) { + cur_pfn =3D cur >> TARGET_PAGE_BITS; + offset =3D cur - (cur_pfn << TARGET_PAGE_BITS); + size =3D (length >=3D TARGET_PAGE_SIZE - offset) ? + TARGET_PAGE_SIZE - offset : length; + + page =3D xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ | PRO= T_WRITE, + 1, &cur_pfn, NULL); + if (!page) { + break; + } + + memcpy(page + offset, buf, size); + xenforeignmemory_unmap(xen_fmem, page, 1); + + copied +=3D size; + buf +=3D size; + cur +=3D size; + length -=3D size; + } + + return copied; +} + +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type) +{ + char value[21]; + ram_addr_t buf_addr; + int rc; + + if (type !=3D XEN_DM_ACPI_BLOB_TYPE_TABLE && + type !=3D XEN_DM_ACPI_BLOB_TYPE_NSDEV) { + return -EINVAL; + } + + buf_addr =3D dm_acpi_buf_alloc(length); + if (!buf_addr) { + return -ENOMEM; + } + if (xen_memcpy_to_guest(buf_addr, blob, length) !=3D length) { + return -EIO; + } + + snprintf(value, sizeof(value), "%d", type); + rc =3D xs_write_dm_acpi_blob_entry(name, "type", value); + if (rc) { + return rc; + } + + snprintf(value, sizeof(value), "%"PRIu64, buf_addr - dm_acpi_buf->base= ); + rc =3D xs_write_dm_acpi_blob_entry(name, "offset", value); + if (rc) { + return rc; + } + + snprintf(value, sizeof(value), "%"PRIu64, length); + rc =3D xs_write_dm_acpi_blob_entry(name, "length", value); + if (rc) { + return rc; + } + + return 0; +} --=20 2.12.0