source: rtems/cpukit/sapi/src/ioregisterdriver.c @ 37f9717a

4.104.115
Last change on this file since 37f9717a was 6914ffe, checked in by Joel Sherrill <joel.sherrill@…>, on 07/25/09 at 01:44:04

2009-07-24 Joel Sherrill <joel.sherrill@…>

  • sapi/src/ioregisterdriver.c: Fix spacing.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  Input/Output Manager - Dynamically Register Device Driver
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/io.h>
20
21/*
22 *  rtems_io_register_driver
23 *
24 *  Register a driver into the device driver table.
25 *
26 *  Input Paramters:
27 *    major            - device major number (0 means allocate
28 *                       a number)
29 *    driver_table     - driver callout function table
30 *    registered_major - the major number which is registered
31 *
32 *  Output Parameters:
33 *    RTEMS_SUCCESSFUL - if successful
34 *    error code       - if unsuccessful
35 */
36
37rtems_status_code rtems_io_register_driver(
38  rtems_device_major_number         major,
39  const rtems_driver_address_table *driver_table,
40  rtems_device_major_number        *registered_major
41)
42{
43
44  /*
45   *  Validate the pointer data and contents passed in
46   */
47  if ( !driver_table )
48    return RTEMS_INVALID_ADDRESS;
49
50  if ( !registered_major )
51    return RTEMS_INVALID_ADDRESS;
52
53  if ( !driver_table->initialization_entry && !driver_table->open_entry )
54    return RTEMS_INVALID_ADDRESS;
55
56  *registered_major = 0;
57
58  /*
59   *  The requested major number is higher than what is configured.
60   */
61  if ( major >= _IO_Number_of_drivers )
62    return RTEMS_INVALID_NUMBER;
63
64  /*
65   * Test for initialise/open being present to indicate the driver slot is
66   * in use.
67   */
68
69  if ( major == 0 ) {
70    bool found = false;
71    for ( major = _IO_Number_of_drivers - 1 ; major ; major-- ) {
72      if ( !_IO_Driver_address_table[major].initialization_entry &&
73           !_IO_Driver_address_table[major].open_entry ) {
74        found = true;
75        break;
76      }
77    }
78
79    if ( !found )
80      return RTEMS_TOO_MANY;
81  }
82
83  if ( _IO_Driver_address_table[major].initialization_entry ||
84       _IO_Driver_address_table[major].open_entry )
85    return RTEMS_RESOURCE_IN_USE;
86
87
88  _IO_Driver_address_table[major] = *driver_table;
89  *registered_major               = major;
90
91  return rtems_io_initialize( major, 0, NULL );
92}
Note: See TracBrowser for help on using the repository browser.