3 * This file is part of the Palacios Virtual Machine Monitor developed
4 * by the V3VEE Project with funding from the United States National
5 * Science Foundation and the Department of Energy.
7 * The V3VEE Project is a joint project between Northwestern University
8 * and the University of New Mexico. You can find out more at
11 * Copyright (c) 2008, Zheng Cui <cuizheng@cs.unm.edu>
12 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
13 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
14 * All rights reserved.
16 * Author: Zheng Cui <cuizheng@cs.unm.edu>
18 * This is free software. You are permitted to use,
19 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
22 #include <devices/cdrom.h>
23 #include <palacios/vmm.h>
26 #define Ramdisk_Print_CD(_f, _a...) PrintTrace("cdrom.c(%d) "_f, __LINE__, ## _a)
28 #define Ramdisk_Print_CD(_f, _a...)
32 extern ulong_t g_ramdiskImage;
33 extern ulong_t s_ramdiskSize;
36 void cdrom_init(struct cdrom_interface * cdrom)
39 Ramdisk_Print_CD("[cdrom_init]\n");
40 V3_ASSERT(g_ramdiskImage);
41 cdrom->fd = g_ramdiskImage;
42 cdrom->capacity_B = s_ramdiskSize;
49 * Load CD-ROM. Returns false if CD is not ready.
53 rd_bool cdrom_insert(struct cdrom_interface * cdrom, char *dev /*= NULL*/)
55 Ramdisk_Print_CD("[cdrom_insert]\n");
60 * Logically eject the CD.
63 void cdrom_eject(struct cdrom_interface *cdrom)
65 Ramdisk_Print_CD("[cdrom_eject]\n");
70 * Read CD TOC. Returns false if start track is out of bounds.
73 rd_bool cdrom_read_toc(struct cdrom_interface *cdrom, uint8* buf, int* length, rd_bool msf, int start_track)
75 Ramdisk_Print_CD("[cdrom_read_toc]\n");
80 * Return CD-ROM capacity (in 2048 byte frames)
83 uint32 cdrom_capacity(struct cdrom_interface *cdrom)
85 Ramdisk_Print_CD("[cdrom_capacity] s_ramdiskSize = %d\n", cdrom->capacity_B);
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;
91 Ramdisk_Print_CD("\t\t capacity in LBA is %d\n", cdrom->capacity_B/2048);
92 return cdrom->capacity_B/2048;
101 * Read a single block from the CD
104 void cdrom_read_block(struct cdrom_interface *cdrom, uint8* buf, int lba)// __attribute__(regparm(2));
109 Ramdisk_Print_CD("[cdrom_read_block] lba = %d\n", lba);
110 memcpy(buf, (uint8 *)(cdrom->fd + lba*2048), 2048);
115 * Start (spin up) the CD.
118 int cdrom_start(struct cdrom_interface *cdrom)
120 Ramdisk_Print_CD("[cdrom_start]\n");
125 void init_cdrom(struct cdrom_interface *cdrom)
127 V3_ASSERT(cdrom != NULL);
129 cdrom->ops.init = &cdrom_init;
130 cdrom->ops.insert_cdrom = &cdrom_insert;
131 cdrom->ops.eject_cdrom = &cdrom_eject;
132 cdrom->ops.read_toc = &cdrom_read_toc;
133 cdrom->ops.capacity = &cdrom_capacity;
134 cdrom->ops.read_block = &cdrom_read_block;
135 cdrom->ops.start_cdrom = &cdrom_start;