Added "-p" to make parent directories as needed.
[AROS.git] / rom / devs / ata / ata.h
blobb9b6860b97c7c5803cc33a809d43950e040f1f91
1 #ifndef _ATA_H
2 #define _ATA_H
4 /*
5 Copyright © 2004-2014, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: ata.device main private include file
9 Lang: English
12 #define __OOP_NOMETHODBASES__
14 #include <exec/devices.h>
15 #include <exec/semaphores.h>
16 #include <exec/execbase.h>
17 #include <exec/libraries.h>
18 #include <exec/ports.h>
19 #include <oop/oop.h>
20 #include <utility/hooks.h>
21 #include <utility/utility.h>
22 #include <exec/io.h>
23 #include <exec/errors.h>
24 #include <devices/trackdisk.h>
25 #include <devices/scsidisk.h>
26 #include <devices/newstyle.h>
27 #include <devices/timer.h>
28 #include <devices/cd.h>
29 #include <hardware/ata.h>
30 #include <hidd/ata.h>
32 #include "include/devices/scsicmds.h"
34 #define MAX_DEVICEBUSES 2
35 #define MAX_BUSUNITS 2
36 #define STACK_SIZE 16384
37 #define TASK_PRI 10
38 #define TIMEOUT 30
41 Don't blame me for information redundance here!
43 Please note, that all structures here are more or less chained together.
44 The aim is, every single function in ata.device, no matter whether it takes
45 ata_Unit or ata_Bus or God knows what else, would have access to ata device
46 base and through it, to all other device structures.
48 I just wanted to avoid passing ataBase everywhere. :-D
51 /* structure forward declarations */
52 struct ata_Unit;
53 struct ata_Bus;
55 /* ata.device base */
56 struct ataBase
58 struct Device ata_Device; /* Exec device structure */
59 struct Task *ata_Daemon; /* master task pointer */
60 struct MsgPort *DaemonPort; /* Daemon's message port */
61 struct MinList Daemon_ios; /* Daemon's IORequests */
62 struct SignalSemaphore DaemonSem;
63 struct Task *daemonParent; /* Who sends control requests to daemon */
64 int ata__buscount; /* Number of all buses */
65 struct SignalSemaphore DetectionSem; /* Device detection semaphore */
67 /* Arguments and flags */
68 UBYTE ata_32bit;
69 UBYTE ata_NoMulti;
70 UBYTE ata_NoDMA;
71 UBYTE ata_Poll;
74 * memory pool
76 APTR ata_MemPool;
78 ULONG ata_ItersPer100ns;
80 struct Library *ata_OOPBase;
81 struct Library *ata_UtilityBase;
82 BPTR ata_SegList;
84 /* Bus HIDD classes */
85 OOP_AttrBase unitAttrBase;
86 OOP_AttrBase hwAttrBase;
87 OOP_AttrBase ataAttrBase;
88 OOP_MethodID hwMethodBase;
89 OOP_MethodID ataMethodBase;
90 OOP_Class *ataClass;
91 OOP_Class *busClass;
92 OOP_Class *unitClass;
93 OOP_Object *ataObj;
96 #undef HWAttrBase
97 #undef HiddATABusAB
98 #undef HiddATAUnitAB
99 #undef HWBase
100 #undef HiddATABusBase
101 #define HWAttrBase (ATABase->hwAttrBase)
102 #define HiddATABusAB (ATABase->ataAttrBase)
103 #define HiddATAUnitAB (ATABase->unitAttrBase)
104 #define HWBase (ATABase->hwMethodBase)
105 #define HiddATABusBase (ATABase->ataMethodBase)
106 #define OOPBase (ATABase->ata_OOPBase)
107 #define UtilityBase (ATABase->ata_UtilityBase)
110 The single IDE bus (channel)
112 struct ata_Bus
114 struct ataBase *ab_Base; /* device self */
115 /* Bus object data */
116 struct ATA_BusInterface *busVectors; /* Control vector table */
117 struct ATA_PIOInterface *pioVectors; /* PIO vector table */
118 APTR *dmaVectors; /* DMA vector table */
119 ULONG pioDataSize; /* PIO interface data size */
120 ULONG dmaDataSize; /* DMA interface data size */
121 void *pioInterface; /* PIO interface object */
122 void *dmaInterface; /* DMA interface object */
123 BOOL keepEmpty; /* Whether we should keep empty bus object */
125 UBYTE ab_Dev[2]; /* Master/Slave type, see below */
126 UBYTE ab_Flags; /* Bus flags similar to unit flags */
127 BYTE ab_SleepySignal; /* Signal used to wake the task up, when it's waiting */
128 /* for data requests/DMA */
129 UBYTE ab_BusNum; /* bus id - used to calculate device id */
131 struct ata_Unit *ab_Units[MAX_BUSUNITS]; /* Units on the bus */
132 struct ata_Unit *ab_SelectedUnit; /* Currently selected unit */
134 ULONG ab_IntCnt;
136 struct Task *ab_Task; /* Bus task handling all not-immediate transactions */
137 struct MsgPort *ab_MsgPort; /* Task's message port */
138 struct IORequest *ab_Timer; /* timer stuff */
140 struct Interrupt ab_ResetInt;
142 /* functions go here */
143 void (*ab_HandleIRQ)(struct ata_Unit* unit, UBYTE status);
146 /* Device types */
147 #define DEV_NONE 0x00
148 #define DEV_UNKNOWN 0x01
149 #define DEV_ATA 0x02
150 #define DEV_SATA 0x03
151 #define DEV_ATAPI 0x80
152 #define DEV_SATAPI 0x81
155 DriveIdent structure as returned by ATA_IDENTIFY_[DEVICE|ATAPI]
157 struct DriveIdent {
158 UWORD id_General; // 0
159 UWORD id_OldCylinders; // 1
160 UWORD id_SpecificConfig; // 2
161 UWORD id_OldHeads; // 3
162 UWORD pad1[2]; // 4-5
163 UWORD id_OldSectors; // 6
164 UWORD pad2[3]; // 7-9
165 UBYTE id_SerialNumber[20]; // 10-19
166 UWORD pad3[3]; // 20-22
167 UBYTE id_FirmwareRev[8]; // 23-26
168 UBYTE id_Model[40]; // 27-46
169 UWORD id_RWMultipleSize; // 47
170 UWORD pad4; // 48
171 UWORD id_Capabilities; // 49
172 UWORD id_OldCaps; // 50
173 UWORD id_OldPIO; // 51
174 UWORD pad5; // 52
175 UWORD id_ConfigAvailable; // 53
176 UWORD id_OldLCylinders; // 54
177 UWORD id_OldLHeads; // 55
178 UWORD id_OldLSectors; // 56
179 UWORD pad6[2]; // 57-58
180 UWORD id_RWMultipleTrans; // 59
181 ULONG id_LBASectors; // 60-61
182 UWORD id_DMADir; // 62
183 UWORD id_MWDMASupport; // 63
184 UWORD id_PIOSupport; // 64
185 UWORD id_MWDMA_MinCycleTime; // 65
186 UWORD id_MWDMA_DefCycleTime; // 66
187 UWORD id_PIO_MinCycleTime; // 67
188 UWORD id_PIO_MinCycleTimeIORDY; // 68
189 UWORD pad8[6]; // 69-74
190 UWORD id_QueueDepth; // 75
191 UWORD pad9[4]; // 76-79
192 UWORD id_ATAVersion; // 80
193 UWORD id_ATARevision; // 81
194 UWORD id_Commands1; // 82
195 UWORD id_Commands2; // 83
196 UWORD id_Commands3; // 84
197 UWORD id_Commands4; // 85
198 UWORD id_Commands5; // 86
199 UWORD id_Commands6; // 87
200 UWORD id_UDMASupport; // 88
201 UWORD id_SecurityEraseTime; // 89
202 UWORD id_ESecurityEraseTime; // 90
203 UWORD id_CurrentAdvPowerMode; // 91
204 UWORD id_MasterPwdRevision; // 92
205 UWORD id_HWResetResult; // 93
206 UWORD id_AcousticManagement; // 94
207 UWORD id_StreamMinimunReqSize; // 95
208 UWORD id_StreamingTimeDMA; // 96
209 UWORD id_StreamingLatency; // 97
210 ULONG id_StreamingGranularity; // 98-99
211 UQUAD id_LBA48Sectors; // 100-103
212 UWORD id_StreamingTimePIO; // 104
213 UWORD pad10; // 105
214 UWORD id_PhysSectorSize; // 106
215 UWORD pad11; // 107
216 UQUAD id_UniqueIDi[2]; // 108-115
217 UWORD pad12; // 116
218 ULONG id_WordsPerLogicalSector; // 117-118
219 UWORD pad13[8]; // 119-126
220 UWORD id_RemMediaStatusNotificationFeatures; // 127
221 UWORD id_SecurityStatus; // 128
222 UWORD pad14[127];
223 } __attribute__((packed));
225 typedef struct
227 UBYTE command; // current ATA command
228 UBYTE feature; // FF to indicate no feature
229 UBYTE secmul; // for read multiple - multiplier. default 1
230 UBYTE pad;
231 UQUAD blk;
232 ULONG sectors;
233 APTR buffer;
234 ULONG length;
235 ULONG actual;
237 enum
239 CM_NoData,
240 CM_PIORead,
241 CM_PIOWrite,
242 CM_DMARead,
243 CM_DMAWrite
244 } method;
245 enum
247 CT_NoBlock,
248 CT_CHS,
249 CT_LBA28,
250 CT_LBA48,
251 } type;
252 } ata_CommandBlock;
254 struct DaemonIO
256 struct MinNode link;
257 struct IOStdReq req;
261 Unit structure describing given device on the bus. It contains all the
262 necessary information unit/device may need.
264 struct ata_Unit
266 struct Unit au_Unit; /* exec's unit */
267 struct DriveIdent *au_Drive; /* Drive Ident after IDENTIFY command */
268 struct ata_Bus *au_Bus; /* Bus on which this unit is */
269 struct IOStdReq *DaemonReq; /* Disk change monitoring request */
271 ULONG au_XferModes; /* available transfer modes */
272 ULONG au_UseModes; /* Used transfer modes */
274 ULONG au_Capacity; /* Highest sector accessible through LBA28 */
275 UQUAD au_Capacity48; /* Highest sector accessible through LBA48 */
276 ULONG au_Cylinders;
277 UBYTE au_Heads;
278 UBYTE au_Sectors;
279 UBYTE au_Model[41];
280 UBYTE au_FirmwareRev[9];
281 UBYTE au_SerialNumber[21];
284 Here are stored pointers to functions responsible for handling this
285 device. They are set during device initialization and point to most
286 effective functions for this particular unit. Read/Write may be done
287 in PIO mode reading single sectors, using multisector PIO, or
288 multiword DMA.
290 BYTE (*au_Read32 )(struct ata_Unit *, ULONG, ULONG, APTR, ULONG *);
291 BYTE (*au_Write32 )(struct ata_Unit *, ULONG, ULONG, APTR, ULONG *);
292 BYTE (*au_Read64 )(struct ata_Unit *, UQUAD, ULONG, APTR, ULONG *);
293 BYTE (*au_Write64 )(struct ata_Unit *, UQUAD, ULONG, APTR, ULONG *);
294 BYTE (*au_Eject )(struct ata_Unit *);
295 BYTE (*au_DirectSCSI)(struct ata_Unit *, struct SCSICmd*);
296 BYTE (*au_Identify )(struct ata_Unit *);
297 VOID (*au_ins )(APTR, APTR, ULONG);
298 VOID (*au_outs )(APTR, APTR, ULONG);
299 void *pioInterface; /* PIO interface object, cached for performance */
301 ULONG au_UnitNum; /* Unit number as coded by device */
302 ULONG au_Flags; /* Unit flags, see below */
303 ULONG au_ChangeNum; /* Number of disc changes */
305 struct Interrupt *au_RemoveInt; /* Raise this interrupt on a disc change */
306 struct List au_SoftList; /* Raise even more interrupts from this list on disc change */
308 UBYTE au_SectorShift; /* Sector shift. 9 here is 512 bytes sector */
309 UBYTE au_DevMask; /* device mask used to simplify device number coding */
310 UBYTE au_SenseKey; /* Sense key from ATAPI devices */
311 UBYTE au_DevType;
313 /******* PIO IO ********/
314 APTR au_cmd_data;
315 ULONG au_cmd_length;
316 ULONG au_cmd_total;
317 ULONG au_cmd_error;
320 #define AF_XFER_DMA_MASK (AF_XFER_MDMA(0)|AF_XFER_MDMA(1)|AF_XFER_MDMA(2)| \
321 AF_XFER_UDMA(0)|AF_XFER_UDMA(1)|AF_XFER_UDMA(2)|AF_XFER_UDMA(3)| \
322 AF_XFER_UDMA(4)|AF_XFER_UDMA(5)|AF_XFER_UDMA(6))
324 /* Unit internal flags */
325 #define AB_DiscPresent 30 /* disc now in drive */
326 #define AB_DiscChanged 29 /* disc changed */
327 #define AB_Removable 28 /* media removable */
328 #define AB_DMA 27 /* DMA is in use */
329 #define AB_CHSOnly 26 /* only supports CHS commands */
331 #define AF_DiscPresent (1 << AB_DiscPresent)
332 #define AF_DiscChanged (1 << AB_DiscChanged)
333 #define AF_Removable (1 << AB_Removable)
334 #define AF_DMA (1 << AB_DMA)
335 #define AF_CHSOnly (1 << AB_CHSOnly)
337 #define Unit(io) ((struct ata_Unit *)(io)->io_Unit)
338 #define IOStdReq(io) ((struct IOStdReq *)io)
340 /* Function prototypes */
342 BOOL Hidd_ATABus_Start(OOP_Object *o, struct ataBase *ATABase);
343 AROS_UFP3(BOOL, Hidd_ATABus_Open,
344 AROS_UFPA(struct Hook *, h, A0),
345 AROS_UFPA(OOP_Object *, obj, A2),
346 AROS_UFPA(IPTR, reqUnit, A1));
348 void ata_InitBus(struct ata_Bus *);
349 int atapi_TestUnitOK(struct ata_Unit *);
350 BOOL ata_setup_unit(struct ata_Bus *bus, struct ata_Unit *unit);
351 void ata_init_unit(struct ata_Bus *bus, struct ata_Unit *unit, UBYTE u);
353 BOOL ata_RegisterVolume(ULONG StartCyl, ULONG EndCyl, struct ata_Unit *unit);
354 void BusTaskCode(struct ata_Bus *bus, struct ataBase *ATABase);
355 void DaemonCode(struct ataBase *LIBBASE);
357 BYTE SCSIEmu(struct ata_Unit*, struct SCSICmd*);
359 #define ATAPI_SS_EJECT 0x02
360 #define ATAPI_SS_LOAD 0x03
362 struct atapi_StartStop
364 UBYTE command;
365 UBYTE immediate;
366 UBYTE pad1[2];
367 UBYTE flags;
368 UBYTE pad2[7];
371 #endif // _ATA_H