Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / CMI8738 / pci_aros.c
blobd47374db87a2037acd81122ec639bce8c002a11a
1 #define __OOP_NOATTRBASES__
4 #include <utility/hooks.h>
5 #include <exec/interrupts.h>
6 #include <aros/macros.h>
7 #include <aros/io.h>
8 #include <oop/oop.h>
9 #include <hidd/pci.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);
38 if (OOPBase)
40 __IHidd_PCIDev = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
41 if (__IHidd_PCIDev)
43 pciobj = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
45 if (pciobj)
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);
55 return TRUE;
60 return FALSE;
63 void ahi_pci_exit(void)
65 if (pciobj)
66 OOP_DisposeObject(pciobj);
67 if (__IHidd_PCIDev)
68 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
69 if (OOPBase)
70 CloseLibrary(OOPBase);
73 struct enum_data
75 OOP_Object *prev_dev;
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))
84 AROS_USERFUNC_INIT
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;
93 AROS_USERFUNC_EXIT
97 APTR ahi_pci_find_device(ULONG vendorid, ULONG deviceid, APTR dev)
99 struct enum_data ed;
101 struct Hook FindHook =
103 h_Entry: (HOOKFUNC)Enumerator,
104 h_Data: &ed,
107 struct TagItem Reqs[] =
109 #if 0
110 { tHidd_PCI_Class , 0x04 }, /* Multimedia */
111 { tHidd_PCI_SubClass , 0x01 }, /* Audio */
112 #endif
113 { tHidd_PCI_VendorID , vendorid },
114 { tHidd_PCI_ProductID , deviceid },
115 { TAG_DONE , 0 },
118 struct pHidd_PCI_EnumDevices enummsg =
120 mID: OOP_GetMethodID(CLID_Hidd_PCI, moHidd_PCI_EnumDevices),
121 callback: &FindHook,
122 requirements: (struct TagItem *)&Reqs,
123 }, *msg = &enummsg;
125 ed.prev_dev = (OOP_Object *)dev;
126 ed.found_dev = 0;
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);
168 data |= value;
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);
177 data &= ~value;
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);
186 data |= value;
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);
195 data &= ~value;
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);
204 data |= value;
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);
213 data &= ~value;
215 pci_outl(data, addr, card);
219 ULONG inl_config(UBYTE reg, APTR dev)
221 struct pHidd_PCIDevice_ReadConfigLong msg;
223 msg.mID = mid_RL;
224 msg.reg = reg;
226 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
229 UWORD inw_config(UBYTE reg, APTR dev)
231 struct pHidd_PCIDevice_ReadConfigWord msg;
233 msg.mID = mid_RW;
234 msg.reg = reg;
236 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
239 UBYTE inb_config(UBYTE reg, APTR dev)
241 struct pHidd_PCIDevice_ReadConfigByte msg;
243 msg.mID = mid_RB;
244 msg.reg = reg;
246 return OOP_DoMethod(dev, (OOP_Msg)&msg);
249 void outl_config(UBYTE reg, ULONG val, APTR dev)
251 struct pHidd_PCIDevice_WriteConfigLong msg;
253 msg.mID = mid_WL;
254 msg.reg = reg;
255 msg.val = val;
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;
264 msg.mID = mid_WW;
265 msg.reg = reg;
266 msg.val = val;
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;
275 msg.mID = mid_WB;
276 msg.reg = reg;
277 msg.val = val;
279 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
282 ULONG ahi_pci_get_irq(APTR dev)
284 IPTR val;
286 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
288 return (ULONG)val;
291 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
293 IPTR val;
295 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
297 AddIntServer(INTB_KERNEL + val, i);
299 inthandler_added = TRUE;
301 return TRUE;
304 void ahi_pci_rem_intserver(struct Interrupt *i, APTR dev)
306 if (inthandler_added)
308 IPTR val;
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)
323 OOP_AttrID attr = 0;
324 IPTR val = 0;
326 switch(which)
328 case 0:
329 attr = aHidd_PCIDevice_Base0;
330 break;
332 case 1:
333 attr = aHidd_PCIDevice_Base1;
334 break;
336 case 2:
337 attr = aHidd_PCIDevice_Base2;
338 break;
340 case 3:
341 attr = aHidd_PCIDevice_Base3;
342 break;
344 case 4:
345 attr = aHidd_PCIDevice_Base4;
346 break;
348 case 5:
349 attr = aHidd_PCIDevice_Base5;
350 break;
352 default:
353 return 0;
356 OOP_GetAttr((OOP_Object *)dev, attr, &val);
358 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
360 return (APTR)val;
363 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
365 OOP_AttrID attr = 0;
366 IPTR val = 0;
368 switch(which)
370 case 0:
371 attr = aHidd_PCIDevice_Size0;
372 break;
374 case 1:
375 attr = aHidd_PCIDevice_Size1;
376 break;
378 case 2:
379 attr = aHidd_PCIDevice_Size2;
380 break;
382 case 3:
383 attr = aHidd_PCIDevice_Size3;
384 break;
386 case 4:
387 attr = aHidd_PCIDevice_Size4;
388 break;
390 case 5:
391 attr = aHidd_PCIDevice_Size5;
392 break;
394 default:
395 return 0;
398 OOP_GetAttr((OOP_Object *)dev, attr, &val);
400 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
402 return (ULONG)val;
408 ULONG ahi_pci_get_type(WORD which, APTR dev)
410 OOP_AttrID attr = 0;
411 IPTR val = 0;
413 switch(which)
415 case 0:
416 attr = aHidd_PCIDevice_Type0;
417 break;
419 case 1:
420 attr = aHidd_PCIDevice_Type1;
421 break;
423 case 2:
424 attr = aHidd_PCIDevice_Type2;
425 break;
427 case 3:
428 attr = aHidd_PCIDevice_Type3;
429 break;
431 case 4:
432 attr = aHidd_PCIDevice_Type4;
433 break;
435 case 5:
436 attr = aHidd_PCIDevice_Type5;
437 break;
439 default:
440 return 0;
443 OOP_GetAttr((OOP_Object *)dev, attr, &val);
445 //KPrintF("ahi_pci_get_type. Result %lx\n", val);
447 return (ULONG) val;