]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/staging/comedi/drivers/icp_multi.h
2 comedi/drivers/icp_multi.h
6 Author: Anne Smorthit <anne.smorthit@sfwte.ch>
13 #include "../comedidev.h"
14 #include "comedi_pci.h"
16 /****************************************************************************/
18 struct pcilst_struct
{
19 struct pcilst_struct
*next
;
21 struct pci_dev
*pcidev
;
22 unsigned short vendor
;
23 unsigned short device
;
24 unsigned char pci_bus
;
25 unsigned char pci_slot
;
26 unsigned char pci_func
;
27 resource_size_t io_addr
[5];
31 struct pcilst_struct
*inova_devices
;
32 /* ptr to root list of all Inova devices */
34 /****************************************************************************/
36 static void pci_card_list_init(unsigned short pci_vendor
, char display
);
37 static void pci_card_list_cleanup(unsigned short pci_vendor
);
38 static struct pcilst_struct
*find_free_pci_card_by_device(unsigned short
42 static int find_free_pci_card_by_position(unsigned short vendor_id
,
43 unsigned short device_id
,
44 unsigned short pci_bus
,
45 unsigned short pci_slot
,
46 struct pcilst_struct
**card
);
47 static struct pcilst_struct
*select_and_alloc_pci_card(unsigned short vendor_id
,
48 unsigned short device_id
,
49 unsigned short pci_bus
,
50 unsigned short pci_slot
);
52 static int pci_card_alloc(struct pcilst_struct
*amcc
);
53 static int pci_card_free(struct pcilst_struct
*amcc
);
54 static void pci_card_list_display(void);
55 static int pci_card_data(struct pcilst_struct
*amcc
,
56 unsigned char *pci_bus
, unsigned char *pci_slot
,
57 unsigned char *pci_func
, resource_size_t
* io_addr
,
60 /****************************************************************************/
62 /* build list of Inova cards in this system */
63 static void pci_card_list_init(unsigned short pci_vendor
, char display
)
65 struct pci_dev
*pcidev
;
66 struct pcilst_struct
*inova
, *last
;
72 for (pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
74 pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pcidev
)) {
75 if (pcidev
->vendor
== pci_vendor
) {
76 inova
= kzalloc(sizeof(*inova
), GFP_KERNEL
);
79 ("icp_multi: pci_card_list_init: allocation failed\n");
84 inova
->pcidev
= pci_dev_get(pcidev
);
88 inova_devices
= inova
;
92 inova
->vendor
= pcidev
->vendor
;
93 inova
->device
= pcidev
->device
;
94 inova
->pci_bus
= pcidev
->bus
->number
;
95 inova
->pci_slot
= PCI_SLOT(pcidev
->devfn
);
96 inova
->pci_func
= PCI_FUNC(pcidev
->devfn
);
97 /* Note: resources may be invalid if PCI device
98 * not enabled, but they are corrected in
100 for (i
= 0; i
< 5; i
++)
102 pci_resource_start(pcidev
, i
);
103 inova
->irq
= pcidev
->irq
;
108 pci_card_list_display();
111 /****************************************************************************/
112 /* free up list of amcc cards in this system */
113 static void pci_card_list_cleanup(unsigned short pci_vendor
)
115 struct pcilst_struct
*inova
, *next
;
117 for (inova
= inova_devices
; inova
; inova
= next
) {
119 pci_dev_put(inova
->pcidev
);
123 inova_devices
= NULL
;
126 /****************************************************************************/
127 /* find first unused card with this device_id */
128 static struct pcilst_struct
*find_free_pci_card_by_device(unsigned short
133 struct pcilst_struct
*inova
, *next
;
135 for (inova
= inova_devices
; inova
; inova
= next
) {
137 if ((!inova
->used
) && (inova
->device
== device_id
)
138 && (inova
->vendor
== vendor_id
))
146 /****************************************************************************/
147 /* find card on requested position */
148 static int find_free_pci_card_by_position(unsigned short vendor_id
,
149 unsigned short device_id
,
150 unsigned short pci_bus
,
151 unsigned short pci_slot
,
152 struct pcilst_struct
**card
)
154 struct pcilst_struct
*inova
, *next
;
157 for (inova
= inova_devices
; inova
; inova
= next
) {
159 if ((inova
->vendor
== vendor_id
) && (inova
->device
== device_id
)
160 && (inova
->pci_bus
== pci_bus
)
161 && (inova
->pci_slot
== pci_slot
)) {
162 if (!(inova
->used
)) {
164 return 0; /* ok, card is found */
166 return 2; /* card exist but is used */
171 return 1; /* no card found */
174 /****************************************************************************/
175 /* mark card as used */
176 static int pci_card_alloc(struct pcilst_struct
*inova
)
181 printk(" - BUG!! inova is NULL!\n");
187 if (comedi_pci_enable(inova
->pcidev
, "icp_multi")) {
188 printk(" - Can't enable PCI device and request regions!\n");
191 /* Resources will be accurate now. */
192 for (i
= 0; i
< 5; i
++)
193 inova
->io_addr
[i
] = pci_resource_start(inova
->pcidev
, i
);
194 inova
->irq
= inova
->pcidev
->irq
;
199 /****************************************************************************/
200 /* mark card as free */
201 static int pci_card_free(struct pcilst_struct
*inova
)
209 comedi_pci_disable(inova
->pcidev
);
213 /****************************************************************************/
214 /* display list of found cards */
215 static void pci_card_list_display(void)
217 struct pcilst_struct
*inova
, *next
;
219 printk("Anne's List of pci cards\n");
220 printk("bus:slot:func vendor device io_inova io_daq irq used\n");
222 for (inova
= inova_devices
; inova
; inova
= next
) {
225 ("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n",
226 inova
->pci_bus
, inova
->pci_slot
, inova
->pci_func
,
227 inova
->vendor
, inova
->device
,
228 (unsigned long long)inova
->io_addr
[0],
229 (unsigned long long)inova
->io_addr
[2], inova
->irq
,
235 /****************************************************************************/
236 /* return all card information for driver */
237 static int pci_card_data(struct pcilst_struct
*inova
,
238 unsigned char *pci_bus
, unsigned char *pci_slot
,
239 unsigned char *pci_func
, resource_size_t
* io_addr
,
246 *pci_bus
= inova
->pci_bus
;
247 *pci_slot
= inova
->pci_slot
;
248 *pci_func
= inova
->pci_func
;
249 for (i
= 0; i
< 5; i
++)
250 io_addr
[i
] = inova
->io_addr
[i
];
255 /****************************************************************************/
256 /* select and alloc card */
257 static struct pcilst_struct
*select_and_alloc_pci_card(unsigned short vendor_id
,
258 unsigned short device_id
,
259 unsigned short pci_bus
,
260 unsigned short pci_slot
)
262 struct pcilst_struct
*card
;
265 if ((pci_bus
< 1) & (pci_slot
< 1)) { /* use autodetection */
267 card
= find_free_pci_card_by_device(vendor_id
, device_id
);
269 printk(" - Unused card not found in system!\n");
273 switch (find_free_pci_card_by_position(vendor_id
, device_id
,
278 (" - Card not found on requested position b:s %d:%d!\n",
283 (" - Card on requested position is used b:s %d:%d!\n",
289 err
= pci_card_alloc(card
);
292 printk(" - Can't allocate card!\n");
293 /* else: error already printed. */