source: rtems/cpukit/sapi/src/io.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was 16351f7a, checked in by Ralf Corsepius <ralf.corsepius@…>, on Jan 28, 2005 at 2:04:21 AM

2005-01-28 Ralf Corsepius <ralf.corsepius@…>

  • sapi/src/debug.c, sapi/src/exinit.c, sapi/src/extension.c, sapi/src/extensioncreate.c, sapi/src/extensiondelete.c, sapi/src/extensionident.c, sapi/src/fatal.c, sapi/src/io.c, sapi/src/itronapi.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c: Include config.h.
  • Property mode set to 100644
File size: 9.8 KB
Line 
1/*
2 *  Input/Output Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/io.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/thread.h>
23#include <rtems/score/wkspace.h>
24
25#include <string.h>
26
27/*PAGE
28 *
29 *  _IO_Manager_initialization
30 *
31 *  The IO manager has been extended to support runtime driver
32 *  registration. The driver table is now allocated in the
33 *  workspace.
34 *
35 */
36
37void _IO_Manager_initialization(
38    rtems_driver_address_table *driver_table,
39    uint32_t                    drivers_in_table,
40    uint32_t                    number_of_drivers,
41    uint32_t                    number_of_devices
42)
43{
44  void                *tmp;
45  uint32_t             index;
46  rtems_driver_name_t *np;
47
48  if ( number_of_drivers < drivers_in_table )
49      number_of_drivers = drivers_in_table;
50
51  tmp = _Workspace_Allocate_or_fatal_error(
52    sizeof( rtems_driver_address_table ) * ( number_of_drivers )
53  );
54
55  _IO_Driver_address_table = (rtems_driver_address_table *) tmp;
56
57  memset(
58    _IO_Driver_address_table, 0,
59    sizeof( rtems_driver_address_table ) * ( number_of_drivers )
60  );
61
62  if ( drivers_in_table )
63      for ( index = 0 ; index < drivers_in_table ; index++ )
64        _IO_Driver_address_table[index] = driver_table[index];
65
66  _IO_Number_of_drivers = number_of_drivers;
67  _IO_Number_of_devices = number_of_devices;
68
69  tmp = _Workspace_Allocate_or_fatal_error(
70    sizeof( rtems_driver_name_t ) * ( number_of_devices + 1 )
71  );
72
73  _IO_Driver_name_table = (rtems_driver_name_t *) tmp;
74
75  for( index=0, np = _IO_Driver_name_table ;
76       index < _IO_Number_of_devices ;
77       index++, np++ ) {
78    np->device_name = 0;
79    np->device_name_length = 0;
80    np->major = 0;
81    np->minor = 0;
82  }
83}
84
85/*PAGE
86 *
87 *  _IO_Initialize_all_drivers
88 *
89 *  This routine initializes all device drivers
90 *
91 *  Input Paramters:   NONE
92 *
93 *  Output Parameters: NONE
94 */
95
96void _IO_Initialize_all_drivers( void )
97{
98   rtems_device_major_number major;
99
100   for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
101     (void) rtems_io_initialize( major, 0, NULL);
102}
103
104/*PAGE
105 *
106 *  rtems_io_register_driver
107 *
108 *  Register a driver into the device driver table.
109 *
110 *  Input Paramters:
111 *    major            - device major number (0 means allocate
112 *                       a number)
113 *    driver_table     - driver callout function table
114 *    registered_major - the major number which is registered
115 *
116 *  Output Parameters:
117 *    RTEMS_SUCCESSFUL - if successful
118 *    error code       - if unsuccessful
119 */
120
121rtems_status_code rtems_io_register_driver(
122    rtems_device_major_number   major,
123    rtems_driver_address_table *driver_table,
124    rtems_device_major_number  *registered_major
125)
126{
127    *registered_major = 0;
128
129    /*
130     * Test for initialise/open being present to indicate the driver slot is
131     * in use.
132     */
133
134    if ( major >= _IO_Number_of_drivers )
135      return RTEMS_INVALID_NUMBER;
136
137    if ( major == 0 )
138    {
139        for ( major = _IO_Number_of_drivers - 1 ; major ; major-- )
140            if ( _IO_Driver_address_table[major].initialization_entry == 0 &&
141                 _IO_Driver_address_table[major].open_entry == 0 )
142                break;
143
144        if (( major == 0 ) &&
145            ( _IO_Driver_address_table[major].initialization_entry == 0 &&
146              _IO_Driver_address_table[major].open_entry == 0 ))
147            return RTEMS_TOO_MANY;
148    }
149
150    if ( _IO_Driver_address_table[major].initialization_entry == 0 &&
151         _IO_Driver_address_table[major].open_entry == 0 )
152    {
153        _IO_Driver_address_table[major] = *driver_table;
154        *registered_major               = major;
155
156        rtems_io_initialize( major, 0, NULL );
157
158        return RTEMS_SUCCESSFUL;
159    }
160
161    return RTEMS_RESOURCE_IN_USE;
162}
163
164/*PAGE
165 *
166 *  rtems_io_unregister_driver
167 *
168 *  Unregister a driver from the device driver table.
169 *
170 *  Input Paramters:
171 *    major            - device major number
172 *
173 *  Output Parameters:
174 *    RTEMS_SUCCESSFUL - if successful
175 *    error code       - if unsuccessful
176 */
177
178rtems_status_code rtems_io_unregister_driver(
179    rtems_device_major_number major
180)
181{
182    if ( major < _IO_Number_of_drivers )
183    {
184        memset(
185            &_IO_Driver_address_table[major],
186            0,
187            sizeof( rtems_driver_address_table )
188        );
189        return RTEMS_SUCCESSFUL;
190    }
191    return RTEMS_UNSATISFIED;
192}
193
194/*PAGE
195 *
196 *  rtems_io_register_name
197 *
198 *  Associate a name with a driver
199 *
200 *  Input Paramters:
201 *    device_name - pointer to name string to associate with device
202 *    major       - device major number to receive name
203 *    minor       - device minor number to receive name
204 *
205 *  Output Parameters:
206 *    RTEMS_SUCCESSFUL - if successful
207 *    error code       - if unsuccessful
208 */
209
210#if 0
211rtems_status_code rtems_io_register_name(
212    char *device_name,
213    rtems_device_major_number major,
214    rtems_device_minor_number minor
215  )
216{
217    rtems_driver_name_t *np;
218    uint32_t   level;
219    uint32_t   index;
220
221    /* find an empty slot */
222    for( index=0, np = _IO_Driver_name_table ;
223         index < _IO_Number_of_devices ;
224         index++, np++ )
225    {
226
227        _ISR_Disable(level);
228        if (np->device_name == 0)
229        {
230            np->device_name = device_name;
231            np->device_name_length = strlen(device_name);
232            np->major = major;
233            np->minor = minor;
234            _ISR_Enable(level);
235
236            return RTEMS_SUCCESSFUL;
237        }
238        _ISR_Enable(level);
239    }
240
241    return RTEMS_TOO_MANY;
242}
243#endif
244
245/*PAGE
246 *
247 *  rtems_io_initialize
248 *
249 *  This routine is the initialization directive of the IO manager.
250 *
251 *  Input Paramters:
252 *    major        - device driver number
253 *    minor        - device number
254 *    argument     - pointer to argument(s)
255 *
256 *  Output Parameters:
257 *    returns       - return code
258 */
259
260rtems_status_code rtems_io_initialize(
261  rtems_device_major_number  major,
262  rtems_device_minor_number  minor,
263  void                      *argument
264)
265{
266    rtems_device_driver_entry callout;
267
268    if ( major >= _IO_Number_of_drivers )
269        return RTEMS_INVALID_NUMBER;
270
271    callout = _IO_Driver_address_table[major].initialization_entry;
272    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
273}
274
275/*PAGE
276 *
277 *  rtems_io_open
278 *
279 *  This routine is the open directive of the IO manager.
280 *
281 *  Input Paramters:
282 *    major        - device driver number
283 *    minor        - device number
284 *    argument     - pointer to argument(s)
285 *
286 *  Output Parameters:
287 *    returns       - return code
288 */
289
290rtems_status_code rtems_io_open(
291  rtems_device_major_number  major,
292  rtems_device_minor_number  minor,
293  void                      *argument
294)
295{
296    rtems_device_driver_entry callout;
297
298    if ( major >= _IO_Number_of_drivers )
299        return RTEMS_INVALID_NUMBER;
300
301    callout = _IO_Driver_address_table[major].open_entry;
302    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
303}
304
305/*PAGE
306 *
307 *  rtems_io_close
308 *
309 *  This routine is the close directive of the IO manager.
310 *
311 *  Input Paramters:
312 *    major        - device driver number
313 *    minor        - device number
314 *    argument     - pointer to argument(s)
315 *
316 *  Output Parameters:
317 *    returns       - return code
318 */
319
320rtems_status_code rtems_io_close(
321  rtems_device_major_number  major,
322  rtems_device_minor_number  minor,
323  void                      *argument
324)
325{
326    rtems_device_driver_entry callout;
327
328    if ( major >= _IO_Number_of_drivers )
329        return RTEMS_INVALID_NUMBER;
330
331    callout = _IO_Driver_address_table[major].close_entry;
332    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
333}
334
335/*PAGE
336 *
337 *  rtems_io_read
338 *
339 *  This routine is the read directive of the IO manager.
340 *
341 *  Input Paramters:
342 *    major        - device driver number
343 *    minor        - device number
344 *    argument     - pointer to argument(s)
345 *
346 *  Output Parameters:
347 *    returns       - return code
348 */
349
350rtems_status_code rtems_io_read(
351  rtems_device_major_number  major,
352  rtems_device_minor_number  minor,
353  void                      *argument
354)
355{
356    rtems_device_driver_entry callout;
357
358    if ( major >= _IO_Number_of_drivers )
359        return RTEMS_INVALID_NUMBER;
360
361    callout = _IO_Driver_address_table[major].read_entry;
362    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
363}
364
365/*PAGE
366 *
367 *  rtems_io_write
368 *
369 *  This routine is the write directive of the IO manager.
370 *
371 *  Input Paramters:
372 *    major        - device driver number
373 *    minor        - device number
374 *    argument     - pointer to argument(s)
375 *
376 *  Output Parameters:
377 *    returns       - return code
378 */
379
380rtems_status_code rtems_io_write(
381  rtems_device_major_number  major,
382  rtems_device_minor_number  minor,
383  void                      *argument
384)
385{
386    rtems_device_driver_entry callout;
387
388    if ( major >= _IO_Number_of_drivers )
389        return RTEMS_INVALID_NUMBER;
390
391    callout = _IO_Driver_address_table[major].write_entry;
392    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
393}
394
395/*PAGE
396 *
397 *  rtems_io_control
398 *
399 *  This routine is the control directive of the IO manager.
400 *
401 *  Input Paramters:
402 *    major        - device driver number
403 *    minor        - device number
404 *    argument     - pointer to argument(s)
405 *
406 *  Output Parameters:
407 *    returns       - return code
408 */
409
410rtems_status_code rtems_io_control(
411  rtems_device_major_number  major,
412  rtems_device_minor_number  minor,
413  void                      *argument
414)
415{
416    rtems_device_driver_entry callout;
417
418    if ( major >= _IO_Number_of_drivers )
419        return RTEMS_INVALID_NUMBER;
420
421    callout = _IO_Driver_address_table[major].control_entry;
422    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
423}
Note: See TracBrowser for help on using the repository browser.