1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use crate::defs::{EfiGuid, EfiRiscvBootProtocol, EFI_STATUS_NOT_FOUND};
16 use crate::protocol::{Protocol, ProtocolInfo};
17 use crate::{efi_call, map_efi_err, EfiResult};
18 
19 /// RISCV_EFI_BOOT_PROTOCOL
20 pub struct RiscvBootProtocol;
21 
22 impl ProtocolInfo for RiscvBootProtocol {
23     type InterfaceType = EfiRiscvBootProtocol;
24 
25     const GUID: EfiGuid =
26         EfiGuid::new(0xccd15fec, 0x6f73, 0x4eec, [0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf]);
27 }
28 
29 impl<'a> Protocol<'a, RiscvBootProtocol> {
get_boot_hartid(&self) -> EfiResult<usize>30     pub fn get_boot_hartid(&self) -> EfiResult<usize> {
31         let mut boot_hart_id: usize = 0;
32         // SAFETY:
33         // `self.interface()?` guarantees `self.interface` is non-null and points to a valid object
34         // established by `Protocol::new()`.
35         // `self.interface` is input parameter and will not be retained. It outlives the call.
36         // `&mut boot_hart_id` is output parameter and will not be retained. It outlives the call.
37         unsafe {
38             efi_call!(self.interface()?.get_boot_hartid, self.interface, &mut boot_hart_id)?;
39         }
40         Ok(boot_hart_id)
41     }
42 
revision(&self) -> EfiResult<u64>43     pub fn revision(&self) -> EfiResult<u64> {
44         Ok(self.interface()?.revision)
45     }
46 }
47