grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / AHI / Drivers / Envy24 / pci_aros.c
blobb938198f02b00e4a10602c770c10fe64a79f0fbd
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 DebugPrintF
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 pci_inl_mt(ULONG addr, struct CardData *card)
226 return LONGIN(card->mtbase + addr);
229 UWORD pci_inw_mt(ULONG addr, struct CardData *card)
231 return WORDIN(card->mtbase + addr);
234 UBYTE pci_inb_mt(ULONG addr, struct CardData *card)
236 return BYTEIN(card->mtbase + addr);
239 void pci_outl_mt(ULONG value, ULONG addr, struct CardData *card)
241 LONGOUT(card->mtbase + addr, value);
244 void pci_outw_mt(UWORD value, ULONG addr, struct CardData *card)
246 WORDOUT(card->mtbase + addr, value);
249 void pci_outb_mt(UBYTE value, ULONG addr, struct CardData *card)
251 BYTEOUT(card->mtbase + addr, value);
254 ULONG inl_config(UBYTE reg, APTR dev)
256 struct pHidd_PCIDevice_ReadConfigLong msg;
258 msg.mID = mid_RL;
259 msg.reg = reg;
261 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
264 UWORD inw_config(UBYTE reg, APTR dev)
266 struct pHidd_PCIDevice_ReadConfigWord msg;
268 msg.mID = mid_RW;
269 msg.reg = reg;
271 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
274 UBYTE inb_config(UBYTE reg, APTR dev)
276 struct pHidd_PCIDevice_ReadConfigByte msg;
278 msg.mID = mid_RB;
279 msg.reg = reg;
281 return OOP_DoMethod(dev, (OOP_Msg)&msg);
284 void outl_config(UBYTE reg, ULONG val, APTR dev)
286 struct pHidd_PCIDevice_WriteConfigLong msg;
288 msg.mID = mid_WL;
289 msg.reg = reg;
290 msg.val = val;
292 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
295 void outw_config(UBYTE reg, UWORD val, APTR dev)
297 struct pHidd_PCIDevice_WriteConfigWord msg;
299 msg.mID = mid_WW;
300 msg.reg = reg;
301 msg.val = val;
303 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
306 void outb_config(UBYTE reg, UBYTE val, APTR dev)
308 struct pHidd_PCIDevice_WriteConfigByte msg;
310 msg.mID = mid_WB;
311 msg.reg = reg;
312 msg.val = val;
314 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
317 ULONG ahi_pci_get_irq(APTR dev)
319 IPTR val;
321 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
323 return (ULONG)val;
326 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
328 IPTR val;
330 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
332 AddIntServer(INTB_KERNEL + val, i);
334 inthandler_added = TRUE;
336 return TRUE;
339 void ahi_pci_rem_intserver(struct Interrupt *i, APTR dev)
341 if (inthandler_added)
343 IPTR val;
345 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
347 RemIntServer(INTB_KERNEL + val, i);
349 inthandler_added = FALSE;
352 KPrintF("ahi_pci_rem_intserver\n");
355 APTR ahi_pci_logic_to_physic_addr(APTR addr, APTR dev)
357 struct pHidd_PCIDriver_CPUtoPCI __msg__, *msg = &__msg__;
358 IPTR driverobj, retval;
360 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_Driver, &driverobj);
362 msg->mID = OOP_GetMethodID(IID_Hidd_PCIDriver, moHidd_PCIDriver_CPUtoPCI);
363 msg->address = addr;
365 KPrintF("ahi_pci_logic_to_physic_addr(%lx)\n", msg->address);
367 retval = OOP_DoMethod((OOP_Object *)driverobj, (OOP_Msg)msg);
369 KPrintF("ahi_pci_logic_to_physic_addr(%lx) = %lx\n", msg->address, retval);
371 return (APTR)retval;
374 APTR ahi_pci_get_base_address(WORD which, APTR dev)
376 OOP_AttrID attr = 0;
377 IPTR val = 0;
379 switch(which)
381 case 0:
382 attr = aHidd_PCIDevice_Base0;
383 break;
385 case 1:
386 attr = aHidd_PCIDevice_Base1;
387 break;
389 case 2:
390 attr = aHidd_PCIDevice_Base2;
391 break;
393 case 3:
394 attr = aHidd_PCIDevice_Base3;
395 break;
397 case 4:
398 attr = aHidd_PCIDevice_Base4;
399 break;
401 case 5:
402 attr = aHidd_PCIDevice_Base5;
403 break;
405 default:
406 return 0;
409 OOP_GetAttr((OOP_Object *)dev, attr, &val);
411 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
413 return (APTR)val;
416 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
418 OOP_AttrID attr = 0;
419 IPTR val = 0;
421 switch(which)
423 case 0:
424 attr = aHidd_PCIDevice_Size0;
425 break;
427 case 1:
428 attr = aHidd_PCIDevice_Size1;
429 break;
431 case 2:
432 attr = aHidd_PCIDevice_Size2;
433 break;
435 case 3:
436 attr = aHidd_PCIDevice_Size3;
437 break;
439 case 4:
440 attr = aHidd_PCIDevice_Size4;
441 break;
443 case 5:
444 attr = aHidd_PCIDevice_Size5;
445 break;
447 default:
448 return 0;
451 OOP_GetAttr((OOP_Object *)dev, attr, &val);
453 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
455 return (ULONG)val;
461 ULONG ahi_pci_get_type(WORD which, APTR dev)
463 OOP_AttrID attr = 0;
464 IPTR val = 0;
466 switch(which)
468 case 0:
469 attr = aHidd_PCIDevice_Type0;
470 break;
472 case 1:
473 attr = aHidd_PCIDevice_Type1;
474 break;
476 case 2:
477 attr = aHidd_PCIDevice_Type2;
478 break;
480 case 3:
481 attr = aHidd_PCIDevice_Type3;
482 break;
484 case 4:
485 attr = aHidd_PCIDevice_Type4;
486 break;
488 case 5:
489 attr = aHidd_PCIDevice_Type5;
490 break;
492 default:
493 return 0;
496 OOP_GetAttr((OOP_Object *)dev, attr, &val);
498 //KPrintF("ahi_pci_get_type. Result %lx\n", val);
500 return (ULONG) val;