1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2019-2022, Linaro Limited 4 */ 5 6 #include <arch_main.h> 7 #include <config.h> 8 #include <initcall.h> 9 #include <kernel/panic.h> 10 #include <mm/core_memprot.h> 11 #include <optee_scmi.h> 12 #include <scmi/scmi_server.h> 13 14 /* 15 * OP-TEE helper function exported to SCP-firmware 16 */ 17 uintptr_t smt_phys_to_virt(uintptr_t pa, size_t sz, bool shmem_is_secure) 18 { 19 if (shmem_is_secure) 20 return (uintptr_t)phys_to_virt(pa, MEM_AREA_IO_SEC, sz); 21 else 22 return (uintptr_t)phys_to_virt(pa, MEM_AREA_IO_NSEC, sz); 23 } 24 25 /* 26 * SCMI server APIs exported to OP-TEE core 27 */ 28 int scmi_server_get_channels_count(void) 29 { 30 return scmi_get_devices_count(); 31 } 32 33 TEE_Result scmi_server_get_channel(unsigned int channel_id, int *handle) 34 { 35 int fwk_id = 0; 36 37 fwk_id = scmi_get_device(channel_id); 38 if (fwk_id < 0) 39 return TEE_ERROR_BAD_PARAMETERS; 40 41 if (handle) 42 *handle = fwk_id; 43 44 return TEE_SUCCESS; 45 } 46 47 TEE_Result scmi_server_smt_process_thread(unsigned int channel_id) 48 { 49 TEE_Result res = TEE_ERROR_GENERIC; 50 int fwk_id = 0; 51 52 res = scmi_server_get_channel(channel_id, &fwk_id); 53 if (!res) 54 scmi_process_mbx_smt(fwk_id); 55 56 return res; 57 } 58 59 TEE_Result scmi_server_msg_process_thread(unsigned int channel_id, 60 void *in_buf, size_t in_sz, 61 void *out_buf, size_t *out_sz) 62 { 63 TEE_Result res = TEE_ERROR_GENERIC; 64 int fwk_id = 0; 65 66 res = scmi_server_get_channel(channel_id, &fwk_id); 67 if (!res) 68 scmi_process_mbx_msg(fwk_id, in_buf, in_sz, out_buf, out_sz); 69 70 return res; 71 } 72 73 static TEE_Result scmi_server_initialize(void) 74 { 75 int rc = 0; 76 77 rc = scmi_arch_init(); 78 if (rc < 0) { 79 EMSG("SCMI server init failed: %d", rc); 80 panic(); 81 } 82 83 return TEE_SUCCESS; 84 } 85 86 boot_final(scmi_server_initialize); 87