Skip to contentSkip to conversation

Question regarding "boot-hartid" DT node

DISCUSSION Sunil V L 7 participants 30 messages Dec 2, 2021 – Jan 18, 2022 1 message not in the archive RISC-V

lore
Share & tools
lore

Sunil V L

author
#0 lore raw

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

Thanks!
Sunil

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#1 lore raw
Quoted 15 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 5 lines

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

What happened to your suggestions in

https://linuxplumbersconf.org/event/11/contributions/1099/attachments/781/1602/LPC_2021_ACPI_RISCV_Sunil.pdf

Best regards

Heinrich

Quoted 4 lines

Thanks!
Sunil

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#2 lore raw

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 15 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 5 lines

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

Quoted 3 lines

What happened to your suggestions in

https://linuxplumbersconf.org/event/11/contributions/1099/attachments/781/1602/LPC_2021_ACPI_RISCV_Sunil.pdf

The challenge is, the EFI stub part which comes very early even before proper kernel starts. If the information required in later stage of the kernel, we can use ACPI tables.

Thanks
Sunil

Quoted 10 lines

Best regards

Heinrich

Quoted 4 lines

Thanks!
Sunil

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
Quoted 24 lines · Sunil V L

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

Quoted 7 lines
Quoted 3 lines

What happened to your suggestions in

https://linuxplumbersconf.org/event/11/contributions/1099/attachments/781/1602/LPC_2021_ACPI_RISCV_Sunil.pdf

The challenge is, the EFI stub part which comes very early even before proper kernel starts. If the information required in later stage of the kernel, we can use ACPI tables.

What I have never understood is why the core calling the EFI stub cannot identify it own hartid which is stored in CSR mhartid. The missing piece seems to be SBI support to read this piece of information. That way we could get rid of passing the boot hartid via a0.

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw
In reply to Sunil V L
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

Note that you don't need any spec changes for this on the ACPI or UEFI side.

Quoted 8 lines

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

Thanks!
Sunil

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw
Quoted 16 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 8 lines
Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

Best regards

Heinrich

Quoted 11 lines

Note that you don't need any spec changes for this on the ACPI or UEFI side.

Quoted 8 lines

Do you have any suggestions what can be done in ACPI case? Can we use a UEFI variable with RVI specific GUID to pass this information? This will have the advantage that it can work with either DT or ACPI. Also, we may not need any UEFI spec update. Do you see any issue with this approach? Your inputs will be very helpful.

Thanks!
Sunil

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw
Quoted 33 lines · Ard Biesheuvel
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which fails in S-mode and the SBI could emulate it.

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#8 lore raw
Quoted 44 lines · Heinrich Schuchardt
Quoted 33 lines · Ard Biesheuvel
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

Quoted 6 lines

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which fails in S-mode and the SBI could emulate it.

That works for me as well, as long as the EFI stub does not have to grow support for protocols beyond EFI based ones.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw
In reply to Heinrich Schuchardt
Quoted 44 lines · Heinrich Schuchardt
Quoted 33 lines · Ard Biesheuvel
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

Quoted 5 lines

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which fails in S-mode and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic
problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require
EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Do you have a link to the older thread where this thing was discussed ?

Quoted 9 lines

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

--
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#10 lore raw
Quoted 62 lines · Atish Patra
Quoted 44 lines · Heinrich Schuchardt
Quoted 33 lines · Ard Biesheuvel
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

Quoted 5 lines

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which fails in S-mode and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic
problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require
EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

Quoted 7 lines

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

Quoted 23 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Do you have a link to the older thread where this thing was discussed ?

Quoted 9 lines

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Quoted 3 lines

--
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#11 lore raw
Quoted 48 lines · Ard Biesheuvel
Quoted 47 lines · Atish Patra
Quoted 44 lines · Heinrich Schuchardt
Quoted 41 lines · Ard Biesheuvel
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Ard Biesheuvel
Quoted 5 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the "boot-hartid" DT node that is being used in RISC-V Linux EFI stub.

Quoted 7 lines

As you know, the boot Hart ID is passed in a0 register to the kernel and hence there is actually no need to pass it via DT. However, since EFI stub follows EFI application calling conventions, it needs to know the boot Hart ID so that it can pass it to the proper kernel via a0. For this issue, the solution was to add "/chosen/boot-hartid" in DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 4 lines

But above approach causes issue for ACPI since ACPI initialization happens late in the proper kernel. Same is true even if we pass this information via SMBIOS.

Quoted 7 lines
Quoted 3 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task SBI would be a better fit.

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which fails in S-mode and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 5 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

Quoted 7 lines

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 10 lines
Quoted 10 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#12 lore raw
Quoted 119 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
      I am starting this thread to discuss about the "boot-hartid" DT node
      that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

      As you know, the boot Hart ID is passed in a0 register to the kernel
      and hence there is actually no need to pass it via DT. However, since
      EFI stub follows EFI application calling conventions, it needs to
      know the boot Hart ID so that it can pass it to the proper kernel via
      a0. For this issue, the solution was to add "/chosen/boot-hartid" in
      DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

      But above approach causes issue for ACPI since ACPI initialization
      happens late in the proper kernel. Same is true even if we pass this
      information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 5 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

