Changeset 059a3714 in rtems for cpukit/sapi/src/io.c


Ignore:
Timestamp:
Oct 16, 2001, 7:05:29 PM (19 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
8670008c
Parents:
8917506d
Message:

2001-10-16 Chris Johns <ccj@…>

  • include/confdefs.h, include/rtems/config.h, include/rtems/io.h, optman/no-io.c, src/exinit.c, src/io.c: Added a device driver register/unregister interface to allow device drivers to be installed and removed at runtime. This means you do not need devices present in the device table when you build.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/sapi/src/io.c

    r8917506d r059a3714  
    2525 *  _IO_Manager_initialization
    2626 *
    27  */
    28  
     27 *  The IO manager has been extended to support runtime driver
     28 *  registration. The driver table is now allocated in the
     29 *  workspace.
     30 *
     31 */
     32 
    2933void _IO_Manager_initialization(
    30   rtems_driver_address_table *driver_table,
    31   unsigned32                  number_of_drivers,
    32   unsigned32                  number_of_devices
     34    rtems_driver_address_table *driver_table,
     35    unsigned32                  drivers_in_table,
     36    unsigned32                  number_of_drivers,
     37    unsigned32                  number_of_devices
    3338)
    3439{
     
    3641  unsigned32           index;
    3742  rtems_driver_name_t *np;
     43
     44  if ( number_of_drivers < drivers_in_table )
     45      number_of_drivers = drivers_in_table;
     46 
     47  tmp = _Workspace_Allocate_or_fatal_error(
     48    sizeof( rtems_driver_address_table ) * ( number_of_drivers )
     49  );
    3850 
    39   _IO_Driver_address_table = driver_table;
    40   _IO_Number_of_drivers    = number_of_drivers;
    41   _IO_Number_of_devices    = number_of_devices;
    42  
     51  _IO_Driver_address_table = (rtems_driver_address_table *) tmp;
     52
     53  memset(
     54    _IO_Driver_address_table, 0,
     55    sizeof( rtems_driver_address_table ) * ( number_of_drivers )
     56  );
     57
     58  if ( drivers_in_table )
     59      for ( index = 0 ; index < drivers_in_table ; index++ )
     60        _IO_Driver_address_table[index] = driver_table[index];
     61 
     62  _IO_Number_of_drivers = number_of_drivers;
     63  _IO_Number_of_devices = number_of_devices;
     64 
    4365  tmp = _Workspace_Allocate_or_fatal_error(
    4466    sizeof( rtems_driver_name_t ) * ( number_of_devices + 1 )
     
    78100/*PAGE
    79101 *
     102 *  rtems_io_register_driver
     103 *
     104 *  Register a driver into the device driver table.
     105 *
     106 *  Input Paramters:
     107 *    major            - device major number (0 means allocate
     108 *                       a number)
     109 *    driver_table     - driver callout function table
     110 *    registered_major - the major number which is registered
     111 *
     112 *  Output Parameters:
     113 *    RTEMS_SUCCESSFUL - if successful
     114 *    error code       - if unsuccessful
     115 */
     116
     117rtems_status_code rtems_io_register_driver(
     118    rtems_device_major_number   major,
     119    rtems_driver_address_table *driver_table,
     120    rtems_device_major_number  *registered_major
     121)
     122{
     123    *registered_major = 0;
     124
     125    /*
     126     * Test for initialise/open being present to indicate the driver slot is
     127     * in use.
     128     */
     129
     130    if ( major >= _IO_Number_of_drivers )
     131      return RTEMS_INVALID_NUMBER;
     132
     133    if ( major == 0 )
     134    {
     135        for ( major = _IO_Number_of_drivers - 1 ; major ; major-- )
     136            if ( _IO_Driver_address_table[major].initialization_entry == 0 &&
     137                 _IO_Driver_address_table[major].open_entry == 0 )
     138                break;
     139
     140        if (( major == 0 ) &&
     141            ( _IO_Driver_address_table[major].initialization_entry == 0 &&
     142              _IO_Driver_address_table[major].open_entry == 0 ))
     143            return RTEMS_TOO_MANY;
     144    }
     145   
     146    if ( _IO_Driver_address_table[major].initialization_entry == 0 &&
     147         _IO_Driver_address_table[major].open_entry == 0 )
     148    {
     149        _IO_Driver_address_table[major] = *driver_table;
     150        *registered_major               = major;
     151
     152        rtems_io_initialize( major, 0, NULL);
     153
     154        return RTEMS_SUCCESSFUL;
     155    }
     156
     157    return RTEMS_RESOURCE_IN_USE;
     158}
     159
     160/*PAGE
     161 *
     162 *  rtems_io_unregister_driver
     163 *
     164 *  Unregister a driver from the device driver table.
     165 *
     166 *  Input Paramters:
     167 *    major            - device major number
     168 *
     169 *  Output Parameters:
     170 *    RTEMS_SUCCESSFUL - if successful
     171 *    error code       - if unsuccessful
     172 */
     173
     174rtems_status_code rtems_io_unregister_driver(
     175    rtems_device_major_number major
     176)
     177{
     178    if ( major < _IO_Number_of_drivers )
     179    {
     180        memset(
     181            &_IO_Driver_address_table[major],
     182            0,
     183            sizeof( rtems_driver_address_table )
     184        );
     185        return RTEMS_SUCCESSFUL;
     186    }
     187    return RTEMS_UNSATISFIED;
     188}
     189
     190/*PAGE
     191 *
    80192 *  rtems_io_register_name
    81193 *
     
    185297  rtems_device_major_number  major,
    186298  rtems_device_minor_number  minor,
    187   void             *argument
     299  void                      *argument
    188300)
    189301{
Note: See TracChangeset for help on using the changeset viewer.