2 * Copyright (C) 2002 MandrakeSoft S.A.
7 * http://www.linux-mandrake.com/
8 * http://www.mandrakesoft.com/
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.
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.
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
24 * Major modifications made for the V3VEE project
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
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
37 #ifndef __DEVICES_IDE_H__
38 #define __DEVICES_IDE_H__
43 #include <palacios/vmm_types.h>
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;
56 #define MAX_ATA_CHANNEL 4
61 SENSE_ILLEGAL_REQUEST = 5,
62 SENSE_UNIT_ATTENTION = 6
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
83 struct interrupt_reason_t {
91 struct controller_status {
95 rd_bool seek_complete;
97 rd_bool corrected_data;
99 unsigned int index_pulse_count;
107 struct sense_info_t {
128 struct error_recovery_t {
129 unsigned char data[8];
136 struct cdrom_ops * cd;
140 int remaining_blocks;
142 struct currentStruct {
143 struct error_recovery_t error_recovery;
151 int total_bytes_remaining;
155 typedef enum { IDE_NONE, IDE_DISK, IDE_CDROM } device_type_t;
157 struct controller_t {
158 struct controller_status status;
159 Bit8u error_register;
164 struct interrupt_reason_t interrupt_reason;
178 Bit8u current_command;
179 Bit8u sectors_per_block;
183 rd_bool reset; // 0=normal, 1=reset controller
184 rd_bool disable_irq; // 0=allow irq, 1=disable irq
187 Bit8u reset_in_progress;
195 device_image_t hard_drive;
196 device_type_t device_type;
197 // 512 byte buffer for ID drive command
198 // These words are stored in native word endian format, as
199 // they are fetched and returned via a return(), so
200 // there's no need to keep them in x86 endian format.
201 Bit16u id_drive[256];
203 struct controller_t controller;
204 struct cdrom_t cdrom;
205 struct sense_info_t sense;
206 struct atapi_t atapi;
216 // For each ATA channel we should have one controller struct
217 // and an array of two drive structs
219 struct drive_t drives[2];
220 unsigned drive_select;
230 struct channel_t channels[MAX_ATA_CHANNEL];
241 #endif // ! __V3VEE__
249 // Open a image. Returns non-negative if successful.
250 //int open (const char* pathname);
252 // Open an image with specific flags. Returns non-negative if successful.
253 int rd_open (const char* pathname, int flags);
258 // Position ourselves. Return the resulting offset from the
259 // beginning of the file.
260 off_t rd_lseek (off_t offset, int whence);
262 // Read count bytes to the buffer buf. Return the number of
263 // bytes read (count).
264 ssize_t rd_read (void* buf, size_t count);
266 // Write count bytes from buf. Return the number of bytes
268 ssize_t rd_write (const void* buf, size_t count);