Renamed the "blkman" module to "block_io".
Also renamed some defines and structures, although the structure and some other names are still odd. This module should probably be moved into the kernel anyway, as it provides basic and crucial services. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12646 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
#ifndef __BLOCK_IO_H__
|
||||||
|
#define __BLOCK_IO_H__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open block device manager
|
Part of Open block device manager
|
||||||
@@ -13,19 +15,17 @@
|
|||||||
by using a buffer (performance will suffer, though).
|
by using a buffer (performance will suffer, though).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BLKMAN_H__
|
|
||||||
#define __BLKMAN_H__
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#include <device_manager.h>
|
#include <device_manager.h>
|
||||||
|
|
||||||
// cookies issued by blkman
|
// cookies issued by block_io
|
||||||
typedef struct blkman_device_info *blkman_device;
|
typedef struct block_io_device_info *block_io_device;
|
||||||
typedef struct blkman_handle_info *blkman_handle;
|
typedef struct block_io_handle_info *block_io_handle;
|
||||||
|
|
||||||
// cookies issued by device driver
|
// cookies issued by device driver
|
||||||
typedef struct blkdev_device_cookie *blkdev_device_cookie;
|
typedef struct block_device_device_cookie *block_device_device_cookie;
|
||||||
typedef struct blkdev_handle_cookie *blkdev_handle_cookie;
|
typedef struct block_device_handle_cookie *block_device_handle_cookie;
|
||||||
|
|
||||||
|
|
||||||
// two reason why to use array of size 1:
|
// two reason why to use array of size 1:
|
||||||
@@ -46,57 +46,55 @@ typedef struct phys_vecs {
|
|||||||
|
|
||||||
// attributes:
|
// attributes:
|
||||||
|
|
||||||
// type code for block devices
|
|
||||||
#define BLKDEV_TYPE_NAME "blkdev"
|
|
||||||
// if true, this device may be a BIOS drive (uint8, optional, default: false)
|
// if true, this device may be a BIOS drive (uint8, optional, default: false)
|
||||||
#define BLKDEV_IS_BIOS_DRIVE "blkdev/is_bios_drive"
|
#define B_BLOCK_DEVICE_IS_BIOS_DRIVE "block_device/is_bios_drive"
|
||||||
// address bits that must be 0 - must be 2^i-1 for some i (uint32, optional, default: 0)
|
// address bits that must be 0 - must be 2^i-1 for some i (uint32, optional, default: 0)
|
||||||
#define BLKDEV_DMA_ALIGNMENT "blkdev/dma_alignment"
|
#define B_BLOCK_DEVICE_DMA_ALIGNMENT "block_device/dma_alignment"
|
||||||
// maximum number of blocks per transfer (uint32, optional, default: unlimited)
|
// maximum number of blocks per transfer (uint32, optional, default: unlimited)
|
||||||
#define BLKDEV_MAX_BLOCKS_ITEM "blkdev/max_blocks"
|
#define B_BLOCK_DEVICE_MAX_BLOCKS_ITEM "block_device/max_blocks"
|
||||||
// mask of bits that can change in one sg block (uint32, optional, default: ~0)
|
// mask of bits that can change in one sg block (uint32, optional, default: ~0)
|
||||||
#define BLKDEV_DMA_BOUNDARY "blkdev/dma_boundary"
|
#define B_BLOCK_DEVICE_DMA_BOUNDARY "block_device/dma_boundary"
|
||||||
// maximum size of one block in scatter/gather list (uint32, optional, default: ~0)
|
// maximum size of one block in scatter/gather list (uint32, optional, default: ~0)
|
||||||
#define BLKDEV_MAX_SG_BLOCK_SIZE "blkdev/max_sg_block_size"
|
#define B_BLOCK_DEVICE_MAX_SG_BLOCK_SIZE "block_device/max_sg_block_size"
|
||||||
// maximum number of scatter/gather blocks (uint32, optional, default: unlimited)
|
// maximum number of scatter/gather blocks (uint32, optional, default: unlimited)
|
||||||
#define BLKDEV_MAX_SG_BLOCKS "blkdev/max_sg_blocks"
|
#define B_BLOCK_DEVICE_MAX_SG_BLOCKS "block_device/max_sg_blocks"
|
||||||
|
|
||||||
|
|
||||||
// interface to be provided by device driver
|
// interface to be provided by device driver
|
||||||
typedef struct blkdev_interface {
|
typedef struct block_device_interface {
|
||||||
driver_module_info dinfo;
|
driver_module_info info;
|
||||||
|
|
||||||
// iovecs are physical address here
|
// iovecs are physical address here
|
||||||
// pos and num_blocks are in blocks; bytes_transferred in bytes
|
// pos and num_blocks are in blocks; bytes_transferred in bytes
|
||||||
// vecs are guaranteed to describe enough data for given block count
|
// vecs are guaranteed to describe enough data for given block count
|
||||||
status_t (*open)(blkdev_device_cookie device, blkdev_handle_cookie *handle);
|
status_t (*open)(block_device_device_cookie device, block_device_handle_cookie *handle);
|
||||||
status_t (*close)(blkdev_handle_cookie handle);
|
status_t (*close)(block_device_handle_cookie handle);
|
||||||
status_t (*free)(blkdev_handle_cookie handle);
|
status_t (*free)(block_device_handle_cookie handle);
|
||||||
|
|
||||||
status_t (*read)(blkdev_handle_cookie handle, const phys_vecs *vecs, off_t pos,
|
status_t (*read)(block_device_handle_cookie handle, const phys_vecs *vecs, off_t pos,
|
||||||
size_t num_blocks, uint32 block_size, size_t *bytes_transferred);
|
size_t num_blocks, uint32 block_size, size_t *bytes_transferred);
|
||||||
status_t (*write)(blkdev_handle_cookie handle, const phys_vecs *vecs, off_t pos,
|
status_t (*write)(block_device_handle_cookie handle, const phys_vecs *vecs, off_t pos,
|
||||||
size_t num_blocks, uint32 block_size, size_t *bytes_transferred);
|
size_t num_blocks, uint32 block_size, size_t *bytes_transferred);
|
||||||
|
|
||||||
status_t (*ioctl)(blkdev_handle_cookie handle, int op, void *buf, size_t len);
|
status_t (*ioctl)(block_device_handle_cookie handle, int op, void *buf, size_t len);
|
||||||
} blkdev_interface;
|
} block_device_interface;
|
||||||
|
|
||||||
#define BLKMAN_MODULE_NAME "generic/blkman/v1"
|
#define B_BLOCK_IO_MODULE_NAME "generic/block_io/v1"
|
||||||
|
|
||||||
|
|
||||||
// Interface for Drivers
|
// Interface for Drivers
|
||||||
|
|
||||||
// blkman interface used for callbacks done by driver
|
// blkman interface used for callbacks done by driver
|
||||||
typedef struct blkman_for_driver_interface {
|
typedef struct block_io_for_driver_interface {
|
||||||
module_info minfo;
|
module_info info;
|
||||||
|
|
||||||
// block_size - block size in bytes
|
// block_size - block size in bytes
|
||||||
// ld_block_size - log2( block_size) (set to zero if block_size is not power of two)
|
// ld_block_size - log2( block_size) (set to zero if block_size is not power of two)
|
||||||
// capacity - capacity in blocks
|
// capacity - capacity in blocks
|
||||||
void (*set_media_params)(blkman_device device, uint32 block_size, uint32 ld_block_size,
|
void (*set_media_params)(block_io_device device, uint32 block_size, uint32 ld_block_size,
|
||||||
uint64 capacity);
|
uint64 capacity);
|
||||||
} blkman_for_driver_interface;
|
} block_io_for_driver_interface;
|
||||||
|
|
||||||
#define BLKMAN_FOR_DRIVER_MODULE_NAME "generic/blkman/driver/v1"
|
#define B_BLOCK_IO_FOR_DRIVER_MODULE_NAME "generic/block_io/driver/v1"
|
||||||
|
|
||||||
#endif
|
#endif /* __BLOCK_IO_H__ */
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Peripheral Driver
|
Part of Open SCSI Peripheral Driver
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
#define __SCSI_PERIPH_H__
|
#define __SCSI_PERIPH_H__
|
||||||
|
|
||||||
#include <bus/SCSI.h>
|
#include <bus/SCSI.h>
|
||||||
#include <blkman.h>
|
#include <block_io.h>
|
||||||
#include <bus/scsi/scsi_cmds.h>
|
#include <bus/scsi/scsi_cmds.h>
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ cd_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
|||||||
|
|
||||||
memset(device, 0, sizeof(*device));
|
memset(device, 0, sizeof(*device));
|
||||||
|
|
||||||
device->blkman_device = user_cookie;
|
device->block_io_device = user_cookie;
|
||||||
device->node = node;
|
device->node = node;
|
||||||
|
|
||||||
res = pnp->get_attr_uint8(node, "removable",
|
res = pnp->get_attr_uint8(node, "removable",
|
||||||
@@ -119,7 +119,7 @@ cd_device_added(device_node_handle node)
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
// get block limit of underlying hardware to lower it (if necessary)
|
// get block limit of underlying hardware to lower it (if necessary)
|
||||||
if( pnp->get_attr_uint32( node, BLKDEV_MAX_BLOCKS_ITEM,
|
if( pnp->get_attr_uint32( node, B_BLOCK_DEVICE_MAX_BLOCKS_ITEM,
|
||||||
&max_blocks, true ) != B_OK )
|
&max_blocks, true ) != B_OK )
|
||||||
max_blocks = INT_MAX;
|
max_blocks = INT_MAX;
|
||||||
|
|
||||||
@@ -140,14 +140,14 @@ cd_device_added(device_node_handle node)
|
|||||||
{
|
{
|
||||||
device_attr attrs[] = {
|
device_attr attrs[] = {
|
||||||
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: SCSI_CD_MODULE_NAME }},
|
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: SCSI_CD_MODULE_NAME }},
|
||||||
// we always want blkman on top of us
|
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: B_BLOCK_IO_MODULE_NAME }},
|
||||||
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: BLKMAN_MODULE_NAME }},
|
|
||||||
// tell blkman whether the device is removable
|
// tell block_io whether the device is removable
|
||||||
{ "removable", B_UINT8_TYPE, { ui8: device_inquiry->RMB }},
|
{ "removable", B_UINT8_TYPE, { ui8: device_inquiry->RMB }},
|
||||||
// tell which name we want to have in devfs
|
// tell which name we want to have in devfs
|
||||||
{ PNP_DEVFS_FILENAME, B_STRING_TYPE, { string: name }},
|
{ PNP_DEVFS_FILENAME, B_STRING_TYPE, { string: name }},
|
||||||
// impose own max block restriction
|
// impose own max block restriction
|
||||||
{ BLKDEV_MAX_BLOCKS_ITEM, B_UINT32_TYPE, { ui32: max_blocks }},
|
{ B_BLOCK_DEVICE_MAX_BLOCKS_ITEM, B_UINT32_TYPE, { ui32: max_blocks }},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
#include <scsi.h>
|
#include <scsi.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
extern blkdev_interface cd_interface;
|
extern block_device_interface cd_interface;
|
||||||
|
|
||||||
scsi_periph_interface *scsi_periph;
|
scsi_periph_interface *scsi_periph;
|
||||||
device_manager_info *pnp;
|
device_manager_info *pnp;
|
||||||
blkman_for_driver_interface *blkman;
|
block_io_for_driver_interface *sBlockIO;
|
||||||
|
|
||||||
|
|
||||||
#define SCSI_CD_STD_TIMEOUT 10
|
#define SCSI_CD_STD_TIMEOUT 10
|
||||||
@@ -663,7 +663,7 @@ cd_set_capacity(cd_device_info *device, uint64 capacity,
|
|||||||
device->capacity = capacity;
|
device->capacity = capacity;
|
||||||
device->block_size = block_size;
|
device->block_size = block_size;
|
||||||
|
|
||||||
blkman->set_media_params(device->blkman_device, block_size,
|
sBlockIO->set_media_params(device->block_io_device, block_size,
|
||||||
ld_block_size, capacity);
|
ld_block_size, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,12 +699,12 @@ std_ops(int32 op, ...)
|
|||||||
|
|
||||||
module_dependency module_dependencies[] = {
|
module_dependency module_dependencies[] = {
|
||||||
{ SCSI_PERIPH_MODULE_NAME, (module_info **)&scsi_periph },
|
{ SCSI_PERIPH_MODULE_NAME, (module_info **)&scsi_periph },
|
||||||
{ BLKMAN_FOR_DRIVER_MODULE_NAME, (module_info **)&blkman },
|
{ B_BLOCK_IO_FOR_DRIVER_MODULE_NAME, (module_info **)&sBlockIO },
|
||||||
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
|
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
blkdev_interface scsi_cd_module = {
|
block_device_interface scsi_cd_module = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SCSI_CD_MODULE_NAME,
|
SCSI_CD_MODULE_NAME,
|
||||||
@@ -719,16 +719,16 @@ blkdev_interface scsi_cd_module = {
|
|||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
(status_t (*)( blkdev_device_cookie, blkdev_handle_cookie * )) &cd_open,
|
(status_t (*)(block_device_device_cookie, block_device_handle_cookie *))&cd_open,
|
||||||
(status_t (*)( blkdev_handle_cookie )) &cd_close,
|
(status_t (*)(block_device_handle_cookie)) &cd_close,
|
||||||
(status_t (*)( blkdev_handle_cookie )) &cd_free,
|
(status_t (*)(block_device_handle_cookie)) &cd_free,
|
||||||
|
|
||||||
(status_t (*)( blkdev_handle_cookie, const phys_vecs *,
|
(status_t (*)(block_device_handle_cookie, const phys_vecs *,
|
||||||
off_t, size_t, uint32, size_t * )) &cd_read,
|
off_t, size_t, uint32, size_t *)) &cd_read,
|
||||||
(status_t (*)( blkdev_handle_cookie, const phys_vecs *,
|
(status_t (*)(block_device_handle_cookie, const phys_vecs *,
|
||||||
off_t, size_t, uint32, size_t * )) &cd_write,
|
off_t, size_t, uint32, size_t *)) &cd_write,
|
||||||
|
|
||||||
(status_t (*)( blkdev_handle_cookie, int, void *, size_t )) &cd_ioctl,
|
(status_t (*)(block_device_handle_cookie, int, void *, size_t))&cd_ioctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_info *modules[] = {
|
module_info *modules[] = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, Thomas Kurschel. All rights reserved.
|
* Copyright 2003, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI CD Driver
|
Part of Open SCSI CD Driver
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <device_manager.h>
|
#include <device_manager.h>
|
||||||
#include "scsi_cd.h"
|
#include "scsi_cd.h"
|
||||||
#include <bus/scsi/scsi_periph.h>
|
#include <bus/scsi/scsi_periph.h>
|
||||||
#include <blkman.h>
|
#include <block_io.h>
|
||||||
|
|
||||||
#define debug_level_flow 0
|
#define debug_level_flow 0
|
||||||
#define debug_level_error 3
|
#define debug_level_error 3
|
||||||
@@ -26,7 +26,7 @@ typedef struct cd_device_info {
|
|||||||
scsi_periph_device scsi_periph_device;
|
scsi_periph_device scsi_periph_device;
|
||||||
scsi_device scsi_device;
|
scsi_device scsi_device;
|
||||||
scsi_device_interface *scsi;
|
scsi_device_interface *scsi;
|
||||||
blkman_device blkman_device;
|
block_io_device block_io_device;
|
||||||
|
|
||||||
uint64 capacity;
|
uint64 capacity;
|
||||||
uint32 block_size;
|
uint32 block_size;
|
||||||
@@ -43,7 +43,6 @@ typedef struct cd_handle_info {
|
|||||||
extern scsi_periph_interface *scsi_periph;
|
extern scsi_periph_interface *scsi_periph;
|
||||||
extern device_manager_info *pnp;
|
extern device_manager_info *pnp;
|
||||||
extern scsi_periph_callbacks callbacks;
|
extern scsi_periph_callbacks callbacks;
|
||||||
extern blkman_for_driver_interface *blkman;
|
|
||||||
|
|
||||||
|
|
||||||
// device_mgr.c
|
// device_mgr.c
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ das_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
|||||||
|
|
||||||
memset(device, 0, sizeof(*device));
|
memset(device, 0, sizeof(*device));
|
||||||
|
|
||||||
device->blkman_device = user_cookie;
|
device->block_io_device = user_cookie;
|
||||||
device->node = node;
|
device->node = node;
|
||||||
|
|
||||||
res = pnp->get_attr_uint8(node, "removable",
|
res = pnp->get_attr_uint8(node, "removable",
|
||||||
@@ -92,7 +92,7 @@ das_uninit_device(das_device_info *device)
|
|||||||
|
|
||||||
/** called whenever a new device was added to system;
|
/** called whenever a new device was added to system;
|
||||||
* if we really support it, we create a new node that gets
|
* if we really support it, we create a new node that gets
|
||||||
* server by blkdev
|
* server by the block_io module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
@@ -116,12 +116,12 @@ das_device_added(device_node_handle node)
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
// get block limit of underlying hardware to lower it (if necessary)
|
// get block limit of underlying hardware to lower it (if necessary)
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_MAX_BLOCKS_ITEM, &max_blocks, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_MAX_BLOCKS_ITEM, &max_blocks, true) != B_OK)
|
||||||
max_blocks = INT_MAX;
|
max_blocks = INT_MAX;
|
||||||
|
|
||||||
// using 10 byte commands, at most 0xffff blocks can be transmitted at once
|
// using 10 byte commands, at most 0xffff blocks can be transmitted at once
|
||||||
// (sadly, we cannot update this value later on if only 6 byte commands
|
// (sadly, we cannot update this value later on if only 6 byte commands
|
||||||
// are supported, but the blkdev can live with that)
|
// are supported, but the block_io module can live with that)
|
||||||
max_blocks = min(max_blocks, 0xffff);
|
max_blocks = min(max_blocks, 0xffff);
|
||||||
|
|
||||||
name = scsi_periph->compose_device_name(node, "disk/scsi");
|
name = scsi_periph->compose_device_name(node, "disk/scsi");
|
||||||
@@ -136,16 +136,15 @@ das_device_added(device_node_handle node)
|
|||||||
{
|
{
|
||||||
device_attr attrs[] = {
|
device_attr attrs[] = {
|
||||||
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: SCSI_DSK_MODULE_NAME }},
|
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: SCSI_DSK_MODULE_NAME }},
|
||||||
// we always want blkman on top of us
|
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: B_BLOCK_IO_MODULE_NAME }},
|
||||||
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: BLKMAN_MODULE_NAME }},
|
// tell block_io whether the device is removable
|
||||||
// tell blkman whether the device is removable
|
|
||||||
{ "removable", B_UINT8_TYPE, { ui8: device_inquiry->RMB }},
|
{ "removable", B_UINT8_TYPE, { ui8: device_inquiry->RMB }},
|
||||||
// tell which name we want to have in devfs
|
// tell which name we want to have in devfs
|
||||||
{ PNP_DEVFS_FILENAME, B_STRING_TYPE, { string: name }},
|
{ PNP_DEVFS_FILENAME, B_STRING_TYPE, { string: name }},
|
||||||
// impose own max block restriction
|
// impose own max block restriction
|
||||||
{ BLKDEV_MAX_BLOCKS_ITEM, B_UINT32_TYPE, { ui32: max_blocks }},
|
{ B_BLOCK_DEVICE_MAX_BLOCKS_ITEM, B_UINT32_TYPE, { ui32: max_blocks }},
|
||||||
// in general, any disk can be a BIOS drive (even ZIP-disks)
|
// in general, any disk can be a BIOS drive (even ZIP-disks)
|
||||||
{ BLKDEV_IS_BIOS_DRIVE, B_UINT8_TYPE, { ui8: 1 }},
|
{ B_BLOCK_DEVICE_IS_BIOS_DRIVE, B_UINT8_TYPE, { ui8: 1 }},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
extern blkdev_interface das_interface;
|
extern block_device_interface das_interface;
|
||||||
|
|
||||||
scsi_periph_interface *scsi_periph;
|
scsi_periph_interface *scsi_periph;
|
||||||
device_manager_info *pnp;
|
device_manager_info *pnp;
|
||||||
blkman_for_driver_interface *blkman;
|
block_io_for_driver_interface *gBlockIO;
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
@@ -161,7 +161,7 @@ das_set_capacity(das_device_info *device, uint64 capacity,
|
|||||||
device->capacity = capacity;
|
device->capacity = capacity;
|
||||||
device->block_size = block_size;
|
device->block_size = block_size;
|
||||||
|
|
||||||
blkman->set_media_params(device->blkman_device, block_size,
|
gBlockIO->set_media_params(device->block_io_device, block_size,
|
||||||
ld_block_size, capacity);
|
ld_block_size, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,12 +271,12 @@ std_ops(int32 op, ...)
|
|||||||
|
|
||||||
module_dependency module_dependencies[] = {
|
module_dependency module_dependencies[] = {
|
||||||
{ SCSI_PERIPH_MODULE_NAME, (module_info **)&scsi_periph },
|
{ SCSI_PERIPH_MODULE_NAME, (module_info **)&scsi_periph },
|
||||||
{ BLKMAN_FOR_DRIVER_MODULE_NAME, (module_info **)&blkman },
|
{ B_BLOCK_IO_FOR_DRIVER_MODULE_NAME, (module_info **)&gBlockIO },
|
||||||
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
|
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
blkdev_interface scsi_dsk_module = {
|
block_device_interface scsi_dsk_module = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SCSI_DSK_MODULE_NAME,
|
SCSI_DSK_MODULE_NAME,
|
||||||
@@ -293,16 +293,16 @@ blkdev_interface scsi_dsk_module = {
|
|||||||
das_get_paths,
|
das_get_paths,
|
||||||
},
|
},
|
||||||
|
|
||||||
(status_t (*)(blkdev_device_cookie, blkdev_handle_cookie *)) &das_open,
|
(status_t (*)(block_device_device_cookie, block_device_handle_cookie *))&das_open,
|
||||||
(status_t (*)(blkdev_handle_cookie)) &das_close,
|
(status_t (*)(block_device_handle_cookie)) &das_close,
|
||||||
(status_t (*)(blkdev_handle_cookie)) &das_free,
|
(status_t (*)(block_device_handle_cookie)) &das_free,
|
||||||
|
|
||||||
(status_t (*)(blkdev_handle_cookie, const phys_vecs *,
|
(status_t (*)(block_device_handle_cookie, const phys_vecs *,
|
||||||
off_t, size_t, uint32, size_t *)) &das_read,
|
off_t, size_t, uint32, size_t *)) &das_read,
|
||||||
(status_t (*)(blkdev_handle_cookie, const phys_vecs *,
|
(status_t (*)(block_device_handle_cookie, const phys_vecs *,
|
||||||
off_t, size_t, uint32, size_t *)) &das_write,
|
off_t, size_t, uint32, size_t *)) &das_write,
|
||||||
|
|
||||||
(status_t (*)(blkdev_handle_cookie, int, void *, size_t)) &das_ioctl,
|
(status_t (*)(block_device_handle_cookie, int, void *, size_t))&das_ioctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !_BUILDING_kernel && !BOOT
|
#if !_BUILDING_kernel && !BOOT
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <device_manager.h>
|
#include <device_manager.h>
|
||||||
#include "scsi_dsk.h"
|
#include "scsi_dsk.h"
|
||||||
#include <bus/scsi/scsi_periph.h>
|
#include <bus/scsi/scsi_periph.h>
|
||||||
#include <blkman.h>
|
#include <block_io.h>
|
||||||
|
|
||||||
#define debug_level_flow 0
|
#define debug_level_flow 0
|
||||||
#define debug_level_info 1
|
#define debug_level_info 1
|
||||||
@@ -28,7 +28,7 @@ typedef struct das_device_info {
|
|||||||
scsi_periph_device scsi_periph_device;
|
scsi_periph_device scsi_periph_device;
|
||||||
scsi_device scsi_device;
|
scsi_device scsi_device;
|
||||||
scsi_device_interface *scsi;
|
scsi_device_interface *scsi;
|
||||||
blkman_device blkman_device;
|
block_io_device block_io_device;
|
||||||
|
|
||||||
uint64 capacity;
|
uint64 capacity;
|
||||||
uint32 block_size;
|
uint32 block_size;
|
||||||
@@ -44,7 +44,7 @@ typedef struct das_handle_info {
|
|||||||
extern scsi_periph_interface *scsi_periph;
|
extern scsi_periph_interface *scsi_periph;
|
||||||
extern device_manager_info *pnp;
|
extern device_manager_info *pnp;
|
||||||
extern scsi_periph_callbacks callbacks;
|
extern scsi_periph_callbacks callbacks;
|
||||||
extern blkman_for_driver_interface *blkman;
|
extern block_io_for_driver_interface *gBlockIO;
|
||||||
|
|
||||||
|
|
||||||
// device_mgr.c
|
// device_mgr.c
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
SubDir OBOS_TOP src add-ons kernel generic blkman ;
|
SubDir OBOS_TOP src add-ons kernel generic block_io ;
|
||||||
|
|
||||||
UsePrivateHeaders kernel ;
|
UsePrivateHeaders kernel ;
|
||||||
UsePrivateHeaders [ FDirName kernel arch $(OBOS_ARCH) ] ;
|
UsePrivateHeaders [ FDirName kernel arch $(OBOS_ARCH) ] ;
|
||||||
@@ -9,8 +9,8 @@ if $(DEBUG) = 0 {
|
|||||||
SubDirCcFlags [ FDefines DEBUG_MAX_LEVEL_FLOW=0 DEBUG_MAX_LEVEL_INFO=0 ] ;
|
SubDirCcFlags [ FDefines DEBUG_MAX_LEVEL_FLOW=0 DEBUG_MAX_LEVEL_INFO=0 ] ;
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelAddon blkman : kernel generic :
|
KernelAddon block_io : kernel generic :
|
||||||
blkman.c
|
block_io.c
|
||||||
io.c
|
io.c
|
||||||
virtual_memory.c
|
virtual_memory.c
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Functions that are missing in kernel.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _KERNEL_EXPORT_EXT_H
|
|
||||||
#define _KERNEL_EXPORT_EXT_H
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <iovec.h>
|
|
||||||
|
|
||||||
|
|
||||||
// get memory map of iovec
|
|
||||||
status_t get_iovec_memory_map(
|
|
||||||
iovec *vec, // iovec to analyze
|
|
||||||
size_t vec_count, // number of entries in vec
|
|
||||||
size_t vec_offset, // number of bytes to skip at beginning of vec
|
|
||||||
size_t len, // number of bytes to analyze
|
|
||||||
physical_entry *map, // resulting memory map
|
|
||||||
size_t max_entries, // max number of entries in map
|
|
||||||
size_t *num_entries, // actual number of map entries used
|
|
||||||
size_t *mapped_len // actual number of bytes described by map
|
|
||||||
);
|
|
||||||
|
|
||||||
// map main memory into virtual address space
|
|
||||||
status_t map_mainmemory(
|
|
||||||
addr_t physical_addr, // physical address to map
|
|
||||||
void **virtual_addr // receives corresponding virtual address
|
|
||||||
);
|
|
||||||
|
|
||||||
// unmap main memory from virtual address space
|
|
||||||
status_t unmap_mainmemory(
|
|
||||||
void *virtual_addr // virtual address to release
|
|
||||||
);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+90
-90
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "blkman_int.h"
|
#include "block_io_private.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -24,28 +24,28 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
uint blkman_buffer_size;
|
uint block_io_buffer_size;
|
||||||
sem_id blkman_buffer_lock;
|
sem_id block_io_buffer_lock;
|
||||||
struct iovec blkman_buffer_vec[1];
|
struct iovec block_io_buffer_vec[1];
|
||||||
void *blkman_buffer_phys;
|
void *block_io_buffer_phys;
|
||||||
char *blkman_buffer;
|
char *block_io_buffer;
|
||||||
phys_vecs blkman_buffer_phys_vec;
|
phys_vecs block_io_buffer_phys_vec;
|
||||||
area_id blkman_buffer_area;
|
static area_id block_io_buffer_area;
|
||||||
|
|
||||||
locked_pool_interface *locked_pool;
|
locked_pool_interface *locked_pool;
|
||||||
device_manager_info *pnp;
|
device_manager_info *pnp;
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_open(blkman_device_info *device, uint32 flags,
|
block_io_open(block_io_device_info *device, uint32 flags,
|
||||||
blkman_handle_info **res_handle)
|
block_io_handle_info **res_handle)
|
||||||
{
|
{
|
||||||
blkman_handle_info *handle;
|
block_io_handle_info *handle;
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
TRACE(("blkman_open()\n"));
|
TRACE(("block_io_open()\n"));
|
||||||
|
|
||||||
handle = (blkman_handle_info *)malloc(sizeof(*handle));
|
handle = (block_io_handle_info *)malloc(sizeof(*handle));
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -69,11 +69,11 @@ err:
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_close(blkman_handle_info *handle)
|
block_io_close(block_io_handle_info *handle)
|
||||||
{
|
{
|
||||||
blkman_device_info *device = handle->device;
|
block_io_device_info *device = handle->device;
|
||||||
|
|
||||||
TRACE(("blkman_close()\n"));
|
TRACE(("block_io_close()\n"));
|
||||||
|
|
||||||
device->interface->close(handle->cookie);
|
device->interface->close(handle->cookie);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -81,11 +81,11 @@ blkman_close(blkman_handle_info *handle)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_freecookie(blkman_handle_info *handle)
|
block_io_freecookie(block_io_handle_info *handle)
|
||||||
{
|
{
|
||||||
blkman_device_info *device = handle->device;
|
block_io_device_info *device = handle->device;
|
||||||
|
|
||||||
TRACE(("blkman_freecookie()\n"));
|
TRACE(("block_io_freecookie()\n"));
|
||||||
|
|
||||||
device->interface->free(handle->cookie);
|
device->interface->free(handle->cookie);
|
||||||
free(handle);
|
free(handle);
|
||||||
@@ -101,7 +101,7 @@ blkman_freecookie(blkman_handle_info *handle)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
verify_checksum(blkman_handle_info *handle, uint64 offset, uint32 len, uint32 chksum)
|
verify_checksum(block_io_handle_info *handle, uint64 offset, uint32 len, uint32 chksum)
|
||||||
{
|
{
|
||||||
void *buffer;
|
void *buffer;
|
||||||
uint32 readlen;
|
uint32 readlen;
|
||||||
@@ -115,7 +115,7 @@ verify_checksum(blkman_handle_info *handle, uint64 offset, uint32 len, uint32 ch
|
|||||||
|
|
||||||
readlen = len;
|
readlen = len;
|
||||||
|
|
||||||
res = blkman_read(handle, offset, buffer, &readlen);
|
res = block_io_read(handle, offset, buffer, &readlen);
|
||||||
if (res < B_OK || readlen < len)
|
if (res < B_OK || readlen < len)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@@ -138,10 +138,10 @@ err:
|
|||||||
/** store BIOS drive id in node's attribute */
|
/** store BIOS drive id in node's attribute */
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
store_bios_drive_in_node(blkman_device_info *device)
|
store_bios_drive_in_node(block_io_device_info *device)
|
||||||
{
|
{
|
||||||
device_attr attribute = {
|
device_attr attribute = {
|
||||||
BLKDEV_BIOS_ID, B_UINT8_TYPE, { ui8:
|
B_BLOCK_DEVICE_BIOS_ID, B_UINT8_TYPE, { ui8:
|
||||||
device->bios_drive != NULL ? device->bios_drive->bios_id : 0 }
|
device->bios_drive != NULL ? device->bios_drive->bios_id : 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,15 +153,15 @@ store_bios_drive_in_node(blkman_device_info *device)
|
|||||||
* this must be called whenever someone wants to access BIOS infos about the drive;
|
* this must be called whenever someone wants to access BIOS infos about the drive;
|
||||||
* there are two reasons to not call this during probe():
|
* there are two reasons to not call this during probe():
|
||||||
* - perhaps nobody is interested in BIOS info
|
* - perhaps nobody is interested in BIOS info
|
||||||
* - we need a working blkman device to handle lower level driver
|
* - we need a working block_io device to handle lower level driver
|
||||||
* restrictions, so this method can only be safely called once the
|
* restrictions, so this method can only be safely called once the
|
||||||
* node has been loaded
|
* node has been loaded
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
find_bios_drive_info(blkman_handle_info *handle)
|
find_bios_drive_info(block_io_handle_info *handle)
|
||||||
{
|
{
|
||||||
blkman_device_info *device = handle->device;
|
block_io_device_info *device = handle->device;
|
||||||
bios_drive *drive = NULL; //, *colliding_drive;
|
bios_drive *drive = NULL; //, *colliding_drive;
|
||||||
char name[32];
|
char name[32];
|
||||||
uint8 bios_id;
|
uint8 bios_id;
|
||||||
@@ -174,7 +174,7 @@ find_bios_drive_info(blkman_handle_info *handle)
|
|||||||
|
|
||||||
// check whether BIOS info was found during one of the previous
|
// check whether BIOS info was found during one of the previous
|
||||||
// loads
|
// loads
|
||||||
if (pnp->get_attr_uint8(device->node, BLKDEV_BIOS_ID, &bios_id, false) == B_OK) {
|
if (pnp->get_attr_uint8(device->node, B_BLOCK_DEVICE_BIOS_ID, &bios_id, false) == B_OK) {
|
||||||
TRACE(("use previous BIOS ID 0x%x\n", bios_id));
|
TRACE(("use previous BIOS ID 0x%x\n", bios_id));
|
||||||
|
|
||||||
// ToDo: this assumes private R5 kernel functions to be present
|
// ToDo: this assumes private R5 kernel functions to be present
|
||||||
@@ -287,9 +287,9 @@ no_bios_drive:
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_ioctl(blkman_handle_info *handle, uint32 op, void *buf, size_t len)
|
block_io_ioctl(block_io_handle_info *handle, uint32 op, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
blkman_device_info *device = handle->device;
|
block_io_device_info *device = handle->device;
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
if (device->is_bios_drive) {
|
if (device->is_bios_drive) {
|
||||||
@@ -340,17 +340,17 @@ blkman_ioctl(blkman_handle_info *handle, uint32 op, void *buf, size_t len)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_register_device(device_node_handle parent)
|
block_io_register_device(device_node_handle parent)
|
||||||
{
|
{
|
||||||
TRACE(("blkman_probe()\n"));
|
TRACE(("block_io_register_device()\n"));
|
||||||
|
|
||||||
// ready to register at devfs
|
// ready to register at devfs
|
||||||
{
|
{
|
||||||
device_attr attrs[] = {
|
device_attr attrs[] = {
|
||||||
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: BLKMAN_MODULE_NAME }},
|
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: B_BLOCK_IO_MODULE_NAME }},
|
||||||
// we always want devfs on top of us
|
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string: "block_io" }},
|
||||||
|
|
||||||
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: PNP_DEVFS_MODULE_NAME }},
|
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: PNP_DEVFS_MODULE_NAME }},
|
||||||
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string: "blkman" }},
|
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,13 +362,13 @@ blkman_register_device(device_node_handle parent)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blkman_remove(device_node_handle node, void *cookie)
|
block_io_remove(device_node_handle node, void *cookie)
|
||||||
{
|
{
|
||||||
uint8 bios_id;
|
uint8 bios_id;
|
||||||
//bios_drive *drive;
|
//bios_drive *drive;
|
||||||
|
|
||||||
// if this drive has a BIOS ID, remove it from BIOS drive list
|
// if this drive has a BIOS ID, remove it from BIOS drive list
|
||||||
if (pnp->get_attr_uint8(node, BLKDEV_BIOS_ID, &bios_id, false) != B_OK
|
if (pnp->get_attr_uint8(node, B_BLOCK_DEVICE_BIOS_ID, &bios_id, false) != B_OK
|
||||||
|| bios_id == 0 )
|
|| bios_id == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -388,26 +388,26 @@ blkman_remove(device_node_handle node, void *cookie)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
block_io_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
||||||
{
|
{
|
||||||
blkman_device_info *device;
|
block_io_device_info *device;
|
||||||
blkdev_params params;
|
block_device_params params;
|
||||||
char *name, *tmp_name;
|
char *name, *tmp_name;
|
||||||
uint8 is_bios_drive;
|
uint8 is_bios_drive;
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
TRACE(("blkman_init_device()\n"));
|
TRACE(("block_io_init_device()\n"));
|
||||||
|
|
||||||
// extract controller/protocoll restrictions from node
|
// extract controller/protocoll restrictions from node
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_DMA_ALIGNMENT, ¶ms.alignment, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_DMA_ALIGNMENT, ¶ms.alignment, true) != B_OK)
|
||||||
params.alignment = 0;
|
params.alignment = 0;
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_MAX_BLOCKS_ITEM, ¶ms.max_blocks, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_MAX_BLOCKS_ITEM, ¶ms.max_blocks, true) != B_OK)
|
||||||
params.max_blocks = 0xffffffff;
|
params.max_blocks = 0xffffffff;
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_DMA_BOUNDARY, ¶ms.dma_boundary, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_DMA_BOUNDARY, ¶ms.dma_boundary, true) != B_OK)
|
||||||
params.dma_boundary = ~0;
|
params.dma_boundary = ~0;
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_MAX_SG_BLOCK_SIZE, ¶ms.max_sg_block_size, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_MAX_SG_BLOCK_SIZE, ¶ms.max_sg_block_size, true) != B_OK)
|
||||||
params.max_sg_block_size = 0xffffffff;
|
params.max_sg_block_size = 0xffffffff;
|
||||||
if (pnp->get_attr_uint32(node, BLKDEV_MAX_SG_BLOCKS, ¶ms.max_sg_blocks, true) != B_OK)
|
if (pnp->get_attr_uint32(node, B_BLOCK_DEVICE_MAX_SG_BLOCKS, ¶ms.max_sg_blocks, true) != B_OK)
|
||||||
params.max_sg_blocks = ~0;
|
params.max_sg_blocks = ~0;
|
||||||
|
|
||||||
// do some sanity check:
|
// do some sanity check:
|
||||||
@@ -439,7 +439,7 @@ blkman_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
|||||||
// (they consume 4KB and can describe up to 2MB virtual cont. memory!)
|
// (they consume 4KB and can describe up to 2MB virtual cont. memory!)
|
||||||
params.max_sg_blocks = min(params.max_sg_blocks, 512);
|
params.max_sg_blocks = min(params.max_sg_blocks, 512);
|
||||||
|
|
||||||
if (pnp->get_attr_uint8(node, BLKDEV_IS_BIOS_DRIVE, &is_bios_drive, true) != B_OK)
|
if (pnp->get_attr_uint8(node, B_BLOCK_DEVICE_IS_BIOS_DRIVE, &is_bios_drive, true) != B_OK)
|
||||||
is_bios_drive = false;
|
is_bios_drive = false;
|
||||||
|
|
||||||
// we don't really care about /dev name, but if it is
|
// we don't really care about /dev name, but if it is
|
||||||
@@ -449,7 +449,7 @@ blkman_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
device = (blkman_device_info *)malloc(sizeof(*device));
|
device = (block_io_device_info *)malloc(sizeof(*device));
|
||||||
if (device == NULL) {
|
if (device == NULL) {
|
||||||
res = B_NO_MEMORY;
|
res = B_NO_MEMORY;
|
||||||
goto err1;
|
goto err1;
|
||||||
@@ -459,7 +459,7 @@ blkman_init_device(device_node_handle node, void *user_cookie, void **cookie)
|
|||||||
|
|
||||||
device->node = node;
|
device->node = node;
|
||||||
|
|
||||||
res = benaphore_init(&device->lock, "blkdev_mutex");
|
res = benaphore_init(&device->lock, "block_device_mutex");
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
goto err2;
|
goto err2;
|
||||||
|
|
||||||
@@ -517,7 +517,7 @@ err1:
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_uninit_device(blkman_device_info *device)
|
block_io_uninit_device(block_io_device_info *device)
|
||||||
{
|
{
|
||||||
pnp->uninit_driver(pnp->get_parent(device->node));
|
pnp->uninit_driver(pnp->get_parent(device->node));
|
||||||
|
|
||||||
@@ -530,54 +530,54 @@ blkman_uninit_device(blkman_device_info *device)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_init_buffer(void)
|
block_io_init_buffer(void)
|
||||||
{
|
{
|
||||||
physical_entry physicalTable[2];
|
physical_entry physicalTable[2];
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
TRACE(("blkman_init_buffer()\n"));
|
TRACE(("block_io_init_buffer()\n"));
|
||||||
|
|
||||||
blkman_buffer_size = 32*1024;
|
block_io_buffer_size = 32*1024;
|
||||||
|
|
||||||
blkman_buffer_lock = create_sem(1, "blkman_buffer_mutex");
|
block_io_buffer_lock = create_sem(1, "block_io_buffer_mutex");
|
||||||
if (blkman_buffer_lock < 0) {
|
if (block_io_buffer_lock < 0) {
|
||||||
res = blkman_buffer_lock;
|
res = block_io_buffer_lock;
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = blkman_buffer_area = create_area("blkman_buffer",
|
res = block_io_buffer_area = create_area("block_io_buffer",
|
||||||
(void **)&blkman_buffer, B_ANY_KERNEL_ADDRESS,
|
(void **)&block_io_buffer, B_ANY_KERNEL_ADDRESS,
|
||||||
blkman_buffer_size, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
|
block_io_buffer_size, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
goto err2;
|
goto err2;
|
||||||
|
|
||||||
res = get_memory_map(blkman_buffer, blkman_buffer_size, physicalTable, 2);
|
res = get_memory_map(block_io_buffer, block_io_buffer_size, physicalTable, 2);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
goto err3;
|
goto err3;
|
||||||
|
|
||||||
blkman_buffer_vec[0].iov_base = blkman_buffer;
|
block_io_buffer_vec[0].iov_base = block_io_buffer;
|
||||||
blkman_buffer_vec[0].iov_len = blkman_buffer_size;
|
block_io_buffer_vec[0].iov_len = block_io_buffer_size;
|
||||||
|
|
||||||
blkman_buffer_phys_vec.num = 1;
|
block_io_buffer_phys_vec.num = 1;
|
||||||
blkman_buffer_phys_vec.total_len = blkman_buffer_size;
|
block_io_buffer_phys_vec.total_len = block_io_buffer_size;
|
||||||
blkman_buffer_phys_vec.vec[0] = physicalTable[0];
|
block_io_buffer_phys_vec.vec[0] = physicalTable[0];
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
err3:
|
err3:
|
||||||
delete_area(blkman_buffer_area);
|
delete_area(block_io_buffer_area);
|
||||||
err2:
|
err2:
|
||||||
delete_sem(blkman_buffer_lock);
|
delete_sem(block_io_buffer_lock);
|
||||||
err1:
|
err1:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_uninit_buffer(void)
|
block_io_uninit_buffer(void)
|
||||||
{
|
{
|
||||||
delete_area(blkman_buffer_area);
|
delete_area(block_io_buffer_area);
|
||||||
delete_sem(blkman_buffer_lock);
|
delete_sem(block_io_buffer_lock);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -588,9 +588,9 @@ std_ops(int32 op, ...)
|
|||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
return blkman_init_buffer();
|
return block_io_init_buffer();
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
blkman_uninit_buffer();
|
block_io_uninit_buffer();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -606,38 +606,38 @@ module_dependency module_dependencies[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pnp_devfs_driver_info blkman_module = {
|
pnp_devfs_driver_info block_io_module = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
BLKMAN_MODULE_NAME,
|
B_BLOCK_IO_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
|
|
||||||
std_ops
|
std_ops
|
||||||
},
|
},
|
||||||
|
|
||||||
NULL, // supports device
|
NULL, // supports device
|
||||||
blkman_register_device,
|
block_io_register_device,
|
||||||
blkman_init_device,
|
block_io_init_device,
|
||||||
(status_t (*)( void * )) blkman_uninit_device,
|
(status_t (*)( void * )) block_io_uninit_device,
|
||||||
blkman_remove,
|
block_io_remove,
|
||||||
NULL, // cleanup
|
NULL, // cleanup
|
||||||
NULL, // get paths
|
NULL, // get paths
|
||||||
},
|
},
|
||||||
|
|
||||||
(status_t (*)(void *, uint32, void **))blkman_open,
|
(status_t (*)(void *, uint32, void **))block_io_open,
|
||||||
(status_t (*)(void *))blkman_close,
|
(status_t (*)(void *))block_io_close,
|
||||||
(status_t (*)(void *))blkman_freecookie,
|
(status_t (*)(void *))block_io_freecookie,
|
||||||
|
|
||||||
(status_t (*)(void *, uint32, void *, size_t))blkman_ioctl,
|
(status_t (*)(void *, uint32, void *, size_t))block_io_ioctl,
|
||||||
|
|
||||||
(status_t (*)(void *, off_t, void *, size_t *))blkman_read,
|
(status_t (*)(void *, off_t, void *, size_t *))block_io_read,
|
||||||
(status_t (*)(void *, off_t, const void *, size_t *))blkman_write,
|
(status_t (*)(void *, off_t, const void *, size_t *))block_io_write,
|
||||||
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
||||||
(status_t (*)(void *, off_t, const iovec *, size_t, size_t *))blkman_readv,
|
(status_t (*)(void *, off_t, const iovec *, size_t, size_t *))block_io_readv,
|
||||||
(status_t (*)(void *, off_t, const iovec *, size_t, size_t *))blkman_writev
|
(status_t (*)(void *, off_t, const iovec *, size_t, size_t *))block_io_writev
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -657,19 +657,19 @@ std_ops_for_driver(int32 op, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
blkman_for_driver_interface blkman_for_driver_module = {
|
block_io_for_driver_interface block_io_for_driver_module = {
|
||||||
{
|
{
|
||||||
BLKMAN_FOR_DRIVER_MODULE_NAME,
|
B_BLOCK_IO_FOR_DRIVER_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
|
|
||||||
std_ops_for_driver
|
std_ops_for_driver
|
||||||
},
|
},
|
||||||
|
|
||||||
blkman_set_media_params,
|
block_io_set_media_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_info *modules[] = {
|
module_info *modules[] = {
|
||||||
&blkman_module.info.info,
|
&block_io_module.info.info,
|
||||||
&blkman_for_driver_module.minfo,
|
&block_io_for_driver_module.info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
+31
-29
@@ -9,70 +9,72 @@
|
|||||||
Internal header.
|
Internal header.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <blkman.h>
|
#include <block_io.h>
|
||||||
#include <string.h>
|
|
||||||
#include <module.h>
|
#include <module.h>
|
||||||
#include <locked_pool.h>
|
#include <locked_pool.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <pnp_devfs.h>
|
#include <pnp_devfs.h>
|
||||||
#include <device_manager.h>
|
#include <device_manager.h>
|
||||||
#include <bios_drive.h>
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "bios_drive.h"
|
||||||
#include "wrapper.h"
|
#include "wrapper.h"
|
||||||
|
|
||||||
|
|
||||||
// controller restrictions (see blkman.h)
|
// controller restrictions (see block_io.h)
|
||||||
typedef struct blkdev_params {
|
typedef struct block_device_params {
|
||||||
uint32 alignment;
|
uint32 alignment;
|
||||||
uint32 max_blocks;
|
uint32 max_blocks;
|
||||||
uint32 dma_boundary;
|
uint32 dma_boundary;
|
||||||
uint32 max_sg_block_size;
|
uint32 max_sg_block_size;
|
||||||
uint32 max_sg_blocks;
|
uint32 max_sg_blocks;
|
||||||
} blkdev_params;
|
} block_device_params;
|
||||||
|
|
||||||
|
|
||||||
// device info
|
// device info
|
||||||
typedef struct blkman_device_info {
|
typedef struct block_io_device_info {
|
||||||
device_node_handle node;
|
device_node_handle node;
|
||||||
blkdev_interface *interface;
|
block_device_interface *interface;
|
||||||
blkdev_device_cookie cookie;
|
block_device_device_cookie cookie;
|
||||||
|
|
||||||
benaphore lock; // used for access to following variables
|
benaphore lock; // used for access to following variables
|
||||||
uint32 block_size;
|
uint32 block_size;
|
||||||
uint32 ld_block_size;
|
uint32 ld_block_size;
|
||||||
uint64 capacity;
|
uint64 capacity;
|
||||||
|
|
||||||
blkdev_params params;
|
block_device_params params;
|
||||||
bool is_bios_drive; // could be a BIOS drive
|
bool is_bios_drive; // could be a BIOS drive
|
||||||
locked_pool_cookie phys_vecs_pool; // pool of temporary phys_vecs
|
locked_pool_cookie phys_vecs_pool; // pool of temporary phys_vecs
|
||||||
bios_drive *bios_drive; // info about corresponding BIOS drive
|
bios_drive *bios_drive; // info about corresponding BIOS drive
|
||||||
} blkman_device_info;
|
} block_io_device_info;
|
||||||
|
|
||||||
|
|
||||||
// file handle info
|
// file handle info
|
||||||
typedef struct blkman_handle_info {
|
typedef struct block_io_handle_info {
|
||||||
blkman_device_info *device;
|
block_io_device_info *device;
|
||||||
blkdev_handle_cookie cookie;
|
block_device_handle_cookie cookie;
|
||||||
} blkman_handle_info;
|
} block_io_handle_info;
|
||||||
|
|
||||||
|
|
||||||
// attribute containing BIOS drive ID (or 0, if it's no BIOS drive) (uint8)
|
// attribute containing BIOS drive ID (or 0, if it's no BIOS drive) (uint8)
|
||||||
#define BLKDEV_BIOS_ID "blkdev/bios_id"
|
#define B_BLOCK_DEVICE_BIOS_ID "blkdev/bios_id"
|
||||||
|
|
||||||
// transmission buffer data:
|
// transmission buffer data:
|
||||||
// size in bytes
|
// size in bytes
|
||||||
extern uint blkman_buffer_size;
|
extern uint block_io_buffer_size;
|
||||||
// to use the buffer, you must own this semaphore
|
// to use the buffer, you must own this semaphore
|
||||||
extern sem_id blkman_buffer_lock;
|
extern sem_id block_io_buffer_lock;
|
||||||
// iovec
|
// iovec
|
||||||
extern struct iovec blkman_buffer_vec[1];
|
extern struct iovec block_io_buffer_vec[1];
|
||||||
// physical address
|
// physical address
|
||||||
extern void *blkman_buffer_phys;
|
extern void *block_io_buffer_phys;
|
||||||
// virtual address
|
// virtual address
|
||||||
extern char *blkman_buffer;
|
extern char *block_io_buffer;
|
||||||
// phys_vec of it (always linear)
|
// phys_vec of it (always linear)
|
||||||
extern phys_vecs blkman_buffer_phys_vec;
|
extern phys_vecs block_io_buffer_phys_vec;
|
||||||
// area containing buffer
|
// area containing buffer
|
||||||
extern area_id blkman_buffer_area;
|
extern area_id block_io_buffer_area;
|
||||||
|
|
||||||
extern locked_pool_interface *locked_pool;
|
extern locked_pool_interface *locked_pool;
|
||||||
extern device_manager_info *pnp;
|
extern device_manager_info *pnp;
|
||||||
@@ -80,11 +82,11 @@ extern device_manager_info *pnp;
|
|||||||
|
|
||||||
// io.c
|
// io.c
|
||||||
|
|
||||||
status_t blkman_readv(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
status_t block_io_readv(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, size_t *len);
|
size_t vec_count, size_t *len);
|
||||||
status_t blkman_read(blkman_handle_info *handle, off_t pos, void *buf, size_t *len);
|
status_t block_io_read(block_io_handle_info *handle, off_t pos, void *buf, size_t *len);
|
||||||
ssize_t blkman_writev(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
ssize_t block_io_writev(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, ssize_t *len);
|
size_t vec_count, ssize_t *len);
|
||||||
ssize_t blkman_write(blkman_handle_info *handle, off_t pos, void *buf, size_t *len);
|
ssize_t block_io_write(block_io_handle_info *handle, off_t pos, void *buf, size_t *len);
|
||||||
void blkman_set_media_params(blkman_device_info *device,
|
void block_io_set_media_params(block_io_device_info *device,
|
||||||
uint32 block_size, uint32 ld_block_size, uint64 capacity);
|
uint32 block_size, uint32 ld_block_size, uint64 capacity);
|
||||||
@@ -29,9 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "blkman_int.h"
|
#include "block_io_private.h"
|
||||||
#include "KernelExport_ext.h"
|
#include "virtual_memory.h"
|
||||||
#include <thread_types.h>
|
|
||||||
|
|
||||||
|
|
||||||
/** get sg list of iovecs, taking dma boundaries and maximum size of
|
/** get sg list of iovecs, taking dma boundaries and maximum size of
|
||||||
@@ -40,7 +39,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
blkman_map_iovecs(iovec *vec, size_t vec_count, size_t vec_offset, size_t len,
|
block_io_map_iovecs(iovec *vec, size_t vec_count, size_t vec_offset, size_t len,
|
||||||
phys_vecs *map, size_t max_phys_entries, size_t dma_boundary,
|
phys_vecs *map, size_t max_phys_entries, size_t dma_boundary,
|
||||||
size_t max_sg_block_size)
|
size_t max_sg_block_size)
|
||||||
{
|
{
|
||||||
@@ -104,7 +103,7 @@ blkman_map_iovecs(iovec *vec, size_t vec_count, size_t vec_offset, size_t len,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
blkman_check_alignment(struct iovec *vecs, uint num_vecs,
|
block_io_check_alignment(struct iovec *vecs, uint num_vecs,
|
||||||
size_t vec_offset, uint alignment)
|
size_t vec_offset, uint alignment)
|
||||||
{
|
{
|
||||||
if (alignment == 0)
|
if (alignment == 0)
|
||||||
@@ -138,7 +137,7 @@ blkman_check_alignment(struct iovec *vecs, uint num_vecs,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
blkman_lock_iovecs(struct iovec *vecs, uint num_vecs,
|
block_io_lock_iovecs(struct iovec *vecs, uint num_vecs,
|
||||||
size_t vec_offset, size_t len, int flags)
|
size_t vec_offset, size_t len, int flags)
|
||||||
{
|
{
|
||||||
size_t orig_len = len;
|
size_t orig_len = len;
|
||||||
@@ -172,7 +171,7 @@ blkman_lock_iovecs(struct iovec *vecs, uint num_vecs,
|
|||||||
/** unlock iovecs */
|
/** unlock iovecs */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blkman_unlock_iovecs(struct iovec *vecs, uint num_vecs,
|
block_io_unlock_iovecs(struct iovec *vecs, uint num_vecs,
|
||||||
size_t vec_offset, size_t len, int flags)
|
size_t vec_offset, size_t len, int flags)
|
||||||
{
|
{
|
||||||
SHOW_FLOW(3, "len = %lu", len);
|
SHOW_FLOW(3, "len = %lu", len);
|
||||||
@@ -197,7 +196,7 @@ blkman_unlock_iovecs(struct iovec *vecs, uint num_vecs,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blkman_copy_buffer(char *buffer, struct iovec *vecs, uint num_vecs,
|
block_io_copy_buffer(char *buffer, struct iovec *vecs, uint num_vecs,
|
||||||
size_t vec_offset, size_t len, bool to_buffer)
|
size_t vec_offset, size_t len, bool to_buffer)
|
||||||
{
|
{
|
||||||
for (; len > 0 && num_vecs > 0; ++vecs, --num_vecs) {
|
for (; len > 0 && num_vecs > 0; ++vecs, --num_vecs) {
|
||||||
@@ -219,7 +218,7 @@ blkman_copy_buffer(char *buffer, struct iovec *vecs, uint num_vecs,
|
|||||||
/** determine number of bytes described by iovecs */
|
/** determine number of bytes described by iovecs */
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
blkman_iovec_len(struct iovec *vecs, uint num_vecs, size_t vec_offset)
|
block_io_iovec_len(struct iovec *vecs, uint num_vecs, size_t vec_offset)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
@@ -240,10 +239,10 @@ blkman_iovec_len(struct iovec *vecs, uint num_vecs, size_t vec_offset)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static inline status_t
|
static inline status_t
|
||||||
blkman_readwrite(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_readwrite(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
int vec_count, size_t *total_len, bool need_locking, bool write)
|
int vec_count, size_t *total_len, bool need_locking, bool write)
|
||||||
{
|
{
|
||||||
blkman_device_info *device = handle->device;
|
block_io_device_info *device = handle->device;
|
||||||
uint32 block_size, ld_block_size;
|
uint32 block_size, ld_block_size;
|
||||||
uint64 capacity;
|
uint64 capacity;
|
||||||
bool need_buffer;
|
bool need_buffer;
|
||||||
@@ -355,7 +354,7 @@ blkman_readwrite(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
|||||||
// you deserve)
|
// you deserve)
|
||||||
need_buffer = block_ofs != 0
|
need_buffer = block_ofs != 0
|
||||||
|| len < block_size
|
|| len < block_size
|
||||||
|| !blkman_check_alignment(vec, vec_count, vec_offset, device->params.alignment);
|
|| !block_io_check_alignment(vec, vec_count, vec_offset, device->params.alignment);
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (need_buffer) {
|
if (need_buffer) {
|
||||||
@@ -365,7 +364,7 @@ retry:
|
|||||||
SHOW_FLOW(1, "buffer required: len=%ld, block_ofs=%ld",
|
SHOW_FLOW(1, "buffer required: len=%ld, block_ofs=%ld",
|
||||||
len, block_ofs);
|
len, block_ofs);
|
||||||
|
|
||||||
acquire_sem(blkman_buffer_lock);
|
acquire_sem(block_io_buffer_lock);
|
||||||
|
|
||||||
// nobody helps us if there are too few iovecs, so test
|
// nobody helps us if there are too few iovecs, so test
|
||||||
// for that explicitely
|
// for that explicitely
|
||||||
@@ -373,7 +372,7 @@ retry:
|
|||||||
// we would get trouble when we try to round up to next
|
// we would get trouble when we try to round up to next
|
||||||
// block size, which would lead to zero, making trouble
|
// block size, which would lead to zero, making trouble
|
||||||
// during lock)
|
// during lock)
|
||||||
tmp_len = blkman_iovec_len(vec, vec_count, vec_offset);
|
tmp_len = block_io_iovec_len(vec, vec_count, vec_offset);
|
||||||
tmp_len = min(tmp_len, len);
|
tmp_len = min(tmp_len, len);
|
||||||
|
|
||||||
SHOW_FLOW(3, "tmp_len: %lu", tmp_len);
|
SHOW_FLOW(3, "tmp_len: %lu", tmp_len);
|
||||||
@@ -385,7 +384,7 @@ retry:
|
|||||||
|
|
||||||
SHOW_FLOW0(3, "partial write at beginning: reading content of first block");
|
SHOW_FLOW0(3, "partial write at beginning: reading content of first block");
|
||||||
res = device->interface->read(handle->cookie,
|
res = device->interface->read(handle->cookie,
|
||||||
&blkman_buffer_phys_vec, block_pos,
|
&block_io_buffer_phys_vec, block_pos,
|
||||||
cur_blocks, block_size, &bytes_transferred);
|
cur_blocks, block_size, &bytes_transferred);
|
||||||
} else {
|
} else {
|
||||||
// alignment problem or partial block read - find out how many
|
// alignment problem or partial block read - find out how many
|
||||||
@@ -395,8 +394,8 @@ retry:
|
|||||||
SHOW_FLOW(3, "cur_blocks: %ld", cur_blocks);
|
SHOW_FLOW(3, "cur_blocks: %ld", cur_blocks);
|
||||||
|
|
||||||
// restrict block count to buffer size
|
// restrict block count to buffer size
|
||||||
if (cur_blocks * block_size > blkman_buffer_size)
|
if (cur_blocks * block_size > block_io_buffer_size)
|
||||||
cur_blocks = blkman_buffer_size / block_size;
|
cur_blocks = block_io_buffer_size / block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy data into buffer before write
|
// copy data into buffer before write
|
||||||
@@ -404,12 +403,12 @@ retry:
|
|||||||
if (write) {
|
if (write) {
|
||||||
SHOW_FLOW(3, "copy data to buffer (%ld bytes)",
|
SHOW_FLOW(3, "copy data to buffer (%ld bytes)",
|
||||||
cur_blocks * block_size - block_ofs);
|
cur_blocks * block_size - block_ofs);
|
||||||
blkman_copy_buffer(blkman_buffer + block_ofs,
|
block_io_copy_buffer(block_io_buffer + block_ofs,
|
||||||
vec, vec_count, vec_offset, cur_blocks * block_size - block_ofs,
|
vec, vec_count, vec_offset, cur_blocks * block_size - block_ofs,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_vecs = blkman_buffer_vec;
|
cur_vecs = block_io_buffer_vec;
|
||||||
cur_vec_count = 1;
|
cur_vec_count = 1;
|
||||||
cur_vec_offset = 0;
|
cur_vec_offset = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -449,7 +448,7 @@ retry:
|
|||||||
|
|
||||||
SHOW_FLOW(3, "trying to lock %lu bytes", cur_len);
|
SHOW_FLOW(3, "trying to lock %lu bytes", cur_len);
|
||||||
|
|
||||||
locked_len = blkman_lock_iovecs(cur_vecs, cur_vec_count,
|
locked_len = block_io_lock_iovecs(cur_vecs, cur_vec_count,
|
||||||
cur_vec_offset, cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
cur_vec_offset, cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
||||||
|
|
||||||
if (locked_len == cur_len)
|
if (locked_len == cur_len)
|
||||||
@@ -469,7 +468,7 @@ retry:
|
|||||||
// got less then one block locked - unlock and retry
|
// got less then one block locked - unlock and retry
|
||||||
SHOW_FLOW0(3, "too few bytes locked - trying again with fewer bytes");
|
SHOW_FLOW0(3, "too few bytes locked - trying again with fewer bytes");
|
||||||
|
|
||||||
blkman_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset, locked_len,
|
block_io_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset, locked_len,
|
||||||
B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +494,7 @@ retry:
|
|||||||
// time to setup sg list
|
// time to setup sg list
|
||||||
SHOW_FLOW0(3, "Creating SG list");
|
SHOW_FLOW0(3, "Creating SG list");
|
||||||
|
|
||||||
res = blkman_map_iovecs(cur_vecs, cur_vec_count, cur_vec_offset, cur_len,
|
res = block_io_map_iovecs(cur_vecs, cur_vec_count, cur_vec_offset, cur_len,
|
||||||
phys_vecs, device->params.max_sg_blocks, device->params.dma_boundary,
|
phys_vecs, device->params.max_sg_blocks, device->params.dma_boundary,
|
||||||
device->params.max_sg_block_size);
|
device->params.max_sg_block_size);
|
||||||
|
|
||||||
@@ -515,7 +514,7 @@ retry:
|
|||||||
SHOW_FLOW0(3, "SG too small to handle even one block");
|
SHOW_FLOW0(3, "SG too small to handle even one block");
|
||||||
|
|
||||||
if (need_locking) {
|
if (need_locking) {
|
||||||
blkman_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset,
|
block_io_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset,
|
||||||
cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +552,7 @@ retry:
|
|||||||
cannot_map:
|
cannot_map:
|
||||||
// unlock data
|
// unlock data
|
||||||
if (need_locking) {
|
if (need_locking) {
|
||||||
blkman_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset,
|
block_io_unlock_iovecs(cur_vecs, cur_vec_count, cur_vec_offset,
|
||||||
cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
cur_len, B_DMA_IO | (write ? 0 : B_READ_DEVICE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,11 +571,11 @@ cannot_map:
|
|||||||
if (!write) {
|
if (!write) {
|
||||||
SHOW_FLOW(3, "copying data back from buffer (%ld bytes)",
|
SHOW_FLOW(3, "copying data back from buffer (%ld bytes)",
|
||||||
bytes_transferred);
|
bytes_transferred);
|
||||||
blkman_copy_buffer(blkman_buffer + block_ofs,
|
block_io_copy_buffer(block_io_buffer + block_ofs,
|
||||||
vec, vec_count, vec_offset, bytes_transferred, false);
|
vec, vec_count, vec_offset, bytes_transferred, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_sem(blkman_buffer_lock);
|
release_sem(block_io_buffer_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
len -= bytes_transferred;
|
len -= bytes_transferred;
|
||||||
@@ -592,7 +591,7 @@ cannot_map:
|
|||||||
|
|
||||||
err3:
|
err3:
|
||||||
if (need_buffer)
|
if (need_buffer)
|
||||||
release_sem(blkman_buffer_lock);
|
release_sem(block_io_buffer_lock);
|
||||||
err2:
|
err2:
|
||||||
locked_pool->free(device->phys_vecs_pool, phys_vecs);
|
locked_pool->free(device->phys_vecs_pool, phys_vecs);
|
||||||
err:
|
err:
|
||||||
@@ -605,18 +604,18 @@ err:
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_readv_int(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_readv_int(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, size_t *len, bool need_locking)
|
size_t vec_count, size_t *len, bool need_locking)
|
||||||
{
|
{
|
||||||
return blkman_readwrite(handle, pos, vec, vec_count, len, need_locking, false);
|
return block_io_readwrite(handle, pos, vec, vec_count, len, need_locking, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
blkman_writev_int(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_writev_int(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, size_t *len, bool need_locking)
|
size_t vec_count, size_t *len, bool need_locking)
|
||||||
{
|
{
|
||||||
return blkman_readwrite(handle, pos, vec, vec_count, len, need_locking, true);
|
return block_io_readwrite(handle, pos, vec, vec_count, len, need_locking, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -626,7 +625,7 @@ blkman_writev_int(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static inline status_t
|
static inline status_t
|
||||||
blkman_readwritev(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_readwritev(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, size_t *len, bool write)
|
size_t vec_count, size_t *len, bool write)
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -649,9 +648,9 @@ blkman_readwritev(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
|||||||
*len = total_len;
|
*len = total_len;
|
||||||
|
|
||||||
if (write)
|
if (write)
|
||||||
res = blkman_writev_int(handle, pos, vec, vec_count, len, true);
|
res = block_io_writev_int(handle, pos, vec, vec_count, len, true);
|
||||||
else
|
else
|
||||||
res = blkman_readv_int(handle, pos, vec, vec_count, len, true);
|
res = block_io_readv_int(handle, pos, vec, vec_count, len, true);
|
||||||
|
|
||||||
unlock_memory(vec, vec_count * sizeof(vec[0]), 0);
|
unlock_memory(vec, vec_count * sizeof(vec[0]), 0);
|
||||||
|
|
||||||
@@ -660,7 +659,7 @@ blkman_readwritev(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
blkman_readv(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_readv(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, size_t *len)
|
size_t vec_count, size_t *len)
|
||||||
{
|
{
|
||||||
/* SHOW_FLOW( 4, "len=%d", (int)*len );
|
/* SHOW_FLOW( 4, "len=%d", (int)*len );
|
||||||
@@ -670,12 +669,12 @@ blkman_readv(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
|||||||
(int)cur_vec->iov_base, (int)cur_vec->iov_len );
|
(int)cur_vec->iov_base, (int)cur_vec->iov_len );
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return blkman_readwritev(handle, pos, vec, vec_count, len, false);
|
return block_io_readwritev(handle, pos, vec, vec_count, len, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
blkman_read(blkman_handle_info *handle, off_t pos, void *buf, size_t *len)
|
block_io_read(block_io_handle_info *handle, off_t pos, void *buf, size_t *len)
|
||||||
{
|
{
|
||||||
iovec vec[1];
|
iovec vec[1];
|
||||||
|
|
||||||
@@ -685,37 +684,37 @@ blkman_read(blkman_handle_info *handle, off_t pos, void *buf, size_t *len)
|
|||||||
SHOW_FLOW0( 3, "" );
|
SHOW_FLOW0( 3, "" );
|
||||||
|
|
||||||
// This assumes that the thread stack is not paged,
|
// This assumes that the thread stack is not paged,
|
||||||
// else you want to use blkman_readv
|
// else you want to use block_io_readv
|
||||||
// But this is not a problem, since kernel stacks
|
// But this is not a problem, since kernel stacks
|
||||||
// are always paged in (since they can be used by
|
// are always paged in (since they can be used by
|
||||||
// an interrupt at any time)
|
// an interrupt at any time)
|
||||||
return blkman_readv_int(handle, pos, vec, 1, len, true);
|
return block_io_readv_int(handle, pos, vec, 1, len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
blkman_writev(blkman_handle_info *handle, off_t pos, struct iovec *vec,
|
block_io_writev(block_io_handle_info *handle, off_t pos, struct iovec *vec,
|
||||||
size_t vec_count, ssize_t *len)
|
size_t vec_count, ssize_t *len)
|
||||||
{
|
{
|
||||||
return blkman_readwritev(handle, pos, vec, vec_count, len, true);
|
return block_io_readwritev(handle, pos, vec, vec_count, len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
blkman_write(blkman_handle_info *handle, off_t pos, void *buf, size_t *len)
|
block_io_write(block_io_handle_info *handle, off_t pos, void *buf, size_t *len)
|
||||||
{
|
{
|
||||||
iovec vec[1];
|
iovec vec[1];
|
||||||
|
|
||||||
vec[0].iov_base = buf;
|
vec[0].iov_base = buf;
|
||||||
vec[0].iov_len = *len;
|
vec[0].iov_len = *len;
|
||||||
|
|
||||||
// see blkman_read
|
// see block_io_read
|
||||||
return blkman_writev_int(handle, pos, vec, 1, len, true);
|
return block_io_writev_int(handle, pos, vec, 1, len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
blkman_set_media_params(blkman_device_info *device, uint32 block_size,
|
block_io_set_media_params(block_io_device_info *device, uint32 block_size,
|
||||||
uint32 ld_block_size, uint64 capacity)
|
uint32 ld_block_size, uint64 capacity)
|
||||||
{
|
{
|
||||||
SHOW_FLOW(3, "block_size = %lu, ld_block_size = %lu, capacity = %Lu\n", block_size,
|
SHOW_FLOW(3, "block_size = %lu, ld_block_size = %lu, capacity = %Lu\n", block_size,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
VM helper functions.
|
VM helper functions.
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
list of length one.
|
list of length one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "KernelExport_ext.h"
|
#include "virtual_memory.h"
|
||||||
#include "wrapper.h"
|
#include "wrapper.h"
|
||||||
|
|
||||||
#include <vm.h>
|
#include <vm.h>
|
||||||
@@ -118,22 +118,3 @@ get_iovec_memory_map(iovec *vec, size_t vec_count, size_t vec_offset, size_t len
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** map main memory into virtual address space */
|
|
||||||
|
|
||||||
status_t
|
|
||||||
map_mainmemory(addr_t physicalAddress, void **_virtualAddress)
|
|
||||||
{
|
|
||||||
return vm_get_physical_page(physicalAddress, (addr_t *)_virtualAddress, PHYSICAL_PAGE_CAN_WAIT);
|
|
||||||
// ToDo: check if CAN_WAIT is correct
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** unmap main memory from virtual address space */
|
|
||||||
|
|
||||||
status_t
|
|
||||||
unmap_mainmemory(void *virtualAddress)
|
|
||||||
{
|
|
||||||
return vm_put_physical_page((addr_t)virtualAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _VIRTUAL_MEMORY_H
|
||||||
|
#define _VIRTUAL_MEMORY_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <KernelExport.h>
|
||||||
|
#include <iovec.h>
|
||||||
|
|
||||||
|
|
||||||
|
// get memory map of iovec
|
||||||
|
extern status_t get_iovec_memory_map(iovec *vec, size_t vecCount,
|
||||||
|
size_t vecOffset, size_t length, physical_entry *map,
|
||||||
|
size_t maxMapEntries, size_t *_numEntries,
|
||||||
|
size_t *_mappedLength);
|
||||||
|
|
||||||
|
#endif /* _VIRTUAL_MEMORY_H */
|
||||||
@@ -12,11 +12,10 @@
|
|||||||
|
|
||||||
#include "scsi_periph_int.h"
|
#include "scsi_periph_int.h"
|
||||||
|
|
||||||
#include <blkman.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#define SCSI_PERIPH_STD_TIMEOUT 10
|
#define SCSI_PERIPH_STD_TIMEOUT 10
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Peripheral Driver
|
Part of Open SCSI Peripheral Driver
|
||||||
@@ -9,9 +9,8 @@
|
|||||||
Error handling
|
Error handling
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scsi_periph_int.h"
|
|
||||||
|
|
||||||
#include <blkman.h>
|
#include "scsi_periph_int.h"
|
||||||
|
|
||||||
|
|
||||||
/** decode sense data and generate error code */
|
/** decode sense data and generate error code */
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Peripheral Driver
|
Part of Open SCSI Peripheral Driver
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "scsi_periph_int.h"
|
#include "scsi_periph_int.h"
|
||||||
|
|
||||||
#include <blkman.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,12 @@
|
|||||||
#define __SCSI_PERIPH_INT_H__
|
#define __SCSI_PERIPH_INT_H__
|
||||||
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <bus/scsi/scsi_periph.h>
|
#include <bus/scsi/scsi_periph.h>
|
||||||
#include <blkman.h>
|
#include <block_io.h>
|
||||||
#include <device_manager.h>
|
#include <device_manager.h>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "wrapper.h"
|
#include "wrapper.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user