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.
18 #define __OOP_NOATTRBASES__
20 #include <aros/debug.h>
22 #include <utility/hooks.h>
23 #include <exec/interrupts.h>
24 #include <aros/macros.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);
55 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
58 pciobj
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
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
);
78 void ahi_pci_exit(void)
81 OOP_DisposeObject(pciobj
);
83 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
85 CloseLibrary(OOPBase
);
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
))
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
;
112 APTR
ahi_pci_find_device(ULONG vendorid
, ULONG deviceid
, APTR dev
)
116 struct Hook FindHook
=
118 h_Entry
: (HOOKFUNC
)Enumerator
,
122 struct TagItem Reqs
[] =
125 { tHidd_PCI_Class
, 0x04 }, /* Multimedia */
126 { tHidd_PCI_SubClass
, 0x01 }, /* Audio */
128 { tHidd_PCI_VendorID
, vendorid
},
129 { tHidd_PCI_ProductID
, deviceid
},
133 struct pHidd_PCI_EnumDevices enummsg
=
135 mID
: OOP_GetMethodID(CLID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
137 requirements
: (struct TagItem
*)&Reqs
,
140 ed
.prev_dev
= (OOP_Object
*)dev
;
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
);
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
);
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
);
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
);
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
);
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
);
230 pci_outl(data
, addr
, card
);
234 ULONG
inl_config(UBYTE reg
, APTR dev
)
236 struct pHidd_PCIDevice_ReadConfigLong msg
;
241 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
244 UWORD
inw_config(UBYTE reg
, APTR dev
)
246 struct pHidd_PCIDevice_ReadConfigWord msg
;
251 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
254 UBYTE
inb_config(UBYTE reg
, APTR dev
)
256 struct pHidd_PCIDevice_ReadConfigByte msg
;
261 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
264 void outl_config(UBYTE reg
, ULONG val
, APTR dev
)
266 struct pHidd_PCIDevice_WriteConfigLong msg
;
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
;
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
;
294 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
297 ULONG
ahi_pci_get_irq(APTR dev
)
301 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
306 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
310 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
312 AddIntServer(INTB_KERNEL
+ val
, i
);
314 inthandler_added
= TRUE
;
319 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
321 if (inthandler_added
)
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
)
344 attr
= aHidd_PCIDevice_Base0
;
348 attr
= aHidd_PCIDevice_Base1
;
352 attr
= aHidd_PCIDevice_Base2
;
356 attr
= aHidd_PCIDevice_Base3
;
360 attr
= aHidd_PCIDevice_Base4
;
364 attr
= aHidd_PCIDevice_Base5
;
371 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
373 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
378 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
386 attr
= aHidd_PCIDevice_Size0
;
390 attr
= aHidd_PCIDevice_Size1
;
394 attr
= aHidd_PCIDevice_Size2
;
398 attr
= aHidd_PCIDevice_Size3
;
402 attr
= aHidd_PCIDevice_Size4
;
406 attr
= aHidd_PCIDevice_Size5
;
413 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
415 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
423 ULONG
ahi_pci_get_type(WORD which
, APTR dev
)
431 attr
= aHidd_PCIDevice_Type0
;
435 attr
= aHidd_PCIDevice_Type1
;
439 attr
= aHidd_PCIDevice_Type2
;
443 attr
= aHidd_PCIDevice_Type3
;
447 attr
= aHidd_PCIDevice_Type4
;
451 attr
= aHidd_PCIDevice_Type5
;
458 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
460 //KPrintF("ahi_pci_get_type. Result %lx\n", val);