From patchwork Wed Mar 11 13:51:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11431963 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D10790 for ; Wed, 11 Mar 2020 15:04:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7006E206C0 for ; Wed, 11 Mar 2020 15:04:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BAeSTC9m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7006E206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2BC2E6E45F; Wed, 11 Mar 2020 15:04:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D4EC8915A; Wed, 11 Mar 2020 13:52:03 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id s5so2733684wrg.3; Wed, 11 Mar 2020 06:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zTmN9DEXOaBKxy4tMmFv7mOnUJY2ke5/2F4me6DvZxM=; b=BAeSTC9mAbQYlziodp36mbOGFsKH7iH3q092S9yg/JaB8KzrHSjHA75LCPhnkgOXWy rPq1mMbAkhv99dEpTtwdyRxvT//fEPGoOr3FpSxAMwwwylFdYazU+S7qE/k1/U6wcO9z rz6YxqI9KOs+KRS1WDGs8DZ754b1KUsvXZKEAImad7Ypui1EcXCKy9znmi2UU7FuSeKB lYVXVtZv1d9TvemNGvwTHI0wCloJ5sMwnlJlPCAPR1miGRgCl7H8B8x2uU55VdQLeF8w /JsODq5PKPptAVb+jR60P0gpPWcmz2aU1zALeQ+st8NSe/g3pzYf2jkOUdf6vkSFZ1YP R0Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zTmN9DEXOaBKxy4tMmFv7mOnUJY2ke5/2F4me6DvZxM=; b=llu5VtsBmZIGUOCfat9RhJqLEIKbDoc++nlnC2l1Paxjn5l+03Y7vgKuqtCSgZ+d4H Ief79eky5/A30qBAuEQYwLki4MibDbYFthUNIADAOdTqYebUdEACtGyQYzZUG22HUIKN 8jcQguFio3mclyAG5OVVnxds9Jo29qYrKGQkVUI4VhRAjr2bMbrFlKzhPHWixkM5rzsd OkAbM6QzFoCx//72NyU2iaSdElDtbbWJcMHykHf9UepeHELlySd6IroRH0CE88TtlHkD yXT59WbiqOz2tW2eATPpi3bQdpqL9tdEzkgyS96Vw00M175dnEvKySw7vIBpa/BmQCgK 0bBw== X-Gm-Message-State: ANhLgQ1pFEmsBJSlJ8Nj8beQlExRToUWnQkorRJM8Yhc4JlLfLAKMdt6 yxMgu/UoUIwps4P0Wi3zW+vNuLDo X-Google-Smtp-Source: ADFU+vsOOz12ce5eYJpqK2qbmEnKZS+AmEeu/Oz2KmbCkMjsmBPhswTyMx1kwU26TJkE3M/mMkmkIQ== X-Received: by 2002:a5d:6208:: with SMTP id y8mr4791359wru.64.1583934721964; Wed, 11 Mar 2020 06:52:01 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8dc:e796:e7da:a319]) by smtp.gmail.com with ESMTPSA id 138sm3183811wmb.21.2020.03.11.06.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 06:52:01 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: David1.Zhou@amd.com, hch@infradead.org, jgg@ziepe.ca, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Wed, 11 Mar 2020 14:51:53 +0100 Message-Id: <20200311135158.3310-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311135158.3310-1-christian.koenig@amd.com> References: <20200311135158.3310-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 11 Mar 2020 15:04:30 +0000 Subject: [Intel-gfx] [PATCH 1/6] lib/scatterlist: add sg_set_dma_addr() function X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" This can be used by drivers to setup P2P DMA between device memory which is not backed by struct pages. The drivers of the involved devices are responsible for setting up and tearing down DMA addresses as necessary using dma_map_resource(). The page pointer is set to NULL and only the DMA address, length and offset values are valid. Signed-off-by: Christian König --- include/linux/scatterlist.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 6eec50fb36c8..28a477bf0bdf 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -145,6 +145,29 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf, sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); } +/** + * sg_set_dma_addr - Set sg entry to point at specified dma address + * @sg: SG entry + * @address: DMA address to set + * @len: Length of data + * @offset: Offset into page + * + * Description: + * Use this function to set an sg entry to point to device resources mapped + * using dma_map_resource(). The page pointer is set to NULL and only the DMA + * address, length and offset values are valid. + * + **/ +static inline void sg_set_dma_addr(struct scatterlist *sg, dma_addr_t address, + unsigned int len, unsigned int offset) +{ + sg_set_page(sg, NULL, len, offset); + sg->dma_address = address; +#ifdef CONFIG_NEED_SG_DMA_LENGTH + sg->dma_length = len; +#endif +} + /* * Loop over each sg element, following the pointer to a new list if necessary */