2 Copyright (C) 2005 Neil Cafferkey
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
},
50 /***************************************************************************
53 AROS_LH2(PCIBoard
*, Prm_FindBoardTagList
,
56 AROS_LHA(PCIBoard
*, previous
, A0
),
57 AROS_LHA(struct TagItem
*, tag_list
, A1
),
60 struct Library
*, PrometheusBase
, 5, Prometheus
)
68 ***************************************************************************/
72 struct LibBase
*base
= (APTR
)PrometheusBase
;
75 struct TagItem
*tag_item
, *temp_tag_list
;
76 struct PCIBoard
*board
, *tail
;
81 board
= (APTR
)previous
->node
.mln_Succ
;
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
;
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
)
109 board
= (APTR
)board
->node
.mln_Succ
;
122 /***************************************************************************
125 AROS_LH2(ULONG
, Prm_GetBoardAttrsTagList
,
128 AROS_LHA(PCIBoard
*, board
, A0
),
129 AROS_LHA(struct TagItem
*, tag_list
, A1
),
132 struct Library
*, PrometheusBase
, 6, Prometheus
)
140 ***************************************************************************/
144 struct LibBase
*base
= (APTR
)PrometheusBase
;
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
;
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
);
178 /***************************************************************************
181 AROS_LH2(ULONG
, Prm_SetBoardAttrsTagList
,
184 AROS_LHA(PCIBoard
*, board
, A0
),
185 AROS_LHA(struct TagItem
*, tag_list
, A1
),
188 struct Library
*, PrometheusBase
, 13, Prometheus
)
196 ***************************************************************************/
200 struct LibBase
*base
= (APTR
)PrometheusBase
;
203 struct TagItem
*tag_item
;
205 tag_item
= FindTagItem(PRM_BoardOwner
, tag_list
);
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
;
224 /***************************************************************************
227 AROS_LH2(UBYTE
, Prm_ReadConfigByte
,
230 AROS_LHA(PCIBoard
*, board
, A0
),
231 AROS_LHA(UBYTE
, offset
, D0
),
234 struct Library
*, PrometheusBase
, 9, Prometheus
)
242 ***************************************************************************/
246 struct LibBase
*base
= (APTR
)PrometheusBase
;
247 struct pHidd_PCIDevice_ReadConfigByte message
;
250 OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
251 message
.reg
= offset
;
253 return (UBYTE
)OOP_DoMethod(board
->aros_board
, (OOP_Msg
)&message
);
260 /***************************************************************************
263 AROS_LH3(VOID
, Prm_WriteConfigByte
,
266 AROS_LHA(PCIBoard
*, board
, A0
),
267 AROS_LHA(UBYTE
, data
, D0
),
268 AROS_LHA(UBYTE
, offset
, D1
),
271 struct Library
*, PrometheusBase
, 12, Prometheus
)
279 ***************************************************************************/
283 struct LibBase
*base
= (APTR
)PrometheusBase
;
284 struct pHidd_PCIDevice_WriteConfigByte message
;
287 OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
288 message
.reg
= offset
;
291 OOP_DoMethod(board
->aros_board
, (OOP_Msg
)&message
);
298 /***************************************************************************
301 AROS_LH2(UWORD
, Prm_ReadConfigWord
,
304 AROS_LHA(PCIBoard
*, board
, A0
),
305 AROS_LHA(UBYTE
, offset
, D0
),
308 struct Library
*, PrometheusBase
, 8, Prometheus
)
316 ***************************************************************************/
320 struct LibBase
*base
= (APTR
)PrometheusBase
;
321 struct pHidd_PCIDevice_ReadConfigWord message
;
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
);
334 /***************************************************************************
337 AROS_LH3(VOID
, Prm_WriteConfigWord
,
340 AROS_LHA(PCIBoard
*, board
, A0
),
341 AROS_LHA(UWORD
, data
, D0
),
342 AROS_LHA(UBYTE
, offset
, D1
),
345 struct Library
*, PrometheusBase
, 11, Prometheus
)
353 ***************************************************************************/
357 struct LibBase
*base
= (APTR
)PrometheusBase
;
358 struct pHidd_PCIDevice_WriteConfigWord message
;
361 OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigWord
);
362 message
.reg
= offset
& ~0x1;
365 OOP_DoMethod(board
->aros_board
, (OOP_Msg
)&message
);
372 /***************************************************************************
375 AROS_LH2(ULONG
, Prm_ReadConfigLong
,
378 AROS_LHA(PCIBoard
*, board
, A0
),
379 AROS_LHA(UBYTE
, offset
, D0
),
382 struct Library
*, PrometheusBase
, 7, Prometheus
)
390 ***************************************************************************/
394 struct LibBase
*base
= (APTR
)PrometheusBase
;
395 struct pHidd_PCIDevice_ReadConfigLong message
;
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
);
408 /***************************************************************************
411 AROS_LH3(VOID
, Prm_WriteConfigLong
,
414 AROS_LHA(PCIBoard
*, board
, A0
),
415 AROS_LHA(ULONG
, data
, D0
),
416 AROS_LHA(UBYTE
, offset
, D1
),
419 struct Library
*, PrometheusBase
, 10, Prometheus
)
427 ***************************************************************************/
431 struct LibBase
*base
= (APTR
)PrometheusBase
;
432 struct pHidd_PCIDevice_WriteConfigLong message
;
435 OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigLong
);
436 message
.reg
= offset
& ~0x3;
439 OOP_DoMethod(board
->aros_board
, (OOP_Msg
)&message
);
446 /***************************************************************************
449 AROS_LH2(BOOL
, Prm_AddIntServer
,
452 AROS_LHA(PCIBoard
*, board
, A0
),
453 AROS_LHA(struct Interrupt
*, interrupt
, A1
),
456 struct Library
*, PrometheusBase
, 14, Prometheus
)
464 ***************************************************************************/
468 struct LibBase
*base
= (APTR
)PrometheusBase
;
470 HIDDT_IRQ_Handler
*aros_irq
;
473 /* Allocate AROS int structure */
475 if(board
== NULL
|| board
->aros_irq
!= NULL
)
481 AllocMem(sizeof(HIDDT_IRQ_Handler
), MEMF_PUBLIC
| MEMF_CLEAR
);
486 /* Add AROS int to system */
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
);
507 /***************************************************************************
510 AROS_LH2(VOID
, Prm_RemIntServer
,
513 AROS_LHA(PCIBoard
*, board
, A0
),
514 AROS_LHA(struct Interrupt
*, interrupt
, A1
),
517 struct Library
*, PrometheusBase
, 15, Prometheus
)
525 ***************************************************************************/
529 struct LibBase
*base
= (APTR
)PrometheusBase
;
533 HIDD_IRQ_RemHandler(base
->irq_hidd
, board
->aros_irq
);
534 FreeMem(board
->aros_irq
, sizeof(HIDDT_IRQ_Handler
));
535 board
->aros_irq
= NULL
;
545 /***************************************************************************
548 AROS_LH1(APTR
, Prm_AllocDMABuffer
,
551 AROS_LHA(ULONG
, size
, D0
),
554 struct Library
*, PrometheusBase
, 16, Prometheus
)
562 ***************************************************************************/
566 struct LibBase
*base
= (APTR
)PrometheusBase
;
570 buffer
= AllocMem(size
, MEMF_PUBLIC
);
581 /***************************************************************************
584 AROS_LH2(VOID
, Prm_FreeDMABuffer
,
587 AROS_LHA(APTR
, buffer
, A0
),
588 AROS_LHA(ULONG
, size
, D0
),
591 struct Library
*, PrometheusBase
, 17, Prometheus
)
599 ***************************************************************************/
603 struct LibBase
*base
= (APTR
)PrometheusBase
;
605 if(buffer
!= NULL
&& size
!= 0)
606 FreeMem(buffer
, size
);
615 /***************************************************************************
618 AROS_LH1(APTR
, Prm_GetPhysicalAddr
,
621 AROS_LHA(APTR
, address
, D0
),
624 struct Library
*, PrometheusBase
, 18, Prometheus
)
632 ***************************************************************************/
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
));