[block] Remove userptr_t from block device abstraction

Simplify the block device code by assuming that all read/write buffers
are directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-24 17:11:30 +01:00
parent 2742ed5d77
commit 2f11f466e6
19 changed files with 86 additions and 93 deletions
+15 -15
View File
@@ -147,8 +147,8 @@ struct ata_command_type {
* @ret data_in Data-in buffer
* @ret data_in_len Data-in buffer length
*/
void ( * data_in ) ( struct ata_command *atacmd, userptr_t buffer,
size_t len, userptr_t *data_in,
void ( * data_in ) ( struct ata_command *atacmd, void *buffer,
size_t len, void **data_in,
size_t *data_in_len );
/**
* Calculate data-out buffer
@@ -160,8 +160,8 @@ struct ata_command_type {
* @ret data_out Data-out buffer
* @ret data_out_len Data-out buffer length
*/
void ( * data_out ) ( struct ata_command *atacmd, userptr_t buffer,
size_t len, userptr_t *data_out,
void ( * data_out ) ( struct ata_command *atacmd, void *buffer,
size_t len, void **data_out,
size_t *data_out_len );
/**
* Handle ATA command completion
@@ -285,8 +285,8 @@ static void atacmd_done ( struct ata_command *atacmd, int rc ) {
* @ret data_len Data buffer length
*/
static void atacmd_data_buffer ( struct ata_command *atacmd __unused,
userptr_t buffer, size_t len,
userptr_t *data, size_t *data_len ) {
void *buffer, size_t len,
void **data, size_t *data_len ) {
*data = buffer;
*data_len = len;
}
@@ -301,8 +301,8 @@ static void atacmd_data_buffer ( struct ata_command *atacmd __unused,
* @ret data_len Data buffer length
*/
static void atacmd_data_none ( struct ata_command *atacmd __unused,
userptr_t buffer __unused, size_t len __unused,
userptr_t *data __unused,
void *buffer __unused, size_t len __unused,
void **data __unused,
size_t *data_len __unused ) {
/* Nothing to do */
}
@@ -317,9 +317,9 @@ static void atacmd_data_none ( struct ata_command *atacmd __unused,
* @ret data_len Data buffer length
*/
static void atacmd_data_priv ( struct ata_command *atacmd,
userptr_t buffer __unused, size_t len __unused,
userptr_t *data, size_t *data_len ) {
*data = virt_to_user ( atacmd_priv ( atacmd ) );
void *buffer __unused, size_t len __unused,
void **data, size_t *data_len ) {
*data = atacmd_priv ( atacmd );
*data_len = atacmd->type->priv_len;
}
@@ -455,7 +455,7 @@ static int atadev_command ( struct ata_device *atadev,
struct interface *block,
struct ata_command_type *type,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
struct ata_command *atacmd;
struct ata_cmd command;
int tag;
@@ -543,7 +543,7 @@ static int atadev_command ( struct ata_device *atadev,
static int atadev_read ( struct ata_device *atadev,
struct interface *block,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
return atadev_command ( atadev, block, &atacmd_read,
lba, count, buffer, len );
}
@@ -562,7 +562,7 @@ static int atadev_read ( struct ata_device *atadev,
static int atadev_write ( struct ata_device *atadev,
struct interface *block,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
return atadev_command ( atadev, block, &atacmd_write,
lba, count, buffer, len );
}
@@ -581,7 +581,7 @@ static int atadev_read_capacity ( struct ata_device *atadev,
assert ( atacmd_identify.priv_len == sizeof ( *identity ) );
assert ( atacmd_identify.priv_len == ATA_SECTOR_SIZE );
return atadev_command ( atadev, block, &atacmd_identify,
0, 1, UNULL, ATA_SECTOR_SIZE );
0, 1, NULL, ATA_SECTOR_SIZE );
}
/**
+8 -8
View File
@@ -279,7 +279,7 @@ struct scsi_command {
/** Number of blocks */
unsigned int count;
/** Data buffer */
userptr_t buffer;
void *buffer;
/** Length of data buffer */
size_t len;
/** Command tag */
@@ -591,12 +591,12 @@ static void scsicmd_read_capacity_cmd ( struct scsi_command *scsicmd,
readcap16->service_action =
SCSI_SERVICE_ACTION_READ_CAPACITY_16;
readcap16->len = cpu_to_be32 ( sizeof ( *capacity16 ) );
command->data_in = virt_to_user ( capacity16 );
command->data_in = capacity16;
command->data_in_len = sizeof ( *capacity16 );
} else {
/* Use READ CAPACITY (10) */
readcap10->opcode = SCSI_OPCODE_READ_CAPACITY_10;
command->data_in = virt_to_user ( capacity10 );
command->data_in = capacity10;
command->data_in_len = sizeof ( *capacity10 );
}
}
@@ -721,7 +721,7 @@ static int scsidev_command ( struct scsi_device *scsidev,
struct interface *block,
struct scsi_command_type *type,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
struct scsi_command *scsicmd;
int rc;
@@ -773,7 +773,7 @@ static int scsidev_command ( struct scsi_device *scsidev,
static int scsidev_read ( struct scsi_device *scsidev,
struct interface *block,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
return scsidev_command ( scsidev, block, &scsicmd_read,
lba, count, buffer, len );
}
@@ -792,7 +792,7 @@ static int scsidev_read ( struct scsi_device *scsidev,
static int scsidev_write ( struct scsi_device *scsidev,
struct interface *block,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) {
void *buffer, size_t len ) {
return scsidev_command ( scsidev, block, &scsicmd_write,
lba, count, buffer, len );
}
@@ -807,7 +807,7 @@ static int scsidev_write ( struct scsi_device *scsidev,
static int scsidev_read_capacity ( struct scsi_device *scsidev,
struct interface *block ) {
return scsidev_command ( scsidev, block, &scsicmd_read_capacity,
0, 0, UNULL, 0 );
0, 0, NULL, 0 );
}
/**
@@ -820,7 +820,7 @@ static int scsidev_read_capacity ( struct scsi_device *scsidev,
static int scsidev_test_unit_ready ( struct scsi_device *scsidev,
struct interface *block ) {
return scsidev_command ( scsidev, block, &scsicmd_test_unit_ready,
0, 0, UNULL, 0 );
0, 0, NULL, 0 );
}
/**
+5 -5
View File
@@ -205,7 +205,7 @@ static int usbblk_out_data ( struct usbblk_device *usbblk ) {
/* Calculate length */
assert ( cmd->tag );
assert ( cmd->scsi.data_out != UNULL );
assert ( cmd->scsi.data_out != NULL );
assert ( cmd->offset < cmd->scsi.data_out_len );
len = ( cmd->scsi.data_out_len - cmd->offset );
if ( len > USBBLK_MAX_LEN )
@@ -220,8 +220,8 @@ static int usbblk_out_data ( struct usbblk_device *usbblk ) {
}
/* Populate I/O buffer */
copy_from_user ( iob_put ( iobuf, len ), cmd->scsi.data_out,
cmd->offset, len );
memcpy ( iob_put ( iobuf, len ),
( cmd->scsi.data_out + cmd->offset ), len );
/* Send data */
if ( ( rc = usb_stream ( &usbblk->out, iobuf, 0 ) ) != 0 ) {
@@ -332,12 +332,12 @@ static int usbblk_in_data ( struct usbblk_device *usbblk, const void *data,
/* Sanity checks */
assert ( cmd->tag );
assert ( cmd->scsi.data_in != UNULL );
assert ( cmd->scsi.data_in != NULL );
assert ( cmd->offset <= cmd->scsi.data_in_len );
assert ( len <= ( cmd->scsi.data_in_len - cmd->offset ) );
/* Store data */
copy_to_user ( cmd->scsi.data_in, cmd->offset, data, len );
memcpy ( ( cmd->scsi.data_in + cmd->offset ), data, len );
cmd->offset += len;
return 0;