From patchwork Tue May 5 19:58:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 186213 Delivered-To: patches@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp1458621ill; Tue, 5 May 2020 12:59:08 -0700 (PDT) X-Received: by 2002:a65:62c7:: with SMTP id m7mr4036490pgv.16.1588708748253; Tue, 05 May 2020 12:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588708748; cv=none; d=google.com; s=arc-20160816; b=0LaF9JLTv98Gdwm4H70md535N9tWFtINa/kFJdm4HQEVwCfwLEje2c+2hJWWYzCEJU ukQRh5/vf/MU8ZCKyKOPoBQE+i8IMDZPP23Yq1p91FWAGfClAWNZyGEhrW6JfcL8jLrE WTINwhfziIkNr0AjeXpZ89bKj2If1gXHrKXl+Im+tjMIiyfiZR0WcVllGWPBm6XnFCbZ nnCtwyn7ZNJgI/Ona63jt895ntjRIwqrXQKvveC5RMXaV7KOvDFnzEwkumXp9wxSeIrz QcPRCglvMPz8nSkw4fMxd87H02y4rWgfU5GwiOMg9JOTyEB6UHpa6Slaesj/6oQrY5qo BKTQ== 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=f1+hms/HzM6XhVGpCUGj/whrgwNh6rfdziobohzGjU0=; b=EbLKlCWHtDvOHL06W6n97vwstztinl49nonJahr+MBj2Ppnmr6OK0ohDjDmbToxSos VSlAz0lrVsffnR7uS2G4/BX2UtZjJo0MOocMr+Q6PJDT46/NEbW3Klvg7rO8/kUCB7sv YOYGs3uQk7yKkVPmGxS06HOYYi9sKYban2R5nSWak9cI2NmXNuuvhd2NJ0yq4YBVt3FV OFcC2oHdFzyHRT++mJizsmC7hLRa7iEBGXXwlYtBdhMcCKqt0HFGxxK0ghHX5Jkp54o1 irWpADjGvg7rXWNrshK6cVAD6mXIHWPN+Iyfoig/56I5ITlbkx8Bt0aTFBdDlruvIXZV UsMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j5icav5E; 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 w23sor2854645pfi.49.2020.05.05.12.59.08 for (Google Transport Security); Tue, 05 May 2020 12:59:08 -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=j5icav5E; 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=f1+hms/HzM6XhVGpCUGj/whrgwNh6rfdziobohzGjU0=; b=j5icav5EDStMOR/2B21rulvYuqmWnmvmIeOriztRfGhaPPUGNpO8dlZp160uR706ZD CN2QM5AhYuYJeuug7vVImTiEEiTMGsbPeeJ8eF7fqxtEhv5IKislP2NiZR0wnIyEP+6f rK6eFlxeOHWZ8uyyHoholRW5OG86eulBa4N8KAS0LFWQ4v5HnXcKlo09ickPrFdKv9Fl SVQwRB5sUrWTArMbmlzeqabNtZtM6Alu25x09aKKycamTKKAJZCpkZssyCHTVYayY6qm Gk11BZ+OM61c5XDtH02v30t9c4Dk2oncvar+SlxiEamjVSxqZjTVrvBfWXpygYfsB9DR 8uAg== 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=f1+hms/HzM6XhVGpCUGj/whrgwNh6rfdziobohzGjU0=; b=hluNK/AUI3ZMc5OuNj8bldE/SiHr0My+Az1fQSJ6GOAPFIHI+qbNQj8dI/aOHc9JpR IgeLtqfQ8w3xmkRBdpNmVX0xyt6v9pTouLbijtBykvT4A0epZlAsuHLVKVVpNjHiHmO+ 9V/GVsQ5b5lFGCpdLzVi2vvFikQQ7q5clF4OXprmSUqi9tQ/0JyTJIClDB75eVQlzvdQ KctGcP19IrxVy/Pz+Zh+gL+gX/V9Ob6OjPEAJFpj4SbhtLjAS73AyIB7e0fb19H0SlAC GulcSqtPjFliEABehnuxXXtdoQdbyavFWni+/1pzncrAWMlIljhP3L8+GOt76FdE0SKf scIA== X-Gm-Message-State: AGi0PuaIeHAjHBG9NqPnMX4WnD16WKR/twsNj2pkxN11bT+aHxNNgjyV XB/t4Ndu9xFXeykyOFnRGZIId4qR X-Google-Smtp-Source: APiQypJTkn2fb2KSXsJtRyKxtCBL8YFjFle7PrivbJtU3P7dZajSC4xcII15Rx0VXANN2wYvfl7zlw== X-Received: by 2002:a62:888a:: with SMTP id l132mr594480pfd.125.1588708747776; Tue, 05 May 2020 12:59:07 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id c1sm2559317pfo.152.2020.05.05.12.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 12:59:07 -0700 (PDT) From: John Stultz To: "Andrew F. Davis" , Sumit Semwal Cc: John Stultz Subject: [PATCH 1/2] dma-heap: Refactor code to allow for future in-kernel users Date: Tue, 5 May 2020 19:58:54 +0000 Message-Id: <20200505195855.94934-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 Really early RFC on this. Signed-off-by: John Stultz --- drivers/dma-buf/dma-heap.c | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index afd22c9dbdcf..de09a0626a61 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -48,10 +48,31 @@ static dev_t dma_heap_devt; static struct class *dma_heap_class; static DEFINE_XARRAY_ALLOC(dma_heap_minors); +static struct dma_heap *dma_heap_find(const char* name) +{ + struct dma_heap *h; + + /* check the name is unique */ + mutex_lock(&heap_list_lock); + list_for_each_entry(h, &heap_list, list) { + if (!strcmp(h->name, name)) { + mutex_unlock(&heap_list_lock); + return h; + } + } + mutex_unlock(&heap_list_lock); + return NULL; +} + static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, unsigned int fd_flags, unsigned int heap_flags) { + if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) + return -EINVAL; + + if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) + return -EINVAL; /* * Allocations from all heaps have to begin * and end on page boundaries. @@ -89,12 +110,6 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data) if (heap_allocation->fd) return -EINVAL; - if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) - return -EINVAL; - - if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) - return -EINVAL; - fd = dma_heap_buffer_alloc(heap, heap_allocation->len, heap_allocation->fd_flags, heap_allocation->heap_flags); @@ -192,7 +207,7 @@ void *dma_heap_get_drvdata(struct dma_heap *heap) struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) { - struct dma_heap *heap, *h, *err_ret; + struct dma_heap *heap, *err_ret; struct device *dev_ret; unsigned int minor; int ret; @@ -208,16 +223,11 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) } /* check the name is unique */ - mutex_lock(&heap_list_lock); - list_for_each_entry(h, &heap_list, list) { - if (!strcmp(h->name, exp_info->name)) { - mutex_unlock(&heap_list_lock); - pr_err("dma_heap: Already registered heap named %s\n", - exp_info->name); - return ERR_PTR(-EINVAL); - } + if (dma_heap_find(exp_info->name)) { + pr_err("dma_heap: Already registered heap named %s\n", + exp_info->name); + return ERR_PTR(-EINVAL); } - mutex_unlock(&heap_list_lock); heap = kzalloc(sizeof(*heap), GFP_KERNEL); if (!heap) From patchwork Tue May 5 19:58:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 186214 Delivered-To: patches@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp1458628ill; Tue, 5 May 2020 12:59:09 -0700 (PDT) X-Received: by 2002:a17:902:6b0a:: with SMTP id o10mr4626106plk.32.1588708749323; Tue, 05 May 2020 12:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588708749; cv=none; d=google.com; s=arc-20160816; b=p38ilKphZ4UUGi4OZKBmnZuSjRfLFoJkQ33KIv+b7uIRXX9hO/uncMc52Z0gg4bKpR a8OGqWl4gx44Dw/Ivvm2hjALwlFnfwDJHbkrA6EzCz9Q0Yrc/l90dqcQRUFVmqc7QR/3 NMj6SdTROZDa04+uTJh3arl2u5Nao+Hamd5cq3qyHNG420FZq7QpUbHaadEAebA2nRxV pm4P0tpMwB5co9JWr2qnRg+qCoGvqetnMoIFvykVBuetidrDReOW5azCerlNtW8zzQnh JRmyozJDd45/ZsZ9+xBiyXqTN3eowB/F3vpu1SqHjPcbeFa9w8beuORzaXBhVejKZXEJ I7cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m+GmLE4pz0xLhaDU1Bou6l9fXNg2SfUgElMcEuCIBRo=; b=Ok/nCiNz1UW0CDkmIffMZlR9/u0deIpIXy4RbKhjUZ+Ol+WNYqo5yvmy5uuxiJlCFp oiuMm5XiB3Kmi20ZsHLnH9ixfcW7d22b8T79+J2DZOYblY+FFh87s4Pk16BqvWnM2ALF tt3KaorQtUCnD5q8kqnUq8TV/V5jWJjajB3QM1FuY6jPKMoKdysoJUGrNfQgOsTWnz8c aArQ2MhPIgfYhsesxYLZxs5qyBC9WN8qUucFfGpgDbISGjAMkKlc6xFre07SCjqWYBRh kDTar8142LRZIMoWypbh402Zk61XiH+OvDjO/pgWoAVMERVNtgCkLhNVDY4K9PCP6Mnh PKVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C8OMBNqI; 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 t74sor2800589pfc.42.2020.05.05.12.59.09 for (Google Transport Security); Tue, 05 May 2020 12:59:09 -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=C8OMBNqI; 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:in-reply-to:references; bh=m+GmLE4pz0xLhaDU1Bou6l9fXNg2SfUgElMcEuCIBRo=; b=C8OMBNqIyGzIYCKP2wQwb726+RHMNXFCdNizC3qDuj6hRiFUDCozV+SCONFUly5CDu 7V0OnUyCZiXPti6Pf19/1Cd1dht2bx3PGeGZuocB5qBfk4xfJYKl3rb/KfwSNlXePuYq +cMo4C65+KxHKfHC+3RiDZTnx8FSBkYF3wT3ZFCzRb5Vmf8b90FmOdydWYT0hHKoHBzl 7nqQjLFRlYykNkt43sVcv4IpCutSr2JTXpu/Mn1rza6PkGjEH7GSX31N2ZnXOeTd4+zV bULYcjlTHCIi9kDywosAK1yF5hWNHwqtQd+oT0GmpJrIrCILDxPfYNcLXkQgkiZ6vnhg r4HQ== 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; bh=m+GmLE4pz0xLhaDU1Bou6l9fXNg2SfUgElMcEuCIBRo=; b=UUOBIK7TgHQKvCSNHIwwUcBN6LK1RoPWJu18k89WE1e0o3vWMfzndmneLB5zzzof/2 sKiXnAsNuk2S+Bxt6qpMn8N0fz28M0uOSaS2tVzoDFG93FOSScdNpaWtzcm6OQLKmJ9l SV9DbBg/T10foT+EkMOVJ2k9qsukb4H3k3PitSpbDiAOAhT79vNYhF0lmgsicAxUCAno CHgHm/Nc4zp5dssLHFMspUYCYlLNgXQ4l4zw7CCjkWHBnI94rlWTZ7SErmVG5uReFyjW K1cqxouUmYFAMM1vsh8i7KFaHCM1fVj2CwLoreTv0P1YKFDo8v7yoBgxhG4lH8t8RsNX YBcg== X-Gm-Message-State: AGi0PuaZ8ywXObf5N+tDOrfwyvSUftr6nZE7VHmQpL0ndnYlSstaRLqI gcn/iZ6u0TkdjOsvbNm+HuG7J12CQMKMhQ== X-Google-Smtp-Source: APiQypKadkqAbDyl+6AauLKxHH+zYTBuqlg/3T8m8CbMCh4BEU1KUam4JOLiybhWmSTw62KL9hEw6w== X-Received: by 2002:aa7:8ec1:: with SMTP id b1mr4733879pfr.103.1588708748963; Tue, 05 May 2020 12:59:08 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id c1sm2559317pfo.152.2020.05.05.12.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 12:59:08 -0700 (PDT) From: John Stultz To: "Andrew F. Davis" , Sumit Semwal Cc: John Stultz Subject: [PATCH 2/2] dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps Date: Tue, 5 May 2020 19:58:55 +0000 Message-Id: <20200505195855.94934-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505195855.94934-1-john.stultz@linaro.org> References: <20200505195855.94934-1-john.stultz@linaro.org> Really early RFC. Basically trying to provide in-kernel accessors to the DMA-BUF heaps, similar to what the ion interface provided Before we can push this patch, we need an actual in-kernel user Signed-off-by: John Stultz --- drivers/dma-buf/dma-heap.c | 8 ++++---- include/linux/dma-heap.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index de09a0626a61..f4f699f9c8c4 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -48,7 +48,7 @@ static dev_t dma_heap_devt; static struct class *dma_heap_class; static DEFINE_XARRAY_ALLOC(dma_heap_minors); -static struct dma_heap *dma_heap_find(const char* name) +struct dma_heap *dma_heap_find(const char* name) { struct dma_heap *h; @@ -64,9 +64,9 @@ static struct dma_heap *dma_heap_find(const char* name) return NULL; } -static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, - unsigned int fd_flags, - unsigned int heap_flags) +int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, + unsigned int fd_flags, + unsigned int heap_flags) { if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) return -EINVAL; diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 454e354d1ffb..2971b0b5f223 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -56,4 +56,22 @@ void *dma_heap_get_drvdata(struct dma_heap *heap); */ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); + + +/** + * dma_heap_find - Returns the registered dma_heap with the specified name + * @name: Name of the heap to find + */ +struct dma_heap *dma_heap_find(char* name); + +/** + * dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap + * @heap: dma_heap to allocate from + * @len: size to allocate + * @fd_flags: flags to set on returned dma-buf fd + * @heap_flags: flags to pass to the dma heap + */ +int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, + unsigned int fd_flags, + unsigned int heap_flags); #endif /* _DMA_HEAPS_H */