1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** ThreadX Component */
16 /** */
17 /** Initialization */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define TX_SOURCE_CODE
23 #define TX_THREAD_SMP_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_initialize.h"
30 #include "tx_timer.h"
31 #include "tx_thread.h"
32
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _tx_thread_smp_high_level_initialize PORTABLE SMP */
40 /* 6.1.3 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function initializes the ThreadX SMP data structures and */
48 /* CPU registers. */
49 /* */
50 /* INPUT */
51 /* */
52 /* None */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* None */
57 /* */
58 /* CALLS */
59 /* */
60 /* None */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* _tx_initialize_kernel_enter ThreadX entry */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
71 /* 12-31-2020 William E. Lamie Modified comments, added */
72 /* cast to address a MISRA */
73 /* compliant issue, */
74 /* resulting in version 6.1.3 */
75 /* */
76 /**************************************************************************/
_tx_thread_smp_high_level_initialize(void)77 void _tx_thread_smp_high_level_initialize(void)
78 {
79
80 /* Clear the system error flag. */
81 _tx_thread_smp_system_error = TX_FALSE;
82
83 /* Ensure that the system state variable is set to indicate
84 initialization is in progress. Note that this variable is
85 later used to represent interrupt nesting. */
86 _tx_thread_smp_current_state_set(TX_INITIALIZE_IN_PROGRESS);
87
88 /* Clear the thread protection. */
89 TX_MEMSET(&_tx_thread_smp_protection, 0, sizeof(TX_THREAD_SMP_PROTECT));
90
91 /* Set the field of the protection to all ones to indicate it is invalid. */
92 _tx_thread_smp_protection.tx_thread_smp_protect_core = ((ULONG) 0xFFFFFFFFUL);
93
94 /* Clear the thread schedule list. */
95 TX_MEMSET(&_tx_thread_smp_schedule_list[0], 0, sizeof(_tx_thread_smp_schedule_list));
96
97 /* Initialize core list. */
98 TX_MEMSET(&_tx_thread_smp_protect_wait_list[0], 0xff, sizeof(_tx_thread_smp_protect_wait_list));
99
100 /* Set the wait list size so we can access it from assembly functions. */
101 _tx_thread_smp_protect_wait_list_size = ((ULONG) TX_THREAD_SMP_PROTECT_WAIT_LIST_SIZE);
102
103 #ifndef TX_THREAD_SMP_DYNAMIC_CORE_MAX
104
105 /* Call low-level SMP initialize. */
106 _tx_thread_smp_low_level_initialize(((UINT) TX_THREAD_SMP_MAX_CORES));
107 #else
108
109 /* Determine if the dynamic maximum number of cores is 0. If so, default it
110 to the compile-time maximum. */
111 if (_tx_thread_smp_max_cores == 0)
112 {
113
114 /* Default to the compile-time maximum. */
115 _tx_thread_smp_max_cores = TX_THREAD_SMP_MAX_CORES;
116 }
117
118 /* Call low-level SMP initialize. */
119 _tx_thread_smp_low_level_initialize(_tx_thread_smp_max_cores);
120 #endif
121 }
122