blob: 623762ad0ed3b5cd0bf391698a866d8ff77c5a8e [file] [log] [blame]
Martin Roth87bbeac2022-10-06 15:52:38 -06001/*****************************************************************************
2 *
3 * Copyright (c) 2022, Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 ***************************************************************************/
29
Martin Roth20646cd2023-01-04 21:27:06 -070030/* TODO: Update for Phoenix */
Martin Roth87bbeac2022-10-06 15:52:38 -060031
32#ifndef _BL_SYSCALL_PUBLIC_H_
33#define _BL_SYSCALL_PUBLIC_H_
34
35#include <stdint.h>
36
37#define SVC_EXIT 0x00
38#define SVC_ENTER 0x02
39#define SVC_VERSTAGE_CMD 0x3A
40
41enum verstage_cmd_id {
42 CMD_SHA = 1,
43 CMD_MODEXP,
44 CMD_DEBUG_PRINT,
45 CMD_DEBUG_PRINT_EX,
46 CMD_UPDATE_PSP_BIOS_DIR,
47 CMD_GET_SPI_INFO,
48 CMD_MAP_SPIROM_DEVICE,
49 CMD_UNMAP_SPIROM_DEVICE,
50 CMD_READ_TIMER_VAL,
51 CMD_DELAY_IN_MICRO_SECONDS,
52 CMD_RESET_SYSTEM,
53 CMD_GET_BOOT_MODE,
54 CMD_COPY_DATA_FROM_UAPP,
55 CMD_MAP_FCH_IO_DEVICE,
56 CMD_UNMAP_FCH_IO_DEVICE,
57 CMD_CCP_DMA,
58 CMD_SET_PLATFORM_BOOT_MODE,
59 CMD_SET_FW_HASH_TABLE,
Karthikeyan Ramasubramanian0507e062023-06-01 14:45:41 -060060 CMD_GET_PREV_BOOT_STATUS,
61 CMD_GET_HSP_SECURE_STATE,
62 CMD_WRITE_POSTCODE,
Martin Roth87bbeac2022-10-06 15:52:38 -060063};
64
65struct mod_exp_params {
66 char *pExponent; // Exponent address
67 unsigned int ExpSize; // Exponent size in bytes
68 char *pModulus; // Modulus address
69 unsigned int ModulusSize; // Modulus size in bytes
70 char *pMessage; // Message address, same size as ModulusSize
71 char *pOutput; // Output address; Must be big enough to hold the
72 // data of ModulusSize
73};
74
75enum psp_boot_mode {
76 PSP_BOOT_MODE_S0 = 0x0,
77 PSP_BOOT_MODE_S0i3_RESUME = 0x1,
78 PSP_BOOT_MODE_S3_RESUME = 0x2,
79 PSP_BOOT_MODE_S4 = 0x3,
80 PSP_BOOT_MODE_S5_COLD = 0x4,
81 PSP_BOOT_MODE_S5_WARM = 0x5,
82};
83
84enum reset_type
85{
86 RESET_TYPE_COLD = 0,
87 RESET_TYPE_WARM = 1,
88 RESET_TYPE_MAX = 2,
89};
90
91enum fch_io_device {
92 FCH_IO_DEVICE_SPI,
93 FCH_IO_DEVICE_I2C,
94 FCH_IO_DEVICE_GPIO,
95 FCH_IO_DEVICE_ESPI,
96 FCH_IO_DEVICE_IOMUX,
97 FCH_IO_DEVICE_MISC,
98 FCH_IO_DEVICE_AOAC,
99 FCH_IO_DEVICE_IOPORT,
Karthikeyan Ramasubramanian0507e062023-06-01 14:45:41 -0600100 FCH_IO_DEVICE_UART,
Martin Roth87bbeac2022-10-06 15:52:38 -0600101 FCH_IO_DEVICE_END,
102};
103
104enum fch_i2c_controller_id {
105 FCH_I2C_CONTROLLER_ID_0 = 0,
106 FCH_I2C_CONTROLLER_ID_1 = 1,
107 FCH_I2C_CONTROLLER_ID_2 = 2,
108 FCH_I2C_CONTROLLER_ID_3 = 3,
109 FCH_I2C_CONTROLLER_ID_MAX,
110};
111
Karthikeyan Ramasubramanian0507e062023-06-01 14:45:41 -0600112enum fch_uart_id {
113 FCH_UART_ID_0 = 0,
114 FCH_UART_ID_1 = 1,
115 FCH_UART_ID_MAX,
116};
117
Martin Roth87bbeac2022-10-06 15:52:38 -0600118struct spirom_info {
119 void *SpiBiosSysHubBase;
120 void *SpiBiosSmnBase;
121 uint32_t SpiBiosSize;
122};
123
124enum psp_timer_type {
125 PSP_TIMER_TYPE_CHRONO = 0,
126 PSP_TIMER_TYPE_SECURE_RTC = 1,
127 PSP_TIMER_TYPE_MAX = 2,
128};
129
130/* SHA types same as ccp SHA type in crypto.h */
131enum sha_type {
132 SHA_TYPE_256,
133 SHA_TYPE_384
134};
135
136/* All SHA operation supported */
137enum sha_operation_mode {
138 SHA_GENERIC
139};
140
141/* SHA Supported Data Structures */
142struct sha_generic_data {
143 enum sha_type SHAType;
144 uint8_t *Data;
145 uint32_t DataLen;
146 uint32_t DataMemType;
147 uint8_t *Digest;
148 uint32_t DigestLen;
149 uint8_t *IntermediateDigest;
150 uint32_t IntermediateMsgLen;
151 uint32_t Init;
152 uint32_t Eom;
153};
154
155/*
156 * This is state that PSP manages internally.
157 * We only report BOOT_MODE_DEVELOPER or BOOT_MODE_NORMAL in verstage.
158 */
159enum chrome_platform_boot_mode
160{
161 NON_CHROME_BOOK_BOOT_MODE = 0x0,
162 CHROME_BOOK_BOOT_MODE_UNSIGNED_VERSTAGE = 0x1,
163 CHROME_BOOK_BOOT_MODE_NORMAL = 0x2,
164 CHROME_BOOK_BOOT_MODE_DEVELOPER = 0x3,
165 CHROME_BOOK_BOOT_MODE_TYPE_MAX_LIMIT = 0x4, // used for boundary check
166};
167
168struct psp_fw_entry_hash_256 {
169 uint16_t fw_type;
170 uint16_t sub_type;
171 uint8_t sha[32];
172} __packed;
173
174struct psp_fw_entry_hash_384 {
175 uint16_t fw_type;
176 uint16_t sub_type;
177 uint8_t sha[48];
178} __packed;
179
180struct psp_fw_hash_table {
181 uint16_t version; // Version of psp_fw_hash_table, Start with 0.
182 uint16_t no_of_entries_256;
183 uint16_t no_of_entries_384;
184 struct psp_fw_entry_hash_256 *fw_hash_256;
185 struct psp_fw_entry_hash_384 *fw_hash_384;
186} __packed;
187
188/*
189 * Exit to the main Boot Loader. This does not return back to user application.
190 *
191 * Parameters:
192 * status - either Ok or error code defined by AGESA
193 */
194void svc_exit(uint32_t status);
195
196/* Print debug message into serial console.
197 *
198 * Parameters:
199 * string - null-terminated string
200 */
201void svc_debug_print(const char *string);
202
203/* Print 4 DWORD values in hex to serial console
204 *
205 * Parameters:
206 * dword0...dword3 - 32-bit DWORD to print
207 */
208void svc_debug_print_ex(uint32_t dword0,
209 uint32_t dword1, uint32_t dword2, uint32_t dword3);
210
211/* Description - Returns the current boot mode from the enum psp_boot_mode found in
212 * bl_public.h.
213 *
214 * Inputs - boot_mode - Output parameter passed in R0
215 *
216 * Outputs - The boot mode in boot_mode.
217 * See Return Values.
218 *
219 * Return Values - BL_OK
220 * BL_ERR_NULL_PTR
221 * Other BL_ERRORs lofted up from called functions
222 */
223uint32_t svc_get_boot_mode(uint32_t *boot_mode);
224
225/* Add delay in micro seconds
226 *
227 * Parameters:
228 * delay - required delay value in microseconds
229 *
230 * Return value: NONE
231 */
232void svc_delay_in_usec(uint32_t delay);
233
234/* Get the SPI-ROM information
235 *
236 * Parameters:
237 * spi_rom_iInfo - SPI-ROM information
238 *
239 * Return value: BL_OK or error code
240 */
241uint32_t svc_get_spi_rom_info(struct spirom_info *spi_rom_info);
242
243/* Map the FCH IO device register space (SPI/I2C/GPIO/eSPI/etc...)
244 *
245 * Parameters:
246 * io_device - ID for respective FCH IO controller register space to be mapped
247 * arg1 - Based on IODevice ID, interpretation of this argument changes.
248 * arg2 - Based on IODevice ID, interpretation of this argument changes.
249 * io_device_axi_addr - AXI address for respective FCH IO device register space
250 *
251 * Return value: BL_OK or error code
252 */
253uint32_t svc_map_fch_dev(enum fch_io_device io_device,
254 uint32_t arg1, uint32_t arg2, void **io_device_axi_addr);
255
256/* Unmap the FCH IO device register space mapped earlier using Svc_MapFchIODevice()
257 *
258 * Parameters:
259 * io_device - ID for respective FCH IO controller register space to be unmapped
260 * io_device_addr - AXI address for respective FCH IO device register space
261 *
262 * Return value: BL_OK or error code
263 */
264uint32_t svc_unmap_fch_dev(enum fch_io_device io_device,
265 void *io_device_axi_addr);
266
267/* Map the SPIROM FLASH device address space
268 *
269 * Parameters:
270 * SpiRomAddr - Address in SPIROM tobe mapped (SMN based)
271 * size - Size to be mapped
272 * pSpiRomAddrAxi - Mapped address in AXI space
273 *
274 * Return value: BL_OK or error code
275 */
276uint32_t svc_map_spi_rom(void *spi_rom_addr,
277 uint32_t size, void **spi_rom_axi_addr);
278
279/* Unmap the SPIROM FLASH device address space mapped earlier using Svc_MapSpiRomDevice()
280 *
281 * Parameters:
282 * pSpiRomAddrAxi - Address in AXI address space previously mapped
283 *
284 * Return value: BL_OK or error code
285 */
286uint32_t svc_unmap_spi_rom(void *spi_rom_addr);
287
288/* Updates the offset at which PSP or BIOS Directory can be found in the
289 * SPI flash
290 *
291 * Parameters:
292 * psp_dir_offset - [in/out] Offset at which PSP Directory can be
293 * found in the SPI Flash. Same pointer is used
294 * to return the offset in case of GET operation
295 * bios_dir_offset - [in/out] Offset at which BIOS Directory can be
296 * found in the SPI Flash. Same pointer is used
297 * to return the offset in case of GET operation
298 *
299 * Return value: BL_OK or error code
300 */
301uint32_t svc_update_psp_bios_dir(uint32_t *psp_dir_offset,
302 uint32_t *bios_dir_offset);
303
304/* Copies the data that is shared by verstage to the PSP BL owned memory
305 *
306 * Parameters:
307 * address - Address in UAPP controlled/owned memory
308 * size - Total size of memory to copy (max 16Kbytes)
309 */
310uint32_t svc_save_uapp_data(void *address, uint32_t size);
311
312/*
313 * Read timer raw (currently CHRONO and RTC) value
314 *
315 * Parameters:
316 * type - [in] Type of timer UAPP would like to read from
317 * (currently CHRONO and RTC)
318 * counter_value - [out] return the raw counter value read from
319 * RTC or CHRONO_LO/HI counter register
320 -----------------------------------------------------------------------------*/
321uint32_t svc_read_timer_val(enum psp_timer_type type, uint64_t *counter_value);
322
323/*
324 * Reset the system
325 *
326 * Parameters:
327 * reset_type - Cold or Warm reset
328 */
329uint32_t svc_reset_system(enum reset_type reset_type);
330
331/*
332 * Write postcode to Port-80
333 *
334 * Parameters:
335 * postcode - Postcode value to be written on port-80h
336 */
337uint32_t svc_write_postcode(uint32_t postcode);
338
339/*
340 * Generic SHA call for SHA, SHA_OTP, SHA_HMAC
341 */
342uint32_t svc_crypto_sha(struct sha_generic_data *sha_op, enum sha_operation_mode sha_mode);
343
344/*
345 * Calculate ModEx
346 *
347 * Parameters:
348 * mod_exp_param - ModExp parameters
349 *
350 * Return value: BL_OK or error code
351 */
352uint32_t svc_modexp(struct mod_exp_params *mod_exp_param);
353
354/*
355 * Copies the data from source to destination using ccp
356 *
357 * Parameters:
358 * Source Address - SPI ROM offset
359 * Destination Address - Address in Verstage memory
360 * Size - Total size to copy
361 *
362 * Return value: BL_OK or error code
363 */
364uint32_t svc_ccp_dma(uint32_t spi_rom_offset, void *dest, uint32_t size);
365
366/*
367 * Get the Platform boot mode from verstage. Normal or developer
368 *
369 * Parameters:
370 * - boot mode
371 -----------------------------------------------------------------------------*/
372uint32_t svc_set_platform_boot_mode(enum chrome_platform_boot_mode boot_mode);
373
374/*
375 * Set the PSP FW hash table.
376 *
377 * Parameters:
378 * - hash_table - Table of hash for each PSP binary signed against SoC chain of trust
379 *
380 * Return value: BL_OK or error code
381 */
382uint32_t svc_set_fw_hash_table(struct psp_fw_hash_table *hash_table);
383
Karthikeyan Ramasubramanian0507e062023-06-01 14:45:41 -0600384/* Get the previous boot status.
385 *
386 * Parameters:
387 * - boot_status - Address where the boot status is read into
388 *
389 * Return value: BL_OK or error code
390 */
391uint32_t svc_get_prev_boot_status(uint32_t *boot_status);
392
393/* Get HSP Secure state
394 *
395 * Parameters:
396 * - hsp_secure_state - Address where the state info is read into
397 *
398 * Return value: BL_OK or error code
399 */
400uint32_t svc_get_hsp_secure_state(uint32_t *hsp_secure_state);
401
Martin Roth87bbeac2022-10-06 15:52:38 -0600402/* C entry point for the Bootloader Userspace Application */
403void Main(void);
404
405#endif /* _BL_SYSCALL__PUBLIC_H_ */