From patchwork Wed Jun 14 16:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 108060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp105948vqr; Wed, 14 Jun 2023 10:15:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kM7GGC/GSCr1XPGl6+6HLdRfy1fD66s92l3CIOjpm89FWFgaaqU3id+ykCmkmJBGO/Xq0 X-Received: by 2002:a05:6a20:1584:b0:10c:467a:536f with SMTP id h4-20020a056a20158400b0010c467a536fmr3005862pzj.14.1686762945911; Wed, 14 Jun 2023 10:15:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686762945; cv=pass; d=google.com; s=arc-20160816; b=yIAEi2759+DkzMYfPEJZOAOUPRC/+r9GNh4q0H1HZuvYAOPJw8F2jvnLz3frkRbLYY HMA2xoxKra/FKL+3V4SBysp3Vp/DPkjr4XqkTBcmnbj+LOvbn16biue5DY0OOoi7PELO NM6eoxtI8eb2u0HQNpMbonhud/Lwpufy12/9ZkkXnHQBLYxhzF3JqoeOOded+gptGxFE Xl+ZIvub33XWVsS6wtq/2jnFasAE5qk8NPdzNJ58kguPkxbu4EvhQNHHvIq7wkDtfYwc xT40Zw4adTFB0LE8uS2LSeK0wyUjyw+WmVvtKEV4rnPaMBcCog4oRJzCoT4/8AnBydCt AgrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature:dkim-signature; bh=7CZkh2tsWk1KLyX3MYfuwePFgnEoOOmuyhey9E40TaI=; b=NxP14r70eB5qGXsJ+xlouX1fitPsCHvJoPYKtOXJt+uKKJktvGXXRROA+YITv6ntkW paAc9jYBEldU9NHYcnV+qnxTAmrOuz2a8oitqVqbNaYjnydTO7rDuQgXrwLDzPG5Dg7J qNtSbkbQRuf5F6eHE5ExTE1S2NE2yfScCpqHv8yOOQbsRXnz8f3XVqjTnmGSPS27TlL3 SCvZCQumtO7ulRUGHcLHaTjsIIJoxw55h8x2a7nQ8Oo8DTdGxLgJHAtW3lWEzywZL2YD CnCNn5FOMmQn3JvTg8UyGHXAbPVSggx626mHVZjKySLsE020N5kFbK9+2dT/qUdLM9Wc G9wQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gerhold.net header.s=strato-dkim-0002 header.b=JcxBcGPa; dkim=neutral (no key) header.i=@gerhold.net header.s=strato-dkim-0003 header.b=qciHgIC2; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020aa79a41000000b0063b64166faesi11301053pfj.157.2023.06.14.10.15.20; Wed, 14 Jun 2023 10:15:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gerhold.net header.s=strato-dkim-0002 header.b=JcxBcGPa; dkim=neutral (no key) header.i=@gerhold.net header.s=strato-dkim-0003 header.b=qciHgIC2; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233996AbjFNQcR (ORCPT + 99 others); Wed, 14 Jun 2023 12:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjFNQcP (ORCPT ); Wed, 14 Jun 2023 12:32:15 -0400 Received: from mo4-p01-ob.smtp.rzone.de (mo4-p01-ob.smtp.rzone.de [81.169.146.164]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426E91A3; Wed, 14 Jun 2023 09:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686760325; cv=none; d=strato.com; s=strato-dkim-0002; b=svbPe323u+L4XXWIhtfqYnowXOJoDHc8+oHjEl5Qt7DhVydd6t1Hh+COLm1+mKS7F9 nxe9UJaA9459NAlfTLRRX3beZeEwqB4JeZv2s0zb++8hzTfq32QdppKPowfb+eonzlpj CSRkjH8EmZr0hbtAnfP+CxUJ1y0bfI4NXZjWjiNLNxqEQJ7wZT/x/9gpuv/tIneJKOrB ONWfYcRxPlGBgJ5m+iCBR/JbycDSUA9Z2u0UxSdeijjM4gMNN84giG6+To6BylzJzbPX Y3Bo747cCRFB4h9HnoaWSIBxzVnEFJXunY3yMkPOVMdDtmc9jcoxuLaaogDlM2Clw2lS K9WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1686760325; s=strato-dkim-0002; d=strato.com; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=7CZkh2tsWk1KLyX3MYfuwePFgnEoOOmuyhey9E40TaI=; b=pLWXrq/l7HJWkttzP11zi3TVWFU7s2t7O5HR6TkhIo8FwgPP0hOF62j6uYLu8P+1Or NUSI4BWpc2JIIUOMG0M+IsajVrkVIceE+yFj/ABzPuNTOW4aIYQJmQO3y9p59TceoB2i +tBu0VrHJGLo9MwDm+vMlzEyCQtMqCXWI9ijy+XJGQmXjQMMI2bCd04OQSgB6KbuUejo jYRpvwe9sWpRTDO27C3YUJXKFK+wNRnw+8HoHJyo8sfGk6UgTCoQ4cS4rQS42yk8T2cU L86gmlZ3rHV6wXr7LXuV+A/xbtxlrJrinVDsvw8w0BbSTH71rnIUU85EhlepmLfuN+Cd CunA== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1686760325; s=strato-dkim-0002; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=7CZkh2tsWk1KLyX3MYfuwePFgnEoOOmuyhey9E40TaI=; b=JcxBcGPaZqH2eE+/LNMff7DL9IRVol6Q5Dyp5d0r1AXlaWe3GPYtFOPYuSj59zdIud Ec6NRiwXwuWG0OF75PvkU3bcrZwNZwpM3MyFinfsIqhjIn7GFzZoPtFKLswbOjvenT9F vIdutPC4AOd4HjQcwXwo6HQbVKhsbLn34Pa1XbHJxOm7wKqlACrYKVhd02tgNjYNv7P1 QshQOleyHGBj69Wyot4xm5CwD6AsM3nVXEu+nvjgfBAL8wg+MChRry1/s1RUC6LleoCm 9Nfck7F1gJt6I1Dtnbo1wPEppR7MOUNVan4H1iXToDs/NwtKU9VjsRqTZZlqZJ/LkCOt 1a5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1686760325; s=strato-dkim-0003; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=7CZkh2tsWk1KLyX3MYfuwePFgnEoOOmuyhey9E40TaI=; b=qciHgIC2hl9TZ//hlpzHC4kgh7sXed9uT58ElvtBAAxkJk5E1j6V21RwxcAMFLGuiD f+f/EvEkWMXCH2I9OcBg== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVOQjVd4CteZ/7jYgS+mLFY+H0JAn8u4xxmw==" Received: from [192.168.244.3] by smtp.strato.de (RZmta 49.6.0 DYNA|AUTH) with ESMTPSA id D0d0a8z5EGW50U3 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 14 Jun 2023 18:32:05 +0200 (CEST) From: Stephan Gerhold Date: Wed, 14 Jun 2023 18:31:54 +0200 Subject: [PATCH v2 1/2] remoteproc: qcom: Handle reserved-memory allocation issues MIME-Version: 1.0 Message-Id: <20230529-rproc-of-rmem-v2-1-95e39b959585@gerhold.net> References: <20230529-rproc-of-rmem-v2-0-95e39b959585@gerhold.net> In-Reply-To: <20230529-rproc-of-rmem-v2-0-95e39b959585@gerhold.net> To: Bjorn Andersson Cc: Andy Gross , Konrad Dybcio , Mathieu Poirier , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768699142380573053?= X-GMAIL-MSGID: =?utf-8?q?1768699142380573053?= If Linux fails to allocate the dynamic reserved memory specified in the device tree, the size of the reserved_mem will be 0. Add a check for this to avoid using an invalid reservation. Signed-off-by: Stephan Gerhold --- New patch in v2, I wasn't aware of this until Bjorn posted a similar patch for rmtfs: https://lore.kernel.org/linux-arm-msm/20230530233643.4044823-4-quic_bjorande@quicinc.com/ --- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 70bffc9f33f6..a35ab6e860f3 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1932,7 +1932,7 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) return 0; rmem = of_reserved_mem_lookup(node); - if (!rmem) { + if (!rmem || !rmem->size) { dev_err(qproc->dev, "unable to resolve metadata region\n"); return -EINVAL; } diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c index b437044aa126..9edab9d60c21 100644 --- a/drivers/remoteproc/qcom_q6v5_wcss.c +++ b/drivers/remoteproc/qcom_q6v5_wcss.c @@ -882,7 +882,7 @@ static int q6v5_alloc_memory_region(struct q6v5_wcss *wcss) rmem = of_reserved_mem_lookup(node); of_node_put(node); - if (!rmem) { + if (!rmem || !rmem->size) { dev_err(dev, "unable to acquire memory-region\n"); return -EINVAL; } From patchwork Wed Jun 14 16:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 108050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp89757vqr; Wed, 14 Jun 2023 09:53:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gHqMgVhWEhsu5g3KrT+WiCWB5pOHbLEccp7Ky2djydS4C6c94gBZ22CiSKz3yHlhYoutG X-Received: by 2002:a17:902:c2c4:b0:1ae:55c8:6b60 with SMTP id c4-20020a170902c2c400b001ae55c86b60mr9998089pla.1.1686761619855; Wed, 14 Jun 2023 09:53:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686761619; cv=pass; d=google.com; s=arc-20160816; b=ZyUZf9V+iI45YbgBGUjmQ7QqVVh2py1TVTPMti7zPsm8D2BCJgMXRjRe0FzHA+Z502 wzhrjIKFMzkPTAA/kY5hYvxt5vkggWoqmwRSmX3K6xTTm8tsHoPZnhf0NLPTOXsiTPeG VQPpbPFFb5qPuMekBrp1bVBUA8OEVS3yTlwhIKutR2rL1v8gI4/0DP+RxP/NCBA/DOrJ iaZhU5OQPXmiJG971oAqvjSWTA6T7u63Zw/LX4r2HTJvy3hgbWyomPWwpdJI0bh+NuNQ rWDkqrf+1L+rfW3kaAAo2SRskqnYKnI05q4QKy32s6PlpBHc/RhglYZDxGEK4XBFF8jg R6Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature:dkim-signature; bh=8VChFjwSwm7NjkinO0t+vZkFyF4jH/l5wQUQYOlqibU=; b=rowv572tZ8NAvUKD3hBcszEJGoRncWwt9bbgdKOu52xWopsnOMSKNlDEUpjBmAH7XI bfbB59yD+zkmsyXHIRewwjzjG6gufGUlX9CToFurPzUVPBQ1KdzwdJPgm78vU2leDN+F lhhHz/TeB75/U7vFiNV8tivf8Lqa/Si3G3NdTo2PHBJxYT86piUVTt5lA2sNhYjpV6h6 59pJn/L51QDSOmmQ++FsGvyxi9y9Q8huEmWUdLmZxfFRxYsz1fSVyWVbpYasuQkfdsmT AiIxmZjJP0dwyqPi74Q6Lsm8r9IAN3mYsMLZN0iEwcZw42BLDEIJHgSf3R+Aes0ww1sj hA/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gerhold.net header.s=strato-dkim-0002 header.b=nJlw8ey+; dkim=neutral (no key) header.i=@gerhold.net header.s=strato-dkim-0003 header.b=G64pqNNX; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a170902d48700b001b39ba93c77si8987988plg.36.2023.06.14.09.53.24; Wed, 14 Jun 2023 09:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gerhold.net header.s=strato-dkim-0002 header.b=nJlw8ey+; dkim=neutral (no key) header.i=@gerhold.net header.s=strato-dkim-0003 header.b=G64pqNNX; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233310AbjFNQcU (ORCPT + 99 others); Wed, 14 Jun 2023 12:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233828AbjFNQcQ (ORCPT ); Wed, 14 Jun 2023 12:32:16 -0400 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736C62130; Wed, 14 Jun 2023 09:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686760326; cv=none; d=strato.com; s=strato-dkim-0002; b=okOjjl8veV+oeEje8GL2Fc+8r4BpKlqo8hJHJdcuaH9FEGdcIPNi679+4xt/7s1+ai 2Dak8gdcrAjHoakNZH/t1cCz2rI3GrmcJOmLssQbBk5XIJR5deuTU1MzfQJPBpcwHWiW sTbbT9DJRhbLXgHrHaBj8TxCckkBtbuL2c4AoOrPwZUTMqerq0brH2U4qIoEw5vBkHhz 0Iu65fTPJlWk3XCD2Yf+JU1kqteY3aDZe1+12IlCgS6QveD0H8TSSoIvDn8tFKKal0Wx yYIyx0n5YJWSQER3zbujbVQoNMVF87B35HEqbjEdAgjcfFu9tJMFZ0uZbA3QcEl9MqVj B3Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1686760326; s=strato-dkim-0002; d=strato.com; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=8VChFjwSwm7NjkinO0t+vZkFyF4jH/l5wQUQYOlqibU=; b=fb944jlC8YqD156z+sRu5J6hV7ezoysdoZ6RH1XMarNwWSRYPf6z0EkQsBn1xJRoCl 8M66HStjxVBIjGnhF6p6YZHVfDQP86ucF9HmWP8P7JYBdx0cH0LruuaEfVMEVZB4yQ/B MdBOln/ZKPKSQf6lXNc8D08lNcwiAIQ5/IDGlrZv0KhX/AwU8z4+cHVDW3VzzND2wme/ IQv257wpuA0BAYO46yhbGbSrPevQXMWIx7riHwlPlLh9NRWwTTd/psekF0r6Kd1ih8t7 2DfQBo77YKnqNGrb3G5vAi1LDjQFwsfShPeppEOD34mOb+rvIxhGkBRkqRcVtYGWCfZe aY5g== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1686760325; s=strato-dkim-0002; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=8VChFjwSwm7NjkinO0t+vZkFyF4jH/l5wQUQYOlqibU=; b=nJlw8ey+FF7ci0tkl57NFD/vDa3Sg9d2ubR1BWoDgEfTzn/tt87XbDAuf2/0EWR6VF KyDNxg8o8feZrp+AmK9AZ9SlASjrkdb2/8opXm4MVDamg7srWEajrSyYzD4NIP7FpF2h 550crwJCmYRpI+dk2wclQK/HQG41jS1IXi+z/tosYtQdf+hV2o/dk7wfFmEKs6G72dz9 N+NFOU1sazoQmvxDkkDWGquK+OzWySBB+KD+Mb+5HkD8lQZVol++wBNrUkIfPj8eRo2F TxpBNFEey1VtJub18CzxulVzh4lwjFYOJ5eqGDz8FM2YHxm75pvarYbs8Gib/ULBtBPe NM5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1686760325; s=strato-dkim-0003; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=8VChFjwSwm7NjkinO0t+vZkFyF4jH/l5wQUQYOlqibU=; b=G64pqNNX1Vf2kLJWW8rq8HwrYWladHLUFBxHChn/Fmt6c4o1b0NbectN5k7AW0eb1D v6+5ALBvr1dnzdi4OEAg== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVOQjVd4CteZ/7jYgS+mLFY+H0JAn8u4xxmw==" Received: from [192.168.244.3] by smtp.strato.de (RZmta 49.6.0 DYNA|AUTH) with ESMTPSA id D0d0a8z5EGW50U4 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 14 Jun 2023 18:32:05 +0200 (CEST) From: Stephan Gerhold Date: Wed, 14 Jun 2023 18:31:55 +0200 Subject: [PATCH v2 2/2] remoteproc: qcom: Use of_reserved_mem_lookup() MIME-Version: 1.0 Message-Id: <20230529-rproc-of-rmem-v2-2-95e39b959585@gerhold.net> References: <20230529-rproc-of-rmem-v2-0-95e39b959585@gerhold.net> In-Reply-To: <20230529-rproc-of-rmem-v2-0-95e39b959585@gerhold.net> To: Bjorn Andersson Cc: Andy Gross , Konrad Dybcio , Mathieu Poirier , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768697752231880888?= X-GMAIL-MSGID: =?utf-8?q?1768697752231880888?= Reserved memory can be either looked up using the generic function of_address_to_resource() or using the special of_reserved_mem_lookup(). The latter has the advantage that it ensures that the referenced memory region was really reserved and is not e.g. status = "disabled". of_reserved_mem also supports allocating reserved memory dynamically at boot time. This works only when using of_reserved_mem_lookup() since there won't be a fixed address in the device tree. Switch the code to use of_reserved_mem_lookup(), similar to qcom_q6v5_wcss.c which is using it already. There is no functional difference for static reserved memory allocations. While at it this also adds two missing of_node_put() calls in qcom_q6v5_pas.c. Link: https://lore.kernel.org/r/20230529-rproc-of-rmem-v1-1-5b1e38880aba@gerhold.net Signed-off-by: Stephan Gerhold --- drivers/remoteproc/qcom_q6v5_adsp.c | 24 ++++++++--------- drivers/remoteproc/qcom_q6v5_mss.c | 33 ++++++++++++++---------- drivers/remoteproc/qcom_q6v5_pas.c | 51 ++++++++++++++++++++----------------- drivers/remoteproc/qcom_wcnss.c | 24 ++++++++--------- 4 files changed, 69 insertions(+), 63 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c index 6777a3bd6226..c87ab77fec16 100644 --- a/drivers/remoteproc/qcom_q6v5_adsp.c +++ b/drivers/remoteproc/qcom_q6v5_adsp.c @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -637,28 +637,26 @@ static int adsp_init_mmio(struct qcom_adsp *adsp, static int adsp_alloc_memory_region(struct qcom_adsp *adsp) { + struct reserved_mem *rmem = NULL; struct device_node *node; - struct resource r; - int ret; node = of_parse_phandle(adsp->dev->of_node, "memory-region", 0); - if (!node) { - dev_err(adsp->dev, "no memory-region specified\n"); + if (node) + rmem = of_reserved_mem_lookup(node); + of_node_put(node); + + if (!rmem || !rmem->size) { + dev_err(adsp->dev, "unable to resolve memory-region\n"); return -EINVAL; } - ret = of_address_to_resource(node, 0, &r); - of_node_put(node); - if (ret) - return ret; - - adsp->mem_phys = adsp->mem_reloc = r.start; - adsp->mem_size = resource_size(&r); + adsp->mem_phys = adsp->mem_reloc = rmem->base; + adsp->mem_size = rmem->size; adsp->mem_region = devm_ioremap_wc(adsp->dev, adsp->mem_phys, adsp->mem_size); if (!adsp->mem_region) { dev_err(adsp->dev, "unable to map memory region: %pa+%zx\n", - &r.start, adsp->mem_size); + &rmem->base, adsp->mem_size); return -EBUSY; } diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index a35ab6e860f3..dbd8bc53d0c9 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -1875,8 +1874,6 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) struct device_node *child; struct reserved_mem *rmem; struct device_node *node; - struct resource r; - int ret; /* * In the absence of mba/mpss sub-child, extract the mba and mpss @@ -1891,15 +1888,20 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) of_node_put(child); } - ret = of_address_to_resource(node, 0, &r); + if (!node) { + dev_err(qproc->dev, "no mba memory-region specified\n"); + return -EINVAL; + } + + rmem = of_reserved_mem_lookup(node); of_node_put(node); - if (ret) { + if (!rmem || !rmem->size) { dev_err(qproc->dev, "unable to resolve mba region\n"); - return ret; + return -EINVAL; } - qproc->mba_phys = r.start; - qproc->mba_size = resource_size(&r); + qproc->mba_phys = rmem->base; + qproc->mba_size = rmem->size; if (!child) { node = of_parse_phandle(qproc->dev->of_node, @@ -1910,15 +1912,20 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) of_node_put(child); } - ret = of_address_to_resource(node, 0, &r); + if (!node) { + dev_err(qproc->dev, "no mpss memory-region specified\n"); + return -EINVAL; + } + + rmem = of_reserved_mem_lookup(node); of_node_put(node); - if (ret) { + if (!rmem || !rmem->size) { dev_err(qproc->dev, "unable to resolve mpss region\n"); - return ret; + return -EINVAL; } - qproc->mpss_phys = qproc->mpss_reloc = r.start; - qproc->mpss_size = resource_size(&r); + qproc->mpss_phys = qproc->mpss_reloc = rmem->base; + qproc->mpss_size = rmem->size; if (!child) { node = of_parse_phandle(qproc->dev->of_node, "memory-region", 2); diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index ca0155f41dac..dd3fba4dae33 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -533,9 +533,8 @@ static void adsp_pds_detach(struct qcom_adsp *adsp, struct device **pds, static int adsp_alloc_memory_region(struct qcom_adsp *adsp) { + struct reserved_mem *rmem; struct device_node *node; - struct resource r; - int ret; node = of_parse_phandle(adsp->dev->of_node, "memory-region", 0); if (!node) { @@ -543,17 +542,19 @@ static int adsp_alloc_memory_region(struct qcom_adsp *adsp) return -EINVAL; } - ret = of_address_to_resource(node, 0, &r); + rmem = of_reserved_mem_lookup(node); of_node_put(node); - if (ret) - return ret; + if (!rmem || !rmem->size) { + dev_err(adsp->dev, "unable to resolve memory-region\n"); + return -EINVAL; + } - adsp->mem_phys = adsp->mem_reloc = r.start; - adsp->mem_size = resource_size(&r); + adsp->mem_phys = adsp->mem_reloc = rmem->base; + adsp->mem_size = rmem->size; adsp->mem_region = devm_ioremap_wc(adsp->dev, adsp->mem_phys, adsp->mem_size); if (!adsp->mem_region) { dev_err(adsp->dev, "unable to map memory region: %pa+%zx\n", - &r.start, adsp->mem_size); + &rmem->base, adsp->mem_size); return -EBUSY; } @@ -566,16 +567,19 @@ static int adsp_alloc_memory_region(struct qcom_adsp *adsp) return -EINVAL; } - ret = of_address_to_resource(node, 0, &r); - if (ret) - return ret; + rmem = of_reserved_mem_lookup(node); + of_node_put(node); + if (!rmem || !rmem->size) { + dev_err(adsp->dev, "unable to resolve dtb memory-region\n"); + return -EINVAL; + } - adsp->dtb_mem_phys = adsp->dtb_mem_reloc = r.start; - adsp->dtb_mem_size = resource_size(&r); + adsp->dtb_mem_phys = adsp->dtb_mem_reloc = rmem->base; + adsp->dtb_mem_size = rmem->size; adsp->dtb_mem_region = devm_ioremap_wc(adsp->dev, adsp->dtb_mem_phys, adsp->dtb_mem_size); if (!adsp->dtb_mem_region) { dev_err(adsp->dev, "unable to map dtb memory region: %pa+%zx\n", - &r.start, adsp->dtb_mem_size); + &rmem->base, adsp->dtb_mem_size); return -EBUSY; } @@ -584,29 +588,28 @@ static int adsp_alloc_memory_region(struct qcom_adsp *adsp) static int adsp_assign_memory_region(struct qcom_adsp *adsp) { + struct reserved_mem *rmem = NULL; struct qcom_scm_vmperm perm; struct device_node *node; - struct resource r; int ret; if (!adsp->region_assign_idx) return 0; node = of_parse_phandle(adsp->dev->of_node, "memory-region", adsp->region_assign_idx); - if (!node) { - dev_err(adsp->dev, "missing shareable memory-region\n"); + if (node) + rmem = of_reserved_mem_lookup(node); + of_node_put(node); + if (!rmem || !rmem->size) { + dev_err(adsp->dev, "unable to resolve shareable memory-region\n"); return -EINVAL; } - ret = of_address_to_resource(node, 0, &r); - if (ret) - return ret; - perm.vmid = QCOM_SCM_VMID_MSS_MSA; perm.perm = QCOM_SCM_PERM_RW; - adsp->region_assign_phys = r.start; - adsp->region_assign_size = resource_size(&r); + adsp->region_assign_phys = rmem->base; + adsp->region_assign_size = rmem->size; adsp->region_assign_perms = BIT(QCOM_SCM_VMID_HLOS); ret = qcom_scm_assign_mem(adsp->region_assign_phys, diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c index 1ed0647bc962..8bb0c8ef0771 100644 --- a/drivers/remoteproc/qcom_wcnss.c +++ b/drivers/remoteproc/qcom_wcnss.c @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -506,27 +506,25 @@ static int wcnss_request_irq(struct qcom_wcnss *wcnss, static int wcnss_alloc_memory_region(struct qcom_wcnss *wcnss) { + struct reserved_mem *rmem = NULL; struct device_node *node; - struct resource r; - int ret; node = of_parse_phandle(wcnss->dev->of_node, "memory-region", 0); - if (!node) { - dev_err(wcnss->dev, "no memory-region specified\n"); + if (node) + rmem = of_reserved_mem_lookup(node); + of_node_put(node); + + if (!rmem || !rmem->size) { + dev_err(wcnss->dev, "unable to resolve memory-region\n"); return -EINVAL; } - ret = of_address_to_resource(node, 0, &r); - of_node_put(node); - if (ret) - return ret; - - wcnss->mem_phys = wcnss->mem_reloc = r.start; - wcnss->mem_size = resource_size(&r); + wcnss->mem_phys = wcnss->mem_reloc = rmem->base; + wcnss->mem_size = rmem->size; wcnss->mem_region = devm_ioremap_wc(wcnss->dev, wcnss->mem_phys, wcnss->mem_size); if (!wcnss->mem_region) { dev_err(wcnss->dev, "unable to map memory region: %pa+%zx\n", - &r.start, wcnss->mem_size); + &rmem->base, wcnss->mem_size); return -EBUSY; }