Quoted 7 lines

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#13 lore raw
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Signature · 7 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#14 lore raw
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol (https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Best regards

Heinrich

Quoted 10 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Quoted 35 lines

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#15 lore raw
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Regards,
Anup

Quoted 50 lines

Best regards

Heinrich

Quoted 45 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#16 lore raw
Quoted 159 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 8 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

The boot-hartid uses to be the hartid of the current thread. Are operating systems supposed to support boot-hartid to relate to another hardware thread then the current one? If the boot-hartid can differ from the current thread, what would be the source of truth? Is there any formal specification defining what the boot-hartid is and how it shall be used? Is there any formal specification which defines the transfer of the boot-hartid in the boot flow?

I only found this in the OpenSBI documentation:

The DT properties of a domain instance DT node are as follows:
* **boot-hart** (Optional) - The DT node phandle of the HART booting the domain instance. If coldboot HART is assigned to the domain instance then this DT property is ignored and the coldboot HART is assumed to be the boot HART of the domain instance.

The only piece of software that cares about the boot-hartid property is neither the SBI nor the UEFI firmware nor the EFI stub but the main OS kernel. Carrying the current hartid from boot stage to boot stage via register and DTB entry looks like a poor design decision. Instead of relying on a chain of transfers it would preferable that whoever in the boot chain wants to know the current hartid requests it from the source of truth.

The source of truth for the current hardware thread is the value of the mhartid CSR. Unfortunately this can only be read in M-mode. It could be made available via the SBI. I see no reason why the operating system or hypervisor should not see the hartid of a software thread at any time.

If we decide to make the current design more complex by using an EFI protocol, we have to decide if we want to reuse an existing one, or introduce a new one.

We already have an existing protocol in U-Boot which could do the job and which uses a dtb as transfer format. Internally OpenSBI, U-Boot and Linux always use a device-tree. But this does not hold true for other software like EDK II. We could instead define a new protocol which uses a uint64_t parameter and does not require support for the flattened devicetree format.

My preferred choice would be getting rid of multiple transfers and letting the piece of software that needs the information read the boot-hartid directly from wherever the source of truth is.

Best regards

Heinrich

Quoted 54 lines

Regards,
Anup

Quoted 50 lines

Best regards

Heinrich

Quoted 45 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#17 lore raw
Quoted 172 lines · Heinrich Schuchardt
Quoted 159 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 18 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 8 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Quoted 4 lines

The boot-hartid uses to be the hartid of the current thread. Are operating systems supposed to support boot-hartid to relate to another hardware thread then the current one? If the boot-hartid can differ from the current thread, what would be the source of truth? Is there any

The boot-hartid is part of the boot protocol (non-EFI or EFI based).

For non-EFI based booting, the previous booting stage passes boot-hartid in the a0 registers. This works perfectly fine and we don't have any issues because OSes can save the boot-hartid from a0 register to some memory location.

This issue of discovering boot-hartid only applies to EFI based booting so we need a RISC-V specific protocol/configuration in EFI tables to allow OSes to discover the boot-hartid.

Quoted 3 lines

formal specification defining what the boot-hartid is and how it shall be used? Is there any formal specification which defines the transfer of the boot-hartid in the boot flow?

For non-EFI based booting, the "a0" register contains the hartid. This convention has been followed in RISC-V since early days (10+ years).

EFI based booting is relatively new in the RISC-V world so this should be solved in an EFI specific way.

Quoted 8 lines

I only found this in the OpenSBI documentation:

The DT properties of a domain instance DT node are as follows:
* **boot-hart** (Optional) - The DT node phandle of the HART booting the domain instance. If coldboot HART is assigned to the domain instance then this DT property is ignored and the coldboot HART is assumed to be the boot HART of the domain instance.

This is not at all related to the problem we are discussing here. This documentation talks about preferred boot-hart within a OpenSBI domain and OpenSBI will remove the domain configuration details from DTB before jumping to the next booting stage.

Quoted 8 lines

The only piece of software that cares about the boot-hartid property is neither the SBI nor the UEFI firmware nor the EFI stub but the main OS kernel. Carrying the current hartid from boot stage to boot stage via register and DTB entry looks like a poor design decision. Instead of relying on a chain of transfers it would preferable that whoever in the boot chain wants to know the current hartid requests it from the source of truth.

Passing boot-hartid in DTB was a temporary decision (2 years back) when Atish added EFI support in the kernel because back then there was no ACPI support being developed for RISC-V kernel.

Now that we can have either DT or ACPI passed via EFI booting, we need a EFI specific solution.

Quoted 5 lines

The source of truth for the current hardware thread is the value of the mhartid CSR. Unfortunately this can only be read in M-mode. It could be made available via the SBI. I see no reason why the operating system or hypervisor should not see the hartid of a software thread at any time.

Both DT and ACPI have details of all HARTs along with their hartids, it's only the boot-hartid (hartid of the booting HART) which needs to be known to the kernel when booted as an EFI application.

Also, "boot-hartid" is a transient read-only information which is of no use at runtime so defining an SBI call for this means has limited utility value:
1) It will be used only once for EFI based booting and never used at runtime
2) Non-EFI booting will never use it because boot-hartid is available in a0 register
3) Hypervisors which prefer booting kernel directly will never implement it because it's redundant for such hypervisors

