• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description:  LOG MEMORY REGION SETUP MODULE
15  * Author:
16  * Create:  2018-10-15
17  */
18 
19 #include "stdbool.h"
20 #include "chip_core_definition.h"
21 #include "product.h"
22 #if (CORE == MASTER_BY_ALL) || (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == YES)
23 #include "securec.h"
24 #endif
25 #include "soc_osal.h"
26 #include "std_def.h"
27 #include "log_memory_definitions.h"
28 #include "common_def.h"
29 #include "log_memory_region.h"
30 
31 /*
32   *  Configuration parameters
33   */
34 #define CONTOL_BLOCK_LOGGING_LENGTH sizeof(log_memory_region_control_t)
35 
36 // Offsets from the start of the memory region
37 #if CORE_NUMS == 1
38 #define APPLICATION_CORE_LOGGING_OFFSET ((CONTOL_BLOCK_LOGGING_LENGTH))
39 #elif CHIP_WS53
40 #define CONTROL_CORE_LOGGING_OFFSET     (CONTOL_BLOCK_LOGGING_LENGTH)
41 #define APPLICATION_CORE_LOGGING_OFFSET ((CONTROL_CORE_LOGGING_OFFSET) + (CONTROL_LOGGING_LENGTH))
42 #else
43 #define BT_CORE_LOGGING_OFFSET          (CONTOL_BLOCK_LOGGING_LENGTH)
44 #define APPLICATION_CORE_LOGGING_OFFSET ((BT_CORE_LOGGING_OFFSET) + (BT_LOGGING_LENGTH))
45 // Fail compilation if they are not word aligned
46 cassert((BT_CORE_LOGGING_OFFSET & 0x3) == 0, LOG_MEMORY_REGION_C_);
47 cassert((APPLICATION_CORE_LOGGING_OFFSET & 0x3) == 0, LOG_MEMORY_REGION_C_);
48 #endif
49 #if CORE_NUMS > 2
50 #define HIFI_CORE_LOGGING_OFFSET        ((APPLICATION_CORE_LOGGING_OFFSET) + (APP_LOGGING_LENGTH))
51 #endif
52 #if defined(CHIP_LIBRA) && (CHIP_LIBRA != 0)
53 #define GNSS_CORE_LOGGING_OFFSET        ((HIFI_CORE_LOGGING_OFFSET) + (DSP_LOGGING_LENGTH))
54 #define SEC_CORE_LOGGING_OFFSET        ((GNSS_CORE_LOGGING_OFFSET) + (GNSS_LOGGING_LENGTH))
55 #endif
56 #define CONTOL_BLOCK_MASS_LENGTH        sizeof(massdata_memory_region_control_t)
57 
58 // Offsets from the start of the memory region
59 // no dsp mass data for now
60 #define BT_CORE_MASS_OFFSET             (MASSDATA_REGION_START + CONTOL_BLOCK_MASS_LENGTH)
61 #define APPLICATION_CORE_MASS_OFFSET    (BT_CORE_MASS_OFFSET + BT_MASSDATA_LENGTH)
62 
63 static bool g_log_inited = false;
64 
65 /*
66  *  Private function definitions
67  */
logger_security_initialize_control_block(void)68 static void logger_security_initialize_control_block(void)
69 {
70     // copy control block header
71     log_memory_region_control_t *initial_ctrl = (log_memory_region_control_t *)(uintptr_t)LOGGING_REGION_START;
72 #if CORE_NUMS == 1
73     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_0] = APPLICATION_CORE_LOGGING_OFFSET;
74 #else
75 #if CHIP_WS53
76     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_0] = CONTROL_CORE_LOGGING_OFFSET;
77 #else
78     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_0] = (uint32_t)BT_CORE_LOGGING_OFFSET;
79 #endif
80     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_1] = (uint32_t)APPLICATION_CORE_LOGGING_OFFSET;
81 #endif
82 #if CORE_NUMS > 2
83     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_2] = (uint32_t)HIFI_CORE_LOGGING_OFFSET;
84 #endif
85 #if defined(CHIP_LIBRA) && (CHIP_LIBRA != 0)
86     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_3] = GNSS_CORE_LOGGING_OFFSET;
87     initial_ctrl->offset[LOG_MEMORY_REGION_SECTION_4] = SEC_CORE_LOGGING_OFFSET;
88 #endif
89     initial_ctrl->length = LOGGING_REGION_LENGTH;
90 }
91 
92 /*
93   *  Public function definitions
94   */
95 // For some builds lint thinks it would be a good idea to move the prototype for this to be in this file
96 /* Initialise the logger_security module.
97  * Sets the shared memory ready for logging */
log_memory_region_init(void)98 void log_memory_region_init(void)
99 {
100     uint32_t irq = osal_irq_lock();
101     if (unlikely(g_log_inited)) {
102         osal_irq_restore(irq);
103         return;
104     }
105 #if CORE == MASTER_BY_ALL
106     memset_s((void *)(uintptr_t)LOGGING_REGION_START, LOGGING_REGION_LENGTH, 0, LOGGING_REGION_LENGTH);
107 #endif
108     logger_security_initialize_control_block();
109     g_log_inited = true;
110     osal_irq_restore(irq);
111 }
112 
113 #if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == YES)
massdata_memory_region_init(void)114 void massdata_memory_region_init(void)
115 {
116     memset_s((void *)(uintptr_t)MASSDATA_REGION_START, MASSDATA_REGION_LENGTH, 0, MASSDATA_REGION_LENGTH);
117     massdata_memory_region_control_t *mass_ctrl = (massdata_memory_region_control_t *)(uintptr_t)MASSDATA_REGION_START;
118 
119     mass_ctrl->region_num = MASS_MEMORY_REGION_MAX_NUMBER;
120     mass_ctrl->mem_len = MASSDATA_REGION_LENGTH;
121     mass_ctrl->section_control[MASS_MEMORY_REGION_SECTION_0].region_start = BT_CORE_MASS_OFFSET;
122     mass_ctrl->section_control[MASS_MEMORY_REGION_SECTION_0].region_len = BT_MASSDATA_LENGTH;
123 
124     mass_ctrl->section_control[MASS_MEMORY_REGION_SECTION_1].region_start = APPLICATION_CORE_MASS_OFFSET;
125     mass_ctrl->section_control[MASS_MEMORY_REGION_SECTION_1].region_len = APP_MASSDATA_LENGTH -
126                                                                           CONTOL_BLOCK_MASS_LENGTH;
127 
128     return;
129 }
130 #endif
131 
log_memory_is_init(void)132 bool log_memory_is_init(void)
133 {
134     return g_log_inited;
135 }