From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4475618E744 for ; Mon, 9 Sep 2024 23:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725926226; cv=none; b=DnwecF1xpfV02RiTPFwY/ZLeskRszMpGPZx+nE2iO7+TPQcUDbU2tEK2FQRuMsg2Ix/ai+H4zKatnzdRI098ttxL2zHMCEkhOxZCNAShMR/dk7nllgnxKXzoIPv7i1dl+MKHhnex5nySk/A0qEXndIiYkybAfijHJzzhgsmqxm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725926226; c=relaxed/simple; bh=3XI5IVZuxU96tWCq021MKnBptmnTHpNo8/GtC8SKI6s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oYq+pwtzTOT8qLP7Q3+QzHWdA9GEaUzpk02oN3IUh0KTE+RKqpeUzTiPwK22DCdO0onSeTK9K8K3eMBLnGu7PpTjSOyPhFS3kR0PCxpgitsVEftxrV6sCKBgcGeomS5BBAJzpNPJchZnikPh8idLTTtPC9QaGD4CGo2aEh7C0Ms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IiMGrPcJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IiMGrPcJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725926224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5KDrfnw4h4KPFm9gkKjM5Pcm4Qn58KLQZ4qPPhdTka4=; b=IiMGrPcJMyPe1iRPH6QOvCcYJMNTYQBT1HA62FtkmekbHUtyWXRuaUY/HuY+cv/8Y/rNkS h424HIy9dUAJ5tpmxSAAUgwM33imP9e7/d7JSw07OViRvX8aB4+AxltsyZvhjHT1cimScJ oUJDHmiO+2jnY08KlJogCSq9lsDlM9w= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-pVhliGHCOP-6gK3jr52QGA-1; Mon, 09 Sep 2024 19:57:01 -0400 X-MC-Unique: pVhliGHCOP-6gK3jr52QGA-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-718e34530dfso243317b3a.3 for ; Mon, 09 Sep 2024 16:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725926221; x=1726531021; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5KDrfnw4h4KPFm9gkKjM5Pcm4Qn58KLQZ4qPPhdTka4=; b=PMKrNFEetISFRPqd32B+BiaPyzh80uFxIoQLQDQMzIAO3bpibp47WuECfbap8O1LbN 6CHOazHXfnZGeB5Ari182q8YhzgJkt2PgyfcH4WI+6ax/OYZY2JE3cKnJ22KT8LGNZ6O +8WiyjZ5w2D4v37AmAQNeFeEqeIFh260fpr9KKMmY5fGEZW2WJra/v+68Uqpmv6/KnNM /gQwPzMlpM5GtLD7+/LEG1naAg/Fx5naTork5RWszO2gfTvvIOaPLJH3YvQLm17pbU8F CFE/PFN+9j++/tpTrHoZfzwWwxP23u+SxHMp2TNyS2LJE/1I8WEoPu6E0t6Gh6JhMT5d 0KKA== X-Forwarded-Encrypted: i=1; AJvYcCULtM3kGj2jopqA0uRIL2zDLbhkqzYbji0UR1CCMep7vb2+N5R1cwajVaadS4Q1VyHSWMQ+DXb/DAGl@lists.linux.dev X-Gm-Message-State: AOJu0Yy5J9LY+4vwTwp7BaMSJDypQeE4ZctMWIcYWFv/Qrzr/XODyiZk BfQZYaHvyo4AwA87vL7fLV12Z5YLOMqQtZ8TK+jtYD/RAidmqeC40+T98s272r/ZZ8c5yEW6PGv 7F5K592l6c3Ezw69jQqmw5JZG/iNMMNZvTZZjHZmOtavkdDvcZ3PLINzqlBk= X-Received: by 2002:a05:6a00:3c85:b0:718:d740:b870 with SMTP id d2e1a72fcca58-718e3352956mr12735770b3a.2.1725926220677; Mon, 09 Sep 2024 16:57:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsgj8V1pojC58pqDKayl2QgqKFvt9FHbNtmUL06MwiNOepfTXdxL0EwUPYChJ+RhkrUXN3AQ== X-Received: by 2002:a05:6a00:3c85:b0:718:d740:b870 with SMTP id d2e1a72fcca58-718e3352956mr12735733b3a.2.1725926220087; Mon, 09 Sep 2024 16:57:00 -0700 (PDT) Received: from [192.168.68.54] ([103.210.27.31]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71909092258sm269939b3a.127.2024.09.09.16.56.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Sep 2024 16:56:59 -0700 (PDT) Message-ID: <41d7c549-072c-4e55-beab-cf339f441ec5@redhat.com> Date: Tue, 10 Sep 2024 09:56:49 +1000 Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 04/19] firmware/psci: Add psci_early_test_conduit() To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Shanker Donthineni , Alper Gun , Jean-Philippe Brucker References: <20240819131924.372366-1-steven.price@arm.com> <20240819131924.372366-5-steven.price@arm.com> From: Gavin Shan In-Reply-To: <20240819131924.372366-5-steven.price@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/19/24 11:19 PM, Steven Price wrote: > From: Jean-Philippe Brucker > > Add a function to test early if PSCI is present and what conduit it > uses. Because the PSCI conduit corresponds to the SMCCC one, this will > let the kernel know whether it can use SMC instructions to discuss with > the Realm Management Monitor (RMM), early enough to enable RAM and > serial access when running in a Realm. > > Signed-off-by: Jean-Philippe Brucker > Signed-off-by: Steven Price > --- > v4: New patch > --- > drivers/firmware/psci/psci.c | 25 +++++++++++++++++++++++++ > include/linux/psci.h | 5 +++++ > 2 files changed, 30 insertions(+) > Question: Do we need same check for ACPI based system? > diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c > index 2328ca58bba6..2b308f97ef2c 100644 > --- a/drivers/firmware/psci/psci.c > +++ b/drivers/firmware/psci/psci.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -769,6 +770,30 @@ int __init psci_dt_init(void) > return ret; > } > > +/* > + * Test early if PSCI is supported, and if its conduit matches @conduit > + */ Nit: The comments needn't span into multiple lines. > +bool __init psci_early_test_conduit(enum arm_smccc_conduit conduit) > +{ > + int len; > + int psci_node; > + const char *method; > + unsigned long dt_root; > + > + /* DT hasn't been unflattened yet, we have to work with the flat blob */ > + dt_root = of_get_flat_dt_root(); > + psci_node = of_get_flat_dt_subnode_by_name(dt_root, "psci"); > + if (psci_node <= 0) > + return false; > + Nit: Strictly speaking, "psci_node == 0" isn't an error. So the check would be "if (psci_node < 0)" if I'm correct. > + method = of_get_flat_dt_prop(psci_node, "method", &len); > + if (!method) > + return false; > + > + return (conduit == SMCCC_CONDUIT_SMC && strncmp(method, "smc", len) == 0) || > + (conduit == SMCCC_CONDUIT_HVC && strncmp(method, "hvc", len) == 0); > +} > + > #ifdef CONFIG_ACPI > /* > * We use PSCI 0.2+ when ACPI is deployed on ARM64 and it's > diff --git a/include/linux/psci.h b/include/linux/psci.h > index 4ca0060a3fc4..a1fc1703ba20 100644 > --- a/include/linux/psci.h > +++ b/include/linux/psci.h > @@ -45,8 +45,13 @@ struct psci_0_1_function_ids get_psci_0_1_function_ids(void); > > #if defined(CONFIG_ARM_PSCI_FW) > int __init psci_dt_init(void); > +bool __init psci_early_test_conduit(enum arm_smccc_conduit conduit); > #else > static inline int psci_dt_init(void) { return 0; } > +static inline bool psci_early_test_conduit(enum arm_smccc_conduit conduit) > +{ > + return false; > +} > #endif > > #if defined(CONFIG_ARM_PSCI_FW) && defined(CONFIG_ACPI) Thanks, Gavin