rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2018 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * mer_kernel.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MERTOS |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * Declare kernel related structure and API. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *****************************************************************************/ |
| 55 | #ifndef _MER_KERNEL_H_ |
| 56 | #define _MER_KERNEL_H_ |
| 57 | |
| 58 | #include "mer_kernel_config_public.h" |
| 59 | #include "mer_service_types.h" |
| 60 | #include "mer_config_public.h" |
| 61 | |
| 62 | #include "mips_ia_utils_public.h" |
| 63 | |
| 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | // Macro |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | #define MER_KERNEL_SYSTEM_STACK_SIZE (8192) |
| 68 | #define MER_KERNEL_ORIGIN_JOB 0x0 |
| 69 | #define MER_KERNEL_JOB_SWITCHED 0x1 |
| 70 | #define MER_KERNEL_OS_INTERRUPT 0x2 |
| 71 | |
| 72 | /* For iA, according to ABI, stack should at least align 8 byte */ |
| 73 | /* For shaolin, according to ABI, stack should at least align 16 byte */ |
| 74 | /* For watchpoint, the minimal protection interval should be at least 32 byte */ |
| 75 | /* So we use the L.C.M: 32 */ |
| 76 | #define MER_KERNEL_STACK_ALIGN 32 |
| 77 | |
| 78 | #if !defined(__MER_CONFIG_ENABLE__) |
| 79 | #error "must include mer_config_public.h" |
| 80 | #endif /* __MER_CONFIG_ENABLE__ */ |
| 81 | |
| 82 | #if defined(__MER_CONFIG_USE_SYSTEM_STACK_IN_INIT__) |
| 83 | #define mer_kernel_system_stack_vpe0 SYS_Stack_Pool_CORE0_VPE0_TC0 |
| 84 | #define mer_kernel_system_stack_vpe1 SYS_Stack_Pool_CORE0_VPE1_TC2 |
| 85 | #define mer_kernel_system_stack_vpe2 SYS_Stack_Pool_CORE0_VPE2_TC4 |
| 86 | #define mer_kernel_system_stack_vpe3 SYS_Stack_Pool_CORE1_VPE0_TC0 |
| 87 | #define mer_kernel_system_stack_vpe4 SYS_Stack_Pool_CORE1_VPE1_TC2 |
| 88 | #define mer_kernel_system_stack_vpe5 SYS_Stack_Pool_CORE1_VPE2_TC4 |
| 89 | #define mer_kernel_system_stack_vpe6 SYS_Stack_Pool_CORE2_VPE0_TC0 |
| 90 | #define mer_kernel_system_stack_vpe7 SYS_Stack_Pool_CORE2_VPE1_TC2 |
| 91 | #define mer_kernel_system_stack_vpe8 SYS_Stack_Pool_CORE2_VPE2_TC4 |
| 92 | #define mer_kernel_system_stack_vpe9 SYS_Stack_Pool_CORE3_VPE0_TC0 |
| 93 | #define mer_kernel_system_stack_vpe10 SYS_Stack_Pool_CORE3_VPE1_TC2 |
| 94 | #define mer_kernel_system_stack_vpe11 SYS_Stack_Pool_CORE3_VPE2_TC4 |
| 95 | #endif |
| 96 | |
| 97 | |
| 98 | |
| 99 | /* The threshold (in micro second) that a preempted task or dpc being migrated to other VPE */ |
| 100 | //#define MER_KERNEL_JOB_MIGRATION_THRESHOLD 200 |
| 101 | #define MER_KERNEL_JOB_MIGRATION_THRESHOLD 0xFFFFFFFF |
| 102 | |
| 103 | #if defined(__MER_KERNEL_USE_MIPS_CP0_CONTEXT_REG__) |
| 104 | |
| 105 | #define MER_KERNEL_GET_INTERRUPT_COUNT_ASM(reg) \ |
| 106 | mfc0 reg, $4, 2 |
| 107 | |
| 108 | #define MER_KERNEL_GET_INTERRUPT_COUNT() \ |
| 109 | (miu_mfc0(MIU_C0_USERLOCAL)) |
| 110 | |
| 111 | #define MER_KERNEL_SET_INTERRUPT_COUNT(value) \ |
| 112 | do {\ |
| 113 | miu_mtc0(MIU_C0_USERLOCAL, (value));\ |
| 114 | }while(0) |
| 115 | |
| 116 | #define MER_KERNEL_GET_CURRENT_CONTROL_BLOCK() \ |
| 117 | (miu_mfc0(MIU_C0_TCCONTEXT)) |
| 118 | |
| 119 | #define MER_KERNEL_SET_CURRENT_CONTROL_BLOCK(value) \ |
| 120 | miu_mtc0(MIU_C0_TCCONTEXT, (value)) |
| 121 | |
| 122 | #endif |
| 123 | |
| 124 | #if !MER_KERNEL_IS_ASSEMBLY |
| 125 | /////////////////////////////////////////////////////////////////////////////// |
| 126 | // Macro |
| 127 | /////////////////////////////////////////////////////////////////////////////// |
| 128 | #if defined(__MD97__) || defined(__MD97P__) |
| 129 | #define MER_KERNEL_OS_INTERRUPT_SW_CODE_BASE SW_TRIGGER_CODE53 |
| 130 | #else |
| 131 | #error "Unsupport platform" |
| 132 | #endif |
| 133 | |
| 134 | |
| 135 | /////////////////////////////////////////////////////////////////////////////// |
| 136 | // Porting variable |
| 137 | /////////////////////////////////////////////////////////////////////////////// |
| 138 | |
| 139 | /////////////////////////////////////////////////////////////////////////////// |
| 140 | // Enum |
| 141 | /////////////////////////////////////////////////////////////////////////////// |
| 142 | |
| 143 | |
| 144 | /////////////////////////////////////////////////////////////////////////////// |
| 145 | // Structure |
| 146 | /////////////////////////////////////////////////////////////////////////////// |
| 147 | |
| 148 | typedef struct isr_info { |
| 149 | mer_uint32 start_time; |
| 150 | mer_uint32 preempted_time; |
| 151 | struct isr_info *previous_ptr; |
| 152 | } mer_kernel_isr_info; |
| 153 | |
| 154 | /////////////////////////////////////////////////////////////////////////////// |
| 155 | // External variable |
| 156 | /////////////////////////////////////////////////////////////////////////////// |
| 157 | extern mer_uint32 mer_kernel_initialize_flag; |
| 158 | extern volatile mer_uint32 mer_kernel_os_interrupt_pending_mask; |
| 159 | extern mer_uint32 mer_kernel_interrupt_count[MIPS_HW_VPE_NUM]; |
| 160 | |
| 161 | extern mer_uint32 mer_kernel_system_stack_vpe0[]; |
| 162 | extern mer_uint32 mer_kernel_system_stack_vpe1[]; |
| 163 | extern mer_uint32 mer_kernel_system_stack_vpe2[]; |
| 164 | extern mer_uint32 mer_kernel_system_stack_vpe3[]; |
| 165 | extern mer_uint32 mer_kernel_system_stack_vpe4[]; |
| 166 | extern mer_uint32 mer_kernel_system_stack_vpe5[]; |
| 167 | extern mer_uint32 mer_kernel_system_stack_vpe6[]; |
| 168 | extern mer_uint32 mer_kernel_system_stack_vpe7[]; |
| 169 | extern mer_uint32 mer_kernel_system_stack_vpe8[]; |
| 170 | extern mer_uint32 mer_kernel_system_stack_vpe9[]; |
| 171 | extern mer_uint32 mer_kernel_system_stack_vpe10[]; |
| 172 | extern mer_uint32 mer_kernel_system_stack_vpe11[]; |
| 173 | /////////////////////////////////////////////////////////////////////////////// |
| 174 | // External functions |
| 175 | /////////////////////////////////////////////////////////////////////////////// |
| 176 | extern void mer_kernel_initialization(); |
| 177 | extern void mer_kernel_isr_job_management(mer_uint32 isr_index, mer_uint32 vpe_id); |
| 178 | extern void mer_kernel_isr_job_management_end(mer_uint32 isr_index, mer_uint32 vpe_id); |
| 179 | extern void mer_kernel_enter_scheduling(); |
| 180 | extern void mer_kernel_initialization_phase0(); |
| 181 | extern void mer_kernel_osipi_handler(); |
| 182 | /////////////////////////////////////////////////////////////////////////////// |
| 183 | // static inline functions |
| 184 | /////////////////////////////////////////////////////////////////////////////// |
| 185 | static inline mer_uint32 mer_kernel_is_initialized(){ |
| 186 | return mer_kernel_initialize_flag; |
| 187 | } |
| 188 | |
| 189 | #include "kal_hrt_api.h" |
| 190 | #include "ex_public.h" |
| 191 | static inline mer_uint32 mer_kernel_is_interrupt_enabled() |
| 192 | { |
| 193 | mer_uint32 ibit; |
| 194 | mer_bool is_in_mt = kal_hrt_if_lisr_mt(); |
| 195 | mer_bool is_in_init = kal_query_systemInit(); |
| 196 | mer_bool is_in_exception = INT_QueryExceptionStatus(); |
| 197 | |
| 198 | do { |
| 199 | __asm__ __volatile__("" : |
| 200 | : |
| 201 | : "memory"); |
| 202 | }while(0); |
| 203 | |
| 204 | __asm__ __volatile__("mfc0 %0, $12\n\t" |
| 205 | "andi %0, 0x1\n\t" |
| 206 | : "=d"(ibit)); |
| 207 | |
| 208 | return is_in_mt || is_in_init || is_in_exception || ibit; |
| 209 | } |
| 210 | |
| 211 | #if !defined(__MER_KERNEL_USE_MIPS_CP0_CONTEXT_REG__) |
| 212 | mer_uint32 mer_kernel_interrupt_count[MIPS_HW_VPE_NUM]; |
| 213 | #endif |
| 214 | |
| 215 | static inline mer_uint32 mer_kernel_get_interrupt_count() |
| 216 | { |
| 217 | #if defined(__MER_KERNEL_USE_MIPS_CP0_CONTEXT_REG__) |
| 218 | mer_uint32 irq_count = MER_KERNEL_GET_INTERRUPT_COUNT(); |
| 219 | #else |
| 220 | mer_uint32 irq_count = mer_kernel_interrupt_count[mer_kernel_utility_get_current_vpe_id()]; |
| 221 | #endif |
| 222 | |
| 223 | return irq_count; |
| 224 | } |
| 225 | |
| 226 | static inline void mer_kernel_set_interrupt_count(mer_uint32 irq_count) |
| 227 | { |
| 228 | #if defined(__MER_KERNEL_USE_MIPS_CP0_CONTEXT_REG__) |
| 229 | MER_KERNEL_SET_INTERRUPT_COUNT(irq_count); |
| 230 | #else |
| 231 | mer_kernel_interrupt_count[mer_kernel_utility_get_current_vpe_id()] = irq_count; |
| 232 | #endif /* __MER_KERNEL_USE_MIPS_CP0_CONTEXT_REG__ */ |
| 233 | } |
| 234 | |
| 235 | #endif /* MER_KERNEL_IS_ASSEMBLY */ |
| 236 | #endif /* _MER_KERNEL_H_ */ |
| 237 | |