source: rtems/cpukit/sapi/src/exinit.c @ cbaac1f7

5
Last change on this file since cbaac1f7 was 92bb345, checked in by Sebastian Huber <sebastian.huber@…>, on 12/10/15 at 10:40:26

Optional Extensions initialization

Update #2408.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization Manager
5 *
6 * @ingroup ClassicRTEMS
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2014.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22/*
23 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
24 *  super API data will be included in this object file.
25 */
26
27#define SAPI_INIT
28#define SCORE_INIT
29
30#include <rtems/system.h>
31#include <rtems/config.h>
32#include <rtems/extensionimpl.h>
33#include <rtems/init.h>
34#include <rtems/sysinit.h>
35#include <rtems/score/sysstate.h>
36
37#include <rtems/score/apiext.h>
38#include <rtems/score/apimutex.h>
39#include <rtems/score/copyrt.h>
40#include <rtems/score/cpusetimpl.h>
41#include <rtems/score/heap.h>
42#include <rtems/score/interr.h>
43#include <rtems/score/isr.h>
44#include <rtems/score/priority.h>
45#include <rtems/score/schedulerimpl.h>
46#include <rtems/score/smpimpl.h>
47#include <rtems/score/timecounter.h>
48#include <rtems/score/threadimpl.h>
49#include <rtems/score/todimpl.h>
50#include <rtems/score/watchdogimpl.h>
51#include <rtems/score/wkspace.h>
52
53#include <rtems/sptables.h>
54
55
56#include <rtems/rtems/rtemsapi.h>
57#include <rtems/posix/posixapi.h>
58
59#ifdef RTEMS_DRVMGR_STARTUP
60  #include <drvmgr/drvmgr.h>
61#endif
62
63static Objects_Information *
64_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
65
66static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
67
68static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
69
70Objects_Information **_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = {
71  NULL,
72  &_Internal_Objects[ 0 ],
73  &_RTEMS_Objects[ 0 ],
74  &_POSIX_Objects[ 0 ]
75};
76
77static void rtems_initialize_data_structures(void)
78{
79  /*
80   *  Dispatching and interrupts are disabled until the end of the
81   *  initialization sequence.  This prevents an inadvertent context
82   *  switch before the executive is initialized.
83   *
84   *  WARNING: Interrupts should have been disabled by the BSP and
85   *           are disabled by boot_card().
86   */
87
88  #if defined(RTEMS_MULTIPROCESSING)
89    /*
90     *  Initialize the system state based on whether this is an MP system.
91     *  In an MP configuration, internally we view single processor
92     *  systems as a very restricted multiprocessor system.
93     */
94    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
95
96    if ( _Configuration_MP_table == NULL ) {
97      _Configuration_MP_table =
98        (void *)&_Initialization_Default_multiprocessing_table;
99    } else {
100      _System_state_Is_multiprocessing = true;
101    }
102  #endif
103
104  /*
105   * Initialize any target architecture specific support as early as possible
106   */
107  _CPU_Initialize();
108
109  #if defined(RTEMS_MULTIPROCESSING)
110    _Objects_MP_Handler_early_initialization();
111  #endif
112
113  _Thread_Dispatch_initialization();
114
115  _ISR_Handler_initialization();
116
117  _API_Mutex_Initialization( 2 );
118  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
119  _API_Mutex_Allocate( &_Once_Mutex );
120
121  _Watchdog_Handler_initialization();
122
123  _Thread_Handler_initialization();
124
125  _Scheduler_Handler_initialization();
126
127  #if defined(RTEMS_MULTIPROCESSING)
128    _Objects_MP_Handler_initialization();
129    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
130  #endif
131
132  _SMP_Handler_initialize();
133
134  _CPU_set_Handler_initialization();
135
136/* MANAGERS */
137
138  _RTEMS_API_Initialize();
139
140  _POSIX_API_Initialize();
141}
142
143static void rtems_initialize_before_drivers(void)
144{
145  #ifdef RTEMS_DRVMGR_STARTUP
146  _DRV_Manager_initialization();
147  #endif
148
149  #if defined(RTEMS_MULTIPROCESSING)
150    _MPCI_Create_server();
151  #endif
152}
153
154static void rtems_initialize_device_drivers(void)
155{
156  /*
157   *  Initialize all the device drivers and initialize the MPCI layer.
158   *
159   *  NOTE:  The MPCI may be build upon a device driver.
160   */
161
162  #ifdef RTEMS_DRVMGR_STARTUP
163  /* BSPs has already registered their "root bus" driver in the
164   * bsp_predriver hook or so.
165   *
166   * Init Drivers to Level 1, constraints:
167   *   - Interrupts and system clock timer does not work.
168   *   - malloc() work, however other memory services may not
169   *     have been initialized yet.
170   *   - initializes most basic stuff
171   *
172   * Typical setup in Level 1:
173   *   - Find most devices in system, do PCI scan and configuration.
174   *   - Reset hardware if needed.
175   *   - Install IRQ driver
176   *   - Install Timer driver
177   *   - Install console driver and debug printk()
178   *   - Install extra memory.
179   */
180  _DRV_Manager_init_level(1);
181  bsp_driver_level_hook(1);
182  #endif
183
184  /* Initialize I/O drivers.
185   *
186   * Driver Manager note:
187   * All drivers may not be registered yet. Drivers will dynamically
188   * be initialized when registered in level 2,3 and 4.
189   */
190  _IO_Initialize_all_drivers();
191
192  #ifdef RTEMS_DRVMGR_STARTUP
193  /* Init Drivers to Level 2, constraints:
194   *  - Interrupts can be registered and enabled.
195   *  - System Clock is running
196   *  - Console may be used.
197   *
198   * This is typically where drivers are initialized
199   * for the first time.
200   */
201  _DRV_Manager_init_level(2);
202  bsp_driver_level_hook(2);
203
204  /* Init Drivers to Level 3
205   *
206   * This is typically where normal drivers are initialized
207   * for the second time, they may depend on other drivers
208   * API inited in level 2
209   */
210  _DRV_Manager_init_level(3);
211  bsp_driver_level_hook(3);
212
213  /* Init Drivers to Level 4,
214   * Init drivers that depend on services initialized in Level 3
215   */
216  _DRV_Manager_init_level(4);
217  bsp_driver_level_hook(4);
218  #endif
219
220  #if defined(RTEMS_MULTIPROCESSING)
221    if ( _System_state_Is_multiprocessing ) {
222      _MPCI_Initialization();
223      _MPCI_Internal_packets_Send_process_packet(
224        MPCI_PACKETS_SYSTEM_VERIFY
225      );
226    }
227  #endif
228
229  /*
230   *  Run the APIs and BSPs postdriver hooks.
231   *
232   *  The API extensions are supposed to create user initialization tasks.
233   */
234  _API_extensions_Run_postdriver();
235}
236
237RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
238
239RTEMS_SYSINIT_ITEM(
240  rtems_initialize_data_structures,
241  RTEMS_SYSINIT_DATA_STRUCTURES,
242  RTEMS_SYSINIT_ORDER_MIDDLE
243);
244
245/*
246 *  No threads should be created before this point!!!
247 *  _Thread_Executing and _Thread_Heir are not set.
248 *
249 *  At this point all API extensions are in place.  After the call to
250 *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
251 *
252 *  Scheduling can properly occur afterwards as long as we avoid dispatching.
253 */
254RTEMS_SYSINIT_ITEM(
255  _Thread_Create_idle,
256  RTEMS_SYSINIT_IDLE_THREADS,
257  RTEMS_SYSINIT_ORDER_MIDDLE
258);
259
260RTEMS_SYSINIT_ITEM(
261  rtems_initialize_before_drivers,
262  RTEMS_SYSINIT_BEFORE_DRIVERS,
263  RTEMS_SYSINIT_ORDER_MIDDLE
264);
265
266RTEMS_SYSINIT_ITEM(
267  rtems_initialize_device_drivers,
268  RTEMS_SYSINIT_DEVICE_DRIVERS,
269  RTEMS_SYSINIT_ORDER_MIDDLE
270);
271
272void rtems_initialize_executive(void)
273{
274  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
275  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
276
277  /* Invoke the registered system initialization handlers */
278  while ( cur != end ) {
279    ( *cur->handler )();
280    ++cur;
281  }
282
283  _System_state_Set( SYSTEM_STATE_UP );
284
285  _SMP_Request_start_multitasking();
286
287  _Thread_Start_multitasking();
288
289  /*******************************************************************
290   *******************************************************************
291   *******************************************************************
292   ******                 APPLICATION RUNS HERE                 ******
293   ******              THE FUNCTION NEVER RETURNS               ******
294   *******************************************************************
295   *******************************************************************
296   *******************************************************************/
297}
Note: See TracBrowser for help on using the repository browser.