mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-16 04:44:45 +08:00
* libblock/include/rtems/diskdevs.h: Added driver data pointer to IO
control function. The IO control handler takes now the disk device as
first parameter instead of the physical device number.
* cpukit/libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c,
libblock/src/blkdev.c, libblock/src/diskdevs.c, libblock/src/nvdisk.c,
libblock/src/flashdisk.c, libblock/src/ramdisk.c: Update for block
device API change.
This commit is contained in:
@@ -5,6 +5,16 @@
|
||||
score/src/userextthreadbegin.c: Reflect having introduced
|
||||
Internal_errors_t.
|
||||
|
||||
2009-10-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||
|
||||
* libblock/include/rtems/diskdevs.h: Added driver data pointer to IO
|
||||
control function. The IO control handler takes now the disk device as
|
||||
first parameter instead of the physical device number.
|
||||
* cpukit/libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c,
|
||||
libblock/src/blkdev.c, libblock/src/diskdevs.c, libblock/src/nvdisk.c,
|
||||
libblock/src/flashdisk.c, libblock/src/ramdisk.c: Update for block
|
||||
device API change.
|
||||
|
||||
2009-10-11 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* posix/src/alarm.c: If 0 seconds do not insert timer.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define _RTEMS_BLKDEV_H
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/diskdevs.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -39,11 +40,6 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Block device block index type.
|
||||
*/
|
||||
typedef uint32_t rtems_blkdev_bnum;
|
||||
|
||||
/**
|
||||
* Block device request type.
|
||||
*/
|
||||
@@ -250,7 +246,7 @@ rtems_blkdev_generic_ioctl(
|
||||
* Use this in all block devices to handle the common set of ioctl requests.
|
||||
*/
|
||||
int
|
||||
rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp);
|
||||
rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
#include <rtems/libio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rtems/blkdev.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct rtems_disk_device rtems_disk_device;
|
||||
|
||||
/**
|
||||
* @defgroup rtems_disk Block Device Disk Management
|
||||
*
|
||||
* @ingroup rtems_libblock
|
||||
*
|
||||
* This module provides functions to manage disk devices.
|
||||
* @brief This module provides functions to manage disk devices.
|
||||
*
|
||||
* A disk is a set of blocks which are identified by a consecutive set of
|
||||
* non-negative integers starting at zero. There are also logical disks which
|
||||
@@ -43,49 +43,58 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Block device IO control handler type.
|
||||
* @brief Block device block index type.
|
||||
*/
|
||||
typedef int (*rtems_block_device_ioctl)( dev_t dev, uint32_t req, void *argp);
|
||||
typedef uint32_t rtems_blkdev_bnum;
|
||||
|
||||
/**
|
||||
* Description of a disk device (logical and physical disks).
|
||||
* @brief Block device IO control handler type.
|
||||
*/
|
||||
typedef int (*rtems_block_device_ioctl)(
|
||||
rtems_disk_device *dd,
|
||||
uint32_t req,
|
||||
void *argp
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Description of a disk device (logical and physical disks).
|
||||
*
|
||||
* An array of pointer tables to rtems_disk_device structures is maintained.
|
||||
* The first table will be indexed by the major number and the second table
|
||||
* will be indexed by the minor number. This allows quick lookup using a data
|
||||
* structure of moderated size.
|
||||
*/
|
||||
typedef struct rtems_disk_device {
|
||||
struct rtems_disk_device {
|
||||
/**
|
||||
* Device identifier (concatenation of major and minor number).
|
||||
* @brief Device identifier (concatenation of major and minor number).
|
||||
*/
|
||||
dev_t dev;
|
||||
|
||||
/**
|
||||
* Physical device identifier (equals the @c dev entry if it specifies a
|
||||
* @brief Physical device identifier (equals the @c dev entry if it specifies a
|
||||
* physical device).
|
||||
*/
|
||||
struct rtems_disk_device *phys_dev;
|
||||
rtems_disk_device *phys_dev;
|
||||
|
||||
/**
|
||||
* Driver capabilities.
|
||||
* @brief Driver capabilities.
|
||||
*/
|
||||
uint32_t capabilities;
|
||||
|
||||
/**
|
||||
* Disk device name.
|
||||
* @brief Disk device name.
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* Usage counter.
|
||||
* @brief Usage counter.
|
||||
*
|
||||
* Devices cannot be removed if they are in use.
|
||||
*/
|
||||
unsigned uses;
|
||||
|
||||
/**
|
||||
* Start block number.
|
||||
* @brief Start block number.
|
||||
*
|
||||
* Equals zero for physical devices. It is a block offset to the related
|
||||
* physical device for logical device.
|
||||
@@ -93,32 +102,106 @@ typedef struct rtems_disk_device {
|
||||
rtems_blkdev_bnum start;
|
||||
|
||||
/**
|
||||
* Size of the physical or logical disk in blocks.
|
||||
* @brief Size of the physical or logical disk in blocks.
|
||||
*/
|
||||
rtems_blkdev_bnum size;
|
||||
|
||||
/**
|
||||
* Device block size in bytes.
|
||||
* @brief Device block size in bytes.
|
||||
*
|
||||
* This is the minimum transfer unit. It can be any size.
|
||||
*/
|
||||
uint32_t block_size;
|
||||
|
||||
/**
|
||||
* Device media block size in bytes.
|
||||
* @brief Device media block size in bytes.
|
||||
*
|
||||
* This is the media transfer unit the hardware defaults to.
|
||||
*/
|
||||
uint32_t media_block_size;
|
||||
|
||||
/**
|
||||
* IO control handler for this disk.
|
||||
* @brief IO control handler for this disk.
|
||||
*/
|
||||
rtems_block_device_ioctl ioctl;
|
||||
} rtems_disk_device;
|
||||
|
||||
/**
|
||||
* @brief Private data for the disk driver.
|
||||
*/
|
||||
void *driver_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a physical disk with device identifier @a dev.
|
||||
* @name Disk Device Data
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
static inline dev_t rtems_disk_physical_device_number(
|
||||
const rtems_disk_device *dd
|
||||
)
|
||||
{
|
||||
return dd->phys_dev->dev;
|
||||
}
|
||||
|
||||
static inline rtems_device_major_number rtems_disk_physical_major_number(
|
||||
const rtems_disk_device *dd
|
||||
)
|
||||
{
|
||||
return rtems_filesystem_dev_major_t(dd->phys_dev->dev);
|
||||
}
|
||||
|
||||
static inline rtems_device_minor_number rtems_disk_physical_minor_number(
|
||||
const rtems_disk_device *dd
|
||||
)
|
||||
{
|
||||
return rtems_filesystem_dev_minor_t(dd->phys_dev->dev);
|
||||
}
|
||||
|
||||
static inline dev_t rtems_disk_device_number(const rtems_disk_device *dd)
|
||||
{
|
||||
return dd->dev;
|
||||
}
|
||||
|
||||
static inline rtems_device_major_number rtems_disk_major_number(
|
||||
const rtems_disk_device *dd
|
||||
)
|
||||
{
|
||||
return rtems_filesystem_dev_major_t(dd->dev);
|
||||
}
|
||||
|
||||
static inline rtems_device_minor_number rtems_disk_minor_number(
|
||||
const rtems_disk_device *dd
|
||||
)
|
||||
{
|
||||
return rtems_filesystem_dev_minor_t(dd->dev);
|
||||
}
|
||||
|
||||
static inline void *rtems_disk_driver_data(const rtems_disk_device *dd)
|
||||
{
|
||||
return dd->driver_data;
|
||||
}
|
||||
|
||||
static inline uint32_t rtems_disk_block_size(const rtems_disk_device *dd)
|
||||
{
|
||||
return dd->block_size;
|
||||
}
|
||||
|
||||
static inline uint32_t rtems_disk_media_block_size(const rtems_disk_device *dd)
|
||||
{
|
||||
return dd->media_block_size;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Disk Device Maintainance
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Creates a physical disk with device identifier @a dev.
|
||||
*
|
||||
* The block size @a block_size must be a power of two. The disk size @a
|
||||
* disk_size is the number of blocks provided by this disk. The block index
|
||||
@@ -134,13 +217,14 @@ rtems_status_code rtems_disk_create_phys(
|
||||
uint32_t block_size,
|
||||
rtems_blkdev_bnum disk_size,
|
||||
rtems_block_device_ioctl handler,
|
||||
void *driver_data,
|
||||
const char *name
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a logical disk with device identifier @a dev.
|
||||
* @brief Creates a logical disk with device identifier @a dev.
|
||||
*
|
||||
* A logical disk manages a subset of consecutive blocks containd in the
|
||||
* A logical disk manages a subset of consecutive blocks contained in the
|
||||
* physical disk with identifier @a phys. The start block index of the logical
|
||||
* disk device is @a start. The block number of the logcal disk will be @a
|
||||
* size. The blocks must be within the range of blocks managed by the
|
||||
@@ -157,7 +241,7 @@ rtems_status_code rtems_disk_create_log(
|
||||
);
|
||||
|
||||
/**
|
||||
* Deletes a physical or logical disk device with identifier @a dev.
|
||||
* @brief Deletes a physical or logical disk device with identifier @a dev.
|
||||
*
|
||||
* Disk devices may be deleted if there usage counter (and the usage counters
|
||||
* of all contained logical disks devices) equals zero. When a physical disk
|
||||
@@ -167,7 +251,7 @@ rtems_status_code rtems_disk_create_log(
|
||||
rtems_status_code rtems_disk_delete(dev_t dev);
|
||||
|
||||
/**
|
||||
* Returns the disk device descriptor for the device identifier @a dev.
|
||||
* @brief Returns the disk device descriptor for the device identifier @a dev.
|
||||
*
|
||||
* Increments usage counter by one. You should release the disk device
|
||||
* descriptor with rtems_disk_release(). Returns @c NULL if no corresponding
|
||||
@@ -176,14 +260,22 @@ rtems_status_code rtems_disk_delete(dev_t dev);
|
||||
rtems_disk_device *rtems_disk_obtain(dev_t dev);
|
||||
|
||||
/**
|
||||
* Releases the disk device description @a dd.
|
||||
* @brief Releases the disk device description @a dd.
|
||||
*
|
||||
* Decrements usage counter by one.
|
||||
*/
|
||||
rtems_status_code rtems_disk_release(rtems_disk_device *dd);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Disk device iterator.
|
||||
* @name Disk Management
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Disk device iterator.
|
||||
*
|
||||
* Returns the next disk device descriptor with a device identifier larger than
|
||||
* @a dev. If there is no such device, @c NULL will be returned. Use minus
|
||||
@@ -200,7 +292,7 @@ rtems_status_code rtems_disk_release(rtems_disk_device *dd);
|
||||
rtems_disk_device *rtems_disk_next(dev_t dev);
|
||||
|
||||
/**
|
||||
* Initializes the disk device management.
|
||||
* @brief Initializes the disk device management.
|
||||
*
|
||||
* This functions returns successful if the disk device management is already
|
||||
* initialized. There is no protection against concurrent access.
|
||||
@@ -208,12 +300,14 @@ rtems_disk_device *rtems_disk_next(dev_t dev);
|
||||
rtems_status_code rtems_disk_io_initialize(void);
|
||||
|
||||
/**
|
||||
* Releases all resources allocated for disk device management.
|
||||
* @brief Releases all resources allocated for disk device management.
|
||||
*/
|
||||
rtems_status_code rtems_disk_io_done(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1975,7 +1975,7 @@ rtems_bdbuf_read (dev_t device,
|
||||
req->status = RTEMS_RESOURCE_IN_USE;
|
||||
req->error = 0;
|
||||
|
||||
result = dd->ioctl (dd->phys_dev->dev, RTEMS_BLKIO_REQUEST, req);
|
||||
result = dd->ioctl (dd, RTEMS_BLKIO_REQUEST, req);
|
||||
|
||||
/*
|
||||
* Inspection of the DOS FS code shows the result from this function is
|
||||
@@ -2401,9 +2401,7 @@ rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
|
||||
* Perform the transfer. No cache locks, no preemption, only the disk
|
||||
* device is being held.
|
||||
*/
|
||||
result = dd->phys_dev->ioctl (dd->phys_dev->dev,
|
||||
RTEMS_BLKIO_REQUEST, transfer->write_req);
|
||||
|
||||
result = dd->ioctl (dd, RTEMS_BLKIO_REQUEST, transfer->write_req);
|
||||
if (result < 0)
|
||||
{
|
||||
rtems_bdbuf_lock_cache ();
|
||||
|
||||
@@ -237,20 +237,19 @@ rtems_blkdev_generic_ioctl(
|
||||
|
||||
case RTEMS_BLKIO_SYNCDEV:
|
||||
rc = rtems_bdbuf_syncdev(dd->dev);
|
||||
args->ioctl_return = (rc == RTEMS_SUCCESSFUL ? 0 : -1);
|
||||
args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
|
||||
break;
|
||||
|
||||
case RTEMS_BLKIO_REQUEST:
|
||||
{
|
||||
rtems_blkdev_request *req = args->buffer;
|
||||
args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
|
||||
req);
|
||||
args->ioctl_return = (uint32_t) dd->ioctl(dd, args->command, req);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
|
||||
args->buffer);
|
||||
args->ioctl_return = (uint32_t) dd->ioctl(dd, args->command,
|
||||
args->buffer);
|
||||
break;
|
||||
}
|
||||
rtems_disk_release(dd);
|
||||
@@ -259,18 +258,10 @@ rtems_blkdev_generic_ioctl(
|
||||
}
|
||||
|
||||
int
|
||||
rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp)
|
||||
rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
|
||||
{
|
||||
rtems_disk_device *dd;
|
||||
size_t *arg_size = argp;
|
||||
int rc = 0;
|
||||
|
||||
dd = rtems_disk_obtain(dev);
|
||||
if (dd == NULL)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (req)
|
||||
{
|
||||
@@ -295,8 +286,6 @@ rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp)
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
rtems_disk_release(dd);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -223,6 +223,7 @@ rtems_status_code rtems_disk_create_phys(
|
||||
uint32_t block_size,
|
||||
rtems_blkdev_bnum disk_size,
|
||||
rtems_block_device_ioctl handler,
|
||||
void *driver_data,
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
@@ -252,12 +253,11 @@ rtems_status_code rtems_disk_create_phys(
|
||||
dd->size = disk_size;
|
||||
dd->block_size = dd->media_block_size = block_size;
|
||||
dd->ioctl = handler;
|
||||
dd->driver_data = driver_data;
|
||||
|
||||
rc = rtems_io_register_name(name, major, minor);
|
||||
|
||||
if (handler (dd->phys_dev->dev,
|
||||
RTEMS_BLKDEV_CAPABILITIES,
|
||||
&dd->capabilities) < 0)
|
||||
if (handler (dd, RTEMS_BLKDEV_CAPABILITIES, &dd->capabilities) < 0)
|
||||
dd->capabilities = 0;
|
||||
|
||||
diskdevs_protected = false;
|
||||
@@ -316,6 +316,7 @@ rtems_status_code rtems_disk_create_log(
|
||||
dd->size = size;
|
||||
dd->block_size = dd->media_block_size = pdd->block_size;
|
||||
dd->ioctl = pdd->ioctl;
|
||||
dd->driver_data = pdd->driver_data;
|
||||
|
||||
rc = rtems_io_register_name(name, major, minor);
|
||||
|
||||
|
||||
@@ -2335,14 +2335,15 @@ rtems_fdisk_print_status (rtems_flashdisk* fd)
|
||||
/**
|
||||
* Flash disk IOCTL handler.
|
||||
*
|
||||
* @param dev Device number (major, minor number).
|
||||
* @param dd Disk device.
|
||||
* @param req IOCTL request code.
|
||||
* @param argp IOCTL argument.
|
||||
* @retval The IOCTL return value
|
||||
*/
|
||||
static int
|
||||
rtems_fdisk_ioctl (dev_t dev, uint32_t req, void* argp)
|
||||
rtems_fdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
|
||||
{
|
||||
dev_t dev = rtems_disk_physical_device_number (dd);
|
||||
rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
|
||||
rtems_blkdev_request* r = argp;
|
||||
rtems_status_code sc;
|
||||
@@ -2408,7 +2409,7 @@ rtems_fdisk_ioctl (dev_t dev, uint32_t req, void* argp)
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_blkdev_ioctl (dev, req, argp);
|
||||
rtems_blkdev_ioctl (dd, req, argp);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2479,7 +2480,7 @@ rtems_fdisk_initialize (rtems_device_major_number major,
|
||||
|
||||
sc = rtems_disk_create_phys(dev, c->block_size,
|
||||
blocks - fd->unavail_blocks,
|
||||
rtems_fdisk_ioctl, name);
|
||||
rtems_fdisk_ioctl, NULL, name);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
{
|
||||
rtems_fdisk_error ("disk create phy failed");
|
||||
|
||||
@@ -674,14 +674,15 @@ rtems_nvdisk_erase_disk (rtems_nvdisk* nvd)
|
||||
/**
|
||||
* NV disk IOCTL handler.
|
||||
*
|
||||
* @param dev Device number (major, minor number).
|
||||
* @param dd Disk device.
|
||||
* @param req IOCTL request code.
|
||||
* @param argp IOCTL argument.
|
||||
* @retval The IOCTL return value
|
||||
*/
|
||||
static int
|
||||
rtems_nvdisk_ioctl (dev_t dev, uint32_t req, void* argp)
|
||||
rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
|
||||
{
|
||||
dev_t dev = rtems_disk_physical_device_number (dd);
|
||||
rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
|
||||
rtems_blkdev_request* r = argp;
|
||||
rtems_status_code sc;
|
||||
@@ -734,7 +735,7 @@ rtems_nvdisk_ioctl (dev_t dev, uint32_t req, void* argp)
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_blkdev_ioctl (dev, req, argp);
|
||||
rtems_blkdev_ioctl (dd, req, argp);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -817,7 +818,7 @@ rtems_nvdisk_initialize (rtems_device_major_number major,
|
||||
nvd->device_count = c->device_count;
|
||||
|
||||
sc = rtems_disk_create_phys(dev, c->block_size, blocks,
|
||||
rtems_nvdisk_ioctl, name);
|
||||
rtems_nvdisk_ioctl, NULL, name);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
{
|
||||
rtems_nvdisk_error ("disk create phy failed");
|
||||
|
||||
@@ -163,24 +163,14 @@ ramdisk_write(struct ramdisk *rd, rtems_blkdev_request *req)
|
||||
* IOCTL return value
|
||||
*/
|
||||
static int
|
||||
ramdisk_ioctl(dev_t dev, uint32_t req, void *argp)
|
||||
ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
|
||||
{
|
||||
switch (req)
|
||||
{
|
||||
case RTEMS_BLKIO_REQUEST:
|
||||
{
|
||||
rtems_device_minor_number minor;
|
||||
rtems_blkdev_request *r = argp;
|
||||
struct ramdisk *rd;
|
||||
|
||||
minor = rtems_filesystem_dev_minor_t(dev);
|
||||
if ((minor >= nramdisks) || !ramdisk[minor].initialized)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rd = ramdisk + minor;
|
||||
struct ramdisk *rd = rtems_disk_driver_data(dd);
|
||||
|
||||
switch (r->req)
|
||||
{
|
||||
@@ -198,7 +188,7 @@ ramdisk_ioctl(dev_t dev, uint32_t req, void *argp)
|
||||
}
|
||||
|
||||
default:
|
||||
return rtems_blkdev_ioctl (dev, req, argp);
|
||||
return rtems_blkdev_ioctl (dd, req, argp);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -266,7 +256,7 @@ ramdisk_initialize(
|
||||
r->area = c->location;
|
||||
}
|
||||
rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
|
||||
ramdisk_ioctl, name);
|
||||
ramdisk_ioctl, r, name);
|
||||
if (rc != RTEMS_SUCCESSFUL)
|
||||
{
|
||||
if (r->malloced)
|
||||
|
||||
Reference in New Issue
Block a user