Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / nouveau / pci-device-mock / pcimockdriverclass.c
blobdfdd29f3fec8e1926bf6121b1563acd15ecc8163
1 /*
2 Copyright 2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <proto/oop.h>
9 #include <aros/symbolsets.h>
11 #include "pcimock_intern.h"
13 #undef HiddPCIDriverAttrBase
14 #define HiddPCIDriverAttrBase (SD(cl)->hiddPCIDriverAB)
16 #undef HiddAttrBase
17 #define HiddAttrBase (SD(cl)->hiddAB)
19 #undef HiddPCIMockHardwareAttrBase
20 #define HiddPCIMockHardwareAttrBase (SD(cl)->hiddPCIMockHardwareAB)
22 OOP_Object * METHOD(PCIMock, Root, New)
24 struct pRoot_New mymsg;
26 struct TagItem mytags[] =
28 { aHidd_Name, (IPTR)"PCIMock" },
29 { aHidd_HardwareName, (IPTR)"Mock PCI Driver" },
30 { TAG_DONE, 0 }
33 mymsg.mID = msg->mID;
34 mymsg.attrList = (struct TagItem *)&mytags;
36 if (msg->attrList)
38 mytags[2].ti_Tag = TAG_MORE;
39 mytags[2].ti_Data = (IPTR)msg->attrList;
42 msg = &mymsg;
44 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
46 return o;
49 ULONG METHOD(PCIMock, Hidd_PCIDriver, ReadConfigLong)
51 IPTR pciconfigspace;
52 OOP_Object * mockHardware = NULL;
53 ULONG val;
55 if (!((msg->bus == 0) && (msg->sub == 0)))
56 return 0;
58 if ((mockHardware = SD(cl)->mockHardwareBus0[msg->dev]) == NULL)
59 return 0;
61 OOP_GetAttr(mockHardware, aHidd_PCIMockHardware_ConfigSpaceAddr, &pciconfigspace);
64 val = *((ULONG *)(pciconfigspace + msg->reg));
66 /* Inform mock device that value in its address space region has been read */
68 struct pHidd_PCIMockHardware_MemoryReadAtAddress mraa =
70 mID : OOP_GetMethodID(IID_Hidd_PCIMockHardware, moHidd_PCIMockHardware_MemoryReadAtAddress),
71 memoryaddress : pciconfigspace + msg->reg
74 OOP_DoMethod(mockHardware, (OOP_Msg)&mraa);
77 return val;
80 VOID METHOD(PCIMock, Hidd_PCIDriver, WriteConfigLong)
82 IPTR pciconfigspace;
83 OOP_Object * mockHardware = NULL;
85 if (!((msg->bus == 0) && (msg->sub == 0)))
86 return;
88 if ((mockHardware = SD(cl)->mockHardwareBus0[msg->dev]) == NULL)
89 return;
91 OOP_GetAttr(mockHardware, aHidd_PCIMockHardware_ConfigSpaceAddr, &pciconfigspace);
93 *((ULONG *)(pciconfigspace + msg->reg)) = msg->val;
95 /* Inform mock device that value in its address space region has changed */
97 struct pHidd_PCIMockHardware_MemoryChangedAtAddress mcaa =
99 mID : OOP_GetMethodID(IID_Hidd_PCIMockHardware, moHidd_PCIMockHardware_MemoryChangedAtAddress),
100 memoryaddress : pciconfigspace + msg->reg
103 OOP_DoMethod(mockHardware, (OOP_Msg)&mcaa);
107 static int PCIMock_ExpungeClass(LIBBASETYPEPTR LIBBASE)
109 ULONG i;
111 D(bug("[PCIMock] deleting classes\n"));
113 for (i = 0; i < MAX_BUS0_DEVICES; i++)
114 if (LIBBASE->sd.mockHardwareBus0[i] != NULL)
116 OOP_DisposeObject(LIBBASE->sd.mockHardwareBus0[i]);
117 LIBBASE->sd.mockHardwareBus0[i] = NULL;
120 OOP_ReleaseAttrBase(IID_Hidd_PCIDriver);
121 OOP_ReleaseAttrBase(IID_Hidd);
122 OOP_ReleaseAttrBase(IID_Hidd_PCIMockHardware);
126 return TRUE;
129 static int PCIMock_InitClass(LIBBASETYPEPTR LIBBASE)
131 OOP_Object *pci = NULL;
132 ULONG i;
134 D(bug("[PCIMock] Driver initialization\n"));
136 LIBBASE->sd.hiddPCIDriverAB = OOP_ObtainAttrBase(IID_Hidd_PCIDriver);
137 LIBBASE->sd.hiddAB = OOP_ObtainAttrBase(IID_Hidd);
138 LIBBASE->sd.hiddPCIMockHardwareAB = OOP_ObtainAttrBase(IID_Hidd_PCIMockHardware);
139 for (i = 0; i < MAX_BUS0_DEVICES; i++)
140 LIBBASE->sd.mockHardwareBus0[i] = NULL;
142 ADD_DEVICE((&LIBBASE->sd), 0, CLID_Hidd_PCIMockHardware_SIS661FX);
143 ADD_DEVICE((&LIBBASE->sd), 2, CLID_Hidd_PCIMockHardware_NV44A);
144 // ADD_DEVICE((&LIBBASE->sd), 3, CLID_Hidd_PCIMockHardware_NVG86);
145 // ADD_DEVICE((&LIBBASE->sd), 4, CLID_Hidd_PCIMockHardware_NVGTS250);
146 // ADD_DEVICE((&LIBBASE->sd), 5, CLID_Hidd_PCIMockHardware_NVGF100);
148 if (LIBBASE->sd.hiddPCIDriverAB)
151 * The class may be added to the system. Add the driver
152 * to PCI subsystem as well
154 struct pHidd_PCI_AddHardwareDriver msg;
157 * PCI is suppose to destroy the class on its Dispose
159 msg.driverClass = LIBBASE->sd.driverClass;
160 msg.mID = OOP_GetMethodID(IID_Hidd_PCI, moHidd_PCI_AddHardwareDriver);
162 pci = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
163 OOP_DoMethod(pci, (OOP_Msg)&msg);
164 OOP_DisposeObject(pci);
166 else
167 return FALSE;
169 D(bug("[PCIMock] Driver ClassPtr = %x\n", psd->driverClass));
171 return TRUE;
174 ADD2INITLIB(PCIMock_InitClass, 0)
175 ADD2EXPUNGELIB(PCIMock_ExpungeClass, 0)