microsoft/mu_feature_ffa

Public

mirrored from https://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Library/TestServiceLibRust/src/test_svc.rs

83lines · modeblame

aa115865kuqin1210 months ago1use ec_service_lib::{Result, Service};
2use log::{debug, error};
3use odp_ffa::{MsgSendDirectReq2, MsgSendDirectResp2, Payload, RegisterPayload};
4use odp_ffa::{Function, NotificationSet};
5use uuid::{uuid, Uuid};
6
7// Protocol CMD definitions for Test
33e335eekuqin129 months ago8#[allow(dead_code)]
aa115865kuqin1210 months ago9const TEST_OPCODE_BASE: u64 = 0xDEF0;
10const TEST_OPCODE_TEST_NOTIFICATION: u64 = 0xDEF1;
11
12/* Test Service Defines */
13const DELAYED_SRI_BIT_POS: u64 = 1;
14
15#[derive(Default)]
16struct GenericRsp {
17status: i64,
18}
19
20impl From<GenericRsp> for RegisterPayload {
21fn from(value: GenericRsp) -> Self {
22RegisterPayload::from_iter(value.status.to_le_bytes())
23}
24}
25
26#[derive(Default)]
27pub struct Test {}
28
29impl Test {
30pub fn new() -> Self {
31Self::default()
32}
33
34fn notification_handler(&self, msg: &MsgSendDirectReq2) -> GenericRsp {
35// Grab the uuid from the message, they will be at x5 and x6
36let sender_uuid = Uuid::from_u128_le(((msg.register_at(2) as u128) << 64) | (msg.register_at(1) as u128));
37let cookie = msg.register_at(3);
38let flag = 1 << DELAYED_SRI_BIT_POS;
39let bit_pos = 1 << cookie;
40
41debug!("notification_handler for {:?}", sender_uuid);
42
43// Set up notification through the Notify service
44// TODO;
45// let notify_msg = MsgSendDirectReq2::new(
46// Function::Notify,
47// 0)
48NotificationSet::new(msg.source_id(), msg.destination_id(), flag, bit_pos)
49.exec()
50.unwrap();
51
52GenericRsp {
53status: 0x0,
54}
55}
56}
57
58const UUID: Uuid = uuid!("e0fad9b3-7f5c-42c5-b2ee-b7a82313cdb2");
59
60impl Service for Test {
61fn service_name(&self) -> &'static str {
62"Test"
63}
64
65fn service_uuid(&self) -> Uuid {
66UUID
67}
68
69async fn ffa_msg_send_direct_req2(&mut self, msg: MsgSendDirectReq2) -> Result<MsgSendDirectResp2> {
70let cmd = msg.u64_at(0);
71debug!("Received Test command 0x{:x}", cmd);
72
73let payload = match cmd {
74TEST_OPCODE_TEST_NOTIFICATION => RegisterPayload::from(self.notification_handler(&msg)),
75_ => {
76error!("Unknown Test Command: {}", cmd);
77return Err(odp_ffa::Error::Other("Unknown Test Command"));
78}
79};
80
81Ok(MsgSendDirectResp2::from_req_with_payload(&msg, payload))
82}
83}