1 /*
2  * Copyright (C) 2019 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 #ifndef __CROS_EC_INCLUDE_CITADEL_EVENTS_H
17 #define __CROS_EC_INCLUDE_CITADEL_EVENTS_H
18 
19 #include <assert.h>
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifndef __packed
27 #define __packed __attribute__((packed))
28 #endif
29 
30 /*
31  * When Citadel needs to tell the AP something without waiting to be asked, the
32  * process is as follows:
33  *
34  *   1. Citadel adds an event_report to its internal queue, then asserts
35  *      the CTDL_AP_IRQ signal to notify the AP.
36  *
37  *   2. The AP (citadeld) requests pending events from Citadel until they've
38  *      all been retrieved.
39  *
40  *   3. Citadel deasserts CTDL_AP_IRQ.
41  *
42  * Because we may want to compare the history and evolution of events over a
43  * long time and for multiple releases, we should only APPEND to this file
44  * instead of changing things.
45  */
46 
47 /*
48  * Event priority.  Stored events of lower priority will be evicted to store
49  * higher-priority events if the queue is full.
50  */
51 enum event_priority {
52   EVENT_PRIORITY_LOW = 0,
53   EVENT_PRIORITY_MEDIUM = 1,
54   EVENT_PRIORITY_HIGH = 2,
55 };
56 
57 /*
58  * Event ID values live forever.
59  * Add to the list, but NEVER change or delete existing entries.
60  */
61 enum event_id {
62   EVENT_NONE = 0,          // Unused ID, used as empty marker.
63   EVENT_ALERT = 1,         // Globalsec alert fired.
64   EVENT_REBOOTED = 2,      // Device rebooted.
65   EVENT_UPGRADED = 3,      // Device has upgraded.
66   EVENT_ALERT_V2 = 4,      // Globalsec Alertv2 fired
67   EVENT_SEC_CH_STATE = 5,  // Update GSA-GSC secure channel state.
68   EVENT_V1_NO_SUPPORT =
69       6  // Report a VXX event that can't fit in struct event_report.
70 };
71 
72 /*
73  * Upgrade state definition.
74  */
75 enum upgrade_state_def {
76   UPGRADE_SUCCESS = 0,
77   UPGRADE_PW_MISMATCH = 1,
78   UPGRADE_EN_FW_FAIL =2,
79 };
80 
81 /*
82  * Big event header flags.
83  */
84 enum hdr_flags {
85   HDR_FLAG_EMPTY_SLOT = 0,    // Used to determine empty slot.
86   HDR_FLAG_OCCUPIED_SLOT = 1  // Used to indicate an occupied slot.
87 };
88 
89 /* Please do not change the size of this struct */
90 #define EVENT_REPORT_SIZE 64
91 struct event_report {
92   uint64_t reset_count;                 /* zeroed by Citadel power cycle */
93   uint64_t uptime_usecs;                /* since last Citadel reset */
94   uint32_t id;
95   uint32_t priority;
96   union {
97     /* id-specific information goes here */
98     struct {
99       uint32_t intr_sts[3];
100     } alert;
101     struct {
102       uint32_t rstsrc;
103       uint32_t exitpd;
104       uint32_t which0;
105       uint32_t which1;
106     } rebooted;
107     struct {
108       uint32_t upgrade_state;
109     } upgraded;
110     struct {
111       uint32_t alert_grp[4];
112       uint16_t camo_breaches[2];
113       uint16_t temp_min;
114       uint16_t temp_max;
115       uint32_t bus_err;
116     } alert_v2;
117     struct {
118       uint32_t state;
119     } sec_ch_state;
120 
121     /* uninterpreted */
122     union {
123       uint32_t w[10];
124       uint16_t h[20];
125       uint8_t b[40];
126     } raw;
127   } event;
128 } __packed;
129 /* Please do not change the size of this struct */
130 static_assert(sizeof(struct event_report) == EVENT_REPORT_SIZE,
131               "Muting the Immutable");
132 
133 struct big_event_report {
134   struct hdr {
135     /* Redundant w.r.t. to v1 event records */
136     uint64_t reset_count;
137     uint64_t uptime_usecs;
138     uint32_t priority;
139 
140     uint8_t version;
141     uint8_t flags;
142     uint16_t length;
143   } hdr;
144   uint8_t data[384];
145 } __packed;
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif  /* __CROS_EC_INCLUDE_CITADEL_EVENTS_H */
152