grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / networks / prism2 / cybpci.c
blob8311ca4eb955dbd28fd8a691b670a86a4aea1fa1
1 /*
3 Copyright (C) 2004-2012 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/cybpci.h>
26 #include <proto/exec.h>
27 #include <proto/cybpci.h>
29 #include "pci.h"
30 #include "plx9052.h"
32 #include "pci_protos.h"
33 #include "cybpci_protos.h"
36 /****i* prism2.device/GetCybPCICount ***************************************
38 * NAME
39 * GetCybPCICount
41 * SYNOPSIS
42 * count = GetCybPCICount()
44 * ULONG GetCybPCICount();
46 ****************************************************************************
50 ULONG GetCybPCICount(struct DevBase *base)
52 ULONG count = 0;
53 APTR card = NULL;
54 UWORD vendor_id, product_id;
56 while((card = PCIFindBoardTagList(card, NULL)) != NULL)
58 vendor_id = PCIReadConfigWord(card, CYBPCICONFIG_VENDOR);
59 product_id = PCIReadConfigWord(card, CYBPCICONFIG_DEVICE);
60 if(IsCardCompatible(vendor_id, product_id, base))
61 count++;
64 return count;
69 /****i* prism2.device/AllocCybPCICard **************************************
71 * NAME
72 * AllocCybPCICard -- Create a unit.
74 * SYNOPSIS
75 * context = AllocCybPCICard(index)
77 * struct BusContext *AllocCybPCICard(ULONG);
79 ****************************************************************************
83 struct BusContext *AllocCybPCICard(ULONG index, struct DevBase *base)
85 BOOL success = TRUE;
86 struct BusContext *context;
87 APTR card = NULL;
88 UWORD i = 0;
89 UPINT vendor_id, product_id, plx_base;
90 UBYTE io_range_no;
91 volatile UBYTE *cor_reg;
92 ULONG pci_control;
94 /* Find a compatible card */
96 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
97 if(context == NULL)
98 success = FALSE;
100 if(success)
102 while(i <= index)
104 card = PCIFindBoardTagList(card, NULL);
105 vendor_id = PCIReadConfigWord(card, CYBPCICONFIG_VENDOR);
106 product_id = PCIReadConfigWord(card, CYBPCICONFIG_DEVICE);
107 if(IsCardCompatible(vendor_id, product_id, base))
108 i++;
111 context->card = card;
112 if(card == NULL)
113 success = FALSE;
116 if(success)
118 /* Find out what type of Prism II PCI card this is */
120 context->bus_type = GetBusType(product_id, base);
122 if(context->bus_type == TMD_BUS)
124 /* Enable the PCCard */
126 cor_reg = (APTR)PCIGetBoardAttr(card, CYBPCITAG_BASEADDRESS1);
127 BYTEOUT((UPINT)cor_reg, COR_ENABLE);
128 io_range_no = 2;
130 else if(context->bus_type == PLX_BUS)
132 /* Enable interrupts on the bridge */
134 plx_base = PCIGetBoardAttr(card, CYBPCITAG_BASEADDRESS1);
135 LELONGOUT(plx_base + PLX9052_INTS,
136 LELONGIN(plx_base + PLX9052_INTS) | (1 << 6));
138 /* Enable the PCCard */
140 cor_reg = (APTR)PCIGetBoardAttr(card, CYBPCITAG_BASEADDRESS2);
141 cor_reg += 0x3e0;
142 *cor_reg = COR_ENABLE;
143 io_range_no = 3;
145 else
146 io_range_no = 0;
148 /* Get the I/O base of the wireless chip */
150 context->io_base = PCIGetBoardAttr(card,
151 CYBPCITAG_BASEADDRESS0 + io_range_no);
152 if(context->io_base == 0)
153 success = FALSE;
156 if(!success)
158 FreeCybPCICard(context, base);
159 context = NULL;
162 return context;
167 /****i* prism2.device/FreeCybPCICard ***************************************
169 * NAME
170 * FreeCybPCICard
172 * SYNOPSIS
173 * FreeCybPCICard(context)
175 * VOID FreeCybPCICard(struct BusContext *);
177 ****************************************************************************
181 VOID FreeCybPCICard(struct BusContext *context, struct DevBase *base)
183 APTR card;
184 APTR owner;
186 if(context != NULL)
187 FreeMem(context, sizeof(struct BusContext));
189 return;
194 /****i* prism2.device/AddCybPCIIntServer ***********************************
196 * NAME
197 * AddCybPCIIntServer
199 * SYNOPSIS
200 * success = AddCybPCIIntServer(card, interrupt)
202 * BOOL AddCybPCIIntServer(APTR, struct Interrupt *);
204 ****************************************************************************
208 BOOL AddCybPCIIntServer(APTR card, struct Interrupt *interrupt,
209 struct DevBase *base)
211 return (interrupt->is_Data = PCICreateIntObjectTagList(card,
212 (APTR)interrupt->is_Code, interrupt->is_Data, NULL)) != NULL;
217 /****i* prism2.device/RemCybPCIIntServer ***********************************
219 * NAME
220 * RemCybPCIIntServer
222 * SYNOPSIS
223 * RemCybPCIIntServer(card, interrupt)
225 * VOID RemCybPCIIntServer(APTR, struct Interrupt *);
227 ****************************************************************************
231 VOID RemCybPCIIntServer(APTR card, struct Interrupt *interrupt,
232 struct DevBase *base)
234 if(interrupt->is_Data != NULL)
235 PCIDeleteIntObject(interrupt->is_Data);
237 return;