Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / networks / atheros5000 / expansion.c
blob4c9a9e390d0e4cb6e9ae54acb3c39c2fcb67a6af
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 <expansion/pci.h>
26 #include <proto/exec.h>
27 #include <proto/expansion.h>
29 #include "pci.h"
31 #include "pci_protos.h"
32 #include "expansion_protos.h"
33 #include "hal/ah.h"
36 IMPORT const UWORD product_codes[];
39 /****i* atheros.device/GetExpansionCount ***********************************
41 * NAME
42 * GetExpansionCount -- Get the number of compatible PCI Cards.
44 * SYNOPSIS
45 * count = GetExpansionCount()
47 * ULONG GetExpansionCount();
49 ****************************************************************************
53 ULONG GetExpansionCount(struct DevBase *base)
55 ULONG count = 0;
56 struct PCIDevice *card;
58 if(base->i_pci != NULL)
60 while((card =
61 base->i_pci->FindDeviceTags(FDT_CandidateList, product_codes,
62 FDT_Index, count, TAG_END)) != NULL)
64 base->i_pci->FreeDevice(card);
65 count++;
69 return count;
74 /****i* atheros.device/AllocExpansionCard **********************************
76 * NAME
77 * AllocExpansionCard -- Take control of a card.
79 * SYNOPSIS
80 * context = AllocExpansionCard(index)
82 * struct BusContext *AllocExpansionCard(ULONG);
84 ****************************************************************************
88 struct BusContext *AllocExpansionCard(ULONG index, struct DevBase *base)
90 BOOL success = TRUE;
91 struct BusContext *context;
92 struct PCIDevice *card = NULL;
93 struct PCIResourceRange *io_range = NULL;
95 /* Find a compatible card */
97 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
98 if(context == NULL)
99 success = FALSE;
101 if(success)
103 context->card = card =
104 base->i_pci->FindDeviceTags(FDT_CandidateList, product_codes,
105 FDT_Index, index, TAG_END);
106 context->id = 0x0013;
107 if(card == NULL)
108 success = FALSE;
111 /* Lock card */
113 if(success)
114 success = card->Lock(PCI_LOCK_EXCLUSIVE);
116 if(success)
118 card->WriteConfigWord(PCI_COMMAND,
119 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); /* For PegII */
121 /* Get the I/O base of the wireless chip */
123 context->have_card = TRUE;
124 card->SetEndian(PCI_MODE_LITTLE_ENDIAN);
125 io_range = card->GetResourceRange(BAR_NO);
126 context->io_base = io_range->BaseAddress;
127 card->FreeResourceRange(io_range);
130 if(!success)
132 FreeExpansionCard(context, base);
133 context = NULL;
136 return context;
141 /****i* atheros.device/FreeExpansionCard ***********************************
143 * NAME
144 * FreeExpansionCard -- Release a card.
146 * SYNOPSIS
147 * FreeExpansionCard(context)
149 * VOID FreeExpansionCard(struct BusContext *);
151 ****************************************************************************
155 VOID FreeExpansionCard(struct BusContext *context, struct DevBase *base)
157 struct PCIDevice *card;
159 if(context != NULL)
161 card = context->card;
162 if(card != NULL)
164 if(context->have_card)
165 card->Unlock();
166 base->i_pci->FreeDevice(card);
167 FreeMem(context, sizeof(struct BusContext));
171 return;
176 /****i* atheros.device/AddExpansionIntServer *******************************
178 * NAME
179 * AddExpansionIntServer
181 * SYNOPSIS
182 * success = AddExpansionIntServer(card, interrupt)
184 * BOOL AddExpansionIntServer(APTR, struct Interrupt *);
186 ****************************************************************************
190 BOOL AddExpansionIntServer(APTR card, struct Interrupt *interrupt,
191 struct DevBase *base)
193 return AddIntServer(((struct PCIDevice *)card)->MapInterrupt(),
194 interrupt);
199 /****i* atheros.device/RemExpansionIntServer *******************************
201 * NAME
202 * RemExpansionIntServer
204 * SYNOPSIS
205 * RemExpansionIntServer(card, interrupt)
207 * VOID RemExpansionIntServer(APTR, struct Interrupt *);
209 ****************************************************************************
213 VOID RemExpansionIntServer(APTR card, struct Interrupt *interrupt,
214 struct DevBase *base)
216 RemIntServer(((struct PCIDevice *)card)->MapInterrupt(), interrupt);
218 return;