1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <lk/compiler.h>
20 #include <stdint.h>
21 
22 __BEGIN_CDECLS
23 
24 #define COVERAGE_AGGREGATOR_PORT "com.android.trusty.coverage.aggregator"
25 
26 /**
27  * enum coverage_aggregator_cmd - command identifiers for coverage aggregator
28  *                                interface
29  * @COVERAGE_AGGREGATOR_CMD_RESP_BIT:   response bit set as part of response
30  * @COVERAGE_AGGREGATOR_CMD_SHIFT:      number of bits used by response bit
31  * @COVERAGE_AGGREGATOR_CMD_REGISTER:   command to register with coverage
32  *                                      aggregator
33  * @COVERAGE_AGGREGATOR_CMD_GET_RECORD: command to get shared memory region
34  *                                      where coverage record will be written to
35  */
36 enum coverage_aggregator_cmd {
37     COVERAGE_AGGREGATOR_CMD_RESP_BIT = 1U,
38     COVERAGE_AGGREGATOR_CMD_SHIFT = 1U,
39     COVERAGE_AGGREGATOR_CMD_REGISTER = (1U << COVERAGE_AGGREGATOR_CMD_SHIFT),
40     COVERAGE_AGGREGATOR_CMD_GET_RECORD = (2U << COVERAGE_AGGREGATOR_CMD_SHIFT),
41 };
42 
43 /**
44  * struct coverage_aggregator_hdr - header for coverage aggregator messages
45  * @cmd: command identifier
46  *
47  * Note that no messages return a status code. Any error on the server side
48  * results in the connection being closed. So, operations can be assumed to be
49  * successful if they return a response.
50  */
51 struct coverage_aggregator_hdr {
52     uint32_t cmd;
53 };
54 
55 /**
56  * struct coverage_aggregator_register_req - arguments for request to register
57  *                                           with coverage aggregator
58  * @record_len: length of coverage record that will be emitted by this TA
59  */
60 struct coverage_aggregator_register_req {
61     uint32_t record_len;
62 };
63 
64 /**
65  * struct coverage_aggregator_register_req - arguments for response to register
66  *                                           with coverage aggregator
67  * @idx:         unique index assigned to this TA
68  * @mailbox_len: length of memory region used as a mailbox
69  *
70  * A handle to a memory region must be sent along with this message. This memory
71  * is used by coverage server to drop messages that TAs asynchronously respond
72  * to. Possible mailbox messages are defined by &enum coverage_mailbox_event.
73  */
74 struct coverage_aggregator_register_resp {
75     uint32_t idx;
76     uint32_t mailbox_len;
77 };
78 
79 /**
80  * struct coverage_aggregator_get_record_req - arguments for response to get
81  *                                             shared memory for coverage record
82  * @shm_len: length of memory region being shared
83  *
84  * A handle to a memory region must be sent along with this message. This memory
85  * is used to store coverage record.
86  */
87 struct coverage_aggregator_get_record_resp {
88     uint32_t shm_len;
89 };
90 
91 /**
92  * struct coverage_aggregator_req - structure for a coverage aggregator request
93  * @hdr:           message header
94  * @register_args: arguments for %COVERAGE_AGGREGATOR_CMD_REGISTER request
95  */
96 struct coverage_aggregator_req {
97     struct coverage_aggregator_hdr hdr;
98     union {
99         struct coverage_aggregator_register_req register_args;
100     };
101 };
102 
103 /**
104  * struct coverage_aggregator_resp - structure for a coverage aggregator
105  *                                   response
106  * @hdr:             message header
107  * @register_args:   arguments for %COVERAGE_AGGREGATOR_CMD_REGISTER response
108  * @get_record_args: arguments for %COVERAGE_AGGREGATOR_CMD_GET_RECORD response
109  */
110 struct coverage_aggregator_resp {
111     struct coverage_aggregator_hdr hdr;
112     union {
113         struct coverage_aggregator_register_resp register_args;
114         struct coverage_aggregator_get_record_resp get_record_args;
115     };
116 };
117 
118 /**
119  * enum coverage_mailbox_event - mailbox messages
120  * @COVERAGE_MAILBOX_EMPTY:        mailbox is empty
121  * @COVERAGE_MAILBOX_RECORD_READY: shared memory for coverage record is ready
122  */
123 enum coverage_mailbox_event {
124     COVERAGE_MAILBOX_EMPTY = 0U,
125     COVERAGE_MAILBOX_RECORD_READY = 1U,
126 };
127 
128 __END_CDECLS
129