Clearly, "boot-hartid" needs to be part of the booting protocol and a SBI call for this has very limited utility value.

Quoted 11 lines

If we decide to make the current design more complex by using an EFI protocol, we have to decide if we want to reuse an existing one, or introduce a new one.

We already have an existing protocol in U-Boot which could do the job and which uses a dtb as transfer format. Internally OpenSBI, U-Boot and Linux always use a device-tree. But this does not hold true for other software like EDK II. We could instead define a new protocol which uses a uint64_t parameter and does not require support for the flattened devicetree format.

Mandating some form of devicetree for EFI booting is a choice to be made by the RISC-V platform specs.

Quoted 4 lines

My preferred choice would be getting rid of multiple transfers and letting the piece of software that needs the information read the boot-hartid directly from wherever the source of truth is.

I disagree with this.

A SBI call just for determining boot-hartid is of limited utility (in this case used only for EFI based booting). It is better to solve this problem in a EFI specific way.

Regards,
Anup

Quoted 59 lines

Best regards

Heinrich

Quoted 54 lines

Regards,
Anup

Quoted 50 lines

Best regards

Heinrich

Quoted 45 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#18 lore raw
In reply to Anup Patel
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

Quoted 12 lines

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

In that case, where should we document it ? UEFI spec or RISC-V platform spec ?

Quoted 54 lines

Regards,
Anup

Quoted 50 lines

Best regards

Heinrich

Quoted 45 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 29 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Signature · 7 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#19 lore raw
Quoted 178 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 18 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

Quoted 8 lines

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

In that case, where should we document it ? UEFI spec or RISC-V platform spec ?

Defining EFI protocols outside the UEFI spec has precedents, e.g. the EFI_TCG2_PROTOCOL is defined in a specification hosted by the Trusted Computing Group.

The UEFI Forum prefers an implemention first approach. We should demonstrate with a patched EDK II or U-Boot and a patched Linux that what we define is working before creating a change request.

Let's start with a draft protocol specification on Github and then develop the necessary patches.

Best regards

Heinrich

Quoted 48 lines
Quoted 48 lines

Regards,
Anup

Quoted 43 lines

Best regards

Heinrich

Quoted 38 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 25 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#20 lore raw
Quoted 189 lines · Heinrich Schuchardt
Quoted 185 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel

On Thu, 2 Dec 2021 at 16:05, Sunil V L <[email protected]>
wrote:

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the
stub can call to discover the boot-hartid value. That wat, it can
pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

Quoted 6 lines
Quoted 1 line

In that case, where should we document it ? UEFI spec or RISC-V platform spec ?

Defining EFI protocols outside the UEFI spec has precedents, e.g. the EFI_TCG2_PROTOCOL is defined in a specification hosted by the Trusted Computing Group.

The 'E' in EFI means 'extensible' and the UEFI spec was never intended as an exhaustive reference of all imaginable protocols. It is perfectly fine to define your own protocols, and document them wherever appropriate.

Quoted 4 lines

The UEFI Forum prefers an implemention first approach. We should demonstrate with a patched EDK II or U-Boot and a patched Linux that what we define is working before creating a change request.

... if needed. There is no need to incorporate this into the UEFI spec.

Quoted 3 lines

Let's start with a draft protocol specification on Github and then develop the necessary patches.

Agreed.

And to Heinrich's point regarding that there should not be a need for this protocol: I completely agree. The fact that passing the boot-hartid in a0 is part of the boot protocol is unfortunate, and sadly, the EFI stub needs to implement what the boot protocol stipulates, even though it is not a great design to begin with.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#21 lore raw
Quoted 208 lines · Ard Biesheuvel
Quoted 189 lines · Heinrich Schuchardt
Quoted 185 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 41 lines · Heinrich Schuchardt

On 12/2/21 17:20, Ard Biesheuvel wrote:
On Thu, 2 Dec 2021 at 16:05, Sunil V L <[email protected]>
wrote:

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

It would be better to define a RISCV specific EFI protocol that the
stub can call to discover the boot-hartid value. That wat, it can
pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific
task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

Quoted 6 lines
Quoted 1 line

In that case, where should we document it ? UEFI spec or RISC-V platform spec ?

Defining EFI protocols outside the UEFI spec has precedents, e.g. the EFI_TCG2_PROTOCOL is defined in a specification hosted by the Trusted Computing Group.

The 'E' in EFI means 'extensible' and the UEFI spec was never intended as an exhaustive reference of all imaginable protocols. It is perfectly fine to define your own protocols, and document them wherever appropriate.

Quoted 4 lines

The UEFI Forum prefers an implemention first approach. We should demonstrate with a patched EDK II or U-Boot and a patched Linux that what we define is working before creating a change request.

Quoted 7 lines

... if needed. There is no need to incorporate this into the UEFI spec.

Quoted 3 lines

Let's start with a draft protocol specification on Github and then develop the necessary patches.

Agreed.

Hi Ard,
Here is the draft EFI_RISCV_BOOT_PROTOCOL specification.
https://github.com/riscv-non-isa/riscv-uefi/releases/download/0.3/EFI_RISCV_PROTOCOL-spec.pdf

If you are fine with this, we can freeze this spec. Thanks a lot for your help on this.

Thanks
Sunil

Quoted 6 lines

