From patchwork Thu Apr 6 15:53:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhang X-Patchwork-Id: 9667835 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 25C74602B8 for ; Thu, 6 Apr 2017 16:15:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66FF72859F for ; Thu, 6 Apr 2017 16:15:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BE05285A4; Thu, 6 Apr 2017 16:15:29 +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 D495F2859F for ; Thu, 6 Apr 2017 16:15:28 +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 1cwA26-0005hk-Ss; Thu, 06 Apr 2017 16:13:14 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwA25-0005hF-MF for xen-devel@lists.xen.org; Thu, 06 Apr 2017 16:13:13 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id E0/32-16497-81966E85; Thu, 06 Apr 2017 16:13:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXS1tYhryua+Sz C4PlVcYslHxezODB6HN39mymAMYo1My8pvyKBNeNH3yXGgmnKFQ92ezUwnpftYuTkEBKolNg4 s4kFxJYQ4JU4smwGK4TtLzFvfidjFyMXUE07o8Tvrh9MIAk2AW2JH6t/M4LYIgLSEtc+XwYrY hboZpRYeXcWO0hCWCBQouf9NLCpLAKqEt23t4M18Ap4SVz/c5MdYoOcxMljk8G2cQp4S2xsns gKcZGXRMeCiSwTGHkXMDKsYlQvTi0qSy3SNdNLKspMzyjJTczM0TU0MNXLTS0uTkxPzUlMKtZ Lzs/dxAgMBgYg2ME4tcH5EKMkB5OSKK+Cz5MIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8wenP IoQEi1LTUyvSMnOAYQmTluDgURLhtQdJ8xYXJOYWZ6ZDpE4xKkqJ815JA0oIgCQySvPg2mCxc IlRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvG0g43ky80rgpr8CWswEtNjn1lOQxSWJCCmpBs bChal/58mwTlIJ/vSoUPLTvqYC5UKXKfZ8vcq7Mv3TefbYmcTt7rSq5Nu7geWwz5Qf4fsStUU e9jEsZzZMUuxwC1ByOLtVxPtH2aolrt9y//D4NxRlc6k3+X7cJXlG6eauaXXzOf0WXeYXzTzF dXOP8EkZC9GXt1Z3TMo/6jL9kvyDGms5eyWW4oxEQy3mouJEAK4RizCAAgAA X-Env-Sender: yu.c.zhang@linux.intel.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1491495187!78261313!1 X-Originating-IP: [134.134.136.31] 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 50520 invoked from network); 6 Apr 2017 16:13:09 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Apr 2017 16:13:09 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 06 Apr 2017 09:13:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,160,1488873600"; d="scan'208";a="842784661" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by FMSMGA003.fm.intel.com with ESMTP; 06 Apr 2017 09:13:05 -0700 From: Yu Zhang To: xen-devel@lists.xen.org Date: Thu, 6 Apr 2017 23:53:34 +0800 Message-Id: <1491494017-30743-4-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491494017-30743-1-git-send-email-yu.c.zhang@linux.intel.com> References: <1491494017-30743-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 v12 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 v3: - Added "Acked-by: 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;