Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / networks / etherlink3 / powerpci.c
blob60ff0227d26a93f1ac377cbf590ab8c7f46f25cf
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 <pci/powerpci_pci.h>
26 #include <proto/exec.h>
27 #include <proto/powerpci.h>
29 #include "device.h"
30 #include "pci.h"
32 #include "pci_protos.h"
33 #include "powerpci_protos.h"
36 /****i* etherlink3.device/GetPowerPCICount *********************************
38 * NAME
39 * GetPowerPCICount
41 * SYNOPSIS
42 * count = GetPowerPCICount()
44 * ULONG GetPowerPCICount();
46 ****************************************************************************
50 ULONG GetPowerPCICount(struct DevBase *base)
52 ULONG count = 0;
53 ULONG card = 0;
54 UWORD vendor_id, product_id;
56 while((card = pci_find_device(0xffff, 0xffff, card)) != NULL)
58 product_id = pci_read_conf_word(card, PCI_DEVICE_ID);
59 vendor_id = pci_read_conf_word(card, PCI_VENDOR_ID);
60 if(IsCardCompatible(vendor_id, product_id, base))
61 count++;
64 return count;
69 /****i* etherlink3.device/AllocPowerPCICard ********************************
71 * NAME
72 * AllocPowerPCICard -- Take control of a card.
74 * SYNOPSIS
75 * context = AllocPowerPCICard(index)
77 * struct BusContext *AllocPowerPCICard(ULONG);
79 ****************************************************************************
83 struct BusContext *AllocPowerPCICard(ULONG index, struct DevBase *base)
85 BOOL success = TRUE;
86 struct BusContext *context;
87 ULONG card = 0;
88 UWORD i = 0, 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 = pci_find_device(0xffff, 0xffff, card);
101 product_id = pci_read_conf_word(card, PCI_DEVICE_ID);
102 vendor_id = pci_read_conf_word(card, PCI_VENDOR_ID);
103 if(IsCardCompatible(vendor_id, product_id, base))
104 i++;
107 context->card = (APTR)card;
108 if(card == NULL)
109 success = FALSE;
112 /* Get base address and generation */
114 if(success)
116 context->io_base = (UPINT)pci_get_base_start(card, BAR_NO);
117 if(context->io_base == NULL)
118 success = FALSE;
119 if((context->io_base & 0xffff0000) == 0xee0000)
120 context->io_base += 0x10000;
121 context->generation = GetGeneration(product_id, base);
124 if(!success)
126 FreePowerPCICard(context, base);
127 context = NULL;
130 return context;
135 /****i* etherlink3.device/FreePowerPCICard *********************************
137 * NAME
138 * FreePowerPCICard -- Release a card.
140 * SYNOPSIS
141 * FreePowerPCICard(context)
143 * VOID FreePowerPCICard(struct BusContext *);
145 ****************************************************************************
149 VOID FreePowerPCICard(struct BusContext *context, struct DevBase *base)
151 if(context != NULL)
153 FreeMem(context, sizeof(struct BusContext));
156 return;
161 /****i* etherlink3.device/AddPowerPCIIntServer *****************************
163 * NAME
164 * AddPowerPCIIntServer
166 * SYNOPSIS
167 * success = AddPowerPCIIntServer(card, interrupt)
169 * BOOL AddPowerPCIIntServer(APTR, struct Interrupt *);
171 ****************************************************************************
175 BOOL AddPowerPCIIntServer(APTR card, struct Interrupt *interrupt,
176 struct DevBase *base)
178 return pci_add_irq((ULONG)card, interrupt);
183 /****i* etherlink3.device/RemPowerPCIIntServer *****************************
185 * NAME
186 * RemPowerPCIIntServer
188 * SYNOPSIS
189 * RemPowerPCIIntServer(card, interrupt)
191 * VOID RemPowerPCIIntServer(APTR, struct Interrupt *);
193 ****************************************************************************
197 VOID RemPowerPCIIntServer(APTR card, struct Interrupt *interrupt,
198 struct DevBase *base)
200 pci_rem_irq((ULONG)card, interrupt);
202 return;