From patchwork Sat Oct 3 04:02:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 67692 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1kOYkn-00HSD8-Ue; Sat, 03 Oct 2020 04:02:38 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725834AbgJCEDU (ORCPT + 1 other); Sat, 3 Oct 2020 00:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725777AbgJCEDR (ORCPT ); Sat, 3 Oct 2020 00:03:17 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B49D3C0613E6 for ; Fri, 2 Oct 2020 21:03:15 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id x2so2146088pjk.0 for ; Fri, 02 Oct 2020 21:03: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=DoA/WXci/N6o2iCahmaE/6s0q36QnObD7Kz0rTkp+Wir/LUz0b97SkvNv7xR8a7ae1 RhoBSY2JhZVsel487aadjO1WZBme5eKV9taGbs7OEZj7tP1hdrTrDyftqkQwVGwgrW61 FiW7nbBi6IUykERJktulqpG5s1Mx4/OOXLINs2shI5aG3o/yj9b+6340TrewWhofNsKh at1Plc5eH1zH3vg7LejixlzlKVVC8vJNdvOHnzLXvQCLdVq15VJl7/7z3xH0J/VNtxJQ K4cNL4vwhilksSyNVrIEvRW/vsqhEu3pCbvcRCAwzTKKo81cnhKZPRUOQaVp2V4vrQaP hzRw== 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=llxpq3nxXwUB/R4Cgkm200nWOCZ6cCD6twjRPHovkA/hZjpfpnjnGe6Y4Rg9acYCvn iRWVEutZ/cb4bo5661NmgWVQ9j+g5JB24Oc4m6IWJQyZBref7CwH+yvFgCAKGeIQ1KCn pNWTN8S1lZTXnJ+N6tGdSbauQ8esYKV7UR5u3pAf6XgtvAXE8QUYvIVzpcugbUt1xc6Y /nTVl5bkle0G6605qeKiPB3ostCNxYKxK4rytS6Lqsk+qW2QxXrLSR8qv9Lp38/6OgMI tJMmx0hltgFJDZqJX2HUzPWTLE7+LDuZ1u9R6BGW02mOBphawrKohAaoHm1EeviF4oWm 9lMQ== X-Gm-Message-State: AOAM532YxpYt6bm8o0IaSA6yoRPvx+74oXh6+xvtCfOZAV8pFxAnoVAz UM+pZkCFa6IO+9VxRFZ0eYxhHg== X-Google-Smtp-Source: ABdhPJx3+jjcIjYbmsHUy2FJCfess91XkiwkBnhEIbWxL3NSmESgIifCive3HkthH2uT5nuo8Gx91A== X-Received: by 2002:a17:90a:ead5:: with SMTP id ev21mr5465614pjb.188.1601697795315; Fri, 02 Oct 2020 21:03:15 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 190sm3909290pfy.22.2020.10.02.21.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 21:03:14 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v3 6/7] dma-buf: dma-heap: Keep track of the heap device struct Date: Sat, 3 Oct 2020 04:02:56 +0000 Message-Id: <20201003040257.62768-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201003040257.62768-1-john.stultz@linaro.org> References: <20201003040257.62768-1-john.stultz@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no 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