17
17
#include <asm/slaunch.h>
18
18
#include <asm/tpm.h>
19
19
20
+ /* SLB is 64k, 64k-aligned */
21
+ #define SKINIT_SLB_SIZE 0x10000
22
+ #define SKINIT_SLB_ALIGN 0x10000
23
+
20
24
/* These variables are initialized by the code near an entry point. */
21
25
bool __initdata slaunch_active ;
22
26
uint32_t __initdata slaunch_slrt ;
@@ -48,8 +52,28 @@ int __init slaunch_map_l2(unsigned long paddr, unsigned long size)
48
52
pages , PAGE_HYPERVISOR );
49
53
}
50
54
55
+ static uint32_t get_slb_start (void )
56
+ {
57
+ /*
58
+ * The runtime computation relies on size being a power of 2 and equal to
59
+ * alignment. Make sure these assumptions hold.
60
+ */
61
+ BUILD_BUG_ON (SKINIT_SLB_SIZE != SKINIT_SLB_ALIGN );
62
+ BUILD_BUG_ON (SKINIT_SLB_SIZE == 0 );
63
+ BUILD_BUG_ON ((SKINIT_SLB_SIZE & (SKINIT_SLB_SIZE - 1 )) != 0 );
64
+
65
+ /*
66
+ * Rounding any address within SLB down to alignment gives SLB base and
67
+ * SLRT is inside SLB on AMD.
68
+ */
69
+ return slaunch_slrt & ~(SKINIT_SLB_SIZE - 1 );
70
+ }
71
+
51
72
static struct slr_table * get_slrt (void )
52
73
{
74
+ bool intel_cpu = (boot_cpu_data .x86_vendor == X86_VENDOR_INTEL );
75
+ uint16_t slrt_architecture = intel_cpu ? SLR_INTEL_TXT : SLR_AMD_SKINIT ;
76
+
53
77
struct slr_table * slrt = __va (slaunch_slrt );
54
78
55
79
slaunch_map_l2 (slaunch_slrt , PAGE_SIZE );
@@ -59,9 +83,9 @@ static struct slr_table *get_slrt(void)
59
83
/* XXX: are newer revisions allowed? */
60
84
if ( slrt -> revision != SLR_TABLE_REVISION )
61
85
panic ("SLRT is of unsupported revision: %#04x!\n" , slrt -> revision );
62
- if ( slrt -> architecture != SLR_INTEL_TXT )
63
- panic ("SLRT is for unexpected architecture: %#04x!\n" ,
64
- slrt -> architecture );
86
+ if ( slrt -> architecture != slrt_architecture )
87
+ panic ("SLRT is for unexpected architecture: %#04x != %#04x !\n" ,
88
+ slrt -> architecture , slrt_architecture );
65
89
if ( slrt -> size > slrt -> max_size )
66
90
panic ("SLRT is larger than its max size: %#08x > %#08x!\n" ,
67
91
slrt -> size , slrt -> max_size );
@@ -80,7 +104,10 @@ void __init slaunch_map_mem_regions(void)
80
104
slaunch_map_l2 (TPM_TIS_BASE , TPM_TIS_SIZE );
81
105
82
106
/* Vendor-specific part. */
83
- txt_map_mem_regions ();
107
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
108
+ txt_map_mem_regions ();
109
+ else if ( boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
110
+ slaunch_map_l2 (get_slb_start (), SKINIT_SLB_SIZE );
84
111
85
112
find_evt_log (get_slrt (), & evt_log_addr , & evt_log_size );
86
113
if ( evt_log_addr != NULL )
@@ -106,7 +133,18 @@ void __init slaunch_reserve_mem_regions(void)
106
133
}
107
134
108
135
/* Vendor-specific part. */
109
- txt_reserve_mem_regions ();
136
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
137
+ {
138
+ txt_reserve_mem_regions ();
139
+ }
140
+ else if ( boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
141
+ {
142
+ uint64_t slb_start = get_slb_start ();
143
+ uint64_t slb_end = slb_start + SKINIT_SLB_SIZE ;
144
+ printk ("SLAUNCH: reserving SLB (%#lx - %#lx)\n" , slb_start , slb_end );
145
+ rc = reserve_e820_ram (& e820_raw , slb_start , slb_end );
146
+ BUG_ON (rc == 0 );
147
+ }
110
148
}
111
149
112
150
void slaunch_measure_slrt (void )
@@ -119,20 +157,41 @@ void slaunch_measure_slrt(void)
119
157
* In revision one of the SLRT, only platform-specific info table is
120
158
* measured.
121
159
*/
122
- struct slr_entry_intel_info tmp ;
123
- struct slr_entry_intel_info * entry ;
160
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
161
+ {
162
+ struct slr_entry_intel_info tmp ;
163
+ struct slr_entry_intel_info * entry ;
124
164
125
- entry = (struct slr_entry_intel_info * )
126
- slr_next_entry_by_tag (slrt , NULL , SLR_ENTRY_INTEL_INFO );
127
- if ( entry == NULL )
128
- panic ("SLRT is missing Intel-specific information!\n" );
165
+ entry = (struct slr_entry_intel_info * )
166
+ slr_next_entry_by_tag (slrt , NULL , SLR_ENTRY_INTEL_INFO );
167
+ if ( entry == NULL )
168
+ panic ("SLRT is missing Intel-specific information!\n" );
129
169
130
- tmp = * entry ;
131
- tmp .boot_params_base = 0 ;
132
- tmp .txt_heap = 0 ;
170
+ tmp = * entry ;
171
+ tmp .boot_params_base = 0 ;
172
+ tmp .txt_heap = 0 ;
133
173
134
- tpm_hash_extend (DRTM_LOC , DRTM_DATA_PCR , (uint8_t * )& tmp ,
135
- sizeof (tmp ), DLE_EVTYPE_SLAUNCH , NULL , 0 );
174
+ tpm_hash_extend (DRTM_LOC , DRTM_DATA_PCR , (uint8_t * )& tmp ,
175
+ sizeof (tmp ), DLE_EVTYPE_SLAUNCH , NULL , 0 );
176
+ }
177
+ else if ( boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
178
+ {
179
+ struct slr_entry_amd_info tmp ;
180
+ struct slr_entry_amd_info * entry ;
181
+
182
+ entry = (struct slr_entry_amd_info * )
183
+ slr_next_entry_by_tag (slrt , NULL , SLR_ENTRY_AMD_INFO );
184
+ if ( entry == NULL )
185
+ panic ("SLRT is missing AMD-specific information!\n" );
186
+
187
+ tmp = * entry ;
188
+ tmp .next = 0 ;
189
+ tmp .slrt_base = 0 ;
190
+ tmp .boot_params_base = 0 ;
191
+
192
+ tpm_hash_extend (DRTM_LOC , DRTM_DATA_PCR , (uint8_t * )& tmp ,
193
+ sizeof (tmp ), DLE_EVTYPE_SLAUNCH , NULL , 0 );
194
+ }
136
195
}
137
196
else
138
197
{
0 commit comments