Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1380124pxj; Fri, 18 Jun 2021 06:03:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsM2KkrpyryaM3U2b0H/wO+TqBB2jYf7yKkRvAqwihyjo1Vyw/5meqXBtuMWU3HZwOEdCT X-Received: by 2002:adf:ec83:: with SMTP id z3mr4273237wrn.222.1624021401281; Fri, 18 Jun 2021 06:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624021401; cv=none; d=google.com; s=arc-20160816; b=tZyTIqECB5fuAP1b1wakZG3TYc5r9pM3vEqTX/Q1BWG9/Pjz3MDXzxy86zHlRstCpo ndcibdhFMOH8q56+ynfwK3WX/mbBt48MAT9bn24Gs+m8LeS9v7EHi63oOmFHMy/i1D92 ZpC/MqPul/iX8qY0pqbIRHPPM6aGAZfQ+LE2N44IjDnilX1Nqnm3OD7Vjvwz2cs82uCR D2+mYP624bj/yx6GqIH2zCI0mfzBJp8D4BNi++Hb/tDSawSkwfHoWowLtu+N/yMQ7xJq M8RNow36SslAD241pJP8ZX8z8ZOHbPFQYL2I4iPdMLeIX/eyfMbV2WMMmNsdjNaQapOx Vo9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wbZktVFJcQw0a+UBJORZ5pV76E/1cny7R2uUFpJmwc4=; b=Y/HhSlxTVxjgrR8M/KNXbhhIvMUWle3TayGNim0iMtLlbrRCfNxBpeLPsjofc/3vA4 3VRLlYYhoYvKypD1HD+HXpmmWk654/NGngoRsMmL4eZV1OebgVn5J7VapsO971DxwoKw 5hZX7SL4LUx8JO1BJ4WhCpU0nW38dpXMv8spdwEty6bGNRGM/szH4W2VjFoWgjozZbZZ SY+e6qO6Yb7OeK8jIHtsV/qrH+kqwWquwOwR7gvHbozINMlwqVjyu5hW0Yym6F3w2h4x 6wu8MD7sKL9o4IpCd0RSLOxIf788iClYR+ZqUVtOTDELmq/NjTk/PYTm82pzFxoYu3ln bj0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k5YrrBAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si2828254ejb.550.2021.06.18.06.02.56; Fri, 18 Jun 2021 06:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k5YrrBAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbhFRMig (ORCPT + 99 others); Fri, 18 Jun 2021 08:38:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbhFRMif (ORCPT ); Fri, 18 Jun 2021 08:38:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 93FB8613EC; Fri, 18 Jun 2021 12:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624019785; bh=kKl+dwSE+1mpdV00Nwtq36eOm8r1Np9GR2J4zMKETqw=; h=From:To:Cc:Subject:Date:From; b=k5YrrBAxdE8zUmY8WvvE6MJEHD4yCIfdhvVUBlI/qsUYJjYXfbKU78ApJg64xU1w0 7qVG5t7WmchDe1sFQazK5BroSYVUpuwWCeJQjZKn+NVSZEZR83wuOrbwgzND8hO6xj LeGInqvzq3wnMOuT582NCuDiz8hpEMnM5/fItlJtMGeIUVem4IjyF9PZlr21qPYRcw 1OrO4AmqhBJCzw7ReLn/CQ97OKXWmWIWJekrO+4rgfXkdFWmthIQCpPPjZbYiMWg6S v8GMav3uPaH40/Rv2M1px0v63R1WEz2KC51rodtiVAv48rOedfjrayds0BLFUoeUOa G8T2S2M7U15bw== From: Oded Gabbay To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: sumit.semwal@linaro.org, christian.koenig@amd.com, daniel.vetter@ffwll.ch, galpress@amazon.com, sleybo@amazon.com, dri-devel@lists.freedesktop.org, Tomer Tayar Subject: [PATCH v3 1/2] habanalabs: define uAPI to export FD for DMA-BUF Date: Fri, 18 Jun 2021 15:36:13 +0300 Message-Id: <20210618123615.11456-1-ogabbay@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org User process might want to share the device memory with another driver/device, and to allow it to access it over PCIe (P2P). To enable this, we utilize the dma-buf mechanism and add a dma-buf exporter support, so the other driver can import the device memory and access it. The device memory is allocated using our existing allocation uAPI, where the user will get a handle that represents the allocation. The user will then need to call the new uAPI (HL_MEM_OP_EXPORT_DMABUF_FD) and give the handle as a parameter. The driver will return a FD that represents the DMA-BUF object that was created to match that allocation. Signed-off-by: Oded Gabbay Reviewed-by: Tomer Tayar --- include/uapi/misc/habanalabs.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/uapi/misc/habanalabs.h b/include/uapi/misc/habanalabs.h index a47a731e4527..aa3d8e0ba060 100644 --- a/include/uapi/misc/habanalabs.h +++ b/include/uapi/misc/habanalabs.h @@ -808,6 +808,10 @@ union hl_wait_cs_args { #define HL_MEM_OP_UNMAP 3 /* Opcode to map a hw block */ #define HL_MEM_OP_MAP_BLOCK 4 +/* Opcode to create DMA-BUF object for an existing device memory allocation + * and to export an FD of that DMA-BUF back to the caller + */ +#define HL_MEM_OP_EXPORT_DMABUF_FD 5 /* Memory flags */ #define HL_MEM_CONTIGUOUS 0x1 @@ -878,11 +882,26 @@ struct hl_mem_in { /* Virtual address returned from HL_MEM_OP_MAP */ __u64 device_virt_addr; } unmap; + + /* HL_MEM_OP_EXPORT_DMABUF_FD */ + struct { + /* Handle returned from HL_MEM_OP_ALLOC. In Gaudi, + * where we don't have MMU for the device memory, the + * driver expects a physical address (instead of + * a handle) in the device memory space. + */ + __u64 handle; + /* Size of memory allocation. Relevant only for GAUDI */ + __u64 mem_size; + } export_dmabuf_fd; }; /* HL_MEM_OP_* */ __u32 op; - /* HL_MEM_* flags */ + /* HL_MEM_* flags. + * For the HL_MEM_OP_EXPORT_DMABUF_FD opcode, this field holds the + * DMA-BUF file/FD flags. + */ __u32 flags; /* Context ID - Currently not in use */ __u32 ctx_id; @@ -919,6 +938,13 @@ struct hl_mem_out { __u32 pad; }; + + /* Returned in HL_MEM_OP_EXPORT_DMABUF_FD. Represents the + * DMA-BUF object that was created to describe a memory + * allocation on the device's memory space. The FD should be + * passed to the importer driver + */ + __u64 fd; }; }; -- 2.25.1