- Fixes to OS wrappers to allow extra mask parameter for PCCard status
[AROS.git] / workbench / devs / networks / etherlink3 / openpci.c
blob4001656ce3112653728f7fa71ea79f7b0f1eb0c1
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* etherlink3.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* etherlink3.device/AllocOpenPCICard *********************************
70 * NAME
71 * AllocOpenPCICard -- Create a unit.
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 if(card == NULL)
108 success = FALSE;
111 /* Get base address and generation */
113 if(success)
115 context->io_base = (UPINT)card->base_address[BAR_NO];
116 if(context->io_base == NULL)
117 success = FALSE;
118 pci_write_config_word(PCI_COMMAND,
119 PCI_COMMAND_MEMORY | PCI_COMMAND_IO, card);
120 context->generation = GetGeneration(product_id, base);
122 /* Cards requiring DMA are not supported under MorphOS because
123 logical and physical addresses differ */
125 if (context->generation >= BOOMERANG_GEN)
126 success = FALSE;
129 if(!success)
131 FreeOpenPCICard(context, base);
132 context = NULL;
135 return context;
140 /****i* etherlink3.device/FreeOpenPCICard **********************************
142 * NAME
143 * FreeOpenPCICard
145 * SYNOPSIS
146 * FreeOpenPCICard(context)
148 * VOID FreeOpenPCICard(struct BusContext *);
150 ****************************************************************************
154 VOID FreeOpenPCICard(struct BusContext *context, struct DevBase *base)
156 if(context != NULL)
157 FreeMem(context, sizeof(struct BusContext));
159 return;
164 /****i* etherlink3.device/AddOpenPCIIntServer ******************************
166 * NAME
167 * AddOpenPCIIntServer
169 * SYNOPSIS
170 * success = AddOpenPCIIntServer(card, interrupt)
172 * BOOL AddOpenPCIIntServer(APTR, struct Interrupt *);
174 ****************************************************************************
178 BOOL AddOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
179 struct DevBase *base)
181 return pci_add_intserver(interrupt, card);
186 /****i* etherlink3.device/RemOpenPCIIntServer ******************************
188 * NAME
189 * RemOpenPCIIntServer
191 * SYNOPSIS
192 * RemOpenPCIIntServer(card, interrupt)
194 * VOID RemOpenPCIIntServer(APTR, struct Interrupt *);
196 ****************************************************************************
200 VOID RemOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
201 struct DevBase *base)
203 pci_rem_intserver(interrupt, card);
205 return;