From: "Marcin Juszkiewicz" <marcin.juszkiewicz@linaro.org>
To: devel@edk2.groups.io, quic_llindhol@quicinc.com
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
Graeme Gregory <graeme@xora.org.uk>
Subject: Re: [edk2-devel] [PATCH edk2-platforms v2 1/4] Platform/SbsaQemu: add SbsaQemuHardwareInfoLib
Date: Wed, 24 Jan 2024 13:55:54 +0100 [thread overview]
Message-ID: <7eebb4a3-b431-4d7f-8027-1ec96c9bb68a@linaro.org> (raw)
In-Reply-To: <ZarK6G3PjlLCW8PS@qc-i7.hemma.eciton.net>
W dniu 19.01.2024 o 20:18, Leif Lindholm pisze:
> On Tue, Jan 16, 2024 at 08:48:32 +0100, Marcin Juszkiewicz wrote:
>> This library provides functions to check for hardware information.
>> For now it covers CPU ones:
>>
>> - amount of cpu cores
>> - MPIDR value for cpu core
>> - NUMA node id for cpu core
>>
>> Values are read from TF-A using platform specific SMC calls.
>>
>> Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
>> ---
>> Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 3 +-
>> .../SbsaQemuHardwareInfoLib.inf | 32 +++++++
>> .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h | 2 +
>> .../Include/Library/SbsaQemuHardwareInfoLib.h | 45 +++++++++
>> .../SbsaQemuHardwareInfoLib.c | 100 ++++++++++++++++++++
>> 5 files changed, 181 insertions(+), 1 deletion(-)
>>
>> diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
>> new file mode 100644
>> index 000000000000..4df973fda75e
>> --- /dev/null
>> +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
>> @@ -0,0 +1,100 @@
>> +/** @file
>> +*
>> +* Copyright (c) 2021, NUVIA Inc. All rights reserved.
>> +* Copyright (c) Linaro Ltd. All rights reserved.
>> +*
>> +* SPDX-License-Identifier: BSD-2-Clause-Patent
>> +*
>> +**/
>> +
>> +#include <Library/ArmSmcLib.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/PcdLib.h>
>> +#include <Library/SbsaQemuHardwareInfoLib.h>
>> +#include <IndustryStandard/SbsaQemuSmc.h>
>> +
>> +/**
>> + Get CPU count from information passed by Qemu.
>> +
>> +**/
>> +VOID
>> +SbsaQemuGetCpuCount (
>> + VOID
>> + )
>> +{
>> + UINTN Arg0;
>> + UINTN SmcResult;
>> + RETURN_STATUS Result;
>> +
>> + SmcResult = ArmCallSmc0 (SIP_SVC_GET_CPU_COUNT, &Arg0, NULL, NULL);
>> + if (SmcResult != SMC_ARCH_CALL_SUCCESS) {
>
> So, this may sound a little bit bonkers, but SMCCC doesn't define
> return codes for SiP functions. And the SMC_ARCH_CALL_SUCCESS macro
> denotes an Arm Architectural function.
> Could you #define an SMC_SIP_CALL_SUCCESS *as* SMC_ARCH_CALL_SUCCESS
> in some platform-specific header and then use that?
Added it in Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
and used.
>> + DEBUG ((DEBUG_INFO, "Too old TF-A. We have to get cpu info from DT.\n"));
>
> We don't *know* the TF-A is too old. Rather print which call failed
> (and that we need to attempt to get the cpu count from DT).
Changed:
DEBUG ((DEBUG_INFO, "SIP_SVC_GET_CPU_COUNT call failed. We have to
get cpu info from DT.\n"));
>> + Arg0 = FdtHelperCountCpus();
>
> We should probably assert this as != 0? Or is that done in the function?
Added code to stop going if we do not have cpu information. In such case
we will not be back here with wrong info.
>
>> + }
>> +
>> + Result = PcdSet32S (PcdCoreCount, Arg0);
>> + ASSERT_RETURN_ERROR (Result);
>> +
>> + Arg0 = PcdGet32 (PcdCoreCount);
>
> Seems redundant to re-set it to the value we know it already holds.
Done
>> +
>> + DEBUG ((DEBUG_INFO, "We have %d cpus.\n", Arg0));
>> +}
>> +
>> +/**
>> + Get MPIDR for a given cpu from device tree passed by Qemu.
>> +
>> + @param [in] CpuId Index of cpu to retrieve MPIDR value for.
>> +
>> + @retval MPIDR value of CPU at index <CpuId>
>> +**/
>> +UINT64
>> +SbsaQemuGetMpidr (
>> + IN UINTN CpuId
>> + )
>> +{
>> + UINTN SmcResult;
>> + UINTN Arg0;
>> + UINTN Arg1;
>> +
>> + Arg0 = CpuId;
>> +
>> + SmcResult = ArmCallSmc0 (SIP_SVC_GET_CPU_NODE, &Arg0, &Arg1, NULL);
>> + if (SmcResult != SMC_ARCH_CALL_SUCCESS) {
>> + DEBUG ((DEBUG_INFO, "Too old TF-A. We have to get cpu info from DT.\n"));
>
> We don't *know* the TF-A is too old. Rather print which call failed
> (and that we need to attempt to get the cpu date from DT).
done
>> +UINT64
>> +SbsaQemuGetCpuNumaNode (
>> + IN UINTN CpuId
>> + )
>> +{
>> + UINTN SmcResult;
>> + UINTN Arg0;
>> + UINTN Arg1;
>> +
>> + Arg0 = CpuId;
>> +
>> + SmcResult = ArmCallSmc0 (SIP_SVC_GET_CPU_NODE, &Arg0, &Arg1, NULL);
>
> It does seem a bit wasteful we're making the same call twice per core,
> discarding one of the results.
> Could we have an init function that allocates an array and
> prepopulates it, with the Get-functions just returning values from the array?
good idea, will look into
>> + if (SmcResult != SMC_ARCH_CALL_SUCCESS) {
>> + /* No fallback to DeviceTree as we did not had that info earlier. */
>
> We don't *know* the TF-A is too old. Rather print which call failed
> (and that we need to attempt to get the cpu count from DT).
done
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114287): https://edk2.groups.io/g/devel/message/114287
Mute This Topic: https://groups.io/mt/103758014/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-01-24 12:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 7:48 [edk2-devel] [PATCH edk2-platforms v2 0/4] get rid of DeviceTree from SbsaQemu Marcin Juszkiewicz
2024-01-16 7:48 ` [edk2-devel] [PATCH edk2-platforms v2 1/4] Platform/SbsaQemu: add SbsaQemuHardwareInfoLib Marcin Juszkiewicz
2024-01-19 19:18 ` Leif Lindholm
2024-01-24 12:55 ` Marcin Juszkiewicz [this message]
2024-02-12 11:53 ` Marcin Juszkiewicz
2024-01-16 7:48 ` [edk2-devel] [PATCH edk2-platforms v2 2/4] Platform/SbsaQemu: read amount of cpus during init Marcin Juszkiewicz
2024-01-16 7:48 ` [edk2-devel] [PATCH edk2-platforms v2 3/4] Platform/SbsaQemu: use PcdCoreCount directly Marcin Juszkiewicz
2024-01-19 19:20 ` Leif Lindholm
2024-01-24 12:57 ` Marcin Juszkiewicz
2024-01-16 7:48 ` [edk2-devel] [PATCH edk2-platforms v2 4/4] Platform/SbsaQemu: move FdtHandlerLib to SbsaQemuHardwareInfoLib Marcin Juszkiewicz
2024-01-19 19:22 ` Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7eebb4a3-b431-4d7f-8027-1ec96c9bb68a@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox