Rev 44 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 44 | Rev 362 | ||
|---|---|---|---|
| 1 | //**************************************************************************** |
1 | //**************************************************************************** |
| 2 | // Copyright (C) 2000-2006 ARW Elektronik Germany |
2 | // Copyright (C) 2000-2006 ARW Elektronik Germany |
| 3 | // |
3 | // |
| 4 | // |
4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
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 |
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 |
7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
8 | // (at your option) any later version. |
| 9 | // |
9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
13 | // GNU General Public License for more details. |
| 14 | // |
14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
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 |
16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | // |
18 | // |
| 19 | // This product is not authorized for use as critical component in |
19 | // This product is not authorized for use as critical component in |
| 20 | // life support systems without the express written approval of |
20 | // life support systems without the express written approval of |
| 21 | // ARW Elektronik Germany. |
21 | // ARW Elektronik Germany. |
| 22 | // |
22 | // |
| 23 | // Please announce changes and hints to ARW Elektronik |
23 | // Please announce changes and hints to ARW Elektronik |
| 24 | // |
24 | // |
| 25 | // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de) |
25 | // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de) |
| 26 | // |
26 | // |
| 27 | //**************************************************************************** |
27 | //**************************************************************************** |
| 28 | 28 | ||
| 29 | //**************************************************************************** |
29 | //**************************************************************************** |
| 30 | // |
30 | // |
| 31 | // main.c -- the main driver module for the PCIVME PCI to VME Interface |
31 | // main.c -- the main driver module for the PCIVME PCI to VME Interface |
| 32 | // Thanks to A.Rubini's Book and Dirk Muelhlenberg and H.J.Mathes |
32 | // Thanks to A.Rubini's Book and Dirk Muelhlenberg and H.J.Mathes |
| 33 | // for their arwvme driver |
33 | // for their arwvme driver |
| 34 | // |
34 | // |
| 35 | // $Log: main.c,v $ |
35 | // $Log: main.c,v $ |
| 36 | // Revision 1.10 2006/06/04 12:20:46 klaus |
36 | // Revision 1.10 2006/06/04 12:20:46 klaus |
| 37 | // release_20060604; Version 3.2; pci_{en|dis}able_device() added |
37 | // release_20060604; Version 3.2; pci_{en|dis}able_device() added |
| 38 | // |
38 | // |
| 39 | // Revision 1.9 2004/08/13 19:23:26 klaus |
39 | // Revision 1.9 2004/08/13 19:23:26 klaus |
| 40 | // conversion to kernel-version 2.6, released version 3.0 |
40 | // conversion to kernel-version 2.6, released version 3.0 |
| 41 | // |
41 | // |
| 42 | // Revision 1.8 2003/06/27 17:25:52 klaus |
42 | // Revision 1.8 2003/06/27 17:25:52 klaus |
| 43 | // incomplete try to get mmap() with nopage() running for automatic page switch |
43 | // incomplete try to get mmap() with nopage() running for automatic page switch |
| 44 | // |
44 | // |
| 45 | // Revision 1.7 2002/10/18 21:56:28 klaus |
45 | // Revision 1.7 2002/10/18 21:56:28 klaus |
| 46 | // completed functional features, untested |
46 | // completed functional features, untested |
| 47 | // |
47 | // |
| 48 | // Revision 1.6 2002/10/18 21:56:28 klaus |
48 | // Revision 1.6 2002/10/18 21:56:28 klaus |
| 49 | // completed functional features, untested |
49 | // completed functional features, untested |
| 50 | // |
50 | // |
| 51 | // Revision 1.5 2002/10/17 19:05:03 klaus |
51 | // Revision 1.5 2002/10/17 19:05:03 klaus |
| 52 | // VME access is working through test to lib to driver |
52 | // VME access is working through test to lib to driver |
| 53 | // |
53 | // |
| 54 | //**************************************************************************** |
54 | //**************************************************************************** |
| 55 | #define NOPAGE_SIGBUS (NULL) |
55 | #define NOPAGE_SIGBUS (NULL) |
| 56 | 56 | ||
| 57 | #define VERSION_HI 3 |
57 | #define VERSION_HI 3 |
| 58 | #define VERSION_LO 2 |
58 | #define VERSION_LO 2 |
| 59 | 59 | ||
| 60 | /*--- INCLUDES ---------------------------------------------------------------------------*/ |
60 | /*--- INCLUDES ---------------------------------------------------------------------------*/ |
| 61 | #include "common.h" /* must be the first include */ |
61 | #include "common.h" /* must be the first include */ |
| 62 | #include <linux/module.h> |
62 | #include <linux/module.h> |
| 63 | 63 | ||
| 64 | #include <linux/sched.h> |
64 | #include <linux/sched.h> |
| 65 | #include <linux/proc_fs.h> |
65 | #include <linux/proc_fs.h> |
| 66 | #include <linux/pci.h> |
66 | #include <linux/pci.h> |
| 67 | #include <asm/types.h> |
67 | #include <asm/types.h> |
| 68 | #include <linux/mm.h> |
68 | #include <linux/mm.h> |
| 69 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
69 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 70 | #include <linux/interrupt.h> |
70 | #include <linux/interrupt.h> |
| 71 | #endif |
71 | #endif |
| 72 | 72 | ||
| 73 | #include "askpci.h" |
73 | #include "askpci.h" |
| 74 | #include "plxbug.h" |
74 | #include "plxbug.h" |
| 75 | #include "plx9050.h" |
75 | #include "plx9050.h" |
| 76 | #include "fops.h" |
76 | #include "fops.h" |
| 77 | #include "pcivme.h" |
77 | #include "pcivme.h" |
| 78 | #include "pciif.h" |
78 | #include "pciif.h" |
| 79 | #include "vic.h" |
79 | #include "vic.h" |
| 80 | #include "main.h" |
80 | #include "main.h" |
| 81 | 81 | ||
| 82 | /*--- DEFINES -----------------------------------------------------------------------------*/ |
82 | /*--- DEFINES -----------------------------------------------------------------------------*/ |
| 83 | MODULE_AUTHOR("klaus.hitschler@gmx.de"); |
83 | MODULE_AUTHOR("klaus.hitschler@gmx.de"); |
| 84 | MODULE_DESCRIPTION("Driver for ARW Elektronik PCI VME interface."); |
84 | MODULE_DESCRIPTION("Driver for ARW Elektronik PCI VME interface."); |
| 85 | MODULE_SUPPORTED_DEVICE("PCIVME"); |
85 | MODULE_SUPPORTED_DEVICE("PCIVME"); |
| 86 | MODULE_LICENSE("GPL"); |
86 | MODULE_LICENSE("GPL"); |
| 87 | 87 | ||
| 88 | #define MAJOR_NO 0 /* use dynamic assignment */ |
88 | #define MAJOR_NO 0 /* use dynamic assignment */ |
| 89 | 89 | ||
| 90 | #define PCIVME_VENDOR_ID 0x10B5 |
90 | #define PCIVME_VENDOR_ID 0x10B5 |
| 91 | #define PCIVME_DEVICE_ID 0x9050 |
91 | #define PCIVME_DEVICE_ID 0x9050 |
| 92 | #define PCIVME_SUBSYS_ID 0x1167 |
92 | #define PCIVME_SUBSYS_ID 0x1167 |
| 93 | #define PCIVME_SUBVEN_ID 0x9050 |
93 | #define PCIVME_SUBVEN_ID 0x9050 |
| 94 | 94 | ||
| 95 | /*--- TYPEDEFS ----------------------------------------------------------------------------*/ |
95 | /*--- TYPEDEFS ----------------------------------------------------------------------------*/ |
| 96 | 96 | ||
| 97 | /*--- GLOBALS -----------------------------------------------------------------------------*/ |
97 | /*--- GLOBALS -----------------------------------------------------------------------------*/ |
| 98 | DRIVER_OBJ drv; |
98 | DRIVER_OBJ drv; |
| 99 | 99 | ||
| 100 | /*--- LOCALS ------------------------------------------------------------------------------*/ |
100 | /*--- LOCALS ------------------------------------------------------------------------------*/ |
| 101 | 101 | ||
| 102 | /*--- FUNCTIONS ---------------------------------------------------------------------------*/ |
102 | /*--- FUNCTIONS ---------------------------------------------------------------------------*/ |
| 103 | 103 | ||
| 104 | struct proc_dir_entry *proc; |
104 | struct proc_dir_entry *proc; |
| 105 | 105 | ||
| 106 | static int my_interrupt(u16 intCSR) |
106 | static int my_interrupt(u16 intCSR) |
| 107 | { |
107 | { |
| 108 | int result = NOT_MY_INTERRUPT; |
108 | int result = NOT_MY_INTERRUPT; |
| 109 | 109 | ||
| 110 | if (intCSR & 0x0040) // it is global enabled |
110 | if (intCSR & 0x0040) // it is global enabled |
| 111 | { |
111 | { |
| 112 | if ((intCSR & 0x0028) == 0x0028) // it is a enabled PCIADA interrupt |
112 | if ((intCSR & 0x0028) == 0x0028) // it is a enabled PCIADA interrupt |
| 113 | result = PCIADA_INTERRUPT; |
113 | result = PCIADA_INTERRUPT; |
| 114 | else |
114 | else |
| 115 | if ((intCSR & 0x0005) == 0x0005) // it is a enabled VMEMM interrupt |
115 | if ((intCSR & 0x0005) == 0x0005) // it is a enabled VMEMM interrupt |
| 116 | result = VMEMM_INTERRUPT; |
116 | result = VMEMM_INTERRUPT; |
| 117 | } |
117 | } |
| 118 | 118 | ||
| 119 | return result; |
119 | return result; |
| 120 | } |
120 | } |
| 121 | 121 | ||
| 122 | static irqreturn_t pcivme_irqhandler(int irq, void *dev_id ) |
122 | static irqreturn_t pcivme_irqhandler(int irq, void *dev_id ) |
| 123 | { |
123 | { |
| 124 | DEVICE_OBJ *pd = (DEVICE_OBJ *)dev_id; |
124 | DEVICE_OBJ *pd = (DEVICE_OBJ *)dev_id; |
| 125 | 125 | ||
| 126 | if (pd) |
126 | if (pd) |
| 127 | { |
127 | { |
| 128 | // evaluate the reason of the interrupt - if it is mine |
128 | // evaluate the reason of the interrupt - if it is mine |
| 129 | u16 intCSR = readw((const volatile void *) (pd->pPCIADAIntCSR)); |
129 | u16 intCSR = readw((const volatile void *) (pd->pPCIADAIntCSR)); |
| 130 | int which_interrupt = my_interrupt(intCSR); |
130 | int which_interrupt = my_interrupt(intCSR); |
| 131 | 131 | ||
| 132 | if (which_interrupt) |
132 | if (which_interrupt) |
| 133 | { |
133 | { |
| 134 | writew(intCSR & ~0x40, (volatile void *) pd->pPCIADAIntCSR); /* disable global interrupts */ |
134 | writew(intCSR & ~0x40, (volatile void *) pd->pPCIADAIntCSR); /* disable global interrupts */ |
| 135 | pd->wIrqStatus = (u16)which_interrupt; |
135 | pd->wIrqStatus = (u16)which_interrupt; |
| 136 | pd->dwInterruptCount++; |
136 | pd->dwInterruptCount++; |
| 137 | wake_up_interruptible(&pd->event_queue); /* stop blocking if any */ |
137 | wake_up_interruptible(&pd->event_queue); /* stop blocking if any */ |
| 138 | 138 | ||
| 139 | return IRQ_RETVAL(1); |
139 | return IRQ_RETVAL(1); |
| 140 | } |
140 | } |
| 141 | } |
141 | } |
| 142 | 142 | ||
| 143 | return IRQ_RETVAL(0); |
143 | return IRQ_RETVAL(0); |
| 144 | } |
144 | } |
| 145 | 145 | ||
| 146 | static int request_io_memory(PCIConfig *pPch) |
146 | static int request_io_memory(PCIConfig *pPch) |
| 147 | { |
147 | { |
| 148 | if ( |
148 | if (!request_mem_region(pci_resource_start(pPch->pciDev, 0), LCR_SPACE, DEVICE_NAME) ) { |
| 149 | { |
- | |
| - | 149 | PRINTK(KERN_WARNING "%s: LCR memory region %llx-%llx already in use\n", DEVICE_NAME, |
|
| 150 |
|
150 | pci_resource_start(pPch->pciDev, 0), pci_resource_start(pPch->pciDev, 0) + LCR_SPACE ); |
| - | 151 | kfree(pPch); |
|
| 151 | return |
152 | return EBUSY; |
| 152 | } |
- | |
| 153 | 153 | ||
| - | 154 | }; |
|
| 154 | if ( |
155 | if (!request_mem_region(pci_resource_start(pPch->pciDev, 2), CTL_SPACE, DEVICE_NAME) ){ |
| 155 | { |
- | |
| - | 156 | PRINTK(KERN_WARNING "%s: CTL memory region %llx-%llx already in use\n", DEVICE_NAME, |
|
| 156 |
|
157 | pci_resource_start(pPch->pciDev, 0), pci_resource_start(pPch->pciDev, 2) + CTL_SPACE ); |
| - | 158 | kfree(pPch); |
|
| 157 | return |
159 | return EBUSY; |
| 158 | } |
- | |
| 159 | 160 | ||
| 160 | if (check_mem_region(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE)) |
- | |
| 161 | { |
- | |
| 162 | PRINTK(KERN_DEBUG "%s : VME 0x%08lx\n", DEVICE_NAME, (long unsigned int) pci_resource_start(pPch->pciDev, 2) + CTL_SPACE); |
- | |
| 163 | return -EBUSY; |
- | |
| 164 | } |
161 | } |
| - | 162 | if (!request_mem_region(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE, DEVICE_NAME) ){ |
|
| - | 163 | PRINTK(KERN_WARNING "%s: VME memory region %llx-%llx already in use\n", DEVICE_NAME, |
|
| - | 164 | pci_resource_start(pPch->pciDev, 0)+CTL_SPACE, pci_resource_start(pPch->pciDev, 0) + LCR_SPACE+VME_SPACE ); |
|
| - | 165 | kfree(pPch); |
|
| - | 166 | return EBUSY; |
|
| 165 | 167 | ||
| 166 | request_mem_region(pci_resource_start(pPch->pciDev, 0), LCR_SPACE, DEVICE_NAME); |
- | |
| 167 | request_mem_region(pci_resource_start(pPch->pciDev, 2), CTL_SPACE, DEVICE_NAME); |
- | |
| 168 | request_mem_region(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE, DEVICE_NAME); |
- | |
| 169 | 168 | }; |
|
| 170 | return 0; |
169 | return 0; |
| 171 | } |
170 | } |
| 172 | 171 | ||
| 173 | static void release_io_memory(PCIConfig *pPch) |
172 | static void release_io_memory(PCIConfig *pPch) |
| 174 | { |
173 | { |
| 175 | release_mem_region(pci_resource_start(pPch->pciDev, 0), LCR_SPACE); |
174 | release_mem_region(pci_resource_start(pPch->pciDev, 0), LCR_SPACE); |
| 176 | release_mem_region(pci_resource_start(pPch->pciDev, 2), CTL_SPACE); |
175 | release_mem_region(pci_resource_start(pPch->pciDev, 2), CTL_SPACE); |
| 177 | release_mem_region(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE); |
176 | release_mem_region(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE); |
| 178 | } |
177 | } |
| 179 | 178 | ||
| 180 | static int translate_addresses(DEVICE_OBJ *pd, PCIConfig *pPch) /* differs from PCICC32 */ |
179 | static int translate_addresses(DEVICE_OBJ *pd, PCIConfig *pPch) /* differs from PCICC32 */ |
| 181 | { |
180 | { |
| 182 | if (pci_resource_start(pPch->pciDev, 0) < LOW_MEMORY) /* LCR ISA base addresses */ |
181 | if (pci_resource_start(pPch->pciDev, 0) < LOW_MEMORY) /* LCR ISA base addresses */ |
| 183 | pd->pLCR = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 0)); |
182 | pd->pLCR = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 0)); |
| 184 | else |
183 | else |
| 185 | pd->pLCR = (u32)ioremap(pci_resource_start(pPch->pciDev, 0), LCR_SPACE); |
184 | pd->pLCR = (u32)ioremap(pci_resource_start(pPch->pciDev, 0), LCR_SPACE); |
| 186 | 185 | ||
| 187 | if (pci_resource_start(pPch->pciDev, 2) < LOW_MEMORY) /* User ISA base addresses */ |
186 | if (pci_resource_start(pPch->pciDev, 2) < LOW_MEMORY) /* User ISA base addresses */ |
| 188 | { |
187 | { |
| 189 | pd->pCtl = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 2) ); |
188 | pd->pCtl = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 2) ); |
| 190 | pd->pVME = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE); |
189 | pd->pVME = (u32)bus_to_virt(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE); |
| 191 | } |
190 | } |
| 192 | else |
191 | else |
| 193 | { |
192 | { |
| 194 | pd->pPhysVME = pci_resource_start(pPch->pciDev, 2) + CTL_SPACE; |
193 | pd->pPhysVME = pci_resource_start(pPch->pciDev, 2) + CTL_SPACE; |
| 195 | 194 | ||
| 196 | pd->pCtl = (u32)ioremap(pci_resource_start(pPch->pciDev, 2) , CTL_SPACE); |
195 | pd->pCtl = (u32)ioremap(pci_resource_start(pPch->pciDev, 2) , CTL_SPACE); |
| 197 | pd->pVME = (u32)ioremap(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE); |
196 | pd->pVME = (u32)ioremap(pci_resource_start(pPch->pciDev, 2) + CTL_SPACE, VME_SPACE); |
| 198 | } |
197 | } |
| 199 | 198 | ||
| 200 | return 0; |
199 | return 0; |
| 201 | } |
200 | } |
| 202 | 201 | ||
| 203 | static void un_translate_addresses(DEVICE_OBJ *pd, PCIConfig *pPch) |
202 | static void un_translate_addresses(DEVICE_OBJ *pd, PCIConfig *pPch) |
| 204 | { |
203 | { |
| 205 | if (pci_resource_start(pPch->pciDev, 0) >= LOW_MEMORY) /* no LCR ISA base addresses */ |
204 | if (pci_resource_start(pPch->pciDev, 0) >= LOW_MEMORY) /* no LCR ISA base addresses */ |
| 206 | iounmap((void *)pd->pLCR); |
205 | iounmap((void *)pd->pLCR); |
| 207 | 206 | ||
| 208 | if (pci_resource_start(pPch->pciDev, 2) >= LOW_MEMORY) |
207 | if (pci_resource_start(pPch->pciDev, 2) >= LOW_MEMORY) |
| 209 | { |
208 | { |
| 210 | pd->pPhysVME = 0; |
209 | pd->pPhysVME = 0; |
| 211 | 210 | ||
| 212 | iounmap((void *)pd->pCtl); |
211 | iounmap((void *)pd->pCtl); |
| 213 | iounmap((void *)pd->pVME); |
212 | iounmap((void *)pd->pVME); |
| 214 | } |
213 | } |
| 215 | } |
214 | } |
| 216 | 215 | ||
| 217 | static void soft_init(DEVICE_OBJ *pd) |
216 | static void soft_init(DEVICE_OBJ *pd) |
| 218 | { |
217 | { |
| 219 | if (pd) |
218 | if (pd) |
| 220 | { |
219 | { |
| 221 | init_waitqueue_head(&pd->event_queue); |
220 | init_waitqueue_head(&pd->event_queue); |
| 222 | 221 | ||
| 223 | pd->pLCR = pd->pCtl = pd->pVME = 0; |
222 | pd->pLCR = pd->pCtl = pd->pVME = 0; |
| 224 | pd->pPch = (PCIConfig *)NULL; |
223 | pd->pPch = (PCIConfig *)NULL; |
| 225 | pd->bConnected = 0; |
224 | pd->bConnected = 0; |
| 226 | pd->wInitStep = 0; |
225 | pd->wInitStep = 0; |
| 227 | pd->wIrq = 0xFFFF; |
226 | pd->wIrq = 0xFFFF; |
| 228 | pd->dwInterruptCount = 0; |
227 | pd->dwInterruptCount = 0; |
| 229 | pd->wIrqStatus = 0; |
228 | pd->wIrqStatus = 0; |
| 230 | pd->nOpenCounter = 0; |
229 | pd->nOpenCounter = 0; |
| 231 | 230 | ||
| 232 | pd->cModuleNumber = 255; |
231 | pd->cModuleNumber = 255; |
| 233 | pd->cFPGAVersion = 255; |
232 | pd->cFPGAVersion = 255; |
| 234 | pd->cSystemController = 0; |
233 | pd->cSystemController = 0; |
| 235 | pd->cWordMode = 0; |
234 | pd->cWordMode = 0; |
| 236 | 235 | ||
| 237 | pd->pAdrMod = 0; |
236 | pd->pAdrMod = 0; |
| 238 | pd->pAdrReg = 0; |
237 | pd->pAdrReg = 0; |
| 239 | pd->pCSR = 0; |
238 | pd->pCSR = 0; |
| 240 | 239 | ||
| 241 | pd->pPCIADACntrl = 0; |
240 | pd->pPCIADACntrl = 0; |
| 242 | pd->pPCIADAIntCSR = 0; |
241 | pd->pPCIADAIntCSR = 0; |
| 243 | 242 | ||
| 244 | pd->bCurrentModifier = 0; |
243 | pd->bCurrentModifier = 0; |
| 245 | pd->dwCurrentPageAddress = -1; |
244 | pd->dwCurrentPageAddress = -1; |
| 246 | pd->currentMap.pageptr = NOPAGE_SIGBUS; |
245 | pd->currentMap.pageptr = NOPAGE_SIGBUS; |
| 247 | pd->currentMap.addr = 0; |
246 | pd->currentMap.addr = 0; |
| 248 | } |
247 | } |
| 249 | } |
248 | } |
| 250 | 249 | ||
| 251 | int test_connection(DEVICE_OBJ *pd) |
250 | int test_connection(DEVICE_OBJ *pd) |
| 252 | { |
251 | { |
| 253 | u16 intCSR_store; |
252 | u16 intCSR_store; |
| 254 | u16 cntrl_store; |
253 | u16 cntrl_store; |
| 255 | int i; |
254 | int i; |
| 256 | int error = 0; |
255 | int error = 0; |
| 257 | u32 dwADRH = pd->pCtl + ADRH; |
256 | u32 dwADRH = pd->pCtl + ADRH; |
| 258 | u32 dwADRL = pd->pCtl + ADRL; |
257 | u32 dwADRL = pd->pCtl + ADRL; |
| 259 | u32 dwADRHL = pd->pCtl + ADRHL; |
258 | u32 dwADRHL = pd->pCtl + ADRHL; |
| 260 | u32 dwStore; |
259 | u32 dwStore; |
| 261 | u16 wRet; |
260 | u16 wRet; |
| 262 | 261 | ||
| 263 | cntrl_store = readw((const volatile void *) pd->pPCIADACntrl); /* read CONTROL register */ |
262 | cntrl_store = readw((const volatile void *) pd->pPCIADACntrl); /* read CONTROL register */ |
| 264 | intCSR_store = readw((const volatile void *) pd->pPCIADAIntCSR); /* read interrupt + CSR register */ |
263 | intCSR_store = readw((const volatile void *) pd->pPCIADAIntCSR); /* read interrupt + CSR register */ |
| 265 | 264 | ||
| 266 | writew(0, (volatile void *) pd->pPCIADAIntCSR); /* disable interrupts */ |
265 | writew(0, (volatile void *) pd->pPCIADAIntCSR); /* disable interrupts */ |
| 267 | writew(cntrl_store | 0x0180, (volatile void *) pd->pPCIADACntrl); /* enable access */ |
266 | writew(cntrl_store | 0x0180, (volatile void *) pd->pPCIADACntrl); /* enable access */ |
| 268 | 267 | ||
| 269 | // save adr register |
268 | // save adr register |
| 270 | dwStore = readl((const volatile void *) dwADRHL); |
269 | dwStore = readl((const volatile void *) dwADRHL); |
| 271 | for (i = 1000; i; i--) |
270 | for (i = 1000; i; i--) |
| 272 | { |
271 | { |
| 273 | writew(0x5555, (volatile void *) dwADRH); |
272 | writew(0x5555, (volatile void *) dwADRH); |
| 274 | writew(0xAAAA, (volatile void *) dwADRL); |
273 | writew(0xAAAA, (volatile void *) dwADRL); |
| 275 | wRet = readw((const volatile void *) dwADRH); |
274 | wRet = readw((const volatile void *) dwADRH); |
| 276 | if (wRet != 0x5555) |
275 | if (wRet != 0x5555) |
| 277 | { |
276 | { |
| 278 | error = 1; |
277 | error = 1; |
| 279 | break; |
278 | break; |
| 280 | } |
279 | } |
| 281 | 280 | ||
| 282 | writew(0xAAAA, (volatile void *) dwADRH); |
281 | writew(0xAAAA, (volatile void *) dwADRH); |
| 283 | writew(0x5555, (volatile void *) dwADRL); |
282 | writew(0x5555, (volatile void *) dwADRL); |
| 284 | wRet = readw((const volatile void *) dwADRH); |
283 | wRet = readw((const volatile void *) dwADRH); |
| 285 | if (wRet != 0xAAAA) |
284 | if (wRet != 0xAAAA) |
| 286 | { |
285 | { |
| 287 | error = 1; |
286 | error = 1; |
| 288 | break; |
287 | break; |
| 289 | } |
288 | } |
| 290 | 289 | ||
| 291 | writew(0x0000, (volatile void *) dwADRH); |
290 | writew(0x0000, (volatile void *) dwADRH); |
| 292 | writew(0xFFFF, (volatile void *) dwADRL); |
291 | writew(0xFFFF, (volatile void *) dwADRL); |
| 293 | wRet = readw((const volatile void *) dwADRH); |
292 | wRet = readw((const volatile void *) dwADRH); |
| 294 | if (wRet != 0x0000) |
293 | if (wRet != 0x0000) |
| 295 | { |
294 | { |
| 296 | error = 1; |
295 | error = 1; |
| 297 | break; |
296 | break; |
| 298 | } |
297 | } |
| 299 | 298 | ||
| 300 | writew(0xFFFF, (volatile void *) dwADRH); |
299 | writew(0xFFFF, (volatile void *) dwADRH); |
| 301 | writew(0x0000, (volatile void *) dwADRL); |
300 | writew(0x0000, (volatile void *) dwADRL); |
| 302 | wRet = readw((const volatile void *) dwADRH); |
301 | wRet = readw((const volatile void *) dwADRH); |
| 303 | if (wRet != 0xFFFF) |
302 | if (wRet != 0xFFFF) |
| 304 | { |
303 | { |
| 305 | error = 1; |
304 | error = 1; |
| 306 | break; |
305 | break; |
| 307 | } |
306 | } |
| 308 | } |
307 | } |
| 309 | 308 | ||
| 310 | // restore register |
309 | // restore register |
| 311 | writel(dwStore, (volatile void *) dwADRHL); |
310 | writel(dwStore, (volatile void *) dwADRHL); |
| 312 | 311 | ||
| 313 | //clear possible interrupts |
312 | //clear possible interrupts |
| 314 | writew(cntrl_store & ~0x0100, (volatile void *) pd->pPCIADACntrl); /* clear potential interrupt */ |
313 | writew(cntrl_store & ~0x0100, (volatile void *) pd->pPCIADACntrl); /* clear potential interrupt */ |
| 315 | 314 | ||
| 316 | // restore LCR registers |
315 | // restore LCR registers |
| 317 | writew(cntrl_store, (volatile void *) pd->pPCIADACntrl); |
316 | writew(cntrl_store, (volatile void *) pd->pPCIADACntrl); |
| 318 | writew(intCSR_store, (volatile void *) pd->pPCIADAIntCSR); |
317 | writew(intCSR_store, (volatile void *) pd->pPCIADAIntCSR); |
| 319 | 318 | ||
| 320 | return error; |
319 | return error; |
| 321 | } |
320 | } |
| 322 | 321 | ||
| 323 | int get_module_info(DEVICE_OBJ *pd) |
322 | int get_module_info(DEVICE_OBJ *pd) |
| 324 | { |
323 | { |
| 325 | u16 intCSR_store; |
324 | u16 intCSR_store; |
| 326 | u16 cntrl_store; |
325 | u16 cntrl_store; |
| 327 | int found = 0; |
326 | int found = 0; |
| 328 | u16 data; |
327 | u16 data; |
| 329 | 328 | ||
| 330 | cntrl_store = readw((const volatile void *) pd->pPCIADACntrl); /* read CONTROL register */ |
329 | cntrl_store = readw((const volatile void *) pd->pPCIADACntrl); /* read CONTROL register */ |
| 331 | intCSR_store = readw((const volatile void *) pd->pPCIADAIntCSR); /* read interrupt + CSR register */ |
330 | intCSR_store = readw((const volatile void *) pd->pPCIADAIntCSR); /* read interrupt + CSR register */ |
| 332 | 331 | ||
| 333 | PRINTK(KERN_DEBUG "%s : cntrl=0x%04x, intCSR=0x%04x\n", DEVICE_NAME, cntrl_store, intCSR_store); |
332 | PRINTK(KERN_DEBUG "%s : cntrl=0x%04x, intCSR=0x%04x\n", DEVICE_NAME, cntrl_store, intCSR_store); |
| 334 | 333 | ||
| 335 | if (cntrl_store & 0x0800) /* a VMEMM is connected */ |
334 | if (cntrl_store & 0x0800) /* a VMEMM is connected */ |
| 336 | { |
335 | { |
| 337 | u16 bla = cntrl_store | 0x0180; |
336 | u16 bla = cntrl_store | 0x0180; |
| 338 | 337 | ||
| 339 | writew(0, (volatile void *) pd->pPCIADAIntCSR); /* disable interrupts */ |
338 | writew(0, (volatile void *) pd->pPCIADAIntCSR); /* disable interrupts */ |
| 340 | writew(bla, (volatile void *) pd->pPCIADACntrl); /* enable access */ |
339 | writew(bla, (volatile void *) pd->pPCIADACntrl); /* enable access */ |
| 341 | 340 | ||
| 342 | // read main status register |
341 | // read main status register |
| 343 | data = readw((const volatile void *) pd->pCSR); |
342 | data = readw((const volatile void *) pd->pCSR); |
| 344 | 343 | ||
| 345 | if ((data & 0xF000) != VMEMM_MODULE_TYPE) |
344 | if ((data & 0xF000) != VMEMM_MODULE_TYPE) |
| 346 | { |
345 | { |
| 347 | pd->cModuleNumber = pd->cFPGAVersion = 255; |
346 | pd->cModuleNumber = pd->cFPGAVersion = 255; |
| 348 | printk(KERN_ERR "%s : Wrong module type connected @ index %d!\n", DEVICE_NAME, pd->wIndex); |
347 | printk(KERN_ERR "%s : Wrong module type connected @ index %d!\n", DEVICE_NAME, pd->wIndex); |
| 349 | } |
348 | } |
| 350 | else |
349 | else |
| 351 | { |
350 | { |
| 352 | found = 1; |
351 | found = 1; |
| 353 | pd->cModuleNumber = (data >> 4) & 0xF; |
352 | pd->cModuleNumber = (data >> 4) & 0xF; |
| 354 | pd->cFPGAVersion = (data >> 8) & 0xF; |
353 | pd->cFPGAVersion = (data >> 8) & 0xF; |
| 355 | pd->cSystemController = (data & 0x0008); |
354 | pd->cSystemController = (data & 0x0008); |
| 356 | pd->cWordMode = (data & 0x0004); |
355 | pd->cWordMode = (data & 0x0004); |
| 357 | } |
356 | } |
| 358 | 357 | ||
| 359 | // clear possible interrupts |
358 | // clear possible interrupts |
| 360 | writew(cntrl_store & ~0x0100, (volatile void *) pd->pPCIADACntrl); /* clear potential interrupt */ |
359 | writew(cntrl_store & ~0x0100, (volatile void *) pd->pPCIADACntrl); /* clear potential interrupt */ |
| 361 | 360 | ||
| 362 | /* restore all contents */ |
361 | /* restore all contents */ |
| 363 | writew(cntrl_store, (volatile void *) pd->pPCIADACntrl); |
362 | writew(cntrl_store, (volatile void *) pd->pPCIADACntrl); |
| 364 | writew(intCSR_store, (volatile void *) pd->pPCIADAIntCSR); |
363 | writew(intCSR_store, (volatile void *) pd->pPCIADAIntCSR); |
| 365 | } |
364 | } |
| 366 | 365 | ||
| 367 | return found; |
366 | return found; |
| 368 | } |
367 | } |
| 369 | 368 | ||
| 370 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) |
- | |
| 371 | static int pcivme_read_proc(char *buf, char **start, off_t offset, int len) |
- | |
| 372 | #else |
- | |
| 373 | //static int pcivme_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *data) |
369 | //static int pcivme_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *data) |
| 374 | static |
370 | static ssize_t pcivme_read_proc(struct file *filp,char *buf,size_t count,loff_t *offp ) |
| 375 | #endif |
- | |
| 376 | { |
371 | { |
| 377 | int pos = 0; |
372 | int pos = 0; |
| 378 | DEVICE_OBJ *pd; |
373 | DEVICE_OBJ *pd; |
| 379 | PCIConfig *ch; |
374 | PCIConfig *ch; |
| 380 | u16 cntrl; |
375 | u16 cntrl; |
| 381 | char *cause = "none"; |
376 | char *cause = "none"; |
| 382 | struct list_head *ptr; |
377 | struct list_head *ptr; |
| 383 | PRINTK(KERN_DEBUG "%s : pcivme_read_proc()\n",DEVICE_NAME); |
378 | PRINTK(KERN_DEBUG "%s : pcivme_read_proc()\n",DEVICE_NAME); |
| 384 | 379 | ||
| 385 | if (*offp != 0) return 0; |
380 | if (*offp != 0) return 0; |
| 386 | pos += sprintf(buf + pos, "\nPCIVME information. Version %d.%d |
381 | pos += sprintf(buf + pos, "\nPCIVME information. Version %d.%d from Klaus Hitschler.\n", VERSION_HI, VERSION_LO); |
| 387 | 382 | ||
| 388 | pos += sprintf(buf + pos, " ---------------------\n"); |
383 | pos += sprintf(buf + pos, " ---------------------\n"); |
| 389 | pos += sprintf(buf + pos, " Interfaces found : %d\n", drv.count); |
384 | pos += sprintf(buf + pos, " Interfaces found : %d\n", drv.count); |
| 390 | pos += sprintf(buf + pos, " Major Number : %d\n", drv.nMajor); |
385 | pos += sprintf(buf + pos, " Major Number : %d\n", drv.nMajor); |
| 391 | 386 | ||
| 392 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
387 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
| 393 | { |
388 | { |
| 394 | pd = list_entry(ptr, DEVICE_OBJ, list); |
389 | pd = list_entry(ptr, DEVICE_OBJ, list); |
| 395 | ch = pd->pPch; |
390 | ch = pd->pPch; |
| 396 | cntrl = readw((const volatile void *)(pd->pLCR + PLX9050_CNTRL)); |
391 | cntrl = readw((const volatile void *)(pd->pLCR + PLX9050_CNTRL)); |
| 397 | pos += sprintf(buf + pos, " --- %d ---------------\n", pd->wIndex + 1); |
392 | pos += sprintf(buf + pos, " --- %d ---------------\n", pd->wIndex + 1); |
| 398 | pos += sprintf(buf + pos, " LCR phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 0), pd->pLCR, LCR_SPACE); |
393 | pos += sprintf(buf + pos, " LCR phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 0), pd->pLCR, LCR_SPACE); |
| 399 | pos += sprintf(buf + pos, " Control phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 2), pd->pCtl, CTL_SPACE); |
394 | pos += sprintf(buf + pos, " Control phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 2), pd->pCtl, CTL_SPACE); |
| 400 | pos += sprintf(buf + pos, " VME phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 2) + CTL_SPACE, pd->pVME, VME_SPACE); |
395 | pos += sprintf(buf + pos, " VME phys/virt/size : 0x%08lx/0x%08x/%d\n",(long unsigned int) pci_resource_start(ch->pciDev, 2) + CTL_SPACE, pd->pVME, VME_SPACE); |
| 401 | pos += sprintf(buf + pos, " Irq : %d\n", pd->wIrq); |
396 | pos += sprintf(buf + pos, " Irq : %d\n", pd->wIrq); |
| 402 | 397 | ||
| 403 | if (pd->bConnected) |
398 | if (pd->bConnected) |
| 404 | { |
399 | { |
| 405 | pos += sprintf(buf + pos, " VMEMM is or was : (software) connected.\n"); |
400 | pos += sprintf(buf + pos, " VMEMM is or was : (software) connected.\n"); |
| 406 | pos += sprintf(buf + pos, " Module-Number : %d\n", pd->cModuleNumber); |
401 | pos += sprintf(buf + pos, " Module-Number : %d\n", pd->cModuleNumber); |
| 407 | pos += sprintf(buf + pos, " FPGA-Version : %d\n", pd->cFPGAVersion); |
402 | pos += sprintf(buf + pos, " FPGA-Version : %d\n", pd->cFPGAVersion); |
| 408 | pos += sprintf(buf + pos, " Systemcontroller : %s\n", (pd->cSystemController) ? "yes" : "no"); |
403 | pos += sprintf(buf + pos, " Systemcontroller : %s\n", (pd->cSystemController) ? "yes" : "no"); |
| 409 | pos += sprintf(buf + pos, " Word Mode : %s\n", (pd->cWordMode) ? "yes" : "no"); |
404 | pos += sprintf(buf + pos, " Word Mode : %s\n", (pd->cWordMode) ? "yes" : "no"); |
| 410 | } |
405 | } |
| 411 | else |
406 | else |
| 412 | pos += sprintf(buf + pos, " VMEMM is or was : not (software) connected.\n"); |
407 | pos += sprintf(buf + pos, " VMEMM is or was : not (software) connected.\n"); |
| 413 | 408 | ||
| 414 | if (!((cntrl & 0x0800) && (!(cntrl & 0x0600)))) |
409 | if (!((cntrl & 0x0800) && (!(cntrl & 0x0600)))) |
| 415 | pos += sprintf(buf + pos, " VMEMM is : powered off or cable disconnected.\n"); |
410 | pos += sprintf(buf + pos, " VMEMM is : powered off or cable disconnected.\n"); |
| 416 | 411 | ||
| 417 | pos += sprintf(buf + pos, " IrqCount : %d\n", pd->dwInterruptCount); |
412 | pos += sprintf(buf + pos, " IrqCount : %d\n", pd->dwInterruptCount); |
| 418 | if (pd->wIrqStatus & PCIADA_INTERRUPT) |
413 | if (pd->wIrqStatus & PCIADA_INTERRUPT) |
| 419 | cause = "Timeout"; |
414 | cause = "Timeout"; |
| 420 | else |
415 | else |
| 421 | if (pd->wIrqStatus & VMEMM_INTERRUPT) |
416 | if (pd->wIrqStatus & VMEMM_INTERRUPT) |
| 422 | cause = "VME"; |
417 | cause = "VME"; |
| 423 | pos += sprintf(buf + pos, " Pending IrqStatus : %s\n", cause); |
418 | pos += sprintf(buf + pos, " Pending IrqStatus : %s\n", cause); |
| 424 | } |
419 | } |
| 425 | 420 | ||
| 426 | pos += sprintf(buf + pos, "\n"); |
421 | pos += sprintf(buf + pos, "\n"); |
| 427 | if (pos>count) { |
422 | if (pos>count) { |
| 428 | buf[count-1]=0; |
423 | buf[count-1]=0; |
| 429 | pos=count; |
424 | pos=count; |
| 430 | } |
425 | } |
| 431 | PRINTK(KERN_DEBUG "%s : pcivme_read_proc() end count=%d\n",DEVICE_NAME, pos); |
426 | PRINTK(KERN_DEBUG "%s : pcivme_read_proc() end count=%d\n",DEVICE_NAME, pos); |
| 432 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) |
- | |
| 433 | //*eof = 1; |
427 | //*eof = 1; |
| 434 | #endif |
- | |
| 435 | *offp = pos; |
428 | *offp = pos; |
| 436 | - | ||
| 437 | return pos; |
429 | return pos; |
| 438 | } |
430 | } |
| 439 | 431 | ||
| 440 | - | ||
| 441 | - | ||
| 442 | - | ||
| 443 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) |
- | |
| 444 | struct proc_dir_entry pcimod_proc_entry = |
- | |
| 445 | { |
- | |
| 446 | namelen: 7, /* len of name */ |
- | |
| 447 | name: DEVICE_NAME, /* entry name */ |
- | |
| 448 | mode: S_IFREG | S_IRUGO, /* mode */ |
- | |
| 449 | nlink: 1, /* nlinks */ |
- | |
| 450 | get_info: pcivme_read_proc, /* function used to read data */ |
- | |
| 451 | }; |
- | |
| 452 | #else |
- | |
| 453 |
|
432 | static const struct proc_ops pcivme_read_proc_fops = { |
| 454 |
|
433 | proc_read: pcivme_read_proc |
| 455 | }; |
434 | }; |
| 456 | #endif |
- | |
| 457 | 435 | ||
| 458 | static void deleteMyLists(void) |
436 | static void deleteMyLists(void) |
| 459 | { |
437 | { |
| 460 | DEVICE_OBJ *pd; |
438 | DEVICE_OBJ *pd; |
| 461 | 439 | ||
| 462 | /* delete my lists */ |
440 | /* delete my lists */ |
| 463 | while (!list_empty(&drv.devList)) // cycle through the list of pci devices and remove them |
441 | while (!list_empty(&drv.devList)) // cycle through the list of pci devices and remove them |
| 464 | { |
442 | { |
| 465 | pd = (DEVICE_OBJ *)drv.devList.prev; // empty in reverse order |
443 | pd = (DEVICE_OBJ *)drv.devList.prev; // empty in reverse order |
| 466 | list_del(&pd->list); |
444 | list_del(&pd->list); |
| 467 | kfree(pd); |
445 | kfree(pd); |
| 468 | } |
446 | } |
| 469 | 447 | ||
| 470 | DeletePCIConfig(&drv); |
448 | DeletePCIConfig(&drv); |
| 471 | } |
449 | } |
| 472 | 450 | ||
| 473 | int pcivme_module_init(void) |
451 | int pcivme_module_init(void) |
| 474 | { |
452 | { |
| 475 | PCIConfig *ch; |
453 | PCIConfig *ch; |
| 476 | DEVICE_OBJ *pd; |
454 | DEVICE_OBJ *pd; |
| 477 | int result = 0; |
455 | int result = 0; |
| 478 | struct list_head *ptr; |
456 | struct list_head *ptr; |
| 479 | 457 | ||
| 480 | PRINTK(KERN_DEBUG "%s : init_module\n", DEVICE_NAME); |
458 | PRINTK(KERN_DEBUG "%s : init_module\n", DEVICE_NAME); |
| 481 | 459 | ||
| 482 | /* create list of PCIADAs and work devices */ |
460 | /* create list of PCIADAs and work devices */ |
| 483 | INIT_LIST_HEAD(&drv.devList); |
461 | INIT_LIST_HEAD(&drv.devList); |
| 484 | INIT_LIST_HEAD(&drv.pciList); |
462 | INIT_LIST_HEAD(&drv.pciList); |
| 485 | 463 | ||
| 486 | drv.count = 0; |
464 | drv.count = 0; |
| 487 | 465 | ||
| 488 | /* search for all PCIADA modules */ |
466 | /* search for all PCIADA modules */ |
| 489 | if ((result = GetPCIConfig(&drv, PCIVME_DEVICE_ID, PCIVME_VENDOR_ID, PCIVME_SUBSYS_ID, PCIVME_SUBVEN_ID))) |
467 | if ((result = GetPCIConfig(&drv, PCIVME_DEVICE_ID, PCIVME_VENDOR_ID, PCIVME_SUBSYS_ID, PCIVME_SUBVEN_ID))) |
| 490 | { |
468 | { |
| 491 | deleteMyLists(); |
469 | deleteMyLists(); |
| 492 | return result; |
470 | return result; |
| 493 | } |
471 | } |
| 494 | 472 | ||
| 495 | /* fix the PLX bug in all PCIADAs */ |
473 | /* fix the PLX bug in all PCIADAs */ |
| 496 | for (ptr = drv.pciList.next; ptr != &drv.pciList; ptr = ptr->next) |
474 | for (ptr = drv.pciList.next; ptr != &drv.pciList; ptr = ptr->next) |
| 497 | { |
475 | { |
| 498 | ch = list_entry(ptr, PCIConfig, list); |
476 | ch = list_entry(ptr, PCIConfig, list); |
| 499 | PLX9050BugFix(ch); |
477 | PLX9050BugFix(ch); |
| 500 | } |
478 | } |
| 501 | 479 | ||
| 502 | /* create work_devices and translate the access addresses */ |
480 | /* create work_devices and translate the access addresses */ |
| 503 | for (ptr = drv.pciList.next; ptr != &drv.pciList; ptr = ptr->next) |
481 | for (ptr = drv.pciList.next; ptr != &drv.pciList; ptr = ptr->next) |
| 504 | { |
482 | { |
| 505 | ch = list_entry(ptr, PCIConfig, list); |
483 | ch = list_entry(ptr, PCIConfig, list); |
| 506 | 484 | ||
| 507 | pd = (DEVICE_OBJ *)kmalloc(sizeof(DEVICE_OBJ), GFP_ATOMIC); |
485 | pd = (DEVICE_OBJ *)kmalloc(sizeof(DEVICE_OBJ), GFP_ATOMIC); |
| 508 | soft_init(pd); |
486 | soft_init(pd); |
| 509 | pd->pPch = ch; |
487 | pd->pPch = ch; |
| 510 | pd->wIndex = drv.count; |
488 | pd->wIndex = drv.count; |
| 511 | 489 | ||
| 512 | if (!request_io_memory(ch)) |
490 | if (!request_io_memory(ch)) |
| 513 | { |
491 | { |
| 514 | pd->wInitStep = 1; |
492 | pd->wInitStep = 1; |
| 515 | 493 | ||
| 516 | if (translate_addresses(pd, ch)) |
494 | if (translate_addresses(pd, ch)) |
| 517 | { |
495 | { |
| 518 | printk(KERN_ERR "%s : translation of addresses failed!\n", DEVICE_NAME); |
496 | printk(KERN_ERR "%s : translation of addresses failed!\n", DEVICE_NAME); |
| 519 | kfree_s(pd, sizeof(*pd)); // FREE(pd); |
497 | kfree_s(pd, sizeof(*pd)); // FREE(pd); |
| 520 | } |
498 | } |
| 521 | else |
499 | else |
| 522 | { |
500 | { |
| 523 | // successful translate_addresses |
501 | // successful translate_addresses |
| 524 | pd->wInitStep = 2; |
502 | pd->wInitStep = 2; |
| 525 | 503 | ||
| 526 | // create some 'fast access' addresses |
504 | // create some 'fast access' addresses |
| 527 | pd->pAdrMod = pd->pCtl + VICBASE + AMSR; |
505 | pd->pAdrMod = pd->pCtl + VICBASE + AMSR; |
| 528 | pd->pAdrReg = pd->pCtl + ADRHL; |
506 | pd->pAdrReg = pd->pCtl + ADRHL; |
| 529 | pd->pCSR = pd->pCtl + CSR; |
507 | pd->pCSR = pd->pCtl + CSR; |
| 530 | 508 | ||
| 531 | pd->pPCIADACntrl = pd->pLCR + PLX9050_CNTRL; |
509 | pd->pPCIADACntrl = pd->pLCR + PLX9050_CNTRL; |
| 532 | pd->pPCIADAIntCSR = pd->pLCR + PLX9050_INTCSR; |
510 | pd->pPCIADAIntCSR = pd->pLCR + PLX9050_INTCSR; |
| 533 | 511 | ||
| 534 |
|
512 | //if (request_irq(pd->pPch->pciDev->irq, pcivme_irqhandler, IRQF_DISABLED| IRQF_SHARED, DEVICE_NAME, pd)) |
| - | 513 | if (request_irq(pd->pPch->pciDev->irq, pcivme_irqhandler, IRQF_SHARED, DEVICE_NAME, pd)) |
|
| 535 | { |
514 | { |
| 536 | printk(KERN_ERR "%s : can't get irq @ %d\n", DEVICE_NAME, pd->pPch->pciDev->irq); |
515 | printk(KERN_ERR "%s : can't get irq @ %d\n", DEVICE_NAME, pd->pPch->pciDev->irq); |
| 537 | kfree_s(pd, sizeof(*pd)); // FREE(pd); |
516 | kfree_s(pd, sizeof(*pd)); // FREE(pd); |
| 538 | } |
517 | } |
| 539 | else |
518 | else |
| 540 | { |
519 | { |
| 541 | // successful request_irq |
520 | // successful request_irq |
| 542 | pd->wInitStep = 3; |
521 | pd->wInitStep = 3; |
| 543 | pd->wIrq = pd->pPch->pciDev->irq; |
522 | pd->wIrq = pd->pPch->pciDev->irq; |
| 544 | 523 | ||
| 545 | list_add_tail(&pd->list, &drv.devList); /* add this device to list of working devices*/ |
524 | list_add_tail(&pd->list, &drv.devList); /* add this device to list of working devices*/ |
| 546 | drv.count++; |
525 | drv.count++; |
| 547 | 526 | ||
| 548 | pd->bConnected = get_module_info(pd); |
527 | pd->bConnected = get_module_info(pd); |
| 549 | if (pd->bConnected && test_connection(pd)) |
528 | if (pd->bConnected && test_connection(pd)) |
| 550 | { |
529 | { |
| 551 | printk(KERN_ERR "%s : connection test @ driver install failed!\n", DEVICE_NAME); |
530 | printk(KERN_ERR "%s : connection test @ driver install failed!\n", DEVICE_NAME); |
| 552 | pd->bConnected = 0; |
531 | pd->bConnected = 0; |
| 553 | } |
532 | } |
| 554 | } |
533 | } |
| 555 | } |
534 | } |
| 556 | } |
535 | } |
| 557 | else |
536 | else |
| 558 | printk(KERN_ERR "%s : requested io-memory still claimed!\n", DEVICE_NAME); |
537 | printk(KERN_ERR "%s : requested io-memory still claimed!\n", DEVICE_NAME); |
| 559 | } |
538 | } |
| 560 | 539 | ||
| 561 | drv.nMajor = MAJOR_NO; |
540 | drv.nMajor = MAJOR_NO; |
| 562 | result = register_chrdev(drv.nMajor, DEVICE_NAME, &pcivme_fops); |
541 | result = register_chrdev(drv.nMajor, DEVICE_NAME, &pcivme_fops); |
| 563 | if (result < 0) |
542 | if (result < 0) |
| 564 | { |
543 | { |
| 565 | printk(KERN_ERR "%s: Can't install driver (%d)\n", DEVICE_NAME, result); |
544 | printk(KERN_ERR "%s: Can't install driver (%d)\n", DEVICE_NAME, result); |
| 566 | 545 | ||
| 567 | /* untranslate translated addresses */ |
546 | /* untranslate translated addresses */ |
| 568 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
547 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
| 569 | { |
548 | { |
| 570 | pd = list_entry(ptr, DEVICE_OBJ, list); |
549 | pd = list_entry(ptr, DEVICE_OBJ, list); |
| 571 | ch = pd->pPch; |
550 | ch = pd->pPch; |
| 572 | un_translate_addresses(pd, ch); |
551 | un_translate_addresses(pd, ch); |
| 573 | } |
552 | } |
| 574 | 553 | ||
| 575 | /* delete my lists */ |
554 | /* delete my lists */ |
| 576 | deleteMyLists(); |
555 | deleteMyLists(); |
| 577 | 556 | ||
| 578 | return result; |
557 | return result; |
| 579 | } |
558 | } |
| 580 | else |
559 | else |
| 581 | { |
560 | { |
| 582 | if (drv.nMajor == 0) |
561 | if (drv.nMajor == 0) |
| 583 | drv.nMajor = result; |
562 | drv.nMajor = result; |
| 584 | 563 | ||
| 585 | printk(KERN_DEBUG "%s : major #%d assigned.\n", DEVICE_NAME, drv.nMajor); |
564 | printk(KERN_DEBUG "%s : major #%d assigned.\n", DEVICE_NAME, drv.nMajor); |
| 586 | } |
565 | } |
| 587 | 566 | ||
| 588 | /* register the proc device */ |
567 | /* register the proc device */ |
| 589 | 568 | ||
| 590 | // create_proc_read_entry is depricated since kernel 3.10 |
569 | // create_proc_read_entry is depricated since kernel 3.10 |
| 591 | //return create_proc_read_entry(DEVICE_NAME, 0, NULL, pcivme_read_proc, NULL) ? 0 : -ENODEV; |
570 | //return create_proc_read_entry(DEVICE_NAME, 0, NULL, pcivme_read_proc, NULL) ? 0 : -ENODEV; |
| 592 | proc = proc_create_data(DEVICE_NAME, 0, NULL, &pcivme_read_proc_fops, NULL); |
571 | proc = proc_create_data(DEVICE_NAME, 0, NULL, &pcivme_read_proc_fops, NULL); |
| 593 | return (proc) ? 0 : -ENODEV; |
572 | return (proc) ? 0 : -ENODEV; |
| 594 | 573 | ||
| 595 | } |
574 | } |
| 596 | 575 | ||
| 597 | void pcivme_module_exit(void) |
576 | void pcivme_module_exit(void) |
| 598 | { |
577 | { |
| 599 | PCIConfig *ch; |
578 | PCIConfig *ch; |
| 600 | DEVICE_OBJ *pd; |
579 | DEVICE_OBJ *pd; |
| 601 | struct list_head *ptr; |
580 | struct list_head *ptr; |
| 602 | 581 | ||
| 603 | PRINTK(KERN_DEBUG "%s : cleanup_module.\n", DEVICE_NAME); |
582 | PRINTK(KERN_DEBUG "%s : cleanup_module.\n", DEVICE_NAME); |
| 604 | 583 | ||
| 605 | unregister_chrdev(drv.nMajor, DEVICE_NAME); |
584 | unregister_chrdev(drv.nMajor, DEVICE_NAME); |
| 606 | 585 | ||
| 607 | /* unregister the proc device */ |
586 | /* unregister the proc device */ |
| 608 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) |
- | |
| 609 | proc_unregister(&proc_root, pcimod_proc_entry.low_ino); |
- | |
| 610 | #else |
- | |
| 611 | remove_proc_entry(DEVICE_NAME, NULL); |
587 | remove_proc_entry(DEVICE_NAME, NULL); |
| 612 | #endif |
- | |
| 613 | 588 | ||
| 614 | /* redo all */ |
589 | /* redo all */ |
| 615 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
590 | for (ptr = drv.devList.next; ptr != &drv.devList; ptr = ptr->next) |
| 616 | { |
591 | { |
| 617 | pd = list_entry(ptr, DEVICE_OBJ, list); |
592 | pd = list_entry(ptr, DEVICE_OBJ, list); |
| 618 | ch = pd->pPch; |
593 | ch = pd->pPch; |
| 619 | switch (pd->wInitStep) |
594 | switch (pd->wInitStep) |
| 620 | { |
595 | { |
| 621 | case 3: writew(readw((const volatile void *)(pd->pLCR + PLX9050_INTCSR)) & ~0x40, (volatile void *) (pd->pLCR + PLX9050_INTCSR)); // disable global interrupts |
596 | case 3: writew(readw((const volatile void *)(pd->pLCR + PLX9050_INTCSR)) & ~0x40, (volatile void *) (pd->pLCR + PLX9050_INTCSR)); // disable global interrupts |
| 622 | free_irq(pd->wIrq, pd); |
597 | free_irq(pd->wIrq, pd); |
| 623 | case 2: un_translate_addresses(pd, ch); |
598 | case 2: un_translate_addresses(pd, ch); |
| 624 | case 1: release_io_memory(ch); |
599 | case 1: release_io_memory(ch); |
| 625 | default: pd->wInitStep = 0; |
600 | default: pd->wInitStep = 0; |
| 626 | } |
601 | } |
| 627 | 602 | ||
| 628 | drv.count--; |
603 | drv.count--; |
| 629 | } |
604 | } |
| 630 | 605 | ||
| 631 | deleteMyLists(); |
606 | deleteMyLists(); |
| 632 | 607 | ||
| 633 | return; |
608 | return; |
| 634 | } |
609 | } |
| 635 | 610 | ||
| 636 | module_init(pcivme_module_init); |
611 | module_init(pcivme_module_init); |
| 637 | module_exit(pcivme_module_exit); |
612 | module_exit(pcivme_module_exit); |
| 638 | 613 | ||
| 639 | 614 | ||