From: Jack Lange Date: Wed, 18 Mar 2009 21:33:45 +0000 (-0500) Subject: added RAM based CD, updates to device registration X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6fe0528310bec884ed00c8d97b45d18120a32e3f added RAM based CD, updates to device registration --- diff --git a/palacios/build/Makefile b/palacios/build/Makefile index ebd751b..6d62c0b 100644 --- a/palacios/build/Makefile +++ b/palacios/build/Makefile @@ -321,7 +321,7 @@ DEVICES_OBJS := \ devices/pci.o \ devices/para_net.o \ devices/ide.o \ - + devices/ram_cd.o \ # devices/cdrom.o \ # devices/ramdisk.o \ diff --git a/palacios/include/devices/ide.h b/palacios/include/devices/ide.h index ee6f2c5..a5b6ea0 100644 --- a/palacios/include/devices/ide.h +++ b/palacios/include/devices/ide.h @@ -24,6 +24,38 @@ #include +typedef enum {IDE_DISK, IDE_CDROM, IDE_NONE} v3_ide_dev_type_t; + +struct v3_ide_cd_ops { + uint32_t (*get_capacity)(void * private_data); + // Reads always operate on 2048 byte blocks + int (*read_block)(uchar_t * buf, int offset, void * private_data); + +}; + + +struct v3_ide_hd_ops { + + +}; + + +int v3_ide_register_cdrom(struct vm_device * ide, + uint_t bus_num, + uint_t drive_num, + char * drive_name, + struct v3_ide_cd_ops * ops, + void * private_data); + +int v3_ide_register_harddisk(struct vm_device * ide, + uint_t bus_num, + uint_t drive_num, + char * drive_name, + struct v3_ide_hd_ops * ops, + void * private_data); + + + struct vm_device * v3_create_ide(); diff --git a/palacios/src/devices/ide-types.h b/palacios/src/devices/ide-types.h index 4dbdc1d..f881157 100644 --- a/palacios/src/devices/ide-types.h +++ b/palacios/src/devices/ide-types.h @@ -78,7 +78,7 @@ struct ide_ctrl_reg { uint8_t val; struct { uint_t rsvd0 : 1; - uint_t irq_enable : 1; + uint_t irq_disable : 1; uint_t soft_reset : 1; uint_t rsvd1 : 5; } __attribute__((packed)); diff --git a/palacios/src/devices/ide.c b/palacios/src/devices/ide.c index d0adb63..87e10c3 100644 --- a/palacios/src/devices/ide.c +++ b/palacios/src/devices/ide.c @@ -46,11 +46,11 @@ #define SEC_ADDR_REG_PORT 0x377 -typedef enum {IDE_DISK, IDE_CDROM, IDE_NONE} ide_dev_type_t; + static const char * ide_dev_type_strs[] = {"HARDDISK", "CDROM", "NONE"}; -static inline const char * device_type_to_str(ide_dev_type_t type) { +static inline const char * device_type_to_str(v3_ide_dev_type_t type) { if (type > 2) { return NULL; } @@ -65,9 +65,17 @@ static inline const char * device_type_to_str(ide_dev_type_t type) { struct ide_drive { // Command Registers - ide_dev_type_t drive_type; + v3_ide_dev_type_t drive_type; + + union { + struct v3_ide_cd_ops * cd_ops; + struct v3_ide_hd_ops * hd_ops; + }; + char model[41]; + void * private_data; + uint8_t sector_count; // 0x1f2,0x172 uint8_t sector_num; // 0x1f3,0x173 union { @@ -162,7 +170,7 @@ static void channel_reset(struct ide_channel * channel) { // clear commands channel->command_reg = 0x00; - channel->ctrl_reg.irq_enable = 0; + channel->ctrl_reg.irq_disable = 0; } static void channel_reset_complete(struct ide_channel * channel) { @@ -365,9 +373,11 @@ static void init_drive(struct ide_drive * drive) { drive->sector_num = 0x01; drive->cylinder = 0x0000; - drive->drive_type = IDE_NONE; + memset(drive->model, 0, sizeof(drive->model)); + + drive->cd_ops = NULL; } static void init_channel(struct ide_channel * channel) { @@ -482,3 +492,74 @@ struct vm_device * v3_create_ide() { return device; } + + + + + +int v3_ide_register_cdrom(struct vm_device * ide_dev, + uint_t bus_num, + uint_t drive_num, + char * dev_name, + struct v3_ide_cd_ops * ops, + void * private_data) { + + struct ide_internal * ide = (struct ide_internal *)(ide_dev->private_data); + struct ide_channel * channel = NULL; + struct ide_drive * drive = NULL; + + V3_ASSERT((bus_num >= 0) && (bus_num < 2)); + V3_ASSERT((drive_num >= 0) && (drive_num < 2)); + + channel = &(ide->channels[bus_num]); + drive = &(channel->drives[drive_num]); + + if (drive->drive_type != IDE_NONE) { + PrintError("Device slot (bus=%d, drive=%d) already occupied\n", bus_num, drive_num); + return -1; + } + + strncpy(drive->model, dev_name, sizeof(drive->model) - 1); + + drive->drive_type = IDE_CDROM; + + drive->cd_ops = ops; + + drive->private_data = private_data; + + return 0; +} + + +int v3_ide_register_harddisk(struct vm_device * ide_dev, + uint_t bus_num, + uint_t drive_num, + char * dev_name, + struct v3_ide_hd_ops * ops, + void * private_data) { + + struct ide_internal * ide = (struct ide_internal *)(ide_dev->private_data); + struct ide_channel * channel = NULL; + struct ide_drive * drive = NULL; + + V3_ASSERT((bus_num >= 0) && (bus_num < 2)); + V3_ASSERT((drive_num >= 0) && (drive_num < 2)); + + channel = &(ide->channels[bus_num]); + drive = &(channel->drives[drive_num]); + + if (drive->drive_type != IDE_NONE) { + PrintError("Device slot (bus=%d, drive=%d) already occupied\n", bus_num, drive_num); + return -1; + } + + strncpy(drive->model, dev_name, sizeof(drive->model) - 1); + + drive->drive_type = IDE_DISK; + + drive->hd_ops = ops; + + drive->private_data = private_data; + + return 0; +}