And to Heinrich's point regarding that there should not be a need for this protocol: I completely agree. The fact that passing the boot-hartid in a0 is part of the boot protocol is unfortunate, and sadly, the EFI stub needs to implement what the boot protocol stipulates, even though it is not a great design to begin with.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#22 lore raw
Quoted 6 lines

Hi Ard,
Here is the draft EFI_RISCV_BOOT_PROTOCOL specification.
https://github.com/riscv-non-isa/riscv-uefi/releases/download/0.3/EFI_RISCV_PROTOCOL-spec.pdf

If you are fine with this, we can freeze this spec. Thanks a lot for your help on this.

Please don't use the EFI_ prefix, it is reserved for protocols that are defined in the UEFI or PI specifications.

Other than that, this looks fine to me.

Signature · 6 lines
Ard.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#23 lore raw
Quoted 9 lines · Ard Biesheuvel
Quoted 6 lines

Hi Ard,
Here is the draft EFI_RISCV_BOOT_PROTOCOL specification.
https://github.com/riscv-non-isa/riscv-uefi/releases/download/0.3/EFI_RISCV_PROTOCOL-spec.pdf

If you are fine with this, we can freeze this spec. Thanks a lot for your help on this.

Please don't use the EFI_ prefix, it is reserved for protocols that are defined in the UEFI or PI specifications.

Oh OK. I didn't know that. TCG2 protocols also start with EFI prefix. Is that a mistake?

Would "RISCV_EFI_BOOT_PROTOCOL" be better?

Thanks
Sunil

Quoted 5 lines

Other than that, this looks fine to me.

Signature · 1 line
Ard.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#24 lore raw
Quoted 6 lines · Sunil V L
Quoted 4 lines · Ard Biesheuvel
Quoted 4 lines

Hi Ard,
Here is the draft EFI_RISCV_BOOT_PROTOCOL specification.
https://github.com/riscv-non-isa/riscv-uefi/releases/download/0.3/EFI_RISCV_PROTOCOL-spec.pdf

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

If you are fine with this, we can freeze this spec. Thanks a lot for your help on this.

Please don't use the EFI_ prefix, it is reserved for protocols that are defined in the UEFI or PI specifications.

Oh OK. I didn't know that. TCG2 protocols also start with EFI prefix. Is that a mistake?

Yes.

Quoted 2 lines

Would "RISCV_EFI_BOOT_PROTOCOL" be better?

Yes, or RISCV_BOOT_PROTOCOL. The EFI is kind of redundant since we are dealing with a EFI protocol.

Quoted 7 lines

Thanks
Sunil

Quoted 5 lines

Other than that, this looks fine to me.

--
Ard.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#25 lore raw
Quoted 17 lines · Ard Biesheuvel
Quoted 6 lines · Sunil V L
Quoted 4 lines · Ard Biesheuvel
Quoted 4 lines

Hi Ard,
Here is the draft EFI_RISCV_BOOT_PROTOCOL specification.
https://github.com/riscv-non-isa/riscv-uefi/releases/download/0.3/EFI_RISCV_PROTOCOL-spec.pdf

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

If you are fine with this, we can freeze this spec. Thanks a lot for your help on this.

Please don't use the EFI_ prefix, it is reserved for protocols that are defined in the UEFI or PI specifications.

Oh OK. I didn't know that. TCG2 protocols also start with EFI prefix. Is that a mistake?

Quoted 7 lines

Yes.

Quoted 2 lines

Would "RISCV_EFI_BOOT_PROTOCOL" be better?

Yes, or RISCV_BOOT_PROTOCOL. The EFI is kind of redundant since we are dealing with a EFI protocol.

Thanks a lot!, Ard. While I agree EFI is kind of redundant, I still prefer to keep it. Since RISC-V supports both EFI and non-EFI systems, having EFI clearly indicates this is for EFI systems.

Thanks
Sunil

Quoted 8 lines
Quoted 8 lines

Thanks
Sunil

Quoted 5 lines

Other than that, this looks fine to me.

--
Ard.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#26 lore raw
In reply to Atish Patra
Quoted 178 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel
Quoted 18 lines · Sunil V L

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

Quoted 6 lines

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the stub can call to discover the boot-hartid value. That wat, it can pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

Quoted 7 lines

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

If RISC-V mandates that every OS (including FreeBSD) should follow the booting protocol that a0 should be used to pass the boot hartid, then only Linux EFI stub becomes a special case which can reuse the existing DT based EFI protocol (mentioned by Heinrich), right?

Thanks
Sunil

Quoted 49 lines

In that case, where should we document it ? UEFI spec or RISC-V platform spec ?

Quoted 47 lines

Regards,
Anup

Quoted 43 lines

Best regards

Heinrich

Quoted 38 lines

My only concern with the RISC-V EFI protocol is that Ard suggested it doesn't need a modification in UEFI spec.
Where should we document it in this case ? We can't document it in Linux or EBBR.
Because, this is a protocol that server systems and other non-Linux OS will also use.
We can define it in the RISC-V platform spec. But that's not the usual place where somebody will look for the definition of such protocol.

Wouldn't it be better to standardize it in UEFI spec ? The UEFI spec already has ARCH specific protocols/config tables.

Quoted 25 lines
Quoted 13 lines

