• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_record 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 };
68 
69 /*
70  * Upgrade state definition.
71  */
72 enum upgrade_state_def {
73   UPGRADE_SUCCESS = 0,
74   UPGRADE_PW_MISMATCH = 1,
75 };
76 
77 /* Please do not change the size of this struct */
78 #define EVENT_RECORD_SIZE 64
79 struct event_record {
80   uint64_t reset_count;                 /* zeroed by Citadel power cycle */
81   uint64_t uptime_usecs;                /* since last Citadel reset */
82   uint32_t id;
83   uint32_t priority;
84   union {
85     /* id-specific information goes here */
86     struct {
87       uint32_t intr_sts[3];
88     } alert;
89     struct {
90       uint32_t rstsrc;
91       uint32_t exitpd;
92       uint32_t which0;
93       uint32_t which1;
94     } rebooted;
95     struct {
96       uint32_t upgrade_state;
97     } upgraded;
98     struct {
99       uint32_t alert_grp[4];
100       uint16_t camo_breaches[2];
101       uint16_t temp_min;
102       uint16_t temp_max;
103       uint32_t bus_err;
104     } alert_v2;
105 
106     /* uninterpreted */
107     union {
108       uint32_t w[10];
109       uint16_t h[20];
110       uint8_t b[40];
111     } raw;
112   } event;
113 } __packed;
114 /* Please do not change the size of this struct */
115 static_assert(sizeof(struct event_record) == EVENT_RECORD_SIZE,
116               "Muting the Immutable");
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif  /* __CROS_EC_INCLUDE_CITADEL_EVENTS_H */
123