summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Vivier2008-11-19 17:31:07 +0100
committerMichael Brown2008-11-19 21:04:43 +0100
commita2686a55c4799f34dcaa60e14097ed0e8f5c9254 (patch)
treecc9d38a621fd9ebeb6ef9f63bfcc083fec1824b5
parent[virtio] Split virtio-net.c into several files. (diff)
downloadipxe-a2686a55c4799f34dcaa60e14097ed0e8f5c9254.tar.gz
ipxe-a2686a55c4799f34dcaa60e14097ed0e8f5c9254.tar.xz
ipxe-a2686a55c4799f34dcaa60e14097ed0e8f5c9254.zip
[blockdev] Move block device operations to structure block_device_operations
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
-rw-r--r--src/arch/i386/interface/pcbios/int13.c12
-rw-r--r--src/drivers/block/ata.c8
-rw-r--r--src/drivers/block/ramdisk.c8
-rw-r--r--src/drivers/block/scsi.c16
-rw-r--r--src/include/gpxe/blockdev.h20
5 files changed, 44 insertions, 20 deletions
diff --git a/src/arch/i386/interface/pcbios/int13.c b/src/arch/i386/interface/pcbios/int13.c
index a18039e0..2e9de5cb 100644
--- a/src/arch/i386/interface/pcbios/int13.c
+++ b/src/arch/i386/interface/pcbios/int13.c
@@ -144,7 +144,7 @@ static int int13_rw_sectors ( struct int13_drive *drive,
static int int13_read_sectors ( struct int13_drive *drive,
struct i386_all_regs *ix86 ) {
DBG ( "Read: " );
- return int13_rw_sectors ( drive, ix86, drive->blockdev->read );
+ return int13_rw_sectors ( drive, ix86, drive->blockdev->op->read );
}
/**
@@ -163,7 +163,7 @@ static int int13_read_sectors ( struct int13_drive *drive,
static int int13_write_sectors ( struct int13_drive *drive,
struct i386_all_regs *ix86 ) {
DBG ( "Write: " );
- return int13_rw_sectors ( drive, ix86, drive->blockdev->write );
+ return int13_rw_sectors ( drive, ix86, drive->blockdev->op->write );
}
/**
@@ -275,7 +275,7 @@ static int int13_extended_rw ( struct int13_drive *drive,
static int int13_extended_read ( struct int13_drive *drive,
struct i386_all_regs *ix86 ) {
DBG ( "Extended read: " );
- return int13_extended_rw ( drive, ix86, drive->blockdev->read );
+ return int13_extended_rw ( drive, ix86, drive->blockdev->op->read );
}
/**
@@ -288,7 +288,7 @@ static int int13_extended_read ( struct int13_drive *drive,
static int int13_extended_write ( struct int13_drive *drive,
struct i386_all_regs *ix86 ) {
DBG ( "Extended write: " );
- return int13_extended_rw ( drive, ix86, drive->blockdev->write );
+ return int13_extended_rw ( drive, ix86, drive->blockdev->op->write );
}
/**
@@ -488,8 +488,8 @@ static void guess_int13_geometry ( struct int13_drive *drive ) {
/* Scan through partition table and modify guesses for heads
* and sectors_per_track if we find any used partitions.
*/
- if ( drive->blockdev->read ( drive->blockdev, 0, 1,
- virt_to_user ( &mbr ) ) == 0 ) {
+ if ( drive->blockdev->op->read ( drive->blockdev, 0, 1,
+ virt_to_user ( &mbr ) ) == 0 ) {
for ( i = 0 ; i < 4 ; i++ ) {
partition = &mbr.partitions[i];
if ( ! partition->type )
diff --git a/src/drivers/block/ata.c b/src/drivers/block/ata.c
index 555a5f6e..c21d2f65 100644
--- a/src/drivers/block/ata.c
+++ b/src/drivers/block/ata.c
@@ -139,6 +139,11 @@ static int ata_identify ( struct block_device *blockdev ) {
return 0;
}
+static struct block_device_operations ata_operations = {
+ .read = ata_read,
+ .write = ata_write
+};
+
/**
* Initialise ATA device
*
@@ -153,7 +158,6 @@ static int ata_identify ( struct block_device *blockdev ) {
*/
int init_atadev ( struct ata_device *ata ) {
/** Fill in read and write methods, and get device capacity */
- ata->blockdev.read = ata_read;
- ata->blockdev.write = ata_write;
+ ata->blockdev.op = &ata_operations;
return ata_identify ( &ata->blockdev );
}
diff --git a/src/drivers/block/ramdisk.c b/src/drivers/block/ramdisk.c
index b5324bf1..50911994 100644
--- a/src/drivers/block/ramdisk.c
+++ b/src/drivers/block/ramdisk.c
@@ -75,6 +75,11 @@ static int ramdisk_write ( struct block_device *blockdev, uint64_t block,
return 0;
}
+static struct block_device_operations ramdisk_operations = {
+ .read = ramdisk_read,
+ .write = ramdisk_write
+};
+
int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
unsigned int blksize ) {
@@ -82,8 +87,7 @@ int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
blksize = 512;
ramdisk->data = data;
- ramdisk->blockdev.read = ramdisk_read;
- ramdisk->blockdev.write = ramdisk_write;
+ ramdisk->blockdev.op = &ramdisk_operations;
ramdisk->blockdev.blksize = blksize;
ramdisk->blockdev.blocks = ( len / blksize );
diff --git a/src/drivers/block/scsi.c b/src/drivers/block/scsi.c
index 9651583a..9ff47f89 100644
--- a/src/drivers/block/scsi.c
+++ b/src/drivers/block/scsi.c
@@ -228,6 +228,16 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
return 0;
}
+static struct block_device_operations scsi_operations_16 = {
+ .read = scsi_read_16,
+ .write = scsi_write_16,
+};
+
+static struct block_device_operations scsi_operations_10 = {
+ .read = scsi_read_10,
+ .write = scsi_write_10,
+};
+
/**
* Initialise SCSI device
*
@@ -250,8 +260,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
scsi_read_capacity_10 ( &scsi->blockdev );
/* Try READ CAPACITY (10), which is a mandatory command, first. */
- scsi->blockdev.read = scsi_read_10;
- scsi->blockdev.write = scsi_write_10;
+ scsi->blockdev.op = &scsi_operations_10;
if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
return rc;
@@ -261,8 +270,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
* mandatory, so we can't just use it straight off.
*/
if ( scsi->blockdev.blocks == 0 ) {
- scsi->blockdev.read = scsi_read_16;
- scsi->blockdev.write = scsi_write_16;
+ scsi->blockdev.op = &scsi_operations_16;
if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
return rc;
}
diff --git a/src/include/gpxe/blockdev.h b/src/include/gpxe/blockdev.h
index 467ed1d9..8222984a 100644
--- a/src/include/gpxe/blockdev.h
+++ b/src/include/gpxe/blockdev.h
@@ -10,12 +10,10 @@
#include <gpxe/uaccess.h>
-/** A block device */
-struct block_device {
- /** Block size */
- size_t blksize;
- /** Total number of blocks */
- uint64_t blocks;
+struct block_device;
+
+/** Block device operations */
+struct block_device_operations {
/**
* Read block
*
@@ -40,4 +38,14 @@ struct block_device {
unsigned long count, userptr_t buffer );
};
+/** A block device */
+struct block_device {
+ /** Block device operations */
+ struct block_device_operations *op;
+ /** Block size */
+ size_t blksize;
+ /** Total number of blocks */
+ uint64_t blocks;
+};
+
#endif /* _GPXE_BLOCKDEV_H */