If GRUB loads a devicetree it will anyway have to call into the firmware for fixups. These will include adding the boot-hartid.

Quoted 9 lines
Quoted 9 lines

@Heinrich Schuchardt
I vaguely remember you proposed something similar when we discussed this first during FOSDEM.
I can't recall why it was abandoned in favor of the DT approach which works. But,
it is not an ideal solution considering RISC-V ACPI support is already on the way.

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Do you have a link to the older thread where this thing was discussed ?

Unfortunately I cannot find anything.

I assume Atish referred to this thread:

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Best regards

Heinrich

Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Signature · 2 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#27 lore raw
Quoted 183 lines · Sunil V L
Quoted 181 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Ard Biesheuvel

On Thu, 2 Dec 2021 at 16:05, Sunil V L <[email protected]>
wrote:

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

Quoted 9 lines
Quoted 4 lines

It would be better to define a RISCV specific EFI protocol that the
stub can call to discover the boot-hartid value. That wat, it can
pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

Quoted 8 lines
Quoted 4 lines

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

If RISC-V mandates that every OS (including FreeBSD) should follow the booting protocol that a0 should be used to pass the boot hartid, then only Linux EFI stub becomes a special case which can reuse the existing DT based EFI protocol (mentioned by Heinrich), right?

Absolutely not. What you are saying is “let’s forbid anyone from using UEFI”. This “booting protocol” thing is a RISC-V-specific low-level interface that is incompatible with UEFI; in it, every architecture, including RISC-V, passes exactly two arguments to the application, the handle to the image and a pointer to the system table, and puts the return address in the usual place. Linux’s EFI stub is not special; *any* EFI application, be it your EFI stub, FreeBSD’s bootloader, grub-efi, systemd-boot, OpenBSD’s bootloader, Haiku’s bootloader, whatever, follows the UEFI spec and so does not, and never will, follow the RISC-V booting protocol.

I wish everyone would stop talking about this “RISC-V booting protocol”. It’s low-level firmware details that, due to not having a mature firmware story at the time OSes were brought up, leaked up into the OS booting process. In FreeBSD the only time it gets used is if the kernel is booted directly from BBL/OpenSBI; if instead you boot the bootloader via UEFI then that code is completely bypassed (and we make the legacy direct boot method look like the bootloader method by creating a “fake” bootloader metadata array, rather than the other way round, which would be backwards and severely limiting). It’s not a good protocol, OSes shouldn’t be using it, and it should fade into obscurity outside of the M-mode firmware<->S-mode firmware interface. It’s just not relevant to an OS. What is relevant is that there is critical information in the firmware that the OS can’t get at if booting via the industry-standard portable rich firmware interface, and that information needs to be provided some way or another via a means compatible with the specification. I like the SBI “get current hartid” extension approach best, it’s the most flexible and there’s no harm in having it exist in a crummy non-UEFI situation. It’s trivial to implement, it’s trivial to use, it provides the interface that *should* have existed in the ISA just like how mpidr_el1 is a thing on AArch64, and it provides a way for even non-UEFI code to not have to care about a0 being hartid (outside of perhaps the hart lottery in the entry point if you need to support pre-HSM SBIs), it can just throw it away and ask for it later when it needs it, just like if booting via UEFI. You could also make it a UEFI protocol, but that’s more annoying to deal with, you now have two different ways to get the same information depending on how you were booted. You could also restrict it to only being “get the boot hartid”, but why, what does that achieve? It doesn’t really make it any simpler to implement, it’s just more restrictive for the sake of being minimal, even if it is sufficient. But at the end of the day all of them do work. So, please, can we stop wasting our lives on this and just do *something* rather than going round and round in circles and forgetting all the details in the process?

As for the “provide a dummy FDT to the proposed fixup protocol” proposal, no, that’s clearly not going to fly with an ACPI-only OS that doesn’t have, and never will include, a device tree parser. If your ACPI system needs a device tree then it’s not ACPI-only any more.

Jess

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#28 lore raw
Quoted 193 lines · Jessica Clarke
Quoted 183 lines · Sunil V L
Quoted 181 lines · Atish Patra
Quoted 160 lines · Anup Patel
Quoted 157 lines · Heinrich Schuchardt
Quoted 142 lines · Atish Patra
Quoted 100 lines · Heinrich Schuchardt
Quoted 98 lines · Heinrich Schuchardt
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Atish Patra
Quoted 58 lines · Heinrich Schuchardt
Quoted 44 lines · Ard Biesheuvel
Quoted 41 lines · Heinrich Schuchardt

On 12/2/21 17:20, Ard Biesheuvel wrote:
On Thu, 2 Dec 2021 at 16:05, Sunil V L <[email protected]>
wrote:

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0 register to
the kernel
and hence there is actually no need to pass it via DT.
However, since
EFI stub follows EFI application calling conventions, it
needs to
know the boot Hart ID so that it can pass it to the proper
kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true even if we
pass this
information via SMBIOS.

It would be better to define a RISCV specific EFI protocol that the
stub can call to discover the boot-hartid value. That wat, it can
pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI specific
task
SBI would be a better fit.

Quoted 8 lines

I disagree. The OS<->loader firmware interface is UEFI not SBI. So if the EFI stub needs to ask the firmware which boot-hartid it should pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI protocol by calling into SBI is a different matter (and likely the best choice). But that does not mean the EFI stub should make SBI calls directly.

