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 new copyright and license
[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 <palacios/vmm.h>
23
24 #ifdef DEBUG_RAMDISK
25 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
26 #else
27 #define Ramdisk_Print_CD(_f, _a...)
28 #endif
29
30
31 extern ulong_t g_ramdiskImage;
32 extern ulong_t s_ramdiskSize;
33
34 static
35 void cdrom_init(struct cdrom_interface * cdrom)
36 {
37
38   Ramdisk_Print_CD("[cdrom_init]\n");
39   V3_ASSERT(g_ramdiskImage);
40   cdrom->fd = g_ramdiskImage;
41   PrintDebug("CDIMAGE located at: %x\n", cdrom->fd);
42   cdrom->capacity_B = s_ramdiskSize; 
43   //FIXME:lba
44   cdrom->lba = 1; 
45   return;
46 }
47
48 /* 
49  * Load CD-ROM. Returns false if CD is not ready.
50  */
51  
52 static
53 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
54 {
55   Ramdisk_Print_CD("[cdrom_insert]\n");
56   return 1;
57 }
58
59 /*
60  * Logically eject the CD.
61  */
62 static
63 void cdrom_eject(struct cdrom_interface *cdrom)
64 {
65   Ramdisk_Print_CD("[cdrom_eject]\n");
66   return;
67 }
68
69 /*
70  * Read CD TOC. Returns false if start track is out of bounds.
71  */
72 static
73 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8_t* buf, int* length, rd_bool msf, int start_track)
74 {
75   Ramdisk_Print_CD("[cdrom_read_toc]\n");
76   return 1;
77 }
78
79 /*
80  * Return CD-ROM capacity (in 2048 byte frames)
81  */
82 static
83 uint32_t cdrom_capacity(struct cdrom_interface *cdrom)
84 {
85   Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
86   if (cdrom->lba) {
87     if (cdrom->capacity_B % 2048) {
88       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048 + 1);
89       return cdrom->capacity_B/2048 + 1;
90     } else {
91       Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
92       return cdrom->capacity_B/2048;
93     }
94   } else {
95     //FIXME CHS mode
96     return 0;
97   }
98 }
99
100 /*
101  * Read a single block from the CD
102  */
103 static
104 void cdrom_read_block(struct cdrom_interface *cdrom, uint8_t* buf, int lba)// __attribute__(regparm(2));
105 {
106
107   V3_ASSERT(lba != 0);
108   
109   Ramdisk_Print_CD("[cdrom_read_block] lba = %d (cdrom_image_start=%x)\n", lba, cdrom->fd);
110   memcpy(buf, (uint8_t *)(cdrom->fd + lba * 2048), 2048);
111   PrintDebug("Returning from read block\n");
112     return;
113 }
114
115 /*
116  * Start (spin up) the CD.
117  */
118 static
119 int cdrom_start(struct cdrom_interface *cdrom)
120 {
121   Ramdisk_Print_CD("[cdrom_start]\n");
122   return 1;
123 }
124
125
126 void init_cdrom(struct cdrom_interface *cdrom)
127 {
128   V3_ASSERT(cdrom != NULL);
129   
130   cdrom->ops.init = &cdrom_init;
131   cdrom->ops.insert_cdrom = &cdrom_insert;
132   cdrom->ops.eject_cdrom = &cdrom_eject;
133   cdrom->ops.read_toc = &cdrom_read_toc;
134   cdrom->ops.capacity = &cdrom_capacity;
135   cdrom->ops.read_block = &cdrom_read_block;
136   cdrom->ops.start_cdrom = &cdrom_start;
137
138   return;
139 }
140