4 #include <utility/hooks.h>
5 #include <exec/interrupts.h>
9 #include <aros/asmcall.h>
11 #include <proto/oop.h>
13 #include "DriverData.h"
14 #include "pci_wrapper.h"
16 #include <aros/debug.h>
17 #define KPrintF kprintf
19 struct Library
*OOPBase
;
21 OOP_AttrBase __IHidd_PCIDev
;
22 static OOP_Object
*pciobj
;
24 static OOP_MethodID mid_RB
;
25 static OOP_MethodID mid_RW
;
26 static OOP_MethodID mid_RL
;
28 static OOP_MethodID mid_WB
;
29 static OOP_MethodID mid_WW
;
30 static OOP_MethodID mid_WL
;
32 static BOOL inthandler_added
;
34 BOOL
ahi_pci_init(struct DriverBase
* AHIsubBase
)
36 KPrintF("== ahi_pci_init 1\n");
37 OOPBase
= OpenLibrary(AROSOOP_NAME
, 0);
40 KPrintF("== ahi_pci_init 2\n");
41 __IHidd_PCIDev
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
44 KPrintF("== ahi_pci_init 3\n");
46 pciobj
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
49 KPrintF("== ahi_pci_init 4\n");
50 mid_RB
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
51 mid_RW
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigWord
);
52 mid_RL
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigLong
);
54 mid_WB
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
55 mid_WW
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigWord
);
56 mid_WL
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigLong
);
66 void ahi_pci_exit(void)
68 KPrintF("== ahi_pci_exit 1\n");
69 if (pciobj
) OOP_DisposeObject(pciobj
);
70 KPrintF("== ahi_pci_exit 2\n");
71 if (__IHidd_PCIDev
) OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
72 KPrintF("== ahi_pci_exit 3\n");
73 if (OOPBase
) CloseLibrary(OOPBase
);
74 KPrintF("== ahi_pci_exit 4\n");
80 OOP_Object
*found_dev
;
83 static AROS_UFH3(void, Enumerator
,
84 AROS_UFHA(struct Hook
*, hook
, A0
),
85 AROS_UFHA(OOP_Object
*, device
, A2
),
86 AROS_UFHA(APTR
, msg
, A1
))
90 struct enum_data
*ed
= (struct enum_data
*)hook
->h_Data
;
92 if ((ed
->found_dev
== 0) && (device
!= ed
->prev_dev
))
94 ed
->found_dev
= device
;
100 APTR
ahi_pci_find_device(ULONG vendorid
, ULONG deviceid
, APTR dev
)
104 struct Hook FindHook
=
106 h_Entry
: (HOOKFUNC
)Enumerator
,
110 struct TagItem Reqs
[] =
113 { tHidd_PCI_Class
, 0x04 }, /* Multimedia */
114 { tHidd_PCI_SubClass
, 0x01 }, /* Audio */
116 { tHidd_PCI_VendorID
, vendorid
},
117 { tHidd_PCI_ProductID
, deviceid
},
121 struct pHidd_PCI_EnumDevices enummsg
=
123 mID
: OOP_GetMethodID(CLID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
125 requirements
: (struct TagItem
*)&Reqs
,
128 KPrintF("ahi_pci_find_device: prevdev = %lx\n", dev
);
129 ed
.prev_dev
= (OOP_Object
*)dev
;
132 OOP_DoMethod(pciobj
, (OOP_Msg
)msg
);
134 KPrintF("ahi_pci_find_device: found_dev = %lx\n", ed
.found_dev
);
136 return (APTR
)ed
.found_dev
;
139 ULONG
ahi_pci_inl(ULONG addr
, APTR dev
)
144 UWORD
ahi_pci_inw(ULONG addr
, APTR dev
)
149 UBYTE
ahi_pci_inb(ULONG addr
, APTR dev
)
154 void ahi_pci_outl(ULONG value
, ULONG addr
, APTR dev
)
159 void ahi_pci_outw(UWORD value
, ULONG addr
, APTR dev
)
164 void ahi_pci_outb(UBYTE value
, ULONG addr
, APTR dev
)
170 ULONG
ahi_pci_read_config_long(UBYTE reg
, APTR dev
)
172 struct pHidd_PCIDevice_ReadConfigLong msg
;
177 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
180 UWORD
ahi_pci_read_config_word(UBYTE reg
, APTR dev
)
182 struct pHidd_PCIDevice_ReadConfigWord msg
;
187 return OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
190 UBYTE
ahi_pci_read_config_byte(UBYTE reg
, APTR dev
)
192 struct pHidd_PCIDevice_ReadConfigByte msg
;
197 return OOP_DoMethod(dev
, (OOP_Msg
)&msg
);
200 void ahi_pci_write_config_long(UBYTE reg
, ULONG val
, APTR dev
)
202 struct pHidd_PCIDevice_WriteConfigLong msg
;
208 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
211 void ahi_pci_write_config_word(UBYTE reg
, UWORD val
, APTR dev
)
213 struct pHidd_PCIDevice_WriteConfigWord msg
;
219 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
222 void ahi_pci_write_config_byte(UBYTE reg
, UBYTE val
, APTR dev
)
224 struct pHidd_PCIDevice_WriteConfigByte msg
;
230 OOP_DoMethod((OOP_Object
*)dev
, (OOP_Msg
)&msg
);
233 ULONG
ahi_pci_get_irq(APTR dev
)
237 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
238 KPrintF("ahi_pci_get_irq: irq = %ld\n", val
);
243 BOOL
ahi_pci_add_intserver(struct Interrupt
*i
, APTR dev
)
247 KPrintF("ahi_pci_add_intserver\n");
249 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
250 KPrintF("ahi_pci_add_intserver: irq = %ld\n", val
);
252 AddIntServer(INTB_KERNEL
+ val
, i
);
254 KPrintF("ahi_pci_add_intserver done\n");
256 inthandler_added
= TRUE
;
261 void ahi_pci_rem_intserver(struct Interrupt
*i
, APTR dev
)
263 KPrintF("ahi_pci_add_intserver\n");
265 KPrintF("ahi_pci_rem_intserver\n");
266 if (inthandler_added
)
270 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_INTLine
, &val
);
272 RemIntServer(INTB_KERNEL
+ val
, i
);
274 inthandler_added
= FALSE
;
276 KPrintF("ahi_pci_rem_intserver\n");
279 APTR
ahi_pci_logic_to_physic_addr(APTR addr
, APTR dev
)
281 struct pHidd_PCIDriver_CPUtoPCI __msg__
, *msg
= &__msg__
;
282 IPTR driverobj
, retval
;
284 OOP_GetAttr((OOP_Object
*)dev
, aHidd_PCIDevice_Driver
, &driverobj
);
286 msg
->mID
= OOP_GetMethodID(IID_Hidd_PCIDriver
, moHidd_PCIDriver_CPUtoPCI
);
289 KPrintF("ahi_pci_logic_to_physic_addr(%lx)\n", msg
->address
);
291 retval
= OOP_DoMethod((OOP_Object
*)driverobj
, (OOP_Msg
)msg
);
293 KPrintF("ahi_pci_logic_to_physic_addr(%lx) = %lx\n", msg
->address
, retval
);
298 APTR
ahi_pci_get_base_address(WORD which
, APTR dev
)
306 attr
= aHidd_PCIDevice_Base0
;
310 attr
= aHidd_PCIDevice_Base1
;
314 attr
= aHidd_PCIDevice_Base2
;
318 attr
= aHidd_PCIDevice_Base3
;
322 attr
= aHidd_PCIDevice_Base4
;
326 attr
= aHidd_PCIDevice_Base5
;
333 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
335 KPrintF("ahi_pci_get_base_address. Result %lx\n", val
);
340 ULONG
ahi_pci_get_base_size(WORD which
, APTR dev
)
348 attr
= aHidd_PCIDevice_Size0
;
352 attr
= aHidd_PCIDevice_Size1
;
356 attr
= aHidd_PCIDevice_Size2
;
360 attr
= aHidd_PCIDevice_Size3
;
364 attr
= aHidd_PCIDevice_Size4
;
368 attr
= aHidd_PCIDevice_Size5
;
375 OOP_GetAttr((OOP_Object
*)dev
, attr
, &val
);
377 KPrintF("ahi_pci_get_base_size. Result %lx\n", val
);