Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / SB128 / pci_aros.c
blobf38b36c5a281029d1c87117c26dd8eade4ce3231
1 /*
3 The contents of this file are subject to the AROS Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4 http://www.aros.org/license.html
6 Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
7 ANY KIND, either express or implied. See the License for the specific language governing rights and
8 limitations under the License.
10 The Original Code is (C) Copyright 2004-2011 Ross Vumbaca.
12 The Initial Developer of the Original Code is Ross Vumbaca.
14 All Rights Reserved.
18 #define __OOP_NOATTRBASES__
20 #include <aros/debug.h>
22 #include <utility/hooks.h>
23 #include <exec/interrupts.h>
24 #include <aros/macros.h>
25 #include <aros/io.h>
26 #include <oop/oop.h>
27 #include <hidd/pci.h>
28 #include <aros/asmcall.h>
30 #include <proto/oop.h>
32 #include "DriverData.h"
33 #include "pci_wrapper.h"
35 struct Library *OOPBase;
37 static OOP_AttrBase __IHidd_PCIDev;
38 static OOP_Object *pciobj;
40 static OOP_MethodID mid_RB;
41 static OOP_MethodID mid_RW;
42 static OOP_MethodID mid_RL;
44 static OOP_MethodID mid_WB;
45 static OOP_MethodID mid_WW;
46 static OOP_MethodID mid_WL;
48 static BOOL inthandler_added;
50 BOOL ahi_pci_init(struct DriverBase* AHIsubBase)
52 OOPBase = OpenLibrary(AROSOOP_NAME, 0);
53 if (OOPBase)
55 __IHidd_PCIDev = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
56 if (__IHidd_PCIDev)
58 pciobj = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
60 if (pciobj)
62 mid_RB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigByte);
63 mid_RW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigWord);
64 mid_RL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigLong);
66 mid_WB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigByte);
67 mid_WW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigWord);
68 mid_WL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigLong);
70 return TRUE;
75 return FALSE;
78 void ahi_pci_exit(void)
80 if (pciobj)
81 OOP_DisposeObject(pciobj);
82 if (__IHidd_PCIDev)
83 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
84 if (OOPBase)
85 CloseLibrary(OOPBase);
88 struct enum_data
90 OOP_Object *prev_dev;
91 OOP_Object *found_dev;
94 static AROS_UFH3(void, Enumerator,
95 AROS_UFHA(struct Hook *, hook, A0),
96 AROS_UFHA(OOP_Object *, device, A2),
97 AROS_UFHA(APTR, msg, A1))
99 AROS_USERFUNC_INIT
101 struct enum_data *ed = (struct enum_data *)hook->h_Data;
103 if ((ed->found_dev == 0) && (device != ed->prev_dev))
105 ed->found_dev = device;
108 AROS_USERFUNC_EXIT
112 APTR ahi_pci_find_device(ULONG vendorid, ULONG deviceid, APTR dev)
114 struct enum_data ed;
116 struct Hook FindHook =
118 h_Entry: (HOOKFUNC)Enumerator,
119 h_Data: &ed,
122 struct TagItem Reqs[] =
124 #if 0
125 { tHidd_PCI_Class , 0x04 }, /* Multimedia */
126 { tHidd_PCI_SubClass , 0x01 }, /* Audio */
127 #endif
128 { tHidd_PCI_VendorID , vendorid },
129 { tHidd_PCI_ProductID , deviceid },
130 { TAG_DONE , 0 },
133 struct pHidd_PCI_EnumDevices enummsg =
135 mID: OOP_GetMethodID(CLID_Hidd_PCI, moHidd_PCI_EnumDevices),
136 callback: &FindHook,
137 requirements: (struct TagItem *)&Reqs,
138 }, *msg = &enummsg;
140 ed.prev_dev = (OOP_Object *)dev;
141 ed.found_dev = 0;
143 OOP_DoMethod(pciobj, (OOP_Msg)msg);
145 D(bug("[SB128] ahi_pci_find_device: found_dev = %lx\n", ed.found_dev));
147 return (APTR)ed.found_dev;
150 ULONG pci_inl(ULONG addr, struct SB128_DATA *card)
152 return LONGIN(card->iobase + addr);
155 UWORD pci_inw(ULONG addr, struct SB128_DATA *card)
157 return WORDIN(card->iobase + addr);
160 UBYTE pci_inb(ULONG addr, struct SB128_DATA *card)
162 return BYTEIN(card->iobase + addr);
165 void pci_outl(ULONG value, ULONG addr, struct SB128_DATA *card)
167 LONGOUT(card->iobase + addr, value);
170 void pci_outw(UWORD value, ULONG addr, struct SB128_DATA *card)
172 WORDOUT(card->iobase + addr, value);
175 void pci_outb(UBYTE value, ULONG addr, struct SB128_DATA *card)
177 BYTEOUT(card->iobase + addr, value);
180 void outb_setbits(UBYTE value, ULONG addr, struct SB128_DATA *card)
182 UBYTE data = pci_inb(addr, card);
183 data |= value;
185 pci_outb(data, addr, card);
189 void outb_clearbits(UBYTE value, ULONG addr, struct SB128_DATA *card)
191 UBYTE data = pci_inb(addr, card);
192 data &= ~value;
194 pci_outb(data, addr, card);
198 void outw_setbits(UWORD value, ULONG addr, struct SB128_DATA *card)
200 UWORD data = pci_inw(addr, card);
201 data |= value;
203 pci_outw(data, addr, card);
207 void outw_clearbits(UWORD value, ULONG addr, struct SB128_DATA *card)
209 UWORD data = pci_inw(addr, card);
210 data &= ~value;
212 pci_outw(data, addr, card);
216 void outl_setbits(ULONG value, ULONG addr, struct SB128_DATA *card)
218 ULONG data = pci_inl(addr, card);
219 data |= value;
221 pci_outl(data, addr, card);
225 void outl_clearbits(ULONG value, ULONG addr, struct SB128_DATA *card)
227 ULONG data = pci_inl(addr, card);
228 data &= ~value;
230 pci_outl(data, addr, card);
234 ULONG inl_config(UBYTE reg, APTR dev)
236 struct pHidd_PCIDevice_ReadConfigLong msg;
238 msg.mID = mid_RL;
239 msg.reg = reg;
241 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
244 UWORD inw_config(UBYTE reg, APTR dev)
246 struct pHidd_PCIDevice_ReadConfigWord msg;
248 msg.mID = mid_RW;
249 msg.reg = reg;
251 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
254 UBYTE inb_config(UBYTE reg, APTR dev)
256 struct pHidd_PCIDevice_ReadConfigByte msg;
258 msg.mID = mid_RB;
259 msg.reg = reg;
261 return OOP_DoMethod(dev, (OOP_Msg)&msg);
264 void outl_config(UBYTE reg, ULONG val, APTR dev)
266 struct pHidd_PCIDevice_WriteConfigLong msg;
268 msg.mID = mid_WL;
269 msg.reg = reg;
270 msg.val = val;
272 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
275 void outw_config(UBYTE reg, UWORD val, APTR dev)
277 struct pHidd_PCIDevice_WriteConfigWord msg;
279 msg.mID = mid_WW;
280 msg.reg = reg;
281 msg.val = val;
283 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
286 void outb_config(UBYTE reg, UBYTE val, APTR dev)
288 struct pHidd_PCIDevice_WriteConfigByte msg;
290 msg.mID = mid_WB;
291 msg.reg = reg;
292 msg.val = val;
294 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
297 ULONG ahi_pci_get_irq(APTR dev)
299 IPTR val;
301 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
303 return (ULONG)val;
306 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
308 IPTR val;
310 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
312 AddIntServer(INTB_KERNEL + val, i);
314 inthandler_added = TRUE;
316 return TRUE;
319 void ahi_pci_rem_intserver(struct Interrupt *i, APTR dev)
321 if (inthandler_added)
323 IPTR val;
325 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
327 RemIntServer(INTB_KERNEL + val, i);
329 inthandler_added = FALSE;
332 //KPrintF("ahi_pci_rem_intserver\n");
336 APTR ahi_pci_get_base_address(WORD which, APTR dev)
338 OOP_AttrID attr = 0;
339 IPTR val = 0;
341 switch(which)
343 case 0:
344 attr = aHidd_PCIDevice_Base0;
345 break;
347 case 1:
348 attr = aHidd_PCIDevice_Base1;
349 break;
351 case 2:
352 attr = aHidd_PCIDevice_Base2;
353 break;
355 case 3:
356 attr = aHidd_PCIDevice_Base3;
357 break;
359 case 4:
360 attr = aHidd_PCIDevice_Base4;
361 break;
363 case 5:
364 attr = aHidd_PCIDevice_Base5;
365 break;
367 default:
368 return 0;
371 OOP_GetAttr((OOP_Object *)dev, attr, &val);
373 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
375 return (APTR)val;
378 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
380 OOP_AttrID attr = 0;
381 IPTR val = 0;
383 switch(which)
385 case 0:
386 attr = aHidd_PCIDevice_Size0;
387 break;
389 case 1:
390 attr = aHidd_PCIDevice_Size1;
391 break;
393 case 2:
394 attr = aHidd_PCIDevice_Size2;
395 break;
397 case 3:
398 attr = aHidd_PCIDevice_Size3;
399 break;
401 case 4:
402 attr = aHidd_PCIDevice_Size4;
403 break;
405 case 5:
406 attr = aHidd_PCIDevice_Size5;
407 break;
409 default:
410 return 0;
413 OOP_GetAttr((OOP_Object *)dev, attr, &val);
415 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
417 return (ULONG)val;
423 ULONG ahi_pci_get_type(WORD which, APTR dev)
425 OOP_AttrID attr = 0;
426 IPTR val = 0;
428 switch(which)
430 case 0:
431 attr = aHidd_PCIDevice_Type0;
432 break;
434 case 1:
435 attr = aHidd_PCIDevice_Type1;
436 break;
438 case 2:
439 attr = aHidd_PCIDevice_Type2;
440 break;
442 case 3:
443 attr = aHidd_PCIDevice_Type3;
444 break;
446 case 4:
447 attr = aHidd_PCIDevice_Type4;
448 break;
450 case 5:
451 attr = aHidd_PCIDevice_Type5;
452 break;
454 default:
455 return 0;
458 OOP_GetAttr((OOP_Object *)dev, attr, &val);
460 //KPrintF("ahi_pci_get_type. Result %lx\n", val);
462 return (ULONG) val;