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