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.


clean up
[palacios.git] / palacios / src / devices / cdrom.c
1 /*
2  * Zheng Cui
3  * cuizheng@cs.unm.edu
4  * July 2008
5  */
6
7
8 #include <devices/cdrom.h>
9 #include <palacios/vmm.h>
10
11 #ifdef DEBUG_RAMDISK
12 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
13 #else
14 #define Ramdisk_Print_CD(_f, _a...)
15 #endif
16
17
18 extern ulong_t g_ramdiskImage;
19 extern ulong_t s_ramdiskSize;
20
21 static
22 void cdrom_init(struct cdrom_interface * cdrom)
23 {
24
25   Ramdisk_Print_CD("[cdrom_init]\n");
26   V3_ASSERT(g_ramdiskImage);
27   cdrom->fd = g_ramdiskImage;
28   cdrom->capacity_B = s_ramdiskSize; 
29   //FIXME:lba
30   cdrom->lba = 1; 
31   return;
32 }
33
34 /* 
35  * Load CD-ROM. Returns false if CD is not ready.
36  */
37  
38 static
39 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
40 {
41   Ramdisk_Print_CD("[cdrom_insert]\n");
42   return 1;
43 }
44
45 /*
46  * Logically eject the CD.
47  */
48 static
49 void cdrom_eject(struct cdrom_interface *cdrom)
50 {
51   Ramdisk_Print_CD("[cdrom_eject]\n");
52   return;
53 }
54
55 /*
56  * Read CD TOC. Returns false if start track is out of bounds.
57  */
58 static
59 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8* buf, int* length, rd_bool msf, int start_track)
60 {
61   Ramdisk_Print_CD("[cdrom_read_toc]\n");
62   return 1;
63 }
64
65 /*
66  * Return CD-ROM capacity (in 2048 byte frames)
67  */
68 static
69 uint32 cdrom_capacity(struct cdrom_interface *cdrom)
70 {
71   Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
72   if (cdrom->lba) {
73     if (cdrom->capacity_B % 2048) {
74       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
75       return cdrom->capacity_B/2048 + 1;
76     } else {
77       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
78       return cdrom->capacity_B/2048;
79     }
80   } else {
81     //FIXME CHS mode
82     return 0;
83   }
84 }
85
86 /*
87  * Read a single block from the CD
88  */
89 static
90 void cdrom_read_block(struct cdrom_interface *cdrom, uint8* buf, int lba)// __attribute__(regparm(2));
91 {
92
93   V3_ASSERT(lba != 0);
94     
95   Ramdisk_Print_CD("[cdrom_read_block] lba = %d\n", lba);
96   memcpy(buf, (uint8 *)(cdrom->fd + lba*2048), 2048);
97     return;
98 }
99
100 /*
101  * Start (spin up) the CD.
102  */
103 static
104 int cdrom_start(struct cdrom_interface *cdrom)
105 {
106   Ramdisk_Print_CD("[cdrom_start]\n");
107   return 1;
108 }
109
110
111 void init_cdrom(struct cdrom_interface *cdrom)
112 {
113   V3_ASSERT(cdrom != NULL);
114   
115   cdrom->ops.init = &cdrom_init;
116   cdrom->ops.insert_cdrom = &cdrom_insert;
117   cdrom->ops.eject_cdrom = &cdrom_eject;
118   cdrom->ops.read_toc = &cdrom_read_toc;
119   cdrom->ops.capacity = &cdrom_capacity;
120   cdrom->ops.read_block = &cdrom_read_block;
121   cdrom->ops.start_cdrom = &cdrom_start;
122
123   return;
124 }
125