grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / AHI / Drivers / HDAudio / pci_aros.c
blobe72b2d775355fc9a4bb2e4f750124a69eebdaba3
1 /*
2 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
3 http://www.aros.org/license.html
5 Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
6 ANY KIND, either express or implied. See the License for the specific language governing rights and
7 limitations under the License.
9 (C) Copyright xxxx-2009 Davy Wentzler.
10 (C) Copyright 2009-2010 Stephen Jones.
12 The Initial Developer of the Original Code is Davy Wentzler.
14 All Rights Reserved.
17 #define __OOP_NOATTRBASES__
19 #include <config.h>
21 #include <utility/hooks.h>
22 #include <exec/interrupts.h>
23 #include <asm/io.h>
24 #include <oop/oop.h>
25 #include <hidd/pci.h>
26 #include <aros/asmcall.h>
28 #include <proto/oop.h>
30 #include "DriverData.h"
31 #include "pci_wrapper.h"
33 #include <aros/debug.h>
34 #define KPrintF kprintf
36 struct Library *OOPBase;
39 static OOP_AttrBase __IHidd_PCIDev;
40 static OOP_Object *pciobj;
42 static OOP_MethodID mid_RB;
43 static OOP_MethodID mid_RW;
44 static OOP_MethodID mid_RL;
46 static OOP_MethodID mid_WB;
47 static OOP_MethodID mid_WW;
48 static OOP_MethodID mid_WL;
50 static BOOL inthandler_added;
52 BOOL ahi_pci_init(struct DriverBase* AHIsubBase)
54 OOPBase = OpenLibrary(AROSOOP_NAME, 0);
55 if (OOPBase)
57 __IHidd_PCIDev = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
58 if (__IHidd_PCIDev)
60 pciobj = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
62 if (pciobj)
64 mid_RB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigByte);
65 mid_RW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigWord);
66 mid_RL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigLong);
68 mid_WB = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigByte);
69 mid_WW = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigWord);
70 mid_WL = OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigLong);
72 return TRUE;
77 return FALSE;
80 void ahi_pci_exit(void)
82 if (pciobj)
83 OOP_DisposeObject(pciobj);
84 if (__IHidd_PCIDev)
85 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
86 if (OOPBase)
87 CloseLibrary(OOPBase);
90 struct enum_data
92 OOP_Object *prev_dev;
93 OOP_Object *found_dev;
96 static AROS_UFH3(void, Enumerator,
97 AROS_UFHA(struct Hook *, hook, A0),
98 AROS_UFHA(OOP_Object *, device, A2),
99 AROS_UFHA(APTR, msg, A1))
101 AROS_USERFUNC_INIT
103 struct enum_data *ed = (struct enum_data *)hook->h_Data;
105 if ((ed->found_dev == 0) && (device != ed->prev_dev))
107 ed->found_dev = device;
110 AROS_USERFUNC_EXIT
114 APTR ahi_pci_find_device(ULONG vendorid, ULONG deviceid, APTR dev)
116 struct enum_data ed;
118 struct Hook FindHook =
120 h_Entry: (HOOKFUNC)Enumerator,
121 h_Data: &ed,
124 struct TagItem Reqs[] =
126 #if 0
127 { tHidd_PCI_Class , 0x04 }, /* Multimedia */
128 { tHidd_PCI_SubClass , 0x01 }, /* Audio */
129 #endif
130 { tHidd_PCI_VendorID , vendorid },
131 { tHidd_PCI_ProductID , deviceid },
132 { TAG_DONE , 0 },
135 struct pHidd_PCI_EnumDevices enummsg =
137 mID: OOP_GetMethodID(CLID_Hidd_PCI, moHidd_PCI_EnumDevices),
138 callback: &FindHook,
139 requirements: (struct TagItem *)&Reqs,
140 }, *msg = &enummsg;
142 ed.prev_dev = (OOP_Object *)dev;
143 ed.found_dev = 0;
145 OOP_DoMethod(pciobj, (OOP_Msg)msg);
147 //KPrintF("ahi_pci_find_device: found_dev = %lx\n", ed.found_dev);
149 return (APTR)ed.found_dev;
152 ULONG pci_inl(ULONG addr, struct HDAudioChip *card)
154 ULONG *real_addr = (ULONG *) (card->iobase + addr); // card->iobase should be virtual
156 return *(real_addr);
159 UWORD pci_inw(ULONG addr, struct HDAudioChip *card)
161 UWORD *real_addr = (UWORD *) (card->iobase + addr);
163 return *(real_addr);
166 UBYTE pci_inb(ULONG addr, struct HDAudioChip *card)
168 UBYTE *real_addr = (UBYTE *) (card->iobase + addr);
170 return *(real_addr);
173 void pci_outl(ULONG value, ULONG addr, struct HDAudioChip *card)
175 *((ULONG *) (card->iobase + addr)) = value;
178 void pci_outw(UWORD value, ULONG addr, struct HDAudioChip *card)
180 *((UWORD *) (card->iobase + addr)) = value;
183 void pci_outb(UBYTE value, ULONG addr, struct HDAudioChip *card)
185 *((UBYTE *) (card->iobase + addr)) = value;
189 void outb_setbits(UBYTE value, ULONG addr, struct HDAudioChip *card)
191 UBYTE data = pci_inb(addr, card);
192 data |= value;
194 pci_outb(data, addr, card);
198 void outb_clearbits(UBYTE value, ULONG addr, struct HDAudioChip *card)
200 UBYTE data = pci_inb(addr, card);
201 data &= ~value;
203 pci_outb(data, addr, card);
207 void outw_setbits(UWORD value, ULONG addr, struct HDAudioChip *card)
209 UWORD data = pci_inw(addr, card);
210 data |= value;
212 pci_outw(data, addr, card);
216 void outw_clearbits(UWORD value, ULONG addr, struct HDAudioChip *card)
218 UWORD data = pci_inw(addr, card);
219 data &= ~value;
221 pci_outw(data, addr, card);
225 void outl_setbits(ULONG value, ULONG addr, struct HDAudioChip *card)
227 ULONG data = pci_inl(addr, card);
228 data |= value;
230 pci_outl(data, addr, card);
234 void outl_clearbits(ULONG value, ULONG addr, struct HDAudioChip *card)
236 ULONG data = pci_inl(addr, card);
237 data &= ~value;
239 pci_outl(data, addr, card);
243 ULONG inl_config(UBYTE reg, APTR dev)
245 struct pHidd_PCIDevice_ReadConfigLong msg;
247 msg.mID = mid_RL;
248 msg.reg = reg;
250 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
253 UWORD inw_config(UBYTE reg, APTR dev)
255 struct pHidd_PCIDevice_ReadConfigWord msg;
257 msg.mID = mid_RW;
258 msg.reg = reg;
260 return OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
263 UBYTE inb_config(UBYTE reg, APTR dev)
265 struct pHidd_PCIDevice_ReadConfigByte msg;
267 msg.mID = mid_RB;
268 msg.reg = reg;
270 return OOP_DoMethod(dev, (OOP_Msg)&msg);
273 void outl_config(UBYTE reg, ULONG val, APTR dev)
275 struct pHidd_PCIDevice_WriteConfigLong msg;
277 msg.mID = mid_WL;
278 msg.reg = reg;
279 msg.val = val;
281 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
284 void outw_config(UBYTE reg, UWORD val, APTR dev)
286 struct pHidd_PCIDevice_WriteConfigWord msg;
288 msg.mID = mid_WW;
289 msg.reg = reg;
290 msg.val = val;
292 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
295 void outb_config(UBYTE reg, UBYTE val, APTR dev)
297 struct pHidd_PCIDevice_WriteConfigByte msg;
299 msg.mID = mid_WB;
300 msg.reg = reg;
301 msg.val = val;
303 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
306 ULONG ahi_pci_get_irq(APTR dev)
308 IPTR val;
310 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
312 return (ULONG)val;
315 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
317 IPTR val;
319 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
321 AddIntServer(INTB_KERNEL + val, i);
323 inthandler_added = TRUE;
325 return TRUE;
328 void ahi_pci_rem_intserver(struct Interrupt *i, APTR dev)
330 if (inthandler_added)
332 IPTR val;
334 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
336 RemIntServer(INTB_KERNEL + val, i);
338 inthandler_added = FALSE;
341 D(bug("[HDAudio] ahi_pci_rem_intserver\n"));
345 APTR ahi_pci_get_base_address(WORD which, APTR dev)
347 OOP_AttrID attr = 0;
348 IPTR val = 0;
350 switch(which)
352 case 0:
353 attr = aHidd_PCIDevice_Base0;
354 break;
356 case 1:
357 attr = aHidd_PCIDevice_Base1;
358 break;
360 case 2:
361 attr = aHidd_PCIDevice_Base2;
362 break;
364 case 3:
365 attr = aHidd_PCIDevice_Base3;
366 break;
368 case 4:
369 attr = aHidd_PCIDevice_Base4;
370 break;
372 case 5:
373 attr = aHidd_PCIDevice_Base5;
374 break;
376 default:
377 return 0;
380 OOP_GetAttr((OOP_Object *)dev, attr, &val);
382 D(bug("[HDAudio] ahi_pci_get_base_address. Result %lx\n", val));
384 return (APTR)val;
387 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
389 OOP_AttrID attr = 0;
390 IPTR val = 0;
392 switch(which)
394 case 0:
395 attr = aHidd_PCIDevice_Size0;
396 break;
398 case 1:
399 attr = aHidd_PCIDevice_Size1;
400 break;
402 case 2:
403 attr = aHidd_PCIDevice_Size2;
404 break;
406 case 3:
407 attr = aHidd_PCIDevice_Size3;
408 break;
410 case 4:
411 attr = aHidd_PCIDevice_Size4;
412 break;
414 case 5:
415 attr = aHidd_PCIDevice_Size5;
416 break;
418 default:
419 return 0;
422 OOP_GetAttr((OOP_Object *)dev, attr, &val);
424 D(bug("[HDAudio] ahi_pci_get_base_size. Result %lx\n", val));
426 return (ULONG)val;
432 ULONG ahi_pci_get_type(WORD which, APTR dev)
434 OOP_AttrID attr = 0;
435 IPTR val = 0;
437 switch(which)
439 case 0:
440 attr = aHidd_PCIDevice_Type0;
441 break;
443 case 1:
444 attr = aHidd_PCIDevice_Type1;
445 break;
447 case 2:
448 attr = aHidd_PCIDevice_Type2;
449 break;
451 case 3:
452 attr = aHidd_PCIDevice_Type3;
453 break;
455 case 4:
456 attr = aHidd_PCIDevice_Type4;
457 break;
459 case 5:
460 attr = aHidd_PCIDevice_Type5;
461 break;
463 default:
464 return 0;
467 OOP_GetAttr((OOP_Object *)dev, attr, &val);
469 D(bug("[HDAudio] ahi_pci_get_type. Result %lx\n", val));
471 return (ULONG) val;