b13929d4e5f446590c2dca0fddf30115419f573d
[firefly-linux-kernel-4.4.55.git] / arch / x86 / include / asm / tboot.h
1 /*
2  * tboot.h: shared data structure with tboot and kernel and functions
3  *          used by kernel for runtime support of Intel(R) Trusted
4  *          Execution Technology
5  *
6  * Copyright (c) 2006-2009, Intel Corporation
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #ifndef _ASM_TBOOT_H
24 #define _ASM_TBOOT_H
25
26 #include <acpi/acpi.h>
27
28 /* these must have the values from 0-5 in this order */
29 enum {
30         TB_SHUTDOWN_REBOOT = 0,
31         TB_SHUTDOWN_S5,
32         TB_SHUTDOWN_S4,
33         TB_SHUTDOWN_S3,
34         TB_SHUTDOWN_HALT,
35         TB_SHUTDOWN_WFS
36 };
37
38 #ifdef CONFIG_INTEL_TXT
39
40 /* used to communicate between tboot and the launched kernel */
41
42 #define TB_KEY_SIZE             64   /* 512 bits */
43
44 #define MAX_TB_MAC_REGIONS      32
45
46 struct tboot_mac_region {
47         u64  start;         /* must be 64 byte -aligned */
48         u32  size;          /* must be 64 byte -granular */
49 } __packed;
50
51 /* GAS - Generic Address Structure (ACPI 2.0+) */
52 struct tboot_acpi_generic_address {
53         u8  space_id;
54         u8  bit_width;
55         u8  bit_offset;
56         u8  access_width;
57         u64 address;
58 } __packed;
59
60 /*
61  * combines Sx info from FADT and FACS tables per ACPI 2.0+ spec
62  * (http://www.acpi.info/)
63  */
64 struct tboot_acpi_sleep_info {
65         struct tboot_acpi_generic_address pm1a_cnt_blk;
66         struct tboot_acpi_generic_address pm1b_cnt_blk;
67         struct tboot_acpi_generic_address pm1a_evt_blk;
68         struct tboot_acpi_generic_address pm1b_evt_blk;
69         u16 pm1a_cnt_val;
70         u16 pm1b_cnt_val;
71         u64 wakeup_vector;
72         u32 vector_width;
73         u64 kernel_s3_resume_vector;
74 } __packed;
75
76 /*
77  * shared memory page used for communication between tboot and kernel
78  */
79 struct tboot {
80         /*
81          * version 3+ fields:
82          */
83
84         /* TBOOT_UUID */
85         u8 uuid[16];
86
87         /* version number: 5 is current */
88         u32 version;
89
90         /* physical addr of tb_log_t log */
91         u32 log_addr;
92
93         /*
94          * physical addr of entry point for tboot shutdown and
95          * type of shutdown (TB_SHUTDOWN_*) being requested
96          */
97         u32 shutdown_entry;
98         u32 shutdown_type;
99
100         /* kernel-specified ACPI info for Sx shutdown */
101         struct tboot_acpi_sleep_info acpi_sinfo;
102
103         /* tboot location in memory (physical) */
104         u32 tboot_base;
105         u32 tboot_size;
106
107         /* memory regions (phys addrs) for tboot to MAC on S3 */
108         u8 num_mac_regions;
109         struct tboot_mac_region mac_regions[MAX_TB_MAC_REGIONS];
110
111
112         /*
113          * version 4+ fields:
114          */
115
116         /* symmetric key for use by kernel; will be encrypted on S3 */
117         u8 s3_key[TB_KEY_SIZE];
118
119
120         /*
121          * version 5+ fields:
122          */
123
124         /* used to 4byte-align num_in_wfs */
125         u8 reserved_align[3];
126
127         /* number of processors in wait-for-SIPI */
128         u32 num_in_wfs;
129 } __packed;
130
131 /*
132  * UUID for tboot data struct to facilitate matching
133  * defined as {663C8DFF-E8B3-4b82-AABF-19EA4D057A08} by tboot, which is
134  * represented as {} in the char array used here
135  */
136 #define TBOOT_UUID      {0xff, 0x8d, 0x3c, 0x66, 0xb3, 0xe8, 0x82, 0x4b, 0xbf,\
137                          0xaa, 0x19, 0xea, 0x4d, 0x5, 0x7a, 0x8}
138
139 extern struct tboot *tboot;
140
141 static inline int tboot_enabled(void)
142 {
143         return tboot != NULL;
144 }
145
146 extern void tboot_probe(void);
147 extern void tboot_create_trampoline(void);
148 extern void tboot_shutdown(u32 shutdown_type);
149 extern void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control);
150 extern int tboot_wait_for_aps(int num_aps);
151 extern struct acpi_table_header *tboot_get_dmar_table(
152                                       struct acpi_table_header *dmar_tbl);
153 extern int tboot_force_iommu(void);
154
155 #else     /* CONFIG_INTEL_TXT */
156
157 static inline int tboot_enabled(void)
158 {
159         return 0;
160 }
161
162 static inline void tboot_probe(void)
163 {
164 }
165
166 static inline void tboot_create_trampoline(void)
167 {
168 }
169
170 static inline void tboot_shutdown(u32 shutdown_type)
171 {
172 }
173
174 static inline void tboot_sleep(u8 sleep_state, u32 pm1a_control,
175                                u32 pm1b_control)
176 {
177 }
178
179 static inline int tboot_wait_for_aps(int num_aps)
180 {
181         return 0;
182 }
183
184 static inline struct acpi_table_header *tboot_get_dmar_table(
185                                         struct acpi_table_header *dmar_tbl)
186 {
187         return dmar_tbl;
188 }
189
190 static inline int tboot_force_iommu(void)
191 {
192         return 0;
193 }
194
195 #endif /* !CONFIG_INTEL_TXT */
196
197 #endif /* _ASM_TBOOT_H */