2 Copyright 2011, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
11 #include "pcimock_intern.h"
13 #undef HiddPCIDriverAttrBase
14 #define HiddPCIDriverAttrBase (SD(cl)->hiddPCIDriverAB)
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" },
34 mymsg
.attrList
= (struct TagItem
*)&mytags
;
38 mytags
[2].ti_Tag
= TAG_MORE
;
39 mytags
[2].ti_Data
= (IPTR
)msg
->attrList
;
44 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
49 ULONG
METHOD(PCIMock
, Hidd_PCIDriver
, ReadConfigLong
)
52 OOP_Object
* mockHardware
= NULL
;
55 if (!((msg
->bus
== 0) && (msg
->sub
== 0)))
58 if ((mockHardware
= SD(cl
)->mockHardwareBus0
[msg
->dev
]) == NULL
)
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
);
80 VOID
METHOD(PCIMock
, Hidd_PCIDriver
, WriteConfigLong
)
83 OOP_Object
* mockHardware
= NULL
;
85 if (!((msg
->bus
== 0) && (msg
->sub
== 0)))
88 if ((mockHardware
= SD(cl
)->mockHardwareBus0
[msg
->dev
]) == NULL
)
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
)
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
);
129 static int PCIMock_InitClass(LIBBASETYPEPTR LIBBASE
)
131 OOP_Object
*pci
= NULL
;
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
);
169 D(bug("[PCIMock] Driver ClassPtr = %x\n", psd
->driverClass
));
174 ADD2INITLIB(PCIMock_InitClass
, 0)
175 ADD2EXPUNGELIB(PCIMock_ExpungeClass
, 0)