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,
23 #include <exec/types.h>
24 #include <libraries/openpci.h>
26 #include <proto/exec.h>
27 #include <proto/openpci.h>
31 #include "pci_protos.h"
32 #include "openpci_protos.h"
35 /****i* atheros5000.device/GetOpenPCICount *********************************
41 * count = GetOpenPCICount()
43 * ULONG GetOpenPCICount();
45 ****************************************************************************
49 ULONG
GetOpenPCICount(struct DevBase
*base
)
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
))
68 /****i* atheros5000.device/AllocOpenPCICard ********************************
71 * AllocOpenPCICard -- Take control of a card.
74 * context = AllocOpenPCICard(index)
76 * struct BusContext *AllocOpenPCICard(ULONG);
78 ****************************************************************************
82 struct BusContext
*AllocOpenPCICard(ULONG index
, struct DevBase
*base
)
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
);
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
))
106 context
->card
= card
;
107 context
->id
= product_id
;
110 /* Get base address */
114 context
->io_base
= (UPINT
)card
->base_address
[BAR_NO
];
115 if(context
->io_base
== NULL
)
118 /* Only enable card once, otherwise it may stop working */
120 if((pci_read_config_word(PCI_COMMAND
, card
)
121 & (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
)) == 0)
122 pci_write_config_word(PCI_COMMAND
,
123 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
, card
);
128 FreeOpenPCICard(context
, base
);
137 /****i* atheros5000.device/FreeOpenPCICard *********************************
140 * FreeOpenPCICard -- Release a card.
143 * FreeOpenPCICard(context)
145 * VOID FreeOpenPCICard(struct BusContext *);
147 ****************************************************************************
151 VOID
FreeOpenPCICard(struct BusContext
*context
, struct DevBase
*base
)
154 FreeMem(context
, sizeof(struct BusContext
));
161 /****i* atheros5000.device/AddOpenPCIIntServer *****************************
164 * AddOpenPCIIntServer
167 * success = AddOpenPCIIntServer(card, interrupt)
169 * BOOL AddOpenPCIIntServer(APTR, struct Interrupt *);
171 ****************************************************************************
175 BOOL
AddOpenPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
176 struct DevBase
*base
)
178 return pci_add_intserver(interrupt
, card
);
183 /****i* atheros5000.device/RemOpenPCIIntServer *****************************
186 * RemOpenPCIIntServer
189 * RemOpenPCIIntServer(card, interrupt)
191 * VOID RemOpenPCIIntServer(APTR, struct Interrupt *);
193 ****************************************************************************
197 VOID
RemOpenPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
198 struct DevBase
*base
)
200 pci_rem_intserver(interrupt
, card
);