2 Copyright © 2004-2018, The AROS Development Team. All rights reserved
9 /* Maintainer: Jason S. McMullan <jason.mcmullan@gmail.com>
12 #include <aros/debug.h>
14 #include <proto/exec.h>
16 /* We want all other bases obtained from our base */
19 #include <proto/timer.h>
20 #include <proto/bootloader.h>
21 #include <proto/expansion.h>
22 #include <proto/oop.h>
24 #include <aros/atomic.h>
25 #include <aros/symbolsets.h>
26 #include <aros/bootloader.h>
27 #include <exec/exec.h>
28 #include <exec/resident.h>
29 #include <exec/tasks.h>
30 #include <exec/memory.h>
31 #include <exec/nodes.h>
32 #include <utility/utility.h>
33 #include <libraries/expansion.h>
34 #include <libraries/configvars.h>
35 #include <devices/trackdisk.h>
36 #include <devices/newstyle.h>
38 #include <dos/dosextens.h>
42 #include <hidd/storage.h>
49 u_int32_t AhciForceGen
;
50 u_int32_t AhciNoFeatures
;
52 #include LC_LIBDEFS_FILE
54 #if defined(__OOP_NOATTRBASES__)
55 /* Keep order the same as order of IDs in struct AHCIBase! */
56 static CONST_STRPTR
const attrBaseIDs
[] =
70 #if defined(__OOP_NOMETHODBASES__)
71 static CONST_STRPTR
const methBaseIDs
[] =
80 static int AHCI_Init(struct AHCIBase
*AHCIBase
)
82 struct BootLoaderBase
*BootLoaderBase
;
84 D(bug("[AHCI--] %s: ahci.device Initialization\n", __PRETTY_FUNCTION__
);)
86 AHCIBase
->ahci_UtilityBase
= OpenLibrary("utility.library", 36);
87 if (!AHCIBase
->ahci_UtilityBase
)
90 /* Initialize lists */
91 NEWLIST(&AHCIBase
->ahci_Controllers
);
92 NEWLIST(&AHCIBase
->ahci_Units
);
93 AHCIBase
->ahci_HostCount
=0;
95 BootLoaderBase
= OpenResource("bootloader.resource");
96 D(bug("[AHCI--] %s: BootloaderBase = %p\n", __PRETTY_FUNCTION__
, BootLoaderBase
));
97 if (BootLoaderBase
!= NULL
)
102 list
= (struct List
*)GetBootInfo(BL_Args
);
105 ForeachNode(list
, node
)
107 if (strncmp(node
->ln_Name
, "AHCI=", 4) == 0)
109 const char *CmdLine
= &node
->ln_Name
[4];
111 if (strstr(CmdLine
, "disable"))
113 D(bug("[AHCI--] %s: Disabling AHCI support\n", __PRETTY_FUNCTION__
));
122 * Alloc everything needed from a pool, so that we avoid memory fragmentation.
124 AHCIBase
->ahci_MemPool
= CreatePool(MEMF_CLEAR
| MEMF_PUBLIC
| MEMF_SEM_PROTECTED
, 8192, 4096);
125 if (AHCIBase
->ahci_MemPool
== NULL
)
128 D(bug("[AHCI--] %s: MemPool @ %p\n", __PRETTY_FUNCTION__
, AHCIBase
->ahci_MemPool
);)
130 #if defined(__OOP_NOATTRBASES__)
131 /* Get some useful bases */
132 if (OOP_ObtainAttrBasesArray(&AHCIBase
->ahci_HWAttrBase
, attrBaseIDs
))
135 #if defined(__OOP_NOMETHODBASES__)
136 if (OOP_ObtainMethodBasesArray(&AHCIBase
->ahci_HiddPCIDeviceMethodBase
, methBaseIDs
))
138 #if defined(__OOP_NOATTRBASES__)
139 OOP_ReleaseAttrBasesArray(&AHCIBase
->ahci_HWAttrBase
, attrBaseIDs
);
145 D(bug("[AHCI--] %s: Base AHCI Hidd Class @ %p\n", __PRETTY_FUNCTION__
, AHCIBase
->ahciClass
);)
146 D(bug("[AHCI--] %s: AHCI PCI Bus Class @ %p\n", __PRETTY_FUNCTION__
, AHCIBase
->busClass
);)
148 AHCIBase
->storageRoot
= OOP_NewObject(NULL
, CLID_Hidd_Storage
, NULL
);
149 if (!AHCIBase
->storageRoot
)
150 AHCIBase
->storageRoot
= OOP_NewObject(NULL
, CLID_HW_Root
, NULL
);
151 if (!AHCIBase
->storageRoot
)
155 D(bug("[AHCI--] %s: storage root @ %p\n", __PRETTY_FUNCTION__
, AHCIBase
->storageRoot
);)
162 struct AHCIBase
*AHCIBase
,
163 struct IORequest
*iorq
,
168 struct cam_sim
*tmp
, *unit
= NULL
;
173 iorq
->io_Error
= IOERR_OPENFAIL
;
175 ForeachNode(&AHCIBase
->ahci_Units
, tmp
) {
176 if (tmp
->sim_Unit
== unitnum
) {
178 AROS_ATOMIC_INC(unit
->sim_UseCount
);
189 iorq
->io_Device
= &AHCIBase
->ahci_Device
;
190 iorq
->io_Unit
= (struct Unit
*)unit
;
196 /* Close given device */
197 static int AHCI_Close
199 struct AHCIBase
*AHCIBase
,
200 struct IORequest
*iorq
203 struct cam_sim
*unit
= (struct cam_sim
*)iorq
->io_Unit
;
205 /* First of all make the important fields of struct IORequest invalid! */
206 iorq
->io_Unit
= (struct Unit
*)~0;
208 /* Decrease use counters of unit */
209 AROS_ATOMIC_DEC(unit
->sim_UseCount
);
214 ADD2INITLIB(AHCI_Init
, 0)
215 ADD2OPENDEV(AHCI_Open
, 0)
216 ADD2CLOSEDEV(AHCI_Close
, 0)