From patchwork Mon Mar 25 10:03:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13601742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28962CD11DD for ; Mon, 25 Mar 2024 10:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xzmVwkis+hzexPTtLlsLYS3gopkXr5NtWHIpduXYnfE=; b=AUBQOW6/pBgI4s 5AerQkGzaqcteRseLn1nGNRF0GmYquAiIYDibLK4YHPduh2OzRGvOOOPhNFN3jwruzwIQSSot0OOv aE5Va1m7OKMzxCwT7Dtwc3Rc5SmLITRjZ/xuJl4miNkEpxbdHL9bUpC0jBnL8eC6jZU+Y2V+9gFed 1DHCB5DRZCoecyXQr6VWV7wH+VuBS8kmyu61+Noa5RYUW79ANROp2zn3SLVONQ2u8d1Ps1r+CwRIS f+BLmbZrENt86G8iPDN7x1bsYtUNXL6VUIMjZGv9MVFtS5RgvSnA87GiQMZks9ypOj2a7pK00pTwT B6O+HMWR6GtDwvg4fIuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohD0-0000000GdHf-020j; Mon, 25 Mar 2024 10:05:38 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBi-0000000GcTR-2aJ8 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 10:04:25 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-341c7c8adf3so969760f8f.0 for ; Mon, 25 Mar 2024 03:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711361056; x=1711965856; darn=lists.infradead.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=ozfFeJyXaUD6FQQEli0mm3wcSChIOoojk249rH7ELtY=; b=VnahmbiJeIm8M8nLMUgtJuyloxx8pgNYcZQ2lW0hie2ublDsZMH16B9H1XCJipyj4u q8Nb5tSt6RX8z6oo+MlPBcnrFyyEFQXEcaBSEri7vdpYkTK782D6tGK7WewfAoP3hY8q wY0t5l0SeYZ0IxME8v0othxTGfRMeYT2W+HLsPVBevulc7NZtZ2q6uKEIvNmm2m4puPW h7crNop5n3Kx8pajO9QbQM77gGNCb8sZFoHu75NL4jNIBc9OC570SnS6pWT7uDfGsjyP qnTolbV6LDcqWxEYFwRUp6XIjNCajCJXaRKizPZ2WAmDQ8nP503EMpoOwh8hekRWb5UP YiiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711361056; x=1711965856; 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=ozfFeJyXaUD6FQQEli0mm3wcSChIOoojk249rH7ELtY=; b=uWdQAEpyfPxcRay3NREDrtimFaFHPaZm45ccfNJTuj2M8VfkgAfRp4jUAioaadDDBp 48lup87gZhYxA5dscGHdtQyIKWq+IQ4pnc3roQDi56dG/zbPRcGIwA2Vv63HWBb0pbIT VmbXSZKQkPKyNyl3LsucEIXv1r2lAkCDsY5iluSImhSqNE85kTxwvoQdAQghBXvqN9Vl 5pvX53t3CVa0+wF1dsEfEDS1Dx1OyUsa0txbAOGYOa/kCzkVRG+76g5ATiOkeMVo5LzS P8S7GJOPiyOhgjHV+4LbY87ALcf5LpVJYekeQopOZt3AjcZzrpZVDzOXbvU+F2cyC+ov idMA== X-Forwarded-Encrypted: i=1; AJvYcCUY+fm5rZIS5IWfa97nAmAk++8VLTCDoFHgPH+peBfaPCDLlzh3T+8SOipcEhiOm4s1cN9jUPVRlWmAew2UemmaLRo7jGTd8Rm5gwWuhI9tb3OnA14= X-Gm-Message-State: AOJu0Ywha7uoM/mqxhEFX61/KmyMP9iVrTaymyiPnucL/7NI5iUBfR25 SEu7aPmTvs9+1aYu7vQrT/gFkagGxBxw7LKbEaZNbl4EXpUfiq9juCdswvcpjXVXVbH5QKbL9+b U X-Google-Smtp-Source: AGHT+IG5oeeUmNjJm+e6PyXNNlgVwD4/ExZy6L7LCkX9nZWS0361na1GOzWnhUYhyhO9dtvSAa29gA== X-Received: by 2002:adf:edd2:0:b0:33e:720e:4a4e with SMTP id v18-20020adfedd2000000b0033e720e4a4emr4442835wro.19.1711361055954; Mon, 25 Mar 2024 03:04:15 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:75a:e000:861d:8b72:a859:4ce9]) by smtp.gmail.com with ESMTPSA id dv13-20020a0560000d8d00b0033e25c39ac3sm9086874wrb.80.2024.03.25.03.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:04:14 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v9 09/13] firmware: qcom: qseecom: convert to using the TZ allocator Date: Mon, 25 Mar 2024 11:03:55 +0100 Message-Id: <20240325100359.17001-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240325100359.17001-1-brgl@bgdev.pl> References: <20240325100359.17001-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_030418_834472_3670CEF4 X-CRM114-Status: GOOD ( 21.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Drop the DMA mapping operations from qcom_scm_qseecom_app_send() and convert all users of it in the qseecom module to using the TZ allocator for creating SCM call buffers. As this is largely a module separate from the SCM driver, let's use a separate memory pool. Set the initial size to 4K and - if we run out - add twice the current amount to the pool. Signed-off-by: Bartosz Golaszewski --- .../firmware/qcom/qcom_qseecom_uefisecapp.c | 47 ++++++++++++------- drivers/firmware/qcom/qcom_scm.c | 30 +++--------- include/linux/firmware/qcom/qcom_qseecom.h | 4 +- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c index 1f8c5efc2b5a..0bb13c8225c2 100644 --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c @@ -14,11 +14,14 @@ #include #include #include +#include #include #include #include #include +#include +#include /* -- Qualcomm "uefisecapp" interface definitions. -------------------------- */ @@ -254,6 +257,7 @@ struct qsee_rsp_uefi_query_variable_info { struct qcuefi_client { struct qseecom_client *client; struct efivars efivars; + struct qcom_tzmem_pool *mempool; }; static struct device *qcuefi_dev(struct qcuefi_client *qcuefi) @@ -273,8 +277,8 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e const efi_guid_t *guid, u32 *attributes, unsigned long *data_size, void *data) { - struct qsee_req_uefi_get_variable *req_data __free(kfree) = NULL; - struct qsee_rsp_uefi_get_variable *rsp_data __free(kfree) = NULL; + struct qsee_req_uefi_get_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_get_variable *rsp_data __free(qcom_tzmem) = NULL; unsigned long buffer_size = *data_size; unsigned long name_length; efi_status_t efi_status; @@ -305,11 +309,11 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e __array(u8, buffer_size) ); - req_data = kzalloc(req_size, GFP_KERNEL); + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); if (!req_data) return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, rsp_size, GFP_KERNEL); if (!rsp_data) return EFI_OUT_OF_RESOURCES; @@ -394,8 +398,8 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e const efi_guid_t *guid, u32 attributes, unsigned long data_size, const void *data) { - struct qsee_req_uefi_set_variable *req_data __free(kfree) = NULL; - struct qsee_rsp_uefi_set_variable *rsp_data __free(kfree) = NULL; + struct qsee_req_uefi_set_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_set_variable *rsp_data __free(qcom_tzmem) = NULL; unsigned long name_length; size_t name_offs; size_t guid_offs; @@ -425,11 +429,11 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e __array_offs(u8, data_size, &data_offs) ); - req_data = kzalloc(req_size, GFP_KERNEL); + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); if (!req_data) return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*rsp_data), GFP_KERNEL); if (!rsp_data) return EFI_OUT_OF_RESOURCES; @@ -476,8 +480,8 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, unsigned long *name_size, efi_char16_t *name, efi_guid_t *guid) { - struct qsee_req_uefi_get_next_variable *req_data __free(kfree) = NULL; - struct qsee_rsp_uefi_get_next_variable *rsp_data __free(kfree) = NULL; + struct qsee_req_uefi_get_next_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_get_next_variable *rsp_data __free(qcom_tzmem) = NULL; efi_status_t efi_status; size_t guid_offs; size_t name_offs; @@ -503,11 +507,11 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, __array(*name, *name_size / sizeof(*name)) ); - req_data = kzalloc(req_size, GFP_KERNEL); + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); if (!req_data) return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, rsp_size, GFP_KERNEL); if (!rsp_data) return EFI_OUT_OF_RESOURCES; @@ -587,15 +591,15 @@ static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, u64 *storage_space, u64 *remaining_space, u64 *max_variable_size) { - struct qsee_req_uefi_query_variable_info *req_data __free(kfree) = NULL; - struct qsee_rsp_uefi_query_variable_info *rsp_data __free(kfree) = NULL; + struct qsee_req_uefi_query_variable_info *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_query_variable_info *rsp_data __free(qcom_tzmem) = NULL; int status; - req_data = kzalloc(sizeof(*req_data), GFP_KERNEL); + req_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*req_data), GFP_KERNEL); if (!req_data) return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*rsp_data), GFP_KERNEL); if (!rsp_data) return EFI_OUT_OF_RESOURCES; @@ -740,6 +744,7 @@ static const struct efivar_operations qcom_efivar_ops = { static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *aux_dev_id) { + struct qcom_tzmem_pool_config pool_config; struct qcuefi_client *qcuefi; int status; @@ -758,6 +763,16 @@ static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev, if (status) qcuefi_set_reference(NULL); + memset(&pool_config, 0, sizeof(pool_config)); + pool_config.initial_size = SZ_4K; + pool_config.policy = QCOM_TZMEM_POLICY_MULTIPLIER; + pool_config.increment = 2; + pool_config.max_size = SZ_256K; + + qcuefi->mempool = devm_qcom_tzmem_pool_new(&aux_dev->dev, &pool_config); + if (IS_ERR(qcuefi->mempool)) + return PTR_ERR(qcuefi->mempool); + return status; } diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index d9b189632e61..f871af4af829 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1570,9 +1570,9 @@ EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_get_id); /** * qcom_scm_qseecom_app_send() - Send to and receive data from a given QSEE app. * @app_id: The ID of the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be TZ memory) * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be TZ memory) * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given ID and read back @@ -1588,26 +1588,12 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, { struct qcom_scm_qseecom_resp res = {}; struct qcom_scm_desc desc = {}; - dma_addr_t req_phys; - dma_addr_t rsp_phys; + phys_addr_t req_phys; + phys_addr_t rsp_phys; int status; - /* Map request buffer */ - req_phys = dma_map_single(__scm->dev, req, req_size, DMA_TO_DEVICE); - status = dma_mapping_error(__scm->dev, req_phys); - if (status) { - dev_err(__scm->dev, "qseecom: failed to map request buffer\n"); - return status; - } - - /* Map response buffer */ - rsp_phys = dma_map_single(__scm->dev, rsp, rsp_size, DMA_FROM_DEVICE); - status = dma_mapping_error(__scm->dev, rsp_phys); - if (status) { - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - dev_err(__scm->dev, "qseecom: failed to map response buffer\n"); - return status; - } + req_phys = qcom_tzmem_to_phys(req); + rsp_phys = qcom_tzmem_to_phys(rsp); /* Set up SCM call data */ desc.owner = QSEECOM_TZ_OWNER_TZ_APPS; @@ -1625,10 +1611,6 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, /* Perform call */ status = qcom_scm_qseecom_call(&desc, &res); - /* Unmap buffers */ - dma_unmap_single(__scm->dev, rsp_phys, rsp_size, DMA_FROM_DEVICE); - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - if (status) return status; diff --git a/include/linux/firmware/qcom/qcom_qseecom.h b/include/linux/firmware/qcom/qcom_qseecom.h index 5c28298a98be..e868fac55675 100644 --- a/include/linux/firmware/qcom/qcom_qseecom.h +++ b/include/linux/firmware/qcom/qcom_qseecom.h @@ -27,9 +27,9 @@ struct qseecom_client { /** * qcom_qseecom_app_send() - Send to and receive data from a given QSEE app. * @client: The QSEECOM client associated with the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be TZ memory). * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be TZ memory). * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given client and read