7 #ifndef __DEVICES_RAMDISK_H_
8 #define __DEVICES_RAMDISK_H_
10 #include <stddef.h> //for off_t in C99
11 #include <sys/types.h> //for size_t
12 #include <geekos/ktypes.h>
13 #include <devices/cdrom.h>
14 #include <palacios/vm_dev.h>
16 #define INDEX_PULSE_CYCLE 10
18 #define MAX_ATA_CHANNEL 4
19 #define RD_LITTLE_ENDIAN
22 #define INTR_REASON_BIT_ERR 0x01
23 #define UNABLE_FIND_TAT_CHANNEL_ERR 0x02
25 #define READ_BUF_GT_512 0x04
29 SENSE_NONE = 0, SENSE_NOT_READY = 2, SENSE_ILLEGAL_REQUEST = 5,
30 SENSE_UNIT_ATTENTION = 6
34 ASC_INV_FIELD_IN_CMD_PACKET = 0x24,
35 ASC_MEDIUM_NOT_PRESENT = 0x3a,
36 ASC_SAVING_PARAMETERS_NOT_SUPPORTED = 0x39,
37 ASC_LOGICAL_BLOCK_OOR = 0x21
42 // Open a image. Returns non-negative if successful.
43 //int open (const char* pathname);
45 // Open an image with specific flags. Returns non-negative if successful.
46 int rd_open (const char* pathname, int flags);
51 // Position ourselves. Return the resulting offset from the
52 // beginning of the file.
53 off_t rd_lseek (off_t offset, int whence);
55 // Read count bytes to the buffer buf. Return the number of
56 // bytes read (count).
57 ssize_t rd_read (void* buf, size_t count);
59 // Write count bytes from buf. Return the number of bytes
61 ssize_t rd_write (const void* buf, size_t count);
81 rd_bool seek_complete ;
83 rd_bool corrected_data ;
85 unsigned int index_pulse_count ;
88 Bit8u error_register ;
93 #ifdef RD_LITTLE_ENDIAN
99 #else /* RD_BIG_ENDIAN */
113 Bit8u buffer[2048]; ;
114 Bit32u buffer_index ;
116 Bit8u current_command ;
117 Bit8u sectors_per_block ;
120 // 0=normal, 1=reset controller
122 // 0=allow irq, 1=disable irq
123 rd_bool disable_irq ;
125 Bit8u reset_in_progress ;
145 struct error_recovery_t {
146 unsigned char data[8] ;
148 // error_recovery_t ();
151 uint16 rd_read_16bit(const uint8* buf); //__attribute__(regparm(1))
152 uint32 rd_read_32bit(const uint8* buf); //__attribute__(regparm(1))
159 struct cdrom_interface *cd ;
163 int remaining_blocks ;
164 struct currentStruct {
165 struct error_recovery_t error_recovery ;
172 int total_bytes_remaining ;
177 IDE_NONE, IDE_DISK, IDE_CDROM
182 // For each ATA channel we should have one controller struct
183 // and an array of two drive structs
186 device_image_t hard_drive ;
187 device_type_t device_type ;
188 // 512 byte buffer for ID drive command
189 // These words are stored in native word endian format, as
190 // they are fetched and returned via a return(), so
191 // there's no need to keep them in x86 endian format.
192 Bit16u id_drive[256] ;
194 struct controller_t controller ;
195 struct cdrom_t cdrom ;
196 struct sense_info_t sense ;
197 struct atapi_t atapi ;
201 unsigned drive_select ;
210 struct ramdisk_ctrl_ops {
211 Bit32u (*init)(struct ramdisk_t *ramdisk,
212 struct vm_device *dev);
213 void (*close)(struct ramdisk_t *ramdisk);
214 void (*reset)(struct ramdisk_t *ramdisk, unsigned type);
218 struct ramdisk_emu_ops {
220 uint_t (*read_port)(ushort_t port,
223 struct vm_device *dev);
225 uint_t (*write_port)(ushort_t port,
228 struct vm_device *dev);
230 uint_t (*read_port_ignore)(ushort_t port,
233 struct vm_device *dev);
235 uint_t (*write_port_ignore)(ushort_t port,
238 struct vm_device *dev);
244 struct channel_t channels[MAX_ATA_CHANNEL] ;
246 struct ramdisk_ctrl_ops cops;
248 struct ramdisk_emu_ops eops;
251 // struct vm_device *dev;
254 struct ramdisk_t * create_ramdisk(void);