Changeset 55e0be36 in rtems


Ignore:
Timestamp:
Sep 16, 2016, 10:58:06 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
e814a23
Parents:
610b9ef
git-author:
Sebastian Huber <sebastian.huber@…> (09/16/16 10:58:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/19/16 05:52:33)
Message:

termios: Use IMFS nodes for new Termios devices

This makes the new Termios devices independent of device major/minor
numbers. It enables BSP independent Termios device drivers which may
reside in the cpukit domain. These drivers require an IMFS and do not
work with the device file system. However, the device file system
should go away in the future.

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/atsam/console/console.c

    r610b9ef r55e0be36  
    2222#include <chip.h>
    2323
     24#include <unistd.h>
     25
    2426typedef struct {
    2527  rtems_termios_device_context base;
     
    489491    rtems_termios_device_install(
    490492      &usart[0],
    491       major,
    492       minor,
    493493      &atsam_usart_handler,
    494494      NULL,
     
    499499    if (i == ATSAM_CONSOLE_DEVICE_INDEX) {
    500500      atsam_usart_instances[i].console = true;
    501       rtems_io_register_name(CONSOLE_DEVICE_NAME, major, minor);
     501      link(&usart[0], CONSOLE_DEVICE_NAME);
    502502    }
    503503#endif
    504 
    505     ++minor;
    506504  }
    507505
     
    512510    rtems_termios_device_install(
    513511      &uart[0],
    514       major,
    515       minor,
    516512      &atsam_uart_handler,
    517513      NULL,
     
    522518    if (i == ATSAM_CONSOLE_DEVICE_INDEX) {
    523519      atsam_uart_instances[i].console = true;
    524       rtems_io_register_name(CONSOLE_DEVICE_NAME, major, minor);
     520      link(&usart[0], CONSOLE_DEVICE_NAME);
    525521    }
    526522#endif
    527 
    528     ++minor;
    529523  }
    530524
  • c/src/lib/libbsp/arm/tms570/console/tms570-sci.c

    r610b9ef r55e0be36  
    139139    sc = rtems_termios_device_install(
    140140        ctx->device_name,
    141         major,
    142         minor,
    143141        handler,
    144142        NULL,
  • c/src/lib/libbsp/powerpc/t32mppc/console/console.c

    r610b9ef r55e0be36  
    116116  rtems_termios_device_install(
    117117    CONSOLE_DEVICE_NAME,
    118     major,
    119     0,
    120118    &t32_console_handler,
    121119    NULL,
  • c/src/lib/libbsp/shared/console-termios-init.c

    r610b9ef r55e0be36  
    11/*
    2  * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1818#include <rtems/console.h>
    1919
    20 RTEMS_INTERRUPT_LOCK_DEFINE( static, console_lock, "console" )
    21 
    22 static rtems_device_major_number console_major = UINT32_MAX;
    23 
    24 static rtems_device_minor_number console_minor;
    25 
    26 rtems_status_code console_device_install(
    27   const char                         *device_file,
    28   const rtems_termios_device_handler *handler,
    29   const rtems_termios_device_flow    *flow,
    30   rtems_termios_device_context       *context
    31 )
    32 {
    33   rtems_interrupt_lock_context lock_context;
    34   rtems_device_minor_number    minor;
    35 
    36   rtems_interrupt_lock_acquire( &console_lock, &lock_context );
    37   minor = console_minor;
    38   ++console_minor;
    39   rtems_interrupt_lock_release( &console_lock, &lock_context );
    40 
    41   return rtems_termios_device_install(
    42     device_file,
    43     console_major,
    44     minor,
    45     handler,
    46     flow,
    47     context
    48   );
    49 }
     20#include <unistd.h>
    5021
    5122bool console_device_probe_default(rtems_termios_device_context *context)
     
    7344      sc = rtems_termios_device_install(
    7445        ctx->device_file,
    75         major,
    76         minor,
    7746        ctx->handler,
    7847        ctx->flow,
     
    8655        console_device_done = true;
    8756
    88         sc = rtems_io_register_name( CONSOLE_DEVICE_NAME, major, minor );
    89         if ( sc != RTEMS_SUCCESSFUL ) {
     57        if ( link( ctx->device_file, CONSOLE_DEVICE_NAME ) != 0 ) {
    9058          bsp_fatal( BSP_FATAL_CONSOLE_INSTALL_1 );
    9159        }
     
    9462  }
    9563
    96   console_major = major;
    97   console_minor = minor;
    98 
    9964  return RTEMS_SUCCESSFUL;
    10065}
  • c/src/lib/libbsp/shared/console-termios.c

    r610b9ef r55e0be36  
    11/*
    2  * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    2222)
    2323{
    24   return rtems_termios_device_open( major, minor, arg );
     24  (void) major;
     25  (void) minor;
     26  (void) arg;
     27
     28  return RTEMS_INTERNAL_ERROR;
    2529}
    2630
     
    3337  (void) major;
    3438  (void) minor;
     39  (void) arg;
    3540
    36   return rtems_termios_device_close( arg );
     41  return RTEMS_INTERNAL_ERROR;
    3742}
    3843
     
    4550  (void) major;
    4651  (void) minor;
     52  (void) arg;
    4753
    48   return rtems_termios_read( arg );
     54  return RTEMS_INTERNAL_ERROR;
    4955}
    5056
     
    5763  (void) major;
    5864  (void) minor;
     65  (void) arg;
    5966
    60   return rtems_termios_write( arg );
     67  return RTEMS_INTERNAL_ERROR;
    6168}
    6269
     
    6976  (void) major;
    7077  (void) minor;
     78  (void) arg;
    7179
    72   return rtems_termios_ioctl( arg );
     80  return RTEMS_INTERNAL_ERROR;
    7381}
  • c/src/lib/libbsp/shared/include/console-termios.h

    r610b9ef r55e0be36  
    8888
    8989/**
    90  * @brief Installs a console device after console driver initialization.
    91  *
    92  * @param[in] device_file The device file path.
    93  * @param[in] handler The Termios device handler.  It must be persistent
    94  *   throughout the installed time of the device.
    95  * @param[in] flow The Termios device flow control handler.  The device flow
    96  *   control handler are optional and may be @c NULL.  If present must be
    97  *   persistent throughout the installed time of the device.
    98  * @param[in] context The Termios device context.  It must be persistent
    99  *   throughout the installed time of the device.
    100  */
    101 rtems_status_code console_device_install(
    102   const char                         *device_file,
    103   const rtems_termios_device_handler *handler,
    104   const rtems_termios_device_flow    *flow,
    105   rtems_termios_device_context       *context
    106 );
    107 
    108 /**
    10990 * @brief Returns true and does nothing else.
    11091 */
  • c/src/lib/libbsp/sparc/leon3/console/console.c

    r610b9ef r55e0be36  
    132132   */
    133133  if (syscon_uart_index < uarts) {
    134     minor = 0;
    135134    status = rtems_termios_device_install(
    136135      CONSOLE_DEVICE_NAME,
    137       major,
    138       minor,
    139136      handler,
    140137      NULL,
     
    149146      continue; /* skip UART that is registered as /dev/console */
    150147    console_name[13] = 'a' + i;
    151     minor = i + 1;
    152148    rtems_termios_device_install(
    153149      console_name,
    154       major,
    155       minor,
    156150      handler,
    157151      NULL,
  • cpukit/libcsupport/include/rtems/termiostypes.h

    r610b9ef r55e0be36  
    345345 * @brief Installs a Termios device.
    346346 *
    347  * @param[in] device_file If not @c NULL, then a device file for the specified
    348  *   major and minor number will be created.
    349  * @param[in] major The device major number of the corresponding device driver.
    350  * @param[in] minor The device minor number of the corresponding device driver.
     347 * The installed Termios device may be removed via unlink().
     348 *
     349 * @param[in] device_file The device file path.
    351350 * @param[in] handler The device handler.  It must be persistent throughout the
    352351 *   installed time of the device.
     
    360359 * @retval RTEMS_NO_MEMORY Not enough memory to create a device node.
    361360 * @retval RTEMS_UNSATISFIED Creation of the device file failed.
    362  * @retval RTEMS_RESOURCE_IN_USE There exists a device node for this major and
    363  *   minor number pair.
    364361 * @retval RTEMS_INCORRECT_STATE Termios is not initialized.
    365362 *
    366  * @see rtems_termios_device_remove(), rtems_termios_device_open(),
    367  *   rtems_termios_device_close() and rtems_termios_get_device_context().
     363 * @see rtems_termios_get_device_context().
    368364 */
    369365rtems_status_code rtems_termios_device_install(
    370366  const char                         *device_file,
    371   rtems_device_major_number           major,
    372   rtems_device_minor_number           minor,
    373367  const rtems_termios_device_handler *handler,
    374368  const rtems_termios_device_flow    *flow,
    375369  rtems_termios_device_context       *context
    376370);
    377 
    378 /**
    379  * @brief Removes a Termios device.
    380  *
    381  * @param[in] device_file If not @c NULL, then the device file to remove.
    382  * @param[in] major The device major number of the corresponding device driver.
    383  * @param[in] minor The device minor number of the corresponding device driver.
    384  *
    385  * @retval RTEMS_SUCCESSFUL Successful operation.
    386  * @retval RTEMS_INVALID_ID There is no device installed with this major and
    387  * minor number pair.
    388  * @retval RTEMS_RESOURCE_IN_USE This device is currently in use.
    389  * @retval RTEMS_UNSATISFIED Removal of the device file failed.
    390  * @retval RTEMS_INCORRECT_STATE Termios is not initialized.
    391  *
    392  * @see rtems_termios_device_install().
    393  */
    394 rtems_status_code rtems_termios_device_remove(
    395   const char                *device_file,
    396   rtems_device_major_number  major,
    397   rtems_device_minor_number  minor
    398 );
    399 
    400 /**
    401  * @brief Opens an installed Termios device.
    402  *
    403  * @see rtems_termios_device_install().
    404  */
    405 rtems_status_code rtems_termios_device_open(
    406   rtems_device_major_number  major,
    407   rtems_device_minor_number  minor,
    408   void                      *arg
    409 );
    410 
    411 /**
    412  * @brief Closes an installed Termios device.
    413  *
    414  * @retval RTEMS_SUCCESSFUL Successful operation.
    415  *
    416  * @see rtems_termios_device_install().
    417  */
    418 rtems_status_code rtems_termios_device_close(void *arg);
    419371
    420372/**
  • cpukit/libcsupport/src/termios.c

    r610b9ef r55e0be36  
    2323#include <rtems.h>
    2424#include <rtems/libio.h>
     25#include <rtems/imfs.h>
     26#include <rtems/score/assert.h>
    2527#include <ctype.h>
    2628#include <errno.h>
     
    8688static size_t rtems_termios_raw_output_size = 64;
    8789
     90static const IMFS_node_control rtems_termios_imfs_node_control;
     91
    8892static struct rtems_termios_tty *rtems_termios_ttyHead;
    8993static struct rtems_termios_tty *rtems_termios_ttyTail;
     
    109113#define TERMIOS_RX_TERMINATE_EVENT RTEMS_EVENT_0
    110114
    111 static rtems_termios_device_node *
    112 rtems_termios_find_device_node(
    113   rtems_device_major_number major,
    114   rtems_device_minor_number minor
    115 )
    116 {
    117   rtems_chain_node *tail = rtems_chain_tail(&rtems_termios_devices);
    118   rtems_chain_node *current = rtems_chain_first(&rtems_termios_devices);
    119 
    120   while (current != tail) {
    121     rtems_termios_device_node *device_node =
    122       (rtems_termios_device_node *) current;
    123 
    124     if (device_node->major == major && device_node->minor == minor) {
    125       return device_node;
    126     }
    127 
    128     current = rtems_chain_next(current);
    129   }
    130 
    131   return NULL;
     115static rtems_status_code
     116rtems_termios_obtain (void)
     117{
     118  return rtems_semaphore_obtain (rtems_termios_ttyMutex, RTEMS_WAIT,
     119    RTEMS_NO_TIMEOUT);
     120}
     121
     122static void
     123rtems_termios_release (void)
     124{
     125  rtems_status_code sc;
     126
     127  sc = rtems_semaphore_release (rtems_termios_ttyMutex);
     128  _Assert (sc == RTEMS_SUCCESSFUL);
     129  (void) sc;
    132130}
    133131
    134132rtems_status_code rtems_termios_device_install(
    135133  const char                         *device_file,
    136   rtems_device_major_number           major,
    137   rtems_device_minor_number           minor,
    138134  const rtems_termios_device_handler *handler,
    139135  const rtems_termios_device_flow    *flow,
     
    141137)
    142138{
    143   rtems_status_code          sc;
    144139  rtems_termios_device_node *new_device_node;
    145   rtems_termios_device_node *existing_device_node;
    146 
    147   new_device_node = malloc(sizeof(*new_device_node));
     140  int rv;
     141
     142  new_device_node = calloc (1, sizeof(*new_device_node));
    148143  if (new_device_node == NULL) {
    149144    return RTEMS_NO_MEMORY;
    150145  }
    151146
    152   rtems_chain_initialize_node(&new_device_node->node);
    153   new_device_node->major = major;
    154   new_device_node->minor = minor;
     147  rtems_chain_initialize_node (&new_device_node->node);
    155148  new_device_node->handler = handler;
    156149  new_device_node->flow = flow;
     
    158151  new_device_node->tty = NULL;
    159152
    160   sc = rtems_semaphore_obtain(
    161     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    162   if (sc != RTEMS_SUCCESSFUL) {
    163     free(new_device_node);
    164     return RTEMS_INCORRECT_STATE;
    165   }
    166 
    167   existing_device_node = rtems_termios_find_device_node (major, minor);
    168   if (existing_device_node != NULL) {
    169     free(new_device_node);
    170     rtems_semaphore_release (rtems_termios_ttyMutex);
    171     return RTEMS_RESOURCE_IN_USE;
    172   }
    173 
    174   if (device_file != NULL) {
    175     sc = rtems_io_register_name (device_file, major, minor);
    176     if (sc != RTEMS_SUCCESSFUL) {
    177       free(new_device_node);
    178       rtems_semaphore_release (rtems_termios_ttyMutex);
    179       return RTEMS_UNSATISFIED;
    180     }
    181   }
    182 
    183   rtems_chain_append_unprotected(
    184     &rtems_termios_devices, &new_device_node->node);
    185 
    186   rtems_semaphore_release (rtems_termios_ttyMutex);
    187 
    188   return RTEMS_SUCCESSFUL;
    189 }
    190 
    191 rtems_status_code rtems_termios_device_remove(
    192   const char                *device_file,
    193   rtems_device_major_number  major,
    194   rtems_device_minor_number  minor
    195 )
    196 {
    197   rtems_status_code          sc;
    198   rtems_termios_device_node *device_node;
    199 
    200   sc = rtems_semaphore_obtain(
    201     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    202   if (sc != RTEMS_SUCCESSFUL) {
    203     return RTEMS_INCORRECT_STATE;
    204   }
    205 
    206   device_node = rtems_termios_find_device_node (major, minor);
    207   if (device_node == NULL) {
    208     rtems_semaphore_release (rtems_termios_ttyMutex);
    209     return RTEMS_INVALID_ID;
    210   }
    211 
    212   if (device_node->tty != NULL) {
    213     rtems_semaphore_release (rtems_termios_ttyMutex);
    214     return RTEMS_RESOURCE_IN_USE;
    215   }
    216 
    217   if (device_file != NULL) {
    218     int rv = unlink (device_file);
    219 
    220     if (rv != 0) {
    221       rtems_semaphore_release (rtems_termios_ttyMutex);
    222       return RTEMS_UNSATISFIED;
    223     }
    224   }
    225 
    226   rtems_chain_extract_unprotected (&device_node->node);
    227   free (device_node);
    228 
    229   rtems_semaphore_release (rtems_termios_ttyMutex);
     153  rv = IMFS_make_generic_node(
     154    device_file,
     155    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
     156    &rtems_termios_imfs_node_control,
     157    new_device_node
     158  );
     159  if (rv != 0) {
     160    free (new_device_node);
     161    return RTEMS_UNSATISFIED;
     162  }
    230163
    231164  return RTEMS_SUCCESSFUL;
     
    630563}
    631564
    632 rtems_status_code
    633 rtems_termios_device_open(
    634   rtems_device_major_number  major,
    635   rtems_device_minor_number  minor,
    636   void                      *arg
    637 )
    638 {
    639   rtems_status_code          sc;
    640   rtems_termios_device_node *device_node;
    641   struct rtems_termios_tty  *tty;
    642 
    643   sc = rtems_semaphore_obtain(
    644     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    645   if (sc != RTEMS_SUCCESSFUL)
    646     return sc;
    647 
    648   device_node = rtems_termios_find_device_node (major, minor);
    649   if (device_node == NULL) {
    650     rtems_semaphore_release (rtems_termios_ttyMutex);
    651     return RTEMS_INVALID_ID;
    652   }
    653 
    654   tty = rtems_termios_open_tty(
    655     major, minor, arg, device_node->tty, device_node, NULL);
    656   if (tty == NULL) {
    657     rtems_semaphore_release (rtems_termios_ttyMutex);
    658     return RTEMS_NO_MEMORY;
    659   }
    660 
    661   rtems_semaphore_release (rtems_termios_ttyMutex);
    662 
    663   return RTEMS_SUCCESSFUL;
    664 }
    665 
    666565/*
    667566 * Open a termios device
     
    681580   * See if the device has already been opened
    682581   */
    683   sc = rtems_semaphore_obtain(
    684     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     582  sc = rtems_termios_obtain ();
    685583  if (sc != RTEMS_SUCCESSFUL)
    686584    return sc;
     
    694592    major, minor, arg, tty, NULL, callbacks);
    695593  if (tty == NULL) {
    696     rtems_semaphore_release (rtems_termios_ttyMutex);
     594    rtems_termios_release ();
    697595    return RTEMS_NO_MEMORY;
    698596  }
     
    711609  }
    712610
    713   rtems_semaphore_release (rtems_termios_ttyMutex);
     611  rtems_termios_release ();
    714612
    715613  return RTEMS_SUCCESSFUL;
     
    756654  struct rtems_termios_tty *tty = args->iop->data1;
    757655
    758   sc = rtems_semaphore_obtain(
    759     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     656  sc = rtems_termios_obtain ();
    760657  if (sc != RTEMS_SUCCESSFUL)
    761658    rtems_fatal_error_occurred (sc);
     
    783680  rtems_termios_close_tty (tty, arg);
    784681
    785   rtems_semaphore_release (rtems_termios_ttyMutex);
    786 
    787   return RTEMS_SUCCESSFUL;
    788 }
    789 
    790 rtems_status_code
    791 rtems_termios_device_close (void *arg)
    792 {
    793   rtems_status_code sc;
    794   rtems_libio_open_close_args_t *args = arg;
    795   struct rtems_termios_tty *tty = args->iop->data1;
    796 
    797   sc = rtems_semaphore_obtain(
    798     rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    799   if (sc != RTEMS_SUCCESSFUL)
    800     rtems_fatal_error_occurred (sc);
    801 
    802   rtems_termios_close_tty (tty, arg);
    803 
    804   rtems_semaphore_release (rtems_termios_ttyMutex);
     682  rtems_termios_release ();
    805683
    806684  return RTEMS_SUCCESSFUL;
     
    11941072}
    11951073
     1074static uint32_t
     1075rtems_termios_write_tty (struct rtems_termios_tty *tty, const char *buffer,
     1076  uint32_t initial_count)
     1077{
     1078
     1079  if (tty->termios.c_oflag & OPOST) {
     1080    uint32_t count;
     1081
     1082    count = initial_count;
     1083
     1084    while (count--)
     1085      oproc (*buffer++, tty);
     1086  } else {
     1087    rtems_termios_puts (buffer, initial_count, tty);
     1088  }
     1089
     1090  return initial_count;
     1091}
     1092
    11961093rtems_status_code
    11971094rtems_termios_write (void *arg)
     
    12091106    return sc;
    12101107  }
    1211   if (tty->termios.c_oflag & OPOST) {
    1212     uint32_t   count = args->count;
    1213     char      *buffer = args->buffer;
    1214     while (count--)
    1215       oproc (*buffer++, tty);
    1216     args->bytes_moved = args->count;
    1217   } else {
    1218     rtems_termios_puts (args->buffer, args->count, tty);
    1219     args->bytes_moved = args->count;
    1220   }
     1108  args->bytes_moved = rtems_termios_write_tty (tty, args->buffer, args->count);
    12211109  rtems_semaphore_release (tty->osem);
    12221110  return sc;
     
    15221410}
    15231411
    1524 rtems_status_code
    1525 rtems_termios_read (void *arg)
    1526 {
    1527   rtems_libio_rw_args_t *args = arg;
    1528   struct rtems_termios_tty *tty = args->iop->data1;
    1529   uint32_t   count = args->count;
    1530   char      *buffer = args->buffer;
    1531   rtems_status_code sc;
    1532 
    1533   sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    1534   if (sc != RTEMS_SUCCESSFUL)
    1535     return sc;
    1536 
    1537   if (rtems_termios_linesw[tty->t_line].l_read != NULL) {
    1538     sc = rtems_termios_linesw[tty->t_line].l_read(tty,args);
    1539     tty->tty_rcvwakeup = 0;
    1540     rtems_semaphore_release (tty->isem);
    1541     return sc;
    1542   }
     1412static uint32_t
     1413rtems_termios_read_tty (struct rtems_termios_tty *tty, char *buffer,
     1414  uint32_t initial_count)
     1415{
     1416  uint32_t count;
     1417
     1418  count = initial_count;
    15431419
    15441420  if (tty->cindex == tty->ccount) {
     1421    rtems_status_code sc;
     1422
    15451423    tty->cindex = tty->ccount = 0;
    15461424    tty->read_start_column = tty->column;
     
    15571435    count--;
    15581436  }
    1559   args->bytes_moved = args->count - count;
    15601437  tty->tty_rcvwakeup = 0;
     1438  return initial_count - count;
     1439}
     1440
     1441rtems_status_code
     1442rtems_termios_read (void *arg)
     1443{
     1444  rtems_libio_rw_args_t *args = arg;
     1445  struct rtems_termios_tty *tty = args->iop->data1;
     1446  rtems_status_code sc;
     1447
     1448  sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     1449  if (sc != RTEMS_SUCCESSFUL)
     1450    return sc;
     1451
     1452  if (rtems_termios_linesw[tty->t_line].l_read != NULL) {
     1453    sc = rtems_termios_linesw[tty->t_line].l_read(tty,args);
     1454    tty->tty_rcvwakeup = 0;
     1455    rtems_semaphore_release (tty->isem);
     1456    return sc;
     1457  }
     1458
     1459  args->bytes_moved = rtems_termios_read_tty (tty, args->buffer, args->count);
    15611460  rtems_semaphore_release (tty->isem);
    15621461  return sc;
     
    19291828  }
    19301829}
     1830
     1831static int
     1832rtems_termios_imfs_open (rtems_libio_t *iop,
     1833  const char *path, int oflag, mode_t mode)
     1834{
     1835  rtems_termios_device_node *device_node;
     1836  rtems_status_code sc;
     1837  rtems_libio_open_close_args_t args;
     1838  struct rtems_termios_tty *tty;
     1839
     1840  device_node = IMFS_generic_get_context_by_iop (iop);
     1841
     1842  memset (&args, 0, sizeof (args));
     1843  args.iop = iop;
     1844  args.flags = iop->flags;
     1845  args.mode = mode;
     1846
     1847  sc = rtems_termios_obtain ();
     1848  if (sc != RTEMS_SUCCESSFUL) {
     1849    rtems_set_errno_and_return_minus_one (ENXIO);
     1850  }
     1851
     1852  tty = rtems_termios_open_tty (device_node->major, device_node->minor, &args,
     1853      device_node->tty, device_node, NULL);
     1854  if (tty == NULL) {
     1855    rtems_termios_release ();
     1856    rtems_set_errno_and_return_minus_one (ENOMEM);
     1857  }
     1858
     1859  rtems_termios_release ();
     1860  return 0;
     1861}
     1862
     1863static int
     1864rtems_termios_imfs_close (rtems_libio_t *iop)
     1865{
     1866  rtems_status_code sc;
     1867  rtems_libio_open_close_args_t args;
     1868  struct rtems_termios_tty *tty;
     1869
     1870  memset (&args, 0, sizeof (args));
     1871  args.iop = iop;
     1872
     1873  tty = iop->data1;
     1874
     1875  sc = rtems_termios_obtain ();
     1876  _Assert (sc == RTEMS_SUCCESSFUL);
     1877  (void) sc;
     1878
     1879  rtems_termios_close_tty (tty, &args);
     1880  rtems_termios_release ();
     1881  return 0;
     1882}
     1883
     1884static ssize_t
     1885rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count)
     1886{
     1887  struct rtems_termios_tty *tty;
     1888  rtems_status_code sc;
     1889  uint32_t bytes_moved;
     1890
     1891  tty = iop->data1;
     1892
     1893  sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     1894  _Assert (sc == RTEMS_SUCCESSFUL);
     1895
     1896  if (rtems_termios_linesw[tty->t_line].l_read != NULL) {
     1897    rtems_libio_rw_args_t args;
     1898
     1899    memset (&args, 0, sizeof (args));
     1900    args.iop = iop;
     1901    args.buffer = buffer;
     1902    args.count = count;
     1903    args.flags = iop->flags;
     1904
     1905    sc = rtems_termios_linesw[tty->t_line].l_read (tty, &args);
     1906    tty->tty_rcvwakeup = 0;
     1907    rtems_semaphore_release (tty->isem);
     1908
     1909    if (sc != RTEMS_SUCCESSFUL) {
     1910      return rtems_status_code_to_errno (sc);
     1911    }
     1912
     1913    return (ssize_t) args.bytes_moved;
     1914  }
     1915
     1916  bytes_moved = rtems_termios_read_tty (tty, buffer, count);
     1917  rtems_semaphore_release (tty->isem);
     1918  return (ssize_t) bytes_moved;
     1919}
     1920
     1921static ssize_t
     1922rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count)
     1923{
     1924  struct rtems_termios_tty *tty;
     1925  rtems_status_code sc;
     1926  uint32_t bytes_moved;
     1927
     1928  tty = iop->data1;
     1929
     1930  sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     1931  _Assert (sc == RTEMS_SUCCESSFUL);
     1932
     1933  if (rtems_termios_linesw[tty->t_line].l_write != NULL) {
     1934    rtems_libio_rw_args_t args;
     1935
     1936    memset (&args, 0, sizeof (args));
     1937    args.iop = iop;
     1938    args.buffer = RTEMS_DECONST (void *, buffer);
     1939    args.count = count;
     1940    args.flags = iop->flags;
     1941
     1942    sc = rtems_termios_linesw[tty->t_line].l_write (tty, &args);
     1943    rtems_semaphore_release (tty->osem);
     1944
     1945    if (sc != RTEMS_SUCCESSFUL) {
     1946      return rtems_status_code_to_errno (sc);
     1947    }
     1948
     1949    return (ssize_t) args.bytes_moved;
     1950  }
     1951
     1952  bytes_moved = rtems_termios_write_tty (tty, buffer, count);
     1953  rtems_semaphore_release (tty->osem);
     1954  return (ssize_t) bytes_moved;
     1955}
     1956
     1957static int
     1958rtems_termios_imfs_ioctl (rtems_libio_t *iop, uint32_t request, void *buffer)
     1959{
     1960  rtems_status_code sc;
     1961  rtems_libio_ioctl_args_t args;
     1962
     1963  memset (&args, 0, sizeof (args));
     1964  args.iop = iop;
     1965  args.command = request;
     1966  args.buffer = buffer;
     1967
     1968  sc = rtems_termios_ioctl (&args);
     1969  if ( sc == RTEMS_SUCCESSFUL ) {
     1970    return args.ioctl_return;
     1971  } else {
     1972    return rtems_status_code_to_errno (sc);
     1973  }
     1974}
     1975
     1976static const rtems_filesystem_file_handlers_r rtems_termios_imfs_handler = {
     1977  .open_h = rtems_termios_imfs_open,
     1978  .close_h = rtems_termios_imfs_close,
     1979  .read_h = rtems_termios_imfs_read,
     1980  .write_h = rtems_termios_imfs_write,
     1981  .ioctl_h = rtems_termios_imfs_ioctl,
     1982  .lseek_h = rtems_filesystem_default_lseek,
     1983  .fstat_h = IMFS_stat,
     1984  .ftruncate_h = rtems_filesystem_default_ftruncate,
     1985  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
     1986  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
     1987  .fcntl_h = rtems_filesystem_default_fcntl,
     1988  .kqfilter_h = rtems_filesystem_default_kqfilter,
     1989  .poll_h = rtems_filesystem_default_poll,
     1990  .readv_h = rtems_filesystem_default_readv,
     1991  .writev_h = rtems_filesystem_default_writev
     1992};
     1993
     1994static IMFS_jnode_t *
     1995rtems_termios_imfs_node_initialize (IMFS_jnode_t *node, void *arg)
     1996{
     1997  rtems_termios_device_node *device_node;
     1998  dev_t dev;
     1999
     2000  node = IMFS_node_initialize_generic (node, arg);
     2001  device_node = IMFS_generic_get_context_by_node (node);
     2002  dev = IMFS_generic_get_device_identifier_by_node (node);
     2003  device_node->major = rtems_filesystem_dev_major_t (dev);
     2004  device_node->minor = rtems_filesystem_dev_minor_t (dev);
     2005
     2006  return node;
     2007}
     2008
     2009static void
     2010rtems_termios_imfs_node_destroy (IMFS_jnode_t *node)
     2011{
     2012  rtems_termios_device_node *device_node;
     2013
     2014  device_node = IMFS_generic_get_context_by_node (node);
     2015  free (device_node);
     2016  IMFS_node_destroy_default (node);
     2017}
     2018
     2019static const IMFS_node_control rtems_termios_imfs_node_control =
     2020  IMFS_GENERIC_INITIALIZER(
     2021    &rtems_termios_imfs_handler,
     2022    rtems_termios_imfs_node_initialize,
     2023    rtems_termios_imfs_node_destroy
     2024  );
  • testsuites/libtests/termios01/init.c

    r610b9ef r55e0be36  
    1919#include <fcntl.h>
    2020#include <limits.h>
     21#include <unistd.h>
    2122#include <sys/errno.h>
     23#include <sys/stat.h>
    2224
    2325const char rtems_test_name[] = "TERMIOS 1";
     
    523525} device_context;
    524526
    525 static rtems_status_code test_early_device_install_remove(
     527static rtems_status_code test_early_device_install(
    526528  rtems_device_major_number major,
    527529  rtems_device_minor_number minor,
     
    529531)
    530532{
     533  static const rtems_termios_device_handler handler;
     534  static const char dev[] = "/foobar";
     535
    531536  rtems_resource_snapshot snapshot;
    532537  rtems_status_code sc;
     538  int fd;
     539  int rv;
    533540
    534541  rtems_resource_snapshot_take( &snapshot );
    535542
    536   sc = rtems_termios_device_install( "/", 0, 0, NULL, NULL, NULL );
    537   rtems_test_assert( sc == RTEMS_INCORRECT_STATE );
    538 
    539   sc = rtems_termios_device_remove( "/", 0, 0 );
    540   rtems_test_assert( sc == RTEMS_INCORRECT_STATE );
     543  sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL );
     544  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     545
     546  errno = 0;
     547  fd = open( &dev[0], O_RDWR );
     548  rtems_test_assert( fd == -1 );
     549  rtems_test_assert( errno == ENXIO );
     550
     551  rv = unlink( &dev[0] );
     552  rtems_test_assert( rv == 0 );
    541553
    542554  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
     
    548560{
    549561  static const rtems_termios_device_handler handler;
    550   static const rtems_device_major_number major = 123456789;
    551   static const rtems_device_minor_number minor = 0xdeadbeef;
    552562  static const char dev[] = "/foobar";
    553563
     
    555565  rtems_status_code sc;
    556566  void *greedy;
    557   rtems_libio_t iop;
    558   rtems_libio_open_close_args_t args;
    559 
    560   memset( &iop, 0, sizeof( iop ) );
    561   memset( &args, 0, sizeof( args ) );
    562   args.iop = &iop;
     567  int rv;
    563568
    564569  rtems_resource_snapshot_take( &snapshot );
     
    566571  greedy = rtems_heap_greedy_allocate( NULL, 0 );
    567572
    568   sc = rtems_termios_device_install( "/", major, minor, &handler, NULL, NULL );
     573  sc = rtems_termios_device_install( "/", &handler, NULL, NULL );
    569574  rtems_test_assert( sc == RTEMS_NO_MEMORY );
    570575
     
    573578  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
    574579
    575   sc = rtems_termios_device_install(
    576     NULL,
    577     major,
    578     minor,
    579     &handler,
    580     NULL,
    581     NULL
    582   );
     580  sc = rtems_termios_device_install( "/", &handler, NULL, NULL );
     581  rtems_test_assert( sc == RTEMS_UNSATISFIED );
     582
     583  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
     584
     585  sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL );
    583586  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    584587
    585   sc = rtems_termios_device_install(
    586     NULL,
    587     major,
    588     minor,
    589     &handler,
    590     NULL,
    591     NULL
    592   );
    593   rtems_test_assert( sc == RTEMS_RESOURCE_IN_USE );
    594 
    595   sc = rtems_termios_device_remove( NULL, major, minor );
    596   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    597 
    598   rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
    599 
    600   sc = rtems_termios_device_install( "/", major, minor, &handler, NULL, NULL );
    601   rtems_test_assert( sc == RTEMS_UNSATISFIED );
    602 
    603   rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
    604 
    605   sc = rtems_termios_device_remove( NULL, major, minor );
    606   rtems_test_assert( sc == RTEMS_INVALID_ID );
    607 
    608   sc = rtems_termios_device_install(
    609     &dev[0],
    610     major,
    611     minor,
    612     &handler,
    613     NULL,
    614     NULL
    615   );
    616   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    617 
    618   sc = rtems_termios_device_remove( "/barfoo", major, minor );
    619   rtems_test_assert( sc == RTEMS_UNSATISFIED );
    620 
    621   sc = rtems_termios_device_open( major, minor, &args );
    622   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    623 
    624   sc = rtems_termios_device_remove( &dev[0], major, minor );
    625   rtems_test_assert( sc == RTEMS_RESOURCE_IN_USE );
    626 
    627   sc = rtems_termios_device_close( &args );
    628   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    629 
    630   sc = rtems_termios_device_remove( &dev[0], major, minor );
    631   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     588  rv = unlink( &dev[0] );
     589  rtems_test_assert( rv == 0 );
    632590
    633591  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
     
    657615    .first_open = first_open_error
    658616  };
    659   static const rtems_device_major_number major = 123456789;
    660   static const rtems_device_minor_number minor = 0xdeadbeef;
    661617  static const char dev[] = "/foobar";
    662618
    663619  rtems_resource_snapshot snapshot;
    664620  rtems_status_code sc;
    665   rtems_libio_t iop;
    666   rtems_libio_open_close_args_t args;
     621  int fd;
     622  int rv;
    667623  device_context ctx = {
    668624    .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ),
     
    672628  rtems_resource_snapshot_take( &snapshot );
    673629
    674   sc = rtems_termios_device_install(
    675     &dev[0],
    676     major,
    677     minor,
    678     &handler,
    679     NULL,
    680     &ctx.base
    681   );
     630  sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base );
    682631  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    683632
    684   memset( &iop, 0, sizeof( iop ) );
    685   memset( &args, 0, sizeof( args ) );
    686   args.iop = &iop;
    687 
    688633  rtems_test_assert( !ctx.done );
    689   sc = rtems_termios_device_open( major, minor, &args );
    690   rtems_test_assert( sc == RTEMS_NO_MEMORY );
     634  errno = 0;
     635  fd = open( &dev[0], O_RDWR );
     636  rtems_test_assert( fd == -1 );
     637  rtems_test_assert( errno == ENOMEM );
    691638  rtems_test_assert( ctx.done );
    692639
    693   sc = rtems_termios_device_remove( &dev[0], major, minor );
    694   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     640  rv = unlink( &dev[0] );
     641  rtems_test_assert( rv == 0 );
    695642
    696643  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
     
    716663    .set_attributes = set_attributes_error
    717664  };
    718   static const rtems_device_major_number major = 123456789;
    719   static const rtems_device_minor_number minor = 0xdeadbeef;
    720665  static const char dev[] = "/foobar";
    721666
    722667  rtems_resource_snapshot snapshot;
    723668  rtems_status_code sc;
    724   rtems_libio_t iop;
    725   rtems_libio_open_close_args_t oc_args;
    726   rtems_libio_ioctl_args_t io_args;
    727669  struct termios term;
    728670  device_context ctx = {
     
    730672    .done = false
    731673  };
     674  int fd;
     675  int rv;
    732676
    733677  rtems_resource_snapshot_take( &snapshot );
    734678
    735   sc = rtems_termios_device_install(
    736     &dev[0],
    737     major,
    738     minor,
    739     &handler,
    740     NULL,
    741     &ctx.base
    742   );
     679  sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base );
    743680  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    744681
    745   memset( &iop, 0, sizeof( iop ) );
    746   memset( &oc_args, 0, sizeof( oc_args ) );
    747   oc_args.iop = &iop;
    748 
    749   sc = rtems_termios_device_open( major, minor, &oc_args );
    750   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    751 
    752   memset( &io_args, 0, sizeof( io_args ) );
    753   io_args.iop = &iop;
    754   io_args.command = RTEMS_IO_SET_ATTRIBUTES;
    755   io_args.buffer = &term;
     682  fd = open( &dev[0], O_RDWR );
     683  rtems_test_assert( fd >= 0 );
    756684
    757685  rtems_test_assert( !ctx.done );
    758   sc = rtems_termios_ioctl( &io_args );
    759   rtems_test_assert( sc == RTEMS_IO_ERROR );
     686  errno = 0;
     687  rv = ioctl( fd, RTEMS_IO_SET_ATTRIBUTES, &term );
     688  rtems_test_assert( rv == -1 );
     689  rtems_test_assert( errno == EIO );
    760690  rtems_test_assert( ctx.done );
    761691
    762   sc = rtems_termios_device_close( &oc_args );
    763   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
    764 
    765   sc = rtems_termios_device_remove( &dev[0], major, minor );
    766   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     692  rv = close( fd );
     693  rtems_test_assert( rv == 0 );
     694
     695  rv = unlink( &dev[0] );
     696  rtems_test_assert( rv == 0 );
    767697
    768698  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
     
    983913
    984914#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
    985   { .initialization_entry = test_early_device_install_remove }
     915  { .initialization_entry = test_early_device_install }
    986916
    987917#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
  • testsuites/psxtests/psxfile01/test.c

    r610b9ef r55e0be36  
    625625
    626626  /* try to truncate the console and see what happens */
     627  errno = 0;
    627628  status = truncate( "/dev/console", 40 );
    628   rtems_test_assert( status == 0 );
     629  rtems_test_assert( status == 0 || ( status == -1 && errno == EINVAL ) );
    629630
    630631  puts( "truncate /tmp/j to length of 0" );
Note: See TracChangeset for help on using the changeset viewer.