microsoft/mu_feature_ffa

Public

mirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Library/TestServiceLibRust/src/test_svc.rs

78lines · modecode

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