1 /*
2  * tboot.h: shared data structure with MLE and kernel and functions
3  *          used by kernel for runtime support
4  *
5  * Copyright (c) 2006-2007, Intel Corporation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *   * Redistributions in binary form must reproduce the above
15  *     copyright notice, this list of conditions and the following
16  *     disclaimer in the documentation and/or other materials provided
17  *     with the distribution.
18  *   * Neither the name of the Intel Corporation nor the names of its
19  *     contributors may be used to endorse or promote products derived
20  *     from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 #ifndef __TBOOT_H__
38 #define __TBOOT_H__
39 
40 #include <xen/acpi.h>
41 
42 typedef struct __packed {
43   uint32_t    data1;
44   uint16_t    data2;
45   uint16_t    data3;
46   uint16_t    data4;
47   uint8_t     data5[6];
48 } uuid_t;
49 
50 /* used to communicate between tboot and the launched kernel (i.e. Xen) */
51 
52 #define TB_KEY_SIZE             64   /* 512 bits */
53 
54 #define MAX_TB_MAC_REGIONS      32
55 typedef struct __packed {
56     uint64_t  start;         /* must be 64 byte -aligned */
57     uint32_t  size;          /* must be 64 byte -granular */
58 } tboot_mac_region_t;
59 
60 /* GAS - Generic Address Structure (ACPI 2.0+) */
61 typedef struct __packed {
62 	uint8_t  space_id;
63 	uint8_t  bit_width;
64 	uint8_t  bit_offset;
65 	uint8_t  access_width;
66 	uint64_t address;
67 } tboot_acpi_generic_address_t;
68 
69 typedef struct __packed {
70     tboot_acpi_generic_address_t pm1a_cnt_blk;
71     tboot_acpi_generic_address_t pm1b_cnt_blk;
72     tboot_acpi_generic_address_t pm1a_evt_blk;
73     tboot_acpi_generic_address_t pm1b_evt_blk;
74     uint16_t pm1a_cnt_val;
75     uint16_t pm1b_cnt_val;
76     uint64_t wakeup_vector;
77     uint32_t vector_width;
78     uint64_t kernel_s3_resume_vector;
79 } tboot_acpi_sleep_info_t;
80 
81 typedef struct __packed {
82     /* version 3+ fields: */
83     uuid_t    uuid;              /* {663C8DFF-E8B3-4b82-AABF-19EA4D057A08} */
84     uint32_t  version;           /* Version number; currently supports 0.6 */
85     uint32_t  log_addr;          /* physical addr of tb_log_t log */
86     uint32_t  shutdown_entry;    /* entry point for tboot shutdown */
87     uint32_t  shutdown_type;     /* type of shutdown (TB_SHUTDOWN_*) */
88     tboot_acpi_sleep_info_t
89               acpi_sinfo;        /* where kernel put acpi sleep info in Sx */
90     uint32_t  tboot_base;        /* starting addr for tboot */
91     uint32_t  tboot_size;        /* size of tboot */
92     uint8_t   num_mac_regions;   /* number mem regions to MAC on S3 */
93                                  /* contig regions memory to MAC on S3 */
94     tboot_mac_region_t mac_regions[MAX_TB_MAC_REGIONS];
95     /* version 4+ fields: */
96                                  /* populated by tboot; will be encrypted */
97     uint8_t   s3_key[TB_KEY_SIZE];
98     /* version 5+ fields: */
99     uint8_t   reserved_align[3]; /* used to 4byte-align num_in_wfs */
100     uint32_t  num_in_wfs;        /* number of processors in wait-for-SIPI */
101     /* version 6+ fields: */
102     uint32_t  flags;
103     uint64_t  ap_wake_addr;      /* phys addr of kernel/VMM SIPI vector */
104     uint32_t  ap_wake_trigger;   /* kernel/VMM writes APIC ID to wake AP */
105 } tboot_shared_t;
106 
107 #define TB_SHUTDOWN_REBOOT      0
108 #define TB_SHUTDOWN_S5          1
109 #define TB_SHUTDOWN_S4          2
110 #define TB_SHUTDOWN_S3          3
111 #define TB_SHUTDOWN_HALT        4
112 
113 #define TB_FLAG_AP_WAKE_SUPPORT   0x00000001  /* kernel/VMM use INIT-SIPI-SIPI
114                                                  if clear, ap_wake_* if set */
115 
116 /* {663C8DFF-E8B3-4b82-AABF-19EA4D057A08} */
117 #define TBOOT_SHARED_UUID    { 0x663c8dff, 0xe8b3, 0x4b82, 0xaabf, \
118                                { 0x19, 0xea, 0x4d, 0x5, 0x7a, 0x8 } };
119 
120 extern tboot_shared_t *g_tboot_shared;
121 
122 #ifdef CONFIG_TBOOT
123 void tboot_probe(void);
124 void tboot_shutdown(uint32_t shutdown_type);
125 int tboot_in_measured_env(void);
126 int tboot_protect_mem_regions(void);
127 int tboot_parse_dmar_table(acpi_table_handler dmar_handler);
128 int tboot_s3_resume(void);
129 void tboot_s3_error(int error);
130 int tboot_wake_ap(int apicid, unsigned long sipi_vec);
131 #else
tboot_probe(void)132 static inline void tboot_probe(void) {}
tboot_shutdown(uint32_t shutdown_type)133 static inline void tboot_shutdown(uint32_t shutdown_type) {}
tboot_in_measured_env(void)134 static inline int tboot_in_measured_env(void) { return 0; }
tboot_protect_mem_regions(void)135 static inline int tboot_protect_mem_regions(void) { return 1; }
136 
tboot_parse_dmar_table(acpi_table_handler dmar_handler)137 static inline int tboot_parse_dmar_table(acpi_table_handler dmar_handler)
138 {
139     return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler);
140 }
141 
tboot_s3_resume(void)142 static inline int tboot_s3_resume(void) { return 0; }
tboot_s3_error(int error)143 static inline void tboot_s3_error(int error) {}
tboot_wake_ap(int apicid,unsigned long sipi_vec)144 static inline int tboot_wake_ap(int apicid, unsigned long sipi_vec)
145 {
146     return 1;
147 }
148 #endif /* CONFIG_TBOOT */
149 
150 #endif /* __TBOOT_H__ */
151 
152 /*
153  * Local variables:
154  * mode: C
155  * c-file-style: "BSD"
156  * c-basic-offset: 4
157  * tab-width: 4
158  * indent-tabs-mode: nil
159  * End:
160  */
161