xref: /aosp_15_r20/external/pigweed/pw_chre/public/pw_chre/host_link.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 
17 #include <cstddef>
18 #include <cstdint>
19 
20 // These host link functions should be implemented by the system integrator.
21 namespace pw::chre {
22 
23 /// This is a token representing a message that CHRE allocated.
24 /// It must be passed to `FreeMessageToAp` when the message is finished.
25 using MessageToApContext = const void*;
26 
27 /// This is a message that should be sent to the AP.
28 /// It was allocated by CHRE, so pw::chre::FreeMessageToAp should be called
29 /// in order to free it.
30 struct MessageToAp {
31   /// The id of the nanoapp sending the message.
32   uint64_t nanoapp_id;
33 
34   /// The type of the message.
35   uint32_t message_type;
36 
37   uint32_t app_permissions;
38   uint32_t message_permissions;
39 
40   /// The id of the client that this message should be delivered to on the host.
41   uint16_t host_endpoint;
42 
43   /// Whether CHRE is responsible for waking the AP.
44   /// If this is true, then the client must wake the AP in
45   /// `SendMessageToAp` before sending this message.
46   bool woke_host;
47 
48   /// The underlying data of the message. This is owned by `chre_context` and
49   /// should not be accessed after the message has been freed.
50   const uint8_t* data;
51 
52   /// The length of `data` in bytes.
53   size_t length;
54 
55   /// The context of the message, used to free the message when the client is
56   /// finished sending it.
57   MessageToApContext chre_context;
58 };
59 
60 /// CHRE calls this method to send a message to the Application Processor (AP).
61 /// The client must implement this method, and the client is responsible for
62 /// calling `FreeMessageToAp` once they are finished with the message.
63 /// @param[in] message The message to be sent.
64 /// @param[out] bool Whether this method was successful.
65 bool SendMessageToAp(MessageToAp message);
66 
67 }  // namespace pw::chre
68