From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 01FB4EC1430 for ; Tue, 3 Mar 2026 12:34:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 56A9E10E7B1; Tue, 3 Mar 2026 12:34:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="W3yrsWkI"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4787610E7B1 for ; Tue, 3 Mar 2026 12:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772541265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YW5SxBIIgkWx2jwEXG8osOzGtmkFwVM71Xjy+8ygUKo=; b=W3yrsWkI06g5t038aIdnqEr/lXUbKFK79FqpchVUEr5oSUrPrpNgLOXcRQGQvfU2rA67N8 bcrEXXc72HgxrAbecPRs41nh2xWyvnhuu/MqY2WN+w44WbvgSk1fyZwII2roCq1R1r52a+ pKS435Xj5qlIrB9vW7IB+FVuLF5DcVY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-384-t6iJc4AkPQu8r09LjPv5Jw-1; Tue, 03 Mar 2026 07:34:19 -0500 X-MC-Unique: t6iJc4AkPQu8r09LjPv5Jw-1 X-Mimecast-MFC-AGG-ID: t6iJc4AkPQu8r09LjPv5Jw_1772541257 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 439B3180025B; Tue, 3 Mar 2026 12:34:17 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.44.32.231]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 26F2830001B9; Tue, 3 Mar 2026 12:34:10 +0000 (UTC) From: Albert Esteve Date: Tue, 03 Mar 2026 13:33:44 +0100 Subject: [PATCH v2 1/6] dma-buf: dma-heap: Keep track of the heap device struct MIME-Version: 1.0 Message-Id: <20260303-b4-dmabuf-heap-coherent-rmem-v2-1-65a4653b3378@redhat.com> References: <20260303-b4-dmabuf-heap-coherent-rmem-v2-0-65a4653b3378@redhat.com> In-Reply-To: <20260303-b4-dmabuf-heap-coherent-rmem-v2-0-65a4653b3378@redhat.com> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy , Rob Herring , Saravana Kannan Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Albert Esteve , echanude@redhat.com, mripard@redhat.com, John Stultz X-Developer-Signature: v=1; a=ed25519-sha256; t=1772541243; l=3358; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=QjNRn783TryVaP32s1fqdde0JJl5VlRoYl0aey6l8JI=; b=ZTgmWxaTm/nzxm/hJzIpamvvLX7d8KyH9pT9SgKvu5Ga0Z6Na1Isl5iBXBfJT8GRq6iQDFm90 qFRX/fnBUg+DuPrGY0zNdK7au0KM6M72mRUXBFqDgF5U5p4HmiO3Qb2 X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-MFC-PROC-ID: 7c7BhVhh3gpPjqhK2FwyYlLxVOVCwTFhzngEAIs2yzw_1772541257 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: John Stultz Keep track of the heap device struct. This will be useful for special DMA allocations and actions. Signed-off-by: John Stultz Signed-off-by: Albert Esteve --- drivers/dma-buf/dma-heap.c | 34 ++++++++++++++++++++++++++-------- include/linux/dma-heap.h | 2 ++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index ac5f8685a6494..1124d63eb1398 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -31,6 +31,7 @@ * @heap_devt: heap device node * @list: list head connecting to list of heaps * @heap_cdev: heap char device + * @heap_dev: heap device * * Represents a heap of memory from which buffers can be made. */ @@ -41,6 +42,7 @@ struct dma_heap { dev_t heap_devt; struct list_head list; struct cdev heap_cdev; + struct device *heap_dev; }; static LIST_HEAD(heap_list); @@ -223,6 +225,19 @@ const char *dma_heap_get_name(struct dma_heap *heap) } EXPORT_SYMBOL_NS_GPL(dma_heap_get_name, "DMA_BUF_HEAP"); +/** + * dma_heap_get_dev() - get device struct for the heap + * @heap: DMA-Heap to retrieve device struct from + * + * Returns: + * The device struct for the heap. + */ +struct device *dma_heap_get_dev(struct dma_heap *heap) +{ + return heap->heap_dev; +} +EXPORT_SYMBOL_NS_GPL(dma_heap_get_dev, "DMA_BUF_HEAP"); + /** * dma_heap_add - adds a heap to dmabuf heaps * @exp_info: information needed to register this heap @@ -230,7 +245,6 @@ EXPORT_SYMBOL_NS_GPL(dma_heap_get_name, "DMA_BUF_HEAP"); struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) { struct dma_heap *heap, *h, *err_ret; - struct device *dev_ret; unsigned int minor; int ret; @@ -272,14 +286,14 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) goto err1; } - dev_ret = device_create(dma_heap_class, - NULL, - heap->heap_devt, - NULL, - heap->name); - if (IS_ERR(dev_ret)) { + heap->heap_dev = device_create(dma_heap_class, + NULL, + heap->heap_devt, + NULL, + heap->name); + if (IS_ERR(heap->heap_dev)) { pr_err("dma_heap: Unable to create device\n"); - err_ret = ERR_CAST(dev_ret); + err_ret = ERR_CAST(heap->heap_dev); goto err2; } @@ -295,6 +309,10 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) } } + /* Make sure it doesn't disappear on us */ + heap->heap_dev = get_device(heap->heap_dev); + + /* Add heap to the list */ list_add(&heap->list, &heap_list); mutex_unlock(&heap_list_lock); diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 648328a64b27e..493085e69b70e 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -12,6 +12,7 @@ #include struct dma_heap; +struct device; /** * struct dma_heap_ops - ops to operate on a given heap @@ -43,6 +44,7 @@ struct dma_heap_export_info { void *dma_heap_get_drvdata(struct dma_heap *heap); const char *dma_heap_get_name(struct dma_heap *heap); +struct device *dma_heap_get_dev(struct dma_heap *heap); struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); -- 2.52.0