1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright 2022 NXP 4 */ 5 6 #include <riscv.h> 7 #include <sbi.h> 8 9 /** 10 * sbi_probe_extension() - Check if an SBI extension ID is supported or not. 11 * @extid: The extension ID to be probed. 12 * 13 * Return: 1 or an extension specific nonzero value if yes, 0 otherwise. 14 */ 15 int sbi_probe_extension(int extid) 16 { 17 struct sbiret ret = { }; 18 19 ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, extid); 20 if (!ret.error) 21 return ret.value; 22 23 return 0; 24 } 25 26 /** 27 * sbi_console_putchar() - Writes given character to the console device. 28 * @ch: The data to be written to the console. 29 */ 30 void sbi_console_putchar(int ch) 31 { 32 sbi_ecall(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, ch); 33 } 34 35 /** 36 * sbi_dbcn_write_byte() - Write byte to debug console 37 * @ch: Byte to be written 38 * 39 * Return: SBI error code (SBI_SUCCESS = 0 on success) 40 */ 41 int sbi_dbcn_write_byte(unsigned char ch) 42 { 43 struct sbiret ret = { }; 44 45 ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, ch); 46 return ret.error; 47 } 48 49 /** 50 * sbi_hsm_hart_start() - Start target hart at OP-TEE entry in S-mode 51 * @hartid: Target hart ID 52 * @start_addr: Physical address of OP-TEE entry 53 * @arg: opaque parameter, typically used as the physical 54 * address of device-tree passed via @arg->a1 55 * 56 * Return: SBI error code (SBI_SUCCESS = 0 on success) 57 */ 58 int sbi_hsm_hart_start(uint32_t hartid, paddr_t start_addr, unsigned long arg) 59 { 60 struct sbiret ret = { }; 61 62 ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START, hartid, start_addr, 63 arg); 64 65 return ret.error; 66 } 67 68 /** 69 * sbi_hsm_hart_get_status() - Get the current HSM state of given hart 70 * @hartid: Target hart ID 71 * @status: Pointer to store HSM state 72 * 73 * Return: SBI error code (SBI_SUCCESS = 0 on success) 74 */ 75 int sbi_hsm_hart_get_status(uint32_t hartid, enum sbi_hsm_hart_state *status) 76 { 77 struct sbiret ret = { }; 78 79 ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_GET_STATUS, hartid); 80 81 if (ret.error) 82 return ret.error; 83 84 *status = ret.value; 85 return SBI_SUCCESS; 86 } 87