Changeset 16f3f10 in rtems


Ignore:
Timestamp:
Jul 31, 2018, 1:54:29 PM (16 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
0fe7133
Parents:
24b94c4
git-author:
Sebastian Huber <sebastian.huber@…> (07/31/18 13:54:29)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/07/18 05:17:16)
Message:

nvdisk: Use rtems_blkdev_create()

Update #3358.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/nvdisk.c

    r24b94c4 r16f3f10  
    2727
    2828#include <rtems/blkdev.h>
    29 #include <rtems/diskdevs.h>
    3029#include <rtems/nvdisk.h>
    3130#include <rtems/thread.h>
     
    9493 * for each minor disk in the system.
    9594 */
    96 typedef struct rtems_mvdisk
    97 {
    98   rtems_device_major_number major;        /**< The driver's major number. */
    99   rtems_device_minor_number minor;        /**< The driver's minor number. */
     95typedef struct
     96{
    10097  uint32_t                  flags;        /**< configuration flags. */
    10198  uint32_t                  block_size;   /**< The block size for this disk. */
     
    107104  uint32_t info_level;                    /**< The info trace level. */
    108105} rtems_nvdisk;
    109 
    110 /**
    111  * The array of NV disks we support.
    112  */
    113 static rtems_nvdisk* rtems_nvdisks;
    114 
    115 /**
    116  * The number of NV disks we have.
    117  */
    118 static uint32_t rtems_nvdisk_count;
    119106
    120107/**
     
    689676rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
    690677{
    691   dev_t                     dev = rtems_disk_get_device_identifier (dd);
    692   rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
    693   rtems_blkdev_request*     r = argp;
    694 
    695   if (minor >= rtems_nvdisk_count)
     678  rtems_nvdisk*         nvd = rtems_disk_get_driver_data (dd);
     679  rtems_blkdev_request* r = argp;
     680
     681  if (nvd->device_count == 0)
    696682  {
    697683    errno = ENODEV;
     
    699685  }
    700686
    701   if (rtems_nvdisks[minor].device_count == 0)
    702   {
    703     errno = ENODEV;
    704     return -1;
    705   }
    706 
    707687  errno = 0;
    708688
    709   rtems_mutex_lock (&rtems_nvdisks[minor].lock);
     689  rtems_mutex_lock (&nvd->lock);
    710690
    711691  switch (req)
     
    715695      {
    716696        case RTEMS_BLKDEV_REQ_READ:
    717           errno = rtems_nvdisk_read (&rtems_nvdisks[minor], r);
     697          errno = rtems_nvdisk_read (nvd, r);
    718698          break;
    719699
    720700        case RTEMS_BLKDEV_REQ_WRITE:
    721           errno = rtems_nvdisk_write (&rtems_nvdisks[minor], r);
     701          errno = rtems_nvdisk_write (nvd, r);
    722702          break;
    723703
     
    729709
    730710    case RTEMS_NVDISK_IOCTL_ERASE_DISK:
    731       errno = rtems_nvdisk_erase_disk (&rtems_nvdisks[minor]);
     711      errno = rtems_nvdisk_erase_disk (nvd);
    732712      break;
    733713
    734714    case RTEMS_NVDISK_IOCTL_INFO_LEVEL:
    735       rtems_nvdisks[minor].info_level = (uintptr_t) argp;
     715      nvd->info_level = (uintptr_t) argp;
    736716      break;
    737717
     
    741721  }
    742722
    743   rtems_mutex_unlock (&rtems_nvdisks[minor].lock);
     723  rtems_mutex_unlock (&nvd->lock);
    744724
    745725  return errno == 0 ? 0 : -1;
     
    756736 */
    757737rtems_device_driver
    758 rtems_nvdisk_initialize (rtems_device_major_number major,
    759                         rtems_device_minor_number minor,
     738rtems_nvdisk_initialize (rtems_device_major_number major RTEMS_UNUSED,
     739                        rtems_device_minor_number minor RTEMS_UNUSED,
    760740                        void*                     arg RTEMS_UNUSED)
    761741{
     
    763743  rtems_nvdisk*              nvd;
    764744  rtems_status_code          sc;
    765 
    766   sc = rtems_disk_io_initialize ();
    767   if (sc != RTEMS_SUCCESSFUL)
    768     return sc;
     745  uint32_t                   i;
    769746
    770747  sc = rtems_nvdisk_crc16_gen_factors (0x8408);
     
    772749      return sc;
    773750
    774   rtems_nvdisks = calloc (rtems_nvdisk_configuration_size,
    775                           sizeof (rtems_nvdisk));
    776 
    777   if (!rtems_nvdisks)
     751  nvd = calloc (rtems_nvdisk_configuration_size, sizeof (*nvd));
     752  if (!nvd)
    778753    return RTEMS_NO_MEMORY;
    779754
    780   for (minor = 0; minor < rtems_nvdisk_configuration_size; minor++, c++)
     755  for (i = 0; i < rtems_nvdisk_configuration_size; i++, c++, nvd++)
    781756  {
    782757    char     name[] = RTEMS_NVDISK_DEVICE_BASE_NAME "a";
    783     dev_t    dev = rtems_filesystem_make_dev_t (major, minor);
    784758    uint32_t device;
    785759    uint32_t blocks = 0;
    786760
    787     nvd = &rtems_nvdisks[minor];
    788 
    789     name [sizeof(RTEMS_NVDISK_DEVICE_BASE_NAME)] += minor;
    790 
    791     nvd->major        = major;
    792     nvd->minor        = minor;
     761    name [sizeof(RTEMS_NVDISK_DEVICE_BASE_NAME)] += i;
     762
    793763    nvd->flags        = c->flags;
    794764    nvd->block_size   = c->block_size;
     
    816786    nvd->device_count = c->device_count;
    817787
    818     sc = rtems_disk_create_phys(dev, c->block_size, blocks,
    819                                 rtems_nvdisk_ioctl, NULL, name);
     788    sc = rtems_blkdev_create(name, c->block_size, blocks,
     789                             rtems_nvdisk_ioctl, nvd);
    820790    if (sc != RTEMS_SUCCESSFUL)
    821791    {
     
    827797  }
    828798
    829   rtems_nvdisk_count = rtems_nvdisk_configuration_size;
    830 
    831799  return RTEMS_SUCCESSFUL;
    832800}
  • testsuites/samples/fileio/init.c

    r24b94c4 r16f3f10  
    7575 */
    7676uint32_t rtems_nvdisk_configuration_size = 1;
    77 
    78 /**
    79  * Create the NV Disk Driver entry.
    80  */
    81 rtems_driver_address_table rtems_nvdisk_io_ops = {
    82   initialization_entry: rtems_nvdisk_initialize,
    83   open_entry:           rtems_blkdev_generic_open,
    84   close_entry:          rtems_blkdev_generic_close,
    85   read_entry:           rtems_blkdev_generic_read,
    86   write_entry:          rtems_blkdev_generic_write,
    87   control_entry:        rtems_blkdev_generic_ioctl
    88 };
    89 
    90 #if 0
    91 int
    92 setup_nvdisk (const char* mntpath)
    93 {
    94   rtems_device_major_number major;
    95   rtems_status_code         sc;
    96 
    97   /*
    98    * For our test we do not have any static RAM or EEPROM devices so
    99    * we allocate the memory from the heap.
    100    */
    101   rtems_nv_heap_device_descriptor[0].base =
    102     malloc (rtems_nv_heap_device_descriptor[0].size);
    103 
    104   if (!rtems_nv_heap_device_descriptor[0].base)
    105   {
    106     printf ("error: no memory for NV disk\n");
    107     return 1;
    108   }
    109  
    110   /*
    111    * Register the NV Disk driver.
    112    */
    113   printf ("Register NV Disk Driver: ");
    114   sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
    115                                  &rtems_nvdisk_io_ops,
    116                                  &major);
    117   if (sc != RTEMS_SUCCESSFUL)
    118   {
    119     printf ("error: nvdisk driver not initialised: %s\n",
    120             rtems_status_text (sc));
    121     return 1;
    122   }
    123  
    124   printf ("successful\n");
    125 
    126   return 0;
    127 }
    128 #endif
    12977
    13078/*
     
    474422create_nvdisk (int argc, char *argv[])
    475423{
    476   rtems_device_major_number major;
    477424  rtems_status_code         sc;
    478425  int                       arg;
     
    486433    if (argv[arg][0] == '-')
    487434    {
    488       switch (argv[arg][0])
     435      switch (argv[arg][1])
    489436      {
    490437        case 's':
     
    546493          rtems_nv_heap_device_descriptor[0].size,
    547494          rtems_nvdisk_configuration[0].block_size);
    548  
    549   sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
    550                                  &rtems_nvdisk_io_ops,
    551                                  &major);
     495
     496  sc = rtems_nvdisk_initialize (0, 0, NULL);
    552497  if (sc != RTEMS_SUCCESSFUL)
    553498  {
  • testsuites/samples/fileio/system.h

    r24b94c4 r16f3f10  
    3636#endif
    3737
    38 #define CONFIGURE_MAXIMUM_DRIVERS           4
    3938#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
    4039#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
Note: See TracChangeset for help on using the changeset viewer.