1 #define __OOP_NOATTRBASES__
4 #include <utility/hooks.h>
5 #include <exec/interrupts.h>
6 #include <aros/macros.h>
10 #include <aros/asmcall.h>
12 #include <proto/oop.h>
14 #include "DriverData.h"
15 #include "pci_wrapper.h"
17 #include <aros/debug.h>
18 #define KPrintF kprintf
20 struct Library
*OOPBase
;
22 static OOP_AttrBase __IHidd_PCIDev
;
23 static OOP_Object
*pciobj
;
25 static OOP_MethodID mid_RB
;
26 static OOP_MethodID mid_RW
;
27 static OOP_MethodID mid_RL
;
29 static OOP_MethodID mid_WB
;
30 static OOP_MethodID mid_WW
;
31 static OOP_MethodID mid_WL
;
33 static BOOL inthandler_added
;
35 BOOL
ahi_pci_init(struct DriverBase
* AHIsubBase
)
37 OOPBase
= OpenLibrary(AROSOOP_NAME
, 0);
40 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
43 pciobj
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
47 mid_RB
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
48 mid_RW
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigWord
);
49 mid_RL
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigLong
);
51 mid_WB
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
52 mid_WW
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigWord
);
53 mid_WL
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigLong
);
63 void ahi_pci_exit(void)
66 OOP_DisposeObject(pciobj
);
68 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
70 CloseLibrary(OOPBase
);
76 OOP_Object
*found_dev
;
79 static AROS_UFH3(void, Enumerator
,
80 AROS_UFHA(struct Hook
*, hook
, A0
),
81 AROS_UFHA(OOP_Object
*, device
, A2
),
82 AROS_UFHA(APTR
, msg
, A1
))
86 struct enum_data
*ed
= (struct enum_data
*)hook
->h_Data
;
88 if ((ed
->found_dev
== 0) && (device
!= ed
->prev_dev
))
90 ed
->found_dev
= device
;
97 APTR
ahi_pci_find_device(ULONG vendorid
, ULONG deviceid
, APTR dev
)
101 struct Hook FindHook
=
103 h_Entry
: (HOOKFUNC
)Enumerator
,
107 struct TagItem Reqs
[] =
110 { tHidd_PCI_Class
, 0x04 }, /* Multimedia */
111 { tHidd_PCI_SubClass
, 0x01 }, /* Audio */
113 { tHidd_PCI_VendorID
, vendorid
},
114 { tHidd_PCI_ProductID
, deviceid
},
118 struct pHidd_PCI_EnumDevices enummsg
=
120 mID
: OOP_GetMethodID(CLID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
122 requirements
: (struct TagItem
*)&Reqs
,
125 ed
.prev_dev
= (OOP_Object
*)dev
;
128 OOP_DoMethod(pciobj
, (OOP_Msg
)msg
);
130 //KPrintF("ahi_pci_find_device: found_dev = %lx\n", ed.found_dev);
132 return (APTR
)ed
.found_dev
;
135 ULONG
pci_inl(ULONG addr
, struct CMI8738_DATA
*card
)
137 return LONGIN(card
->iobase
+ addr
);
140 UWORD
pci_inw(ULONG addr
, struct CMI8738_DATA
*card
)
142 return WORDIN(card
->iobase
+ addr
);
145 UBYTE
pci_inb(ULONG addr
, struct CMI8738_DATA
*card
)
147 return BYTEIN(card
->iobase
+ addr
);
150 void pci_outl(ULONG value
, ULONG addr
, struct CMI8738_DATA
*card
)
152 LONGOUT(card
->iobase
+ addr
, value
);
155 void pci_outw(UWORD value
, ULONG addr
, struct CMI8738_DATA
*card
)
157 WORDOUT(card
->iobase
+ addr
, value
);
160 void pci_outb(UBYTE value
, ULONG addr
, struct CMI8738_DATA
*card
)
162 BYTEOUT(card
->iobase
+ addr
, value
);
165 void outb_setbits(UBYTE value
, ULONG addr
, struct CMI8738_DATA
*card
)
167 UBYTE data
= pci_inb(addr
, card
);
170 pci_outb(data
, addr
, card
);
174 void outb_clearbits(UBYTE value
, ULONG addr
, struct CMI8738_DATA
*card
)
176 UBYTE data
= pci_inb(addr
, card
);
179 pci_outb(data
, addr
, card
);
183 void outw_setbits(UWORD value
, ULONG addr
, struct CMI8738_DATA
*card
)
185 UWORD data
= pci_inw(addr
, card
);
188 pci_outw(data
, addr
, card
);
192 void outw_clearbits(UWORD value
, ULONG addr
, struct CMI8738_DATA
*card
)
194 UWORD data
= pci_inw(addr
, card
);
197 pci_outw(data
, addr
, card
);
201 void outl_setbits(ULONG value
, ULONG addr
, struct CMI8738_DATA
*card
)
203 ULONG data
= pci_inl(addr
, card
);
206 pci_outl(data
, addr
, card
);
210 void outl_clearbits(ULONG value
, ULONG addr
, struct CMI8738_DATA
*card
)
212 ULONG data
= pci_inl(addr
, card
);
215 pci_outl(data
, addr
, card
);
219 ULONG
inl_config(UBYTE reg
, APTR dev
)
221 struct pHidd_PCIDevice_ReadConfigLong msg
;
226 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
229 UWORD
inw_config(UBYTE reg
, APTR dev
)
231 struct pHidd_PCIDevice_ReadConfigWord msg
;
236 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
239 UBYTE
inb_config(UBYTE reg
, APTR dev
)
241 struct pHidd_PCIDevice_ReadConfigByte msg
;
246 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
249 void outl_config(UBYTE reg
, ULONG val
, APTR dev
)
251 struct pHidd_PCIDevice_WriteConfigLong msg
;
257 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
260 void outw_config(UBYTE reg
, UWORD val
, APTR dev
)
262 struct pHidd_PCIDevice_WriteConfigWord msg
;
268 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
271 void outb_config(UBYTE reg
, UBYTE val
, APTR dev
)
273 struct pHidd_PCIDevice_WriteConfigByte msg
;
279 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
282 ULONG
ahi_pci_get_irq(APTR dev
)
286 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
291 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
295 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
297 AddIntServer(INTB_KERNEL
+ val
, i
);
299 inthandler_added
= TRUE
;
304 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
306 if (inthandler_added
)
310 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
312 RemIntServer(INTB_KERNEL
+ val
, i
);
314 inthandler_added
= FALSE
;
317 KPrintF("ahi_pci_rem_intserver\n");
321 APTR
ahi_pci_get_base_address(WORD which
, APTR dev
)
329 attr
= aHidd_PCIDevice_Base0
;
333 attr
= aHidd_PCIDevice_Base1
;
337 attr
= aHidd_PCIDevice_Base2
;
341 attr
= aHidd_PCIDevice_Base3
;
345 attr
= aHidd_PCIDevice_Base4
;
349 attr
= aHidd_PCIDevice_Base5
;
356 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
358 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
363 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
371 attr
= aHidd_PCIDevice_Size0
;
375 attr
= aHidd_PCIDevice_Size1
;
379 attr
= aHidd_PCIDevice_Size2
;
383 attr
= aHidd_PCIDevice_Size3
;
387 attr
= aHidd_PCIDevice_Size4
;
391 attr
= aHidd_PCIDevice_Size5
;
398 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
400 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
408 ULONG
ahi_pci_get_type(WORD which
, APTR dev
)
416 attr
= aHidd_PCIDevice_Type0
;
420 attr
= aHidd_PCIDevice_Type1
;
424 attr
= aHidd_PCIDevice_Type2
;
428 attr
= aHidd_PCIDevice_Type3
;
432 attr
= aHidd_PCIDevice_Type4
;
436 attr
= aHidd_PCIDevice_Type5
;
443 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
445 //KPrintF("ahi_pci_get_type. Result %lx\n", val);