1  /* SPDX-License-Identifier: GPL-2.0-only */
2  /*
3   * tboot.h: shared data structure with tboot and kernel and functions
4   *          used by kernel for runtime support of Intel(R) Trusted
5   *          Execution Technology
6   *
7   * Copyright (c) 2006-2009, Intel Corporation
8   */
9  
10  #ifndef _LINUX_TBOOT_H
11  #define _LINUX_TBOOT_H
12  
13  /* these must have the values from 0-5 in this order */
14  enum {
15  	TB_SHUTDOWN_REBOOT = 0,
16  	TB_SHUTDOWN_S5,
17  	TB_SHUTDOWN_S4,
18  	TB_SHUTDOWN_S3,
19  	TB_SHUTDOWN_HALT,
20  	TB_SHUTDOWN_WFS
21  };
22  
23  #ifdef CONFIG_INTEL_TXT
24  #include <linux/acpi.h>
25  /* used to communicate between tboot and the launched kernel */
26  
27  #define TB_KEY_SIZE             64   /* 512 bits */
28  
29  #define MAX_TB_MAC_REGIONS      32
30  
31  struct tboot_mac_region {
32  	u64  start;         /* must be 64 byte -aligned */
33  	u32  size;          /* must be 64 byte -granular */
34  } __packed;
35  
36  /* GAS - Generic Address Structure (ACPI 2.0+) */
37  struct tboot_acpi_generic_address {
38  	u8  space_id;
39  	u8  bit_width;
40  	u8  bit_offset;
41  	u8  access_width;
42  	u64 address;
43  } __packed;
44  
45  /*
46   * combines Sx info from FADT and FACS tables per ACPI 2.0+ spec
47   * (https://uefi.org/specifications)
48   */
49  struct tboot_acpi_sleep_info {
50  	struct tboot_acpi_generic_address pm1a_cnt_blk;
51  	struct tboot_acpi_generic_address pm1b_cnt_blk;
52  	struct tboot_acpi_generic_address pm1a_evt_blk;
53  	struct tboot_acpi_generic_address pm1b_evt_blk;
54  	u16 pm1a_cnt_val;
55  	u16 pm1b_cnt_val;
56  	u64 wakeup_vector;
57  	u32 vector_width;
58  	u64 kernel_s3_resume_vector;
59  } __packed;
60  
61  /*
62   * shared memory page used for communication between tboot and kernel
63   */
64  struct tboot {
65  	/*
66  	 * version 3+ fields:
67  	 */
68  
69  	/* TBOOT_UUID */
70  	u8 uuid[16];
71  
72  	/* version number: 5 is current */
73  	u32 version;
74  
75  	/* physical addr of tb_log_t log */
76  	u32 log_addr;
77  
78  	/*
79  	 * physical addr of entry point for tboot shutdown and
80  	 * type of shutdown (TB_SHUTDOWN_*) being requested
81  	 */
82  	u32 shutdown_entry;
83  	u32 shutdown_type;
84  
85  	/* kernel-specified ACPI info for Sx shutdown */
86  	struct tboot_acpi_sleep_info acpi_sinfo;
87  
88  	/* tboot location in memory (physical) */
89  	u32 tboot_base;
90  	u32 tboot_size;
91  
92  	/* memory regions (phys addrs) for tboot to MAC on S3 */
93  	u8 num_mac_regions;
94  	struct tboot_mac_region mac_regions[MAX_TB_MAC_REGIONS];
95  
96  
97  	/*
98  	 * version 4+ fields:
99  	 */
100  
101  	/* symmetric key for use by kernel; will be encrypted on S3 */
102  	u8 s3_key[TB_KEY_SIZE];
103  
104  
105  	/*
106  	 * version 5+ fields:
107  	 */
108  
109  	/* used to 4byte-align num_in_wfs */
110  	u8 reserved_align[3];
111  
112  	/* number of processors in wait-for-SIPI */
113  	u32 num_in_wfs;
114  } __packed;
115  
116  /*
117   * UUID for tboot data struct to facilitate matching
118   * defined as {663C8DFF-E8B3-4b82-AABF-19EA4D057A08} by tboot, which is
119   * represented as {} in the char array used here
120   */
121  #define TBOOT_UUID	{0xff, 0x8d, 0x3c, 0x66, 0xb3, 0xe8, 0x82, 0x4b, 0xbf,\
122  			 0xaa, 0x19, 0xea, 0x4d, 0x5, 0x7a, 0x8}
123  
124  bool tboot_enabled(void);
125  extern void tboot_probe(void);
126  extern void tboot_shutdown(u32 shutdown_type);
127  extern struct acpi_table_header *tboot_get_dmar_table(
128  				      struct acpi_table_header *dmar_tbl);
129  
130  #else
131  
132  #define tboot_enabled()			0
133  #define tboot_probe()			do { } while (0)
134  #define tboot_shutdown(shutdown_type)	do { } while (0)
135  #define tboot_sleep(sleep_state, pm1a_control, pm1b_control)	\
136  					do { } while (0)
137  #define tboot_get_dmar_table(dmar_tbl)	(dmar_tbl)
138  
139  #endif /* !CONFIG_INTEL_TXT */
140  
141  #endif /* _LINUX_TBOOT_H */
142