Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added a configuration structure for the binary inputs to the vmm (ramdisk, bios)
[palacios.git] / palacios / src / devices / cdrom.c
index 4a52bb4..e77c280 100644 (file)
  */
 
 #include <devices/cdrom.h>
+#include <devices/ide.h>
 #include <palacios/vmm.h>
 
-#ifdef DEBUG_RAMDISK
-#define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
-#else
-#define Ramdisk_Print_CD(_f, _a...)
+#ifndef DEBUG_RAMDISK
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
 #endif
 
 
 
-ulong_t g_ramdiskImage;
-ulong_t s_ramdiskSize;
+struct cdrom_state {
+  uchar_t * image_addr; //memory address
+  ulong_t capacity_B;
+  ulong_t head; //current position
+
+  struct vm_device * ide_dev;
+
+  uchar_t lba;
+};
+
 
-static
-void cdrom_init(struct cdrom_interface * cdrom)
-{
 
-  Ramdisk_Print_CD("[cdrom_init]\n");
-  V3_ASSERT(g_ramdiskImage);
-  cdrom->fd = g_ramdiskImage;
-  PrintDebug("CDIMAGE located at: %x\n", cdrom->fd);
-  cdrom->capacity_B = s_ramdiskSize; 
-  //FIXME:lba
-  cdrom->lba = 1; 
-  return;
-}
 
 /* 
  * Load CD-ROM. Returns false if CD is not ready.
  */
  
-static
-rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
-{
-  Ramdisk_Print_CD("[cdrom_insert]\n");
+static rd_bool cdrom_insert(void * private_data) {
+  PrintDebug("[cdrom_insert]\n");
   return 1;
 }
 
 /*
  * Logically eject the CD.
  */
-static
-void cdrom_eject(struct cdrom_interface *cdrom)
-{
-  Ramdisk_Print_CD("[cdrom_eject]\n");
+static void cdrom_eject(void * private_data) {
+  PrintDebug("[cdrom_eject]\n");
   return;
 }
 
 /*
  * Read CD TOC. Returns false if start track is out of bounds.
  */
-static
-rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8_t* buf, int* length, rd_bool msf, int start_track)
+static rd_bool cdrom_read_toc(void * private_data, uint8_t* buf, int* length, rd_bool msf, int start_track)
 {
-  Ramdisk_Print_CD("[cdrom_read_toc]\n");
+  PrintDebug("[cdrom_read_toc]\n");
   return 1;
 }
 
 /*
  * Return CD-ROM capacity (in 2048 byte frames)
  */
-static
-uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
-{
-  Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
+static uint32_t cdrom_capacity(void * private_data) {
+  struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
+
+  PrintDebug("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
+
   if (cdrom->lba) {
     if (cdrom->capacity_B % 2048) {
-      Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
-      return cdrom->capacity_B/2048 + 1;
+      PrintDebug("\t\t capacity in LBA is %d\n", (cdrom->capacity_B / 2048) + 1);
+      return (cdrom->capacity_B / 2048) + 1;
     } else {
-      Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
-      return cdrom->capacity_B/2048;
+      PrintDebug("\t\t capacity in LBA is %d\n", cdrom->capacity_B / 2048);
+      return cdrom->capacity_B / 2048;
     }
   } else {
+    PrintError("Unsupported CDROM mode in capacity query\n");
     //FIXME CHS mode
     return 0;
   }
@@ -101,42 +94,86 @@ uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
 /*
  * Read a single block from the CD
  */
-static
-void cdrom_read_block(struct cdrom_interface *cdrom, uint8_t* buf, int lba)// __attribute__(regparm(2));
-{
+static void cdrom_read_block(void * private_data, uint8_t * buf, int lba)/* __attribute__(regparm(2)); */ {
+  struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
 
   V3_ASSERT(lba != 0);
   
-  Ramdisk_Print_CD("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->fd);
-  memcpy(buf, (uint8_t *)(cdrom->fd + lba * 2048), 2048);
+  PrintDebug("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->image_addr);
+  memcpy(buf, (uchar_t *)(cdrom->image_addr + lba * 2048), 2048);
   PrintDebug("Returning from read block\n");
-    return;
+  return;
 }
 
+static void set_LBA(void * private_data, uchar_t lba) {
+  struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
+  cdrom->lba = lba;
+}
+
+
 /*
  * Start (spin up) the CD.
  */
-static
-int cdrom_start(struct cdrom_interface *cdrom)
-{
-  Ramdisk_Print_CD("[cdrom_start]\n");
+static int cdrom_start(void * private_data) {
+  PrintDebug("[cdrom_start]\n");
   return 1;
 }
 
 
-void init_cdrom(struct cdrom_interface *cdrom)
-{
-  V3_ASSERT(cdrom != NULL);
+static struct cdrom_ops cd_ops = {
+  .insert_cdrom = cdrom_insert,
+  .eject_cdrom = cdrom_eject,
+  .read_toc = cdrom_read_toc,
+  .capacity = cdrom_capacity,
+  .read_block = cdrom_read_block,
+  .start_cdrom = cdrom_start,
+  .set_LBA = set_LBA,
+};
+
+
+
+
+static int cdrom_device_init(struct vm_device * dev) {
+  struct cdrom_state * cdrom = (struct cdrom_state *)dev->private_data;
+  PrintDebug("[cdrom_init]\n");
+  PrintDebug("CDIMAGE located at: %x\n", cdrom->image_addr);
+
+  //FIXME:lba
+  cdrom->lba = 1; 
+
+  v3_ramdisk_register_cdrom(cdrom->ide_dev, 1, 0, &cd_ops, cdrom);
+
+  return 0;
+}
+
+
+static int cdrom_device_deinit(struct vm_device * dev) {
+  return 0;
+}
+
+static struct vm_device_ops dev_ops = {
+  .init = cdrom_device_init,
+  .deinit = cdrom_device_deinit,
+  .reset = NULL,
+  .start = NULL,
+  .stop = NULL,
+};
+
+struct vm_device *  v3_create_cdrom(struct vm_device * ramdisk_dev, void * ramdisk, uint_t ramdisk_size){
+  struct cdrom_state * cd = (struct cdrom_state *)V3_Malloc(sizeof(struct cdrom_state));
+  V3_ASSERT(cd != NULL);
+
+  memset(cd, 0, sizeof(struct cdrom_state));
+
+  cd->image_addr = (uchar_t *)ramdisk;
+  cd->capacity_B = ramdisk_size;
+  cd->ide_dev = ramdisk_dev;
   
-  cdrom->ops.init = &cdrom_init;
-  cdrom->ops.insert_cdrom = &cdrom_insert;
-  cdrom->ops.eject_cdrom = &cdrom_eject;
-  cdrom->ops.read_toc = &cdrom_read_toc;
-  cdrom->ops.capacity = &cdrom_capacity;
-  cdrom->ops.read_block = &cdrom_read_block;
-  cdrom->ops.start_cdrom = &cdrom_start;
+  PrintDebug("Creating RamDISK CDROM\n");
 
-  return;
+  struct vm_device * cd_dev = create_device("Ram Based CD", &dev_ops, cd);
+
+  return cd_dev;
 }