store the pre-alphacomposit hook and allow it to be queried.
[AROS.git] / workbench / devs / networks / prism2 / powerpci.c
blobc0364164836737dae62e4577e2a40354356492f7
1 /*
3 Copyright (C) 2004-2010 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 "pci.h"
30 #include "plx9052.h"
32 #include "pci_protos.h"
33 #include "powerpci_protos.h"
36 /****i* prism2.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 vendor_id = pci_read_conf_word(card, PCI_VENDOR_ID);
59 product_id = pci_read_conf_word(card, PCI_DEVICE_ID);
60 if(IsCardCompatible(vendor_id, product_id, base))
61 count++;
64 return count;
69 /****i* prism2.device/AllocPowerPCICard ************************************
71 * NAME
72 * AllocPowerPCICard
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;
89 UBYTE io_range_no;
90 volatile UBYTE *cor_reg;
91 UPINT int_reg;
93 /* Find a compatible card */
95 context = AllocMem(sizeof(struct BusContext), MEMF_PUBLIC | MEMF_CLEAR);
96 if(context == NULL)
97 success = FALSE;
99 if(success)
101 while(i <= index)
103 card = pci_find_device(0xffff, 0xffff, card);
104 product_id = pci_read_conf_word(card, PCI_DEVICE_ID);
105 vendor_id = pci_read_conf_word(card, PCI_VENDOR_ID);
106 if(IsCardCompatible(vendor_id, product_id, base))
107 i++;
110 context->card = (APTR)card;
111 if(card == NULL)
112 success = FALSE;
115 if(success)
117 /* Find out what type of Prism II PCI card this is */
119 context->bus_type = GetBusType(product_id, base);
121 if(context->bus_type == TMD_BUS)
123 /* Enable the PCCard */
125 cor_reg = pci_get_base_start(card, 1);
126 BYTEOUT((UPINT)cor_reg, COR_ENABLE);
127 io_range_no = 2;
129 else if(context->bus_type == PLX_BUS)
131 /* Enable the PCCard */
133 cor_reg = pci_get_base_start(card, 2) + 0x3e0;
134 *cor_reg = COR_ENABLE;
136 /* Enable interrupts on the bridge */
138 int_reg = (UPINT)pci_get_base_start(card, 1) + PLX9052_INTS;
139 LELONGOUT(int_reg, LELONGIN(int_reg) | (1 << 6));
140 io_range_no = 3;
142 else
143 io_range_no = 0;
145 /* Get the I/O base of the wireless chip */
147 context->io_base = (UPINT)pci_get_base_start(card, io_range_no);
148 if(context->io_base == NULL)
149 success = FALSE;
152 if(!success)
154 FreePowerPCICard(context, base);
155 context = NULL;
158 return context;
163 /****i* prism2.device/FreePowerPCICard *************************************
165 * NAME
166 * FreePowerPCICard
168 * SYNOPSIS
169 * FreePowerPCICard(context)
171 * VOID FreePowerPCICard(struct BusContext *);
173 ****************************************************************************
177 VOID FreePowerPCICard(struct BusContext *context, struct DevBase *base)
179 if(context != NULL)
180 FreeMem(context, sizeof(struct BusContext));
182 return;
187 /****i* prism2.device/AddPowerPCIIntServer *********************************
189 * NAME
190 * AddPowerPCIIntServer
192 * SYNOPSIS
193 * success = AddPowerPCIIntServer(card, interrupt)
195 * BOOL AddPowerPCIIntServer(APTR, struct Interrupt *);
197 ****************************************************************************
201 BOOL AddPowerPCIIntServer(APTR card, struct Interrupt *interrupt,
202 struct DevBase *base)
204 return pci_add_irq((ULONG)card, interrupt);
209 /****i* prism2.device/RemPowerPCIIntServer *********************************
211 * NAME
212 * RemPowerPCIIntServer
214 * SYNOPSIS
215 * RemPowerPCIIntServer(card, interrupt)
217 * VOID RemPowerPCIIntServer(APTR, struct Interrupt *);
219 ****************************************************************************
223 VOID RemPowerPCIIntServer(APTR card, struct Interrupt *interrupt,
224 struct DevBase *base)
226 pci_rem_irq((ULONG)card, interrupt);
228 return;