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.


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