From patchwork Fri Aug 14 06:24:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 247695 Delivered-To: patches@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp127405ilo; Thu, 13 Aug 2020 23:25:02 -0700 (PDT) X-Received: by 2002:a17:902:fe17:: with SMTP id g23mr1047065plj.30.1597386302579; Thu, 13 Aug 2020 23:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597386302; cv=none; d=google.com; s=arc-20160816; b=cJID/eHUO0G1BgYBuMqaUU9m5YMo3fkJbyndH5/89OfkGgJY9TP+4lVv7Eb5/klXXu VQb/BtZR/gYjn252qhpwejz3kQm7IAGLLVGSCTMQiBiG7Q2LQBurfr2LZbw7XWqJ1g0G tlZifVuAHIH1vty9ny8VoeVsLK1JBQ1KkESHREvEuIR781kVI+V11ove2fBA3Kx5kLUf r+aUKZGNErYb+amrpGCjRCyMnwGf4kI1koWNCLtnpCeToupF3Q0FkRgvZcmR84a7bRxk PDITVIHn7IUwhe7iOr9yJggznJY6CZF1ewddNJGP197DzwdZ5uB4mfOL8mc9EEAhLLsl gEPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=pwDOHGKYvCi61mHFneVF0EduuTKfnrQsk03HbkNHX20=; b=GJZ+GP5dBJo83+kFh4bjSnlChatIdQtlXsGmcKOL2IHq3InCUO9DLLxgx7WJi274re hjuAcmnyJTwYpdbNwIuslF23s7eOXeGAqKtrxhF0vTYiC1tGBbBy7lfpjKnklQJ+4TYp 5T8KvIE5xCd1+LKsys50fX3j2wAovUvJ2MjbWP+Gn2xhcywQ+NPjRtzMtoXsd97fDkwC h5vcGMkaEfaZaMpV5cKUZd99uYVuYiEBRYy1kh6d6ye4njbYEeVA5DBudOkcP9BAnkJw a7imPsN/M8DevQ5OGSidKbqGBYPjppGPMnhNrSBOP3l4xFu2gRlkc5rr+AvtK0NfVn5+ vizA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dOPsv7f/"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y1sor7870186pjf.13.2020.08.13.23.25.02 for (Google Transport Security); Thu, 13 Aug 2020 23:25:02 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dOPsv7f/"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=pwDOHGKYvCi61mHFneVF0EduuTKfnrQsk03HbkNHX20=; b=dOPsv7f/wEuHeXmKjjFDeLAv02B1ounW5ulazhQV8hHqRYaoJ6XQBCnvtser32aA0E lgWuqqXH8kA0synMTCgHcFY7N2wuxSKoFOHOV6kqBkcKr5CSJ0fDOOolLuankz4PSiHm g+oRPe6gRdVqcAEnDUy6PIBRaTLR1LZZEGpxq4/ei7DQd0f9nkuuUli4Irvpx6e132Ev KKUCcTypG0YxXTabLVsyduvK5KJXFsR2GNAFoPL+SZGzbV9iiCoUhTMcAOa0EfqUFfJT LfhJ8/iUXz/Nfy9Wl7PPWVm2+2qUjp++JKg7RGAM5d8BbrjLDB9TujIrQQZgqMVHr1gt 0Mig== 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; bh=pwDOHGKYvCi61mHFneVF0EduuTKfnrQsk03HbkNHX20=; b=JuL1l14EXpgi5qmKgcAK9gIpL74iDoeM8ADl3rQkC/JB7OMMnTH/wDW/7DgFuply+I b0qTW71JyBXvcoUvMLVNKPRhbuf0wJLHGqweaW4ySv1aI/Q46b9WRs5Kx9XxedUFe7ug Gyv31a/O42oEfBV3kUsUAXK6QeIzgZ2v9Db8ne0YUaHJi2blOq0Ymq68r/po8aGMRskW aCkYL/gwh8mivyyjAl43G5EUcgAhVdtjoeuFGzRk5VkZNYvwXCXXNGCLrajIvadQ5/iH SbYoaXxltplEAU3pb38K4kCp1mnapRkj45xjAtd3EdEDDgUtvsXEttbGexG14vvACzhh W5Kw== X-Gm-Message-State: AOAM531WnA0IJGg9qOXxa/gPxR5IkeE0EQd37l0KBXq+2T/FIXjANDBD XBtj+P8aGZgOWWW8vaIsY81pdl96 X-Google-Smtp-Source: ABdhPJxnGWB4G0BauuF1CXzPhUUlFpGdCXVBwviMTN5qRwfvr9KZRSe4Mu5Ey8K87w5P6jwDUx+ihA== X-Received: by 2002:a17:90b:1254:: with SMTP id gx20mr1133241pjb.117.1597386302081; Thu, 13 Aug 2020 23:25:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id z4sm7651496pfb.55.2020.08.13.23.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 23:25:01 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , "Andrew F . Davis" , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Robin Murphy , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [RFC][PATCH v2 1/2] dma-heap: Keep track of the heap device struct Date: Fri, 14 Aug 2020 06:24:57 +0000 Message-Id: <20200814062458.53049-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 Keep track of the heap device struct. This will be useful for special DMA allocations and actions. Cc: Sumit Semwal Cc: Andrew F. Davis Cc: Benjamin Gaignard Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Robin Murphy 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(-) -- 2.17.1 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