grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / AHI / Drivers / EMU10kx / pci_aros.c
blobc26a8b651c585de9edfa77c94c708b68a6ee58d4
2 #include <config.h>
4 #include <utility/hooks.h>
5 #include <exec/interrupts.h>
6 #include <asm/io.h>
7 #include <oop/oop.h>
8 #include <hidd/pci.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);
38 if (OOPBase)
40 KPrintF("== ahi_pci_init 2\n");
41 __IHidd_PCIDev = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
42 if (__IHidd_PCIDev)
44 KPrintF("== ahi_pci_init 3\n");
46 pciobj = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
47 if(pciobj)
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);
58 return TRUE;
63 return FALSE;
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");
77 struct enum_data
79 OOP_Object *prev_dev;
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))
88 AROS_USERFUNC_INIT
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;
97 AROS_USERFUNC_EXIT
100 APTR ahi_pci_find_device(ULONG vendorid, ULONG deviceid, APTR dev)
102 struct enum_data ed;
104 struct Hook FindHook =
106 h_Entry: (HOOKFUNC)Enumerator,
107 h_Data: &ed,
110 struct TagItem Reqs[] =
112 #if 0
113 { tHidd_PCI_Class , 0x04 }, /* Multimedia */
114 { tHidd_PCI_SubClass , 0x01 }, /* Audio */
115 #endif
116 { tHidd_PCI_VendorID , vendorid },
117 { tHidd_PCI_ProductID , deviceid },
118 { TAG_DONE , 0 },
121 struct pHidd_PCI_EnumDevices enummsg =
123 mID: OOP_GetMethodID(CLID_Hidd_PCI, moHidd_PCI_EnumDevices),
124 callback: &FindHook,
125 requirements: (struct TagItem *)&Reqs,
126 }, *msg = &enummsg;
128 KPrintF("ahi_pci_find_device: prevdev = %lx\n", dev);
129 ed.prev_dev = (OOP_Object *)dev;
130 ed.found_dev = 0;
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)
141 return inl(addr);
144 UWORD ahi_pci_inw(ULONG addr, APTR dev)
146 return inw(addr);
149 UBYTE ahi_pci_inb(ULONG addr, APTR dev)
151 return inb(addr);
154 void ahi_pci_outl(ULONG value, ULONG addr, APTR dev)
156 outl(value, addr);
159 void ahi_pci_outw(UWORD value, ULONG addr, APTR dev)
161 outw(value, addr);
164 void ahi_pci_outb(UBYTE value, ULONG addr, APTR dev)
166 outb(value, addr);
170 ULONG ahi_pci_read_config_long(UBYTE reg, APTR dev)
172 struct pHidd_PCIDevice_ReadConfigLong msg;
174 msg.mID = mid_RL;
175 msg.reg = reg;
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;
184 msg.mID = mid_RW;
185 msg.reg = reg;
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;
194 msg.mID = mid_RB;
195 msg.reg = reg;
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;
204 msg.mID = mid_WL;
205 msg.reg = reg;
206 msg.val = val;
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;
215 msg.mID = mid_WW;
216 msg.reg = reg;
217 msg.val = val;
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;
226 msg.mID = mid_WB;
227 msg.reg = reg;
228 msg.val = val;
230 OOP_DoMethod((OOP_Object *)dev, (OOP_Msg)&msg);
233 ULONG ahi_pci_get_irq(APTR dev)
235 IPTR val;
237 OOP_GetAttr((OOP_Object *)dev, aHidd_PCIDevice_INTLine, &val);
238 KPrintF("ahi_pci_get_irq: irq = %ld\n", val);
240 return (ULONG)val;
243 BOOL ahi_pci_add_intserver(struct Interrupt *i, APTR dev)
245 IPTR val;
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;
258 return 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)
268 IPTR val;
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);
287 msg->address = addr;
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);
295 return (APTR)retval;
298 APTR ahi_pci_get_base_address(WORD which, APTR dev)
300 OOP_AttrID attr = 0;
301 IPTR val = 0;
303 switch(which)
305 case 0:
306 attr = aHidd_PCIDevice_Base0;
307 break;
309 case 1:
310 attr = aHidd_PCIDevice_Base1;
311 break;
313 case 2:
314 attr = aHidd_PCIDevice_Base2;
315 break;
317 case 3:
318 attr = aHidd_PCIDevice_Base3;
319 break;
321 case 4:
322 attr = aHidd_PCIDevice_Base4;
323 break;
325 case 5:
326 attr = aHidd_PCIDevice_Base5;
327 break;
329 default:
330 return 0;
333 OOP_GetAttr((OOP_Object *)dev, attr, &val);
335 KPrintF("ahi_pci_get_base_address. Result %lx\n", val);
337 return (APTR)val;
340 ULONG ahi_pci_get_base_size(WORD which, APTR dev)
342 OOP_AttrID attr = 0;
343 IPTR val = 0;
345 switch(which)
347 case 0:
348 attr = aHidd_PCIDevice_Size0;
349 break;
351 case 1:
352 attr = aHidd_PCIDevice_Size1;
353 break;
355 case 2:
356 attr = aHidd_PCIDevice_Size2;
357 break;
359 case 3:
360 attr = aHidd_PCIDevice_Size3;
361 break;
363 case 4:
364 attr = aHidd_PCIDevice_Size4;
365 break;
367 case 5:
368 attr = aHidd_PCIDevice_Size5;
369 break;
371 default:
372 return 0;
375 OOP_GetAttr((OOP_Object *)dev, attr, &val);
377 KPrintF("ahi_pci_get_base_size. Result %lx\n", val);
379 return (ULONG)val;