grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / networks / intelpro100 / openpci.c
blob31ca0fdd36bd6145b301e2f8465ebe67a283a382
1 /*
3 Copyright (C) 2004,2005 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>
25 #include <emul/emulinterface.h>
27 #include <proto/exec.h>
28 #include <proto/openpci.h>
30 #include "pci.h"
32 #include "pci_protos.h"
33 #include "openpci_protos.h"
36 /****i* intelpro100.device/GetOpenPCICount *********************************
38 * NAME
39 * GetOpenPCICount
41 * SYNOPSIS
42 * count = GetOpenPCICount()
44 * ULONG GetOpenPCICount();
46 ****************************************************************************
50 ULONG GetOpenPCICount(struct DevBase *base)
52 ULONG count = 0;
53 struct pci_dev *card = NULL;
54 UWORD vendor_id, product_id;
56 while((card = pci_find_device(0xffff, 0xffff, card)) != NULL)
58 product_id = pci_read_config_word(PCI_DEVICE_ID, card);
59 vendor_id = pci_read_config_word(PCI_VENDOR_ID, card);
60 if(IsCardCompatible(vendor_id, product_id, base))
61 count++;
64 return count;
69 /****i* intelpro100.device/AllocOpenPCICard ********************************
71 * NAME
72 * AllocOpenPCICard -- Take control of a card.
74 * SYNOPSIS
75 * context = AllocOpenPCICard(index)
77 * struct BusContext *AllocOpenPCICard(ULONG);
79 ****************************************************************************
83 struct BusContext *AllocOpenPCICard(ULONG index, struct DevBase *base)
85 BOOL success = TRUE;
86 struct BusContext *context;
87 struct pci_dev *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_config_word(PCI_DEVICE_ID, card);
102 vendor_id = pci_read_config_word(PCI_VENDOR_ID, card);
103 if(IsCardCompatible(vendor_id, product_id, base))
104 i++;
107 context->card = card;
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 stops working */
120 if((pci_read_config_word(PCI_COMMAND, card)
121 & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)) == 0)
123 pci_write_config_word(PCI_COMMAND,
124 PCI_COMMAND_MEMORY | PCI_COMMAND_IO, card);
128 if(!success)
130 FreeOpenPCICard(context, base);
131 context = NULL;
134 return context;
139 /****i* intelpro100.device/FreeOpenPCICard *********************************
141 * NAME
142 * FreeOpenPCICard -- Release a card.
144 * SYNOPSIS
145 * FreeOpenPCICard(context)
147 * VOID FreeOpenPCICard(struct BusContext *);
149 ****************************************************************************
153 VOID FreeOpenPCICard(struct BusContext *context, struct DevBase *base)
155 if(context != NULL)
156 FreeMem(context, sizeof(struct BusContext));
158 return;
163 /****i* intelpro100.device/AddOpenPCIIntServer *****************************
165 * NAME
166 * AddOpenPCIIntServer
168 * SYNOPSIS
169 * context = AddOpenPCIIntServer(index)
171 * struct BusContext *AddOpenPCIIntServer(ULONG);
173 ****************************************************************************
177 BOOL AddOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
178 struct DevBase *base)
180 return pci_add_intserver(interrupt, card);
185 /****i* intelpro100.device/RemOpenPCIIntServer *****************************
187 * NAME
188 * RemOpenPCIIntServer
190 * SYNOPSIS
191 * RemOpenPCIIntServer()
193 * VOID RemOpenPCIIntServer(ULONG);
195 ****************************************************************************
199 VOID RemOpenPCIIntServer(APTR card, struct Interrupt *interrupt,
200 struct DevBase *base)
202 pci_rem_intserver(interrupt, card);
204 return;