1 | I/O Manager |
---|
2 | ########### |
---|
3 | |
---|
4 | .. index:: device drivers |
---|
5 | .. index:: IO Manager |
---|
6 | |
---|
7 | Introduction |
---|
8 | ============ |
---|
9 | |
---|
10 | The input/output interface manager provides a |
---|
11 | well-defined mechanism for accessing device drivers and a |
---|
12 | structured methodology for organizing device drivers. The |
---|
13 | directives provided by the I/O manager are: |
---|
14 | |
---|
15 | - ``rtems_io_initialize`` - Initialize a device driver |
---|
16 | |
---|
17 | - ``rtems_io_register_driver`` - Register a device driver |
---|
18 | |
---|
19 | - ``rtems_io_unregister_driver`` - Unregister a device driver |
---|
20 | |
---|
21 | - ``rtems_io_register_name`` - Register a device name |
---|
22 | |
---|
23 | - ``rtems_io_lookup_name`` - Look up a device name |
---|
24 | |
---|
25 | - ``rtems_io_open`` - Open a device |
---|
26 | |
---|
27 | - ``rtems_io_close`` - Close a device |
---|
28 | |
---|
29 | - ``rtems_io_read`` - Read from a device |
---|
30 | |
---|
31 | - ``rtems_io_write`` - Write to a device |
---|
32 | |
---|
33 | - ``rtems_io_control`` - Special device services |
---|
34 | |
---|
35 | Background |
---|
36 | ========== |
---|
37 | |
---|
38 | Device Driver Table |
---|
39 | ------------------- |
---|
40 | .. index:: Device Driver Table |
---|
41 | |
---|
42 | Each application utilizing the RTEMS I/O manager must specify the |
---|
43 | address of a Device Driver Table in its Configuration Table. This table |
---|
44 | contains each device driver's entry points that is to be initialised by |
---|
45 | RTEMS during initialization. Each device driver may contain the |
---|
46 | following entry points: |
---|
47 | |
---|
48 | - Initialization |
---|
49 | |
---|
50 | - Open |
---|
51 | |
---|
52 | - Close |
---|
53 | |
---|
54 | - Read |
---|
55 | |
---|
56 | - Write |
---|
57 | |
---|
58 | - Control |
---|
59 | |
---|
60 | If the device driver does not support a particular |
---|
61 | entry point, then that entry in the Configuration Table should |
---|
62 | be NULL. RTEMS will return``RTEMS_SUCCESSFUL`` as the executive's and |
---|
63 | zero (0) as the device driver's return code for these device |
---|
64 | driver entry points. |
---|
65 | |
---|
66 | Applications can register and unregister drivers with the RTEMS I/O |
---|
67 | manager avoiding the need to have all drivers statically defined and |
---|
68 | linked into this table. |
---|
69 | |
---|
70 | The :file:`confdefs.h` entry ``CONFIGURE_MAXIMUM_DRIVERS`` configures |
---|
71 | the number of driver slots available to the application. |
---|
72 | |
---|
73 | Major and Minor Device Numbers |
---|
74 | ------------------------------ |
---|
75 | .. index:: major device number |
---|
76 | .. index:: minor device number |
---|
77 | |
---|
78 | Each call to the I/O manager must provide a device's |
---|
79 | major and minor numbers as arguments. The major number is the |
---|
80 | index of the requested driver's entry points in the Device |
---|
81 | Driver Table, and is used to select a specific device driver. |
---|
82 | The exact usage of the minor number is driver specific, but is |
---|
83 | commonly used to distinguish between a number of devices |
---|
84 | controlled by the same driver... index:: rtems_device_major_number |
---|
85 | .. index:: rtems_device_minor_number |
---|
86 | |
---|
87 | The data types ``rtems_device_major_number`` and``rtems_device_minor_number`` are used to |
---|
88 | manipulate device major and minor numbers, respectively. |
---|
89 | |
---|
90 | Device Names |
---|
91 | ------------ |
---|
92 | .. index:: device names |
---|
93 | |
---|
94 | The I/O Manager provides facilities to associate a |
---|
95 | name with a particular device. Directives are provided to |
---|
96 | register the name of a device and to look up the major/minor |
---|
97 | number pair associated with a device name. |
---|
98 | |
---|
99 | Device Driver Environment |
---|
100 | ------------------------- |
---|
101 | |
---|
102 | Application developers, as well as device driver |
---|
103 | developers, must be aware of the following regarding the RTEMS |
---|
104 | I/O Manager: |
---|
105 | |
---|
106 | - A device driver routine executes in the context of the |
---|
107 | invoking task. Thus if the driver blocks, the invoking task |
---|
108 | blocks. |
---|
109 | |
---|
110 | - The device driver is free to change the modes of the |
---|
111 | invoking task, although the driver should restore them to their |
---|
112 | original values. |
---|
113 | |
---|
114 | - Device drivers may be invoked from ISRs. |
---|
115 | |
---|
116 | - Only local device drivers are accessible through the I/O |
---|
117 | manager. |
---|
118 | |
---|
119 | - A device driver routine may invoke all other RTEMS |
---|
120 | directives, including I/O directives, on both local and global |
---|
121 | objects. |
---|
122 | |
---|
123 | Although the RTEMS I/O manager provides a framework |
---|
124 | for device drivers, it makes no assumptions regarding the |
---|
125 | construction or operation of a device driver. |
---|
126 | |
---|
127 | Runtime Driver Registration |
---|
128 | --------------------------- |
---|
129 | .. index:: runtime driver registration |
---|
130 | |
---|
131 | Board support package and application developers can select wether a |
---|
132 | device driver is statically entered into the default device table or |
---|
133 | registered at runtime. |
---|
134 | |
---|
135 | Dynamic registration helps applications where: |
---|
136 | |
---|
137 | # The BSP and kernel libraries are common to a range of applications |
---|
138 | for a specific target platform. An application may be built upon a |
---|
139 | common library with all drivers. The application selects and registers |
---|
140 | the drivers. Uniform driver name lookup protects the application. |
---|
141 | |
---|
142 | # The type and range of drivers may vary as the application probes a |
---|
143 | bus during initialization. |
---|
144 | |
---|
145 | # Support for hot swap bus system such as Compact PCI. |
---|
146 | |
---|
147 | # Support for runtime loadable driver modules. |
---|
148 | |
---|
149 | Device Driver Interface |
---|
150 | ----------------------- |
---|
151 | .. index:: device driver interface |
---|
152 | |
---|
153 | When an application invokes an I/O manager directive, |
---|
154 | RTEMS determines which device driver entry point must be |
---|
155 | invoked. The information passed by the application to RTEMS is |
---|
156 | then passed to the correct device driver entry point. RTEMS |
---|
157 | will invoke each device driver entry point assuming it is |
---|
158 | compatible with the following prototype: |
---|
159 | .. code:: c |
---|
160 | |
---|
161 | rtems_device_driver io_entry( |
---|
162 | rtems_device_major_number major, |
---|
163 | rtems_device_minor_number minor, |
---|
164 | void \*argument_block |
---|
165 | ); |
---|
166 | |
---|
167 | The format and contents of the parameter block are |
---|
168 | device driver and entry point dependent. |
---|
169 | |
---|
170 | It is recommended that a device driver avoid |
---|
171 | generating error codes which conflict with those used by |
---|
172 | application components. A common technique used to generate |
---|
173 | driver specific error codes is to make the most significant part |
---|
174 | of the status indicate a driver specific code. |
---|
175 | |
---|
176 | Device Driver Initialization |
---|
177 | ---------------------------- |
---|
178 | |
---|
179 | RTEMS automatically initializes all device drivers |
---|
180 | when multitasking is initiated via the``rtems_initialize_executive`` |
---|
181 | directive. RTEMS initializes the device drivers by invoking |
---|
182 | each device driver initialization entry point with the following |
---|
183 | parameters: |
---|
184 | |
---|
185 | major |
---|
186 | the major device number for this device driver. |
---|
187 | |
---|
188 | minor |
---|
189 | zero. |
---|
190 | |
---|
191 | argument_block |
---|
192 | will point to the Configuration Table. |
---|
193 | |
---|
194 | The returned status will be ignored by RTEMS. If the driver |
---|
195 | cannot successfully initialize the device, then it should invoke |
---|
196 | the fatal_error_occurred directive. |
---|
197 | |
---|
198 | Operations |
---|
199 | ========== |
---|
200 | |
---|
201 | Register and Lookup Name |
---|
202 | ------------------------ |
---|
203 | |
---|
204 | The ``rtems_io_register`` directive associates a name with the |
---|
205 | specified device (i.e. major/minor number pair). Device names |
---|
206 | are typically registered as part of the device driver |
---|
207 | initialization sequence. The ``rtems_io_lookup`` |
---|
208 | directive is used to |
---|
209 | determine the major/minor number pair associated with the |
---|
210 | specified device name. The use of these directives frees the |
---|
211 | application from being dependent on the arbitrary assignment of |
---|
212 | major numbers in a particular application. No device naming |
---|
213 | conventions are dictated by RTEMS. |
---|
214 | |
---|
215 | Accessing an Device Driver |
---|
216 | -------------------------- |
---|
217 | |
---|
218 | The I/O manager provides directives which enable the |
---|
219 | application program to utilize device drivers in a standard |
---|
220 | manner. There is a direct correlation between the RTEMS I/O |
---|
221 | manager directives``rtems_io_initialize``,``rtems_io_open``,``rtems_io_close``,``rtems_io_read``,``rtems_io_write``, and``rtems_io_control`` |
---|
222 | and the underlying device driver entry points. |
---|
223 | |
---|
224 | Directives |
---|
225 | ========== |
---|
226 | |
---|
227 | This section details the I/O manager's directives. A |
---|
228 | subsection is dedicated to each of this manager's directives and |
---|
229 | describes the calling sequence, related constants, usage, and |
---|
230 | status codes. |
---|
231 | |
---|
232 | IO_REGISTER_DRIVER - Register a device driver |
---|
233 | --------------------------------------------- |
---|
234 | .. index:: register a device driver |
---|
235 | |
---|
236 | **CALLING SEQUENCE:** |
---|
237 | |
---|
238 | .. index:: rtems_io_register_driver |
---|
239 | |
---|
240 | .. code:: c |
---|
241 | |
---|
242 | rtems_status_code rtems_io_register_driver( |
---|
243 | rtems_device_major_number major, |
---|
244 | rtems_driver_address_table \*driver_table, |
---|
245 | rtems_device_major_number \*registered_major |
---|
246 | ); |
---|
247 | |
---|
248 | **DIRECTIVE STATUS CODES:** |
---|
249 | |
---|
250 | ``RTEMS_SUCCESSFUL`` - successfully registered |
---|
251 | ``RTEMS_INVALID_ADDRESS`` - invalid registered major pointer |
---|
252 | ``RTEMS_INVALID_ADDRESS`` - invalid driver table |
---|
253 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
254 | ``RTEMS_TOO_MANY`` - no available major device table slot |
---|
255 | ``RTEMS_RESOURCE_IN_USE`` - major device number entry in use |
---|
256 | |
---|
257 | **DESCRIPTION:** |
---|
258 | |
---|
259 | This directive attempts to add a new device driver to the Device Driver |
---|
260 | Table. The user can specify a specific major device number via the |
---|
261 | directive's ``major`` parameter, or let the registration routine find |
---|
262 | the next available major device number by specifing a major number of``0``. The selected major device number is returned via the``registered_major`` directive parameter. The directive automatically |
---|
263 | allocation major device numbers from the highest value down. |
---|
264 | |
---|
265 | This directive automatically invokes the IO_INITIALIZE directive if |
---|
266 | the driver address table has an initialization and open entry. |
---|
267 | |
---|
268 | The directive returns RTEMS_TOO_MANY if Device Driver Table is |
---|
269 | full, and RTEMS_RESOURCE_IN_USE if a specific major device |
---|
270 | number is requested and it is already in use. |
---|
271 | |
---|
272 | **NOTES:** |
---|
273 | |
---|
274 | The Device Driver Table size is specified in the Configuration Table |
---|
275 | condiguration. This needs to be set to maximum size the application |
---|
276 | requires. |
---|
277 | |
---|
278 | IO_UNREGISTER_DRIVER - Unregister a device driver |
---|
279 | ------------------------------------------------- |
---|
280 | .. index:: unregister a device driver |
---|
281 | |
---|
282 | **CALLING SEQUENCE:** |
---|
283 | |
---|
284 | .. index:: rtems_io_unregister_driver |
---|
285 | |
---|
286 | .. code:: c |
---|
287 | |
---|
288 | rtems_status_code rtems_io_unregister_driver( |
---|
289 | rtems_device_major_number major |
---|
290 | ); |
---|
291 | |
---|
292 | **DIRECTIVE STATUS CODES:** |
---|
293 | |
---|
294 | ``RTEMS_SUCCESSFUL`` - successfully registered |
---|
295 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
296 | |
---|
297 | **DESCRIPTION:** |
---|
298 | |
---|
299 | This directive removes a device driver from the Device Driver Table. |
---|
300 | |
---|
301 | **NOTES:** |
---|
302 | |
---|
303 | Currently no specific checks are made and the driver is not closed. |
---|
304 | |
---|
305 | IO_INITIALIZE - Initialize a device driver |
---|
306 | ------------------------------------------ |
---|
307 | .. index:: initialize a device driver |
---|
308 | |
---|
309 | **CALLING SEQUENCE:** |
---|
310 | |
---|
311 | .. index:: rtems_io_initialize |
---|
312 | |
---|
313 | .. code:: c |
---|
314 | |
---|
315 | rtems_status_code rtems_io_initialize( |
---|
316 | rtems_device_major_number major, |
---|
317 | rtems_device_minor_number minor, |
---|
318 | void \*argument |
---|
319 | ); |
---|
320 | |
---|
321 | **DIRECTIVE STATUS CODES:** |
---|
322 | |
---|
323 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
324 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
325 | |
---|
326 | **DESCRIPTION:** |
---|
327 | |
---|
328 | This directive calls the device driver initialization |
---|
329 | routine specified in the Device Driver Table for this major |
---|
330 | number. This directive is automatically invoked for each device |
---|
331 | driver when multitasking is initiated via the |
---|
332 | initialize_executive directive. |
---|
333 | |
---|
334 | A device driver initialization module is responsible |
---|
335 | for initializing all hardware and data structures associated |
---|
336 | with a device. If necessary, it can allocate memory to be used |
---|
337 | during other operations. |
---|
338 | |
---|
339 | **NOTES:** |
---|
340 | |
---|
341 | This directive may or may not cause the calling task |
---|
342 | to be preempted. This is dependent on the device driver being |
---|
343 | initialized. |
---|
344 | |
---|
345 | IO_REGISTER_NAME - Register a device |
---|
346 | ------------------------------------ |
---|
347 | .. index:: register device |
---|
348 | |
---|
349 | **CALLING SEQUENCE:** |
---|
350 | |
---|
351 | .. index:: rtems_io_register_name |
---|
352 | |
---|
353 | .. code:: c |
---|
354 | |
---|
355 | rtems_status_code rtems_io_register_name( |
---|
356 | const char \*name, |
---|
357 | rtems_device_major_number major, |
---|
358 | rtems_device_minor_number minor |
---|
359 | ); |
---|
360 | |
---|
361 | **DIRECTIVE STATUS CODES:** |
---|
362 | |
---|
363 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
364 | ``RTEMS_TOO_MANY`` - too many devices registered |
---|
365 | |
---|
366 | **DESCRIPTION:** |
---|
367 | |
---|
368 | This directive associates name with the specified |
---|
369 | major/minor number pair. |
---|
370 | |
---|
371 | **NOTES:** |
---|
372 | |
---|
373 | This directive will not cause the calling task to be |
---|
374 | preempted. |
---|
375 | |
---|
376 | IO_LOOKUP_NAME - Lookup a device |
---|
377 | -------------------------------- |
---|
378 | .. index:: lookup device major and minor number |
---|
379 | |
---|
380 | **CALLING SEQUENCE:** |
---|
381 | |
---|
382 | .. index:: rtems_io_lookup_name |
---|
383 | |
---|
384 | .. code:: c |
---|
385 | |
---|
386 | rtems_status_code rtems_io_lookup_name( |
---|
387 | const char \*name, |
---|
388 | rtems_driver_name_t \*device_info |
---|
389 | ); |
---|
390 | |
---|
391 | **DIRECTIVE STATUS CODES:** |
---|
392 | |
---|
393 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
394 | ``RTEMS_UNSATISFIED`` - name not registered |
---|
395 | |
---|
396 | **DESCRIPTION:** |
---|
397 | |
---|
398 | This directive returns the major/minor number pair |
---|
399 | associated with the given device name in ``device_info``. |
---|
400 | |
---|
401 | **NOTES:** |
---|
402 | |
---|
403 | This directive will not cause the calling task to be |
---|
404 | preempted. |
---|
405 | |
---|
406 | IO_OPEN - Open a device |
---|
407 | ----------------------- |
---|
408 | .. index:: open a devive |
---|
409 | |
---|
410 | **CALLING SEQUENCE:** |
---|
411 | |
---|
412 | .. index:: rtems_io_open |
---|
413 | |
---|
414 | .. code:: c |
---|
415 | |
---|
416 | rtems_status_code rtems_io_open( |
---|
417 | rtems_device_major_number major, |
---|
418 | rtems_device_minor_number minor, |
---|
419 | void \*argument |
---|
420 | ); |
---|
421 | |
---|
422 | **DIRECTIVE STATUS CODES:** |
---|
423 | |
---|
424 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
425 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
426 | |
---|
427 | **DESCRIPTION:** |
---|
428 | |
---|
429 | This directive calls the device driver open routine |
---|
430 | specified in the Device Driver Table for this major number. The |
---|
431 | open entry point is commonly used by device drivers to provide |
---|
432 | exclusive access to a device. |
---|
433 | |
---|
434 | **NOTES:** |
---|
435 | |
---|
436 | This directive may or may not cause the calling task |
---|
437 | to be preempted. This is dependent on the device driver being |
---|
438 | invoked. |
---|
439 | |
---|
440 | IO_CLOSE - Close a device |
---|
441 | ------------------------- |
---|
442 | .. index:: close a device |
---|
443 | |
---|
444 | **CALLING SEQUENCE:** |
---|
445 | |
---|
446 | .. index:: rtems_io_close |
---|
447 | |
---|
448 | .. code:: c |
---|
449 | |
---|
450 | rtems_status_code rtems_io_close( |
---|
451 | rtems_device_major_number major, |
---|
452 | rtems_device_minor_number minor, |
---|
453 | void \*argument |
---|
454 | ); |
---|
455 | |
---|
456 | **DIRECTIVE STATUS CODES:** |
---|
457 | |
---|
458 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
459 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
460 | |
---|
461 | **DESCRIPTION:** |
---|
462 | |
---|
463 | This directive calls the device driver close routine |
---|
464 | specified in the Device Driver Table for this major number. The |
---|
465 | close entry point is commonly used by device drivers to |
---|
466 | relinquish exclusive access to a device. |
---|
467 | |
---|
468 | **NOTES:** |
---|
469 | |
---|
470 | This directive may or may not cause the calling task |
---|
471 | to be preempted. This is dependent on the device driver being |
---|
472 | invoked. |
---|
473 | |
---|
474 | IO_READ - Read from a device |
---|
475 | ---------------------------- |
---|
476 | .. index:: read from a device |
---|
477 | |
---|
478 | **CALLING SEQUENCE:** |
---|
479 | |
---|
480 | .. index:: rtems_io_read |
---|
481 | |
---|
482 | .. code:: c |
---|
483 | |
---|
484 | rtems_status_code rtems_io_read( |
---|
485 | rtems_device_major_number major, |
---|
486 | rtems_device_minor_number minor, |
---|
487 | void \*argument |
---|
488 | ); |
---|
489 | |
---|
490 | **DIRECTIVE STATUS CODES:** |
---|
491 | |
---|
492 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
493 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
494 | |
---|
495 | **DESCRIPTION:** |
---|
496 | |
---|
497 | This directive calls the device driver read routine |
---|
498 | specified in the Device Driver Table for this major number. |
---|
499 | Read operations typically require a buffer address as part of |
---|
500 | the argument parameter block. The contents of this buffer will |
---|
501 | be replaced with data from the device. |
---|
502 | |
---|
503 | **NOTES:** |
---|
504 | |
---|
505 | This directive may or may not cause the calling task |
---|
506 | to be preempted. This is dependent on the device driver being |
---|
507 | invoked. |
---|
508 | |
---|
509 | IO_WRITE - Write to a device |
---|
510 | ---------------------------- |
---|
511 | .. index:: write to a device |
---|
512 | |
---|
513 | **CALLING SEQUENCE:** |
---|
514 | |
---|
515 | .. index:: rtems_io_write |
---|
516 | |
---|
517 | .. code:: c |
---|
518 | |
---|
519 | rtems_status_code rtems_io_write( |
---|
520 | rtems_device_major_number major, |
---|
521 | rtems_device_minor_number minor, |
---|
522 | void \*argument |
---|
523 | ); |
---|
524 | |
---|
525 | **DIRECTIVE STATUS CODES:** |
---|
526 | |
---|
527 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
528 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
529 | |
---|
530 | **DESCRIPTION:** |
---|
531 | |
---|
532 | This directive calls the device driver write routine |
---|
533 | specified in the Device Driver Table for this major number. |
---|
534 | Write operations typically require a buffer address as part of |
---|
535 | the argument parameter block. The contents of this buffer will |
---|
536 | be sent to the device. |
---|
537 | |
---|
538 | **NOTES:** |
---|
539 | |
---|
540 | This directive may or may not cause the calling task |
---|
541 | to be preempted. This is dependent on the device driver being |
---|
542 | invoked. |
---|
543 | |
---|
544 | IO_CONTROL - Special device services |
---|
545 | ------------------------------------ |
---|
546 | .. index:: special device services |
---|
547 | .. index:: IO Control |
---|
548 | |
---|
549 | **CALLING SEQUENCE:** |
---|
550 | |
---|
551 | .. index:: rtems_io_control |
---|
552 | |
---|
553 | .. code:: c |
---|
554 | |
---|
555 | rtems_status_code rtems_io_control( |
---|
556 | rtems_device_major_number major, |
---|
557 | rtems_device_minor_number minor, |
---|
558 | void \*argument |
---|
559 | ); |
---|
560 | |
---|
561 | **DIRECTIVE STATUS CODES:** |
---|
562 | |
---|
563 | ``RTEMS_SUCCESSFUL`` - successfully initialized |
---|
564 | ``RTEMS_INVALID_NUMBER`` - invalid major device number |
---|
565 | |
---|
566 | **DESCRIPTION:** |
---|
567 | |
---|
568 | This directive calls the device driver I/O control |
---|
569 | routine specified in the Device Driver Table for this major |
---|
570 | number. The exact functionality of the driver entry called by |
---|
571 | this directive is driver dependent. It should not be assumed |
---|
572 | that the control entries of two device drivers are compatible. |
---|
573 | For example, an RS-232 driver I/O control operation may change |
---|
574 | the baud rate of a serial line, while an I/O control operation |
---|
575 | for a floppy disk driver may cause a seek operation. |
---|
576 | |
---|
577 | **NOTES:** |
---|
578 | |
---|
579 | This directive may or may not cause the calling task |
---|
580 | to be preempted. This is dependent on the device driver being |
---|
581 | invoked. |
---|
582 | |
---|
583 | .. COMMENT: COPYRIGHT (c) 1988-2002. |
---|
584 | |
---|
585 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
586 | |
---|
587 | .. COMMENT: All rights reserved. |
---|
588 | |
---|