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
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Zheng Cui <cuizheng@cs.unm.edu> 
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Zheng Cui <cuizheng@cs.unm.edu> 
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #include <devices/cdrom.h>
22 #include <devices/ide.h>
23 #include <palacios/vmm.h>
24
25 #ifndef DEBUG_RAMDISK
26 #undef PrintDebug
27 #define PrintDebug(fmt, args...)
28 #endif
29
30
31
32 struct cdrom_state {
33   uchar_t * image_addr; //memory address
34   ulong_t capacity_B;
35   ulong_t head; //current position
36
37   struct vm_device * ide_dev;
38
39   uchar_t lba;
40 };
41
42
43
44
45 /* 
46  * Load CD-ROM. Returns false if CD is not ready.
47  */
48  
49 static rd_bool cdrom_insert(void * private_data) {
50   PrintDebug("[cdrom_insert]\n");
51   return 1;
52 }
53
54 /*
55  * Logically eject the CD.
56  */
57 static void cdrom_eject(void * private_data) {
58   PrintDebug("[cdrom_eject]\n");
59   return;
60 }
61
62 /*
63  * Read CD TOC. Returns false if start track is out of bounds.
64  */
65 static rd_bool cdrom_read_toc(void * private_data, uint8_t* buf, int* length, rd_bool msf, int start_track)
66 {
67   PrintDebug("[cdrom_read_toc]\n");
68   return 1;
69 }
70
71 /*
72  * Return CD-ROM capacity (in 2048 byte frames)
73  */
74 static uint32_t cdrom_capacity(void * private_data) {
75   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
76
77   PrintDebug("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
78
79   if (cdrom->lba) {
80     if (cdrom->capacity_B % 2048) {
81       PrintDebug("\t\t capacity in LBA is %d\n", (cdrom->capacity_B / 2048) + 1);
82       return (cdrom->capacity_B / 2048) + 1;
83     } else {
84       PrintDebug("\t\t capacity in LBA is %d\n", cdrom->capacity_B / 2048);
85       return cdrom->capacity_B / 2048;
86     }
87   } else {
88     PrintError("Unsupported CDROM mode in capacity query\n");
89     //FIXME CHS mode
90     return 0;
91   }
92 }
93
94 /*
95  * Read a single block from the CD
96  */
97 static void cdrom_read_block(void * private_data, uint8_t * buf, int lba)/* __attribute__(regparm(2)); */ {
98   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
99
100   V3_ASSERT(lba != 0);
101   
102   PrintDebug("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->image_addr);
103   memcpy(buf, (uchar_t *)(cdrom->image_addr + lba * 2048), 2048);
104   PrintDebug("Returning from read block\n");
105   return;
106 }
107
108 static void set_LBA(void * private_data, uchar_t lba) {
109   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
110   cdrom->lba = lba;
111 }
112
113
114 /*
115  * Start (spin up) the CD.
116  */
117 static int cdrom_start(void * private_data) {
118   PrintDebug("[cdrom_start]\n");
119   return 1;
120 }
121
122
123 static struct cdrom_ops cd_ops = {
124   .insert_cdrom = cdrom_insert,
125   .eject_cdrom = cdrom_eject,
126   .read_toc = cdrom_read_toc,
127   .capacity = cdrom_capacity,
128   .read_block = cdrom_read_block,
129   .start_cdrom = cdrom_start,
130   .set_LBA = set_LBA,
131 };
132
133
134
135
136 static int cdrom_device_init(struct vm_device * dev) {
137   struct cdrom_state * cdrom = (struct cdrom_state *)dev->private_data;
138   PrintDebug("[cdrom_init]\n");
139   PrintDebug("CDIMAGE located at: %x\n", cdrom->image_addr);
140
141   //FIXME:lba
142   cdrom->lba = 1; 
143
144   v3_ramdisk_register_cdrom(cdrom->ide_dev, 1, 0, &cd_ops, cdrom);
145
146   return 0;
147 }
148
149
150 static int cdrom_device_deinit(struct vm_device * dev) {
151   return 0;
152 }
153
154 static struct vm_device_ops dev_ops = {
155   .init = cdrom_device_init,
156   .deinit = cdrom_device_deinit,
157   .reset = NULL,
158   .start = NULL,
159   .stop = NULL,
160 };
161
162 struct vm_device *  v3_create_cdrom(struct vm_device * ramdisk_dev, void * ramdisk, uint_t ramdisk_size){
163   struct cdrom_state * cd = (struct cdrom_state *)V3_Malloc(sizeof(struct cdrom_state));
164   V3_ASSERT(cd != NULL);
165
166   memset(cd, 0, sizeof(struct cdrom_state));
167
168   cd->image_addr = (uchar_t *)ramdisk;
169   cd->capacity_B = ramdisk_size;
170   cd->ide_dev = ramdisk_dev;
171   
172   PrintDebug("Creating RamDISK CDROM\n");
173
174   struct vm_device * cd_dev = create_device("Ram Based CD", &dev_ops, cd);
175
176   return cd_dev;
177 }
178
179