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 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);
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
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
;
261 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
264 UWORD
inw_config(UBYTE reg
, APTR dev
)
266 struct pHidd_PCIDevice_ReadConfigWord msg
;
271 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
274 UBYTE
inb_config(UBYTE reg
, APTR dev
)
276 struct pHidd_PCIDevice_ReadConfigByte msg
;
281 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
284 void outl_config(UBYTE reg
, ULONG val
, APTR dev
)
286 struct pHidd_PCIDevice_WriteConfigLong msg
;
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
;
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
;
314 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
317 ULONG
ahi_pci_get_irq(APTR dev
)
321 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
326 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
330 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
332 AddIntServer(INTB_KERNEL
+ val
, i
);
334 inthandler_added
= TRUE
;
339 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
341 if (inthandler_added
)
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
);
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
);
374 APTR
ahi_pci_get_base_address(WORD which
, APTR dev
)
382 attr
= aHidd_PCIDevice_Base0
;
386 attr
= aHidd_PCIDevice_Base1
;
390 attr
= aHidd_PCIDevice_Base2
;
394 attr
= aHidd_PCIDevice_Base3
;
398 attr
= aHidd_PCIDevice_Base4
;
402 attr
= aHidd_PCIDevice_Base5
;
409 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
411 //KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
416 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
424 attr
= aHidd_PCIDevice_Size0
;
428 attr
= aHidd_PCIDevice_Size1
;
432 attr
= aHidd_PCIDevice_Size2
;
436 attr
= aHidd_PCIDevice_Size3
;
440 attr
= aHidd_PCIDevice_Size4
;
444 attr
= aHidd_PCIDevice_Size5
;
451 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
453 //KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
461 ULONG
ahi_pci_get_type(WORD which
, APTR dev
)
469 attr
= aHidd_PCIDevice_Type0
;
473 attr
= aHidd_PCIDevice_Type1
;
477 attr
= aHidd_PCIDevice_Type2
;
481 attr
= aHidd_PCIDevice_Type3
;
485 attr
= aHidd_PCIDevice_Type4
;
489 attr
= aHidd_PCIDevice_Type5
;
496 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
498 //KPrintF("ahi_pci_get_type. Result %lx\n", val);