From patchwork Wed May 15 13:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665303 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BCBF64CFC; Wed, 15 May 2024 13:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781465; cv=none; b=L+msbWDSBlz8xEeWVu8RN0eYz71M7x6SPp3KWb+XLDfk7zjhGp9CewMYlLO1KOC9XE2X1HJaEZcz6h/zuRTdvnNM3Jhmet0xrPLE9lI9+wUrpmoHJxzUbS5ruCZqTwxmfaubJWmkOLLXKAK5OLz+0rIn1BoS118iVFGRMj1PU/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781465; c=relaxed/simple; bh=y4c5Ovhy94byqgEWHicSc3d/PAkjnLlMSsPZmPA2CY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ktYxxCT6Rdaz/izq/hTDWibQTmNqHAuQuPglpZQIHcvPARgysIfclO68s1nIxtseAOVsXNZ9OSOldkAYKVWZOUnaFl1Ct7FNJrebot1uAW1/WxIqZkpAbkzZk5+60xmlproYeqDzyGlDwB5stlKHZWh6XOuO3OSR+E5j+HR6MqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WxSnfSTm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WxSnfSTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FAD3C4AF19; Wed, 15 May 2024 13:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781464; bh=y4c5Ovhy94byqgEWHicSc3d/PAkjnLlMSsPZmPA2CY4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WxSnfSTmQ/csjEC2fejH+PymBQ7/2Gv2FU3ve4/QA2kxCOURBe1IcIN3l7T56t2uo m0dglIusTz5Ckpsvo0Rawk7iFM8OAo9r7czY2FuhmGIwYDWUpT/KauDYo355CHhV9Z igQJoWElO4xiLoUIQ/DzdfS3+kgD7l5VVR89N0b/5ckoAUz39/6AO3bu1I/3b/WuHa KORhwnw0kV8jAfZuqnqzj02bt85XjEdZp8N7snX6wUgbfdk1m+tcaCGGA2zEBxBvq/ BYqFU9tddtWMy9s28lvy8+AjgUpK9NEQqPNnPG0XX78WlWnvpSRVGTR7t+klSSeiAU XwD1+9VdLQT1w== From: Maxime Ripard Date: Wed, 15 May 2024 15:56:56 +0200 Subject: [PATCH 1/8] dma-buf: heaps: Introduce a new heap for reserved memory Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-1-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9483; i=mripard@kernel.org; h=from:subject:message-id; bh=y4c5Ovhy94byqgEWHicSc3d/PAkjnLlMSsPZmPA2CY4=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+30tkivZGtj+2vRlvdih5t2+sUmOa28rw7qJs/4/b mTJ9zvZMZWFQZiTQVZMkeWJTNjp5e2LqxzsV/6AmcPKBDKEgYtTACaS5cBYn3Fzof6U71OkEm4s XePqtdGj8sCHmS9fFS23yHdbtP5D/T3F37vSzB43HYg9LZZ71vGFF2PDBLPK1M6/gokbFULVbHa byT7/G6TGYTg7XX7uH9uQKRMDt900VbkeslZxtf9TFedz/8oB X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Some reserved memory regions might have particular memory setup or attributes that make them good candidates for heaps. Let's provide a heap type that will create a new heap for each reserved memory region flagged as such. Signed-off-by: Maxime Ripard --- drivers/dma-buf/heaps/Kconfig | 8 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/carveout_heap.c | 314 ++++++++++++++++++++++++++++++++++ 3 files changed, 323 insertions(+) diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig index a5eef06c4226..c6981d696733 100644 --- a/drivers/dma-buf/heaps/Kconfig +++ b/drivers/dma-buf/heaps/Kconfig @@ -1,5 +1,13 @@ +config DMABUF_HEAPS_CARVEOUT + bool "Carveout Heaps" + depends on DMABUF_HEAPS + help + Choose this option to enable the carveout dmabuf heap. The carveout + heap is backed by pages from reserved memory regions flagged as + exportable. If in doubt, say Y. + config DMABUF_HEAPS_SYSTEM bool "DMA-BUF System Heap" depends on DMABUF_HEAPS help Choose this option to enable the system dmabuf heap. The system heap diff --git a/drivers/dma-buf/heaps/Makefile b/drivers/dma-buf/heaps/Makefile index 974467791032..b734647ad5c8 100644 --- a/drivers/dma-buf/heaps/Makefile +++ b/drivers/dma-buf/heaps/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_DMABUF_HEAPS_CARVEOUT) += carveout_heap.o obj-$(CONFIG_DMABUF_HEAPS_SYSTEM) += system_heap.o obj-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o diff --git a/drivers/dma-buf/heaps/carveout_heap.c b/drivers/dma-buf/heaps/carveout_heap.c new file mode 100644 index 000000000000..896ca67e6bd9 --- /dev/null +++ b/drivers/dma-buf/heaps/carveout_heap.c @@ -0,0 +1,314 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +struct carveout_heap_priv { + struct dma_heap *heap; + struct gen_pool *pool; +}; + +struct carveout_heap_buffer_priv { + struct mutex lock; + struct list_head attachments; + + unsigned long len; + unsigned long num_pages; + struct carveout_heap_priv *heap; + void *buffer; +}; + +struct carveout_heap_attachment { + struct list_head head; + struct sg_table table; + + struct device *dev; + bool mapped; +}; + +static int carveout_heap_attach(struct dma_buf *buf, + struct dma_buf_attachment *attachment) +{ + struct carveout_heap_buffer_priv *priv = buf->priv; + struct carveout_heap_attachment *a; + int ret; + + a = kzalloc(sizeof(*a), GFP_KERNEL); + if (!a) + return -ENOMEM; + INIT_LIST_HEAD(&a->head); + a->dev = attachment->dev; + attachment->priv = a; + + ret = sg_alloc_table(&a->table, priv->num_pages, GFP_KERNEL); + if (ret) + goto err_cleanup_attach; + + mutex_lock(&priv->lock); + list_add(&a->head, &priv->attachments); + mutex_unlock(&priv->lock); + + return 0; + +err_cleanup_attach: + kfree(a); + return ret; +} + +static void carveout_heap_detach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct carveout_heap_buffer_priv *priv = dmabuf->priv; + struct carveout_heap_attachment *a = attachment->priv; + + mutex_lock(&priv->lock); + list_del(&a->head); + mutex_unlock(&priv->lock); + + sg_free_table(&a->table); + kfree(a); +} + +static struct sg_table * +carveout_heap_map_dma_buf(struct dma_buf_attachment *attachment, + enum dma_data_direction direction) +{ + struct carveout_heap_attachment *a = attachment->priv; + struct sg_table *table = &a->table; + int ret; + + ret = dma_map_sgtable(a->dev, table, direction, 0); + if (ret) + return ERR_PTR(-ENOMEM); + + a->mapped = true; + + return table; +} + +static void carveout_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction) +{ + struct carveout_heap_attachment *a = attachment->priv; + + a->mapped = false; + dma_unmap_sgtable(a->dev, table, direction, 0); +} + +static int +carveout_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct carveout_heap_buffer_priv *priv = dmabuf->priv; + struct carveout_heap_attachment *a; + + mutex_lock(&priv->lock); + + list_for_each_entry(a, &priv->attachments, head) { + if (!a->mapped) + continue; + + dma_sync_sgtable_for_cpu(a->dev, &a->table, direction); + } + + mutex_unlock(&priv->lock); + + return 0; +} + +static int +carveout_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct carveout_heap_buffer_priv *priv = dmabuf->priv; + struct carveout_heap_attachment *a; + + mutex_lock(&priv->lock); + + list_for_each_entry(a, &priv->attachments, head) { + if (!a->mapped) + continue; + + dma_sync_sgtable_for_device(a->dev, &a->table, direction); + } + + mutex_unlock(&priv->lock); + + return 0; +} + +static int carveout_heap_mmap(struct dma_buf *dmabuf, + struct vm_area_struct *vma) +{ + struct carveout_heap_buffer_priv *priv = dmabuf->priv; + struct page *page = virt_to_page(priv->buffer); + + return remap_pfn_range(vma, vma->vm_start, page_to_pfn(page), + priv->num_pages * PAGE_SIZE, vma->vm_page_prot); +} + +static void carveout_heap_dma_buf_release(struct dma_buf *buf) +{ + struct carveout_heap_buffer_priv *buffer_priv = buf->priv; + struct carveout_heap_priv *heap_priv = buffer_priv->heap; + + gen_pool_free(heap_priv->pool, (unsigned long)buffer_priv->buffer, + buffer_priv->len); + kfree(buffer_priv); +} + +static const struct dma_buf_ops carveout_heap_buf_ops = { + .attach = carveout_heap_attach, + .detach = carveout_heap_detach, + .map_dma_buf = carveout_heap_map_dma_buf, + .unmap_dma_buf = carveout_heap_unmap_dma_buf, + .begin_cpu_access = carveout_heap_dma_buf_begin_cpu_access, + .end_cpu_access = carveout_heap_dma_buf_end_cpu_access, + .mmap = carveout_heap_mmap, + .release = carveout_heap_dma_buf_release, +}; + +static struct dma_buf *carveout_heap_allocate(struct dma_heap *heap, + unsigned long len, + unsigned long fd_flags, + unsigned long heap_flags) +{ + struct carveout_heap_priv *heap_priv = dma_heap_get_drvdata(heap); + struct carveout_heap_buffer_priv *buffer_priv; + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct dma_buf *buf; + dma_addr_t daddr; + void *buffer; + int ret; + + buffer_priv = kzalloc(sizeof(*buffer_priv), GFP_KERNEL); + if (!buffer_priv) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&buffer_priv->attachments); + mutex_init(&buffer_priv->lock); + + buffer = gen_pool_dma_zalloc(heap_priv->pool, len, &daddr); + if (!buffer) { + ret = -ENOMEM; + goto err_free_buffer_priv; + } + + buffer_priv->buffer = buffer; + buffer_priv->heap = heap_priv; + buffer_priv->len = len; + buffer_priv->num_pages = len / PAGE_SIZE; + + /* create the dmabuf */ + exp_info.exp_name = dma_heap_get_name(heap); + exp_info.ops = &carveout_heap_buf_ops; + exp_info.size = buffer_priv->len; + exp_info.flags = fd_flags; + exp_info.priv = buffer_priv; + + buf = dma_buf_export(&exp_info); + if (IS_ERR(buf)) { + ret = PTR_ERR(buf); + goto err_free_buffer; + } + + return buf; + +err_free_buffer: + gen_pool_free(heap_priv->pool, (unsigned long)buffer, len); +err_free_buffer_priv: + kfree(buffer_priv); + + return ERR_PTR(ret); +} + +static const struct dma_heap_ops carveout_heap_ops = { + .allocate = carveout_heap_allocate, +}; + +static int __init carveout_heap_setup(struct device_node *node) +{ + struct dma_heap_export_info exp_info = {}; + const struct reserved_mem *rmem; + struct carveout_heap_priv *priv; + struct dma_heap *heap; + struct gen_pool *pool; + void *base; + int ret; + + rmem = of_reserved_mem_lookup(node); + if (!rmem) + return -EINVAL; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + pool = gen_pool_create(PAGE_SHIFT, NUMA_NO_NODE); + if (!pool) { + ret = -ENOMEM; + goto err_cleanup_heap; + } + priv->pool = pool; + + base = memremap(rmem->base, rmem->size, MEMREMAP_WB); + if (!base) { + ret = -ENOMEM; + goto err_release_mem_region; + } + + ret = gen_pool_add_virt(pool, (unsigned long)base, rmem->base, + rmem->size, NUMA_NO_NODE); + if (ret) + goto err_unmap; + + exp_info.name = node->full_name; + exp_info.ops = &carveout_heap_ops; + exp_info.priv = priv; + + heap = dma_heap_add(&exp_info); + if (IS_ERR(heap)) { + ret = PTR_ERR(heap); + goto err_cleanup_pool_region; + } + priv->heap = heap; + + return 0; + +err_cleanup_pool_region: + gen_pool_free(pool, (unsigned long)base, rmem->size); +err_unmap: + memunmap(base); +err_release_mem_region: + gen_pool_destroy(pool); +err_cleanup_heap: + kfree(priv); + return ret; +} + +static int __init carveout_heap_init(void) +{ + struct device_node *rmem_node; + struct device_node *node; + int ret; + + rmem_node = of_find_node_by_path("/reserved-memory"); + if (!rmem_node) + return 0; + + for_each_child_of_node(rmem_node, node) { + if (!of_property_read_bool(node, "export")) + continue; + + ret = carveout_heap_setup(node); + if (ret) + return ret; + } + + return 0; +} + +module_init(carveout_heap_init); From patchwork Wed May 15 13:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665304 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C612813EFF3; Wed, 15 May 2024 13:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781468; cv=none; b=nThswmWa0MKM5FwI5wjLuXMev/1Wb6Qb2oqgH1TXomLpqwERateKK8U6EsVyCRTG4vVYg4V1dc0LdcLd8w5VAg3Lex83EzC+LNx0IVPSzUBGaYjaZxghw20cIP/a3aXVNoqZ06boMtpuCrkh+v7ErmxBGg/jPLItfhGZvlyVFRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781468; c=relaxed/simple; bh=8ZuUxwBuqIl5xv9FwD6zxHdkEr4bqeDZSbsEsg2zPmU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mygWS5UKztmktTTeJ7pwevLbNAsgE+Mm4h5qowbUB/Vh7/4hoRhnKDM++7ApaudeCRxX8KgPh3lO/+H4fyTpF4fH/dlJkOA3uWIToOFKYJU8ZkcQLlu4sx+FXGiU6ZjtXBtgkCuKEGioP3Z3mdZ1FuhR3EORiEeze2rno9pI4pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oj3FlSFO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oj3FlSFO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4CB9C4AF08; Wed, 15 May 2024 13:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781468; bh=8ZuUxwBuqIl5xv9FwD6zxHdkEr4bqeDZSbsEsg2zPmU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Oj3FlSFOr68/qWfihvTAujUUhPEGoUh0a2EeRfwvOp8t6TcAJblJSqUhG15QQTajm X0ZypIvahxAHTF82FIRmlU2JmeCiZMwvZg+EGvVdwOy+OSOe2xcXF1JXL/koBjWJ8f uY1eH1kzAK3EKpSlqeE4zNl58tmABu/OHRqvET7KDksCSKN7RmxdJnLqrBLyDwRdHT tj9PWxBrP/AM1H0vdT+uxhTO2BFPXx2o3XWUE0K/GWe/3iVt7N8oPjgzVElc+MOGeJ 74zzL/+8OcKcEv9NJp/Th0hDHXFns5PI1R9GkALEM+tDghU+PYNfMeHNgQ21rMnH+z MvHx0X9dwRxgQ== From: Maxime Ripard Date: Wed, 15 May 2024 15:56:57 +0200 Subject: [PATCH 2/8] of: Add helper to retrieve ECC memory bits Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-2-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1585; i=mripard@kernel.org; h=from:subject:message-id; bh=8ZuUxwBuqIl5xv9FwD6zxHdkEr4bqeDZSbsEsg2zPmU=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+/3WZlme0eHdaHF23mbWzIrm86HrbRLD7LyCko8rz uJ85re0YyoLgzAng6yYIssTmbDTy9sXVznYr/wBM4eVCWQIAxenAEzkYjpjndaJwD3Xp39eISqZ bOWhaGUqfPC+tbxHZce+b2VbV6lc4Ap8mKG7L8Nf/dPlvvmn739RZmw4p9u4J+i/zY7Hpn97nvC k2mQ5mV6d/XPaqwcblXumnVxr6J4cufGVjJSY2aW6VRcUq44BAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The /memory device tree bindings allow to store the ECC detection and correction bits through the ecc-detection-bits and ecc-correction-bits properties. Our next patches rely on whether ECC is enabled, so let's add a helper to retrieve the ECC correction bits from the /memory node. Signed-off-by: Maxime Ripard --- include/linux/of.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index a0bedd038a05..2fbee65a7aa9 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1510,10 +1510,35 @@ static inline int of_get_available_child_count(const struct device_node *np) num++; return num; } +/** + * of_memory_get_ecc_correction_bits() - Returns the number of ECC correction bits + * + * Search for the number of bits in memory that can be corrected by the + * ECC algorithm. + * + * Returns: + * The number of ECC bits, 0 if there's no ECC support, a negative error + * code on failure. + */ +static inline int of_memory_get_ecc_correction_bits(void) +{ + struct device_node *mem; + u32 val = 0; + + mem = of_find_node_by_path("/memory"); + if (!mem) + return -ENODEV; + + of_property_read_u32(mem, "ecc-correction-bits", &val); + of_node_put(mem); + + return val; +} + #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type) \ static const struct of_device_id __of_table_##name \ __attribute__((unused)) \ = { .compatible = compat, \ .data = (fn == (fn_type)NULL) ? fn : fn } From patchwork Wed May 15 13:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665305 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B769C14036A; Wed, 15 May 2024 13:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781471; cv=none; b=uw5GjysECbnsMly5EdG6OdgxwF4I1lvVKtszDILgWgpPwTDuWXsqOh36eqN0OB4DRzSjxdjr4sYeRF0zRISu+0Jr/vk2hKmDVCeBEtEj0K4IMLq08iryFVI0bYn756SY/EQlGJZa5orBb+ayS4kh09ufdH10srNXoc3KRrJs0Os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781471; c=relaxed/simple; bh=WlatdzDn5ln9onnNggxk+fyl1HpLY51fWYKvzy2mHOg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c91rY8S5tUzr6ewzTbtiYbFvo3hwMJeW/5d7nPDmVOl6TChiKIot8qRF7W9LXXQ6LPrWJdmXKOvqRTTNzjvSqcfvkVDUwoCY6eYeAWcTzRxJQGFop7xW1ooVScjZsHsvCmrYLDBvj0w1jQ9baGL7wP/ILJrcMuEdRK/dxm0oqG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tOp4lR8X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tOp4lR8X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18B28C116B1; Wed, 15 May 2024 13:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781471; bh=WlatdzDn5ln9onnNggxk+fyl1HpLY51fWYKvzy2mHOg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tOp4lR8Xi9y7SXrlPN4RRDtbbEihJDZsXFsYuT50HqukD2dqQDCKdRN12/0+EMRKb 4GxcHkEYYQwNTs55WBFKc3l8txKL7m7sWXy58yR6ih2EpH7fbVOpRIbmJzLB6y7L43 z3tzAMtENCjfDLcFGgLMxefwVbI2x/Ra7oqPq5kA6UeMNjS2ontIRJ7DJYf23xlGTD xRqA61OBzd3oV7HWy8to7fJOtP3opiZ9MdMxQw1dt2zDLuA0DQztG0HIZC/g1962Us k5i+gtEJav11An/G8O6Hb/Kv3zajjRErguxEBm1vDSs9KJn7+vjtGWzAjdYB9tbZ1E XDf25KvPwtkxA== From: Maxime Ripard Date: Wed, 15 May 2024 15:56:58 +0200 Subject: [PATCH 3/8] dma-buf: heaps: Import uAPI header Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-3-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=758; i=mripard@kernel.org; h=from:subject:message-id; bh=WlatdzDn5ln9onnNggxk+fyl1HpLY51fWYKvzy2mHOg=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+/3e/CltXrZHt3vnu0l/DhuoJs0MtQxoT13VdKcst 2F5oU55x1QWBmFOBlkxRZYnMmGnl7cvrnKwX/kDZg4rE8gQBi5OAZjI9cmMDY8aVp+d+WfjezXZ BxK7Ww+09n27yvEt6mCamVPDJU9H0ef93XVdB32ttZZOu7j37cmVVxnrPdJ8JPqMt8d3xXZP5t7 xT1xa/dZ8lb1mKvf895zO+z7ZtenGhg5hzzuPwsUUkhKear4GAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The uAPI header has a bunch of constants and structures that might be handy in drivers. Let's include the header in the driver-side dma-heap header. Signed-off-by: Maxime Ripard --- include/linux/dma-heap.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 0c05561cad6e..e7cf110c5fdc 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -10,10 +10,12 @@ #define _DMA_HEAPS_H #include #include +#include + struct dma_heap; /** * struct dma_heap_ops - ops to operate on a given heap * @allocate: allocate dmabuf and return struct dma_buf ptr From patchwork Wed May 15 13:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665306 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4136913F427; Wed, 15 May 2024 13:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781475; cv=none; b=IsIhDa7+lo1LU0BkuFsgz+gmeOtLJt37bRS8BXsV9qNXREt4p0z/W4Wr0kJoqAHQ2np4nugzpWMJslAfhWfN7IAE/RxUhlhJAaXNv9pYCCgbtNjhku2zzLdB4lRFUDLPSpGve26IlwydtJ1yppNLg2NqB+hC2dSvGtTiOstpqhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781475; c=relaxed/simple; bh=3a1PkEj7cE+sch219RIbB9Jk0bMgUp62q1dLoyBXtNE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DogI8Qe+m21FvAnqLO+tMIdSQ+NfwRgoUS5D9uRGTZbBPpr5YrWl7T2t6mZ6bUYmo+ErKpbDu6rZvYpN3vL/yWqh9Da48pt8Euc2sHUwBKbE6WiyEL/qvuFQkJ8dijXyX8jIZSJD2o1zdy6FmmaTE+Ds0Ad4iLxGLkT18BQ58Hs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXu68TXf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QXu68TXf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EF92C116B1; Wed, 15 May 2024 13:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781474; bh=3a1PkEj7cE+sch219RIbB9Jk0bMgUp62q1dLoyBXtNE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QXu68TXftiz2lZOlszefjpiO6hArafdb17Coy3vmlIKkWX1OTyUhmaxRP9Gkg92cH htkRgOtHMIewMzwPQE9UXTJz7jkSgrRdaRpNs0HD7mkSCmw/NSbr2Me1iPuizOTvpX xjJWdWNZYkbmCExVJkX80T7at917TAo29YHxraWuxwC2hZpBJgWFRWj74MZU/a8K62 QTjhcN9n27uj0cTaUj/VBMnC+dlSa1CYn1E21Pyj6lT5FL6CFXiVAOC/didMJdwlPG RBqhC1ZopZGwWC3mrWGmGpxAHYPFEWTByZ60XzEqdIDZGy3iq3Xe5j9uxQt4n+DeHT R9aKXFT8gVe5g== From: Maxime Ripard Date: Wed, 15 May 2024 15:56:59 +0200 Subject: [PATCH 4/8] dma-buf: heaps: Add ECC protection flags Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-4-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2044; i=mripard@kernel.org; h=from:subject:message-id; bh=3a1PkEj7cE+sch219RIbB9Jk0bMgUp62q1dLoyBXtNE=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+/2nKmw4Xr3PpCAtJ9HX6rfW47R9Dit2ez1IiU7p5 phpe8G3YyoLgzAng6yYIssTmbDTy9sXVznYr/wBM4eVCWQIAxenAEykhImxYfev3IBfD6+9YDuc 2t2+614VF/dWOcUVfXc41n2rveHQrVlV4x7Qz73kL6f+39v2hZt6GRv+mvRsZot9yu0tP9m/82P TvNeat1UCvjcpnVfI+cYVKSlxuihVdOniK7tfLn0moneHYxYA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Some systems run with ECC enabled on the memory by default, but with some memory regions with ECC disabled to mitigate the downsides of enabling ECC (reduced performances, increased memory usage) for buffers that don't require it. Let's create some allocation flags to ask for a particular ECC setup when allocate a dma-buf through a heap. Signed-off-by: Maxime Ripard --- drivers/dma-buf/dma-heap.c | 4 ++++ include/uapi/linux/dma-heap.h | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 84ae708fafe7..a96c1865b627 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -106,10 +106,14 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data) return -EINVAL; if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) return -EINVAL; + if ((heap_allocation->heap_flags & DMA_HEAP_FLAG_ECC_PROTECTED) && + (heap_allocation->heap_flags & DMA_HEAP_FLAG_ECC_UNPROTECTED)) + return -EINVAL; + fd = dma_heap_buffer_alloc(heap, heap_allocation->len, heap_allocation->fd_flags, heap_allocation->heap_flags); if (fd < 0) return fd; diff --git a/include/uapi/linux/dma-heap.h b/include/uapi/linux/dma-heap.h index 6f84fa08e074..677b6355552d 100644 --- a/include/uapi/linux/dma-heap.h +++ b/include/uapi/linux/dma-heap.h @@ -16,12 +16,13 @@ */ /* Valid FD_FLAGS are O_CLOEXEC, O_RDONLY, O_WRONLY, O_RDWR */ #define DMA_HEAP_VALID_FD_FLAGS (O_CLOEXEC | O_ACCMODE) -/* Currently no heap flags */ -#define DMA_HEAP_VALID_HEAP_FLAGS (0) +#define DMA_HEAP_FLAG_ECC_PROTECTED BIT(0) +#define DMA_HEAP_FLAG_ECC_UNPROTECTED BIT(1) +#define DMA_HEAP_VALID_HEAP_FLAGS (DMA_HEAP_FLAG_ECC_PROTECTED | DMA_HEAP_FLAG_ECC_UNPROTECTED) /** * struct dma_heap_allocation_data - metadata passed from userspace for * allocations * @len: size of the allocation From patchwork Wed May 15 13:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665307 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 099751411DB; Wed, 15 May 2024 13:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781478; cv=none; b=qccHXTjTShCBjxBbSPxVvcY7RZizKfqnwEo+9P7A+GRj3/ypnFd3Cr1oO9NJdQMMaGzhVikOnffI5P6KT69aVnrWWf2Avy+E74I0suTCm6cyHrQR9aQtK+xTpdJM7/1xl3uu/6uYezVGQh/q9kT/WoDWppwPcecKhxo6gP/2SKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781478; c=relaxed/simple; bh=+td2VTdxnfVRiC1SSw6dBtys0XD7Sod+cqvq7T/2at8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kR6iQm36QeK2O9qm1NDjr1/MbSIWMeUf+KtM2haoyam2Bo5qV6rXcvg+19UngJ/rIeMY/N6D1zP2jdZzq/I1NhZ+fGmulTsHugE4myqzHBipP99qhkWZO+cbhphtoGIvNPyO25rX0afvN0hLG7+qbYtPPcE3i+GWYkbUDbJFreA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KtdH8diI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KtdH8diI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47694C2BD11; Wed, 15 May 2024 13:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781477; bh=+td2VTdxnfVRiC1SSw6dBtys0XD7Sod+cqvq7T/2at8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KtdH8diImn5gIEe0U7/AhqBlZ7YEtbhRy6QCY7F6lxBQkdF5Ctxrj9Uc7TMvLQbp7 Zb+vFQM9TKFFcOyEYx2GwJ1NWd4Han36isoLtvmMqXDDU6NWjUnb40FJNrywbYpmME vq9Nzb0xa1oAoA3HduTOopGkMp17mn/A14jg7fcIU/ghx0AQ2hnmYDpC+H/rREJ1dA HEy4TUvR4dQ4kcT2NP6sJkCBu6RkZnB9V6M1iiWYv0Qb/QkMLS4fjKtlt5gKX+Eqj8 VA0k9ubrvJvcZjM3JLgi3wlmippUnGZ/mDAvxVJhxYABsg+qdGtootB7uKAiHumCaH z0ybkFLOOhCEw== From: Maxime Ripard Date: Wed, 15 May 2024 15:57:00 +0200 Subject: [PATCH 5/8] dma-buf: heaps: system: Remove global variable Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-5-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1705; i=mripard@kernel.org; h=from:subject:message-id; bh=+td2VTdxnfVRiC1SSw6dBtys0XD7Sod+cqvq7T/2at8=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+/0vr4tVvXx5rcA68dY53V7P43MLbmlFVFxelf615 bKyDqtAx1QWBmFOBlkxRZYnMmGnl7cvrnKwX/kDZg4rE8gQBi5OAZjIz1rGWvmESVdfXVrnsvWM 5ZV5XTtvv5nv0vOpZ+muNZJdJ9O5jPcvSdxwp2vVjilOJ54l3/GYa89YzVJ+5U1ncHDQnzvFb1p /lNm/dv6p/zB36vwJxiucfl4+53KiSET88P1HOiHcht6W3gX9AA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The system heap has been using its struct dma_heap pointer but wasn't using it anywhere. Since we'll need additional parameters to attach to that heap type, let's create a private structure and set it as the dma_heap drvdata, removing the global variable in the process. Signed-off-by: Maxime Ripard --- drivers/dma-buf/heaps/system_heap.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 9076d47ed2ef..8b5e6344eea4 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -19,11 +19,13 @@ #include #include #include #include -static struct dma_heap *sys_heap; +struct system_heap { + struct dma_heap *heap; +}; struct system_heap_buffer { struct dma_heap *heap; struct list_head attachments; struct mutex lock; @@ -422,17 +424,22 @@ static const struct dma_heap_ops system_heap_ops = { }; static int system_heap_create(void) { struct dma_heap_export_info exp_info; + struct system_heap *sys_heap; + + sys_heap = kzalloc(sizeof(*sys_heap), GFP_KERNEL); + if (!sys_heap) + return -ENOMEM; exp_info.name = "system"; exp_info.ops = &system_heap_ops; - exp_info.priv = NULL; + exp_info.priv = sys_heap; - sys_heap = dma_heap_add(&exp_info); - if (IS_ERR(sys_heap)) - return PTR_ERR(sys_heap); + sys_heap->heap = dma_heap_add(&exp_info); + if (IS_ERR(sys_heap->heap)) + return PTR_ERR(sys_heap->heap); return 0; } module_init(system_heap_create); From patchwork Wed May 15 13:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665308 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22F9514199C; Wed, 15 May 2024 13:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781481; cv=none; b=Be3vBx0MxyDuTbuhcXSE1EdeeVeVdl5nXT33eHM9LojUsGjIb37tjae8aoEXCiveAml+xZtNlVSlqa+XG93ZZBfWQrcdiaSSfTLFo7VO7+yycILIeN5/bzqSQkuxeAb8/P6OZkxm116aszkLtxMQ65szDBDz1CXrV6DYv1w7LL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781481; c=relaxed/simple; bh=5mlKKVq2eJW/2EfLe5DfEKj2I4ZhUMzP6qbNsK6waI0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IN5smj/uWZQ2hxTw2bW65Av2jhgka3+gcCY70ZNeAbcmrj4aGE7CKiuAvcAVrE4qkIZzgk4ot7U3tYv3IHJvfXrPO63uBNGPir66Pgwk7Yj4smG3LjO7jWB146oMmo1+hUi9QZRi45a+AF7zoDQxISRyHdam9O1iK6IADaViIOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nIEWiQt3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nIEWiQt3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40576C32786; Wed, 15 May 2024 13:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781480; bh=5mlKKVq2eJW/2EfLe5DfEKj2I4ZhUMzP6qbNsK6waI0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nIEWiQt3XuLSsZQZbWwRK/SZdLBw0yS/Z0FGjHBgaacZPjdEhuvlesyZ8P2aS0pKQ srv93C5wQVlqvWYipTMZJtZkgbHq/VwWSyr800bzc1x5redx59NQJdYgwBXAAOXVp3 bd/xYluu06uM4adros5GaK5yunJRLnzDWy3zsrWOlhAz4ooJ7GaW7Refb43pAaAke+ pD4dZONJjf5kqS7QGfLgjzNkk8J9bmYLNCnLz4HFQBSobuX9Ph5jn4qfMdiIkcX4Fa sMtVnTiOpr2gkKTD8v9lNzqDJXZ5ixtZSVg6BTB/p1gmSmVvl0HWAyEOChq5jbIPfh dJB3NWSekMMSg== From: Maxime Ripard Date: Wed, 15 May 2024 15:57:01 +0200 Subject: [PATCH 6/8] dma-buf: heaps: system: Handle ECC flags Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-6-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2333; i=mripard@kernel.org; h=from:subject:message-id; bh=5mlKKVq2eJW/2EfLe5DfEKj2I4ZhUMzP6qbNsK6waI0=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+wMqyhNdctYvMNP72vKxoNKqpU9Xykhq7o8rXG6Tn j5n3OvTMZWFQZiTQVZMkeWJTNjp5e2LqxzsV/6AmcPKBDKEgYtTACai9oKxviBz/06PH5mvm05b 6tktPvglcFHO/COB24oK7X9dO274mbmNbaropF3il/T3vueOYvK4zlhnOz+6QcGIT+jg7wdWG/p ro9hjbR7cPlj0R+6uyrtsn7LCnum7/dcYenOmb/x/NPNHRxkA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Now that we have introduced ECC-related flags for the dma-heaps buffer allocations, let's honour these flags depending on the memory setup. Signed-off-by: Maxime Ripard --- drivers/dma-buf/heaps/system_heap.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 8b5e6344eea4..dd7c8b6f9cf6 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -18,13 +18,15 @@ #include #include #include #include #include +#include struct system_heap { struct dma_heap *heap; + bool ecc_enabled; }; struct system_heap_buffer { struct dma_heap *heap; struct list_head attachments; @@ -336,10 +338,11 @@ static struct page *alloc_largest_available(unsigned long size, static struct dma_buf *system_heap_allocate(struct dma_heap *heap, unsigned long len, unsigned long fd_flags, unsigned long heap_flags) { + struct system_heap *sys_heap = dma_heap_get_drvdata(heap); struct system_heap_buffer *buffer; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); unsigned long size_remaining = len; unsigned int max_order = orders[0]; struct dma_buf *dmabuf; @@ -347,10 +350,16 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, struct scatterlist *sg; struct list_head pages; struct page *page, *tmp_page; int i, ret = -ENOMEM; + if (!sys_heap->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_PROTECTED)) + return ERR_PTR(-EINVAL); + + if (sys_heap->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_UNPROTECTED)) + return ERR_PTR(-EINVAL); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&buffer->attachments); @@ -430,10 +439,13 @@ static int system_heap_create(void) sys_heap = kzalloc(sizeof(*sys_heap), GFP_KERNEL); if (!sys_heap) return -ENOMEM; + if (of_memory_get_ecc_correction_bits() > 0) + sys_heap->ecc_enabled = true; + exp_info.name = "system"; exp_info.ops = &system_heap_ops; exp_info.priv = sys_heap; sys_heap->heap = dma_heap_add(&exp_info); From patchwork Wed May 15 13:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665309 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 412391420CC; Wed, 15 May 2024 13:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781484; cv=none; b=JNgtkOrWUIfct9FYNcdTvm0KgVK4rFlrxZBZU4uH+iyrtwFL/bhwFQ0gkwDBcao9YNktFfg03P0gA/udab0nTGIyvKSK/6cJvCqapMFEGPcBD+EPvCa2q4hqaOYG12xZLOu/bJ2JozLsC+Y2enA8B61KhUBh4g6uCf368YwTQrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781484; c=relaxed/simple; bh=YUErc85/2hAb52W29W1xwDRHgxBJ9b98hEp6JztRUTU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BJmodLjlZDGDU05WESPQMIDcqQooInuUEiPzDCdGaOuMNXFSYeiGV+LEHnauMIMzEHDGxkWbXwFmpRk/lFyzgUZl+uT7gRS4coO+LQWtM+rdRQUa4JDUcCwK8maTGhEb9YATJ+dBn4FPjR+UsCPrEKdJs8v6eEuIDzrLgXacviY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YcvfAYs4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YcvfAYs4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A7AEC116B1; Wed, 15 May 2024 13:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781483; bh=YUErc85/2hAb52W29W1xwDRHgxBJ9b98hEp6JztRUTU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YcvfAYs4MQ/iPuLlDRw7jerxbsdvqmH1YeUKSESyTVc25nYwLnn998MVTf8yNGoPt CyPLk+6ErqwaAA51LtcDUbMLO6TFCHeN4Or/PCPvWSlwVVX2cTUoGxhQFra104sMzM /7xjmWYePVTITzjvZL/qnMttRS1kPOKZ2kIFAYA1Gigux2Mb4B/du15eP2gq81Yl56 ZK3cXYmhs1Evg2FaP+ud6/SgQ3wtav4CxWHQ7NakmSB6rriIF3A37c1e7X3fPkenBG 6l85/xnA0Gyc4AqpRauj3YgokQ6ZvDilnyQaA5Gnd+gdBT2SMHIyr8G96gShdeoWmg LCbVU0tNoLIWg== From: Maxime Ripard Date: Wed, 15 May 2024 15:57:02 +0200 Subject: [PATCH 7/8] dma-buf: heaps: cma: Handle ECC flags Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-7-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1665; i=mripard@kernel.org; h=from:subject:message-id; bh=YUErc85/2hAb52W29W1xwDRHgxBJ9b98hEp6JztRUTU=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+wN1TUXfl925deTd7NccCpoPdkYUelmaHTfbsyOfP 3CzlKhDx1QWBmFOBlkxRZYnMmGnl7cvrnKwX/kDZg4rE8gQBi5OAZjIj8+MtaI9fU+M9Ka2bpzl /X6HxNXHXQWLmC+06wTFNtyf2hLyfKKRZZLul5cJzAmVcU/ZLbfvYGz4pXzj6bz5vcs7rdg8QoM NN0cLCe15IqKW25RYvCJyztwXz7J31R3Q/H5bwcduyeWo93YA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Now that we have introduced ECC-related flags for the dma-heaps buffer allocations, let's honour these flags depending on the memory setup. Signed-off-by: Maxime Ripard --- drivers/dma-buf/heaps/cma_heap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 4a63567e93ba..1e6babbd8eb5 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -24,10 +24,11 @@ struct cma_heap { struct dma_heap *heap; struct cma *cma; + bool ecc_enabled; }; struct cma_heap_buffer { struct cma_heap *heap; struct list_head attachments; @@ -286,10 +287,16 @@ static struct dma_buf *cma_heap_allocate(struct dma_heap *heap, struct page *cma_pages; struct dma_buf *dmabuf; int ret = -ENOMEM; pgoff_t pg; + if (!cma_heap->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_PROTECTED)) + return -EINVAL; + + if (cma_heap->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_UNPROTECTED)) + return -EINVAL; + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&buffer->attachments); @@ -374,10 +381,13 @@ static int __add_cma_heap(struct cma *cma, void *data) cma_heap = kzalloc(sizeof(*cma_heap), GFP_KERNEL); if (!cma_heap) return -ENOMEM; cma_heap->cma = cma; + if (of_memory_get_ecc_correction_bits() > 0) + cma_heap->ecc_enabled = true; + exp_info.name = cma_get_name(cma); exp_info.ops = &cma_heap_ops; exp_info.priv = cma_heap; cma_heap->heap = dma_heap_add(&exp_info); From patchwork Wed May 15 13:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13665310 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EE6C1420CC; Wed, 15 May 2024 13:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781487; cv=none; b=HQVnhEuWKx0IpOtHQC8Djt4NBwxrmJ3bSVwVpZh5+zsX85FNdkv+oj8fOkkexdr9vMic1qCOSQa91EB7yDNfKku9ZfPqGsBWzSFMByfVQ33qypD82WPi31EG4ze/ssqs90AGn8H6JJAgf5/JDxrO/LHBE4342TIxx11D1REyaTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781487; c=relaxed/simple; bh=N5UwfZ1hKMI6+ZrGSh9smBi+SvvW9VpZtds2AMuGHos=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o8D51Wh/k2IJB0Y8ddDaI5l3C1gp2twFCqztAG+1lvm6GtrOp/o3qgZBx4ppqyh4BhqGfHSnHJ+aI/wNlc5eexL37L3MTXRNJya6tXKGiNd22AYt3eqGMlM7jSIdeJb8UrkIfdJizYNT8PvTsw/OaSZ1Cbk3vlcSMpiBGHtydnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TwfJbMJr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TwfJbMJr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE3B1C2BD11; Wed, 15 May 2024 13:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781487; bh=N5UwfZ1hKMI6+ZrGSh9smBi+SvvW9VpZtds2AMuGHos=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TwfJbMJr2eudO50gB4jtqCfWmhQ4amIjE1zaF6WRdIcpHwO5rxvJbZJuVPBjUSigc 8TO0sFjBMWieujTeWTcuXI80s/WdCooRLCshP+Q/b0ITdjgasFFSNbNxExZovj+gwM MqxQyWjQ9L4GKUH5za52rqgOSxbjtXji1bS6WDBU09KLKF6xXnGxBua7W8KBwKwYTv kTyJG45a37w38lAwA6FHp1phbWKUmqeti4YPxDNtGMpGRIPOYhZd/GFlbyoIEyxavY r47jnKx51PjUmobjfH+JRFKkFOOn0ocJkOqbql9gO5OBozz9g9Hmqn6m9vT+dk6kVi oqdf60asXfERQ== From: Maxime Ripard Date: Wed, 15 May 2024 15:57:03 +0200 Subject: [PATCH 8/8] dma-buf: heaps: carveout: Handle ECC flags Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240515-dma-buf-ecc-heap-v1-8-54cbbd049511@kernel.org> References: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> In-Reply-To: <20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org> To: Rob Herring , Saravana Kannan , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Mattijs Korpershoek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Maxime Ripard X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2094; i=mripard@kernel.org; h=from:subject:message-id; bh=N5UwfZ1hKMI6+ZrGSh9smBi+SvvW9VpZtds2AMuGHos=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGku+wOVf9vPYLP0PMqdtrWoJ7LZR7Lp+cNXh60Z5vbwa D3c2HqlYyoLgzAng6yYIssTmbDTy9sXVznYr/wBM4eVCWQIAxenAExkbh5jnYYCo0VUtc+Dd+uE 2daUX+142sf9ZzNr7g5joTNPPvPvWLjxoFSLysFas91tCT8vZjzoYaxmSWWJajqzSnUrN69XyMV 0Lukrn8/LlLqZ6FROnnTgt2SU9adC6ZaXZtJ3NbLWr572kQ0A X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Now that we have introduced ECC-related flags for the dma-heaps buffer allocations, let's honour these flags depending on the memory setup. Signed-off-by: Maxime Ripard --- drivers/dma-buf/heaps/carveout_heap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/dma-buf/heaps/carveout_heap.c b/drivers/dma-buf/heaps/carveout_heap.c index 896ca67e6bd9..81b167785999 100644 --- a/drivers/dma-buf/heaps/carveout_heap.c +++ b/drivers/dma-buf/heaps/carveout_heap.c @@ -6,10 +6,11 @@ #include struct carveout_heap_priv { struct dma_heap *heap; struct gen_pool *pool; + bool ecc_enabled; }; struct carveout_heap_buffer_priv { struct mutex lock; struct list_head attachments; @@ -182,10 +183,16 @@ static struct dma_buf *carveout_heap_allocate(struct dma_heap *heap, struct dma_buf *buf; dma_addr_t daddr; void *buffer; int ret; + if (!heap_priv->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_PROTECTED)) + return ERR_PTR(-EINVAL); + + if (heap_priv->ecc_enabled && (heap_flags & DMA_HEAP_FLAG_ECC_UNPROTECTED)) + return ERR_PTR(-EINVAL); + buffer_priv = kzalloc(sizeof(*buffer_priv), GFP_KERNEL); if (!buffer_priv) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&buffer_priv->attachments); @@ -235,20 +242,29 @@ static int __init carveout_heap_setup(struct device_node *node) const struct reserved_mem *rmem; struct carveout_heap_priv *priv; struct dma_heap *heap; struct gen_pool *pool; void *base; + u32 val = 0; int ret; rmem = of_reserved_mem_lookup(node); if (!rmem) return -EINVAL; priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; + of_property_read_u32(node, "ecc-correction-bits", &val); + if (val <= 0) { + if (of_memory_get_ecc_correction_bits() > 0) + priv->ecc_enabled = true; + } else { + priv->ecc_enabled = true; + } + pool = gen_pool_create(PAGE_SHIFT, NUMA_NO_NODE); if (!pool) { ret = -ENOMEM; goto err_cleanup_heap; }