The EFI stub does not need the boot-hartid. It is the main Linux kernel that does. And that kernel already implements SBI calls.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The main kernel could just try to read CSR mhartid which fails in S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other way to solve a generic

I am not sure this feature would be implemented as SBI extension or as a CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would require an update of the SBI specification.

Quoted 2 lines
Quoted 2 lines

problem. The boot hartid issue is very specific to efi booting only. Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running single threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic means to find out on which hart it is currently running.

Quoted 13 lines
Quoted 12 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last resort rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard should work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the caller. We do need to support it in the grub though.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a loader with a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Yes!! Thanks for refreshing the memory. It seems after 2 years, we are still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub code to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than EFI variables.
2. DT modification - This was preferred over the configuration table at that time given because RISC-V was DT only at that time. We already had all the infrastructure
around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI support.
Adding a similar entry in ACPI tables
is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is. Thus, it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard suggested EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

Quoted 2 lines

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either option.

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented in U-Boot and already used by systemd-boot. Pass a devicetree (which may be empty) to the Fixup() method and it will add the /chosen node with the boot-hartid parameter.

Quoted 3 lines
Quoted 3 lines

The EFI stub anyway creates a new device-tree to pass the memory map to the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 5 lines

Are you suggesting that DTB (skeletal or full-blown) will always be there when booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231
[2] https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

Quoted 8 lines
Quoted 4 lines

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

If RISC-V mandates that every OS (including FreeBSD) should follow the booting protocol that a0 should be used to pass the boot hartid, then only Linux EFI stub becomes a special case which can reuse the existing DT based EFI protocol (mentioned by Heinrich), right?

Quoted 11 lines

Absolutely not. What you are saying is “let’s forbid anyone from using UEFI”. This “booting protocol” thing is a RISC-V-specific low-level interface that is incompatible with UEFI; in it, every architecture, including RISC-V, passes exactly two arguments to the application, the handle to the image and a pointer to the system table, and puts the return address in the usual place. Linux’s EFI stub is not special; *any* EFI application, be it your EFI stub, FreeBSD’s bootloader, grub-efi, systemd-boot, OpenBSD’s bootloader, Haiku’s bootloader, whatever, follows the UEFI spec and so does not, and never will, follow the RISC-V booting protocol.

Yes, understood. Thanks!.

Quoted 34 lines

I wish everyone would stop talking about this “RISC-V booting protocol”. It’s low-level firmware details that, due to not having a mature firmware story at the time OSes were brought up, leaked up into the OS booting process. In FreeBSD the only time it gets used is if the kernel is booted directly from BBL/OpenSBI; if instead you boot the bootloader via UEFI then that code is completely bypassed (and we make the legacy direct boot method look like the bootloader method by creating a “fake” bootloader metadata array, rather than the other way round, which would be backwards and severely limiting). It’s not a good protocol, OSes shouldn’t be using it, and it should fade into obscurity outside of the M-mode firmware<->S-mode firmware interface. It’s just not relevant to an OS. What is relevant is that there is critical information in the firmware that the OS can’t get at if booting via the industry-standard portable rich firmware interface, and that information needs to be provided some way or another via a means compatible with the specification. I like the SBI “get current hartid” extension approach best, it’s the most flexible and there’s no harm in having it exist in a crummy non-UEFI situation. It’s trivial to implement, it’s trivial to use, it provides the interface that *should* have existed in the ISA just like how mpidr_el1 is a thing on AArch64, and it provides a way for even non-UEFI code to not have to care about a0 being hartid (outside of perhaps the hart lottery in the entry point if you need to support pre-HSM SBIs), it can just throw it away and ask for it later when it needs it, just like if booting via UEFI. You could also make it a UEFI protocol, but that’s more annoying to deal with, you now have two different ways to get the same information depending on how you were booted. You could also restrict it to only being “get the boot hartid”, but why, what does that achieve? It doesn’t really make it any simpler to implement, it’s just more restrictive for the sake of being minimal, even if it is sufficient. But at the end of the day all of them do work. So, please, can we stop wasting our lives on this and just do *something* rather than going round and round in circles and forgetting all the details in the process?

Quoted 5 lines

As for the “provide a dummy FDT to the proposed fixup protocol” proposal, no, that’s clearly not going to fly with an ACPI-only OS that doesn’t have, and never will include, a device tree parser. If your ACPI system needs a device tree then it’s not ACPI-only any more.

Completely agree.

I can draft the EFI protocol but I also feel "SBI interface to get current hartid" is better. Considering that the software ecosystem is expanding for risc-v, this will cater to any future needs. I am concerned that this EFI protocol will be of no use if SBI implements "get current hart id" in future.

Thanks
Sunil

Quoted 2 lines

Jess

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

A message that is not in the archive (sent off-list or not yet received): CAOnJCUJ1jmwj4jrWsL2UnV8Wit_-w2KVnqUxy3gsvzE4ZugHBQ@mail.gmail.com

author
#30 lore raw
Quoted 304 lines · Atish Patra
Quoted 293 lines · Sunil V L
Quoted 4 lines · Jessica Clarke
Quoted 3 lines · Sunil V L
Quoted 1 line · Atish Patra

