source: rtems/cpukit/sapi/src/io.c @ 3235ad9

4.104.114.84.95
Last change on this file since 3235ad9 was b06e68ef, checked in by Joel Sherrill <joel.sherrill@…>, on 08/17/95 at 19:51:51

Numerous miscellaneous features incorporated from Tony Bennett
(tbennett@…) including the following major additions:

+ variable length messages
+ named devices
+ debug monitor
+ association tables/variables

  • Property mode set to 100644
File size: 6.5 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#include <rtems/intr.h>
22
23#include <string.h>
24
25/*PAGE
26 *
27 *  _IO_Initialize_all_drivers
28 *
29 *  This routine initializes all device drivers
30 *
31 *  Input Paramters:   NONE
32 *
33 *  Output Parameters: NONE
34 */
35
36void _IO_Initialize_all_drivers( void )
37{
38   rtems_device_major_number major;
39
40   for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
41     (void) rtems_io_initialize( major, 0, _Configuration_Table);
42}
43
44/*PAGE
45 *
46 *  rtems_io_register_name
47 *
48 *  Associate a name with a driver
49 *
50 *  Input Paramters:
51 *
52 *  Output Parameters:
53 */
54
55rtems_status_code rtems_io_register_name(
56    char *device_name,
57    rtems_device_major_number major,
58    rtems_device_minor_number minor
59  )
60{
61    rtems_driver_name_t *np;
62    unsigned32 level;
63
64    /* find an empty slot */
65    for (np = rtems_driver_name_table; np < &rtems_driver_name_table[RTEMS_MAX_DRIVER_NAMES]; np++)
66    {
67        rtems_interrupt_disable(level);
68        if (np->device_name == 0)
69        {
70            np->device_name = device_name;
71            np->device_name_length = strlen(device_name);
72            np->major = major;
73            np->minor = minor;
74            rtems_interrupt_enable(level);
75
76            return RTEMS_SUCCESSFUL;
77        }
78        rtems_interrupt_enable(level);
79    }
80
81    return RTEMS_TOO_MANY;
82}
83
84/*PAGE
85 *
86 *  rtems_io_lookup_name
87 *
88 *  Find what driver "owns" this name
89 *
90 *  Input Paramters:
91 *
92 *  Output Parameters:
93 */
94
95rtems_status_code rtems_io_lookup_name(
96    const char *pathname,
97    rtems_driver_name_t **rnp
98  )
99{
100    rtems_driver_name_t *np;
101
102    for (np = rtems_driver_name_table; np < &rtems_driver_name_table[RTEMS_MAX_DRIVER_NAMES]; np++)
103        if (np->device_name)
104            if (strncmp(np->device_name, pathname, np->device_name_length) == 0)
105            {               
106                *rnp = np;
107                return RTEMS_SUCCESSFUL;
108            }
109   
110    *rnp = 0;
111    return RTEMS_UNSATISFIED;
112}
113
114
115/*PAGE
116 *
117 *  rtems_io_initialize
118 *
119 *  This routine is the initialization directive of the IO manager.
120 *
121 *  Input Paramters:
122 *    major        - device driver number
123 *    minor        - device number
124 *    argument     - pointer to argument(s)
125 *
126 *  Output Parameters:
127 *    returns       - return code
128 */
129
130rtems_status_code rtems_io_initialize(
131  rtems_device_major_number  major,
132  rtems_device_minor_number  minor,
133  void             *argument
134)
135{
136    rtems_device_driver_entry callout;
137   
138    if ( major >= _IO_Number_of_drivers )
139        return RTEMS_INVALID_NUMBER;
140
141    callout = _IO_Driver_address_table[major].initialization;
142    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
143}
144
145/*PAGE
146 *
147 *  rtems_io_open
148 *
149 *  This routine is the open directive of the IO manager.
150 *
151 *  Input Paramters:
152 *    major        - device driver number
153 *    minor        - device number
154 *    argument     - pointer to argument(s)
155 *
156 *  Output Parameters:
157 *    returns       - return code
158 */
159
160rtems_status_code rtems_io_open(
161  rtems_device_major_number  major,
162  rtems_device_minor_number  minor,
163  void             *argument
164)
165{
166    rtems_device_driver_entry callout;
167   
168    if ( major >= _IO_Number_of_drivers )
169        return RTEMS_INVALID_NUMBER;
170
171    callout = _IO_Driver_address_table[major].open;
172    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
173}
174
175/*PAGE
176 *
177 *  rtems_io_close
178 *
179 *  This routine is the close directive of the IO manager.
180 *
181 *  Input Paramters:
182 *    major        - device driver number
183 *    minor        - device number
184 *    argument     - pointer to argument(s)
185 *
186 *  Output Parameters:
187 *    returns       - return code
188 */
189
190rtems_status_code rtems_io_close(
191  rtems_device_major_number  major,
192  rtems_device_minor_number  minor,
193  void             *argument
194)
195{
196    rtems_device_driver_entry callout;
197   
198    if ( major >= _IO_Number_of_drivers )
199        return RTEMS_INVALID_NUMBER;
200
201    callout = _IO_Driver_address_table[major].close;
202    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
203}
204
205/*PAGE
206 *
207 *  rtems_io_read
208 *
209 *  This routine is the read directive of the IO manager.
210 *
211 *  Input Paramters:
212 *    major        - device driver number
213 *    minor        - device number
214 *    argument     - pointer to argument(s)
215 *
216 *  Output Parameters:
217 *    returns       - return code
218 */
219
220rtems_status_code rtems_io_read(
221  rtems_device_major_number  major,
222  rtems_device_minor_number  minor,
223  void             *argument
224)
225{
226    rtems_device_driver_entry callout;
227   
228    if ( major >= _IO_Number_of_drivers )
229        return RTEMS_INVALID_NUMBER;
230
231    callout = _IO_Driver_address_table[major].read;
232    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
233}
234
235/*PAGE
236 *
237 *  rtems_io_write
238 *
239 *  This routine is the write directive of the IO manager.
240 *
241 *  Input Paramters:
242 *    major        - device driver number
243 *    minor        - device number
244 *    argument     - pointer to argument(s)
245 *
246 *  Output Parameters:
247 *    returns       - return code
248 */
249
250rtems_status_code rtems_io_write(
251  rtems_device_major_number  major,
252  rtems_device_minor_number  minor,
253  void             *argument
254)
255{
256    rtems_device_driver_entry callout;
257   
258    if ( major >= _IO_Number_of_drivers )
259        return RTEMS_INVALID_NUMBER;
260
261    callout = _IO_Driver_address_table[major].write;
262    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
263}
264
265/*PAGE
266 *
267 *  rtems_io_control
268 *
269 *  This routine is the control directive of the IO manager.
270 *
271 *  Input Paramters:
272 *    major        - device driver number
273 *    minor        - device number
274 *    argument     - pointer to argument(s)
275 *
276 *  Output Parameters:
277 *    returns       - return code
278 */
279
280rtems_status_code rtems_io_control(
281  rtems_device_major_number  major,
282  rtems_device_minor_number  minor,
283  void             *argument
284)
285{
286    rtems_device_driver_entry callout;
287   
288    if ( major >= _IO_Number_of_drivers )
289        return RTEMS_INVALID_NUMBER;
290
291    callout = _IO_Driver_address_table[major].control;
292    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
293}
294
Note: See TracBrowser for help on using the repository browser.