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

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on May 11, 1995 at 5:39:37 PM

Initial revision

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 *  Input/Output Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
6 *  On-Line Applications Research Corporation (OAR).
7 *  All rights assigned to U.S. Government, 1994.
8 *
9 *  This material may be reproduced by or for the U.S. Government pursuant
10 *  to the copyright license under the clause at DFARS 252.227-7013.  This
11 *  notice must appear in all copies of this file and its derivatives.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/config.h>
18#include <rtems/io.h>
19#include <rtems/isr.h>
20#include <rtems/thread.h>
21
22/*PAGE
23 *
24 *  _IO_Initialize_all_drivers
25 *
26 *  This routine initializes all device drivers
27 *
28 *  Input Paramters:   NONE
29 *
30 *  Output Parameters: NONE
31 */
32
33void _IO_Initialize_all_drivers( void )
34{
35   rtems_device_major_number major;
36   unsigned32                ignored;
37
38   for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
39     (void) rtems_io_initialize( major, 0, _Configuration_Table, &ignored );
40}
41
42/*PAGE
43 *
44 *  rtems_io_initialize
45 *
46 *  This routine is the initialization directive of the IO manager.
47 *
48 *  Input Paramters:
49 *    major        - device driver number
50 *    minor        - device number
51 *    argument     - pointer to argument(s)
52 *    return_value - pointer to driver's return value
53 *
54 *  Output Parameters:
55 *    returns       - return code
56 *    *return_value - driver's return code
57 */
58
59rtems_status_code rtems_io_initialize(
60  rtems_device_major_number  major,
61  rtems_device_minor_number  minor,
62  void             *argument,
63  unsigned32       *return_value
64)
65{
66  return _IO_Handler_routine(
67            IO_INITIALIZE_OPERATION,
68            major,
69            minor,
70            argument,
71            return_value
72         );
73}
74
75/*PAGE
76 *
77 *  rtems_io_open
78 *
79 *  This routine is the open directive of the IO manager.
80 *
81 *  Input Paramters:
82 *    major        - device driver number
83 *    minor        - device number
84 *    argument     - pointer to argument(s)
85 *    return_value - pointer to driver's return value
86 *
87 *  Output Parameters:
88 *    returns       - return code
89 *    *return_value - driver's return code
90 */
91
92rtems_status_code rtems_io_open(
93  rtems_device_major_number  major,
94  rtems_device_minor_number  minor,
95  void             *argument,
96  unsigned32       *return_value
97)
98{
99  return _IO_Handler_routine(
100            IO_OPEN_OPERATION,
101            major,
102            minor,
103            argument,
104            return_value
105         );
106}
107
108/*PAGE
109 *
110 *  rtems_io_close
111 *
112 *  This routine is the close directive of the IO manager.
113 *
114 *  Input Paramters:
115 *    major        - device driver number
116 *    minor        - device number
117 *    argument     - pointer to argument(s)
118 *    return_value - pointer to driver's return value
119 *
120 *  Output Parameters:
121 *    returns       - return code
122 *    *return_value - driver's return code
123 */
124
125rtems_status_code rtems_io_close(
126  rtems_device_major_number  major,
127  rtems_device_minor_number  minor,
128  void             *argument,
129  unsigned32       *return_value
130)
131{
132  return _IO_Handler_routine(
133            IO_CLOSE_OPERATION,
134            major,
135            minor,
136            argument,
137            return_value
138         );
139}
140
141/*PAGE
142 *
143 *  rtems_io_read
144 *
145 *  This routine is the read directive of the IO manager.
146 *
147 *  Input Paramters:
148 *    major        - device driver number
149 *    minor        - device number
150 *    argument     - pointer to argument(s)
151 *    return_value - pointer to driver's return value
152 *
153 *  Output Parameters:
154 *    returns       - return code
155 *    *return_value - driver's return code
156 */
157
158rtems_status_code rtems_io_read(
159  rtems_device_major_number  major,
160  rtems_device_minor_number  minor,
161  void             *argument,
162  unsigned32       *return_value
163)
164{
165  return _IO_Handler_routine(
166            IO_READ_OPERATION,
167            major,
168            minor,
169            argument,
170            return_value
171         );
172}
173
174/*PAGE
175 *
176 *  rtems_io_write
177 *
178 *  This routine is the write directive of the IO manager.
179 *
180 *  Input Paramters:
181 *    major        - device driver number
182 *    minor        - device number
183 *    argument     - pointer to argument(s)
184 *    return_value - pointer to driver's return value
185 *
186 *  Output Parameters:
187 *    returns       - return code
188 *    *return_value - driver's return code
189 */
190
191rtems_status_code rtems_io_write(
192  rtems_device_major_number  major,
193  rtems_device_minor_number  minor,
194  void             *argument,
195  unsigned32       *return_value
196)
197{
198  return _IO_Handler_routine(
199            IO_WRITE_OPERATION,
200            major,
201            minor,
202            argument,
203            return_value
204         );
205}
206
207/*PAGE
208 *
209 *  rtems_io_control
210 *
211 *  This routine is the control directive of the IO manager.
212 *
213 *  Input Paramters:
214 *    major        - device driver number
215 *    minor        - device number
216 *    argument     - pointer to argument(s)
217 *    return_value - pointer to driver's return value
218 *
219 *  Output Parameters:
220 *    returns       - return code
221 *    *return_value - driver's return code
222 */
223
224rtems_status_code rtems_io_control(
225  rtems_device_major_number  major,
226  rtems_device_minor_number  minor,
227  void             *argument,
228  unsigned32       *return_value
229)
230{
231  return _IO_Handler_routine(
232            IO_CONTROL_OPERATION,
233            major,
234            minor,
235            argument,
236            return_value
237         );
238}
239
240/*PAGE
241 *
242 *  _IO_Handler_routine
243 *
244 *  This routine implements all IO manager directives.
245 *
246 *  Input Paramters:
247 *    operation    - I/O operation to be performed
248 *    major        - device driver number
249 *    minor        - device number
250 *    argument     - pointer to argument(s)
251 *    return_value - pointer to driver's return value
252 *
253 *  Output Parameters:
254 *    returns       - return code
255 *    *return_value - driver's return code
256 */
257
258rtems_status_code _IO_Handler_routine(
259  IO_operations     operation,
260  rtems_device_major_number  major,
261  rtems_device_minor_number  minor,
262  void             *argument,
263  unsigned32       *return_value
264)
265{
266  rtems_device_driver_entry io_callout;
267
268  /*
269   *  NOTE:  There is no range checking as in Ada because:
270   *           + arrays in Ada are not always zero based.
271   *           + with zero based arrays, a comparison of an unsigned
272   *             number being less than zero would be necessary to
273   *             check it as a range.  This would cause a warning for
274   *             checking an unsigned number for being negative.
275   */
276
277  if ( major >= _IO_Number_of_drivers )
278    return ( RTEMS_INVALID_NUMBER );
279
280  switch ( operation ) {
281     case IO_INITIALIZE_OPERATION:
282        io_callout = _IO_Driver_address_table[ major ].initialization;
283        break;
284     case IO_OPEN_OPERATION:
285        io_callout = _IO_Driver_address_table[ major ].open;
286        break;
287     case IO_CLOSE_OPERATION:
288        io_callout = _IO_Driver_address_table[ major ].close;
289        break;
290     case IO_READ_OPERATION:
291        io_callout = _IO_Driver_address_table[ major ].read;
292        break;
293     case IO_WRITE_OPERATION:
294        io_callout = _IO_Driver_address_table[ major ].write;
295        break;
296     case IO_CONTROL_OPERATION:
297        io_callout = _IO_Driver_address_table[ major ].control;
298        break;
299     default:             /* unreached -- only to remove warnings */
300        io_callout = NULL;
301        break;
302  }
303
304  if ( io_callout != NULL )
305     (*io_callout)(
306        major,
307        minor,
308        argument,
309        _Thread_Executing->Object.id,
310        return_value
311     );
312  else
313     *return_value = 0;
314
315  return( RTEMS_SUCCESSFUL );
316}
Note: See TracBrowser for help on using the repository browser.