source: rtems-docs/c_user/io_manager.rst @ f916fca

4.115
Last change on this file since f916fca was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

  • Property mode set to 100644
File size: 16.2 KB
Line 
1I/O Manager
2###########
3
4.. index:: device drivers
5.. index:: IO Manager
6
7Introduction
8============
9
10The input/output interface manager provides a
11well-defined mechanism for accessing device drivers and a
12structured methodology for organizing device drivers.  The
13directives 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
35Background
36==========
37
38Device Driver Table
39-------------------
40.. index:: Device Driver Table
41
42Each application utilizing the RTEMS I/O manager must specify the
43address of a Device Driver Table in its Configuration Table. This table
44contains each device driver's entry points that is to be initialised by
45RTEMS during initialization.  Each device driver may contain the
46following entry points:
47
48- Initialization
49
50- Open
51
52- Close
53
54- Read
55
56- Write
57
58- Control
59
60If the device driver does not support a particular
61entry point, then that entry in the Configuration Table should
62be NULL.  RTEMS will return``RTEMS_SUCCESSFUL`` as the executive's and
63zero (0) as the device driver's return code for these device
64driver entry points.
65
66Applications can register and unregister drivers with the RTEMS I/O
67manager avoiding the need to have all drivers statically defined and
68linked into this table.
69
70The :file:`confdefs.h` entry ``CONFIGURE_MAXIMUM_DRIVERS`` configures
71the number of driver slots available to the application.
72
73Major and Minor Device Numbers
74------------------------------
75.. index:: major device number
76.. index:: minor device number
77
78Each call to the I/O manager must provide a device's
79major and minor numbers as arguments.  The major number is the
80index of the requested driver's entry points in the Device
81Driver Table, and is used to select a specific device driver.
82The exact usage of the minor number is driver specific, but is
83commonly used to distinguish between a number of devices
84controlled by the same driver... index:: rtems_device_major_number
85.. index:: rtems_device_minor_number
86
87The data types ``rtems_device_major_number`` and``rtems_device_minor_number`` are used to
88manipulate device major and minor numbers, respectively.
89
90Device Names
91------------
92.. index:: device names
93
94The I/O Manager provides facilities to associate a
95name with a particular device.  Directives are provided to
96register the name of a device and to look up the major/minor
97number pair associated with a device name.
98
99Device Driver Environment
100-------------------------
101
102Application developers, as well as device driver
103developers, must be aware of the following regarding the RTEMS
104I/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
123Although the RTEMS I/O manager provides a framework
124for device drivers, it makes no assumptions regarding the
125construction or operation of a device driver.
126
127Runtime Driver Registration
128---------------------------
129.. index:: runtime driver registration
130
131Board support package and application developers can select wether a
132device driver is statically entered into the default device table or
133registered at runtime.
134
135Dynamic 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
149Device Driver Interface
150-----------------------
151.. index:: device driver interface
152
153When an application invokes an I/O manager directive,
154RTEMS determines which device driver entry point must be
155invoked.  The information passed by the application to RTEMS is
156then passed to the correct device driver entry point.  RTEMS
157will invoke each device driver entry point assuming it is
158compatible 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
167The format and contents of the parameter block are
168device driver and entry point dependent.
169
170It is recommended that a device driver avoid
171generating error codes which conflict with those used by
172application components.  A common technique used to generate
173driver specific error codes is to make the most significant part
174of the status indicate a driver specific code.
175
176Device Driver Initialization
177----------------------------
178
179RTEMS automatically initializes all device drivers
180when multitasking is initiated via the``rtems_initialize_executive``
181directive.  RTEMS initializes the device drivers by invoking
182each device driver initialization entry point with the following
183parameters:
184
185major
186    the major device number for this device driver.
187
188minor
189    zero.
190
191argument_block
192    will point to  the Configuration Table.
193
194The returned status will be ignored by RTEMS.  If the driver
195cannot successfully initialize the device, then it should invoke
196the fatal_error_occurred directive.
197
198Operations
199==========
200
201Register and Lookup Name
202------------------------
203
204The ``rtems_io_register`` directive associates a name with the
205specified device (i.e. major/minor number pair).  Device names
206are typically registered as part of the device driver
207initialization sequence.  The ``rtems_io_lookup``
208directive is used to
209determine the major/minor number pair associated with the
210specified device name.  The use of these directives frees the
211application from being dependent on the arbitrary assignment of
212major numbers in a particular application.  No device naming
213conventions are dictated by RTEMS.
214
215Accessing an Device Driver
216--------------------------
217
218The I/O manager provides directives which enable the
219application program to utilize device drivers in a standard
220manner.  There is a direct correlation between the RTEMS I/O
221manager directives``rtems_io_initialize``,``rtems_io_open``,``rtems_io_close``,``rtems_io_read``,``rtems_io_write``, and``rtems_io_control``
222and the underlying device driver entry points.
223
224Directives
225==========
226
227This section details the I/O manager's directives.  A
228subsection is dedicated to each of this manager's directives and
229describes the calling sequence, related constants, usage, and
230status codes.
231
232IO_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
259This directive attempts to add a new device driver to the Device Driver
260Table. The user can specify a specific major device number via the
261directive's ``major`` parameter, or let the registration routine find
262the 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
263allocation major device numbers from the highest value down.
264
265This directive automatically invokes the IO_INITIALIZE directive if
266the driver address table has an initialization and open entry.
267
268The directive returns RTEMS_TOO_MANY if Device Driver Table is
269full, and RTEMS_RESOURCE_IN_USE if a specific major device
270number is requested and it is already in use.
271
272**NOTES:**
273
274The Device Driver Table size is specified in the Configuration Table
275condiguration. This needs to be set to maximum size the application
276requires.
277
278IO_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
299This directive removes a device driver from the Device Driver Table.
300
301**NOTES:**
302
303Currently no specific checks are made and the driver is not closed.
304
305IO_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
328This directive calls the device driver initialization
329routine specified in the Device Driver Table for this major
330number. This directive is automatically invoked for each device
331driver when multitasking is initiated via the
332initialize_executive directive.
333
334A device driver initialization module is responsible
335for initializing all hardware and data structures associated
336with a device. If necessary, it can allocate memory to be used
337during other operations.
338
339**NOTES:**
340
341This directive may or may not cause the calling task
342to be preempted.  This is dependent on the device driver being
343initialized.
344
345IO_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
368This directive associates name with the specified
369major/minor number pair.
370
371**NOTES:**
372
373This directive will not cause the calling task to be
374preempted.
375
376IO_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
398This directive returns the major/minor number pair
399associated with the given device name in ``device_info``.
400
401**NOTES:**
402
403This directive will not cause the calling task to be
404preempted.
405
406IO_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
429This directive calls the device driver open routine
430specified in the Device Driver Table for this major number.  The
431open entry point is commonly used by device drivers to provide
432exclusive access to a device.
433
434**NOTES:**
435
436This directive may or may not cause the calling task
437to be preempted.  This is dependent on the device driver being
438invoked.
439
440IO_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
463This directive calls the device driver close routine
464specified in the Device Driver Table for this major number.  The
465close entry point is commonly used by device drivers to
466relinquish exclusive access to a device.
467
468**NOTES:**
469
470This directive may or may not cause the calling task
471to be preempted.  This is dependent on the device driver being
472invoked.
473
474IO_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
497This directive calls the device driver read routine
498specified in the Device Driver Table for this major number.
499Read operations typically require a buffer address as part of
500the argument parameter block.  The contents of this buffer will
501be replaced with data from the device.
502
503**NOTES:**
504
505This directive may or may not cause the calling task
506to be preempted.  This is dependent on the device driver being
507invoked.
508
509IO_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
532This directive calls the device driver write routine
533specified in the Device Driver Table for this major number.
534Write operations typically require a buffer address as part of
535the argument parameter block.  The contents of this buffer will
536be sent to the device.
537
538**NOTES:**
539
540This directive may or may not cause the calling task
541to be preempted.  This is dependent on the device driver being
542invoked.
543
544IO_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
568This directive calls the device driver I/O control
569routine specified in the Device Driver Table for this major
570number.  The exact functionality of the driver entry called by
571this directive is driver dependent.  It should not be assumed
572that the control entries of two device drivers are compatible.
573For example, an RS-232 driver I/O control operation may change
574the baud rate of a serial line, while an I/O control operation
575for a floppy disk driver may cause a seek operation.
576
577**NOTES:**
578
579This directive may or may not cause the calling task
580to be preempted.  This is dependent on the device driver being
581invoked.
582
583.. COMMENT: COPYRIGHT (c) 1988-2002.
584
585.. COMMENT: On-Line Applications Research Corporation (OAR).
586
587.. COMMENT: All rights reserved.
588
Note: See TracBrowser for help on using the repository browser.