Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / Envy24HT / pci_aros.c
blob90169fa88ff8a8f8a42f3466eaa5ccd2b75c0677
1 /*
2 Copyright © 2004-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define __OOP_NOATTRBASES__
9 #include <utility/hooks.h>
10 #include <exec/interrupts.h>
11 #include <aros/macros.h>
12 #include <aros/io.h>
13 #include <oop/oop.h>
14 #include <hidd/pci.h>
15 #include <aros/asmcall.h>
17 #include <proto/oop.h>
19 #include "DriverData.h"
20 #include "pci_wrapper.h"
22 #include <aros/debug.h>
23 #define KPrintF kprintf
25 struct Library *OOPBase;
27 static OOP_AttrBase __IHidd_PCIDev;
28 static OOP_Object *pciobj;
30 static OOP_MethodID mid_RB;
31 static OOP_MethodID mid_RW;
32 static OOP_MethodID mid_RL;
34 static OOP_MethodID mid_WB;
35 static OOP_MethodID mid_WW;
36 static OOP_MethodID mid_WL;
38 static BOOL inthandler_added;
40 BOOL ahi_pci_init(struct DriverBase* AHIsubBase)
42 OOPBase = OpenLibrary(AROSOOP_NAME, 0);
43 if (OOPBase)
45 __IHidd_PCIDev = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
46 if (__IHidd_PCIDev)
48 pciobj = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
50 if (pciobj)
52 mid_RB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigByte);
53 mid_RW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigWord);
54 mid_RL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigLong);
56 mid_WB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigByte);
57 mid_WW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigWord);
58 mid_WL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigLong);
60 return TRUE;
65 return FALSE;
68 void ahi_pci_exit(void)
70 if (pciobj)
71 OOP_DisposeObject(pciobj);
72 if (__IHidd_PCIDev)
73 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
74 if (OOPBase)
75 CloseLibrary(OOPBase);
78 struct enum_data
80 OOP_Object *prev_dev;
81 OOP_Object *found_dev;
84 static AROS_UFH3(void, Enumerator,
85 AROS_UFHA(struct Hook *, hook, A0),
86 AROS_UFHA(OOP_Object *, device, A2),
87 AROS_UFHA(APTR, msg, A1))
89 AROS_USERFUNC_INIT
91 struct enum_data *ed = (struct enum_data *)hook->h_Data;
93 if ((ed->found_dev == 0) && (device != ed->prev_dev))
95 ed->found_dev = device;
98 AROS_USERFUNC_EXIT
102 APTR ahi_pci_find_device(ULONG vendorid, ULONG deviceid, APTR dev)
104 struct enum_data ed;
106 struct Hook FindHook =
108 h_Entry: (HOOKFUNC)Enumerator,
109 h_Data: &ed,
112 struct TagItem Reqs[] =
114 #if 0
115 { tHidd_PCI_Class , 0x04 }, /* Multimedia */
116 { tHidd_PCI_SubClass , 0x01 }, /* Audio */
117 #endif
118 { tHidd_PCI_VendorID , vendorid },
119 { tHidd_PCI_ProductID , deviceid },
120 { TAG_DONE , 0 },
123 struct pHidd_PCI_EnumDevices enummsg =
125 mID: OOP_GetMethodID(CLID_Hidd_PCI, moHidd_PCI_EnumDevices),
126 callback: &FindHook,
127 requirements: (struct TagItem *)&Reqs,
128 }, *msg = &enummsg;
130 ed.prev_dev = (OOP_Object *)dev;
131 ed.found_dev = 0;
133 OOP_DoMethod(pciobj, (OOP_Msg)msg);
135 //KPrintF("ahi_pci_find_device: found_dev = %lx\n", ed.found_dev);
137 return (APTR)ed.found_dev;
140 ULONG pci_inl(ULONG addr, struct CardData *card)
142 return LONGIN(card->iobase + addr);
145 UWORD pci_inw(ULONG addr, struct CardData *card)
147 return WORDIN(card->iobase + addr);
150 UBYTE pci_inb(ULONG addr, struct CardData *card)
152 return BYTEIN(card->iobase + addr);
155 void pci_outl(ULONG value, ULONG addr, struct CardData *card)
157 LONGOUT(card->iobase + addr, value);
160 void pci_outw(UWORD value, ULONG addr, struct CardData *card)
162 WORDOUT(card->iobase + addr, value);
165 void pci_outb(UBYTE value, ULONG addr, struct CardData *card)
167 BYTEOUT(card->iobase + addr, value);
170 void outb_setbits(UBYTE value, ULONG addr, struct CardData *card)
172 UBYTE data = pci_inb(addr, card);
173 data |= value;
175 pci_outb(data, addr, card);
179 void outb_clearbits(UBYTE value, ULONG addr, struct CardData *card)
181 UBYTE data = pci_inb(addr, card);
182 data &= ~value;
184 pci_outb(data, addr, card);
188 void outw_setbits(UWORD value, ULONG addr, struct CardData *card)
190 UWORD data = pci_inw(addr, card);
191 data |= value;
193 pci_outw(data, addr, card);
197 void outw_clearbits(UWORD value, ULONG addr, struct CardData *card)
199 UWORD data = pci_inw(addr, card);
200 data &= ~value;
202 pci_outw(data, addr, card);
206 void outl_setbits(ULONG value, ULONG addr, struct CardData *card)
208 ULONG data = pci_inl(addr, card);
209 data |= value;
211 pci_outl(data, addr, card);
215 void outl_clearbits(ULONG value, ULONG addr, struct CardData *card)
217 ULONG data = pci_inl(addr, card);
218 data &= ~value;
220 pci_outl(data, addr, card);
224 ULONG inl_config(UBYTE reg, APTR dev)
226 struct pHidd_PCIDevice_ReadConfigLong msg;
228 msg.mID = mid_RL;
229 msg.reg = reg;
231 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
234 UWORD inw_config(UBYTE reg, APTR dev)
236 struct pHidd_PCIDevice_ReadConfigWord msg;
238 msg.mID = mid_RW;
239 msg.reg = reg;
241 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
244 UBYTE inb_config(UBYTE reg, APTR dev)
246 struct pHidd_PCIDevice_ReadConfigByte msg;
248 msg.mID = mid_RB;
249 msg.reg = reg;
251 return OOP_DoMethod(dev, (OOP_Msg)&msg);
254 void outl_config(UBYTE reg, ULONG val, APTR dev)
256 struct pHidd_PCIDevice_WriteConfigLong msg;
258 msg.mID = mid_WL;
259 msg.reg = reg;
260 msg.val = val;
262 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
265 void outw_config(UBYTE reg, UWORD val, APTR dev)
267 struct pHidd_PCIDevice_WriteConfigWord msg;
269 msg.mID = mid_WW;
270 msg.reg = reg;
271 msg.val = val;
273 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
276 void outb_config(UBYTE reg, UBYTE val, APTR dev)
278 struct pHidd_PCIDevice_WriteConfigByte msg;
280 msg.mID = mid_WB;
281 msg.reg = reg;
282 msg.val = val;
284 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
287 ULONG ahi_pci_get_irq(APTR dev)
289 IPTR val;
291 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
293 return (ULONG)val;
296 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
298 IPTR val;
300 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
302 AddIntServer(INTB_KERNEL + val, i);
304 inthandler_added = TRUE;
306 return TRUE;
309 void ahi_pci_rem_intserver(struct Interrupt *i, APTR dev)
311 if (inthandler_added)
313 IPTR val;
315 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
317 RemIntServer(INTB_KERNEL + val, i);
319 inthandler_added = FALSE;
322 KPrintF("ahi_pci_rem_intserver\n");
326 APTR ahi_pci_get_base_address(WORD which, APTR dev)
328 OOP_AttrID attr = 0;
329 IPTR val = 0;
331 switch(which)
333 case 0:
334 attr = aHidd_PCIDevice_Base0;
335 break;
337 case 1:
338 attr = aHidd_PCIDevice_Base1;
339 break;
341 case 2:
342 attr = aHidd_PCIDevice_Base2;
343 break;
345 case 3:
346 attr = aHidd_PCIDevice_Base3;
347 break;
349 case 4:
350 attr = aHidd_PCIDevice_Base4;
351 break;
353 case 5:
354 attr = aHidd_PCIDevice_Base5;
355 break;
357 default:
358 return 0;
361 OOP_GetAttr((OOP_Object *)dev, attr, &val);
363 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
365 return (APTR)val;
368 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
370 OOP_AttrID attr = 0;
371 IPTR val = 0;
373 switch(which)
375 case 0:
376 attr = aHidd_PCIDevice_Size0;
377 break;
379 case 1:
380 attr = aHidd_PCIDevice_Size1;
381 break;
383 case 2:
384 attr = aHidd_PCIDevice_Size2;
385 break;
387 case 3:
388 attr = aHidd_PCIDevice_Size3;
389 break;
391 case 4:
392 attr = aHidd_PCIDevice_Size4;
393 break;
395 case 5:
396 attr = aHidd_PCIDevice_Size5;
397 break;
399 default:
400 return 0;
403 OOP_GetAttr((OOP_Object *)dev, attr, &val);
405 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
407 return (ULONG)val;
413 ULONG ahi_pci_get_type(WORD which, APTR dev)
415 OOP_AttrID attr = 0;
416 IPTR val = 0;
418 switch(which)
420 case 0:
421 attr = aHidd_PCIDevice_Type0;
422 break;
424 case 1:
425 attr = aHidd_PCIDevice_Type1;
426 break;
428 case 2:
429 attr = aHidd_PCIDevice_Type2;
430 break;
432 case 3:
433 attr = aHidd_PCIDevice_Type3;
434 break;
436 case 4:
437 attr = aHidd_PCIDevice_Type4;
438 break;
440 case 5:
441 attr = aHidd_PCIDevice_Type5;
442 break;
444 default:
445 return 0;
448 OOP_GetAttr((OOP_Object *)dev, attr, &val);
450 //KPrintF("ahi_pci_get_type. Result %lx\n", val);
452 return (ULONG) val;