Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3412339rdh; Thu, 28 Sep 2023 10:47:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgIgtUA7VYQaYx82ZTEPmoIY7CcW7h5FXsEjD5N52LH4BDoMmz8UJOTxPfGnfjAqzC8VZ+ X-Received: by 2002:a17:90b:3010:b0:277:3565:30cf with SMTP id hg16-20020a17090b301000b00277356530cfmr3095058pjb.6.1695923245641; Thu, 28 Sep 2023 10:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695923245; cv=none; d=google.com; s=arc-20160816; b=NfZI/Wvu23AdGRNh0v2PtoVOyawM8Ky8A+B0YItCYgYSfThqUrlEa3OgKyAesy9l6I 2CHYcu7cUy8Zk1D7KCGTNMm4OMcw9YHrebqW77gK/u8V5VOokTANIHYPCkks1tAkwZOB KTEcdDnTVcd3v1iBa38fLUBx3s/Y/STRz/18b+FbkKPlfpHgA/Aka7pzS7epKPUDCPHM ElMOs29RhwnPsUI2z030fjPtbTa/zDZ8HEKyfmDdRPDeGAHhrXxn1Ws4Qc/BRC6dS0iB 723El1jFiHefqF1ENkr+n6AbWdvkQQMYG9WshAbRWBIGcJRI7aOU/jazLifzQQ7Yulvw AX+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bwhz75YMPOq4qEC9+ip9OVp9daQY2HSr3vN/IaeFnqw=; fh=qciho/xsTxNUsKJZ3hehiaQZTIzl+I3IMsnaV40iMRE=; b=dcUhe13aCQP3SgWsOiLWBVrZBL39AY8p+pqZB1EpFa9jgG7NMhMJtNGOGydCBEKuPF 7fjHK5Srbtv+OG/bwwk+ycHwB0DD2owGflEcWDfH5T7babe05uabd1PspQeKzhr92+a1 VMu/z/aEJgJgL46bSEXvCLV3kkbgALSJiGES5uLCxa21gTJy9b1e6v0LZZ7GrgTIdLCl hIPdhkIIi2T3qglKX+SIb0kuOlezOMKXYhBq0TGmihR7oZ4woR6E+q8G4YIlcxIhkMwg 6/NothnyT3ytAzxMjDSObGqKQOE9zCtHdSm2NxQxLtYeN+ivOfx1KaKDTpJNjTBTZhmD drGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=ZdFDth24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b005855f67e490si4557961pgp.690.2023.09.28.10.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 10:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=ZdFDth24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 00F3C817C1C7; Thu, 28 Sep 2023 02:22:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbjI1JVy (ORCPT + 99 others); Thu, 28 Sep 2023 05:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231652AbjI1JVU (ORCPT ); Thu, 28 Sep 2023 05:21:20 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2530194 for ; Thu, 28 Sep 2023 02:21:12 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-32003aae100so9290847f8f.0 for ; Thu, 28 Sep 2023 02:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892871; x=1696497671; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bwhz75YMPOq4qEC9+ip9OVp9daQY2HSr3vN/IaeFnqw=; b=ZdFDth24YL6VP5Sf68aAW8r37uMQJFqqSeWLlHNT60ZZwMRLJLmztpN2sC5ES1hr22 YLrnccYBdJoTe/3xD4rLP4gK9jYfIQwhSDPkcTsEz42Fsf/mA9zxww0I99nHpu9ibuGX gmVaEC8Qze5sMMlGLvWeUx7l7CGW914AZaNpoqhsTDtMbJ1ueW8WQco9+IO3xpoxEM+Q CGiwaZCzSPUR4curXfdiGNWm79c0MfqFEVfTrwzlmXErt6rBk4dxW3dO2d41B/VOQ7Hj T7/uLsj9JHSV/LlZjGlKZklaBqtNUptZV7v7IgN48pSlW9qmtgmyB7xHOuY7hF86xNNY 9QYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892871; x=1696497671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bwhz75YMPOq4qEC9+ip9OVp9daQY2HSr3vN/IaeFnqw=; b=M8NPUdPtsR2hpScfZaMcL9ZR1AiBEPIMv150m/Y+xumN7dSRdBoK1PgZbBn0LYlldJ fGQnvPnCvSRJoxW8to5u6wnuAd6vcgfgmz7IOWz95HTqxd++eox4g3S48ts4nuQcbbSH fdgNGBxBhvVOWcGVtL9l0mwmmcCZuLgQEoGHAy4rnhl4N1Xt1KZ5LlXbcy5ca32af4dq EmewuwgJKeGfHTEwOQ0rij5xfom/62pf3ZdwEWYKfhXJKanIZdcFc6zh0EEy7zuZwBgM 9+BkCuORaPLgB/Z0FAEaofFnJKX1Uv8xgnA1y9SB4Zv7JymO+vY5u5/wc1987KUVzvfq kE3A== X-Gm-Message-State: AOJu0YytPUajvGCduchwc/vtXce99oVi+p/S50pF0V0agoixIaCTKlnr ZzOqgqL3RMxcg63lbDTTlPyyuQ== X-Received: by 2002:a5d:574f:0:b0:319:6997:9432 with SMTP id q15-20020a5d574f000000b0031969979432mr783332wrw.1.1695892871336; Thu, 28 Sep 2023 02:21:11 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:10 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 11/11] firmware: qcom: scm: enable SHM bridge Date: Thu, 28 Sep 2023 11:20:40 +0200 Message-Id: <20230928092040.9420-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 28 Sep 2023 02:22:27 -0700 (PDT) From: Bartosz Golaszewski Extens the SCM memory allocator with using the SHM Bridge feature if available on the platform. This makes the trustzone only use dedicated buffers for SCM calls. We map the entire SCM genpool as a bridge. Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm-mem.c | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-mem.c b/drivers/firmware/qcom/qcom_scm-mem.c index eafecbe23770..12b12b15f46f 100644 --- a/drivers/firmware/qcom/qcom_scm-mem.c +++ b/drivers/firmware/qcom/qcom_scm-mem.c @@ -16,6 +16,8 @@ #include "qcom_scm.h" +#define QCOM_SHM_BRIDGE_NUM_VM_SHIFT 9 + static size_t qcom_scm_mem_pool_size = SZ_2M; module_param_named(qcom_scm_mem_pool_size, qcom_scm_mem_pool_size, ulong, 0400); @@ -108,8 +110,24 @@ phys_addr_t qcom_scm_mem_to_phys(void *vaddr) return chunk->paddr; } +static int qcom_scm_mem_shm_bridge_create(void) +{ + uint64_t pfn_and_ns_perm, ipfn_and_s_perm, size_and_flags, ns_perms; + + ns_perms = (QCOM_SCM_PERM_WRITE | QCOM_SCM_PERM_READ); + pfn_and_ns_perm = (u64)qcom_scm_mem.pbase | ns_perms; + ipfn_and_s_perm = (u64)qcom_scm_mem.pbase | ns_perms; + size_and_flags = qcom_scm_mem.size | (1 << QCOM_SHM_BRIDGE_NUM_VM_SHIFT); + + return qcom_scm_create_shm_bridge(qcom_scm_mem.dev, pfn_and_ns_perm, + ipfn_and_s_perm, size_and_flags, + QCOM_SCM_VMID_HLOS); +} + int qcom_scm_mem_enable(struct device *dev) { + int ret; + INIT_RADIX_TREE(&qcom_scm_mem.chunks, GFP_ATOMIC); spin_lock_init(&qcom_scm_mem.lock); qcom_scm_mem.dev = dev; @@ -128,7 +146,25 @@ int qcom_scm_mem_enable(struct device *dev) gen_pool_set_algo(qcom_scm_mem.pool, gen_pool_best_fit, NULL); - return gen_pool_add_virt(qcom_scm_mem.pool, - (unsigned long)qcom_scm_mem.vbase, - qcom_scm_mem.pbase, qcom_scm_mem.size, -1); + ret = gen_pool_add_virt(qcom_scm_mem.pool, + (unsigned long)qcom_scm_mem.vbase, + qcom_scm_mem.pbase, qcom_scm_mem.size, -1); + if (ret) + return ret; + + ret = qcom_scm_enable_shm_bridge(); + if (ret) { + if (ret == EOPNOTSUPP) + dev_info(dev, "SHM Bridge not supported\n"); + else + return ret; + } else { + ret = qcom_scm_mem_shm_bridge_create(); + if (ret) + return ret; + + dev_info(dev, "SHM Bridge enabled\n"); + } + + return 0; } -- 2.39.2