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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Zheng Cui <cuizheng@cs.unm.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Zheng Cui <cuizheng@cs.unm.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #ifndef __DEVICES_RAMDISK_H_
21 #define __DEVICES_RAMDISK_H_
23 #include <stddef.h> //for off_t in C99
24 #include <sys/types.h> //for size_t
25 #include <geekos/ktypes.h>
26 #include <devices/cdrom.h>
27 #include <palacios/vm_dev.h>
29 #define INDEX_PULSE_CYCLE 10
31 #define MAX_ATA_CHANNEL 4
32 #define RD_LITTLE_ENDIAN
35 #define INTR_REASON_BIT_ERR 0x01
36 #define UNABLE_FIND_TAT_CHANNEL_ERR 0x02
38 #define READ_BUF_GT_512 0x04
42 SENSE_NONE = 0, SENSE_NOT_READY = 2, SENSE_ILLEGAL_REQUEST = 5,
43 SENSE_UNIT_ATTENTION = 6
47 ASC_INV_FIELD_IN_CMD_PACKET = 0x24,
48 ASC_MEDIUM_NOT_PRESENT = 0x3a,
49 ASC_SAVING_PARAMETERS_NOT_SUPPORTED = 0x39,
50 ASC_LOGICAL_BLOCK_OOR = 0x21
55 // Open a image. Returns non-negative if successful.
56 //int open (const char* pathname);
58 // Open an image with specific flags. Returns non-negative if successful.
59 int rd_open (const char* pathname, int flags);
64 // Position ourselves. Return the resulting offset from the
65 // beginning of the file.
66 off_t rd_lseek (off_t offset, int whence);
68 // Read count bytes to the buffer buf. Return the number of
69 // bytes read (count).
70 ssize_t rd_read (void* buf, size_t count);
72 // Write count bytes from buf. Return the number of bytes
74 ssize_t rd_write (const void* buf, size_t count);
94 rd_bool seek_complete ;
96 rd_bool corrected_data ;
98 unsigned int index_pulse_count ;
101 Bit8u error_register ;
106 #ifdef RD_LITTLE_ENDIAN
112 #else /* RD_BIG_ENDIAN */
126 Bit8u buffer[2048]; ;
127 Bit32u buffer_index ;
129 Bit8u current_command ;
130 Bit8u sectors_per_block ;
133 // 0=normal, 1=reset controller
135 // 0=allow irq, 1=disable irq
136 rd_bool disable_irq ;
138 Bit8u reset_in_progress ;
158 struct error_recovery_t {
159 unsigned char data[8] ;
161 // error_recovery_t ();
164 uint16 rd_read_16bit(const uint8* buf); //__attribute__(regparm(1))
165 uint32 rd_read_32bit(const uint8* buf); //__attribute__(regparm(1))
172 struct cdrom_interface *cd ;
176 int remaining_blocks ;
177 struct currentStruct {
178 struct error_recovery_t error_recovery ;
185 int total_bytes_remaining ;
190 IDE_NONE, IDE_DISK, IDE_CDROM
195 // For each ATA channel we should have one controller struct
196 // and an array of two drive structs
199 device_image_t hard_drive ;
200 device_type_t device_type ;
201 // 512 byte buffer for ID drive command
202 // These words are stored in native word endian format, as
203 // they are fetched and returned via a return(), so
204 // there's no need to keep them in x86 endian format.
205 Bit16u id_drive[256] ;
207 struct controller_t controller ;
208 struct cdrom_t cdrom ;
209 struct sense_info_t sense ;
210 struct atapi_t atapi ;
214 unsigned drive_select ;
223 struct ramdisk_ctrl_ops {
224 Bit32u (*init)(struct ramdisk_t *ramdisk,
225 struct vm_device *dev);
226 void (*close)(struct ramdisk_t *ramdisk);
227 void (*reset)(struct ramdisk_t *ramdisk, unsigned type);
231 struct ramdisk_emu_ops {
233 uint_t (*read_port)(ushort_t port,
236 struct vm_device *dev);
238 uint_t (*write_port)(ushort_t port,
241 struct vm_device *dev);
243 uint_t (*read_port_ignore)(ushort_t port,
246 struct vm_device *dev);
248 uint_t (*write_port_ignore)(ushort_t port,
251 struct vm_device *dev);
257 struct channel_t channels[MAX_ATA_CHANNEL] ;
259 struct ramdisk_ctrl_ops cops;
261 struct ramdisk_emu_ops eops;
264 // struct vm_device *dev;
267 struct ramdisk_t * create_ramdisk(void);