2 Copyright © 2004-2013, The AROS Development Team. All rights reserved.
6 #define __OOP_NOATTRBASES__
9 #include <utility/hooks.h>
10 #include <exec/interrupts.h>
11 #include <aros/macros.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 kprintf
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);
45 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
48 pciobj
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
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
);
68 void ahi_pci_exit(void)
71 OOP_DisposeObject(pciobj
);
73 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
75 CloseLibrary(OOPBase
);
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
))
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
;
102 APTR
ahi_pci_find_device(ULONG vendorid
, ULONG deviceid
, APTR dev
)
106 struct Hook FindHook
=
108 h_Entry
: (HOOKFUNC
)Enumerator
,
112 struct TagItem Reqs
[] =
115 { tHidd_PCI_Class
, 0x04 }, /* Multimedia */
116 { tHidd_PCI_SubClass
, 0x01 }, /* Audio */
118 { tHidd_PCI_VendorID
, vendorid
},
119 { tHidd_PCI_ProductID
, deviceid
},
123 struct pHidd_PCI_EnumDevices enummsg
=
125 mID
: OOP_GetMethodID(CLID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
127 requirements
: (struct TagItem
*)&Reqs
,
130 ed
.prev_dev
= (OOP_Object
*)dev
;
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
);
175 pci_outb(data
, addr
, card
);
179 void outb_clearbits(UBYTE value
, ULONG addr
, struct CardData
*card
)
181 UBYTE data
= pci_inb(addr
, card
);
184 pci_outb(data
, addr
, card
);
188 void outw_setbits(UWORD value
, ULONG addr
, struct CardData
*card
)
190 UWORD data
= pci_inw(addr
, card
);
193 pci_outw(data
, addr
, card
);
197 void outw_clearbits(UWORD value
, ULONG addr
, struct CardData
*card
)
199 UWORD data
= pci_inw(addr
, card
);
202 pci_outw(data
, addr
, card
);
206 void outl_setbits(ULONG value
, ULONG addr
, struct CardData
*card
)
208 ULONG data
= pci_inl(addr
, card
);
211 pci_outl(data
, addr
, card
);
215 void outl_clearbits(ULONG value
, ULONG addr
, struct CardData
*card
)
217 ULONG data
= pci_inl(addr
, card
);
220 pci_outl(data
, addr
, card
);
224 ULONG
inl_config(UBYTE reg
, APTR dev
)
226 struct pHidd_PCIDevice_ReadConfigLong msg
;
231 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
234 UWORD
inw_config(UBYTE reg
, APTR dev
)
236 struct pHidd_PCIDevice_ReadConfigWord msg
;
241 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
244 UBYTE
inb_config(UBYTE reg
, APTR dev
)
246 struct pHidd_PCIDevice_ReadConfigByte msg
;
251 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
254 void outl_config(UBYTE reg
, ULONG val
, APTR dev
)
256 struct pHidd_PCIDevice_WriteConfigLong msg
;
262 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
265 void outw_config(UBYTE reg
, UWORD val
, APTR dev
)
267 struct pHidd_PCIDevice_WriteConfigWord msg
;
273 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
276 void outb_config(UBYTE reg
, UBYTE val
, APTR dev
)
278 struct pHidd_PCIDevice_WriteConfigByte msg
;
284 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
287 ULONG
ahi_pci_get_irq(APTR dev
)
291 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
296 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
300 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
302 AddIntServer(INTB_KERNEL
+ val
, i
);
304 inthandler_added
= TRUE
;
309 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
311 if (inthandler_added
)
315 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
317 RemIntServer(INTB_KERNEL
+ val
, i
);
319 inthandler_added
= FALSE
;
322 KPrintF("ahi_pci_rem_intserver\n");
326 APTR
ahi_pci_get_base_address(WORD which
, APTR dev
)
334 attr
= aHidd_PCIDevice_Base0
;
338 attr
= aHidd_PCIDevice_Base1
;
342 attr
= aHidd_PCIDevice_Base2
;
346 attr
= aHidd_PCIDevice_Base3
;
350 attr
= aHidd_PCIDevice_Base4
;
354 attr
= aHidd_PCIDevice_Base5
;
361 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
363 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
368 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
376 attr
= aHidd_PCIDevice_Size0
;
380 attr
= aHidd_PCIDevice_Size1
;
384 attr
= aHidd_PCIDevice_Size2
;
388 attr
= aHidd_PCIDevice_Size3
;
392 attr
= aHidd_PCIDevice_Size4
;
396 attr
= aHidd_PCIDevice_Size5
;
403 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
405 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
413 ULONG
ahi_pci_get_type(WORD which
, APTR dev
)
421 attr
= aHidd_PCIDevice_Type0
;
425 attr
= aHidd_PCIDevice_Type1
;
429 attr
= aHidd_PCIDevice_Type2
;
433 attr
= aHidd_PCIDevice_Type3
;
437 attr
= aHidd_PCIDevice_Type4
;
441 attr
= aHidd_PCIDevice_Type5
;
448 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
450 //KPrintF("ahi_pci_get_type. Result %lx\n", val);