revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / rom / devs / ahci / ahci_unitclass.c
blob3ffb93d6b9219a38a4113afd8dc47b57595cb0cd
1 /*
2 Copyright © 2018, 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 <proto/utility.h>
15 #include <hidd/storage.h>
16 #include <hidd/ahci.h>
17 #include <oop/oop.h>
19 #include "ahci.h"
22 static void ahci_strcpy(const UBYTE *str1, UBYTE *str2, ULONG size)
24 register int i = size;
26 while (i--)
28 if (str1[i] < ' ')
29 str2[i] = '\0';
30 else
31 str2[i] = str1[i];
35 /*****************************************************************************************
37 NAME
38 --background_unitclass--
40 LOCATION
41 IID_Hidd_AHCIUnit
43 NOTES
44 Unit class is private to ahci.device. Instances of this class represent
45 devices connected to AHCI buses, and can be used to obtain information
46 about these devices.
48 *****************************************************************************************/
50 OOP_Object *AHCIUnit__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
52 struct AHCIBase *AHCIBase = cl->UserData;
53 struct ahci_Bus *uBus = (struct ahci_Bus *)GetTagData(aHidd_DriverData, 0, msg->attrList);
55 D(bug ("[AHCI:Unit] Root__New()\n");)
57 if (!uBus)
58 return NULL;
60 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
61 if (o)
63 struct ahci_Unit *unit = OOP_INST_DATA(cl, o);
64 struct ata_port *at = uBus->ab_Port->ap_ata[0];
66 D(bug ("[AHCI:Unit] Root__New: Unit Obj @ %p\n", o);)
68 unit->au_Bus = uBus;
69 uBus->ab_Unit = o;
71 ahci_strcpy(at->at_identify.model, unit->au_Model, 40);
72 D(bug ("[AHCI:Unit] Root__New: Model %s\n", unit->au_Model);)
73 ahci_strcpy(at->at_identify.serial, unit->au_SerialNumber, 20);
74 D(bug ("[AHCI:Unit] Root__New: Serial %s\n", unit->au_SerialNumber);)
75 ahci_strcpy(at->at_identify.firmware, unit->au_FirmwareRev, 8);
76 D(bug ("[AHCI:Unit] Root__New: FW Revis %s\n", unit->au_FirmwareRev);)
78 return o;
81 void AHCIUnit__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
83 #if (0)
84 struct AHCIBase *AHCIBase = cl->UserData;
85 struct ahci_Unit *unit = OOP_INST_DATA(cl, o);
86 #endif
87 D(bug ("[AHCI:Unit] Root__Dispose(%p)\n", o);)
89 OOP_DoSuperMethod(cl, o, msg);
92 void AHCIUnit__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
94 struct AHCIBase *AHCIBase = cl->UserData;
95 struct ahci_Unit *unit = OOP_INST_DATA(cl, o);
96 struct ata_port *at = unit->au_Bus->ab_Port->ap_ata[0];
97 ULONG idx;
99 Hidd_StorageUnit_Switch (msg->attrID, idx)
101 case aoHidd_StorageUnit_Device:
102 *msg->storage = (IPTR)"ahci.device";
103 return;
105 case aoHidd_StorageUnit_Number:
106 *msg->storage = unit->au_UnitNum;
107 return;
109 case aoHidd_StorageUnit_Type:
111 switch (unit->au_Bus->ab_Port->ap_type)
113 case ATA_PORT_T_DISK:
115 if (at->at_identify.support_dsm & ATA_SUPPORT_DSM_TRIM)
116 *msg->storage = vHidd_StorageUnit_Type_SolidStateDisk;
117 else
118 *msg->storage = vHidd_StorageUnit_Type_FixedDisk;
119 break;
121 case ATA_PORT_T_ATAPI:
122 *msg->storage = vHidd_StorageUnit_Type_OpticalDisc;
123 break;
125 default:
126 *msg->storage = vHidd_StorageUnit_Type_Unknown;
127 break;
129 return;
132 case aoHidd_StorageUnit_Model:
133 *msg->storage = (IPTR)unit->au_Model;
134 return;
136 case aoHidd_StorageUnit_Revision:
137 *msg->storage = (IPTR)unit->au_FirmwareRev;
138 return;
140 case aoHidd_StorageUnit_Serial:
141 *msg->storage = (IPTR)unit->au_SerialNumber;
142 return;
144 case aoHidd_StorageUnit_Removable:
146 if (at->at_identify.config & (1 << 7))
147 *msg->storage = (IPTR)TRUE;
148 else
149 *msg->storage = (IPTR)FALSE;
150 return;
154 Hidd_AHCIUnit_Switch (msg->attrID, idx)
156 case aoHidd_AHCIUnit_Features:
157 *msg->storage = (IPTR)at->at_features;
158 return;
161 OOP_DoSuperMethod(cl, o, &msg->mID);