revert commit 56204.
[AROS.git] / rom / hidds / base / storage / storage_controllerclass.c
blob231c695dd4aea47ab9280bc9486e3e51e3a552a2
1 /*
2 Copyright (C) 2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <oop/oop.h>
9 #include <utility/tagitem.h>
11 #include "storage_intern.h"
13 OOP_Object *StorageController__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
15 D(bug ("[Storage:Controller] Root__New()\n");)
16 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
17 if (o)
19 struct HIDDStorageControllerData *data = OOP_INST_DATA(cl, o);
20 NEWLIST(&data->scd_Buses);
21 InitSemaphore(&data->scd_BusLock);
23 D(bug ("[Storage:Controller] Root__New: Instance @ 0x%p\n", o);)
24 return o;
27 VOID StorageController__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
29 D(bug ("[Storage:Controller] Root__Dispose(0x%p)\n", o);)
30 OOP_DoSuperMethod(cl, o, msg);
34 /*****************************************************************************************
36 NAME
37 moHidd_StorageController_AddBus
39 SYNOPSIS
40 OOP_Object *OOP_DoMethod(OOP_Object *obj, struct pHidd_StorageController_AddBus *Msg);
42 OOP_Object *Hidd_StorageController_AddBus(OOP_Object *obj, OOP_Class *busClass,
43 struct TagItem *tags);
45 LOCATION
46 CLID_HW
48 FUNCTION
49 Creates a bus driver object and registers it in the controller.
51 INPUTS
52 obj - An ATA Controller object to operate on.
53 busClass - A pointer to OOP class of the bus. In order to create an object
54 of some previously registered public class, use
55 oop.library/OOP_FindClass().
56 tags - An optional taglist which will be passed to bus class' New() method.
58 RESULT
59 A pointer to bus object or NULL in case of failure.
61 NOTES
62 Do not dispose the returned bus yourself, use Hidd_StorageController_RemoveBus() for it.
64 EXAMPLE
66 BUGS
68 SEE ALSO
69 moHidd_StorageController_RemoveBus
71 INTERNALS
73 *****************************************************************************************/
75 OOP_Object *StorageController__Hidd_StorageController__AddBus(OOP_Class *cl, OOP_Object *o,
76 struct pHidd_StorageController_AddBus *msg)
78 struct HIDDStorageControllerData *data = OOP_INST_DATA(cl, o);
79 OOP_Object *bus = NULL;
80 struct BusNode *bn;
82 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Adding Bus class 0x%p\n", msg->busClass));
84 if (msg->busClass != NULL)
86 // Get some extra memory for bus node
87 bn = AllocPooled( CSD(cl)->cs_MemPool, sizeof(struct BusNode));
88 if (bn)
90 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Bus Node @ 0x%p\n", bn));
91 bus = OOP_NewObject(msg->busClass, NULL, msg->tags);
93 if (!bus)
95 FreePooled( CSD(cl)->cs_MemPool, bn, sizeof(struct BusNode));
96 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Failed to instantiate Bus\n"));
97 return NULL;
100 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Bus Instance @ 0x%p\n", bus));
102 if (HIDD_StorageController_SetUpBus(o, bus))
104 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Bus Initialized\n"));
105 /* Add the driver to the end of drivers list */
106 bn->busObject = bus;
107 ObtainSemaphore(&data->scd_BusLock);
108 ADDTAIL(&data->scd_Buses, bn);
109 ReleaseSemaphore(&data->scd_BusLock);
111 return bus;
114 D(bug("[Storage:Controller] Hidd_StorageController__AddBus: Bus failed to Initialize\n"));
116 FreePooled( CSD(cl)->cs_MemPool, bn, sizeof(struct BusNode));
117 OOP_DisposeObject(bus);
120 return NULL;
123 /*****************************************************************************************
125 NAME
126 moHidd_StorageController_RemoveBus
128 SYNOPSIS
129 void OOP_DoMethod(OOP_Object *obj, struct pHidd_StorageController_RemoveBus *Msg);
131 void Hidd_StorageController_RemoveBus(OOP_Object *obj, OOP_Object *driver);
133 LOCATION
134 CLID_HW
136 FUNCTION
137 Unregisters and disposes hardware bus object.
139 INPUTS
140 obj - An ATA Controller object from which the bus should be removed.
141 driver - A pointer to a bus object, returned by Hidd_StorageController_AddBus().
143 RESULT
144 TRUE if removal successful or FALSE upon failure.
146 NOTES
148 EXAMPLE
150 BUGS
152 SEE ALSO
153 moHidd_StorageController_AddBus
155 INTERNALS
157 *****************************************************************************************/
159 BOOL StorageController__Hidd_StorageController__RemoveBus(OOP_Class *cl, OOP_Object *o, struct pHidd_StorageController_RemoveBus *Msg)
162 * Currently we don't support unloading bus drivers.
163 * This is a very-very big TODO.
165 D(bug ("[Storage:Controller] Hidd_StorageController__RemoveBus(0x%p)\n", o);)
166 return FALSE;
169 /*****************************************************************************************
171 NAME
172 moHidd_StorageController_EnumBuses
174 SYNOPSIS
175 void OOP_DoMethod(OOP_Object *obj, struct pHidd_StorageController_EnumBuses *Msg);
177 void Hidd_StorageController_EnumBuses(OOP_Object *obj, struct Hook *callback, APTR hookMsg);
179 LOCATION
180 CLID_HW
182 FUNCTION
183 Enumerates all installed driver in the subsystem.
185 INPUTS
186 obj - A subsystem object to query.
187 callback - A user-supplied hook which will be called for every driver.
188 hookMsg - A user-defined data to be passed to the hook.
190 The hook will be called with the following parameters:
191 AROS_UFHA(struct Hook *, hook , A0)
192 - A pointer to hook structure itself
193 AROS_UFHA(OOP_Object * , busObject, A2)
194 - A bus object
195 AROS_UFHA(APTR , message , A1)
196 - User-defined data
198 The hook should return FALSE in order to continue enumeration
199 or TRUE in order to stop it.
201 RESULT
202 None.
204 NOTES
206 EXAMPLE
208 BUGS
210 SEE ALSO
212 INTERNALS
213 The function uses internal semaphore locking. Because of this,
214 it is illegal to attempt to add or remove buses within the hook.
216 *****************************************************************************************/
218 void StorageController__Hidd_StorageController__EnumBuses(OOP_Class *cl, OOP_Object *o, struct pHidd_StorageController_EnumBuses *msg)
220 struct HIDDStorageControllerData *data = OOP_INST_DATA(cl, o);
221 struct BusNode *bn;
223 /* Lock Bus list for shared use */
224 ObtainSemaphoreShared(&data->scd_BusLock);
226 /* For every Bus on the controller... */
227 ForeachNode(&data->scd_Buses, bn)
229 BOOL stop = CALLHOOKPKT(msg->callback, bn->busObject, msg->hookMsg);
231 if (stop)
232 break;
235 ReleaseSemaphore(&data->scd_BusLock);
239 /*****************************************************************************************
241 NAME
242 moHidd_StorageController_SetUpBus
244 SYNOPSIS
245 void OOP_DoMethod(OOP_Object *obj, struct pHidd_StorageController_SetUpBus *Msg);
247 void Hidd_StorageController_SetUpBus(OOP_Object *obj, OOP_Object *busObject);
249 LOCATION
250 CLID_HW
252 FUNCTION
253 Performs subsystem-specific setup after driver object creation.
254 This method is intended to be used only by subclasses of CLID_HW.
256 INPUTS
257 obj - A subsystem object.
258 busObject - Device driver object.
260 RESULT
261 TRUE if setup completed successfully and FALSE in case of error.
262 If this method returns error, the driver object will be disposed
263 and moHidd_StorageController_AddBus method will fail.
265 NOTES
266 In base class this method does nothing and always returns TRUE.
268 EXAMPLE
270 BUGS
272 SEE ALSO
273 moHidd_StorageController_CleanUpBus
275 INTERNALS
277 *****************************************************************************************/
279 BOOL StorageController__Hidd_StorageController__SetUpBus(OOP_Class *cl, OOP_Object *o, struct pHidd_StorageController_SetUpBus *Msg)
281 D(bug ("[Storage:Controller] Hidd_StorageController__SetUpBus(0x%p)\n", o);)
283 /* By default we have nothing to do here */
285 return TRUE;
288 /*****************************************************************************************
290 NAME
291 moHidd_StorageController_CleanUpBus
293 SYNOPSIS
294 void OOP_DoMethod(OOP_Object *obj, struct pHidd_StorageController_CleanUpBus *Msg);
296 void Hidd_StorageController_CleanUpBus(OOP_Object *obj, OOP_Object *busObject);
298 LOCATION
299 CLID_HW
301 FUNCTION
302 Performs subsystem-specific cleanup before driver object disposal.
303 This method is intended to be used only by subclasses of CLID_HW.
305 INPUTS
306 obj - A subsystem object.
307 busObject - Device driver object.
309 RESULT
310 None.
312 NOTES
313 In base class this method does nothing.
315 EXAMPLE
317 BUGS
319 SEE ALSO
320 moHidd_StorageController_SetUpBus
322 INTERNALS
324 *****************************************************************************************/
326 void StorageController__Hidd_StorageController__CleanUpBus(OOP_Class *cl, OOP_Object *o, struct pHidd_StorageController_CleanUpBus *msg)
328 D(bug ("[Storage:Controller] Hidd_StorageController__CleanUpBus(0x%p)\n", o);)
329 /* By default we have nothing to do here */