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* etherlink3.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* etherlink3.device/AllocOpenPCICard *********************************
71 * AllocOpenPCICard -- Create a unit.
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
;
111 /* Get base address and generation */
115 context
->io_base
= (UPINT
)card
->base_address
[BAR_NO
];
116 if(context
->io_base
== NULL
)
118 pci_write_config_word(PCI_COMMAND
,
119 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
, card
);
120 context
->generation
= GetGeneration(product_id
, base
);
122 /* Cards requiring DMA are not supported under MorphOS because
123 logical and physical addresses differ */
125 if (context
->generation
>= BOOMERANG_GEN
)
131 FreeOpenPCICard(context
, base
);
140 /****i* etherlink3.device/FreeOpenPCICard **********************************
146 * FreeOpenPCICard(context)
148 * VOID FreeOpenPCICard(struct BusContext *);
150 ****************************************************************************
154 VOID
FreeOpenPCICard(struct BusContext
*context
, struct DevBase
*base
)
157 FreeMem(context
, sizeof(struct BusContext
));
164 /****i* etherlink3.device/AddOpenPCIIntServer ******************************
167 * AddOpenPCIIntServer
170 * success = AddOpenPCIIntServer(card, interrupt)
172 * BOOL AddOpenPCIIntServer(APTR, struct Interrupt *);
174 ****************************************************************************
178 BOOL
AddOpenPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
179 struct DevBase
*base
)
181 return pci_add_intserver(interrupt
, card
);
186 /****i* etherlink3.device/RemOpenPCIIntServer ******************************
189 * RemOpenPCIIntServer
192 * RemOpenPCIIntServer(card, interrupt)
194 * VOID RemOpenPCIIntServer(APTR, struct Interrupt *);
196 ****************************************************************************
200 VOID
RemOpenPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
201 struct DevBase
*base
)
203 pci_rem_intserver(interrupt
, card
);