On Fri, Dec 3, 2021 at 8:24 PM Anup Patel <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Heinrich Schuchardt
Quoted 1 line · Atish Patra

On Fri, Dec 3, 2021 at 10:45 AM Heinrich Schuchardt <

Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Heinrich Schuchardt
Quoted 2 lines · Ard Biesheuvel
Quoted 1 line

On Thu, 2 Dec 2021 at 20:29, Atish Patra <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines · Heinrich Schuchardt

On 12/2/21 17:58, Ard Biesheuvel wrote:
On Thu, 2 Dec 2021 at 17:53, Heinrich Schuchardt
<[email protected]> wrote:

On 12/2/21 17:20, Ard Biesheuvel wrote:
On Thu, 2 Dec 2021 at 16:05, Sunil V L <

[email protected]>

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

wrote:

Hi All,
I am starting this thread to discuss about the
"boot-hartid" DT node
that is being used in RISC-V Linux EFI stub.

As you know, the boot Hart ID is passed in a0

register to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the kernel
and hence there is actually no need to pass it via

DT.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, since
EFI stub follows EFI application calling

conventions, it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

needs to
know the boot Hart ID so that it can pass it to the

proper

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

kernel via
a0. For this issue, the solution was to add
"/chosen/boot-hartid" in
DT. Both EDK2 and u-boot append this node in DT.

I think this was a mistake tbh

But above approach causes issue for ACPI since ACPI
initialization
happens late in the proper kernel. Same is true

even if we

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

pass this
information via SMBIOS.

It would be better to define a RISCV specific EFI protocol

that the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

stub can call to discover the boot-hartid value. That wat,

it can

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

pass
it directly, without having to rely on firmware tables.

As discovering the current process' hartid is not a UEFI

specific

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

task
SBI would be a better fit.

I disagree. The OS<->loader firmware interface is UEFI not

SBI. So if

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the EFI stub needs to ask the firmware which boot-hartid it

should

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

pass in A0, it should use a EFI protocol and nothing else.

Whether or not the loader/firmware *implements* this EFI

protocol by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

calling into SBI is a different matter (and likely the best

choice).

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

But that does not mean the EFI stub should make SBI calls

directly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The EFI stub does not need the boot-hartid. It is the main

Linux kernel

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that does. And that kernel already implements SBI calls.

The main kernel could just try to read CSR mhartid which

fails in

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

S-mode
and the SBI could emulate it.

New SBI extension should be added only if there is no other

way to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

solve a generic

I am not sure this feature would be implemented as SBI extension

or as a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

CSR emulation. Cf. sbi_emulate_csr_read(). But anyway it would

require

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

an update of the SBI specification.

Quoted 1 line
Quoted 1 line

problem. The boot hartid issue is very specific to efi booting

only.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Any system that doesn't require

The boot hartid is not EFI related at all. A firmware running

single

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

threaded does not need this information.

Information about the boot hartid is a general OS need.

I am wondering why S-mode software should not have a generic

means to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

find out on which hart it is currently running.

Quoted 3 lines
Quoted 3 lines

EFI booting won't need it. Even for EFI booting, we have other approaches already proposed
to solve it. That's why, SBI extension should be the last

resort

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rather than first.

I think an RISC-V specific EFI protocol as suggested by Ard

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

work for all the cases.
Is there a case where you think it may not work ? U-Boot & EDK2 already stores the boot hartid.
They just implement that protocol and pass the hartid to the

caller.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

We do need to support it in the grub though.

Why would GRUB care about this? The EFI stub will call into the underlying firmware to invoke the protocol, GRUB is just a

loader with

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

a fancy menu that allows you to select which image to load, no?

This is a related discussion:

https://github.com/tekkamanninja/grub/commit/be9d4f1863a1fcb1cbbd2f867309457fade8be73#commitcomment-60851029

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Yes!! Thanks for refreshing the memory. It seems after 2 years, we

are

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

still debating the same topic :).
Let me summarize the thread. There are multiple ways for EFI stub

code

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

to retrieve the boot hartid.

1. EFI variables - This is what Henerich proposed last time. Ard suggested that EFI configuration tables are better candidates than

EFI

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

variables.
2. DT modification - This was preferred over the configuration

table

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

at that time given because RISC-V was DT only at that time.
We already had all the

infrastructure

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

around DT. Thus, DT seemed to be a natural choice then.
It works now for existing setup
however, the DT approach will not work for systems with ACPI

support.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Adding a similar entry in ACPI

tables

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

is possible but adding ACPI support in EFI stub is not trivial.
3. SMBIOS - Only for platforms with SMBIOS support. SMBIOS is not mandatory and adding SMBIOS support in EFI stub is not trivial.
4. SBI - As I mentioned before, this is an EFI specific
problem because EFI stub doesn't know what the boot hartid is.

Thus,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

it should be solved
in an EFI specific way. An SBI extension for
such features may not be acceptable as the non-EFI booting method works fine without the SBI extension.
5. RISC-V specific EFI configuration table or protocol: Ard

suggested

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines

EFI configuration table last time. Earlier in this thread, EFI protocol was suggested.
My personal preference has always been one of
these as it solves the problem for all EFI booting methods
for platforms-os
combination(DT/ACPI-Linux/FreeBSD) in an EFI specific way.

