From patchwork Thu Apr 6 13:18:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhang X-Patchwork-Id: 9667421 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 CF8B5601EB for ; Thu, 6 Apr 2017 13:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 868ED283F4 for ; Thu, 6 Apr 2017 13:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B60828472; Thu, 6 Apr 2017 13:40:05 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 D419A283F4 for ; Thu, 6 Apr 2017 13:40:04 +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 1cw7bh-0004RW-80; Thu, 06 Apr 2017 13:37:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cw7bg-0004Qq-9H for xen-devel@lists.xen.org; Thu, 06 Apr 2017 13:37:48 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id EE/C1-03430-BA446E85; Thu, 06 Apr 2017 13:37:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tbhqLva5Vm EwaWlzBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bF04oFK5QqOlovMjUwfpLpYuTiYBG4xSQx bd5FZhBHSGA6o8Styd/Zuxg5OSQEeCWOLJvBCmH7SXxq7GSFKGpnlHj4oZMJJMEmoC3xY/VvR hBbREBa4trny2A2s4CERNvaw2DNwgKBEne3LmQBsVkEVCUWPbsAZvMKeEqserYMapmcxMljk8 HqOQW8JI58ewYWFwKqefz9I8sERr4FjAyrGDWKU4vKUot0Dc30kooy0zNKchMzc3QNDcz0clO LixPTU3MSk4r1kvNzNzECA4UBCHYw3t8YcIhRkoNJSZRXwedJhBBfUn5KZUZicUZ8UWlOavEh RhkODiUJ3onOzyKEBItS01Mr0jJzgCELk5bg4FES4e0BSfMWFyTmFmemQ6ROMSpKifN6gCQEQ BIZpXlwbbA4ucQoKyXMywh0iBBPQWpRbmYJqvwrRnEORiVh3jMgU3gy80rgpr8CWswEtNjn1l OQxSWJCCmpBsZu3i2sW8US/+axzfjncNyV/59vhHCUYKJOckBjNUvc1Dr35xUZRo8ZNU9N8HX d331GdOmR037ntjzZPWf1+vwy41cWeYKhdXlmnK0fGXrfHFH/Wb6H02qP0RXBCycTVp5uDPzc JtPzy9GwSV257l/TRrf/nW0f3cMcBHK3v/hgeUrnV0S9mxJLcUaioRZzUXEiAJvUQhmOAgAA X-Env-Sender: yu.c.zhang@linux.intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1491485864!55940067!1 X-Originating-IP: [134.134.136.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30307 invoked from network); 6 Apr 2017 13:37:46 -0000 Received: from mga03.intel.com (HELO mga03.intel.com) (134.134.136.65) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Apr 2017 13:37:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491485866; x=1523021866; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=YkEWMhYdmEkexZfyYKMKk3x38NrsQTUW4+lUSgoA68Y=; b=u/+ybR8ppHukZ8PE1OuOcyeVo5sEDxGghfGt4J+HVIlkX/zq79Lbwlr3 cnK31Iq1HryELZ3NtFqYeMNiasrRXg==; Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Apr 2017 06:37:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,159,1488873600"; d="scan'208";a="85705829" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by fmsmga006.fm.intel.com with ESMTP; 06 Apr 2017 06:37:43 -0700 From: Yu Zhang To: xen-devel@lists.xen.org Date: Thu, 6 Apr 2017 21:18:35 +0800 Message-Id: <1491484718-5048-4-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491484718-5048-1-git-send-email-yu.c.zhang@linux.intel.com> References: <1491484718-5048-1-git-send-email-yu.c.zhang@linux.intel.com> Cc: zhiyuan.lv@intel.com Subject: [Xen-devel] [PATCH v11 3/6] x86/ioreq server: Add device model wrappers for new DMOP 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 A new device model wrapper is added for the newly introduced DMOP - XEN_DMOP_map_mem_type_to_ioreq_server. Since currently this DMOP only supports the emulation of write operations, attempts to trigger the DMOP with values other than XEN_DMOP_IOREQ_MEM_ACCESS_WRITE or 0(to unmap the ioreq server) shall fail. The wrapper shall be updated once read operations are also to be emulated in the future. Also note currently this DMOP only supports one memory type, and can be extended in the future to map multiple memory types to multiple ioreq servers, e.g. mapping HVMMEM_ioreq_serverX to ioreq server X, This wrapper shall be updated when such change is made. Signed-off-by: Yu Zhang Reviewed-by: Paul Durrant --- Cc: Paul Durrant Cc: Ian Jackson Cc: Wei Liu changes in v2: - According to Paul and Wei's comments: drop the compat wrapper changes. - Added "Reviewed-by: Paul Durrant ". --- tools/libs/devicemodel/core.c | 25 +++++++++++++++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 18 ++++++++++++++++++ tools/libs/devicemodel/libxendevicemodel.map | 1 + 3 files changed, 44 insertions(+) diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c index a85cb49..ff09819 100644 --- a/tools/libs/devicemodel/core.c +++ b/tools/libs/devicemodel/core.c @@ -244,6 +244,31 @@ int xendevicemodel_unmap_io_range_from_ioreq_server( return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); } +int xendevicemodel_map_mem_type_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t type, + uint32_t flags) +{ + struct xen_dm_op op; + struct xen_dm_op_map_mem_type_to_ioreq_server *data; + + if (type != HVMMEM_ioreq_server || + flags & ~XEN_DMOP_IOREQ_MEM_ACCESS_WRITE) { + errno = EINVAL; + return -1; + } + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_map_mem_type_to_ioreq_server; + data = &op.u.map_mem_type_to_ioreq_server; + + data->id = id; + data->type = type; + data->flags = flags; + + return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); +} + int xendevicemodel_map_pcidev_to_ioreq_server( xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t segment, uint8_t bus, uint8_t device, uint8_t function) diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index b3f600e..1da216f 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -104,6 +104,24 @@ int xendevicemodel_unmap_io_range_from_ioreq_server( uint64_t start, uint64_t end); /** + * This function registers/deregisters a memory type for emulation. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm domid the domain id to be serviced. + * @parm id the IOREQ Server id. + * @parm type the memory type to be emulated. For now, only HVMMEM_ioreq_server + * is supported, and in the future new types can be introduced, e.g. + * HVMMEM_ioreq_serverX mapped to ioreq server X. + * @parm flags operations to be emulated; 0 for unmap. For now, only write + * operations will be emulated and can be extended to emulate + * read ones in the future. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_map_mem_type_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t type, + uint32_t flags); + +/** * This function registers a PCI device for config space emulation. * * @parm dmod a handle to an open devicemodel interface. diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 45c773e..130222c 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -5,6 +5,7 @@ VERS_1.0 { xendevicemodel_get_ioreq_server_info; xendevicemodel_map_io_range_to_ioreq_server; xendevicemodel_unmap_io_range_from_ioreq_server; + xendevicemodel_map_mem_type_to_ioreq_server; xendevicemodel_map_pcidev_to_ioreq_server; xendevicemodel_unmap_pcidev_from_ioreq_server; xendevicemodel_destroy_ioreq_server;