blob: 4ca9d02cc2c8b869b6f452135e169d46e53f01a0 [file] [log] [blame]
Martyn Welcha17a75e2009-07-31 09:28:17 +01001/*
2 * VME Bridge Framework
3 *
Martyn Welch66bd8db2010-02-18 15:12:52 +00004 * Author: Martyn Welch <martyn.welch@ge.com>
5 * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
Martyn Welcha17a75e2009-07-31 09:28:17 +01006 *
7 * Based on work by Tom Armistead and Ajit Prem
8 * Copyright 2004 Motorola Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
Martyn Welcha17a75e2009-07-31 09:28:17 +010016#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/mm.h>
19#include <linux/types.h>
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/pci.h>
23#include <linux/poll.h>
24#include <linux/highmem.h>
25#include <linux/interrupt.h>
26#include <linux/pagemap.h>
27#include <linux/device.h>
28#include <linux/dma-mapping.h>
29#include <linux/syscalls.h>
Martyn Welch400822f2009-08-11 16:20:22 +010030#include <linux/mutex.h>
Martyn Welcha17a75e2009-07-31 09:28:17 +010031#include <linux/spinlock.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Martyn Welcha17a75e2009-07-31 09:28:17 +010033
34#include "vme.h"
35#include "vme_bridge.h"
36
Martyn Welch400822f2009-08-11 16:20:22 +010037/* Bitmask and mutex to keep track of bridge numbers */
Martyn Welcha17a75e2009-07-31 09:28:17 +010038static unsigned int vme_bus_numbers;
Bill Pemberton1fe923e2010-04-28 16:40:10 -040039static DEFINE_MUTEX(vme_bus_num_mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +010040
Martyn Welchead1f3e2009-12-15 08:43:02 +000041static void __exit vme_exit(void);
42static int __init vme_init(void);
Martyn Welcha17a75e2009-07-31 09:28:17 +010043
44
45/*
46 * Find the bridge resource associated with a specific device resource
47 */
48static struct vme_bridge *dev_to_bridge(struct device *dev)
49{
50 return dev->platform_data;
51}
52
53/*
54 * Find the bridge that the resource is associated with.
55 */
56static struct vme_bridge *find_bridge(struct vme_resource *resource)
57{
58 /* Get list to search */
59 switch (resource->type) {
60 case VME_MASTER:
61 return list_entry(resource->entry, struct vme_master_resource,
62 list)->parent;
63 break;
64 case VME_SLAVE:
65 return list_entry(resource->entry, struct vme_slave_resource,
66 list)->parent;
67 break;
68 case VME_DMA:
69 return list_entry(resource->entry, struct vme_dma_resource,
70 list)->parent;
71 break;
Martyn Welch42fb5032009-08-11 17:44:56 +010072 case VME_LM:
73 return list_entry(resource->entry, struct vme_lm_resource,
74 list)->parent;
75 break;
Martyn Welcha17a75e2009-07-31 09:28:17 +010076 default:
77 printk(KERN_ERR "Unknown resource type\n");
78 return NULL;
79 break;
80 }
81}
82
83/*
84 * Allocate a contiguous block of memory for use by the driver. This is used to
85 * create the buffers for the slave windows.
Martyn Welcha17a75e2009-07-31 09:28:17 +010086 */
Martyn Welchead1f3e2009-12-15 08:43:02 +000087void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
Martyn Welcha17a75e2009-07-31 09:28:17 +010088 dma_addr_t *dma)
89{
90 struct vme_bridge *bridge;
Martyn Welcha17a75e2009-07-31 09:28:17 +010091
Martyn Welchead1f3e2009-12-15 08:43:02 +000092 if (resource == NULL) {
93 printk(KERN_ERR "No resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +010094 return NULL;
95 }
96
97 bridge = find_bridge(resource);
Martyn Welchead1f3e2009-12-15 08:43:02 +000098 if (bridge == NULL) {
99 printk(KERN_ERR "Can't find bridge\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100100 return NULL;
101 }
102
Martyn Welcha17a75e2009-07-31 09:28:17 +0100103 if (bridge->parent == NULL) {
Manohar Vanga7f58f022011-08-10 11:33:46 +0200104 printk(KERN_ERR "Dev entry NULL for"
105 " bridge %s\n", bridge->name);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100106 return NULL;
107 }
Martyn Welcha17a75e2009-07-31 09:28:17 +0100108
Manohar Vanga7f58f022011-08-10 11:33:46 +0200109 if (bridge->alloc_consistent == NULL) {
110 printk(KERN_ERR "alloc_consistent not supported by"
111 " bridge %s\n", bridge->name);
112 return NULL;
113 }
114
115 return bridge->alloc_consistent(bridge->parent, size, dma);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100116}
117EXPORT_SYMBOL(vme_alloc_consistent);
118
119/*
120 * Free previously allocated contiguous block of memory.
Martyn Welcha17a75e2009-07-31 09:28:17 +0100121 */
122void vme_free_consistent(struct vme_resource *resource, size_t size,
123 void *vaddr, dma_addr_t dma)
124{
125 struct vme_bridge *bridge;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100126
Martyn Welchead1f3e2009-12-15 08:43:02 +0000127 if (resource == NULL) {
128 printk(KERN_ERR "No resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100129 return;
130 }
131
132 bridge = find_bridge(resource);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000133 if (bridge == NULL) {
134 printk(KERN_ERR "Can't find bridge\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100135 return;
136 }
137
Manohar Vanga7f58f022011-08-10 11:33:46 +0200138 if (bridge->parent == NULL) {
139 printk(KERN_ERR "Dev entry NULL for"
140 " bridge %s\n", bridge->name);
141 return;
142 }
Martyn Welcha17a75e2009-07-31 09:28:17 +0100143
Manohar Vanga7f58f022011-08-10 11:33:46 +0200144 if (bridge->free_consistent == NULL) {
145 printk(KERN_ERR "free_consistent not supported by"
146 " bridge %s\n", bridge->name);
147 return;
148 }
149
150 bridge->free_consistent(bridge->parent, size, vaddr, dma);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100151}
152EXPORT_SYMBOL(vme_free_consistent);
153
154size_t vme_get_size(struct vme_resource *resource)
155{
156 int enabled, retval;
157 unsigned long long base, size;
158 dma_addr_t buf_base;
159 vme_address_t aspace;
160 vme_cycle_t cycle;
161 vme_width_t dwidth;
162
163 switch (resource->type) {
164 case VME_MASTER:
165 retval = vme_master_get(resource, &enabled, &base, &size,
166 &aspace, &cycle, &dwidth);
167
168 return size;
169 break;
170 case VME_SLAVE:
171 retval = vme_slave_get(resource, &enabled, &base, &size,
172 &buf_base, &aspace, &cycle);
173
174 return size;
175 break;
176 case VME_DMA:
177 return 0;
178 break;
179 default:
180 printk(KERN_ERR "Unknown resource type\n");
181 return 0;
182 break;
183 }
184}
185EXPORT_SYMBOL(vme_get_size);
186
187static int vme_check_window(vme_address_t aspace, unsigned long long vme_base,
188 unsigned long long size)
189{
190 int retval = 0;
191
192 switch (aspace) {
193 case VME_A16:
194 if (((vme_base + size) > VME_A16_MAX) ||
195 (vme_base > VME_A16_MAX))
196 retval = -EFAULT;
197 break;
198 case VME_A24:
199 if (((vme_base + size) > VME_A24_MAX) ||
200 (vme_base > VME_A24_MAX))
201 retval = -EFAULT;
202 break;
203 case VME_A32:
204 if (((vme_base + size) > VME_A32_MAX) ||
205 (vme_base > VME_A32_MAX))
206 retval = -EFAULT;
207 break;
208 case VME_A64:
209 /*
210 * Any value held in an unsigned long long can be used as the
211 * base
212 */
213 break;
214 case VME_CRCSR:
215 if (((vme_base + size) > VME_CRCSR_MAX) ||
216 (vme_base > VME_CRCSR_MAX))
217 retval = -EFAULT;
218 break;
219 case VME_USER1:
220 case VME_USER2:
221 case VME_USER3:
222 case VME_USER4:
223 /* User Defined */
224 break;
225 default:
Martyn Welchead1f3e2009-12-15 08:43:02 +0000226 printk(KERN_ERR "Invalid address space\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100227 retval = -EINVAL;
228 break;
229 }
230
231 return retval;
232}
233
234/*
235 * Request a slave image with specific attributes, return some unique
236 * identifier.
237 */
Martyn Welchead1f3e2009-12-15 08:43:02 +0000238struct vme_resource *vme_slave_request(struct device *dev,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100239 vme_address_t address, vme_cycle_t cycle)
240{
241 struct vme_bridge *bridge;
242 struct list_head *slave_pos = NULL;
243 struct vme_slave_resource *allocated_image = NULL;
244 struct vme_slave_resource *slave_image = NULL;
245 struct vme_resource *resource = NULL;
246
247 bridge = dev_to_bridge(dev);
248 if (bridge == NULL) {
249 printk(KERN_ERR "Can't find VME bus\n");
250 goto err_bus;
251 }
252
253 /* Loop through slave resources */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000254 list_for_each(slave_pos, &bridge->slave_resources) {
Martyn Welcha17a75e2009-07-31 09:28:17 +0100255 slave_image = list_entry(slave_pos,
256 struct vme_slave_resource, list);
257
258 if (slave_image == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000259 printk(KERN_ERR "Registered NULL Slave resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100260 continue;
261 }
262
263 /* Find an unlocked and compatible image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000264 mutex_lock(&slave_image->mtx);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000265 if (((slave_image->address_attr & address) == address) &&
Martyn Welcha17a75e2009-07-31 09:28:17 +0100266 ((slave_image->cycle_attr & cycle) == cycle) &&
267 (slave_image->locked == 0)) {
268
269 slave_image->locked = 1;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000270 mutex_unlock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100271 allocated_image = slave_image;
272 break;
273 }
Emilio G. Cota886953e2010-11-12 11:14:07 +0000274 mutex_unlock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100275 }
276
277 /* No free image */
278 if (allocated_image == NULL)
279 goto err_image;
280
281 resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
282 if (resource == NULL) {
283 printk(KERN_WARNING "Unable to allocate resource structure\n");
284 goto err_alloc;
285 }
286 resource->type = VME_SLAVE;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000287 resource->entry = &allocated_image->list;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100288
289 return resource;
290
291err_alloc:
292 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000293 mutex_lock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100294 slave_image->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000295 mutex_unlock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100296err_image:
297err_bus:
298 return NULL;
299}
300EXPORT_SYMBOL(vme_slave_request);
301
Martyn Welchead1f3e2009-12-15 08:43:02 +0000302int vme_slave_set(struct vme_resource *resource, int enabled,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100303 unsigned long long vme_base, unsigned long long size,
304 dma_addr_t buf_base, vme_address_t aspace, vme_cycle_t cycle)
305{
306 struct vme_bridge *bridge = find_bridge(resource);
307 struct vme_slave_resource *image;
308 int retval;
309
310 if (resource->type != VME_SLAVE) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000311 printk(KERN_ERR "Not a slave resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100312 return -EINVAL;
313 }
314
315 image = list_entry(resource->entry, struct vme_slave_resource, list);
316
317 if (bridge->slave_set == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000318 printk(KERN_ERR "Function not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100319 return -ENOSYS;
320 }
321
Martyn Welchead1f3e2009-12-15 08:43:02 +0000322 if (!(((image->address_attr & aspace) == aspace) &&
Martyn Welcha17a75e2009-07-31 09:28:17 +0100323 ((image->cycle_attr & cycle) == cycle))) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000324 printk(KERN_ERR "Invalid attributes\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100325 return -EINVAL;
326 }
327
328 retval = vme_check_window(aspace, vme_base, size);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000329 if (retval)
Martyn Welcha17a75e2009-07-31 09:28:17 +0100330 return retval;
331
332 return bridge->slave_set(image, enabled, vme_base, size, buf_base,
333 aspace, cycle);
334}
335EXPORT_SYMBOL(vme_slave_set);
336
Martyn Welchead1f3e2009-12-15 08:43:02 +0000337int vme_slave_get(struct vme_resource *resource, int *enabled,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100338 unsigned long long *vme_base, unsigned long long *size,
339 dma_addr_t *buf_base, vme_address_t *aspace, vme_cycle_t *cycle)
340{
341 struct vme_bridge *bridge = find_bridge(resource);
342 struct vme_slave_resource *image;
343
344 if (resource->type != VME_SLAVE) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000345 printk(KERN_ERR "Not a slave resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100346 return -EINVAL;
347 }
348
349 image = list_entry(resource->entry, struct vme_slave_resource, list);
350
Emilio G. Cota51a569f2009-08-10 16:52:42 +0200351 if (bridge->slave_get == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000352 printk(KERN_ERR "vme_slave_get not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100353 return -EINVAL;
354 }
355
356 return bridge->slave_get(image, enabled, vme_base, size, buf_base,
357 aspace, cycle);
358}
359EXPORT_SYMBOL(vme_slave_get);
360
361void vme_slave_free(struct vme_resource *resource)
362{
363 struct vme_slave_resource *slave_image;
364
365 if (resource->type != VME_SLAVE) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000366 printk(KERN_ERR "Not a slave resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100367 return;
368 }
369
370 slave_image = list_entry(resource->entry, struct vme_slave_resource,
371 list);
372 if (slave_image == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000373 printk(KERN_ERR "Can't find slave resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100374 return;
375 }
376
377 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000378 mutex_lock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100379 if (slave_image->locked == 0)
380 printk(KERN_ERR "Image is already free\n");
381
382 slave_image->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000383 mutex_unlock(&slave_image->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100384
385 /* Free up resource memory */
386 kfree(resource);
387}
388EXPORT_SYMBOL(vme_slave_free);
389
390/*
391 * Request a master image with specific attributes, return some unique
392 * identifier.
393 */
Martyn Welchead1f3e2009-12-15 08:43:02 +0000394struct vme_resource *vme_master_request(struct device *dev,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100395 vme_address_t address, vme_cycle_t cycle, vme_width_t dwidth)
396{
397 struct vme_bridge *bridge;
398 struct list_head *master_pos = NULL;
399 struct vme_master_resource *allocated_image = NULL;
400 struct vme_master_resource *master_image = NULL;
401 struct vme_resource *resource = NULL;
402
403 bridge = dev_to_bridge(dev);
404 if (bridge == NULL) {
405 printk(KERN_ERR "Can't find VME bus\n");
406 goto err_bus;
407 }
408
409 /* Loop through master resources */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000410 list_for_each(master_pos, &bridge->master_resources) {
Martyn Welcha17a75e2009-07-31 09:28:17 +0100411 master_image = list_entry(master_pos,
412 struct vme_master_resource, list);
413
414 if (master_image == NULL) {
415 printk(KERN_WARNING "Registered NULL master resource\n");
416 continue;
417 }
418
419 /* Find an unlocked and compatible image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000420 spin_lock(&master_image->lock);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000421 if (((master_image->address_attr & address) == address) &&
Martyn Welcha17a75e2009-07-31 09:28:17 +0100422 ((master_image->cycle_attr & cycle) == cycle) &&
423 ((master_image->width_attr & dwidth) == dwidth) &&
424 (master_image->locked == 0)) {
425
426 master_image->locked = 1;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000427 spin_unlock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100428 allocated_image = master_image;
429 break;
430 }
Emilio G. Cota886953e2010-11-12 11:14:07 +0000431 spin_unlock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100432 }
433
434 /* Check to see if we found a resource */
435 if (allocated_image == NULL) {
436 printk(KERN_ERR "Can't find a suitable resource\n");
437 goto err_image;
438 }
439
440 resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
441 if (resource == NULL) {
442 printk(KERN_ERR "Unable to allocate resource structure\n");
443 goto err_alloc;
444 }
445 resource->type = VME_MASTER;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000446 resource->entry = &allocated_image->list;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100447
448 return resource;
449
Martyn Welcha17a75e2009-07-31 09:28:17 +0100450err_alloc:
451 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000452 spin_lock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100453 master_image->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000454 spin_unlock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100455err_image:
456err_bus:
457 return NULL;
458}
459EXPORT_SYMBOL(vme_master_request);
460
Martyn Welchead1f3e2009-12-15 08:43:02 +0000461int vme_master_set(struct vme_resource *resource, int enabled,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100462 unsigned long long vme_base, unsigned long long size,
463 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth)
464{
465 struct vme_bridge *bridge = find_bridge(resource);
466 struct vme_master_resource *image;
467 int retval;
468
469 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000470 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100471 return -EINVAL;
472 }
473
474 image = list_entry(resource->entry, struct vme_master_resource, list);
475
476 if (bridge->master_set == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000477 printk(KERN_WARNING "vme_master_set not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100478 return -EINVAL;
479 }
480
Martyn Welchead1f3e2009-12-15 08:43:02 +0000481 if (!(((image->address_attr & aspace) == aspace) &&
Martyn Welcha17a75e2009-07-31 09:28:17 +0100482 ((image->cycle_attr & cycle) == cycle) &&
483 ((image->width_attr & dwidth) == dwidth))) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000484 printk(KERN_WARNING "Invalid attributes\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100485 return -EINVAL;
486 }
487
488 retval = vme_check_window(aspace, vme_base, size);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000489 if (retval)
Martyn Welcha17a75e2009-07-31 09:28:17 +0100490 return retval;
491
492 return bridge->master_set(image, enabled, vme_base, size, aspace,
493 cycle, dwidth);
494}
495EXPORT_SYMBOL(vme_master_set);
496
Martyn Welchead1f3e2009-12-15 08:43:02 +0000497int vme_master_get(struct vme_resource *resource, int *enabled,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100498 unsigned long long *vme_base, unsigned long long *size,
499 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
500{
501 struct vme_bridge *bridge = find_bridge(resource);
502 struct vme_master_resource *image;
503
504 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000505 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100506 return -EINVAL;
507 }
508
509 image = list_entry(resource->entry, struct vme_master_resource, list);
510
Emilio G. Cota51a569f2009-08-10 16:52:42 +0200511 if (bridge->master_get == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000512 printk(KERN_WARNING "vme_master_set not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100513 return -EINVAL;
514 }
515
516 return bridge->master_get(image, enabled, vme_base, size, aspace,
517 cycle, dwidth);
518}
519EXPORT_SYMBOL(vme_master_get);
520
521/*
522 * Read data out of VME space into a buffer.
523 */
Martyn Welchead1f3e2009-12-15 08:43:02 +0000524ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100525 loff_t offset)
526{
527 struct vme_bridge *bridge = find_bridge(resource);
528 struct vme_master_resource *image;
529 size_t length;
530
531 if (bridge->master_read == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000532 printk(KERN_WARNING "Reading from resource not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100533 return -EINVAL;
534 }
535
536 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000537 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100538 return -EINVAL;
539 }
540
541 image = list_entry(resource->entry, struct vme_master_resource, list);
542
543 length = vme_get_size(resource);
544
545 if (offset > length) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000546 printk(KERN_WARNING "Invalid Offset\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100547 return -EFAULT;
548 }
549
550 if ((offset + count) > length)
551 count = length - offset;
552
553 return bridge->master_read(image, buf, count, offset);
554
555}
556EXPORT_SYMBOL(vme_master_read);
557
558/*
559 * Write data out to VME space from a buffer.
560 */
Martyn Welchead1f3e2009-12-15 08:43:02 +0000561ssize_t vme_master_write(struct vme_resource *resource, void *buf,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100562 size_t count, loff_t offset)
563{
564 struct vme_bridge *bridge = find_bridge(resource);
565 struct vme_master_resource *image;
566 size_t length;
567
568 if (bridge->master_write == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000569 printk(KERN_WARNING "Writing to resource not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100570 return -EINVAL;
571 }
572
573 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000574 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100575 return -EINVAL;
576 }
577
578 image = list_entry(resource->entry, struct vme_master_resource, list);
579
580 length = vme_get_size(resource);
581
582 if (offset > length) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000583 printk(KERN_WARNING "Invalid Offset\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100584 return -EFAULT;
585 }
586
587 if ((offset + count) > length)
588 count = length - offset;
589
590 return bridge->master_write(image, buf, count, offset);
591}
592EXPORT_SYMBOL(vme_master_write);
593
594/*
595 * Perform RMW cycle to provided location.
596 */
Martyn Welchead1f3e2009-12-15 08:43:02 +0000597unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask,
Martyn Welcha17a75e2009-07-31 09:28:17 +0100598 unsigned int compare, unsigned int swap, loff_t offset)
599{
600 struct vme_bridge *bridge = find_bridge(resource);
601 struct vme_master_resource *image;
602
603 if (bridge->master_rmw == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000604 printk(KERN_WARNING "Writing to resource not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100605 return -EINVAL;
606 }
607
608 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000609 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100610 return -EINVAL;
611 }
612
613 image = list_entry(resource->entry, struct vme_master_resource, list);
614
615 return bridge->master_rmw(image, mask, compare, swap, offset);
616}
617EXPORT_SYMBOL(vme_master_rmw);
618
619void vme_master_free(struct vme_resource *resource)
620{
621 struct vme_master_resource *master_image;
622
623 if (resource->type != VME_MASTER) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000624 printk(KERN_ERR "Not a master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100625 return;
626 }
627
628 master_image = list_entry(resource->entry, struct vme_master_resource,
629 list);
630 if (master_image == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000631 printk(KERN_ERR "Can't find master resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100632 return;
633 }
634
635 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000636 spin_lock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100637 if (master_image->locked == 0)
638 printk(KERN_ERR "Image is already free\n");
639
640 master_image->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000641 spin_unlock(&master_image->lock);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100642
643 /* Free up resource memory */
644 kfree(resource);
645}
646EXPORT_SYMBOL(vme_master_free);
647
648/*
649 * Request a DMA controller with specific attributes, return some unique
650 * identifier.
651 */
Martyn Welch4f723df2010-02-18 15:12:58 +0000652struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
Martyn Welcha17a75e2009-07-31 09:28:17 +0100653{
654 struct vme_bridge *bridge;
655 struct list_head *dma_pos = NULL;
656 struct vme_dma_resource *allocated_ctrlr = NULL;
657 struct vme_dma_resource *dma_ctrlr = NULL;
658 struct vme_resource *resource = NULL;
659
660 /* XXX Not checking resource attributes */
661 printk(KERN_ERR "No VME resource Attribute tests done\n");
662
663 bridge = dev_to_bridge(dev);
664 if (bridge == NULL) {
665 printk(KERN_ERR "Can't find VME bus\n");
666 goto err_bus;
667 }
668
669 /* Loop through DMA resources */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000670 list_for_each(dma_pos, &bridge->dma_resources) {
Martyn Welcha17a75e2009-07-31 09:28:17 +0100671 dma_ctrlr = list_entry(dma_pos,
672 struct vme_dma_resource, list);
673
674 if (dma_ctrlr == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000675 printk(KERN_ERR "Registered NULL DMA resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100676 continue;
677 }
678
Martyn Welch4f723df2010-02-18 15:12:58 +0000679 /* Find an unlocked and compatible controller */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000680 mutex_lock(&dma_ctrlr->mtx);
Martyn Welch4f723df2010-02-18 15:12:58 +0000681 if (((dma_ctrlr->route_attr & route) == route) &&
682 (dma_ctrlr->locked == 0)) {
683
Martyn Welcha17a75e2009-07-31 09:28:17 +0100684 dma_ctrlr->locked = 1;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000685 mutex_unlock(&dma_ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100686 allocated_ctrlr = dma_ctrlr;
687 break;
688 }
Emilio G. Cota886953e2010-11-12 11:14:07 +0000689 mutex_unlock(&dma_ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100690 }
691
692 /* Check to see if we found a resource */
693 if (allocated_ctrlr == NULL)
694 goto err_ctrlr;
695
696 resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
697 if (resource == NULL) {
698 printk(KERN_WARNING "Unable to allocate resource structure\n");
699 goto err_alloc;
700 }
701 resource->type = VME_DMA;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000702 resource->entry = &allocated_ctrlr->list;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100703
704 return resource;
705
706err_alloc:
707 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +0000708 mutex_lock(&dma_ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100709 dma_ctrlr->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000710 mutex_unlock(&dma_ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100711err_ctrlr:
712err_bus:
713 return NULL;
714}
Martyn Welch58e50792009-10-29 16:35:20 +0000715EXPORT_SYMBOL(vme_dma_request);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100716
717/*
718 * Start new list
719 */
720struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource)
721{
722 struct vme_dma_resource *ctrlr;
723 struct vme_dma_list *dma_list;
724
725 if (resource->type != VME_DMA) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000726 printk(KERN_ERR "Not a DMA resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100727 return NULL;
728 }
729
730 ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
731
Martyn Welchead1f3e2009-12-15 08:43:02 +0000732 dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL);
733 if (dma_list == NULL) {
734 printk(KERN_ERR "Unable to allocate memory for new dma list\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100735 return NULL;
736 }
Emilio G. Cota886953e2010-11-12 11:14:07 +0000737 INIT_LIST_HEAD(&dma_list->entries);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100738 dma_list->parent = ctrlr;
Emilio G. Cota886953e2010-11-12 11:14:07 +0000739 mutex_init(&dma_list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100740
741 return dma_list;
742}
743EXPORT_SYMBOL(vme_new_dma_list);
744
745/*
746 * Create "Pattern" type attributes
747 */
748struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern,
749 vme_pattern_t type)
750{
751 struct vme_dma_attr *attributes;
752 struct vme_dma_pattern *pattern_attr;
753
Martyn Welchead1f3e2009-12-15 08:43:02 +0000754 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
755 if (attributes == NULL) {
756 printk(KERN_ERR "Unable to allocate memory for attributes "
757 "structure\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100758 goto err_attr;
759 }
760
Martyn Welchead1f3e2009-12-15 08:43:02 +0000761 pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL);
762 if (pattern_attr == NULL) {
763 printk(KERN_ERR "Unable to allocate memory for pattern "
764 "attributes\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100765 goto err_pat;
766 }
767
768 attributes->type = VME_DMA_PATTERN;
769 attributes->private = (void *)pattern_attr;
770
771 pattern_attr->pattern = pattern;
772 pattern_attr->type = type;
773
774 return attributes;
775
Martyn Welcha17a75e2009-07-31 09:28:17 +0100776err_pat:
777 kfree(attributes);
778err_attr:
779 return NULL;
780}
781EXPORT_SYMBOL(vme_dma_pattern_attribute);
782
783/*
784 * Create "PCI" type attributes
785 */
786struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address)
787{
788 struct vme_dma_attr *attributes;
789 struct vme_dma_pci *pci_attr;
790
791 /* XXX Run some sanity checks here */
792
Martyn Welchead1f3e2009-12-15 08:43:02 +0000793 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
794 if (attributes == NULL) {
795 printk(KERN_ERR "Unable to allocate memory for attributes "
796 "structure\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100797 goto err_attr;
798 }
799
Martyn Welchead1f3e2009-12-15 08:43:02 +0000800 pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL);
801 if (pci_attr == NULL) {
802 printk(KERN_ERR "Unable to allocate memory for pci "
803 "attributes\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100804 goto err_pci;
805 }
806
807
808
809 attributes->type = VME_DMA_PCI;
810 attributes->private = (void *)pci_attr;
811
812 pci_attr->address = address;
813
814 return attributes;
815
Martyn Welcha17a75e2009-07-31 09:28:17 +0100816err_pci:
817 kfree(attributes);
818err_attr:
819 return NULL;
820}
821EXPORT_SYMBOL(vme_dma_pci_attribute);
822
823/*
824 * Create "VME" type attributes
825 */
826struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address,
827 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth)
828{
829 struct vme_dma_attr *attributes;
830 struct vme_dma_vme *vme_attr;
831
Martyn Welchead1f3e2009-12-15 08:43:02 +0000832 attributes = kmalloc(
Martyn Welcha17a75e2009-07-31 09:28:17 +0100833 sizeof(struct vme_dma_attr), GFP_KERNEL);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000834 if (attributes == NULL) {
835 printk(KERN_ERR "Unable to allocate memory for attributes "
836 "structure\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100837 goto err_attr;
838 }
839
Martyn Welchead1f3e2009-12-15 08:43:02 +0000840 vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL);
841 if (vme_attr == NULL) {
842 printk(KERN_ERR "Unable to allocate memory for vme "
843 "attributes\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100844 goto err_vme;
845 }
846
847 attributes->type = VME_DMA_VME;
848 attributes->private = (void *)vme_attr;
849
850 vme_attr->address = address;
851 vme_attr->aspace = aspace;
852 vme_attr->cycle = cycle;
853 vme_attr->dwidth = dwidth;
854
855 return attributes;
856
Martyn Welcha17a75e2009-07-31 09:28:17 +0100857err_vme:
858 kfree(attributes);
859err_attr:
860 return NULL;
861}
862EXPORT_SYMBOL(vme_dma_vme_attribute);
863
864/*
865 * Free attribute
866 */
867void vme_dma_free_attribute(struct vme_dma_attr *attributes)
868{
869 kfree(attributes->private);
870 kfree(attributes);
871}
872EXPORT_SYMBOL(vme_dma_free_attribute);
873
874int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
875 struct vme_dma_attr *dest, size_t count)
876{
877 struct vme_bridge *bridge = list->parent->parent;
878 int retval;
879
880 if (bridge->dma_list_add == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000881 printk(KERN_WARNING "Link List DMA generation not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100882 return -EINVAL;
883 }
884
Emilio G. Cota886953e2010-11-12 11:14:07 +0000885 if (!mutex_trylock(&list->mtx)) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000886 printk(KERN_ERR "Link List already submitted\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100887 return -EINVAL;
888 }
889
890 retval = bridge->dma_list_add(list, src, dest, count);
891
Emilio G. Cota886953e2010-11-12 11:14:07 +0000892 mutex_unlock(&list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100893
894 return retval;
895}
896EXPORT_SYMBOL(vme_dma_list_add);
897
898int vme_dma_list_exec(struct vme_dma_list *list)
899{
900 struct vme_bridge *bridge = list->parent->parent;
901 int retval;
902
903 if (bridge->dma_list_exec == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000904 printk(KERN_ERR "Link List DMA execution not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100905 return -EINVAL;
906 }
907
Emilio G. Cota886953e2010-11-12 11:14:07 +0000908 mutex_lock(&list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100909
910 retval = bridge->dma_list_exec(list);
911
Emilio G. Cota886953e2010-11-12 11:14:07 +0000912 mutex_unlock(&list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100913
914 return retval;
915}
916EXPORT_SYMBOL(vme_dma_list_exec);
917
918int vme_dma_list_free(struct vme_dma_list *list)
919{
920 struct vme_bridge *bridge = list->parent->parent;
921 int retval;
922
923 if (bridge->dma_list_empty == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000924 printk(KERN_WARNING "Emptying of Link Lists not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100925 return -EINVAL;
926 }
927
Emilio G. Cota886953e2010-11-12 11:14:07 +0000928 if (!mutex_trylock(&list->mtx)) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000929 printk(KERN_ERR "Link List in use\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100930 return -EINVAL;
931 }
932
933 /*
934 * Empty out all of the entries from the dma list. We need to go to the
935 * low level driver as dma entries are driver specific.
936 */
937 retval = bridge->dma_list_empty(list);
938 if (retval) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000939 printk(KERN_ERR "Unable to empty link-list entries\n");
Emilio G. Cota886953e2010-11-12 11:14:07 +0000940 mutex_unlock(&list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100941 return retval;
942 }
Emilio G. Cota886953e2010-11-12 11:14:07 +0000943 mutex_unlock(&list->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100944 kfree(list);
945
946 return retval;
947}
948EXPORT_SYMBOL(vme_dma_list_free);
949
950int vme_dma_free(struct vme_resource *resource)
951{
952 struct vme_dma_resource *ctrlr;
953
954 if (resource->type != VME_DMA) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000955 printk(KERN_ERR "Not a DMA resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100956 return -EINVAL;
957 }
958
959 ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
960
Emilio G. Cota886953e2010-11-12 11:14:07 +0000961 if (!mutex_trylock(&ctrlr->mtx)) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000962 printk(KERN_ERR "Resource busy, can't free\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +0100963 return -EBUSY;
964 }
965
Emilio G. Cota886953e2010-11-12 11:14:07 +0000966 if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000967 printk(KERN_WARNING "Resource still processing transfers\n");
Emilio G. Cota886953e2010-11-12 11:14:07 +0000968 mutex_unlock(&ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100969 return -EBUSY;
970 }
971
972 ctrlr->locked = 0;
973
Emilio G. Cota886953e2010-11-12 11:14:07 +0000974 mutex_unlock(&ctrlr->mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100975
976 return 0;
977}
978EXPORT_SYMBOL(vme_dma_free);
979
Martyn Welchc813f592009-10-29 16:34:54 +0000980void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
981{
982 void (*call)(int, int, void *);
983 void *priv_data;
984
985 call = bridge->irq[level - 1].callback[statid].func;
986 priv_data = bridge->irq[level - 1].callback[statid].priv_data;
987
988 if (call != NULL)
989 call(level, statid, priv_data);
990 else
991 printk(KERN_WARNING "Spurilous VME interrupt, level:%x, "
992 "vector:%x\n", level, statid);
993}
994EXPORT_SYMBOL(vme_irq_handler);
995
996int vme_irq_request(struct device *dev, int level, int statid,
Martyn Welch29848ac2010-02-18 15:13:05 +0000997 void (*callback)(int, int, void *),
Martyn Welcha17a75e2009-07-31 09:28:17 +0100998 void *priv_data)
999{
1000 struct vme_bridge *bridge;
1001
1002 bridge = dev_to_bridge(dev);
1003 if (bridge == NULL) {
1004 printk(KERN_ERR "Can't find VME bus\n");
1005 return -EINVAL;
1006 }
1007
Martyn Welchead1f3e2009-12-15 08:43:02 +00001008 if ((level < 1) || (level > 7)) {
Martyn Welchc813f592009-10-29 16:34:54 +00001009 printk(KERN_ERR "Invalid interrupt level\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001010 return -EINVAL;
1011 }
1012
Martyn Welchc813f592009-10-29 16:34:54 +00001013 if (bridge->irq_set == NULL) {
1014 printk(KERN_ERR "Configuring interrupts not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001015 return -EINVAL;
1016 }
1017
Emilio G. Cota886953e2010-11-12 11:14:07 +00001018 mutex_lock(&bridge->irq_mtx);
Martyn Welchc813f592009-10-29 16:34:54 +00001019
1020 if (bridge->irq[level - 1].callback[statid].func) {
Emilio G. Cota886953e2010-11-12 11:14:07 +00001021 mutex_unlock(&bridge->irq_mtx);
Martyn Welchc813f592009-10-29 16:34:54 +00001022 printk(KERN_WARNING "VME Interrupt already taken\n");
1023 return -EBUSY;
1024 }
1025
1026 bridge->irq[level - 1].count++;
1027 bridge->irq[level - 1].callback[statid].priv_data = priv_data;
1028 bridge->irq[level - 1].callback[statid].func = callback;
1029
1030 /* Enable IRQ level */
Martyn Welch29848ac2010-02-18 15:13:05 +00001031 bridge->irq_set(bridge, level, 1, 1);
Martyn Welchc813f592009-10-29 16:34:54 +00001032
Emilio G. Cota886953e2010-11-12 11:14:07 +00001033 mutex_unlock(&bridge->irq_mtx);
Martyn Welchc813f592009-10-29 16:34:54 +00001034
1035 return 0;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001036}
Martyn Welchc813f592009-10-29 16:34:54 +00001037EXPORT_SYMBOL(vme_irq_request);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001038
Martyn Welchc813f592009-10-29 16:34:54 +00001039void vme_irq_free(struct device *dev, int level, int statid)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001040{
1041 struct vme_bridge *bridge;
1042
1043 bridge = dev_to_bridge(dev);
1044 if (bridge == NULL) {
1045 printk(KERN_ERR "Can't find VME bus\n");
1046 return;
1047 }
1048
Martyn Welchead1f3e2009-12-15 08:43:02 +00001049 if ((level < 1) || (level > 7)) {
Martyn Welchc813f592009-10-29 16:34:54 +00001050 printk(KERN_ERR "Invalid interrupt level\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001051 return;
1052 }
1053
Martyn Welchc813f592009-10-29 16:34:54 +00001054 if (bridge->irq_set == NULL) {
1055 printk(KERN_ERR "Configuring interrupts not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001056 return;
1057 }
1058
Emilio G. Cota886953e2010-11-12 11:14:07 +00001059 mutex_lock(&bridge->irq_mtx);
Martyn Welchc813f592009-10-29 16:34:54 +00001060
1061 bridge->irq[level - 1].count--;
1062
1063 /* Disable IRQ level if no more interrupts attached at this level*/
1064 if (bridge->irq[level - 1].count == 0)
Martyn Welch29848ac2010-02-18 15:13:05 +00001065 bridge->irq_set(bridge, level, 0, 1);
Martyn Welchc813f592009-10-29 16:34:54 +00001066
1067 bridge->irq[level - 1].callback[statid].func = NULL;
1068 bridge->irq[level - 1].callback[statid].priv_data = NULL;
1069
Emilio G. Cota886953e2010-11-12 11:14:07 +00001070 mutex_unlock(&bridge->irq_mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001071}
Martyn Welchc813f592009-10-29 16:34:54 +00001072EXPORT_SYMBOL(vme_irq_free);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001073
Martyn Welchc813f592009-10-29 16:34:54 +00001074int vme_irq_generate(struct device *dev, int level, int statid)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001075{
1076 struct vme_bridge *bridge;
1077
1078 bridge = dev_to_bridge(dev);
1079 if (bridge == NULL) {
1080 printk(KERN_ERR "Can't find VME bus\n");
1081 return -EINVAL;
1082 }
1083
Martyn Welchead1f3e2009-12-15 08:43:02 +00001084 if ((level < 1) || (level > 7)) {
Martyn Welcha17a75e2009-07-31 09:28:17 +01001085 printk(KERN_WARNING "Invalid interrupt level\n");
1086 return -EINVAL;
1087 }
1088
Martyn Welchc813f592009-10-29 16:34:54 +00001089 if (bridge->irq_generate == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +00001090 printk(KERN_WARNING "Interrupt generation not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001091 return -EINVAL;
1092 }
1093
Martyn Welch29848ac2010-02-18 15:13:05 +00001094 return bridge->irq_generate(bridge, level, statid);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001095}
Martyn Welchc813f592009-10-29 16:34:54 +00001096EXPORT_SYMBOL(vme_irq_generate);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001097
Martyn Welch42fb5032009-08-11 17:44:56 +01001098/*
1099 * Request the location monitor, return resource or NULL
1100 */
1101struct vme_resource *vme_lm_request(struct device *dev)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001102{
1103 struct vme_bridge *bridge;
Martyn Welch42fb5032009-08-11 17:44:56 +01001104 struct list_head *lm_pos = NULL;
1105 struct vme_lm_resource *allocated_lm = NULL;
1106 struct vme_lm_resource *lm = NULL;
1107 struct vme_resource *resource = NULL;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001108
1109 bridge = dev_to_bridge(dev);
1110 if (bridge == NULL) {
1111 printk(KERN_ERR "Can't find VME bus\n");
Martyn Welch42fb5032009-08-11 17:44:56 +01001112 goto err_bus;
1113 }
1114
1115 /* Loop through DMA resources */
Emilio G. Cota886953e2010-11-12 11:14:07 +00001116 list_for_each(lm_pos, &bridge->lm_resources) {
Martyn Welch42fb5032009-08-11 17:44:56 +01001117 lm = list_entry(lm_pos,
1118 struct vme_lm_resource, list);
1119
1120 if (lm == NULL) {
1121 printk(KERN_ERR "Registered NULL Location Monitor "
1122 "resource\n");
1123 continue;
1124 }
1125
1126 /* Find an unlocked controller */
Emilio G. Cota886953e2010-11-12 11:14:07 +00001127 mutex_lock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001128 if (lm->locked == 0) {
1129 lm->locked = 1;
Emilio G. Cota886953e2010-11-12 11:14:07 +00001130 mutex_unlock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001131 allocated_lm = lm;
1132 break;
1133 }
Emilio G. Cota886953e2010-11-12 11:14:07 +00001134 mutex_unlock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001135 }
1136
1137 /* Check to see if we found a resource */
1138 if (allocated_lm == NULL)
1139 goto err_lm;
1140
1141 resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
1142 if (resource == NULL) {
1143 printk(KERN_ERR "Unable to allocate resource structure\n");
1144 goto err_alloc;
1145 }
1146 resource->type = VME_LM;
Emilio G. Cota886953e2010-11-12 11:14:07 +00001147 resource->entry = &allocated_lm->list;
Martyn Welch42fb5032009-08-11 17:44:56 +01001148
1149 return resource;
1150
1151err_alloc:
1152 /* Unlock image */
Emilio G. Cota886953e2010-11-12 11:14:07 +00001153 mutex_lock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001154 lm->locked = 0;
Emilio G. Cota886953e2010-11-12 11:14:07 +00001155 mutex_unlock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001156err_lm:
1157err_bus:
1158 return NULL;
1159}
1160EXPORT_SYMBOL(vme_lm_request);
1161
1162int vme_lm_count(struct vme_resource *resource)
1163{
1164 struct vme_lm_resource *lm;
1165
1166 if (resource->type != VME_LM) {
1167 printk(KERN_ERR "Not a Location Monitor resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001168 return -EINVAL;
1169 }
1170
Martyn Welch42fb5032009-08-11 17:44:56 +01001171 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1172
1173 return lm->monitors;
1174}
1175EXPORT_SYMBOL(vme_lm_count);
1176
1177int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base,
1178 vme_address_t aspace, vme_cycle_t cycle)
1179{
1180 struct vme_bridge *bridge = find_bridge(resource);
1181 struct vme_lm_resource *lm;
1182
1183 if (resource->type != VME_LM) {
1184 printk(KERN_ERR "Not a Location Monitor resource\n");
1185 return -EINVAL;
1186 }
1187
1188 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1189
Martyn Welcha17a75e2009-07-31 09:28:17 +01001190 if (bridge->lm_set == NULL) {
Martyn Welch42fb5032009-08-11 17:44:56 +01001191 printk(KERN_ERR "vme_lm_set not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001192 return -EINVAL;
1193 }
1194
Martyn Welch8be92262009-10-29 16:35:08 +00001195 return bridge->lm_set(lm, lm_base, aspace, cycle);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001196}
1197EXPORT_SYMBOL(vme_lm_set);
1198
Martyn Welch42fb5032009-08-11 17:44:56 +01001199int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base,
1200 vme_address_t *aspace, vme_cycle_t *cycle)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001201{
Martyn Welch42fb5032009-08-11 17:44:56 +01001202 struct vme_bridge *bridge = find_bridge(resource);
1203 struct vme_lm_resource *lm;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001204
Martyn Welch42fb5032009-08-11 17:44:56 +01001205 if (resource->type != VME_LM) {
1206 printk(KERN_ERR "Not a Location Monitor resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001207 return -EINVAL;
1208 }
1209
Martyn Welch42fb5032009-08-11 17:44:56 +01001210 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1211
Martyn Welcha17a75e2009-07-31 09:28:17 +01001212 if (bridge->lm_get == NULL) {
Martyn Welch42fb5032009-08-11 17:44:56 +01001213 printk(KERN_ERR "vme_lm_get not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001214 return -EINVAL;
1215 }
1216
Martyn Welch42fb5032009-08-11 17:44:56 +01001217 return bridge->lm_get(lm, lm_base, aspace, cycle);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001218}
1219EXPORT_SYMBOL(vme_lm_get);
1220
Martyn Welch42fb5032009-08-11 17:44:56 +01001221int vme_lm_attach(struct vme_resource *resource, int monitor,
1222 void (*callback)(int))
Martyn Welcha17a75e2009-07-31 09:28:17 +01001223{
Martyn Welch42fb5032009-08-11 17:44:56 +01001224 struct vme_bridge *bridge = find_bridge(resource);
1225 struct vme_lm_resource *lm;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001226
Martyn Welch42fb5032009-08-11 17:44:56 +01001227 if (resource->type != VME_LM) {
1228 printk(KERN_ERR "Not a Location Monitor resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001229 return -EINVAL;
1230 }
1231
Martyn Welch42fb5032009-08-11 17:44:56 +01001232 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1233
Martyn Welcha17a75e2009-07-31 09:28:17 +01001234 if (bridge->lm_attach == NULL) {
Martyn Welch42fb5032009-08-11 17:44:56 +01001235 printk(KERN_ERR "vme_lm_attach not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001236 return -EINVAL;
1237 }
1238
Martyn Welch42fb5032009-08-11 17:44:56 +01001239 return bridge->lm_attach(lm, monitor, callback);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001240}
1241EXPORT_SYMBOL(vme_lm_attach);
1242
Martyn Welch42fb5032009-08-11 17:44:56 +01001243int vme_lm_detach(struct vme_resource *resource, int monitor)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001244{
Martyn Welch42fb5032009-08-11 17:44:56 +01001245 struct vme_bridge *bridge = find_bridge(resource);
1246 struct vme_lm_resource *lm;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001247
Martyn Welch42fb5032009-08-11 17:44:56 +01001248 if (resource->type != VME_LM) {
1249 printk(KERN_ERR "Not a Location Monitor resource\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001250 return -EINVAL;
1251 }
1252
Martyn Welch42fb5032009-08-11 17:44:56 +01001253 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1254
Martyn Welcha17a75e2009-07-31 09:28:17 +01001255 if (bridge->lm_detach == NULL) {
Martyn Welch42fb5032009-08-11 17:44:56 +01001256 printk(KERN_ERR "vme_lm_detach not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001257 return -EINVAL;
1258 }
1259
Martyn Welch42fb5032009-08-11 17:44:56 +01001260 return bridge->lm_detach(lm, monitor);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001261}
1262EXPORT_SYMBOL(vme_lm_detach);
1263
Martyn Welch42fb5032009-08-11 17:44:56 +01001264void vme_lm_free(struct vme_resource *resource)
1265{
1266 struct vme_lm_resource *lm;
1267
1268 if (resource->type != VME_LM) {
1269 printk(KERN_ERR "Not a Location Monitor resource\n");
1270 return;
1271 }
1272
1273 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1274
Emilio G. Cota886953e2010-11-12 11:14:07 +00001275 mutex_lock(&lm->mtx);
Martyn Welch42fb5032009-08-11 17:44:56 +01001276
Martyn Welch8be92262009-10-29 16:35:08 +00001277 /* XXX
1278 * Check to see that there aren't any callbacks still attached, if
1279 * there are we should probably be detaching them!
1280 */
Martyn Welch42fb5032009-08-11 17:44:56 +01001281
1282 lm->locked = 0;
1283
Emilio G. Cota886953e2010-11-12 11:14:07 +00001284 mutex_unlock(&lm->mtx);
Martyn Welch8be92262009-10-29 16:35:08 +00001285
1286 kfree(resource);
Martyn Welch42fb5032009-08-11 17:44:56 +01001287}
1288EXPORT_SYMBOL(vme_lm_free);
1289
Martyn Welcha17a75e2009-07-31 09:28:17 +01001290int vme_slot_get(struct device *bus)
1291{
1292 struct vme_bridge *bridge;
1293
1294 bridge = dev_to_bridge(bus);
1295 if (bridge == NULL) {
1296 printk(KERN_ERR "Can't find VME bus\n");
1297 return -EINVAL;
1298 }
1299
1300 if (bridge->slot_get == NULL) {
Martyn Welchead1f3e2009-12-15 08:43:02 +00001301 printk(KERN_WARNING "vme_slot_get not supported\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001302 return -EINVAL;
1303 }
1304
Martyn Welch29848ac2010-02-18 15:13:05 +00001305 return bridge->slot_get(bridge);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001306}
1307EXPORT_SYMBOL(vme_slot_get);
1308
1309
1310/* - Bridge Registration --------------------------------------------------- */
1311
1312static int vme_alloc_bus_num(void)
1313{
1314 int i;
1315
Martyn Welch400822f2009-08-11 16:20:22 +01001316 mutex_lock(&vme_bus_num_mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001317 for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) {
1318 if (((vme_bus_numbers >> i) & 0x1) == 0) {
1319 vme_bus_numbers |= (0x1 << i);
1320 break;
1321 }
1322 }
Martyn Welch400822f2009-08-11 16:20:22 +01001323 mutex_unlock(&vme_bus_num_mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001324
1325 return i;
1326}
1327
1328static void vme_free_bus_num(int bus)
1329{
Martyn Welch400822f2009-08-11 16:20:22 +01001330 mutex_lock(&vme_bus_num_mtx);
Emilio G. Cotadb6d8fc2010-11-12 11:14:27 +00001331 vme_bus_numbers &= ~(0x1 << bus);
Martyn Welch400822f2009-08-11 16:20:22 +01001332 mutex_unlock(&vme_bus_num_mtx);
Martyn Welcha17a75e2009-07-31 09:28:17 +01001333}
1334
Martyn Welchead1f3e2009-12-15 08:43:02 +00001335int vme_register_bridge(struct vme_bridge *bridge)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001336{
1337 struct device *dev;
1338 int retval;
1339 int i;
1340
1341 bridge->num = vme_alloc_bus_num();
1342
1343 /* This creates 32 vme "slot" devices. This equates to a slot for each
1344 * ID available in a system conforming to the ANSI/VITA 1-1994
1345 * specification.
1346 */
1347 for (i = 0; i < VME_SLOTS_MAX; i++) {
Emilio G. Cota886953e2010-11-12 11:14:07 +00001348 dev = &bridge->dev[i];
Martyn Welcha17a75e2009-07-31 09:28:17 +01001349 memset(dev, 0, sizeof(struct device));
1350
1351 dev->parent = bridge->parent;
Emilio G. Cota886953e2010-11-12 11:14:07 +00001352 dev->bus = &vme_bus_type;
Martyn Welcha17a75e2009-07-31 09:28:17 +01001353 /*
1354 * We save a pointer to the bridge in platform_data so that we
1355 * can get to it later. We keep driver_data for use by the
1356 * driver that binds against the slot
1357 */
1358 dev->platform_data = bridge;
1359 dev_set_name(dev, "vme-%x.%x", bridge->num, i + 1);
1360
1361 retval = device_register(dev);
Martyn Welchead1f3e2009-12-15 08:43:02 +00001362 if (retval)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001363 goto err_reg;
1364 }
1365
1366 return retval;
1367
Martyn Welcha17a75e2009-07-31 09:28:17 +01001368err_reg:
Manohar Vangada1bbd12011-02-23 14:25:28 +01001369 while (--i >= 0) {
Emilio G. Cota886953e2010-11-12 11:14:07 +00001370 dev = &bridge->dev[i];
Martyn Welcha17a75e2009-07-31 09:28:17 +01001371 device_unregister(dev);
1372 }
1373 vme_free_bus_num(bridge->num);
1374 return retval;
1375}
1376EXPORT_SYMBOL(vme_register_bridge);
1377
Martyn Welchead1f3e2009-12-15 08:43:02 +00001378void vme_unregister_bridge(struct vme_bridge *bridge)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001379{
1380 int i;
1381 struct device *dev;
1382
1383
1384 for (i = 0; i < VME_SLOTS_MAX; i++) {
Emilio G. Cota886953e2010-11-12 11:14:07 +00001385 dev = &bridge->dev[i];
Martyn Welcha17a75e2009-07-31 09:28:17 +01001386 device_unregister(dev);
1387 }
1388 vme_free_bus_num(bridge->num);
1389}
1390EXPORT_SYMBOL(vme_unregister_bridge);
1391
1392
1393/* - Driver Registration --------------------------------------------------- */
1394
Martyn Welchead1f3e2009-12-15 08:43:02 +00001395int vme_register_driver(struct vme_driver *drv)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001396{
1397 drv->driver.name = drv->name;
1398 drv->driver.bus = &vme_bus_type;
1399
1400 return driver_register(&drv->driver);
1401}
1402EXPORT_SYMBOL(vme_register_driver);
1403
Martyn Welchead1f3e2009-12-15 08:43:02 +00001404void vme_unregister_driver(struct vme_driver *drv)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001405{
1406 driver_unregister(&drv->driver);
1407}
1408EXPORT_SYMBOL(vme_unregister_driver);
1409
1410/* - Bus Registration ------------------------------------------------------ */
1411
Bill Pembertonb1a5fad42010-04-28 16:40:11 -04001412static int vme_calc_slot(struct device *dev)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001413{
1414 struct vme_bridge *bridge;
1415 int num;
1416
1417 bridge = dev_to_bridge(dev);
1418
1419 /* Determine slot number */
1420 num = 0;
Martyn Welchead1f3e2009-12-15 08:43:02 +00001421 while (num < VME_SLOTS_MAX) {
Emilio G. Cota886953e2010-11-12 11:14:07 +00001422 if (&bridge->dev[num] == dev)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001423 break;
Martyn Welchead1f3e2009-12-15 08:43:02 +00001424
Martyn Welcha17a75e2009-07-31 09:28:17 +01001425 num++;
1426 }
1427 if (num == VME_SLOTS_MAX) {
1428 dev_err(dev, "Failed to identify slot\n");
1429 num = 0;
1430 goto err_dev;
1431 }
1432 num++;
1433
1434err_dev:
1435 return num;
1436}
1437
1438static struct vme_driver *dev_to_vme_driver(struct device *dev)
1439{
Martyn Welchead1f3e2009-12-15 08:43:02 +00001440 if (dev->driver == NULL)
1441 printk(KERN_ERR "Bugger dev->driver is NULL\n");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001442
1443 return container_of(dev->driver, struct vme_driver, driver);
1444}
1445
1446static int vme_bus_match(struct device *dev, struct device_driver *drv)
1447{
1448 struct vme_bridge *bridge;
1449 struct vme_driver *driver;
1450 int i, num;
1451
1452 bridge = dev_to_bridge(dev);
1453 driver = container_of(drv, struct vme_driver, driver);
1454
1455 num = vme_calc_slot(dev);
1456 if (!num)
1457 goto err_dev;
1458
1459 if (driver->bind_table == NULL) {
1460 dev_err(dev, "Bind table NULL\n");
1461 goto err_table;
1462 }
1463
1464 i = 0;
Martyn Welchead1f3e2009-12-15 08:43:02 +00001465 while ((driver->bind_table[i].bus != 0) ||
Martyn Welcha17a75e2009-07-31 09:28:17 +01001466 (driver->bind_table[i].slot != 0)) {
1467
Martyn Welcha37b0da2009-08-06 09:43:07 +01001468 if (bridge->num == driver->bind_table[i].bus) {
1469 if (num == driver->bind_table[i].slot)
1470 return 1;
1471
1472 if (driver->bind_table[i].slot == VME_SLOT_ALL)
1473 return 1;
1474
1475 if ((driver->bind_table[i].slot == VME_SLOT_CURRENT) &&
1476 (num == vme_slot_get(dev)))
1477 return 1;
1478 }
Martyn Welcha17a75e2009-07-31 09:28:17 +01001479 i++;
1480 }
1481
1482err_dev:
1483err_table:
1484 return 0;
1485}
1486
1487static int vme_bus_probe(struct device *dev)
1488{
1489 struct vme_bridge *bridge;
1490 struct vme_driver *driver;
1491 int retval = -ENODEV;
1492
1493 driver = dev_to_vme_driver(dev);
1494 bridge = dev_to_bridge(dev);
1495
Martyn Welchead1f3e2009-12-15 08:43:02 +00001496 if (driver->probe != NULL)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001497 retval = driver->probe(dev, bridge->num, vme_calc_slot(dev));
Martyn Welcha17a75e2009-07-31 09:28:17 +01001498
1499 return retval;
1500}
1501
1502static int vme_bus_remove(struct device *dev)
1503{
1504 struct vme_bridge *bridge;
1505 struct vme_driver *driver;
1506 int retval = -ENODEV;
1507
1508 driver = dev_to_vme_driver(dev);
1509 bridge = dev_to_bridge(dev);
1510
Martyn Welchead1f3e2009-12-15 08:43:02 +00001511 if (driver->remove != NULL)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001512 retval = driver->remove(dev, bridge->num, vme_calc_slot(dev));
Martyn Welcha17a75e2009-07-31 09:28:17 +01001513
1514 return retval;
1515}
1516
1517struct bus_type vme_bus_type = {
1518 .name = "vme",
1519 .match = vme_bus_match,
1520 .probe = vme_bus_probe,
1521 .remove = vme_bus_remove,
1522};
1523EXPORT_SYMBOL(vme_bus_type);
1524
Martyn Welchead1f3e2009-12-15 08:43:02 +00001525static int __init vme_init(void)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001526{
1527 return bus_register(&vme_bus_type);
1528}
1529
Martyn Welchead1f3e2009-12-15 08:43:02 +00001530static void __exit vme_exit(void)
Martyn Welcha17a75e2009-07-31 09:28:17 +01001531{
1532 bus_unregister(&vme_bus_type);
1533}
1534
1535MODULE_DESCRIPTION("VME bridge driver framework");
Martyn Welch66bd8db2010-02-18 15:12:52 +00001536MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
Martyn Welcha17a75e2009-07-31 09:28:17 +01001537MODULE_LICENSE("GPL");
1538
1539module_init(vme_init);
1540module_exit(vme_exit);