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 / include / devices / ramdisk.h
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, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Zheng Cui <cuizheng@cs.unm.edu> 
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __DEVICES_RAMDISK_H_
21 #define __DEVICES_RAMDISK_H_
22
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>
28
29 #define INDEX_PULSE_CYCLE 10
30
31 #define MAX_ATA_CHANNEL 4
32 #define RD_LITTLE_ENDIAN
33
34
35 #define INTR_REASON_BIT_ERR           0x01
36 #define UNABLE_FIND_TAT_CHANNEL_ERR   0x02
37 #define DRQ_ERR                       0x03
38 #define READ_BUF_GT_512               0x04
39
40
41 typedef enum _sense {
42       SENSE_NONE = 0, SENSE_NOT_READY = 2, SENSE_ILLEGAL_REQUEST = 5,
43       SENSE_UNIT_ATTENTION = 6
44 } sense_t ;
45
46 typedef enum _asc {
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
51 } asc_t ;
52
53
54 // FLAT MODE
55 // Open a image. Returns non-negative if successful.
56 //int open (const char* pathname);
57
58 // Open an image with specific flags. Returns non-negative if successful.
59 int rd_open (const char* pathname, int flags);
60
61 // Close the image.
62 void rd_close ();
63
64 // Position ourselves. Return the resulting offset from the
65 // beginning of the file.
66 off_t rd_lseek (off_t offset, int whence);
67
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);
71
72 // Write count bytes from buf. Return the number of bytes
73 // written (count).
74 ssize_t rd_write (const void* buf, size_t count);
75
76
77 typedef struct  {
78
79       unsigned cylinders               ;
80       unsigned heads                   ;
81       unsigned sectors                 ;
82
83   //iso file descriptor
84       int fd                           ;
85 } device_image_t;
86
87
88
89 struct  controller_t {
90   struct  {
91     rd_bool busy                       ;
92     rd_bool drive_ready                ;
93     rd_bool write_fault                ;
94     rd_bool seek_complete              ;
95     rd_bool drq                        ;
96     rd_bool corrected_data             ;
97     rd_bool index_pulse                ;
98     unsigned int index_pulse_count     ;
99     rd_bool err                        ;
100     } status;
101   Bit8u    error_register              ;
102   Bit8u    head_no                     ;
103   union  {
104     Bit8u    sector_count              ;
105     struct  {
106 #ifdef RD_LITTLE_ENDIAN
107       unsigned  c_d : 1; 
108       unsigned  i_o : 1; 
109       unsigned  rel : 1; 
110       unsigned  tag : 5; 
111
112 #else  /* RD_BIG_ENDIAN */
113       unsigned tag : 5;
114       unsigned rel : 1;
115       unsigned i_o : 1;
116       unsigned c_d : 1;
117 #endif
118       
119     } interrupt_reason;
120   };
121   Bit8u    sector_no                   ;
122   union  {
123     Bit16u   cylinder_no               ;
124     Bit16u   byte_count                ;
125   };
126   Bit8u    buffer[2048];               ; 
127   Bit32u   buffer_index                ;
128   Bit32u   drq_index                   ;
129   Bit8u    current_command             ;
130   Bit8u    sectors_per_block           ;
131   Bit8u    lba_mode                    ;
132   struct  {
133     // 0=normal, 1=reset controller
134     rd_bool reset                      ;       
135     // 0=allow irq, 1=disable irq
136     rd_bool disable_irq                ; 
137     } control;
138   Bit8u    reset_in_progress           ;
139   Bit8u    features                    ;
140   };
141
142 struct  sense_info_t{
143   sense_t sense_key                    ;
144   struct  {
145     Bit8u arr[4]                       ;
146   } information;
147   struct  {
148     Bit8u arr[4]                       ;
149   } specific_inf;
150   struct  {
151     Bit8u arr[3]                       ;
152   } key_spec;
153   Bit8u fruc                           ;
154   Bit8u asc                            ;
155   Bit8u ascq                           ;
156 };
157
158 struct  error_recovery_t {
159   unsigned char data[8]                ;
160
161   //  error_recovery_t ();
162 };
163
164 uint16 rd_read_16bit(const uint8* buf); //__attribute__(regparm(1))
165 uint32 rd_read_32bit(const uint8* buf); //__attribute__(regparm(1))
166
167 struct  cdrom_t {
168   rd_bool ready                                      ;
169   rd_bool locked                                     ;
170
171
172   struct cdrom_interface *cd                         ;
173
174   uint32 capacity                                    ;
175   int next_lba                                       ;
176   int remaining_blocks                               ;
177   struct  currentStruct {
178     struct error_recovery_t error_recovery           ;
179   } current;
180 };
181
182 struct  atapi_t {
183   uint8 command                                      ;
184   int drq_bytes                                      ;
185   int total_bytes_remaining                          ;
186 };
187
188
189 typedef enum {
190       IDE_NONE, IDE_DISK, IDE_CDROM
191 } device_type_t ;
192
193
194   // FIXME:
195   // For each ATA channel we should have one controller struct
196   // and an array of two drive structs
197 struct  channel_t {
198     struct  drive_t {
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]                           ;
206
207       struct controller_t controller                 ;
208       struct cdrom_t cdrom                           ;
209       struct sense_info_t sense                      ;
210       struct atapi_t atapi                           ;
211
212       Bit8u model_no[41]                             ;
213       } drives[2];
214     unsigned drive_select                            ;
215
216     Bit16u ioaddr1                                   ;
217     Bit16u ioaddr2                                   ;
218     Bit8u  irq                                       ;
219 };
220
221 struct ramdisk_t;
222
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);
228
229 };
230
231 struct ramdisk_emu_ops {
232
233   uint_t (*read_port)(ushort_t port,
234                       void *src,
235                       uint_t length,
236                       struct vm_device *dev);
237
238   uint_t (*write_port)(ushort_t port,
239                        void *src,
240                        uint_t length,
241                        struct vm_device *dev);
242
243   uint_t (*read_port_ignore)(ushort_t port,
244                              void *src,
245                              uint_t length,
246                              struct vm_device *dev);
247
248   uint_t (*write_port_ignore)(ushort_t port,
249                               void *src,
250                               uint_t length,
251                               struct vm_device *dev);
252 };
253
254
255 struct  ramdisk_t {
256   
257   struct channel_t channels[MAX_ATA_CHANNEL]         ;
258
259   struct ramdisk_ctrl_ops cops;
260
261   struct ramdisk_emu_ops eops;
262
263   void *private_data                                 ;
264   //  struct vm_device *dev;
265 };
266
267 struct ramdisk_t * create_ramdisk(void);
268
269 #endif