Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / networks / atheros5000 / openpci.c
blob01dd3d7aec60212f0e1a2a5b40b708a5eca3b1e4
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/openpci.h>
26 #include <proto/exec.h>
27 #include <proto/openpci.h>
29 #include "pci.h"
31 #include "pci_protos.h"
32 #include "openpci_protos.h"
35 /****i* atheros5000.device/GetOpenPCICount *********************************
37 * NAME
38 * GetOpenPCICount
40 * SYNOPSIS
41 * count = GetOpenPCICount()
43 * ULONG GetOpenPCICount();
45 ****************************************************************************
49 ULONG GetOpenPCICount(struct DevBase *base)
51 ULONG count = 0;
52 struct pci_dev *card = NULL;
53 UWORD vendor_id, product_id;
55 while((card = pci_find_device(0xffff, 0xffff, card)) != NULL)
57 product_id = pci_read_config_word(PCI_DEVICE_ID, card);
58 vendor_id = pci_read_config_word(PCI_VENDOR_ID, card);
59 if(IsCardCompatible(vendor_id, product_id, base))
60 count++;
63 return count;
68 /****i* atheros5000.device/AllocOpenPCICard ********************************
70 * NAME
71 * AllocOpenPCICard -- Take control of a card.
73 * SYNOPSIS
74 * context = AllocOpenPCICard(index)
76 * struct BusContext *AllocOpenPCICard(ULONG);
78 ****************************************************************************
82 struct BusContext *AllocOpenPCICard(ULONG index, struct DevBase *base)
84 BOOL success = TRUE;
85 struct BusContext *context;
86 struct pci_dev *card = 0;
87 UWORD i = 0, vendor_id, product_id;
89 /* Find a compatible card */
91 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
92 if(context == NULL)
93 success = FALSE;
95 if(success)
97 while(i <= index)
99 card = pci_find_device(0xffff, 0xffff, card);
100 product_id = pci_read_config_word(PCI_DEVICE_ID, card);
101 vendor_id = pci_read_config_word(PCI_VENDOR_ID, card);
102 if(IsCardCompatible(vendor_id, product_id, base))
103 i++;
106 context->card = card;
107 context->id = product_id;
110 /* Get base address */
112 if(success)
114 context->io_base = (UPINT)card->base_address[BAR_NO];
115 if(context->io_base == NULL)
116 success = FALSE;
118 /* Only enable card once, otherwise it may stop working */
120 if((pci_read_config_word(PCI_COMMAND, card)
121 & (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)) == 0)
122 pci_write_config_word(PCI_COMMAND,
123 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, card);
126 if(!success)
128 FreeOpenPCICard(context, base);
129 context = NULL;
132 return context;
137 /****i* atheros5000.device/FreeOpenPCICard *********************************
139 * NAME
140 * FreeOpenPCICard -- Release a card.
142 * SYNOPSIS
143 * FreeOpenPCICard(context)
145 * VOID FreeOpenPCICard(struct BusContext *);
147 ****************************************************************************
151 VOID FreeOpenPCICard(struct BusContext *context, struct DevBase *base)
153 if(context != NULL)
154 FreeMem(context, sizeof(struct BusContext));
156 return;
161 /****i* atheros5000.device/AddOpenPCIIntServer *****************************
163 * NAME
164 * AddOpenPCIIntServer
166 * SYNOPSIS
167 * success = AddOpenPCIIntServer(card, interrupt)
169 * BOOL AddOpenPCIIntServer(APTR, struct Interrupt *);
171 ****************************************************************************
175 BOOL AddOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
176 struct DevBase *base)
178 return pci_add_intserver(interrupt, card);
183 /****i* atheros5000.device/RemOpenPCIIntServer *****************************
185 * NAME
186 * RemOpenPCIIntServer
188 * SYNOPSIS
189 * RemOpenPCIIntServer(card, interrupt)
191 * VOID RemOpenPCIIntServer(APTR, struct Interrupt *);
193 ****************************************************************************
197 VOID RemOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
198 struct DevBase *base)
200 pci_rem_intserver(interrupt, card);
202 return;