// SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2019, STMicroelectronics * Copyright (c) 2021, Microchip */ #include #include #include #include #include static_assert(SMT_BUF_SLOT_SIZE <= CFG_SCMI_SHMEM_SIZE); register_phys_mem(MEM_AREA_IO_NSEC, CFG_SCMI_SHMEM_START, CFG_SCMI_SHMEM_SIZE); struct channel_resources { struct scmi_msg_channel *channel; }; static const struct channel_resources scmi_channel[] = { [0] = { .channel = &(struct scmi_msg_channel){ .shm_addr = { .pa = CFG_SCMI_SHMEM_START }, .shm_size = SMT_BUF_SLOT_SIZE, }, }, }; static const struct channel_resources *find_resource(unsigned int channel_id) { assert(channel_id < ARRAY_SIZE(scmi_channel)); return scmi_channel + channel_id; } struct scmi_msg_channel *plat_scmi_get_channel(unsigned int channel_id) { const size_t max_id = ARRAY_SIZE(scmi_channel); unsigned int confined_id = confine_array_index(channel_id, max_id); if (channel_id >= max_id) return NULL; return find_resource(confined_id)->channel; } static const char vendor[] = "Microchip"; static const char sub_vendor[] = ""; const char *plat_scmi_vendor_name(void) { return vendor; } const char *plat_scmi_sub_vendor_name(void) { return sub_vendor; } /* Currently supporting only SCMI Base protocol */ static const uint8_t plat_protocol_list[] = { SCMI_PROTOCOL_ID_CLOCK, 0 /* Null termination */ }; size_t plat_scmi_protocol_count(void) { return ARRAY_SIZE(plat_protocol_list) - 1; } const uint8_t *plat_scmi_protocol_list(unsigned int channel_id __unused) { return plat_protocol_list; } /* * Initialize platform SCMI resources */ static TEE_Result sam_init_scmi_server(void) { size_t i = 0; for (i = 0; i < ARRAY_SIZE(scmi_channel); i++) { const struct channel_resources *res = scmi_channel + i; struct scmi_msg_channel *chan = res->channel; /* Enforce non-secure shm mapped as device memory */ chan->shm_addr.va = (vaddr_t)phys_to_virt(chan->shm_addr.pa, MEM_AREA_IO_NSEC, 1); assert(chan->shm_addr.va); scmi_smt_init_agent_channel(chan); } return TEE_SUCCESS; } driver_init_late(sam_init_scmi_server);