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.


updated ramdisk with initial pci placeholders
[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 __DEVICES_IDE_H__
38 #define __DEVICES_IDE_H__
39
40 #ifdef __V3VEE__
41
42
43 #include <palacios/vmm_types.h>
44 #include <palacios/vm_dev.h>
45
46 typedef long off_t;
47 typedef sint32_t ssize_t;
48 typedef unsigned int rd_bool;
49 typedef uchar_t Bit8u;
50 typedef ushort_t Bit16u;
51 typedef uint32_t Bit32u;
52 typedef uint64_t Bit64u;
53
54
55
56 #define MAX_ATA_CHANNEL 4
57
58 typedef enum _sense {
59     SENSE_NONE = 0, 
60     SENSE_NOT_READY = 2, 
61     SENSE_ILLEGAL_REQUEST = 5,
62     SENSE_UNIT_ATTENTION = 6
63 } sense_t ;
64
65 typedef enum _asc {
66     ASC_INV_FIELD_IN_CMD_PACKET = 0x24,
67     ASC_MEDIUM_NOT_PRESENT = 0x3a,
68     ASC_SAVING_PARAMETERS_NOT_SUPPORTED = 0x39,
69     ASC_LOGICAL_BLOCK_OOR = 0x21
70 } asc_t ;
71
72
73
74 typedef struct  {
75     unsigned cylinders;
76     unsigned heads;
77     unsigned sectors;
78 } device_image_t;
79
80
81
82
83 struct interrupt_reason_t {
84     unsigned  c_d : 1; 
85     unsigned  i_o : 1; 
86     unsigned  rel : 1; 
87     unsigned  tag : 5; 
88 };
89
90
91 struct controller_status {
92     rd_bool busy;
93     rd_bool drive_ready;
94     rd_bool write_fault;
95     rd_bool seek_complete;
96     rd_bool drq;
97     rd_bool corrected_data;
98     rd_bool index_pulse;
99     unsigned int index_pulse_count;
100     rd_bool err;
101 };
102
103
104
105
106
107 struct  sense_info_t {
108     sense_t sense_key;
109
110     struct  {
111         Bit8u arr[4];
112     } information;
113
114     struct  {
115         Bit8u arr[4];
116     } specific_inf;
117
118     struct  {
119         Bit8u arr[3];
120     } key_spec;
121
122     Bit8u fruc;
123     Bit8u asc;
124     Bit8u ascq;
125 };
126
127
128 struct  error_recovery_t {
129     unsigned char data[8];
130 };
131
132 struct  cdrom_t {
133     rd_bool ready;
134     rd_bool locked;
135
136     struct cdrom_ops * cd;
137
138     uint32_t capacity;
139     int next_lba;
140     int remaining_blocks;
141
142     struct  currentStruct {
143         struct error_recovery_t error_recovery;
144     } current;
145
146 };
147
148 struct  atapi_t {
149     uint8_t command;
150     int drq_bytes;
151     int total_bytes_remaining;
152 };
153
154
155 typedef enum { IDE_NONE, IDE_DISK, IDE_CDROM } device_type_t;
156
157 struct controller_t  {
158     struct controller_status status;
159     Bit8u    error_register;
160     Bit8u    head_no;
161
162     union {
163         Bit8u    sector_count;
164         struct interrupt_reason_t interrupt_reason;
165     };
166
167
168     Bit8u    sector_no;
169
170     union  {
171         Bit16u   cylinder_no;
172         Bit16u   byte_count;
173     };
174
175     Bit8u    buffer[2048]; 
176     Bit32u   buffer_index;
177     Bit32u   drq_index;
178     Bit8u    current_command;
179     Bit8u    sectors_per_block;
180     Bit8u    lba_mode;
181
182     struct vm_device * pci;
183
184     struct  {
185         rd_bool reset;       // 0=normal, 1=reset controller
186         rd_bool disable_irq;     // 0=allow irq, 1=disable irq
187     } control;
188
189     Bit8u    reset_in_progress;
190     Bit8u    features;
191 };
192
193
194
195
196 struct  drive_t {
197     device_image_t  hard_drive;
198     device_type_t device_type;
199     // 512 byte buffer for ID drive command
200     // These words are stored in native word endian format, as
201     // they are fetched and returned via a return(), so
202     // there's no need to keep them in x86 endian format.
203     Bit16u id_drive[256];
204   
205     struct controller_t controller;
206     struct cdrom_t cdrom;
207     struct sense_info_t sense;
208     struct atapi_t atapi;
209   
210     /* JRL */
211     void * private_data;
212
213     Bit8u model_no[41];
214 };
215
216
217 // FIXME:
218 // For each ATA channel we should have one controller struct
219 // and an array of two drive structs
220 struct  channel_t {
221     struct drive_t drives[2];
222     unsigned drive_select;
223   
224     Bit16u ioaddr1;
225     Bit16u ioaddr2;
226     Bit8u  irq;
227 };
228
229
230
231 struct  ramdisk_t {
232     struct channel_t channels[MAX_ATA_CHANNEL];
233 };
234
235
236
237
238
239
240
241
242
243 #endif // ! __V3VEE__
244
245
246 #endif
247
248 #if 0
249
250 // FLAT MODE
251 // Open a image. Returns non-negative if successful.
252 //int open (const char* pathname);
253
254 // Open an image with specific flags. Returns non-negative if successful.
255 int rd_open (const char* pathname, int flags);
256
257 // Close the image.
258 void rd_close ();
259
260 // Position ourselves. Return the resulting offset from the
261 // beginning of the file.
262 off_t rd_lseek (off_t offset, int whence);
263
264 // Read count bytes to the buffer buf. Return the number of
265 // bytes read (count).
266 ssize_t rd_read (void* buf, size_t count);
267
268 // Write count bytes from buf. Return the number of bytes
269 // written (count).
270 ssize_t rd_write (const void* buf, size_t count);
271
272
273 #endif