From nobody Thu Mar 28 09:27:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1589965490; cv=none; d=zohomail.com; s=zohoarc; b=RHZTBHjFJyRg51R2RLZehXAfmJeydWww3BdFex+2ZjawOzDCZwx288vRk1h/yIZQx0Ej3u9FbNgLVbKFL2oAwz3r+O2QDVJdWQtAPIxac1iReFl5c4OwSG8W3uVDJbBxq2R6fu81wlKG2Ih9ZNm27Uym32uWekBvuxsVmwLlNe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589965490; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cxVe7z5qO5Qs7eGgcvSh31+4K5/DeD3iRNuzH0HAxuk=; b=iybXDv2K3L2KaqseYaYXaSB4C+/FSUHNUwwY32zZtur6lkSiMMpASTMudYipDAQqbEgZZNI6QA9t4/p5zbYLWT5PHR5HCsq4/87Nendo+uAq/hAoYB9AJU+E2k85snE5nvVlVKfgNCCL/F2t4QKnJZ00xbjCZhgpEnLtcgca/ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158996549080738.255287209943276; Wed, 20 May 2020 02:04:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbKeR-0002wu-TU; Wed, 20 May 2020 09:04:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbKeQ-0002wo-5I for xen-devel@lists.xenproject.org; Wed, 20 May 2020 09:04:34 +0000 Received: from mail-ed1-x543.google.com (unknown [2a00:1450:4864:20::543]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e944c724-9a78-11ea-ae69-bc764e2007e4; Wed, 20 May 2020 09:04:29 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id b91so2221536edf.3 for ; Wed, 20 May 2020 02:04:29 -0700 (PDT) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id p5sm1324811edi.82.2020.05.20.02.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 02:04:27 -0700 (PDT) X-Inumbo-ID: e944c724-9a78-11ea-ae69-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cxVe7z5qO5Qs7eGgcvSh31+4K5/DeD3iRNuzH0HAxuk=; b=TXm3L+NIb3XAHg5yp445t0VZcIT8EbggRa9KdpEROqmJVDAorllnh26t5yqkvwlDKW m5PYDkHpx2PqIfT+SIzZTnPtrIR5PniAeBGoeJx6ByvxV8W+D//I+TZ1RYeMYUg56pGA Hp+md7wmt/K9hc5lEXoIf2byBQ9+5h8OLAM+npMWpK346fnn0SkPoGlQP7147bPACxhH +3dR3IXpZQMQ1Brb/iJZi3o/vdsQW0p5vonKvFtEjS2CyBcXcVk+qR7bE7HDDjtfZsDH HbSTNn2rVoSy7Zx6d1XKPtqF5tNGZu8Gaqj8LWbvyLlPH/1Z4BQD1hv8z54IJR4yORds hsTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cxVe7z5qO5Qs7eGgcvSh31+4K5/DeD3iRNuzH0HAxuk=; b=UmQmGiG+8X+oIQx8szfvE3MmrpaKwo83sLuvi0p0b8zQSxQS8hbq1lfFbxb7BpRAME nkj5KgRsoZT+QLBdBqP/cT+ZxsZxQIuuY9IY++PNgMlbRL3FHsP0EFNO8BlR67beVMN4 RW0xCP+fPg8ZQfO8HUjA80TaT4jwSvBnI4W/hc2R7O/OawBsB0Cktt8fMC2EXr93g6Kk KyS6XaygQad+b81tx9YZqDNORDAtfqMNrXJtNWAh4SziZqYlhFYyV238Jvik7qYcoYA3 uUdFjJqIl2VR3WT1u7e4gQQ3/nbda0jO6iTGYPgSO9Z9CdvbrjIyrVxQHy9am3B1CqbM K5pA== X-Gm-Message-State: AOAM530DLcRYdvx/GexYraIVqM4XPSZrmKN2n0ENI2g/nVejh46Ft9aI vKn6ZhY1v4Wg93fh0MDJA1fj+xHA X-Google-Smtp-Source: ABdhPJy2i0oSG0uCwwcpW62NAlWD2JX+n/HqLBknlQfX98ojK0xiYyvde6gKBX5uCZRiWByiX3l0mA== X-Received: by 2002:a50:b286:: with SMTP id p6mr2541409edd.350.1589965468129; Wed, 20 May 2020 02:04:28 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, jgross@suse.com, ian.jackson@eu.citrix.com, wei.liu2@citrix.com, konrad.wilk@oracle.com Subject: [PATCH 1/2] xen/displif: Protocol version 2 Date: Wed, 20 May 2020 12:04:24 +0300 Message-Id: <20200520090425.28558-2-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200520090425.28558-1-andr2000@gmail.com> References: <20200520090425.28558-1-andr2000@gmail.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Andrushchenko Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko 1. Change protocol version from string to integer Version string, which is in fact an integer, is hard to handle in the code that supports different protocol versions. To simplify that make the version an integer. 2. Pass buffer offset with XENDISPL_OP_DBUF_CREATE There are cases when display data buffer is created with non-zero offset to the data start. Handle such cases and provide that offset while creating a display buffer. 3. Add XENDISPL_OP_GET_EDID command Add an optional request for reading Extended Display Identification Data (EDID) structure which allows better configuration of the display connectors over the configuration set in XenStore. With this change connectors may have multiple resolutions defined with respect to detailed timing definitions and additional properties normally provided by displays. If this request is not supported by the backend then visible area is defined by the relevant XenStore's "resolution" property. If backend provides extended display identification data (EDID) with XENDISPL_OP_GET_EDID request then EDID values must take precedence over the resolutions defined in XenStore. 4. Bump protocol version to 2. Signed-off-by: Oleksandr Andrushchenko --- xen/include/public/io/displif.h | 83 +++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/xen/include/public/io/displif.h b/xen/include/public/io/displi= f.h index cc5de9cb1f35..4d43ba5078c8 100644 --- a/xen/include/public/io/displif.h +++ b/xen/include/public/io/displif.h @@ -38,7 +38,7 @@ * Protocol version *************************************************************************= ***** */ -#define XENDISPL_PROTOCOL_VERSION "1" +#define XENDISPL_PROTOCOL_VERSION 2 =20 /* *************************************************************************= ***** @@ -202,6 +202,9 @@ * Width and height of the connector in pixels separated by * XENDISPL_RESOLUTION_SEPARATOR. This defines visible area of the * display. + * If backend provides extended display identification data (EDID) wi= th + * XENDISPL_OP_GET_EDID request then EDID values must take precedence + * over the resolutions defined here. * *------------------ Connector Request Transport Parameters --------------= ----- * @@ -349,6 +352,7 @@ #define XENDISPL_OP_FB_DETACH 0x13 #define XENDISPL_OP_SET_CONFIG 0x14 #define XENDISPL_OP_PG_FLIP 0x15 +#define XENDISPL_OP_GET_EDID 0x16 =20 /* *************************************************************************= ***** @@ -377,6 +381,10 @@ #define XENDISPL_FIELD_BE_ALLOC "be-alloc" #define XENDISPL_FIELD_UNIQUE_ID "unique-id" =20 +#define XENDISPL_EDID_BLOCK_SIZE 128 +#define XENDISPL_EDID_BLOCK_COUNT 256 +#define XENDISPL_EDID_MAX_SIZE (XENDISPL_EDID_BLOCK_SIZE * XENDISPL= _EDID_BLOCK_COUNT) + /* *************************************************************************= ***** * STATUS RETURN CODES @@ -451,7 +459,9 @@ * +----------------+----------------+----------------+----------------+ * | gref_directory | 40 * +----------------+----------------+----------------+----------------+ - * | reserved | 44 + * | data_ofs | 44 + * +----------------+----------------+----------------+----------------+ + * | reserved | 48 * +----------------+----------------+----------------+----------------+ * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| * +----------------+----------------+----------------+----------------+ @@ -494,6 +504,7 @@ * buffer size (buffer_sz) exceeds what can be addressed by this single = page, * then reference to the next page must be supplied (see gref_dir_next_p= age * below) + * data_ofs - uint32_t, offset of the data in the buffer, octets */ =20 #define XENDISPL_DBUF_FLG_REQ_ALLOC (1 << 0) @@ -506,6 +517,7 @@ struct xendispl_dbuf_create_req { uint32_t buffer_sz; uint32_t flags; grant_ref_t gref_directory; + uint32_t data_ofs; }; =20 /* @@ -731,6 +743,42 @@ struct xendispl_page_flip_req { uint64_t fb_cookie; }; =20 +/* + * Request EDID - request EDID describing current connector: + * 0 1 2 3 oct= et + * +----------------+----------------+----------------+----------------+ + * | id | _OP_GET_EDID | reserved | 4 + * +----------------+----------------+----------------+----------------+ + * | buffer_sz | 8 + * +----------------+----------------+----------------+----------------+ + * | gref_directory | 12 + * +----------------+----------------+----------------+----------------+ + * | reserved | 16 + * +----------------+----------------+----------------+----------------+ + * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| + * +----------------+----------------+----------------+----------------+ + * | reserved | 64 + * +----------------+----------------+----------------+----------------+ + * + * Notes: + * - This request is optional and if not supported then visible area + * is defined by the relevant XenStore's "resolution" property. + * - Shared buffer, allocated for EDID storage, must not be less then + * XENDISPL_EDID_MAX_SIZE octets. + * + * buffer_sz - uint32_t, buffer size to be allocated, octets + * gref_directory - grant_ref_t, a reference to the first shared page + * describing EDID buffer references. See XENDISPL_OP_DBUF_CREATE for + * grant page directory structure (struct xendispl_page_directory). + * + * See response format for this request. + */ + +struct xendispl_get_edid_req { + uint32_t buffer_sz; + grant_ref_t gref_directory; +}; + /* *---------------------------------- Responses ---------------------------= ----- * @@ -753,6 +801,31 @@ struct xendispl_page_flip_req { * id - uint16_t, private guest value, echoed from request * status - int32_t, response status, zero on success and -XEN_EXX on fail= ure * + * + * Get EDID response - response for XENDISPL_OP_GET_EDID: + * 0 1 2 3 oct= et + * +----------------+----------------+----------------+----------------+ + * | id | operation | reserved | 4 + * +----------------+----------------+----------------+----------------+ + * | status | 8 + * +----------------+----------------+----------------+----------------+ + * | edid_sz | 12 + * +----------------+----------------+----------------+----------------+ + * | reserved | 16 + * +----------------+----------------+----------------+----------------+ + * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| + * +----------------+----------------+----------------+----------------+ + * | reserved | 64 + * +----------------+----------------+----------------+----------------+ + * + * edid_sz - uint32_t, size of the EDID, octets + */ + +struct xendispl_get_edid_resp { + uint32_t edid_sz; +}; + +/* *----------------------------------- Events -----------------------------= ----- * * Events are sent via a shared page allocated by the front and propagated= by @@ -804,6 +877,7 @@ struct xendispl_req { struct xendispl_fb_detach_req fb_detach; struct xendispl_set_config_req set_config; struct xendispl_page_flip_req pg_flip; + struct xendispl_get_edid_req get_edid; uint8_t reserved[56]; } op; }; @@ -813,7 +887,10 @@ struct xendispl_resp { uint8_t operation; uint8_t reserved; int32_t status; - uint8_t reserved1[56]; + union { + struct xendispl_get_edid_resp get_edid; + uint8_t reserved1[56]; + } op; }; =20 struct xendispl_evt { --=20 2.17.1 From nobody Thu Mar 28 09:27:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1589965502; cv=none; d=zohomail.com; s=zohoarc; b=fSIJzhSMTPmAyzF7HQ13LobeE4k3+m1PmofJzFi9VUrBYFyBsq6Cs3NuX7jcXfi9btJt2qupHgAvE0VssUzOPRjrsrSEBKqdaiiVxiqeSxUrtC7FtiqBKrQOAzYMyiTigQwnLYDHK/fOzANld+GkKoa2mlBZ0w6P2PfStHPvck0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589965502; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ykFRqSJsGAZwDGWi4dbag+7FdI9nXWeCtn40RKaRM34=; b=AppMkWbaJr2U3pLXa05Ol7QIuH9c7n5jZH9CZg+1knS3hOE57VFTrwaoIb3pKs/hdHv9fjvNNV8o63rareNhtGo2qDUFfP2RNRLpnBERy2AP+eUCvP7WYU2v2QNF6vogOApZJ17FJ9Ug3pgXOIixzjoKwEOysImpP6sKyXM3580= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1589965502946498.3170239727252; Wed, 20 May 2020 02:05:02 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbKeX-0002xz-6Q; Wed, 20 May 2020 09:04:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbKeV-0002xc-5D for xen-devel@lists.xenproject.org; Wed, 20 May 2020 09:04:39 +0000 Received: from mail-ed1-x544.google.com (unknown [2a00:1450:4864:20::544]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e9f7be6a-9a78-11ea-ae69-bc764e2007e4; Wed, 20 May 2020 09:04:30 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id b91so2221633edf.3 for ; Wed, 20 May 2020 02:04:30 -0700 (PDT) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id p5sm1324811edi.82.2020.05.20.02.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 02:04:28 -0700 (PDT) X-Inumbo-ID: e9f7be6a-9a78-11ea-ae69-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ykFRqSJsGAZwDGWi4dbag+7FdI9nXWeCtn40RKaRM34=; b=WjiRCyFue2N3loEHJeK1ZQ8K7qO/HzUwKXn36WqXp4dz8aFHTj3FtmsUjDZP3emB3o kUV421Ndka2pFFZoJGgStuk0GX/UB1DqkWaCD4Z2Z7Xqi2VVEkmxG2Wt8BkztOiWNKlf CRo9eHIrbvfZqTnDG7dUPWWi5KhuMxrLluZGo2+faLPg0ONJJ5LxB7dYaZqjFXKrp90r 7yZKDyBSBEX7O0jJgbb2qL36F+TYs7dzGGeftYA78ES1n0ZR6kUw7m3+eWYW+3klfMPk ZmvKuIOiYXIQAEh6Is8WOhCU5yg9yTOQwyPDE+xkOht810efiAVDpw8eQTjHLXSRDszA BTmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ykFRqSJsGAZwDGWi4dbag+7FdI9nXWeCtn40RKaRM34=; b=XhaizOd5FBrTO/vaR0w9+2Kowqkw7PaPmrqjyCg6+QSzSsmx8zYA6zPKV+xowzQxic Bbnjn3AlG7wtGa3ZwlvJUSkJWGiVFMuj0+h+zheWqA1en823smEvRvcaHdIbRHo6ywKo kYjpVIIScUrcUzDm+oWkOfKcA2IuQSOYiVPZvMqs/7cgw2wffnGlpsZFI5Ef0jjAfERX 3ISqv3oZzFmdA5NfGPC4ahLOWaHlChl1dq8xH309YbG4leTdiRCZXnBFEVOc9OnSgWEc Wmv+owcfctM7E/0rHFL9nDpziCy+aX9drxRn+P5gTbzPcNPtZOSXqWOvv/LwzAB/e6p3 n1oQ== X-Gm-Message-State: AOAM530ZQAtwwzsfN5xtytlUdiEKtjPKF72uDtSlg/B8tPdMmmAe0YuZ PWCCUcGO8v0KtuQ20VRAqW9rBv1a X-Google-Smtp-Source: ABdhPJzqHH2vMiODcT+P2Pg8ABrNQ3ilHz5qnBMwlB4nD9B4Qyvqz/yVuRnzx6KUPsxUGCp859Ri0Q== X-Received: by 2002:aa7:dd16:: with SMTP id i22mr2593357edv.366.1589965469263; Wed, 20 May 2020 02:04:29 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, jgross@suse.com, ian.jackson@eu.citrix.com, wei.liu2@citrix.com, konrad.wilk@oracle.com Subject: [PATCH 2/2] libgnttab: Add support for Linux dma-buf offset Date: Wed, 20 May 2020 12:04:25 +0300 Message-Id: <20200520090425.28558-3-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200520090425.28558-1-andr2000@gmail.com> References: <20200520090425.28558-1-andr2000@gmail.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Andrushchenko Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Add version 2 of the dma-buf ioctls which adds data_ofs parameter. dma-buf is backed by a scatter-gather table and has offset parameter which tells where the actual data starts. Relevant ioctls are extended to support that offset: - when dma-buf is created (exported) from grant references then data_ofs is used to set the offset field in the scatter list of the new dma-buf - when dma-buf is imported and grant references provided then data_ofs is used to report that offset to user-space Signed-off-by: Oleksandr Andrushchenko --- tools/include/xen-sys/Linux/gntdev.h | 53 +++++++++++++++++ tools/libs/gnttab/Makefile | 2 +- tools/libs/gnttab/freebsd.c | 15 +++++ tools/libs/gnttab/gnttab_core.c | 17 ++++++ tools/libs/gnttab/include/xengnttab.h | 13 ++++ tools/libs/gnttab/libxengnttab.map | 6 ++ tools/libs/gnttab/linux.c | 86 +++++++++++++++++++++++++++ tools/libs/gnttab/minios.c | 15 +++++ tools/libs/gnttab/private.h | 9 +++ 9 files changed, 215 insertions(+), 1 deletion(-) diff --git a/tools/include/xen-sys/Linux/gntdev.h b/tools/include/xen-sys/L= inux/gntdev.h index d16076044c71..0c43393cbee5 100644 --- a/tools/include/xen-sys/Linux/gntdev.h +++ b/tools/include/xen-sys/Linux/gntdev.h @@ -274,4 +274,57 @@ struct ioctl_gntdev_dmabuf_imp_release { uint32_t reserved; }; =20 +/* + * Version 2 of the ioctls adds @data_ofs parameter. + * + * dma-buf is backed by a scatter-gather table and has offset + * parameter which tells where the actual data starts. + * Relevant ioctls are extended to support that offset: + * - when dma-buf is created (exported) from grant references then + * @data_ofs is used to set the offset field in the scatter list + * of the new dma-buf + * - when dma-buf is imported and grant references are provided then + * @data_ofs is used to report that offset to user-space + */ +#define IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS_V2 \ + _IOC(_IOC_NONE, 'G', 13, \ + sizeof(struct ioctl_gntdev_dmabuf_exp_from_refs_v2)) +struct ioctl_gntdev_dmabuf_exp_from_refs_v2 { + /* IN parameters. */ + /* Specific options for this dma-buf: see GNTDEV_DMA_FLAG_XXX. */ + uint32_t flags; + /* Number of grant references in @refs array. */ + uint32_t count; + /* Offset of the data in the dma-buf. */ + uint32_t data_ofs; + /* OUT parameters. */ + /* File descriptor of the dma-buf. */ + uint32_t fd; + /* The domain ID of the grant references to be mapped. */ + uint32_t domid; + /* Variable IN parameter. */ + /* Array of grant references of size @count. */ + uint32_t refs[1]; +}; + +#define IOCTL_GNTDEV_DMABUF_IMP_TO_REFS_V2 \ + _IOC(_IOC_NONE, 'G', 14, \ + sizeof(struct ioctl_gntdev_dmabuf_imp_to_refs_v2)) +struct ioctl_gntdev_dmabuf_imp_to_refs_v2 { + /* IN parameters. */ + /* File descriptor of the dma-buf. */ + uint32_t fd; + /* Number of grant references in @refs array. */ + uint32_t count; + /* The domain ID for which references to be granted. */ + uint32_t domid; + /* Reserved - must be zero. */ + uint32_t reserved; + /* OUT parameters. */ + /* Offset of the data in the dma-buf. */ + uint32_t data_ofs; + /* Array of grant references of size @count. */ + uint32_t refs[1]; +}; + #endif /* __LINUX_PUBLIC_GNTDEV_H__ */ diff --git a/tools/libs/gnttab/Makefile b/tools/libs/gnttab/Makefile index 2da8fbbb7f6f..5ee2d965214f 100644 --- a/tools/libs/gnttab/Makefile +++ b/tools/libs/gnttab/Makefile @@ -2,7 +2,7 @@ XEN_ROOT =3D $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk =20 MAJOR =3D 1 -MINOR =3D 2 +MINOR =3D 3 LIBNAME :=3D gnttab USELIBS :=3D toollog toolcore =20 diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c index 886b588303a0..baf0f60aa4d3 100644 --- a/tools/libs/gnttab/freebsd.c +++ b/tools/libs/gnttab/freebsd.c @@ -319,6 +319,14 @@ int osdep_gnttab_dmabuf_exp_from_refs(xengnttab_handle= *xgt, uint32_t domid, abort(); } =20 +int osdep_gnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t d= omid, + uint32_t flags, uint32_t count, + const uint32_t *refs, + uint32_t *dmabuf_fd, uint32_t dat= a_ofs) +{ + abort(); +} + int osdep_gnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd, uint32_t wait_to_ms) { @@ -331,6 +339,13 @@ int osdep_gnttab_dmabuf_imp_to_refs(xengnttab_handle *= xgt, uint32_t domid, abort(); } =20 +int osdep_gnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t dom= id, + uint32_t fd, uint32_t count, + uint32_t *refs, uint32_t *data_ofs) +{ + abort(); +} + int osdep_gnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd) { abort(); diff --git a/tools/libs/gnttab/gnttab_core.c b/tools/libs/gnttab/gnttab_cor= e.c index 92e7228a2671..3af3cec80045 100644 --- a/tools/libs/gnttab/gnttab_core.c +++ b/tools/libs/gnttab/gnttab_core.c @@ -144,6 +144,15 @@ int xengnttab_dmabuf_exp_from_refs(xengnttab_handle *x= gt, uint32_t domid, refs, fd); } =20 +int xengnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t domi= d, + uint32_t flags, uint32_t count, + const uint32_t *refs, uint32_t *fd, + uint32_t data_ofs) +{ + return osdep_gnttab_dmabuf_exp_from_refs_v2(xgt, domid, flags, count, + refs, fd, data_ofs); +} + int xengnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd, uint32_t wait_to_ms) { @@ -156,6 +165,14 @@ int xengnttab_dmabuf_imp_to_refs(xengnttab_handle *xgt= , uint32_t domid, return osdep_gnttab_dmabuf_imp_to_refs(xgt, domid, fd, count, refs); } =20 +int xengnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t domid, + uint32_t fd, uint32_t count, uint32_t = *refs, + uint32_t *data_ofs) +{ + return osdep_gnttab_dmabuf_imp_to_refs_v2(xgt, domid, fd, count, refs, + data_ofs); +} + int xengnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd) { return osdep_gnttab_dmabuf_imp_release(xgt, fd); diff --git a/tools/libs/gnttab/include/xengnttab.h b/tools/libs/gnttab/incl= ude/xengnttab.h index 111fc88caeb3..0956bd91e0df 100644 --- a/tools/libs/gnttab/include/xengnttab.h +++ b/tools/libs/gnttab/include/xengnttab.h @@ -322,12 +322,19 @@ int xengnttab_grant_copy(xengnttab_handle *xgt, * Returns 0 if dma-buf was successfully created and the corresponding * dma-buf's file descriptor is returned in @fd. * + * Version 2 also accepts @data_ofs offset of the data in the buffer. + * * [1] https://elixir.bootlin.com/linux/latest/source/Documentation/driver= -api/dma-buf.rst */ int xengnttab_dmabuf_exp_from_refs(xengnttab_handle *xgt, uint32_t domid, uint32_t flags, uint32_t count, const uint32_t *refs, uint32_t *fd); =20 +int xengnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t domi= d, + uint32_t flags, uint32_t count, + const uint32_t *refs, uint32_t *fd, + uint32_t data_ofs); + /* * This will block until the dma-buf with the file descriptor @fd is * released. This is only valid for buffers created with @@ -345,10 +352,16 @@ int xengnttab_dmabuf_exp_wait_released(xengnttab_hand= le *xgt, uint32_t fd, /* * Import a dma-buf with file descriptor @fd and export granted references * to the pages of that dma-buf into array @refs of size @count. + * + * Version 2 also provides @data_ofs offset of the data in the buffer. */ int xengnttab_dmabuf_imp_to_refs(xengnttab_handle *xgt, uint32_t domid, uint32_t fd, uint32_t count, uint32_t *re= fs); =20 +int xengnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t domid, + uint32_t fd, uint32_t count, uint32_t = *refs, + uint32_t *data_ofs); + /* * This will close all references to an imported buffer, so it can be * released by the owner. This is only valid for buffers created with diff --git a/tools/libs/gnttab/libxengnttab.map b/tools/libs/gnttab/libxeng= nttab.map index d2a9b7e18bea..ddf77e064b08 100644 --- a/tools/libs/gnttab/libxengnttab.map +++ b/tools/libs/gnttab/libxengnttab.map @@ -36,3 +36,9 @@ VERS_1.2 { xengnttab_dmabuf_imp_to_refs; xengnttab_dmabuf_imp_release; } VERS_1.1; + +VERS_1.3 { + global: + xengnttab_dmabuf_exp_from_refs_v2; + xengnttab_dmabuf_imp_to_refs_v2; +} VERS_1.2; diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c index a01bb6c698c6..75e249fb3202 100644 --- a/tools/libs/gnttab/linux.c +++ b/tools/libs/gnttab/linux.c @@ -352,6 +352,51 @@ out: return rc; } =20 +int osdep_gnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t d= omid, + uint32_t flags, uint32_t count, + const uint32_t *refs, + uint32_t *dmabuf_fd, + uint32_t data_ofs) +{ + struct ioctl_gntdev_dmabuf_exp_from_refs_v2 *from_refs_v2 =3D NULL; + int rc =3D -1; + + if ( !count ) + { + errno =3D EINVAL; + goto out; + } + + from_refs_v2 =3D malloc(sizeof(*from_refs_v2) + + (count - 1) * sizeof(from_refs_v2->refs[0])); + if ( !from_refs_v2 ) + { + errno =3D ENOMEM; + goto out; + } + + from_refs_v2->flags =3D flags; + from_refs_v2->count =3D count; + from_refs_v2->domid =3D domid; + from_refs_v2->data_ofs =3D data_ofs; + + memcpy(from_refs_v2->refs, refs, count * sizeof(from_refs_v2->refs[0])= ); + + if ( (rc =3D ioctl(xgt->fd, IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS_V2, + from_refs_v2)) ) + { + GTERROR(xgt->logger, "ioctl DMABUF_EXP_FROM_REFS_V2 failed"); + goto out; + } + + *dmabuf_fd =3D from_refs_v2->fd; + rc =3D 0; + +out: + free(from_refs_v2); + return rc; +} + int osdep_gnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd, uint32_t wait_to_ms) { @@ -413,6 +458,47 @@ out: return rc; } =20 +int osdep_gnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t dom= id, + uint32_t fd, uint32_t count, + uint32_t *refs, + uint32_t *data_ofs) +{ + struct ioctl_gntdev_dmabuf_imp_to_refs_v2 *to_refs_v2 =3D NULL; + int rc =3D -1; + + if ( !count ) + { + errno =3D EINVAL; + goto out; + } + + to_refs_v2 =3D malloc(sizeof(*to_refs_v2) + + (count - 1) * sizeof(to_refs_v2->refs[0])); + if ( !to_refs_v2 ) + { + errno =3D ENOMEM; + goto out; + } + + to_refs_v2->fd =3D fd; + to_refs_v2->count =3D count; + to_refs_v2->domid =3D domid; + + if ( (rc =3D ioctl(xgt->fd, IOCTL_GNTDEV_DMABUF_IMP_TO_REFS_V2, to_ref= s_v2)) ) + { + GTERROR(xgt->logger, "ioctl DMABUF_IMP_TO_REFS_V2 failed"); + goto out; + } + + memcpy(refs, to_refs_v2->refs, count * sizeof(*refs)); + *data_ofs =3D to_refs_v2->data_ofs; + rc =3D 0; + +out: + free(to_refs_v2); + return rc; +} + int osdep_gnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd) { struct ioctl_gntdev_dmabuf_imp_release release; diff --git a/tools/libs/gnttab/minios.c b/tools/libs/gnttab/minios.c index f78caadd3043..298416b2a98d 100644 --- a/tools/libs/gnttab/minios.c +++ b/tools/libs/gnttab/minios.c @@ -120,6 +120,14 @@ int osdep_gnttab_dmabuf_exp_from_refs(xengnttab_handle= *xgt, uint32_t domid, return -1; } =20 +int osdep_gnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t d= omid, + uint32_t flags, uint32_t count, + const uint32_t *refs, uint32_t *f= d, + uint32_t data_ofs) +{ + return -1; +} + int osdep_gnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd, uint32_t wait_to_ms) { @@ -133,6 +141,13 @@ int osdep_gnttab_dmabuf_imp_to_refs(xengnttab_handle *= xgt, uint32_t domid, return -1; } =20 +int osdep_gnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t dom= id, + uint32_t fd, uint32_t count, + uint32_t *refs, uint32_t *data_ofs) +{ + return -1; +} + int osdep_gnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd) { return -1; diff --git a/tools/libs/gnttab/private.h b/tools/libs/gnttab/private.h index c5e23639b141..07271637f609 100644 --- a/tools/libs/gnttab/private.h +++ b/tools/libs/gnttab/private.h @@ -39,6 +39,11 @@ int osdep_gnttab_dmabuf_exp_from_refs(xengnttab_handle *= xgt, uint32_t domid, uint32_t flags, uint32_t count, const uint32_t *refs, uint32_t *fd); =20 +int osdep_gnttab_dmabuf_exp_from_refs_v2(xengnttab_handle *xgt, uint32_t d= omid, + uint32_t flags, uint32_t count, + const uint32_t *refs, uint32_t *f= d, + uint32_t data_ofs); + int osdep_gnttab_dmabuf_exp_wait_released(xengnttab_handle *xgt, uint32_t fd, uint32_t wait_to_ms= ); =20 @@ -46,6 +51,10 @@ int osdep_gnttab_dmabuf_imp_to_refs(xengnttab_handle *xg= t, uint32_t domid, uint32_t fd, uint32_t count, uint32_t *refs); =20 +int osdep_gnttab_dmabuf_imp_to_refs_v2(xengnttab_handle *xgt, uint32_t dom= id, + uint32_t fd, uint32_t count, + uint32_t *refs, uint32_t *data_ofs); + int osdep_gnttab_dmabuf_imp_release(xengnttab_handle *xgt, uint32_t fd); =20 int osdep_gntshr_open(xengntshr_handle *xgs); --=20 2.17.1