revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / networks / atheros5000 / prometheus.c
blob32bec7c0e221ec462e84b4b9df613e15b5b5129b
1 /*
3 Copyright (C) 2004-2010 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 "pci.h"
31 #include "pci_protos.h"
32 #include "prometheus_protos.h"
35 /****i* atheros5000.device/GetPrometheusCount ******************************
37 * NAME
38 * GetPrometheusCount
40 * SYNOPSIS
41 * count = GetPrometheusCount()
43 * ULONG GetPrometheusCount();
45 ****************************************************************************
49 ULONG GetPrometheusCount(struct DevBase *base)
51 ULONG count = 0;
52 PCIBoard *card = NULL;
53 UPINT vendor_id, product_id;
55 while((card = Prm_FindBoardTagList(card, NULL)) != NULL)
57 Prm_GetBoardAttrsTags(card, PRM_Vendor, (UPINT)&vendor_id,
58 PRM_Device, (UPINT)&product_id, TAG_END);
59 if(IsCardCompatible(vendor_id, product_id, base))
60 count++;
63 return count;
68 /****i* atheros5000.device/AllocPrometheusCard *****************************
70 * NAME
71 * AllocPrometheusCard -- Take control of a card.
73 * SYNOPSIS
74 * context = AllocPrometheusCard(index)
76 * struct BusContext *AllocPrometheusCard(ULONG);
78 ****************************************************************************
82 struct BusContext *AllocPrometheusCard(ULONG index, struct DevBase *base)
84 BOOL success = TRUE;
85 struct BusContext *context;
86 PCIBoard *card = NULL;
87 UWORD i = 0;
88 UPINT vendor_id, product_id;
90 /* Find a compatible card */
92 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
93 if(context == NULL)
94 success = FALSE;
96 if(success)
98 while(i <= index)
100 card = Prm_FindBoardTagList(card, NULL);
101 Prm_GetBoardAttrsTags(card, PRM_Vendor, (UPINT)&vendor_id,
102 PRM_Device, (UPINT)&product_id, TAG_END);
103 if(IsCardCompatible(vendor_id, product_id, base))
104 i++;
107 context->card = card;
108 context->id = product_id;
109 if(card == NULL)
110 success = FALSE;
113 if(success)
115 /* Get I/O base address */
117 Prm_GetBoardAttrsTags(card, PRM_MemoryAddr0 + BAR_NO,
118 (UPINT)&context->io_base, TAG_END);
119 if(context->io_base == 0)
120 success = FALSE;
123 /* Lock card */
125 if(success)
127 if(!Prm_SetBoardAttrsTags(card, PRM_BoardOwner, (UPINT)base, TAG_END))
128 success = FALSE;
131 if(!success)
133 FreePrometheusCard(context, base);
134 context = NULL;
137 return context;
142 /****i* atheros5000.device/FreePrometheusCard ******************************
144 * NAME
145 * FreePrometheusCard -- Release a card.
147 * SYNOPSIS
148 * FreePrometheusCard(context)
150 * VOID FreePrometheusCard(struct BusContext *);
152 ****************************************************************************
156 VOID FreePrometheusCard(struct BusContext *context, struct DevBase *base)
158 PCIBoard *card;
159 APTR owner;
161 if(context != NULL)
163 card = context->card;
164 if(card != NULL)
166 /* Unlock board */
168 Prm_GetBoardAttrsTags(card, PRM_BoardOwner, (UPINT)&owner,
169 TAG_END);
170 if(owner == base)
171 Prm_SetBoardAttrsTags(card, PRM_BoardOwner, NULL, TAG_END);
174 FreeMem(context, sizeof(struct BusContext));
177 return;
182 /****i* atheros5000.device/AddPrometheusIntServer **************************
184 * NAME
185 * AddPrometheusIntServer
187 * SYNOPSIS
188 * success = AddPrometheusIntServer(card, interrupt)
190 * BOOL AddPrometheusIntServer(APTR, struct Interrupt *);
192 ****************************************************************************
196 BOOL AddPrometheusIntServer(APTR card, struct Interrupt *interrupt,
197 struct DevBase *base)
199 return Prm_AddIntServer(card, interrupt);
204 /****i* atheros5000.device/RemPrometheusIntServer **************************
206 * NAME
207 * RemPrometheusIntServer
209 * SYNOPSIS
210 * RemPrometheusIntServer(card, interrupt)
212 * VOID RemPrometheusIntServer(APTR, struct Interrupt *);
214 ****************************************************************************
218 VOID RemPrometheusIntServer(APTR card, struct Interrupt *interrupt,
219 struct DevBase *base)
221 Prm_RemIntServer(card, interrupt);
223 return;
228 /****i* atheros5000.device/AllocPrometheusDMAMem ***************************
230 * NAME
231 * AllocPrometheusDMAMem
233 * SYNOPSIS
234 * mem = AllocPrometheusDMAMem(context, size, alignment)
236 * APTR AllocPrometheusDMAMem(struct BusContext *, UPINT, UWORD);
238 ****************************************************************************
240 * Alignment currently must be minimum of 8 bytes.
244 APTR AllocPrometheusDMAMem(UPINT size, struct DevBase *base)
246 return Prm_AllocDMABuffer(size);
251 /****i* atheros5000.device/FreePrometheusDMAMem ****************************
253 * NAME
254 * FreePrometheusDMAMem
256 * SYNOPSIS
257 * FreePrometheusDMAMem(context, mem)
259 * VOID FreePrometheusDMAMem(struct BusContext *, APTR);
261 ****************************************************************************
265 VOID FreePrometheusDMAMem(APTR mem, UPINT size, struct DevBase *base)
267 Prm_FreeDMABuffer(mem, size);
269 return;