revert between 56095 -> 55830 in arch
[AROS.git] / rom / devs / ahci / ahci_init.c
blob84935c875e084e442cba9bec7caf19d2864062a4
1 /*
2 Copyright © 2004-2018, The AROS Development Team. All rights reserved
3 $Id$
5 Desc:
6 Lang: English
7 */
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 */
17 #define __NOLIBBASE__
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>
37 #include <dos/bptr.h>
38 #include <dos/dosextens.h>
40 #include <hidd/pci.h>
41 #include <hidd/bus.h>
42 #include <hidd/storage.h>
44 #include <string.h>
46 #include "ahci.h"
47 #include "timer.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[] =
58 IID_HW,
59 IID_Hidd,
60 IID_Hidd_PCIDevice,
61 IID_Hidd_StorageUnit,
62 IID_Hidd_AHCI,
63 IID_Hidd_Bus,
64 IID_Hidd_AHCIBus,
65 IID_Hidd_AHCIUnit,
66 NULL
68 #endif
70 #if defined(__OOP_NOMETHODBASES__)
71 static CONST_STRPTR const methBaseIDs[] =
73 IID_Hidd_PCIDevice,
74 IID_Hidd_PCIDriver,
75 IID_HW,
76 NULL
78 #endif
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)
88 return FALSE;
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)
99 struct List *list;
100 struct Node *node;
102 list = (struct List *)GetBootInfo(BL_Args);
103 if (list)
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__));
114 return FALSE;
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)
126 return FALSE;
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))
133 return FALSE;
134 #endif
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);
140 #endif
141 return FALSE;
143 #endif
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)
153 return FALSE;
155 D(bug("[AHCI--] %s: storage root @ %p\n", __PRETTY_FUNCTION__, AHCIBase->storageRoot);)
157 return TRUE;
160 static int AHCI_Open
162 struct AHCIBase *AHCIBase,
163 struct IORequest *iorq,
164 ULONG unitnum,
165 ULONG flags
168 struct cam_sim *tmp, *unit = NULL;
171 * Assume it failed
173 iorq->io_Error = IOERR_OPENFAIL;
175 ForeachNode(&AHCIBase->ahci_Units, tmp) {
176 if (tmp->sim_Unit == unitnum) {
177 unit = tmp;
178 AROS_ATOMIC_INC(unit->sim_UseCount);
179 break;
183 if (unit == NULL)
184 return FALSE;
187 * set up iorequest
189 iorq->io_Device = &AHCIBase->ahci_Device;
190 iorq->io_Unit = (struct Unit *)unit;
191 iorq->io_Error = 0;
193 return TRUE;
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);
211 return TRUE;
214 ADD2INITLIB(AHCI_Init, 0)
215 ADD2OPENDEV(AHCI_Open, 0)
216 ADD2CLOSEDEV(AHCI_Close, 0)