|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright (c) Bao Project and Contributors. All rights reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <platform.h> |
| 7 | + |
| 8 | +struct platform platform = { |
| 9 | + .cpu_num = 2, |
| 10 | + .region_num = 2, |
| 11 | + .regions = |
| 12 | + (struct mem_region[]){ |
| 13 | + { |
| 14 | + .base = 0x80000000, |
| 15 | + .size = 0x80000000, |
| 16 | + }, |
| 17 | + { |
| 18 | + .base = 0x880000000, |
| 19 | + .size = 0x80000000, |
| 20 | + }, |
| 21 | + }, |
| 22 | + .console = |
| 23 | + { |
| 24 | + .base = 0x02800000, |
| 25 | + }, |
| 26 | + .arch = |
| 27 | + { |
| 28 | + .gic = |
| 29 | + { |
| 30 | + .gicd_addr = 0x01800000, |
| 31 | + .gicr_addr = 0x01900000, |
| 32 | + .gicc_addr = 0x6f000000, |
| 33 | + .gich_addr = 0x6f010000, |
| 34 | + .gicv_addr = 0x6f020000, |
| 35 | + .maintenance_id = 25, |
| 36 | + }, |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +#ifndef GENERATING_DEFS |
| 41 | + |
| 42 | +static mbox_k3_sec_proxy_thread_desc sec_proxy_thread_desc[] = { |
| 43 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_0_SECURE, 0, 2, 30, 10, 20), |
| 44 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_1_SECURE, 5, 2, 30, 10, 20), |
| 45 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_2_NON_SECURE, 10, 2, 22, 2, |
| 46 | + 20), |
| 47 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_3_NON_SECURE, 15, 2, 7, 2, 5), |
| 48 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_4_NON_SECURE, 20, 2, 7, 2, 5), |
| 49 | + MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY(J721E_HOST_ID_MAIN_A72_CONTEXT_5_NON_SECURE, 55, 2, 7, 2, 5), |
| 50 | +}; |
| 51 | + |
| 52 | +static mbox_k3_sec_proxy_desc k3_sec_proxy = { |
| 53 | + .thread_inst = |
| 54 | + { |
| 55 | + .id = 0U, |
| 56 | + .rt_base = 0x0032400000U, |
| 57 | + .rt_size = 0x100000U, |
| 58 | + .scfg_base = 0x0032800000U, |
| 59 | + .scfg_size = 0x100000U, |
| 60 | + .data_base = 0x0032C00000, |
| 61 | + .data_size = 0x100000, |
| 62 | + .max_msg_size = TISCI_MSG_MAX_SIZE, |
| 63 | + }, |
| 64 | + .read_timeout_us = TISCI_MSG_TXN_TIMEOUT, |
| 65 | + .sec_proxy_thread_desc = sec_proxy_thread_desc, |
| 66 | + .num_threads = sizeof(sec_proxy_thread_desc) / sizeof(sec_proxy_thread_desc[0]), |
| 67 | +}; |
| 68 | + |
| 69 | +static int32_t platform_tisci_send(uint8_t chan_id, void* buffer, size_t len) |
| 70 | +{ |
| 71 | + return mbox_k3_sec_proxy_write(&k3_sec_proxy, chan_id, buffer, len); |
| 72 | +} |
| 73 | + |
| 74 | +static int32_t platform_tisci_recv(uint8_t chan_id, void* buffer, size_t len) |
| 75 | +{ |
| 76 | + return mbox_k3_sec_proxy_read(&k3_sec_proxy, chan_id, buffer, len); |
| 77 | +} |
| 78 | + |
| 79 | +static tisci_ctx tisci_context = { |
| 80 | + .ops = |
| 81 | + { |
| 82 | + .send = platform_tisci_send, |
| 83 | + .recv = platform_tisci_recv, |
| 84 | + }, |
| 85 | + .seq_id_lock = {0, 0}, |
| 86 | + .seq_id = 0U, |
| 87 | +}; |
| 88 | + |
| 89 | +void platform_default_init(void) |
| 90 | +{ |
| 91 | + if (cpu_is_master()) { |
| 92 | + cpu_sync_init(&cpu_glb_sync, platform.cpu_num); |
| 93 | + } |
| 94 | + |
| 95 | + mbox_k3_sec_proxy_init(&k3_sec_proxy); |
| 96 | + cpu_sync_barrier(&cpu_glb_sync); |
| 97 | + |
| 98 | + uint8_t cur_host_id = cpu_is_master() ? J721E_HOST_ID_MAIN_A72_CONTEXT_2_NON_SECURE : |
| 99 | + J721E_HOST_ID_MAIN_A72_CONTEXT_3_NON_SECURE; |
| 100 | + |
| 101 | + mbox_k3_sec_proxy_thread_desc* host_threads = |
| 102 | + mbox_k3_sec_proxy_get_thread_by_host_func(&k3_sec_proxy, cur_host_id, 0U); |
| 103 | + if (NULL == host_threads) { |
| 104 | + ERROR("platform init failed, no secure proxy threads found"); |
| 105 | + return; |
| 106 | + } |
| 107 | + |
| 108 | + /* probe all secure proxy threads owned by this host */ |
| 109 | + for (uint8_t func_iterator = 0U; func_iterator < MBOX_K3_SEC_PROXY_NUM_HOST_FUNCTIONS; |
| 110 | + func_iterator++) { |
| 111 | + int32_t probe_status = |
| 112 | + mbox_k3_sec_proxy_probe(&k3_sec_proxy, host_threads[func_iterator].sec_proxy_thread_id); |
| 113 | + if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR != probe_status) { |
| 114 | + ERROR("platform init failed, k3 secure_proxy_thread_%d probe status=%d", |
| 115 | + host_threads[func_iterator].sec_proxy_thread_id, probe_status); |
| 116 | + return; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + /* ping test to ensure that host<->sysfw pipeline is clean */ |
| 121 | + tisci_msg_version_rsp ping_rsp = { 0 }; |
| 122 | + int32_t ping_status = tisci_get_revision(&tisci_context, cur_host_id, |
| 123 | + host_threads[MBOX_K3_SEC_PROXY_HOST_FUNCTION_LOW_PRIORITY].sec_proxy_thread_id, |
| 124 | + host_threads[MBOX_K3_SEC_PROXY_HOST_FUNCTION_RESPONSE].sec_proxy_thread_id, &ping_rsp); |
| 125 | + if (TISCI_STATUS_CODE_NO_ERROR != ping_status) { |
| 126 | + ERROR("platform init failed, ping to sysfw failed, ping_status=%d", ping_status); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +#endif /* ifndef GENERATING_DEFS */ |
0 commit comments