fix some flag usage in mmakefiles. provide suitable names for amiga hardware devices...
[AROS.git] / rom / devs / ata / ata_unitclass.c
blobdf4e80eefd105219915eea55e71eb5b59a8ba1fb
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <proto/exec.h>
10 /* We want all other bases obtained from our base */
11 #define __NOLIBBASE__
13 #include <hidd/storage.h>
14 #include <hidd/ata.h>
15 #include <oop/oop.h>
17 #include "ata.h"
19 /*****************************************************************************************
21 NAME
22 --background--
24 LOCATION
25 IID_Hidd_ATAUnit
27 NOTES
28 Unit class is private to ata.device. Instances of this class represent
29 devices connected to IDE buses, and can be used to obtain information
30 about these devices.
32 *****************************************************************************************/
35 * a STUB function for commands not supported by this particular device
37 static BYTE ata_STUB(struct ata_Unit *au)
39 D(bug("[ATA%02ld] CALLED STUB FUNCTION (GENERIC). THIS OPERATION IS NOT "
40 "SUPPORTED BY DEVICE\n", au->au_UnitNum));
41 return CDERR_NOCMD;
44 static BYTE ata_STUB_IO32(struct ata_Unit *au, ULONG blk, ULONG len,
45 APTR buf, ULONG* act)
47 D(bug("[ATA%02ld] CALLED STUB FUNCTION (IO32). THIS OPERATION IS NOT "
48 "SUPPORTED BY DEVICE\n", au->au_UnitNum));
49 return CDERR_NOCMD;
52 static BYTE ata_STUB_IO64(struct ata_Unit *au, UQUAD blk, ULONG len,
53 APTR buf, ULONG* act)
55 D(bug("[ATA%02ld] CALLED STUB FUNCTION -- IO ACCESS TO BLOCK %08lx:%08lx, LENGTH %08lx. THIS OPERATION IS NOT SUPPORTED BY DEVICE\n", au->au_UnitNum, (blk >> 32), (blk & 0xffffffff), len));
56 return CDERR_NOCMD;
59 static BYTE ata_STUB_SCSI(struct ata_Unit *au, struct SCSICmd* cmd)
61 D(bug("[ATA%02ld] CALLED STUB FUNCTION. THIS OPERATION IS NOT SUPPORTED BY DEVICE\n", au->au_UnitNum));
62 return CDERR_NOCMD;
65 OOP_Object *ATAUnit__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
67 D(bug("[ATA:Unit] %s()\n", __PRETTY_FUNCTION__));
69 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, &msg->mID);
70 if (o)
72 struct ataBase *ATABase = cl->UserData;
73 struct ata_Unit *unit = OOP_INST_DATA(cl, o);
75 D(bug("[ATA:Unit] %s: instance @ 0x%p\n", __PRETTY_FUNCTION__, o));
77 unit->au_Drive = AllocPooled(ATABase->ata_MemPool, sizeof(struct DriveIdent));
78 if (!unit->au_Drive)
80 OOP_MethodID disp_msg = msg->mID - moRoot_New + moRoot_Dispose;
82 OOP_DoSuperMethod(cl, o, &disp_msg);
83 return NULL;
86 unit->au_SectorShift = 9; /* this really has to be set here. */
88 NEWLIST(&unit->au_SoftList);
91 * since the stack is always handled by caller
92 * it's safe to stub all calls with one function
94 unit->au_Read32 = ata_STUB_IO32;
95 unit->au_Read64 = ata_STUB_IO64;
96 unit->au_Write32 = ata_STUB_IO32;
97 unit->au_Write64 = ata_STUB_IO64;
98 unit->au_Eject = ata_STUB;
99 unit->au_DirectSCSI = ata_STUB_SCSI;
100 unit->au_Identify = ata_STUB;
102 return o;
105 void ATAUnit__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
107 struct ataBase *ATABase = cl->UserData;
108 struct ata_Unit *unit = OOP_INST_DATA(cl, o);
110 D(bug("[ATA:Unit] %s()\n", __PRETTY_FUNCTION__));
112 FreePooled(ATABase->ata_MemPool, unit->au_Drive, sizeof(struct DriveIdent));
113 OOP_DoSuperMethod(cl, o, msg);
116 /*****************************************************************************************
118 NAME
119 aoHidd_ATAUnit_XferModes
121 SYNOPSIS
122 [..G], ULONG
124 LOCATION
125 IID_Hidd_ATAUnit
127 FUNCTION
128 Tells which transfer modes are supported by this device. The returned value
129 is a bitwise combination of the following flags (see include/hidd/ata.h):
131 AF_XFER_PIO(x) - PIO mode number x (0 - 4)
132 AF_XFER_MDMA(x) - multiword DMA mode number x (0 - 2)
133 AF_XFER_UDMA(x) - Ultra DMA mode number x (0 - 6)
134 AF_XFER_48BIT - LBA48 block addressing
135 AF_XFER_RWMILTI - Multisector PIO
136 AF_XFER_PACKET - ATAPI
137 AF_XFER_LBA - LBA28 block addressing
138 AF_XFER_PIO32 - 32-bit PIO
140 NOTES
142 EXAMPLE
144 BUGS
145 32-bit PIO is actually controller's property and not drive's property.
146 Because of this AF_XFER_PIO32 flag can never be returned by this attribute.
147 Nevertheless, it can be returned by aoHidd_ATAUnit_ConfiguredModes
148 attribute.
150 SEE ALSO
151 aoHidd_ATAUnit_ConfiguredModes
153 INTERNALS
155 *****************************************************************************************/
156 /*****************************************************************************************
158 NAME
159 aoHidd_ATAUnit_MultiSector
161 SYNOPSIS
162 [..G], UBYTE
164 LOCATION
165 IID_Hidd_ATAUnit
167 FUNCTION
168 Tells maximum allowed number of sectors for multisector transfer.
170 NOTES
172 EXAMPLE
174 BUGS
176 SEE ALSO
178 INTERNALS
180 *****************************************************************************************/
181 /*****************************************************************************************
183 NAME
184 aoHidd_ATAUnit_ConfiguredModes
186 SYNOPSIS
187 [..G], ULONG
189 LOCATION
190 IID_Hidd_ATAUnit
192 FUNCTION
193 Tells which transfer modes are currently configured for use with the drive.
194 The returned value is a bitmask of the same flags as for
195 aoHidd_ATAUnit_XferModes attribute.
197 NOTES
199 EXAMPLE
201 BUGS
202 Currently ata.device does not distinguish between PIO modes and does not
203 set any bit for them. Absence of DMA mode flags automatically means that
204 PIO mode is used.
206 SEE ALSO
207 aoHidd_ATAUnit_XferModes
209 INTERNALS
211 *****************************************************************************************/
213 void ATAUnit__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
215 struct ataBase *ATABase = cl->UserData;
216 struct ata_Unit *unit = OOP_INST_DATA(cl, o);
217 ULONG idx;
219 Hidd_StorageUnit_Switch (msg->attrID, idx)
221 case aoHidd_StorageUnit_Device:
222 *msg->storage = (IPTR)"ata.device";
223 return;
225 case aoHidd_StorageUnit_Number:
226 *msg->storage = unit->au_UnitNum;
227 return;
229 case aoHidd_StorageUnit_Type:
231 UBYTE u = unit->au_UnitNum & 1;
232 switch (unit->au_Bus->ab_Dev[u])
234 case DEV_SATA:
235 case DEV_ATA:
236 *msg->storage = vHidd_StorageUnit_Type_FixedDisk;
237 break;
239 case DEV_SATAPI:
240 case DEV_ATAPI:
241 *msg->storage = vHidd_StorageUnit_Type_OpticalDisc;
242 break;
244 default:
245 *msg->storage = vHidd_StorageUnit_Type_Unknown;
246 break;
248 return;
251 case aoHidd_StorageUnit_Model:
252 *msg->storage = (IPTR)unit->au_Model;
253 return;
255 case aoHidd_StorageUnit_Revision:
256 *msg->storage = (IPTR)unit->au_FirmwareRev;
257 return;
259 case aoHidd_StorageUnit_Serial:
260 *msg->storage = (IPTR)unit->au_SerialNumber;
261 return;
263 case aoHidd_StorageUnit_Removable:
264 *msg->storage = (unit->au_Flags & AF_Removable) ? TRUE : FALSE;
265 return;
268 Hidd_ATAUnit_Switch (msg->attrID, idx)
270 case aoHidd_ATAUnit_XferModes:
271 *msg->storage = unit->au_XferModes;
272 return;
274 case aoHidd_ATAUnit_MultiSector:
275 *msg->storage = unit->au_Drive->id_RWMultipleSize & 0xFF;
276 return;
278 case aoHidd_ATAUnit_ConfiguredModes:
279 *msg->storage = unit->au_UseModes;
280 return;
283 OOP_DoSuperMethod(cl, o, &msg->mID);