@Heinrich: Do you see any issue with the EFI configuration table or protocol to retrieve the boot hartid?

There is nothing technical stopping us from implementing either

option.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

We could simply reuse the EFI Device Tree Fixup Protocol
(https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL) implemented

in

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

U-Boot and already used by systemd-boot. Pass a devicetree (which

may be

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

empty) to the Fixup() method and it will add the /chosen node with

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

boot-hartid parameter.

The EFI stub anyway creates a new device-tree to pass the memory

map to

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

the kernel in the ACPI case (function update_fdt()). Calling the EFI Device Tree Fixup Protocol could be easily added.

Thanks. Yes. We can solve the current problem for EFI stub in Linux.

Quoted 2 lines

Are you suggesting that DTB (skeletal or full-blown) will always be

there when

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

booting the kernel as an EFI application ? If yes then we are indirectly mandating
skeletal DTB for UEFI+ACPI system.

Yes. EFI Stub tries to find a fdt from the command line (not a preferred method) or EFI configuration table[1] (currently used for RISC-V systems). If it can't find a device tree, it generates one [2]

[1]

https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/efi-stub.c#L231

Quoted 1 line
Quoted 1 line
Quoted 1 line

[2]

https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/efi/libstub/fdt.c#L58

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

However, we may still need to define the RISC-V EFI protocol to support ACPI for other OS (FreeBSD) which doesn't have a stub like loader that uses DT.

If RISC-V mandates that every OS (including FreeBSD) should follow the booting protocol that a0 should be used to pass the boot hartid, then only Linux EFI stub becomes a special case which can reuse the existing DT based EFI protocol (mentioned by Heinrich), right?

Quoted 11 lines

Absolutely not. What you are saying is “let’s forbid anyone from using UEFI”. This “booting protocol” thing is a RISC-V-specific low-level interface that is incompatible with UEFI; in it, every architecture, including RISC-V, passes exactly two arguments to the application, the handle to the image and a pointer to the system table, and puts the return address in the usual place. Linux’s EFI stub is not special; *any* EFI application, be it your EFI stub, FreeBSD’s bootloader, grub-efi, systemd-boot, OpenBSD’s bootloader, Haiku’s bootloader, whatever, follows the UEFI spec and so does not, and never will, follow the RISC-V booting protocol.

Yes, understood. Thanks!.

Quoted 34 lines

I wish everyone would stop talking about this “RISC-V booting protocol”. It’s low-level firmware details that, due to not having a mature firmware story at the time OSes were brought up, leaked up into the OS booting process. In FreeBSD the only time it gets used is if the kernel is booted directly from BBL/OpenSBI; if instead you boot the bootloader via UEFI then that code is completely bypassed (and we make the legacy direct boot method look like the bootloader method by creating a “fake” bootloader metadata array, rather than the other way round, which would be backwards and severely limiting). It’s not a good protocol, OSes shouldn’t be using it, and it should fade into obscurity outside of the M-mode firmware<->S-mode firmware interface. It’s just not relevant to an OS. What is relevant is that there is critical information in the firmware that the OS can’t get at if booting via the industry-standard portable rich firmware interface, and that information needs to be provided some way or another via a means compatible with the specification. I like the SBI “get current hartid” extension approach best, it’s the most flexible and there’s no harm in having it exist in a crummy non-UEFI situation. It’s trivial to implement, it’s trivial to use, it provides the interface that *should* have existed in the ISA just like how mpidr_el1 is a thing on AArch64, and it provides a way for even non-UEFI code to not have to care about a0 being hartid (outside of perhaps the hart lottery in the entry point if you need to support pre-HSM SBIs), it can just throw it away and ask for it later when it needs it, just like if booting via UEFI. You could also make it a UEFI protocol, but that’s more annoying to deal with, you now have two different ways to get the same information depending on how you were booted. You could also restrict it to only being “get the boot hartid”, but why, what does that achieve? It doesn’t really make it any simpler to implement, it’s just more restrictive for the sake of being minimal, even if it is sufficient. But at the end of the day all of them do work. So, please, can we stop wasting our lives on this and just do *something* rather than going round and round in circles and forgetting all the details in the process?

Quoted 5 lines

As for the “provide a dummy FDT to the proposed fixup protocol” proposal, no, that’s clearly not going to fly with an ACPI-only OS that doesn’t have, and never will include, a device tree parser. If your ACPI system needs a device tree then it’s not ACPI-only any more.

Quoted 8 lines

Completely agree.

I can draft the EFI protocol but I also feel "SBI interface to get current hartid" is better. Considering that the software ecosystem is expanding for risc-v, this will cater to any future needs. I am concerned that this EFI protocol will be of no use if SBI implements "get current hart id" in future.

Quoted 4 lines

There won’t be an SBI extension for “get current hart id” for the reasons explained by earlier. So EFI protocol should be the way forward to solve this issue.

Thank you Atish for that confirmation. Let me draft the EFI protocol with a PoC and will request for review. We can decide where to host it (RVI or UEFI spec) later.

Thank you all for your inputs. This was very helpful.

Thanks
Sunil

Quoted 10 lines
Quoted 7 lines

Thanks
Sunil

Quoted 2 lines

Jess

Signature · 2 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv