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,
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>
32 #include "pci_protos.h"
33 #include "openpci_protos.h"
36 /****i* intelpro100.device/GetOpenPCICount *********************************
42 * count = GetOpenPCICount()
44 * ULONG GetOpenPCICount();
46 ****************************************************************************
50 ULONG
GetOpenPCICount(struct DevBase
*base
)
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
))
69 /****i* intelpro100.device/AllocOpenPCICard ********************************
72 * AllocOpenPCICard -- Take control of a card.
75 * context = AllocOpenPCICard(index)
77 * struct BusContext *AllocOpenPCICard(ULONG);
79 ****************************************************************************
83 struct BusContext
*AllocOpenPCICard(ULONG index
, struct DevBase
*base
)
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
);
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
))
107 context
->card
= card
;
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 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
);
130 FreeOpenPCICard(context
, base
);
139 /****i* intelpro100.device/FreeOpenPCICard *********************************
142 * FreeOpenPCICard -- Release a card.
145 * FreeOpenPCICard(context)
147 * VOID FreeOpenPCICard(struct BusContext *);
149 ****************************************************************************
153 VOID
FreeOpenPCICard(struct BusContext
*context
, struct DevBase
*base
)
156 FreeMem(context
, sizeof(struct BusContext
));
163 /****i* intelpro100.device/AddOpenPCIIntServer *****************************
166 * AddOpenPCIIntServer
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 *****************************
188 * RemOpenPCIIntServer
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
);