source: rtems/cpukit/sapi/src/ioregisterdriver.c @ 4c98a3e

4.115
Last change on this file since 4c98a3e was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicIO
5 *
6 * @brief Classic Input/Output Manager implementation.
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2009.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  Copyright (c) 2009 embedded brains GmbH.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/system.h>
25#include <rtems/io.h>
26#include <rtems/rtems/intr.h>
27#include <rtems/score/thread.h>
28
29static inline bool rtems_io_is_empty_table(
30  const rtems_driver_address_table *table
31)
32{
33  return table->initialization_entry == NULL && table->open_entry == NULL;
34}
35
36static rtems_status_code rtems_io_obtain_major_number(
37  rtems_device_major_number *major
38)
39{
40  rtems_device_major_number n = _IO_Number_of_drivers;
41  rtems_device_major_number m = 0;
42
43  /* major is error checked by caller */
44
45  for ( m = 0; m < n; ++m ) {
46    rtems_driver_address_table *const table = _IO_Driver_address_table + m;
47
48    if ( rtems_io_is_empty_table( table ) )
49      break;
50  }
51
52  /* Assigns invalid value in case of failure */
53  *major = m;
54
55  if ( m != n )
56    return RTEMS_SUCCESSFUL;
57
58  return RTEMS_TOO_MANY;
59}
60
61rtems_status_code rtems_io_register_driver(
62  rtems_device_major_number         major,
63  const rtems_driver_address_table *driver_table,
64  rtems_device_major_number        *registered_major
65)
66{
67  rtems_device_major_number major_limit = _IO_Number_of_drivers;
68
69  if ( rtems_interrupt_is_in_progress() )
70    return RTEMS_CALLED_FROM_ISR;
71
72  if ( registered_major == NULL )
73    return RTEMS_INVALID_ADDRESS;
74
75  /* Set it to an invalid value */
76  *registered_major = major_limit;
77
78  if ( driver_table == NULL )
79    return RTEMS_INVALID_ADDRESS;
80
81  if ( rtems_io_is_empty_table( driver_table ) )
82    return RTEMS_INVALID_ADDRESS;
83
84  if ( major >= major_limit )
85    return RTEMS_INVALID_NUMBER;
86
87  _Thread_Disable_dispatch();
88
89  if ( major == 0 ) {
90    rtems_status_code sc = rtems_io_obtain_major_number( registered_major );
91
92    if ( sc != RTEMS_SUCCESSFUL ) {
93      _Thread_Enable_dispatch();
94      return sc;
95    }
96    major = *registered_major;
97  } else {
98    rtems_driver_address_table *const table = _IO_Driver_address_table + major;
99
100    if ( !rtems_io_is_empty_table( table ) ) {
101      _Thread_Enable_dispatch();
102      return RTEMS_RESOURCE_IN_USE;
103    }
104
105    *registered_major = major;
106  }
107
108  _IO_Driver_address_table [major] = *driver_table;
109
110  _Thread_Enable_dispatch();
111
112  return rtems_io_initialize( major, 0, NULL );
113}
Note: See TracBrowser for help on using the repository browser.