-
-
Notifications
You must be signed in to change notification settings - Fork 170
how can I found the Miscellaneous Protocols
and use it
#1084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, that protocol is not currently implemented in uefi-rs. (Contributions welcome, if you are interested in implementing it!) Depending on what your use case is, https://docs.rs/uefi/latest/uefi/table/runtime/struct.RuntimeServices.html#method.get_time might be an acceptable alternative. |
if I want to implement it, how could I found the |
First add the raw protocol in this directory: https://github.com/rust-osdev/uefi-rs/tree/main/uefi-raw/src/protocol. This could go in a new Then you'll add the higher-level version to the That's the general outline, happy to answer questions about any of the details. And/or, feel free to put up a PR even if it's not complete, and I can make comments there too. |
like this: uefi-rs/uefi-raw/src/protocol/console/serial.rs Lines 78 to 98 in 86e200e
but I didn't know how to found out the "efiapi" 's set_control_bits func definition.
|
Using typedef struct {
UINT32 Revision;
EFI_SERIAL_RESET Reset;
EFI_SERIAL_SET_ATTRIBUTES SetAttributes;
EFI_SERIAL_SET_CONTROL_BITS SetControl;
EFI_SERIAL_GET_CONTROL_BITS GetControl;
EFI_SERIAL_WRITE Write;
EFI_SERIAL_READ Read;
SERIAL_IO_MODE *Mode;
CONST EFI_GUID *DeviceTypeGuid; // Revision 1.1
} EFI_SERIAL_IO_PROTOCOL; The type of typedef
EFI_STATUS
(EFIAPI *EFI_SERIAL_SET_CONTROL_BITS) (
IN EFI_SERIAL_IO_PROTOCOL *This,
IN UINT32 Control
); You can usually translate these function types pretty directly into Rust. Note that we don't bother with creating a One last note, our definition of the function does look a little different from C in a couple ways:
|
I've put up a PR to add support for this protocol: #1109 Unfortunately, despite this having been added to the UEFI spec a while ago, it doesn't seem to be well supported. I tested a recent Lenovo, as well as OVMF in QEMU, and neither one has this protocol. |
Weee!! I just completed the support of TimestampProtocol today yeah. Docs: EDK2: |
I think its implementation is related to the UEFI Spec version number commonly used by vendors, probably an ancient version. It seem that I should find another way to get timestamp. |
One option you could try (if you are on x86) is the Depending on exactly what your needs are, this can be somewhat complex; see How to Benchmark Code Execution There's also the question of units. On new-ish processors the timestamp frequency is invariant, and on sufficiently new processors you can directly query the scaling factors needed to convert timestamps to seconds. See for example this code in edk2. On older processors you might need to figure out the frequency by measuring the timestamp on both sides of a call to |
A function pointer in Rust looks very much like a regular function definition. Here's an example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b8ce6ab497a1119b2db8e1a22ac98742 extern "C" fn f2() {}
fn f1(fn_ptr: extern "C" fn() -> ()) {
dbg!(fn_ptr);
}
fn main() {
f1(f2);
} |
It seems that nothing different with C. let func_ptr = |x| -> {
fmt.println(x);
unsafe{
/* some code for ABI call */
}
}
set_callback(type, func_ptr); I wanna know whether uefi-rs has any design or paradigm? The Sorry for my poor English. |
yeah, the one that I need now is only the duration counter. I am an embeded developer for Arm Soc, it has a timer/counter which meet demand, And x86 should also has it. But now I try develop uefi app/driver at x86, just for fun, coding fun! but x86 is really complex which I couldn't easy to get the way. thank you, I read the code, found they are using the reg named TSC (Time Stamp Counter), though affected by cpu hz. I ever use it in Linux. and also could use the the ACPI Timer, HPET, or High Precision Event Timer, AP IC Timer/PIC and so on. see: I found blog on the internet which recommend |
Regarding how to use and implement callbacks, a good example is BootService::create_event: uefi-rs/uefi/src/table/boot.rs Lines 317 to 338 in 6093205
And here's an example of calling it: uefi-rs/uefi-test-runner/src/boot/misc.rs Lines 40 to 49 in 6093205
Note that although Rust does have closures ( |
PR #1116 , though in OVMF run at [ INFO]: uefi-test-runner\src\proto\misc.rs@020: Running loaded Timestamp Protocol test
[ WARN]: uefi-test-runner\src\proto\misc.rs@034: Failed to open Timestamp Protocol: Error { status: UNSUPPORTED, data: () }
[ INFO]: uefi-test-runner\src\proto\misc.rs@041: Running loaded ResetNotification protocol test
[ WARN]: uefi-test-runner\src\proto\misc.rs@076: Failed to open ResetNotification Protocol: Error { status: UNSUPPORTED, data: () } the new log after I use readonly hook, I think it related to the runtime hook:
|
Well, OVMF doesn't has the protocol compiled in, I suppose? Is there an easy way to add it to our pre-build OVMF version, @nicholasbishop ? |
I run uefi-rs/uefi-test-runner/src/main.rs Lines 24 to 42 in 6093205
I think it should be replaced as warnning if want to test on other platforms. edit those two line assert code, I finally Test failed for VMware uefi firmware is old, even not support the console serial. |
Regarding the timestamp protocol, it seems to me that for whatever reason edk2 doesn't broadly enable it. I'm not 100% sure, but I don't think there's an easy way to just enable it at compile time; some code changes would be needed. For the uefi-test-runner, it's intentional that it only works under QEMU. Originally it was more flexible and would only warn instead of fail if the environment was different, but this made the test less useful for actually finding errors. Several times I introduced a change that accidentally broke something, but we didn't notice because the test runner still "passed". So, we changed it to require QEMU, and provided prebuilt OVMF files that have various extra things enabled. See #553 for some more info. |
I want to get the timestamp in uefi, and the docs 39. Miscellaneous Protocols in UEFI Spec 2.10.
the docs' context as follow:

but I couldn't found and misc protocols or any timestamp api in
uefi-rs
, could you help me for giving some suggestion. thanks!The text was updated successfully, but these errors were encountered: