5 Copyright © 2004-2014, The AROS Development Team. All rights reserved.
8 Desc: ata.device main private include file
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>
20 #include <utility/hooks.h>
21 #include <utility/utility.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>
32 #include "include/devices/scsicmds.h"
34 #define MAX_DEVICEBUSES 2
35 #define MAX_BUSUNITS 2
36 #define STACK_SIZE 16384
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 */
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 */
78 ULONG ata_ItersPer100ns
;
80 struct Library
*ata_OOPBase
;
81 struct Library
*ata_UtilityBase
;
84 /* Bus HIDD classes */
85 OOP_AttrBase unitAttrBase
;
86 OOP_AttrBase hwAttrBase
;
87 OOP_AttrBase ataAttrBase
;
88 OOP_MethodID hwMethodBase
;
89 OOP_MethodID ataMethodBase
;
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)
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 */
126 UBYTE ab_Dev
[2]; /* Master/Slave type, see below */
127 UBYTE ab_Flags
; /* Bus flags similar to unit flags */
128 BYTE ab_SleepySignal
; /* Signal used to wake the task up, when it's waiting */
129 /* for data requests/DMA */
130 UBYTE ab_BusNum
; /* bus id - used to calculate device id */
132 struct ata_Unit
*ab_Units
[MAX_BUSUNITS
]; /* Units on the bus */
133 struct ata_Unit
*ab_SelectedUnit
; /* Currently selected unit */
137 struct Task
*ab_Task
; /* Bus task handling all not-immediate transactions */
138 struct MsgPort
*ab_MsgPort
; /* Task's message port */
139 struct IORequest
*ab_Timer
; /* timer stuff */
141 struct Interrupt ab_ResetInt
;
143 APTR ab_BounceBufferPool
;
145 /* functions go here */
146 void (*ab_HandleIRQ
)(struct ata_Unit
* unit
, UBYTE status
);
150 #define DEV_NONE 0x00
151 #define DEV_UNKNOWN 0x01
153 #define DEV_SATA 0x03
154 #define DEV_ATAPI 0x80
155 #define DEV_SATAPI 0x81
158 DriveIdent structure as returned by ATA_IDENTIFY_[DEVICE|ATAPI]
161 UWORD id_General
; // 0
162 UWORD id_OldCylinders
; // 1
163 UWORD id_SpecificConfig
; // 2
164 UWORD id_OldHeads
; // 3
165 UWORD pad1
[2]; // 4-5
166 UWORD id_OldSectors
; // 6
167 UWORD pad2
[3]; // 7-9
168 UBYTE id_SerialNumber
[20]; // 10-19
169 UWORD pad3
[3]; // 20-22
170 UBYTE id_FirmwareRev
[8]; // 23-26
171 UBYTE id_Model
[40]; // 27-46
172 UWORD id_RWMultipleSize
; // 47
174 UWORD id_Capabilities
; // 49
175 UWORD id_OldCaps
; // 50
176 UWORD id_OldPIO
; // 51
178 UWORD id_ConfigAvailable
; // 53
179 UWORD id_OldLCylinders
; // 54
180 UWORD id_OldLHeads
; // 55
181 UWORD id_OldLSectors
; // 56
182 UWORD pad6
[2]; // 57-58
183 UWORD id_RWMultipleTrans
; // 59
184 ULONG id_LBASectors
; // 60-61
185 UWORD id_DMADir
; // 62
186 UWORD id_MWDMASupport
; // 63
187 UWORD id_PIOSupport
; // 64
188 UWORD id_MWDMA_MinCycleTime
; // 65
189 UWORD id_MWDMA_DefCycleTime
; // 66
190 UWORD id_PIO_MinCycleTime
; // 67
191 UWORD id_PIO_MinCycleTimeIORDY
; // 68
192 UWORD pad8
[6]; // 69-74
193 UWORD id_QueueDepth
; // 75
194 UWORD pad9
[4]; // 76-79
195 UWORD id_ATAVersion
; // 80
196 UWORD id_ATARevision
; // 81
197 UWORD id_Commands1
; // 82
198 UWORD id_Commands2
; // 83
199 UWORD id_Commands3
; // 84
200 UWORD id_Commands4
; // 85
201 UWORD id_Commands5
; // 86
202 UWORD id_Commands6
; // 87
203 UWORD id_UDMASupport
; // 88
204 UWORD id_SecurityEraseTime
; // 89
205 UWORD id_ESecurityEraseTime
; // 90
206 UWORD id_CurrentAdvPowerMode
; // 91
207 UWORD id_MasterPwdRevision
; // 92
208 UWORD id_HWResetResult
; // 93
209 UWORD id_AcousticManagement
; // 94
210 UWORD id_StreamMinimunReqSize
; // 95
211 UWORD id_StreamingTimeDMA
; // 96
212 UWORD id_StreamingLatency
; // 97
213 ULONG id_StreamingGranularity
; // 98-99
214 UQUAD id_LBA48Sectors
; // 100-103
215 UWORD id_StreamingTimePIO
; // 104
217 UWORD id_PhysSectorSize
; // 106
219 UQUAD id_UniqueIDi
[2]; // 108-115
221 ULONG id_WordsPerLogicalSector
; // 117-118
222 UWORD pad13
[8]; // 119-126
223 UWORD id_RemMediaStatusNotificationFeatures
; // 127
224 UWORD id_SecurityStatus
; // 128
226 } __attribute__((packed
));
230 UBYTE command
; // current ATA command
231 UBYTE feature
; // FF to indicate no feature
232 UBYTE secmul
; // for read multiple - multiplier. default 1
264 Unit structure describing given device on the bus. It contains all the
265 necessary information unit/device may need.
269 struct Unit au_Unit
; /* exec's unit */
270 struct DriveIdent
*au_Drive
; /* Drive Ident after IDENTIFY command */
271 struct ata_Bus
*au_Bus
; /* Bus on which this unit is */
272 struct IOStdReq
*DaemonReq
; /* Disk change monitoring request */
274 ULONG au_XferModes
; /* available transfer modes */
275 ULONG au_UseModes
; /* Used transfer modes */
277 ULONG au_Capacity
; /* Highest sector accessible through LBA28 */
278 UQUAD au_Capacity48
; /* Highest sector accessible through LBA48 */
283 UBYTE au_FirmwareRev
[9];
284 UBYTE au_SerialNumber
[21];
287 Here are stored pointers to functions responsible for handling this
288 device. They are set during device initialization and point to most
289 effective functions for this particular unit. Read/Write may be done
290 in PIO mode reading single sectors, using multisector PIO, or
293 BYTE (*au_Read32
)(struct ata_Unit
*, ULONG
, ULONG
, APTR
, ULONG
*);
294 BYTE (*au_Write32
)(struct ata_Unit
*, ULONG
, ULONG
, APTR
, ULONG
*);
295 BYTE (*au_Read64
)(struct ata_Unit
*, UQUAD
, ULONG
, APTR
, ULONG
*);
296 BYTE (*au_Write64
)(struct ata_Unit
*, UQUAD
, ULONG
, APTR
, ULONG
*);
297 BYTE (*au_Eject
)(struct ata_Unit
*);
298 BYTE (*au_DirectSCSI
)(struct ata_Unit
*, struct SCSICmd
*);
299 BYTE (*au_Identify
)(struct ata_Unit
*);
300 VOID (*au_ins
)(APTR
, APTR
, ULONG
);
301 VOID (*au_outs
)(APTR
, APTR
, ULONG
);
302 void *pioInterface
; /* PIO interface object, cached for performance */
304 ULONG au_UnitNum
; /* Unit number as coded by device */
305 ULONG au_Flags
; /* Unit flags, see below */
306 ULONG au_ChangeNum
; /* Number of disc changes */
308 struct Interrupt
*au_RemoveInt
; /* Raise this interrupt on a disc change */
309 struct List au_SoftList
; /* Raise even more interrupts from this list on disc change */
311 UBYTE au_SectorShift
; /* Sector shift. 9 here is 512 bytes sector */
312 UBYTE au_DevMask
; /* device mask used to simplify device number coding */
313 UBYTE au_SenseKey
; /* Sense key from ATAPI devices */
316 /******* PIO IO ********/
323 #define AF_XFER_DMA_MASK (AF_XFER_MDMA(0)|AF_XFER_MDMA(1)|AF_XFER_MDMA(2)| \
324 AF_XFER_UDMA(0)|AF_XFER_UDMA(1)|AF_XFER_UDMA(2)|AF_XFER_UDMA(3)| \
325 AF_XFER_UDMA(4)|AF_XFER_UDMA(5)|AF_XFER_UDMA(6))
327 /* Unit internal flags */
328 #define AB_DiscPresent 30 /* disc now in drive */
329 #define AB_DiscChanged 29 /* disc changed */
330 #define AB_Removable 28 /* media removable */
331 #define AB_DMA 27 /* DMA is in use */
332 #define AB_CHSOnly 26 /* only supports CHS commands */
334 #define AF_DiscPresent (1 << AB_DiscPresent)
335 #define AF_DiscChanged (1 << AB_DiscChanged)
336 #define AF_Removable (1 << AB_Removable)
337 #define AF_DMA (1 << AB_DMA)
338 #define AF_CHSOnly (1 << AB_CHSOnly)
340 #define Unit(io) ((struct ata_Unit *)(io)->io_Unit)
341 #define IOStdReq(io) ((struct IOStdReq *)io)
343 /* Function prototypes */
345 BOOL
Hidd_ATABus_Start(OOP_Object
*o
, struct ataBase
*ATABase
);
346 AROS_UFP3(BOOL
, Hidd_ATABus_Open
,
347 AROS_UFPA(struct Hook
*, h
, A0
),
348 AROS_UFPA(OOP_Object
*, obj
, A2
),
349 AROS_UFPA(IPTR
, reqUnit
, A1
));
351 void ata_InitBus(struct ata_Bus
*);
352 int atapi_TestUnitOK(struct ata_Unit
*);
353 BOOL
ata_setup_unit(struct ata_Bus
*bus
, struct ata_Unit
*unit
);
354 void ata_init_unit(struct ata_Bus
*bus
, struct ata_Unit
*unit
, UBYTE u
);
356 BOOL
ata_RegisterVolume(ULONG StartCyl
, ULONG EndCyl
, struct ata_Unit
*unit
);
357 void BusTaskCode(struct ata_Bus
*bus
, struct ataBase
*ATABase
);
358 void DaemonCode(struct ataBase
*LIBBASE
);
360 BYTE
SCSIEmu(struct ata_Unit
*, struct SCSICmd
*);
362 #define ATAPI_SS_EJECT 0x02
363 #define ATAPI_SS_LOAD 0x03
365 struct atapi_StartStop