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 a configuration structure for the binary inputs to the vmm (ramdisk, bios)
[palacios.git] / palacios / include / devices / ide.h
1 /* 
2  *   Copyright (C) 2002  MandrakeSoft S.A.
3  *
4  *     MandrakeSoft S.A.
5  *     43, rue d'Aboukir
6  *     75002 Paris - France
7  *     http://www.linux-mandrake.com/
8  *     http://www.mandrakesoft.com/
9  *
10  *   This library is free software; you can redistribute it and/or
11  *   modify it under the terms of the GNU Lesser General Public
12  *   License as published by the Free Software Foundation; either
13  *   version 2 of the License, or (at your option) any later version.
14  *
15  *   This library is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *   Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  *
24  * Major modifications made for the V3VEE project
25  * 
26  * The V3VEE Project is a joint project between Northwestern University
27  * and the University of New Mexico.  You can find out more at 
28  * http://www.v3vee.org
29  * 
30  * Copyright (c) 2008, Zheng Cui <cuizheng@cs.unm.edu>
31  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
32  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
33  * All rights reserved for original changes
34  * 
35  */
36
37 #ifndef __IDE_H__
38 #define __IDE_H__
39
40
41 #ifdef __V3VEE__
42 #include <palacios/vmm_types.h>
43
44 #ifdef __V3_32BIT__
45 typedef long off_t;
46 typedef sint32_t ssize_t;
47 typedef unsigned int rd_bool;
48 typedef uchar_t Bit8u;
49 typedef ushort_t Bit16u;
50 typedef uint32_t Bit32u;
51 typedef uint64_t Bit64u;
52 #endif
53
54
55 #define MAX_ATA_CHANNEL 4
56
57 typedef enum _sense {
58       SENSE_NONE = 0, 
59       SENSE_NOT_READY = 2, 
60       SENSE_ILLEGAL_REQUEST = 5,
61       SENSE_UNIT_ATTENTION = 6
62 } sense_t ;
63
64 typedef enum _asc {
65       ASC_INV_FIELD_IN_CMD_PACKET = 0x24,
66       ASC_MEDIUM_NOT_PRESENT = 0x3a,
67       ASC_SAVING_PARAMETERS_NOT_SUPPORTED = 0x39,
68       ASC_LOGICAL_BLOCK_OOR = 0x21
69 } asc_t ;
70
71
72
73 typedef struct  {
74   unsigned cylinders;
75   unsigned heads;
76   unsigned sectors;
77 } device_image_t;
78
79
80
81
82 struct interrupt_reason_t {
83   unsigned  c_d : 1; 
84   unsigned  i_o : 1; 
85   unsigned  rel : 1; 
86   unsigned  tag : 5; 
87 };
88
89
90 struct controller_status {
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 };
101
102
103
104
105
106 struct  sense_info_t {
107   sense_t sense_key;
108
109   struct  {
110     Bit8u arr[4];
111   } information;
112
113   struct  {
114     Bit8u arr[4];
115   } specific_inf;
116
117   struct  {
118     Bit8u arr[3];
119   } key_spec;
120
121   Bit8u fruc;
122   Bit8u asc;
123   Bit8u ascq;
124 };
125
126
127 struct  error_recovery_t {
128   unsigned char data[8];
129 };
130
131 struct  cdrom_t {
132   rd_bool ready;
133   rd_bool locked;
134
135   struct cdrom_ops * cd;
136
137   uint32_t capacity;
138   int next_lba;
139   int remaining_blocks;
140
141   struct  currentStruct {
142     struct error_recovery_t error_recovery;
143   } current;
144
145 };
146
147 struct  atapi_t {
148   uint8_t command;
149   int drq_bytes;
150   int total_bytes_remaining;
151 };
152
153
154 typedef enum { IDE_NONE, IDE_DISK, IDE_CDROM } device_type_t;
155
156 struct controller_t  {
157   struct controller_status status;
158   Bit8u    error_register;
159   Bit8u    head_no;
160
161   union {
162     Bit8u    sector_count;
163     struct interrupt_reason_t interrupt_reason;
164   };
165
166
167   Bit8u    sector_no;
168
169   union  {
170     Bit16u   cylinder_no;
171     Bit16u   byte_count;
172   };
173
174   Bit8u    buffer[2048]; 
175   Bit32u   buffer_index;
176   Bit32u   drq_index;
177   Bit8u    current_command;
178   Bit8u    sectors_per_block;
179   Bit8u    lba_mode;
180
181   struct  {
182     rd_bool reset;       // 0=normal, 1=reset controller
183     rd_bool disable_irq;     // 0=allow irq, 1=disable irq
184   } control;
185
186   Bit8u    reset_in_progress;
187   Bit8u    features;
188 };
189
190
191
192
193 struct  drive_t {
194   device_image_t  hard_drive;
195   device_type_t device_type;
196   // 512 byte buffer for ID drive command
197   // These words are stored in native word endian format, as
198   // they are fetched and returned via a return(), so
199   // there's no need to keep them in x86 endian format.
200   Bit16u id_drive[256];
201   
202   struct controller_t controller;
203   struct cdrom_t cdrom;
204   struct sense_info_t sense;
205   struct atapi_t atapi;
206   
207   /* JRL */
208   void * private_data;
209
210   Bit8u model_no[41];
211 };
212
213
214 // FIXME:
215 // For each ATA channel we should have one controller struct
216 // and an array of two drive structs
217 struct  channel_t {
218   struct drive_t drives[2];
219   unsigned drive_select;
220   
221   Bit16u ioaddr1;
222   Bit16u ioaddr2;
223   Bit8u  irq;
224 };
225
226
227
228 struct  ramdisk_t {
229   struct channel_t channels[MAX_ATA_CHANNEL];
230 };
231
232
233
234
235
236
237
238
239
240 #endif // ! __V3VEE__
241
242
243 #endif
244
245 #if 0
246
247 // FLAT MODE
248 // Open a image. Returns non-negative if successful.
249 //int open (const char* pathname);
250
251 // Open an image with specific flags. Returns non-negative if successful.
252 int rd_open (const char* pathname, int flags);
253
254 // Close the image.
255 void rd_close ();
256
257 // Position ourselves. Return the resulting offset from the
258 // beginning of the file.
259 off_t rd_lseek (off_t offset, int whence);
260
261 // Read count bytes to the buffer buf. Return the number of
262 // bytes read (count).
263 ssize_t rd_read (void* buf, size_t count);
264
265 // Write count bytes from buf. Return the number of bytes
266 // written (count).
267 ssize_t rd_write (const void* buf, size_t count);
268
269
270 #endif