Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / prometheus / board.c
blob01fe7284056d86f0741d5e07b9fec74132c16acf
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 Tag tag, aros_tag;
74 const struct TagItem *temp_tag_list;
75 struct TagItem *tag_item;
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, (const struct TagItem *)map_tag_list);
96 if(aros_tag != TAG_DONE)
98 OOP_GetAttr(board->aros_board,
99 base->pcidevice_attr_base + aros_tag, (IPTR *)&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((const struct TagItem **)&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 (IPTR *)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 ULONG count = 0;
201 APTR new_owner;
202 struct TagItem *tag_item;
204 tag_item = FindTagItem(PRM_BoardOwner, tag_list);
205 if(tag_item != NULL)
207 new_owner = (APTR)tag_item->ti_Data;
208 if(new_owner != NULL && board->owner == NULL
209 || new_owner == NULL && board->owner != NULL)
211 board->owner = new_owner;
212 count++;
216 return count;
218 AROS_LIBFUNC_EXIT
223 /***************************************************************************
225 NAME */
226 AROS_LH2(UBYTE, Prm_ReadConfigByte,
228 /* SYNOPSIS */
229 AROS_LHA(PCIBoard *, board, A0),
230 AROS_LHA(UBYTE, offset, D0),
232 /* LOCATION */
233 struct Library *, PrometheusBase, 9, Prometheus)
235 /* FUNCTION
237 INPUTS
239 RESULT
241 ***************************************************************************/
243 AROS_LIBFUNC_INIT
245 struct pHidd_PCIDevice_ReadConfigByte message;
247 message.mID =
248 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigByte);
249 message.reg = offset;
251 return (UBYTE)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
253 AROS_LIBFUNC_EXIT
258 /***************************************************************************
260 NAME */
261 AROS_LH3(VOID, Prm_WriteConfigByte,
263 /* SYNOPSIS */
264 AROS_LHA(PCIBoard *, board, A0),
265 AROS_LHA(UBYTE, data, D0),
266 AROS_LHA(UBYTE, offset, D1),
268 /* LOCATION */
269 struct Library *, PrometheusBase, 12, Prometheus)
271 /* FUNCTION
273 INPUTS
275 RESULT
277 ***************************************************************************/
279 AROS_LIBFUNC_INIT
281 struct pHidd_PCIDevice_WriteConfigByte message;
283 message.mID =
284 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigByte);
285 message.reg = offset;
286 message.val = data;
288 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
290 AROS_LIBFUNC_EXIT
295 /***************************************************************************
297 NAME */
298 AROS_LH2(UWORD, Prm_ReadConfigWord,
300 /* SYNOPSIS */
301 AROS_LHA(PCIBoard *, board, A0),
302 AROS_LHA(UBYTE, offset, D0),
304 /* LOCATION */
305 struct Library *, PrometheusBase, 8, Prometheus)
307 /* FUNCTION
309 INPUTS
311 RESULT
313 ***************************************************************************/
315 AROS_LIBFUNC_INIT
317 struct pHidd_PCIDevice_ReadConfigWord message;
319 message.mID =
320 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigWord);
321 message.reg = offset & ~0x1;
323 return (UWORD)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
325 AROS_LIBFUNC_EXIT
330 /***************************************************************************
332 NAME */
333 AROS_LH3(VOID, Prm_WriteConfigWord,
335 /* SYNOPSIS */
336 AROS_LHA(PCIBoard *, board, A0),
337 AROS_LHA(UWORD, data, D0),
338 AROS_LHA(UBYTE, offset, D1),
340 /* LOCATION */
341 struct Library *, PrometheusBase, 11, Prometheus)
343 /* FUNCTION
345 INPUTS
347 RESULT
349 ***************************************************************************/
351 AROS_LIBFUNC_INIT
353 struct pHidd_PCIDevice_WriteConfigWord message;
355 message.mID =
356 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigWord);
357 message.reg = offset & ~0x1;
358 message.val = data;
360 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
362 AROS_LIBFUNC_EXIT
367 /***************************************************************************
369 NAME */
370 AROS_LH2(ULONG, Prm_ReadConfigLong,
372 /* SYNOPSIS */
373 AROS_LHA(PCIBoard *, board, A0),
374 AROS_LHA(UBYTE, offset, D0),
376 /* LOCATION */
377 struct Library *, PrometheusBase, 7, Prometheus)
379 /* FUNCTION
381 INPUTS
383 RESULT
385 ***************************************************************************/
387 AROS_LIBFUNC_INIT
389 struct pHidd_PCIDevice_ReadConfigLong message;
391 message.mID =
392 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_ReadConfigLong);
393 message.reg = offset & ~0x3;
395 return (ULONG)OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
397 AROS_LIBFUNC_EXIT
402 /***************************************************************************
404 NAME */
405 AROS_LH3(VOID, Prm_WriteConfigLong,
407 /* SYNOPSIS */
408 AROS_LHA(PCIBoard *, board, A0),
409 AROS_LHA(ULONG, data, D0),
410 AROS_LHA(UBYTE, offset, D1),
412 /* LOCATION */
413 struct Library *, PrometheusBase, 10, Prometheus)
415 /* FUNCTION
417 INPUTS
419 RESULT
421 ***************************************************************************/
423 AROS_LIBFUNC_INIT
425 struct pHidd_PCIDevice_WriteConfigLong message;
427 message.mID =
428 OOP_GetMethodID(IID_Hidd_PCIDevice, moHidd_PCIDevice_WriteConfigLong);
429 message.reg = offset & ~0x3;
430 message.val = data;
432 OOP_DoMethod(board->aros_board, (OOP_Msg)&message);
434 AROS_LIBFUNC_EXIT
439 /***************************************************************************
441 NAME */
442 AROS_LH2(BOOL, Prm_AddIntServer,
444 /* SYNOPSIS */
445 AROS_LHA(PCIBoard *, board, A0),
446 AROS_LHA(struct Interrupt *, interrupt, A1),
448 /* LOCATION */
449 struct Library *, PrometheusBase, 14, Prometheus)
451 /* FUNCTION
453 INPUTS
455 RESULT
457 ***************************************************************************/
459 AROS_LIBFUNC_INIT
461 struct LibBase *base = (APTR)PrometheusBase;
462 BOOL success = TRUE;
463 HIDDT_IRQ_Handler *aros_irq;
464 UPINT int_no;
466 /* Allocate AROS int structure */
468 if(board == NULL || board->aros_irq != NULL)
469 success = FALSE;
471 if(success)
473 aros_irq =
474 AllocMem(sizeof(HIDDT_IRQ_Handler), MEMF_PUBLIC | MEMF_CLEAR);
475 if(aros_irq == NULL)
476 success = FALSE;
479 /* Add AROS int to system */
481 if(success)
483 OOP_GetAttr(board->aros_board,
484 base->pcidevice_attr_base + aoHidd_PCIDevice_INTLine, (IPTR *)&int_no);
485 board->aros_irq = aros_irq;
486 aros_irq->h_Node.ln_Name = interrupt->is_Node.ln_Name;
487 aros_irq->h_Code = WrapperIRQ;
488 aros_irq->h_Data = interrupt;
490 success = HIDD_IRQ_AddHandler(base->irq_hidd, aros_irq, int_no);
493 return success;
495 AROS_LIBFUNC_EXIT
500 /***************************************************************************
502 NAME */
503 AROS_LH2(VOID, Prm_RemIntServer,
505 /* SYNOPSIS */
506 AROS_LHA(PCIBoard *, board, A0),
507 AROS_LHA(struct Interrupt *, interrupt, A1),
509 /* LOCATION */
510 struct Library *, PrometheusBase, 15, Prometheus)
512 /* FUNCTION
514 INPUTS
516 RESULT
518 ***************************************************************************/
520 AROS_LIBFUNC_INIT
522 struct LibBase *base = (APTR)PrometheusBase;
524 if(board != NULL)
526 HIDD_IRQ_RemHandler(base->irq_hidd, board->aros_irq);
527 FreeMem(board->aros_irq, sizeof(HIDDT_IRQ_Handler));
528 board->aros_irq = NULL;
531 return;
533 AROS_LIBFUNC_EXIT
538 /***************************************************************************
540 NAME */
541 AROS_LH1(APTR, Prm_AllocDMABuffer,
543 /* SYNOPSIS */
544 AROS_LHA(ULONG, size, D0),
546 /* LOCATION */
547 struct Library *, PrometheusBase, 16, Prometheus)
549 /* FUNCTION
551 INPUTS
553 RESULT
555 ***************************************************************************/
557 AROS_LIBFUNC_INIT
559 APTR buffer;
561 if(size != 0)
562 buffer = AllocMem(size, MEMF_PUBLIC);
563 else
564 buffer = NULL;
566 return buffer;
568 AROS_LIBFUNC_EXIT
573 /***************************************************************************
575 NAME */
576 AROS_LH2(VOID, Prm_FreeDMABuffer,
578 /* SYNOPSIS */
579 AROS_LHA(APTR, buffer, A0),
580 AROS_LHA(ULONG, size, D0),
582 /* LOCATION */
583 struct Library *, PrometheusBase, 17, Prometheus)
585 /* FUNCTION
587 INPUTS
589 RESULT
591 ***************************************************************************/
593 AROS_LIBFUNC_INIT
595 if(buffer != NULL && size != 0)
596 FreeMem(buffer, size);
598 return;
600 AROS_LIBFUNC_EXIT
605 /***************************************************************************
607 NAME */
608 AROS_LH1(APTR, Prm_GetPhysicalAddr,
610 /* SYNOPSIS */
611 AROS_LHA(APTR, address, D0),
613 /* LOCATION */
614 struct Library *, PrometheusBase, 18, Prometheus)
616 /* FUNCTION
618 INPUTS
620 RESULT
622 ***************************************************************************/
624 AROS_LIBFUNC_INIT
626 return address;
628 AROS_LIBFUNC_EXIT
633 static VOID WrapperIRQ(HIDDT_IRQ_Handler *irq, HIDDT_IRQ_HwInfo *hw_info)
635 struct Interrupt *interrupt;
637 interrupt = (struct Interrupt *)irq->h_Data;
638 AROS_UFC2(BOOL, interrupt->is_Code,
639 AROS_UFCA(APTR, interrupt->is_Data, A1),
640 AROS_UFCA(APTR, interrupt->is_Code, A5));
642 return;