Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2636842rdh; Wed, 27 Sep 2023 08:20:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxTdzAm6gWf3aVrOxWkMLBidRYyKZ5aRXaEClnv857QykcbGU4Fn6rQOCk9GiYCICWzZLS X-Received: by 2002:a05:6a00:1817:b0:68f:cb69:8e66 with SMTP id y23-20020a056a00181700b0068fcb698e66mr4039967pfa.15.1695828035227; Wed, 27 Sep 2023 08:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695828035; cv=none; d=google.com; s=arc-20160816; b=JTSDmrq0DvE9a7rcFfGb0Rxj+YlfQq2GVTvdriEqsX7V1U+2MtVW50z4MmLXN3GFGq qiCip8Gb3w4jbP3M1ni4zSGzn/8Jc9GLbRlXdMowfAd2I/G2nlegvm0kFIHIjJlXTZZN 2AE75DsgYUcteXXCR5O9tFsd42IvPAljDAY9KE7cIpTztbiL1JHTSx0YzWrDCrCxq6B0 g4DiAtAYu0KCC6u37bHFYcQStH5YIPzH1mmQjlaMaooVBWug/YCfX40GE7eDi4udcoF3 t6wfAnPmGzfiqs9ASbHveVshiqNCBodf4Pb61aE+Un32zXl7wUSTpFVX27i8Rs7oKRA/ sF+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DQa0uS9ZxVzUEvSIaoDnSyYxM+uNjYjcw68CuBARJN8=; fh=RS9Hi79KnH0Naasn8huAzCtItHxJOV97nFcCVb6vwuw=; b=kP+tGHluSyVzRkOOIfX/2f/AIgeBAR4z9d/LsblsLYKiGrp6ERaZ5Wh4GLUAXA9bIe 7CNgAXbi9j3HniA1yfgFTRALRdB3FL6qls10zli6OmmPlXHmB1LU0Dy3zmvgE86umNrA wu8Y26Fik26uPKf8R337l+fDZSYt+fCJUd0vYqRyUHBxc/lPCp4XbaJxKjpoCh+2ltBT yDdJtvxHcEuZYZmulRyV88WSaQOC3R80gdEZd/494amuwCR8a1GCNUheuB4DvCDiK5h6 gOFIFT8zPju/5wj7remhiMsF28iuyVIXXbYdA/MzTrE3foAJky57xyTo9JQA8JgJ/o4c KWFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zP6Ci+AS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s66-20020a632c45000000b0058556a636dbsi1648823pgs.434.2023.09.27.08.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zP6Ci+AS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CDE5E8065E10; Wed, 27 Sep 2023 07:43:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232228AbjI0Omf (ORCPT + 99 others); Wed, 27 Sep 2023 10:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232214AbjI0Omc (ORCPT ); Wed, 27 Sep 2023 10:42:32 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99582F9 for ; Wed, 27 Sep 2023 07:42:30 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso1446104466b.2 for ; Wed, 27 Sep 2023 07:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695825749; x=1696430549; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=DQa0uS9ZxVzUEvSIaoDnSyYxM+uNjYjcw68CuBARJN8=; b=zP6Ci+AS0YD9HOVXRL0t943eT6TcafVJ64evKwFlzwPDJHaburIJTQBFBgQgQj5SUO FpEvO1rpAgxIawVFLhITNS8N3NAlNWAlPWe9CHotKdF0qKXonICKaqeIFQ9EOjjLC8Gz nVaWDgr7VYdgpAl2v+awvrnGu/b+60UzHQECVJ2V27D0BR30u2k4vDu745CLYJ3u3cvJ 5+Q0Kq7DJzNLesg44T6rabOJ8idrWox6+pmIY6Qof56yTAgIrZj2mHHcbvQeYyi2Gthj xcTPjlz/JGt+k/EemsBBM+aHGfuKxzv3gm8dJLGmj2soDxGqOsdSE3mTszDxAQSkioXL uL7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695825749; x=1696430549; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=DQa0uS9ZxVzUEvSIaoDnSyYxM+uNjYjcw68CuBARJN8=; b=vFzbV/d74nN6quqIk0/GepbXR59sKd4LAKnbeARB1Fn+leHDqKGTiBgzbyH5Bjsb6P hQMzHO7mb6Gm3llLWCXN05+nbZmzaEnJIp9PEvL3o7hz91/761ihCKiHtRriPWQcTu5q Ja7t8yQqxmrhfEs893Mt85OfqbxItHoMltyP3j5mH/q1XeaLEmdgAvuZoMH0qWHfDycA ebntoFnIFCSI7VlzFiNTmdHT1Dxo+6PkPUECLIvBd+x6vCmepylEYHXn39DDkOL8rAMW RNbIcP3RUyDpjIHK+1eJg3+U8DBagHeD9UzHr7pwYIpVyQkObr46zhpXIEYteZ4m++x+ L2mA== X-Gm-Message-State: AOJu0YwDwiX2v/8rpwJc3K4SBQLakGr+tsPKze4T9YcYSLm4gC60AYTm rlk1vdMC/7j2i8XYd4ZsfSMvIw== X-Received: by 2002:a17:906:5142:b0:9b2:ba65:db21 with SMTP id jr2-20020a170906514200b009b2ba65db21mr368111ejc.45.1695825749077; Wed, 27 Sep 2023 07:42:29 -0700 (PDT) Received: from pop-os.localdomain (81-231-61-187-no276.tbcn.telia.com. [81.231.61.187]) by smtp.gmail.com with ESMTPSA id z15-20020a170906944f00b00993928e4d1bsm9374996ejx.24.2023.09.27.07.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:42:28 -0700 (PDT) Date: Wed, 27 Sep 2023 16:42:26 +0200 From: Joakim Bech To: Yong Wu Cc: Rob Herring , Sumit Semwal , christian.koenig@amd.com, Matthias Brugger , Krzysztof Kozlowski , Conor Dooley , Benjamin Gaignard , Brian Starkey , John Stultz , tjmercier@google.com, AngeloGioacchino Del Regno , 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, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, jianjiao.zeng@mediatek.com, kuohong.wang@mediatek.com Subject: Re: [PATCH 4/9] dma-buf: heaps: Initialise MediaTek secure heap Message-ID: <20230927144226.pdssel3dwv53g546@pop-os.localdomain> References: <20230911023038.30649-1-yong.wu@mediatek.com> <20230911023038.30649-5-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230911023038.30649-5-yong.wu@mediatek.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 07:43:01 -0700 (PDT) On Mon, Sep 11, 2023 at 10:30:33AM +0800, Yong Wu wrote: > Initialise a mtk_svp heap. Currently just add a null heap, Prepare for > the later patches. > > Signed-off-by: Yong Wu > --- > drivers/dma-buf/heaps/Kconfig | 8 ++ > drivers/dma-buf/heaps/Makefile | 1 + > drivers/dma-buf/heaps/mtk_secure_heap.c | 99 +++++++++++++++++++++++++ > 3 files changed, 108 insertions(+) > create mode 100644 drivers/dma-buf/heaps/mtk_secure_heap.c > > diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig > index a5eef06c4226..729c0cf3eb7c 100644 > --- a/drivers/dma-buf/heaps/Kconfig > +++ b/drivers/dma-buf/heaps/Kconfig > @@ -12,3 +12,11 @@ config DMABUF_HEAPS_CMA > Choose this option to enable dma-buf CMA heap. This heap is backed > by the Contiguous Memory Allocator (CMA). If your system has these > regions, you should say Y here. > + > +config DMABUF_HEAPS_MTK_SECURE > + bool "DMA-BUF MediaTek Secure Heap" > + depends on DMABUF_HEAPS && TEE > + help > + Choose this option to enable dma-buf MediaTek secure heap for Secure > + Video Path. This heap is backed by TEE client interfaces. If in Although this is intended for SVP right now, this is something that very well could work for other use cases. So, I think I'd not mention "Secure Video Path" and just mention "secure heap". > + doubt, say N. > diff --git a/drivers/dma-buf/heaps/Makefile b/drivers/dma-buf/heaps/Makefile > index 974467791032..df559dbe33fe 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_SYSTEM) += system_heap.o > obj-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o > +obj-$(CONFIG_DMABUF_HEAPS_MTK_SECURE) += mtk_secure_heap.o > diff --git a/drivers/dma-buf/heaps/mtk_secure_heap.c b/drivers/dma-buf/heaps/mtk_secure_heap.c > new file mode 100644 > index 000000000000..bbf1c8dce23e > --- /dev/null > +++ b/drivers/dma-buf/heaps/mtk_secure_heap.c > @@ -0,0 +1,99 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * DMABUF mtk_secure_heap exporter > + * > + * Copyright (C) 2023 MediaTek Inc. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +/* > + * MediaTek secure (chunk) memory type > + * > + * @KREE_MEM_SEC_CM_TZ: static chunk memory carved out for trustzone. nit: s/trustzone/TrustZone/ -- // Regards Joakim > + */ > +enum kree_mem_type { > + KREE_MEM_SEC_CM_TZ = 1, > +}; > + > +struct mtk_secure_heap_buffer { > + struct dma_heap *heap; > + size_t size; > +}; > + > +struct mtk_secure_heap { > + const char *name; > + const enum kree_mem_type mem_type; > +}; > + > +static struct dma_buf * > +mtk_sec_heap_allocate(struct dma_heap *heap, size_t size, > + unsigned long fd_flags, unsigned long heap_flags) > +{ > + struct mtk_secure_heap_buffer *sec_buf; > + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); > + struct dma_buf *dmabuf; > + int ret; > + > + sec_buf = kzalloc(sizeof(*sec_buf), GFP_KERNEL); > + if (!sec_buf) > + return ERR_PTR(-ENOMEM); > + > + sec_buf->size = size; > + sec_buf->heap = heap; > + > + exp_info.exp_name = dma_heap_get_name(heap); > + exp_info.size = sec_buf->size; > + exp_info.flags = fd_flags; > + exp_info.priv = sec_buf; > + > + dmabuf = dma_buf_export(&exp_info); > + if (IS_ERR(dmabuf)) { > + ret = PTR_ERR(dmabuf); > + goto err_free_buf; > + } > + > + return dmabuf; > + > +err_free_buf: > + kfree(sec_buf); > + return ERR_PTR(ret); > +} > + > +static const struct dma_heap_ops mtk_sec_heap_ops = { > + .allocate = mtk_sec_heap_allocate, > +}; > + > +static struct mtk_secure_heap mtk_sec_heap[] = { > + { > + .name = "mtk_svp", > + .mem_type = KREE_MEM_SEC_CM_TZ, > + }, > +}; > + > +static int mtk_sec_heap_init(void) > +{ > + struct mtk_secure_heap *sec_heap = mtk_sec_heap; > + struct dma_heap_export_info exp_info; > + struct dma_heap *heap; > + unsigned int i; > + > + for (i = 0; i < ARRAY_SIZE(mtk_sec_heap); i++, sec_heap++) { > + exp_info.name = sec_heap->name; > + exp_info.ops = &mtk_sec_heap_ops; > + exp_info.priv = (void *)sec_heap; > + > + heap = dma_heap_add(&exp_info); > + if (IS_ERR(heap)) > + return PTR_ERR(heap); > + } > + return 0; > +} > + > +module_init(mtk_sec_heap_init); > +MODULE_DESCRIPTION("MediaTek Secure Heap Driver"); > +MODULE_LICENSE("GPL"); > -- > 2.25.1 >