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

4.115
Last change on this file since e7fade3 was e7fade3, checked in by Daniel Hellstrom <daniel@…>, on 11/28/11 at 08:52:03

DRVMGR: added driver manager to cpukit/libdrvmgr

  • Property mode set to 100644
File size: 7.4 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/debug.h>
33#include <rtems/extensionimpl.h>
34#include <rtems/init.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/threadimpl.h>
48#include <rtems/score/todimpl.h>
49#include <rtems/score/userextimpl.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
63Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
64
65void rtems_initialize_data_structures(void)
66{
67  /*
68   *  Dispatching and interrupts are disabled until the end of the
69   *  initialization sequence.  This prevents an inadvertent context
70   *  switch before the executive is initialized.
71   *
72   *  WARNING: Interrupts should have been disabled by the BSP and
73   *           are disabled by boot_card().
74   */
75
76  #if defined(RTEMS_MULTIPROCESSING)
77    /*
78     *  Initialize the system state based on whether this is an MP system.
79     *  In an MP configuration, internally we view single processor
80     *  systems as a very restricted multiprocessor system.
81     */
82    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
83
84    if ( _Configuration_MP_table == NULL ) {
85      _Configuration_MP_table =
86        (void *)&_Initialization_Default_multiprocessing_table;
87      _System_state_Handler_initialization( FALSE );
88    } else {
89      _System_state_Handler_initialization( TRUE );
90    }
91  #else
92    _System_state_Handler_initialization( FALSE );
93  #endif
94
95  /*
96   * Initialize any target architecture specific support as early as possible
97   */
98  _CPU_Initialize();
99
100  #if defined(RTEMS_MULTIPROCESSING)
101    _Objects_MP_Handler_early_initialization();
102  #endif
103
104  /*
105   *  Do this as early as possible to ensure no debugging output
106   *  is even attempted to be printed.
107   */
108  _Debug_Manager_initialization();
109
110  _API_extensions_Initialization();
111
112  _Thread_Dispatch_initialization();
113
114  _User_extensions_Handler_initialization();
115  _ISR_Handler_initialization();
116
117  /*
118   * Initialize the internal support API and allocator Mutex
119   */
120  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
121
122  _API_Mutex_Initialization( 2 );
123  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
124  _API_Mutex_Allocate( &_Once_Mutex );
125
126  _Watchdog_Handler_initialization();
127  _TOD_Handler_initialization();
128
129  _Thread_Handler_initialization();
130
131  _Scheduler_Handler_initialization();
132
133  #if defined(RTEMS_MULTIPROCESSING)
134    _Objects_MP_Handler_initialization();
135    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
136  #endif
137
138  _SMP_Handler_initialize();
139
140  _CPU_set_Handler_initialization();
141
142/* MANAGERS */
143
144  _RTEMS_API_Initialize();
145
146  _Extension_Manager_initialization();
147
148  _POSIX_API_Initialize();
149
150  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
151
152  /*
153   *  No threads should be created before this point!!!
154   *  _Thread_Executing and _Thread_Heir are not set.
155   *
156   *  At this point all API extensions are in place.  After the call to
157   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
158   */
159  _Thread_Create_idle();
160
161  /*
162   *  Scheduling can properly occur now as long as we avoid dispatching.
163   */
164}
165
166void rtems_initialize_before_drivers(void)
167{
168  #ifdef RTEMS_DRVMGR_STARTUP
169  _DRV_Manager_initialization();
170  #endif
171
172  #if defined(RTEMS_MULTIPROCESSING)
173    _MPCI_Create_server();
174  #endif
175
176  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
177    /*
178     *  Run the API and BSPs predriver hook.
179     */
180    _API_extensions_Run_predriver();
181  #endif
182}
183
184void rtems_initialize_device_drivers(void)
185{
186  /*
187   *  Initialize all the device drivers and initialize the MPCI layer.
188   *
189   *  NOTE:  The MPCI may be build upon a device driver.
190   */
191
192  #ifdef RTEMS_DRVMGR_STARTUP
193  /* BSPs has already registered their "root bus" driver in the
194   * bsp_predriver hook or so.
195   *
196   * Init Drivers to Level 1, constraints:
197   *   - Interrupts and system clock timer does not work.
198   *   - malloc() work, however other memory services may not
199   *     have been initialized yet.
200   *   - initializes most basic stuff
201   *
202   * Typical setup in Level 1:
203   *   - Find most devices in system, do PCI scan and configuration.
204   *   - Reset hardware if needed.
205   *   - Install IRQ driver
206   *   - Install Timer driver
207   *   - Install console driver and debug printk()
208   *   - Install extra memory.
209   */
210  _DRV_Manager_init_level(1);
211  bsp_driver_level_hook(1);
212  #endif
213
214  /* Initialize I/O drivers.
215   *
216   * Driver Manager note:
217   * All drivers may not be registered yet. Drivers will dynamically
218   * be initialized when registered in level 2,3 and 4.
219   */
220  _IO_Initialize_all_drivers();
221
222  #ifdef RTEMS_DRVMGR_STARTUP
223  /* Init Drivers to Level 2, constraints:
224   *  - Interrupts can be registered and enabled.
225   *  - System Clock is running
226   *  - Console may be used.
227   *
228   * This is typically where drivers are initialized
229   * for the first time.
230   */
231  _DRV_Manager_init_level(2);
232  bsp_driver_level_hook(2);
233
234  /* Init Drivers to Level 3
235   *
236   * This is typically where normal drivers are initialized
237   * for the second time, they may depend on other drivers
238   * API inited in level 2
239   */
240  _DRV_Manager_init_level(3);
241  bsp_driver_level_hook(3);
242
243  /* Init Drivers to Level 4,
244   * Init drivers that depend on services initialized in Level 3
245   */
246  _DRV_Manager_init_level(4);
247  bsp_driver_level_hook(4);
248  #endif
249
250  #if defined(RTEMS_MULTIPROCESSING)
251    if ( _System_state_Is_multiprocessing ) {
252      _MPCI_Initialization();
253      _MPCI_Internal_packets_Send_process_packet(
254        MPCI_PACKETS_SYSTEM_VERIFY
255      );
256    }
257  #endif
258
259  /*
260   *  Run the APIs and BSPs postdriver hooks.
261   *
262   *  The API extensions are supposed to create user initialization tasks.
263   */
264  _API_extensions_Run_postdriver();
265}
266
267void rtems_initialize_start_multitasking(void)
268{
269  _System_state_Set( SYSTEM_STATE_UP );
270
271  _SMP_Request_start_multitasking();
272
273  _Thread_Start_multitasking();
274
275  /*******************************************************************
276   *******************************************************************
277   *******************************************************************
278   ******                 APPLICATION RUNS HERE                 ******
279   ******              THE FUNCTION NEVER RETURNS               ******
280   *******************************************************************
281   *******************************************************************
282   *******************************************************************/
283}
Note: See TracBrowser for help on using the repository browser.