microsoft/mu_feature_ffa
Publicmirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/SecurePartitions/MsSecurePartitionRust/src/main.rs
60lines · modecode
| 1 | // This project is dual-licensed under Apache 2.0 and MIT terms. |
| 2 | // See LICENSE-APACHE and LICENSE-MIT for details. |
| 3 | |
| 4 | #![cfg_attr(target_os = "none", no_std)] |
| 5 | #![cfg_attr(target_os = "none", no_main)] |
| 6 | #![deny(clippy::undocumented_unsafe_blocks)] |
| 7 | #![deny(unsafe_op_in_unsafe_fn)] |
| 8 | |
| 9 | #[cfg(target_os = "none")] |
| 10 | mod baremetal; |
| 11 | |
| 12 | #[cfg(not(target_os = "none"))] |
| 13 | fn main() { |
| 14 | println!("qemu-sp stub"); |
| 15 | } |
| 16 | |
| 17 | #[cfg(target_os = "none")] |
| 18 | fn main() -> ! { |
| 19 | use ec_service_lib::MessageHandler; |
| 20 | #[cfg(feature = "tpm")] |
| 21 | use ec_service_lib::services::{TpmService, TpmSst}; |
| 22 | #[cfg(not(feature = "tpm"))] |
| 23 | use ec_service_lib::services::TpmServiceStub; |
| 24 | use test_service_lib::test_svc::Test; |
| 25 | use odp_ffa::Function; |
| 26 | |
| 27 | log::info!("QEMU Secure Partition - build time: {}", env!("BUILD_TIME")); |
| 28 | let version = odp_ffa::Version::new().exec().unwrap(); |
| 29 | log::info!("FFA version: {}.{}", version.major(), version.minor()); |
| 30 | |
| 31 | #[cfg(feature = "tpm")] |
| 32 | let tpm_service = { |
| 33 | // Non-secure CRB region shared between non-secure world and secure world. |
| 34 | // Secure CRB region only accessible by the TPM service. |
| 35 | let (tpm_internal_crb_address, tpm_external_crb_address): (u64, u64) = |
| 36 | (0x40200000, 0x0c000000); |
| 37 | log::info!("TPM Internal CRB Address: {:X}", tpm_internal_crb_address); |
| 38 | log::info!("TPM External CRB Address: {:X}", tpm_external_crb_address); |
| 39 | // Initialize the TPM service with its state-translation backend. |
| 40 | let mut svc = TpmService::new(TpmSst::new()); |
| 41 | |
| 42 | // SAFETY: Writes to the memory-mapped internal CRB regions and initializes |
| 43 | // the SST layer for the external TPM device. |
| 44 | unsafe { svc.init(tpm_internal_crb_address, tpm_external_crb_address) }; |
| 45 | svc |
| 46 | }; |
| 47 | |
| 48 | #[cfg(not(feature = "tpm"))] |
| 49 | let tpm_service = TpmServiceStub::new(); |
| 50 | |
| 51 | MessageHandler::new() |
| 52 | .append(ec_service_lib::services::FwMgmt::new()) |
| 53 | .append(ec_service_lib::services::Notify::new()) |
| 54 | .append(tpm_service) |
| 55 | .append(Test::new()) |
| 56 | .run_message_loop() |
| 57 | .expect("Error in run_message_loop"); |
| 58 | |
| 59 | unreachable!() |
| 60 | } |
| 61 | |