microsoft/mu_feature_ffa

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
818f98457c414ab23fe870089c633ad464a8216d

Branches

Tags

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

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Library/TestServiceLibRust/src/test_svc.rs

83lines · modecode

1use 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
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 RegisterPayload {
21 fn from(value: GenericRsp) -> Self {
22 RegisterPayload::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 sender_uuid = Uuid::from_u128_le(((msg.register_at(2) as u128) << 64) | (msg.register_at(1) as u128));
37 let cookie = msg.register_at(3);
38 let flag = 1 << DELAYED_SRI_BIT_POS;
39 let bit_pos = 1 << cookie;
40
41 debug!("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)
48 NotificationSet::new(msg.source_id(), msg.destination_id(), flag, bit_pos)
49 .exec()
50 .unwrap();
51
52 GenericRsp {
53 status: 0x0,
54 }
55 }
56}
57
58const UUID: Uuid = uuid!("e0fad9b3-7f5c-42c5-b2ee-b7a82313cdb2");
59
60impl Service for Test {
61 fn service_name(&self) -> &'static str {
62 "Test"
63 }
64
65 fn service_uuid(&self) -> Uuid {
66 UUID
67 }
68
69 async fn ffa_msg_send_direct_req2(&mut self, msg: MsgSendDirectReq2) -> Result<MsgSendDirectResp2> {
70 let cmd = msg.u64_at(0);
71 debug!("Received Test command 0x{:x}", cmd);
72
73 let payload = match cmd {
74 TEST_OPCODE_TEST_NOTIFICATION => RegisterPayload::from(self.notification_handler(&msg)),
75 _ => {
76 error!("Unknown Test Command: {}", cmd);
77 return Err(odp_ffa::Error::Other("Unknown Test Command"));
78 }
79 };
80
81 Ok(MsgSendDirectResp2::from_req_with_payload(&msg, payload))
82 }
83}
84