source: rtems-docs/c-user/io_manager.rst @ c65aeed

5
Last change on this file since c65aeed was 3384994, checked in by Chris Johns <chrisj@…>, on 11/13/17 at 02:25:18

Clean up sphinx warnings.

  • Fix minor formatting issues.
  • Fix reference the gloassary TLS using ':term:'.
  • Make sure nothing is between an anchor and the heading where ':ref:' references the anchor. This meant moving all the recently added '.. index::' entries.

Update #3232.
Update #3229.

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