source: rtems/cpukit/sapi/src/ioregisterdriver.c @ 7b1df577

4.104.115
Last change on this file since 7b1df577 was 7b1df577, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 6, 2009 at 10:42:48 PM

2009-10-06 Joel Sherrill <joel.sherrill@…>

  • sapi/src/ioregisterdriver.c: Reowork so this is a context switch disable critical section not interrupt disable critical section. Hopefully eliminated dead code which showed up in coverage runs.
  • 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 *  $Id$
20 */
21
22#if HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <rtems/system.h>
27#include <rtems/io.h>
28#include <rtems/rtems/intr.h>
29#include <rtems/score/thread.h>
30
31static inline bool rtems_io_is_empty_table(
32  const rtems_driver_address_table *table
33)
34{
35  return table->initialization_entry == NULL && table->open_entry == NULL;
36}
37
38static rtems_status_code rtems_io_obtain_major_number(
39  rtems_device_major_number *major
40)
41{
42  rtems_device_major_number n = _IO_Number_of_drivers;
43  rtems_device_major_number m = 0;
44 
45  /* major is error checked by caller */
46
47  for ( m = 0; m < n; ++m ) {
48    rtems_driver_address_table *const table = _IO_Driver_address_table + m;
49
50    if ( rtems_io_is_empty_table( table ) )
51      break;
52  }
53
54  /* Assigns invalid value in case of failure */
55  *major = m;
56
57  if ( m != n )
58    return RTEMS_SUCCESSFUL;
59
60  return RTEMS_TOO_MANY;
61}
62
63rtems_status_code rtems_io_register_driver(
64  rtems_device_major_number         major,
65  const rtems_driver_address_table *driver_table,
66  rtems_device_major_number        *registered_major
67)
68{
69  rtems_device_major_number major_limit = _IO_Number_of_drivers;
70
71  if ( registered_major == NULL )
72    return RTEMS_INVALID_ADDRESS;
73
74  /* Set it to an invalid value */
75  *registered_major = major_limit;
76
77  if ( driver_table == NULL )
78    return RTEMS_INVALID_ADDRESS;
79
80  if ( rtems_io_is_empty_table( driver_table ) )
81    return RTEMS_INVALID_ADDRESS;
82
83  if ( major >= major_limit )
84    return RTEMS_INVALID_NUMBER;
85
86  _Thread_Disable_dispatch();
87
88  if ( major == 0 ) {
89    rtems_status_code sc = rtems_io_obtain_major_number( registered_major );
90
91    if ( sc != RTEMS_SUCCESSFUL ) {
92      _Thread_Enable_dispatch();
93      return sc;
94    }
95    major = *registered_major;
96  } else {
97    rtems_driver_address_table *const table = _IO_Driver_address_table + major;
98
99    if ( !rtems_io_is_empty_table( table ) ) {
100      _Thread_Enable_dispatch();
101      return RTEMS_RESOURCE_IN_USE;
102    }
103
104    *registered_major = major;
105  }
106
107  _IO_Driver_address_table [major] = *driver_table;
108
109  _Thread_Enable_dispatch();
110
111  return rtems_io_initialize( major, 0, NULL );
112}
Note: See TracBrowser for help on using the repository browser.