From patchwork Sat Oct 17 01:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11842493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 545C4C433E7 for ; Sat, 17 Oct 2020 01:33:21 +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 EEDF12083B for ; Sat, 17 Oct 2020 01:33:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bdWzJhf+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEDF12083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 475126E30F; Sat, 17 Oct 2020 01:33:16 +0000 (UTC) Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0560B6E30C for ; Sat, 17 Oct 2020 01:33:15 +0000 (UTC) Received: by mail-pj1-x1042.google.com with SMTP id hk7so2443821pjb.2 for ; Fri, 16 Oct 2020 18:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P68wKVWfyCPNBm8l+XiI7Y585elPVzN5iuk0IO/H+/E=; b=bdWzJhf+Kt74SwdjGClZiLTK6Liqdc61K8jTehvBvcFdqmcILzkkCu6ynV2hBRrVEu 1pRQZehRxNgqVrBa+pMecr5Dr5+lqyMsuF9ucnzNvuTHw6CYBI5fUrMj2ZPC1UISlEk3 vLSJokv2OQC/BD4QC9wF367LFkQRvq06c0vFklyVkA+BJQHi0RBeH04qnblM6/0wWzzG 6ZR1WV9D+zUofDWUzH14k1P3gCaQQA2uWDojbYTMR6x+otkXIYbKyvhQxxUm0gOS/xbS cRYRiVFLPRMQtjWVoUAm9wKpGrsUL/6T1fVEeBTIzDsoNW/by0HXALYNmTPMIN3ewHq/ Q38g== 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:mime-version:content-transfer-encoding; bh=P68wKVWfyCPNBm8l+XiI7Y585elPVzN5iuk0IO/H+/E=; b=TUn5BiKFuP+Aj0ZDORChdMMcRIE/w9DprlHsE6aEd1pZwGa3AruQdgBMD44cW/+n7k bdPGJBI4DfeayO8o9gPY0dQ1vMGIBfVRp8GfE2JflxMjPdZwkGPzVz0yD6gRYLqxrRhT ez4Ahpx9dUi8jj9SMEQfqApA0x86sz+L45S/e2Wj2MloHP6TbYrQZbMLDA0qvyoDrfis itymSyHUcSMQuRlEKwA9fcW3wJqt04JwbRiQppiDLKFMqbs3n1qSQ9Yjg4aXuXpQV1Xj FKeon9Lih2Pt+UDlR7/wYqJlLyvXnDhaTWuhp3vBi0MPKGB9d2OXbzOyKKX+voJowZLI QXLw== X-Gm-Message-State: AOAM531KRHdny6wGPE0vSM94NitM2FBOyUGg50SkGTq0lYR4PPNTbbNt +tEMP7HNHe/QP/METTcwzUNvkQ== X-Google-Smtp-Source: ABdhPJxXdKj7nSAtkG+Eczc0+aZcCvZHERtkfZGx5ovLSOefr82WKn91iVR+sj6Dnq0bOj3NmoOHFw== X-Received: by 2002:a17:90a:8c87:: with SMTP id b7mr6918045pjo.66.1602898394682; Fri, 16 Oct 2020 18:33:14 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id e186sm4222122pfh.60.2020.10.16.18.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2020 18:33:14 -0700 (PDT) From: John Stultz To: lkml Subject: [PATCH v4 6/7] dma-buf: dma-heap: Keep track of the heap device struct Date: Sat, 17 Oct 2020 01:32:54 +0000 Message-Id: <20201017013255.43568-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201017013255.43568-1-john.stultz@linaro.org> References: <20201017013255.43568-1-john.stultz@linaro.org> MIME-Version: 1.0 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: , Cc: Sandeep Patil , dri-devel@lists.freedesktop.org, Ezequiel Garcia , Robin Murphy , James Jones , Liam Mark , Laura Abbott , Chris Goldsworthy , Hridya Valsaraju , =?utf-8?q?=C3=98rjan_Eide?= , linux-media@vger.kernel.org, Suren Baghdasaryan , Daniel Mentz Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Keep track of the heap device struct. This will be useful for special DMA allocations and actions. Cc: Sumit Semwal Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Chris Goldsworthy Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/dma-buf/dma-heap.c | 33 +++++++++++++++++++++++++-------- include/linux/dma-heap.h | 9 +++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index afd22c9dbdcf..72c746755d89 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -30,6 +30,7 @@ * @heap_devt heap device node * @list list head connecting to list of heaps * @heap_cdev heap char device + * @heap_dev heap device struct * * Represents a heap of memory from which buffers can be made. */ @@ -40,6 +41,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); @@ -190,10 +192,21 @@ void *dma_heap_get_drvdata(struct dma_heap *heap) return heap->priv; } +/** + * 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; +} + 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; @@ -247,16 +260,20 @@ 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; } + + /* Make sure it doesn't disappear on us */ + heap->heap_dev = get_device(heap->heap_dev); + /* Add heap to the list */ mutex_lock(&heap_list_lock); list_add(&heap->list, &heap_list); diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 454e354d1ffb..82857e096910 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -50,6 +50,15 @@ struct dma_heap_export_info { */ void *dma_heap_get_drvdata(struct dma_heap *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); + /** * dma_heap_add - adds a heap to dmabuf heaps * @exp_info: information needed to register this heap