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

5
Last change on this file since 12dccfe was 12dccfe, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:05

Remove superfluous "All rights reserved."

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