From patchwork Thu Apr 6 13:19:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhang X-Patchwork-Id: 9667427 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 97346601EB for ; Thu, 6 Apr 2017 13:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E17227FAE for ; Thu, 6 Apr 2017 13:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42BB528179; Thu, 6 Apr 2017 13:40:39 +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 AA76927FAE for ; Thu, 6 Apr 2017 13:40:38 +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 1cw7cU-0004m5-Ov; Thu, 06 Apr 2017 13:38:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cw7cS-0004lb-Rp for xen-devel@lists.xen.org; Thu, 06 Apr 2017 13:38:36 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 36/16-04817-CD446E85; Thu, 06 Apr 2017 13:38:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tYhonvb5Vm Ewdq3+hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bF04oFK5QqOlovMjUwfpLpYuTiYBG4xSRx fXoPWxcjJ4eQwHRGicZOWxBbQoBX4siyGawQtr/Exx/z2UAahATaGSXuLp3KCJJgE9CW+LH6N 5gtIiAtce3zZUaQImaBbkaJlXdnsYMkhAUCJe5uXcgCYrMIqErMX3mSCcTmFfCU2Ph6IdQGOY mTxyaD2ZwCXhJb9u1kgbjIU+LruqVsExj5FjAyrGLUKE4tKkst0jU01ksqykzPKMlNzMzRNTQ w08tNLS5OTE/NSUwq1kvOz93ECAwUBiDYwfhlWcAhRkkOJiVRXgWfJxFCfEn5KZUZicUZ8UWl OanFhxhlODiUJHjZgYEnJFiUmp5akZaZAwxZmLQEB4+SCG+AM1Cat7ggMbc4Mx0idYpRUUqc9 wBIQgAkkVGaB9cGi5NLjLJSwryMQIcI8RSkFuVmlqDKv2IU52BUEuYNApnCk5lXAjf9FdBiJq DFPreegiwuSURISTUwSpeWuLNkSHKsT5PV5lxd0HRyQuJ93oCVNxdpiz+ZK5T3Zd5FjbNT/E+ 9+uLM46xztezsjQf+IgZ9B3Uu2+ftqHm+/mXJh1PO8+Qe/xB99ykkacNRgWvuR3dfXWO6Xacv NsJ5ta1x0dplsZ0Ts4WK/2+qUHnG9vcOr9PtVt28lJkGOQZaX1uYlViKMxINtZiLihMBeWjTH Y4CAAA= X-Env-Sender: yu.c.zhang@linux.intel.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1491485913!96162937!1 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.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22861 invoked from network); 6 Apr 2017 13:38:35 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-9.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Apr 2017 13:38:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491485915; x=1523021915; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=YkEWMhYdmEkexZfyYKMKk3x38NrsQTUW4+lUSgoA68Y=; b=nFtT2bXfgF3GFrMesHLZ0d7ZMCt2A8Nr1VZdyfw47cdvcAWbOJs0ffDg Og6zge/pjWBNOUS5oldF2EULB6wiDA==; Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Apr 2017 06:38:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,159,1488873600"; d="scan'208";a="842691699" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by FMSMGA003.fm.intel.com with ESMTP; 06 Apr 2017 06:38:30 -0700 From: Yu Zhang To: xen-devel@lists.xen.org Date: Thu, 6 Apr 2017 21:19:04 +0800 Message-Id: <1491484747-5133-4-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491484747-5133-1-git-send-email-yu.c.zhang@linux.intel.com> References: <1491484747-5133-1-git-send-email-yu.c.zhang@linux.intel.com> Cc: Wei Liu , Paul Durrant , Ian Jackson , 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 Acked-by: Wei Liu --- 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;