grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hidds / pci / pci_init.c
blobf188aa1c84cb698b590459521ee36fde33fca104
1 /*
2 Copyright © 2003-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/symbolsets.h>
8 #include <exec/execbase.h>
9 #include <exec/types.h>
10 #include <exec/resident.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <exec/lists.h>
14 #include <exec/semaphores.h>
15 #include <dos/bptr.h>
17 #include <utility/utility.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
20 #include <aros/debug.h>
21 #include <hidd/system.h>
23 #include "pci.h"
25 #undef HWAttrBase
26 #undef HWBase
27 #undef OOPBase
28 #define HWAttrBase (LIBBASE->psd.hwAttrBase)
29 #define HWBase (LIBBASE->psd.hwMethodBase)
30 #define OOPBase (LIBBASE->psd.oopBase)
32 static int PCI_Init(struct pcibase *LIBBASE)
34 D(bug("[PCI] Initializing PCI system\n"));
36 LIBBASE->psd.kernelBase = OpenResource("kernel.resource");
37 if (!LIBBASE->psd.kernelBase)
38 return FALSE;
40 LIBBASE->psd.utilityBase = OpenLibrary("utility.library", 36);
41 if (!LIBBASE->psd.utilityBase)
42 return FALSE;
44 LIBBASE->psd.hiddPCIAB = OOP_ObtainAttrBase(IID_Hidd_PCI);
45 LIBBASE->psd.hiddPCIDeviceAB = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
46 LIBBASE->psd.hiddPCIDriverAB = OOP_ObtainAttrBase(IID_Hidd_PCIDriver);
47 LIBBASE->psd.hwAttrBase = OOP_ObtainAttrBase(IID_HW);
48 LIBBASE->psd.hiddPCIDriverMB = OOP_GetMethodID(IID_Hidd_PCIDriver, 0);
49 LIBBASE->psd.hwMethodBase = OOP_GetMethodID(IID_HW, 0);
51 if (LIBBASE->psd.hiddPCIAB && LIBBASE->psd.hiddPCIDeviceAB &&
52 LIBBASE->psd.hiddPCIDriverAB && LIBBASE->psd.hwAttrBase)
54 OOP_Object *root = OOP_NewObject(NULL, CLID_Hidd_System, NULL);
56 if (!root)
57 root = OOP_NewObject(NULL, CLID_HW_Root, NULL);
59 InitSemaphore(&LIBBASE->psd.dev_lock);
60 NEWLIST(&LIBBASE->psd.devices);
62 if (HW_AddDriver(root, LIBBASE->psd.pciClass, NULL))
64 D(bug("[PCI] Everything OK\n"));
65 return TRUE;
69 return FALSE;
72 static int PCI_Expunge(struct pcibase *LIBBASE)
74 D(bug("[PCI] Base Class destruction\n"));
77 * FIXME: This class can be loaded on hosted systems for debugging
78 * purposes. However, expunging it is totally broken and will
79 * introduce memory leak.
80 * Before expunging we must make sure we have no drivers.
82 if (LIBBASE->psd.pciObject)
84 IPTR used;
86 OOP_GetAttr(LIBBASE->psd.pciObject, aHW_InUse, &used);
87 if (used)
89 D(bug("[PCI] In use, cannot expunge\n"));
90 return FALSE;
92 else
94 OOP_Object *root = OOP_NewObject(NULL, CLID_HW_Root, NULL);
95 OOP_MethodID disp_msg = OOP_GetMethodID(IID_Root, moRoot_Dispose);
97 HW_RemoveDriver(root, LIBBASE->psd.pciObject);
99 * HW_RemoveDriver() will try to dispose us, but since we are
100 * singletone, our Dispose() method does nothing. So, we have to
101 * manually dispose ourselves after detaching from the root object.
103 OOP_DoSuperMethod(LIBBASE->psd.pciClass, LIBBASE->psd.pciObject, &disp_msg);
107 if (LIBBASE->psd.hiddPCIAB)
108 OOP_ReleaseAttrBase(IID_Hidd_PCI);
109 if (LIBBASE->psd.hiddPCIDeviceAB)
110 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
111 if (LIBBASE->psd.hiddPCIDriverAB)
112 OOP_ReleaseAttrBase(IID_Hidd_PCIDriver);
113 if (LIBBASE->psd.hwAttrBase)
114 OOP_ReleaseAttrBase(IID_HW);
116 return TRUE;
119 ADD2INITLIB(PCI_Init, 0)
120 ADD2EXPUNGELIB(PCI_Expunge, 0)