add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / prometheus / board.c
blobfe7a7929eea5c7266235073c7127312054ffeaea
1 /*
2 Copyright (C) 2005 Neil Cafferkey
3 $Id$
4 */
7 #include <exec/types.h>
8 #include <utility/tagitem.h>
9 #include <libraries/prometheus.h>
11 #include <proto/exec.h>
12 #include <proto/utility.h>
13 #include <proto/oop.h>
15 #include "prometheus_intern.h"
18 /* Private prototypes */
20 static VOID WrapperIRQ(HIDDT_IRQ_Handler *irq, HIDDT_IRQ_HwInfo *hw_info);
23 static const struct TagItem map_tag_list[] =
25 {PRM_Vendor, aoHidd_PCIDevice_VendorID},
26 {PRM_Device, aoHidd_PCIDevice_ProductID},
27 {PRM_Revision, aoHidd_PCIDevice_RevisionID},
28 {PRM_Class, aoHidd_PCIDevice_Class},
29 {PRM_SubClass, aoHidd_PCIDevice_SubClass},
30 {PRM_MemoryAddr0, aoHidd_PCIDevice_Base0},
31 {PRM_MemoryAddr1, aoHidd_PCIDevice_Base1},
32 {PRM_MemoryAddr2, aoHidd_PCIDevice_Base2},
33 {PRM_MemoryAddr3, aoHidd_PCIDevice_Base3},
34 {PRM_MemoryAddr4, aoHidd_PCIDevice_Base4},
35 {PRM_MemoryAddr5, aoHidd_PCIDevice_Base5},
36 {PRM_ROM_Address, aoHidd_PCIDevice_RomBase},
37 {PRM_MemorySize0, aoHidd_PCIDevice_Size0},
38 {PRM_MemorySize1, aoHidd_PCIDevice_Size1},
39 {PRM_MemorySize2, aoHidd_PCIDevice_Size2},
40 {PRM_MemorySize3, aoHidd_PCIDevice_Size3},
41 {PRM_MemorySize4, aoHidd_PCIDevice_Size4},
42 {PRM_MemorySize5, aoHidd_PCIDevice_Size5},
43 {PRM_ROM_Size, aoHidd_PCIDevice_RomSize},
44 {PRM_SlotNumber, aoHidd_PCIDevice_Dev},
45 {PRM_FunctionNumber, aoHidd_PCIDevice_Sub},
46 {TAG_END, 0}
50 /***************************************************************************
52 NAME */
53 AROS_LH2(PCIBoard *, Prm_FindBoardTagList,
55 /* SYNOPSIS */
56 AROS_LHA(PCIBoard *, previous, A0),
57 AROS_LHA(struct TagItem *, tag_list, A1),
59 /* LOCATION */
60 struct Library *, PrometheusBase, 5, Prometheus)
62 /* FUNCTION
64 INPUTS
66 RESULT
68 ***************************************************************************/
70 AROS_LIBFUNC_INIT
72 struct LibBase *base = (APTR)PrometheusBase;
73 ULONG count = 0;
74 Tag tag, aros_tag;
75 struct TagItem *tag_item, *temp_tag_list;
76 struct PCIBoard *board, *tail;
77 BOOL success = FALSE;
78 UPINT board_data;
80 if(previous != NULL)
81 board = (APTR)previous->node.mln_Succ;
82 else
83 board = (APTR)base->boards.mlh_Head;
84 tail = (APTR)&base->boards.mlh_Tail;
86 while(board != tail && !success)
88 /* Check if the current board matches all requirements */
90 temp_tag_list = tag_list;
91 success = TRUE;
92 while((tag_item = NextTagItem(&temp_tag_list)) != NULL)
94 tag = tag_item->ti_Tag;
95 aros_tag = GetTagData(tag, TAG_DONE, map_tag_list);
96 if(aros_tag != TAG_DONE)
98 OOP_GetAttr(board->aros_board,
99 base->pcidevice_attr_base + aros_tag, &board_data);
101 else if(tag == PRM_BoardOwner)
102 board_data = (UPINT)board->owner;
104 if(board_data != tag_item->ti_Data)
105 success = FALSE;
108 if(!success)
109 board = (APTR)board->node.mln_Succ;
112 if(!success)
113 board = NULL;
115 return board;
117 AROS_LIBFUNC_EXIT
122 /***************************************************************************
124 NAME */
125 AROS_LH2(ULONG, Prm_GetBoardAttrsTagList,
127 /* SYNOPSIS */
128 AROS_LHA(PCIBoard *, board, A0),
129 AROS_LHA(struct TagItem *, tag_list, A1),
131 /* LOCATION */
132 struct Library *, PrometheusBase, 6, Prometheus)
134 /* FUNCTION
136 INPUTS
138 RESULT
140 ***************************************************************************/
142 AROS_LIBFUNC_INIT
144 struct LibBase *base = (APTR)PrometheusBase;
145 ULONG count = 0;
146 Tag aros_tag;
147 UPINT *tag_data_ptr;
148 struct TagItem *tag_item;
150 while((tag_item = NextTagItem(&tag_list)) != NULL)
152 if(tag_item->ti_Tag == PRM_BoardOwner)
154 tag_data_ptr = (UPINT *)tag_item->ti_Data;
155 *tag_data_ptr = (UPINT)board->owner;
156 count++;
158 else
160 aros_tag = GetTagData(tag_item->ti_Tag, TAG_DONE, map_tag_list);
161 if(aros_tag != TAG_DONE)
163 OOP_GetAttr(board->aros_board,
164 base->pcidevice_attr_base + aros_tag,
165 (UPINT *)tag_item->ti_Data);
166 count++;
171 return count;
173 AROS_LIBFUNC_EXIT
178 /***************************************************************************
180 NAME */
181 AROS_LH2(ULONG, Prm_SetBoardAttrsTagList,
183 /* SYNOPSIS */
184 AROS_LHA(PCIBoard *, board, A0),
185 AROS_LHA(struct TagItem *, tag_list, A1),
187 /* LOCATION */
188 struct Library *, PrometheusBase, 13, Prometheus)
190 /* FUNCTION
192 INPUTS
194 RESULT
196 ***************************************************************************/
198 AROS_LIBFUNC_INIT
200 struct LibBase *base = (APTR)PrometheusBase;
201 ULONG count = 0;
202 APTR new_owner;
203 struct TagItem *tag_item;
205 tag_item = FindTagItem(PRM_BoardOwner, tag_list);
206 if(tag_item != NULL)
208 new_owner = (APTR)tag_item->ti_Data;
209 if(new_owner != NULL && board->owner == NULL
210 || new_owner == NULL && board->owner != NULL)
212 board->owner = new_owner;
213 count++;
217 return count;
219 AROS_LIBFUNC_EXIT
224 /***************************************************************************
226 NAME */
227 AROS_LH2(UBYTE, Prm_ReadConfigByte,
229 /* SYNOPSIS */
230 AROS_LHA(PCIBoard *, board, A0),
231 AROS_LHA(UBYTE, offset, D0),
233 /* LOCATION */
234 struct Library *, PrometheusBase, 9, Prometheus)
236 /* FUNCTION
238 INPUTS
240 RESULT
242 ***************************************************************************/
244 AROS_LIBFUNC_INIT
246 struct LibBase *base = (APTR)PrometheusBase;
247 struct pHidd_PCIDevice_ReadConfigByte message;
249 message.mID =
250 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigByte);
251 message.reg = offset;
253 return (UBYTE)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
255 AROS_LIBFUNC_EXIT
260 /***************************************************************************
262 NAME */
263 AROS_LH3(VOID, Prm_WriteConfigByte,
265 /* SYNOPSIS */
266 AROS_LHA(PCIBoard *, board, A0),
267 AROS_LHA(UBYTE, data, D0),
268 AROS_LHA(UBYTE, offset, D1),
270 /* LOCATION */
271 struct Library *, PrometheusBase, 12, Prometheus)
273 /* FUNCTION
275 INPUTS
277 RESULT
279 ***************************************************************************/
281 AROS_LIBFUNC_INIT
283 struct LibBase *base = (APTR)PrometheusBase;
284 struct pHidd_PCIDevice_WriteConfigByte message;
286 message.mID =
287 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigByte);
288 message.reg = offset;
289 message.val = data;
291 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
293 AROS_LIBFUNC_EXIT
298 /***************************************************************************
300 NAME */
301 AROS_LH2(UWORD, Prm_ReadConfigWord,
303 /* SYNOPSIS */
304 AROS_LHA(PCIBoard *, board, A0),
305 AROS_LHA(UBYTE, offset, D0),
307 /* LOCATION */
308 struct Library *, PrometheusBase, 8, Prometheus)
310 /* FUNCTION
312 INPUTS
314 RESULT
316 ***************************************************************************/
318 AROS_LIBFUNC_INIT
320 struct LibBase *base = (APTR)PrometheusBase;
321 struct pHidd_PCIDevice_ReadConfigWord message;
323 message.mID =
324 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigWord);
325 message.reg = offset & ~0x1;
327 return (UWORD)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
329 AROS_LIBFUNC_EXIT
334 /***************************************************************************
336 NAME */
337 AROS_LH3(VOID, Prm_WriteConfigWord,
339 /* SYNOPSIS */
340 AROS_LHA(PCIBoard *, board, A0),
341 AROS_LHA(UWORD, data, D0),
342 AROS_LHA(UBYTE, offset, D1),
344 /* LOCATION */
345 struct Library *, PrometheusBase, 11, Prometheus)
347 /* FUNCTION
349 INPUTS
351 RESULT
353 ***************************************************************************/
355 AROS_LIBFUNC_INIT
357 struct LibBase *base = (APTR)PrometheusBase;
358 struct pHidd_PCIDevice_WriteConfigWord message;
360 message.mID =
361 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigWord);
362 message.reg = offset & ~0x1;
363 message.val = data;
365 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
367 AROS_LIBFUNC_EXIT
372 /***************************************************************************
374 NAME */
375 AROS_LH2(ULONG, Prm_ReadConfigLong,
377 /* SYNOPSIS */
378 AROS_LHA(PCIBoard *, board, A0),
379 AROS_LHA(UBYTE, offset, D0),
381 /* LOCATION */
382 struct Library *, PrometheusBase, 7, Prometheus)
384 /* FUNCTION
386 INPUTS
388 RESULT
390 ***************************************************************************/
392 AROS_LIBFUNC_INIT
394 struct LibBase *base = (APTR)PrometheusBase;
395 struct pHidd_PCIDevice_ReadConfigLong message;
397 message.mID =
398 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigLong);
399 message.reg = offset & ~0x3;
401 return (ULONG)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
403 AROS_LIBFUNC_EXIT
408 /***************************************************************************
410 NAME */
411 AROS_LH3(VOID, Prm_WriteConfigLong,
413 /* SYNOPSIS */
414 AROS_LHA(PCIBoard *, board, A0),
415 AROS_LHA(ULONG, data, D0),
416 AROS_LHA(UBYTE, offset, D1),
418 /* LOCATION */
419 struct Library *, PrometheusBase, 10, Prometheus)
421 /* FUNCTION
423 INPUTS
425 RESULT
427 ***************************************************************************/
429 AROS_LIBFUNC_INIT
431 struct LibBase *base = (APTR)PrometheusBase;
432 struct pHidd_PCIDevice_WriteConfigLong message;
434 message.mID =
435 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigLong);
436 message.reg = offset & ~0x3;
437 message.val = data;
439 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
441 AROS_LIBFUNC_EXIT
446 /***************************************************************************
448 NAME */
449 AROS_LH2(BOOL, Prm_AddIntServer,
451 /* SYNOPSIS */
452 AROS_LHA(PCIBoard *, board, A0),
453 AROS_LHA(struct Interrupt *, interrupt, A1),
455 /* LOCATION */
456 struct Library *, PrometheusBase, 14, Prometheus)
458 /* FUNCTION
460 INPUTS
462 RESULT
464 ***************************************************************************/
466 AROS_LIBFUNC_INIT
468 struct LibBase *base = (APTR)PrometheusBase;
469 BOOL success = TRUE;
470 HIDDT_IRQ_Handler *aros_irq;
471 UPINT int_no;
473 /* Allocate AROS int structure */
475 if(board == NULL || board->aros_irq != NULL)
476 success = FALSE;
478 if(success)
480 aros_irq =
481 AllocMem(sizeof(HIDDT_IRQ_Handler), MEMF_PUBLIC | MEMF_CLEAR);
482 if(aros_irq == NULL)
483 success = FALSE;
486 /* Add AROS int to system */
488 if(success)
490 OOP_GetAttr(board->aros_board,
491 base->pcidevice_attr_base + aoHidd_PCIDevice_INTLine, &int_no);
492 board->aros_irq = aros_irq;
493 aros_irq->h_Node.ln_Name = interrupt->is_Node.ln_Name;
494 aros_irq->h_Code = WrapperIRQ;
495 aros_irq->h_Data = interrupt;
497 success = HIDD_IRQ_AddHandler(base->irq_hidd, aros_irq, int_no);
500 return success;
502 AROS_LIBFUNC_EXIT
507 /***************************************************************************
509 NAME */
510 AROS_LH2(VOID, Prm_RemIntServer,
512 /* SYNOPSIS */
513 AROS_LHA(PCIBoard *, board, A0),
514 AROS_LHA(struct Interrupt *, interrupt, A1),
516 /* LOCATION */
517 struct Library *, PrometheusBase, 15, Prometheus)
519 /* FUNCTION
521 INPUTS
523 RESULT
525 ***************************************************************************/
527 AROS_LIBFUNC_INIT
529 struct LibBase *base = (APTR)PrometheusBase;
531 if(board != NULL)
533 HIDD_IRQ_RemHandler(base->irq_hidd, board->aros_irq);
534 FreeMem(board->aros_irq, sizeof(HIDDT_IRQ_Handler));
535 board->aros_irq = NULL;
538 return;
540 AROS_LIBFUNC_EXIT
545 /***************************************************************************
547 NAME */
548 AROS_LH1(APTR, Prm_AllocDMABuffer,
550 /* SYNOPSIS */
551 AROS_LHA(ULONG, size, D0),
553 /* LOCATION */
554 struct Library *, PrometheusBase, 16, Prometheus)
556 /* FUNCTION
558 INPUTS
560 RESULT
562 ***************************************************************************/
564 AROS_LIBFUNC_INIT
566 struct LibBase *base = (APTR)PrometheusBase;
567 APTR buffer;
569 if(size != 0)
570 buffer = AllocMem(size, MEMF_PUBLIC);
571 else
572 buffer = NULL;
574 return buffer;
576 AROS_LIBFUNC_EXIT
581 /***************************************************************************
583 NAME */
584 AROS_LH2(VOID, Prm_FreeDMABuffer,
586 /* SYNOPSIS */
587 AROS_LHA(APTR, buffer, A0),
588 AROS_LHA(ULONG, size, D0),
590 /* LOCATION */
591 struct Library *, PrometheusBase, 17, Prometheus)
593 /* FUNCTION
595 INPUTS
597 RESULT
599 ***************************************************************************/
601 AROS_LIBFUNC_INIT
603 struct LibBase *base = (APTR)PrometheusBase;
605 if(buffer != NULL && size != 0)
606 FreeMem(buffer, size);
608 return;
610 AROS_LIBFUNC_EXIT
615 /***************************************************************************
617 NAME */
618 AROS_LH1(APTR, Prm_GetPhysicalAddr,
620 /* SYNOPSIS */
621 AROS_LHA(APTR, address, D0),
623 /* LOCATION */
624 struct Library *, PrometheusBase, 18, Prometheus)
626 /* FUNCTION
628 INPUTS
630 RESULT
632 ***************************************************************************/
634 AROS_LIBFUNC_INIT
636 return address;
638 AROS_LIBFUNC_EXIT
643 static VOID WrapperIRQ(HIDDT_IRQ_Handler *irq, HIDDT_IRQ_HwInfo *hw_info)
645 struct Interrupt *interrupt;
647 interrupt = (struct Interrupt *)irq->h_Data;
648 AROS_UFC2(BOOL, interrupt->is_Code,
649 AROS_UFCA(APTR, interrupt->is_Data, A1),
650 AROS_UFCA(APTR, interrupt->is_Code, A5));
652 return;