revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / networks / etherlink3 / prometheus.c
bloba85cf8b982f8b2acb2d92eac4be56d88725ad4ed
1 /*
3 Copyright (C) 2004-2011 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA.
23 #include <exec/types.h>
24 #include <libraries/prometheus.h>
26 #include <proto/exec.h>
27 #include <proto/prometheus.h>
29 #include "device.h"
30 #include "pci.h"
32 #include "pci_protos.h"
33 #include "prometheus_protos.h"
36 /****i* etherlink3.device/GetPrometheusCount *******************************
38 * NAME
39 * GetPrometheusCount
41 * SYNOPSIS
42 * count = GetPrometheusCount()
44 * ULONG GetPrometheusCount();
46 ****************************************************************************
50 ULONG GetPrometheusCount(struct DevBase *base)
52 ULONG count = 0;
53 PCIBoard *card = NULL;
54 UPINT vendor_id, product_id;
56 while((card = Prm_FindBoardTagList(card, NULL)) != NULL)
58 Prm_GetBoardAttrsTags(card, PRM_Vendor, (UPINT)&vendor_id,
59 PRM_Device, (UPINT)&product_id, TAG_END);
60 if(IsCardCompatible(vendor_id, product_id, base))
61 count++;
64 return count;
69 /****i* etherlink3.device/AllocPrometheusCard ******************************
71 * NAME
72 * AllocPrometheusCard -- Take control of a card.
74 * SYNOPSIS
75 * context = AllocPrometheusCard(index)
77 * struct BusContext *AllocPrometheusCard(ULONG);
79 ****************************************************************************
83 struct BusContext *AllocPrometheusCard(ULONG index, struct DevBase *base)
85 BOOL success = TRUE;
86 struct BusContext *context;
87 PCIBoard *card = NULL;
88 UWORD i = 0;
89 UPINT vendor_id, product_id;
91 /* Find a compatible card */
93 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
94 if(context == NULL)
95 success = FALSE;
97 if(success)
99 while(i <= index)
101 card = Prm_FindBoardTagList(card, NULL);
102 Prm_GetBoardAttrsTags(card, PRM_Vendor, (UPINT)&vendor_id,
103 PRM_Device, (UPINT)&product_id, TAG_END);
104 if(IsCardCompatible(vendor_id, product_id, base))
105 i++;
108 context->card = card;
109 if(card == NULL)
110 success = FALSE;
113 /* Get base address and generation */
115 if(success)
117 Prm_GetBoardAttrsTags(card,
118 PRM_MemoryAddr0 + BAR_NO, (UPINT)&context->io_base, TAG_END);
119 if(context->io_base == 0)
120 success = FALSE;
121 context->generation = GetGeneration(product_id, base);
124 /* Lock card */
126 if(success)
128 if(!Prm_SetBoardAttrsTags(card, PRM_BoardOwner, (UPINT)base, TAG_END))
129 success = FALSE;
132 if(!success)
134 FreePrometheusCard(context, base);
135 context = NULL;
138 return context;
143 /****i* etherlink3.device/FreePrometheusCard *******************************
145 * NAME
146 * FreePrometheusCard -- Release a card.
148 * SYNOPSIS
149 * FreePrometheusCard(context)
151 * VOID FreePrometheusCard(struct BusContext *);
153 ****************************************************************************
157 VOID FreePrometheusCard(struct BusContext *context, struct DevBase *base)
159 PCIBoard *card;
160 APTR owner;
162 if(context != NULL)
164 card = context->card;
165 if(card != NULL)
167 /* Unlock board */
169 Prm_GetBoardAttrsTags(card, PRM_BoardOwner, (UPINT)&owner,
170 TAG_END);
171 if(owner == base)
172 Prm_SetBoardAttrsTags(card, PRM_BoardOwner, NULL, TAG_END);
175 FreeMem(context, sizeof(struct BusContext));
178 return;
183 /****i* etherlink3.device/AddPrometheusIntServer ***************************
185 * NAME
186 * AddPrometheusIntServer
188 * SYNOPSIS
189 * success = AddPrometheusIntServer(card, interrupt)
191 * BOOL AddPrometheusIntServer(APTR, struct Interrupt *);
193 ****************************************************************************
197 BOOL AddPrometheusIntServer(APTR card, struct Interrupt *interrupt,
198 struct DevBase *base)
200 return Prm_AddIntServer(card, interrupt);
205 /****i* etherlink3.device/RemPrometheusIntServer ***************************
207 * NAME
208 * RemPrometheusIntServer
210 * SYNOPSIS
211 * RemPrometheusIntServer(card, interrupt)
213 * VOID RemPrometheusIntServer(APTR, struct Interrupt *);
215 ****************************************************************************
219 VOID RemPrometheusIntServer(APTR card, struct Interrupt *interrupt,
220 struct DevBase *base)
222 Prm_RemIntServer(card, interrupt);
224 return;
229 /****i* etherlink3.device/AllocPrometheusDMAMem ****************************
231 * NAME
232 * AllocPrometheusDMAMem
234 * SYNOPSIS
235 * mem = AllocPrometheusDMAMem(context, size, alignment)
237 * APTR AllocPrometheusDMAMem(struct BusContext *, UPINT, UWORD);
239 ****************************************************************************
241 * Alignment currently must be minimum of 8 bytes.
245 APTR AllocPrometheusDMAMem(UPINT size, struct DevBase *base)
247 return Prm_AllocDMABuffer(size);
252 /****i* etherlink3.device/FreePrometheusDMAMem *****************************
254 * NAME
255 * FreePrometheusDMAMem
257 * SYNOPSIS
258 * FreePrometheusDMAMem(context, mem)
260 * VOID FreePrometheusDMAMem(struct BusContext *, APTR);
262 ****************************************************************************
266 VOID FreePrometheusDMAMem(APTR mem, UPINT size, struct DevBase *base)
268 Prm_FreeDMABuffer(mem, size);
270 return;