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.
17 #define __OOP_NOATTRBASES__
21 #include <utility/hooks.h>
22 #include <exec/interrupts.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);
57 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
60 pciobj
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
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
);
80 void ahi_pci_exit(void)
83 OOP_DisposeObject(pciobj
);
85 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
87 CloseLibrary(OOPBase
);
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
))
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
;
114 APTR
ahi_pci_find_device(ULONG vendorid
, ULONG deviceid
, APTR dev
)
118 struct Hook FindHook
=
120 h_Entry
: (HOOKFUNC
)Enumerator
,
124 struct TagItem Reqs
[] =
127 { tHidd_PCI_Class
, 0x04 }, /* Multimedia */
128 { tHidd_PCI_SubClass
, 0x01 }, /* Audio */
130 { tHidd_PCI_VendorID
, vendorid
},
131 { tHidd_PCI_ProductID
, deviceid
},
135 struct pHidd_PCI_EnumDevices enummsg
=
137 mID
: OOP_GetMethodID(CLID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
139 requirements
: (struct TagItem
*)&Reqs
,
142 ed
.prev_dev
= (OOP_Object
*)dev
;
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
159 UWORD
pci_inw(ULONG addr
, struct HDAudioChip
*card
)
161 UWORD
*real_addr
= (UWORD
*) (card
->iobase
+ addr
);
166 UBYTE
pci_inb(ULONG addr
, struct HDAudioChip
*card
)
168 UBYTE
*real_addr
= (UBYTE
*) (card
->iobase
+ 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
);
194 pci_outb(data
, addr
, card
);
198 void outb_clearbits(UBYTE value
, ULONG addr
, struct HDAudioChip
*card
)
200 UBYTE data
= pci_inb(addr
, card
);
203 pci_outb(data
, addr
, card
);
207 void outw_setbits(UWORD value
, ULONG addr
, struct HDAudioChip
*card
)
209 UWORD data
= pci_inw(addr
, card
);
212 pci_outw(data
, addr
, card
);
216 void outw_clearbits(UWORD value
, ULONG addr
, struct HDAudioChip
*card
)
218 UWORD data
= pci_inw(addr
, card
);
221 pci_outw(data
, addr
, card
);
225 void outl_setbits(ULONG value
, ULONG addr
, struct HDAudioChip
*card
)
227 ULONG data
= pci_inl(addr
, card
);
230 pci_outl(data
, addr
, card
);
234 void outl_clearbits(ULONG value
, ULONG addr
, struct HDAudioChip
*card
)
236 ULONG data
= pci_inl(addr
, card
);
239 pci_outl(data
, addr
, card
);
243 ULONG
inl_config(UBYTE reg
, APTR dev
)
245 struct pHidd_PCIDevice_ReadConfigLong msg
;
250 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
253 UWORD
inw_config(UBYTE reg
, APTR dev
)
255 struct pHidd_PCIDevice_ReadConfigWord msg
;
260 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
263 UBYTE
inb_config(UBYTE reg
, APTR dev
)
265 struct pHidd_PCIDevice_ReadConfigByte msg
;
270 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
273 void outl_config(UBYTE reg
, ULONG val
, APTR dev
)
275 struct pHidd_PCIDevice_WriteConfigLong msg
;
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
;
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
;
303 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
306 ULONG
ahi_pci_get_irq(APTR dev
)
310 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
315 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
319 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
321 AddIntServer(INTB_KERNEL
+ val
, i
);
323 inthandler_added
= TRUE
;
328 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
330 if (inthandler_added
)
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
)
353 attr
= aHidd_PCIDevice_Base0
;
357 attr
= aHidd_PCIDevice_Base1
;
361 attr
= aHidd_PCIDevice_Base2
;
365 attr
= aHidd_PCIDevice_Base3
;
369 attr
= aHidd_PCIDevice_Base4
;
373 attr
= aHidd_PCIDevice_Base5
;
380 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
382 D(bug("[HDAudio] ahi_pci_get_base_address. Result %lx\n", val
));
387 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
395 attr
= aHidd_PCIDevice_Size0
;
399 attr
= aHidd_PCIDevice_Size1
;
403 attr
= aHidd_PCIDevice_Size2
;
407 attr
= aHidd_PCIDevice_Size3
;
411 attr
= aHidd_PCIDevice_Size4
;
415 attr
= aHidd_PCIDevice_Size5
;
422 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
424 D(bug("[HDAudio] ahi_pci_get_base_size. Result %lx\n", val
));
432 ULONG
ahi_pci_get_type(WORD which
, APTR dev
)
440 attr
= aHidd_PCIDevice_Type0
;
444 attr
= aHidd_PCIDevice_Type1
;
448 attr
= aHidd_PCIDevice_Type2
;
452 attr
= aHidd_PCIDevice_Type3
;
456 attr
= aHidd_PCIDevice_Type4
;
460 attr
= aHidd_PCIDevice_Type5
;
467 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
469 D(bug("[HDAudio] ahi_pci_get_type. Result %lx\n", val
));