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.


Release 1.0
[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
22
23 #include <devices/cdrom.h>
24 #include <devices/ide.h>
25 #include <palacios/vmm.h>
26
27 #ifndef DEBUG_RAMDISK
28 #undef PrintDebug
29 #define PrintDebug(fmt, args...)
30 #endif
31
32
33
34 struct cdrom_state {
35   uchar_t * image_addr; //memory address
36   ulong_t capacity_in_bytes;
37   ulong_t head; //current position
38
39   struct vm_device * ide_dev;
40
41   uchar_t lba;
42 };
43
44
45
46
47 /* 
48  * Load CD-ROM. Returns false if CD is not ready.
49  */
50  
51 static rd_bool cdrom_insert(void * private_data) {
52   PrintDebug("[cdrom_insert]\n");
53   return 1;
54 }
55
56 /*
57  * Logically eject the CD.
58  */
59 static void cdrom_eject(void * private_data) {
60   PrintDebug("[cdrom_eject]\n");
61   return;
62 }
63
64 /*
65  * Read CD TOC. Returns false if start track is out of bounds.
66  */
67 static rd_bool cdrom_read_toc(void * private_data, uint8_t* buf, int* length, rd_bool msf, int start_track)
68 {
69   *length = 4;
70   PrintDebug("[cdrom_read_toc]\n");
71   return 1;
72 }
73
74 /*
75  * Return CD-ROM capacity (in 2048 byte frames)
76  */
77 static uint32_t cdrom_capacity(void * private_data) {
78   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
79
80   PrintDebug("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_in_bytes);
81
82   if (cdrom->lba) {
83     if (cdrom->capacity_in_bytes % 2048) {
84       PrintDebug("\t\t capacity in LBA is %d\n", (cdrom->capacity_in_bytes / 2048) + 1);
85       return (cdrom->capacity_in_bytes / 2048) + 1;
86     } else {
87       PrintDebug("\t\t capacity in LBA is %d\n", cdrom->capacity_in_bytes / 2048);
88       return cdrom->capacity_in_bytes / 2048;
89     }
90   } else {
91     PrintError("Unsupported CDROM mode in capacity query\n");
92     //FIXME CHS mode
93     return 0;
94   }
95 }
96
97 /*
98  * Read a single block from the CD
99  */
100 static void cdrom_read_block(void * private_data, uint8_t * buf, int lba)/* __attribute__(regparm(2)); */ {
101   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
102
103   V3_ASSERT(lba != 0);
104   
105   PrintDebug("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->image_addr);
106   memcpy(buf, (uchar_t *)(cdrom->image_addr + lba * 2048), 2048);
107   //PrintDebug("Returning from read block\n");
108   return;
109 }
110
111 static void set_LBA(void * private_data, uchar_t lba) {
112   struct cdrom_state * cdrom = (struct cdrom_state *)private_data;
113   cdrom->lba = lba;
114 }
115
116
117 /*
118  * Start (spin up) the CD.
119  */
120 static int cdrom_start(void * private_data) {
121   PrintDebug("[cdrom_start]\n");
122   return 1;
123 }
124
125
126 static struct cdrom_ops cd_ops = {
127   .insert_cdrom = cdrom_insert,
128   .eject_cdrom = cdrom_eject,
129   .read_toc = cdrom_read_toc,
130   .capacity = cdrom_capacity,
131   .read_block = cdrom_read_block,
132   .start_cdrom = cdrom_start,
133   .set_LBA = set_LBA,
134 };
135
136
137
138
139 static int cdrom_device_init(struct vm_device * dev) {
140   struct cdrom_state * cdrom = (struct cdrom_state *)dev->private_data;
141   PrintDebug("[cdrom_init]\n");
142   PrintDebug("CDIMAGE located at: %x\n", cdrom->image_addr);
143
144   //FIXME:lba
145   cdrom->lba = 1; 
146
147   v3_ramdisk_register_cdrom(cdrom->ide_dev, 1, 0, &cd_ops, cdrom);
148
149   return 0;
150 }
151
152
153 static int cdrom_device_deinit(struct vm_device * dev) {
154   return 0;
155 }
156
157 static struct vm_device_ops dev_ops = {
158   .init = cdrom_device_init,
159   .deinit = cdrom_device_deinit,
160   .reset = NULL,
161   .start = NULL,
162   .stop = NULL,
163 };
164
165 struct vm_device *  v3_create_cdrom(struct vm_device * ramdisk_dev, void * ramdisk, uint_t ramdisk_size){
166   struct cdrom_state * cd = (struct cdrom_state *)V3_Malloc(sizeof(struct cdrom_state));
167   V3_ASSERT(cd != NULL);
168
169   memset(cd, 0, sizeof(struct cdrom_state));
170
171   cd->image_addr = (uchar_t *)V3_VAddr(ramdisk);
172   cd->capacity_in_bytes = ramdisk_size;
173   cd->ide_dev = ramdisk_dev;
174   
175   PrintDebug("Creating RamDISK CDROM\n");
176
177   struct vm_device * cd_dev = v3_create_device("Ram Based CD", &dev_ops, cd);
178
179   return cd_dev;
180 }
181
182