Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * VME Bridge Framework |
| 3 | * |
Martyn Welch | 66bd8db | 2010-02-18 15:12:52 +0000 | [diff] [blame] | 4 | * Author: Martyn Welch <martyn.welch@ge.com> |
| 5 | * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 6 | * |
| 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 | |
Paul Gortmaker | 050c3d5 | 2016-07-03 14:05:56 -0400 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/export.h> |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 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 Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 30 | #include <linux/mutex.h> |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 31 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Greg Kroah-Hartman | db3b9e9 | 2012-04-26 12:34:58 -0700 | [diff] [blame] | 33 | #include <linux/vme.h> |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 34 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 35 | #include "vme_bridge.h" |
| 36 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 37 | /* Bitmask and list of registered buses both protected by common mutex */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 38 | static unsigned int vme_bus_numbers; |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 39 | static LIST_HEAD(vme_bus_list); |
| 40 | static DEFINE_MUTEX(vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 41 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 42 | static int __init vme_init(void); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 43 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 44 | static struct vme_dev *dev_to_vme_dev(struct device *dev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 45 | { |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 46 | return container_of(dev, struct vme_dev, dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Find the bridge that the resource is associated with. |
| 51 | */ |
| 52 | static struct vme_bridge *find_bridge(struct vme_resource *resource) |
| 53 | { |
| 54 | /* Get list to search */ |
| 55 | switch (resource->type) { |
| 56 | case VME_MASTER: |
| 57 | return list_entry(resource->entry, struct vme_master_resource, |
| 58 | list)->parent; |
| 59 | break; |
| 60 | case VME_SLAVE: |
| 61 | return list_entry(resource->entry, struct vme_slave_resource, |
| 62 | list)->parent; |
| 63 | break; |
| 64 | case VME_DMA: |
| 65 | return list_entry(resource->entry, struct vme_dma_resource, |
| 66 | list)->parent; |
| 67 | break; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 68 | case VME_LM: |
| 69 | return list_entry(resource->entry, struct vme_lm_resource, |
| 70 | list)->parent; |
| 71 | break; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 72 | default: |
| 73 | printk(KERN_ERR "Unknown resource type\n"); |
| 74 | return NULL; |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Allocate a contiguous block of memory for use by the driver. This is used to |
| 81 | * create the buffers for the slave windows. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 82 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 83 | void *vme_alloc_consistent(struct vme_resource *resource, size_t size, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 84 | dma_addr_t *dma) |
| 85 | { |
| 86 | struct vme_bridge *bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 87 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 88 | if (resource == NULL) { |
| 89 | printk(KERN_ERR "No resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | bridge = find_bridge(resource); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 94 | if (bridge == NULL) { |
| 95 | printk(KERN_ERR "Can't find bridge\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 96 | return NULL; |
| 97 | } |
| 98 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 99 | if (bridge->parent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 100 | printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 101 | return NULL; |
| 102 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 103 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 104 | if (bridge->alloc_consistent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 105 | printk(KERN_ERR "alloc_consistent not supported by bridge %s\n", |
| 106 | bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | return bridge->alloc_consistent(bridge->parent, size, dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 111 | } |
| 112 | EXPORT_SYMBOL(vme_alloc_consistent); |
| 113 | |
| 114 | /* |
| 115 | * Free previously allocated contiguous block of memory. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 116 | */ |
| 117 | void vme_free_consistent(struct vme_resource *resource, size_t size, |
| 118 | void *vaddr, dma_addr_t dma) |
| 119 | { |
| 120 | struct vme_bridge *bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 121 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 122 | if (resource == NULL) { |
| 123 | printk(KERN_ERR "No resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
| 127 | bridge = find_bridge(resource); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 128 | if (bridge == NULL) { |
| 129 | printk(KERN_ERR "Can't find bridge\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 133 | if (bridge->parent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 134 | printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 135 | return; |
| 136 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 137 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 138 | if (bridge->free_consistent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 139 | printk(KERN_ERR "free_consistent not supported by bridge %s\n", |
| 140 | bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
| 144 | bridge->free_consistent(bridge->parent, size, vaddr, dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 145 | } |
| 146 | EXPORT_SYMBOL(vme_free_consistent); |
| 147 | |
| 148 | size_t vme_get_size(struct vme_resource *resource) |
| 149 | { |
| 150 | int enabled, retval; |
| 151 | unsigned long long base, size; |
| 152 | dma_addr_t buf_base; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 153 | u32 aspace, cycle, dwidth; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 154 | |
| 155 | switch (resource->type) { |
| 156 | case VME_MASTER: |
| 157 | retval = vme_master_get(resource, &enabled, &base, &size, |
| 158 | &aspace, &cycle, &dwidth); |
Martyn Welch | 6ad3756 | 2016-10-21 17:36:19 +0100 | [diff] [blame] | 159 | if (retval) |
| 160 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 161 | |
| 162 | return size; |
| 163 | break; |
| 164 | case VME_SLAVE: |
| 165 | retval = vme_slave_get(resource, &enabled, &base, &size, |
| 166 | &buf_base, &aspace, &cycle); |
Martyn Welch | 6ad3756 | 2016-10-21 17:36:19 +0100 | [diff] [blame] | 167 | if (retval) |
| 168 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 169 | |
| 170 | return size; |
| 171 | break; |
| 172 | case VME_DMA: |
| 173 | return 0; |
| 174 | break; |
| 175 | default: |
| 176 | printk(KERN_ERR "Unknown resource type\n"); |
| 177 | return 0; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | EXPORT_SYMBOL(vme_get_size); |
| 182 | |
Dmitry Kalinkin | ef73f88 | 2015-05-28 15:07:04 +0300 | [diff] [blame] | 183 | int vme_check_window(u32 aspace, unsigned long long vme_base, |
| 184 | unsigned long long size) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 185 | { |
| 186 | int retval = 0; |
| 187 | |
| 188 | switch (aspace) { |
| 189 | case VME_A16: |
| 190 | if (((vme_base + size) > VME_A16_MAX) || |
| 191 | (vme_base > VME_A16_MAX)) |
| 192 | retval = -EFAULT; |
| 193 | break; |
| 194 | case VME_A24: |
| 195 | if (((vme_base + size) > VME_A24_MAX) || |
| 196 | (vme_base > VME_A24_MAX)) |
| 197 | retval = -EFAULT; |
| 198 | break; |
| 199 | case VME_A32: |
| 200 | if (((vme_base + size) > VME_A32_MAX) || |
| 201 | (vme_base > VME_A32_MAX)) |
| 202 | retval = -EFAULT; |
| 203 | break; |
| 204 | case VME_A64: |
Dmitry Kalinkin | e7fd80c | 2015-05-28 15:07:03 +0300 | [diff] [blame] | 205 | if ((size != 0) && (vme_base > U64_MAX + 1 - size)) |
| 206 | retval = -EFAULT; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 207 | break; |
| 208 | case VME_CRCSR: |
| 209 | if (((vme_base + size) > VME_CRCSR_MAX) || |
| 210 | (vme_base > VME_CRCSR_MAX)) |
| 211 | retval = -EFAULT; |
| 212 | break; |
| 213 | case VME_USER1: |
| 214 | case VME_USER2: |
| 215 | case VME_USER3: |
| 216 | case VME_USER4: |
| 217 | /* User Defined */ |
| 218 | break; |
| 219 | default: |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 220 | printk(KERN_ERR "Invalid address space\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 221 | retval = -EINVAL; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | return retval; |
| 226 | } |
Dmitry Kalinkin | ef73f88 | 2015-05-28 15:07:04 +0300 | [diff] [blame] | 227 | EXPORT_SYMBOL(vme_check_window); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 228 | |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 229 | static u32 vme_get_aspace(int am) |
| 230 | { |
| 231 | switch (am) { |
| 232 | case 0x29: |
| 233 | case 0x2D: |
| 234 | return VME_A16; |
| 235 | case 0x38: |
| 236 | case 0x39: |
| 237 | case 0x3A: |
| 238 | case 0x3B: |
| 239 | case 0x3C: |
| 240 | case 0x3D: |
| 241 | case 0x3E: |
| 242 | case 0x3F: |
| 243 | return VME_A24; |
| 244 | case 0x8: |
| 245 | case 0x9: |
| 246 | case 0xA: |
| 247 | case 0xB: |
| 248 | case 0xC: |
| 249 | case 0xD: |
| 250 | case 0xE: |
| 251 | case 0xF: |
| 252 | return VME_A32; |
| 253 | case 0x0: |
| 254 | case 0x1: |
| 255 | case 0x3: |
| 256 | return VME_A64; |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 262 | /* |
| 263 | * Request a slave image with specific attributes, return some unique |
| 264 | * identifier. |
| 265 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 266 | struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, |
| 267 | u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 268 | { |
| 269 | struct vme_bridge *bridge; |
| 270 | struct list_head *slave_pos = NULL; |
| 271 | struct vme_slave_resource *allocated_image = NULL; |
| 272 | struct vme_slave_resource *slave_image = NULL; |
| 273 | struct vme_resource *resource = NULL; |
| 274 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 275 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 276 | if (bridge == NULL) { |
| 277 | printk(KERN_ERR "Can't find VME bus\n"); |
| 278 | goto err_bus; |
| 279 | } |
| 280 | |
| 281 | /* Loop through slave resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 282 | list_for_each(slave_pos, &bridge->slave_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 283 | slave_image = list_entry(slave_pos, |
| 284 | struct vme_slave_resource, list); |
| 285 | |
| 286 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 287 | printk(KERN_ERR "Registered NULL Slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 288 | continue; |
| 289 | } |
| 290 | |
| 291 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 292 | mutex_lock(&slave_image->mtx); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 293 | if (((slave_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 294 | ((slave_image->cycle_attr & cycle) == cycle) && |
| 295 | (slave_image->locked == 0)) { |
| 296 | |
| 297 | slave_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 298 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 299 | allocated_image = slave_image; |
| 300 | break; |
| 301 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 302 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* No free image */ |
| 306 | if (allocated_image == NULL) |
| 307 | goto err_image; |
| 308 | |
| 309 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 310 | if (resource == NULL) { |
| 311 | printk(KERN_WARNING "Unable to allocate resource structure\n"); |
| 312 | goto err_alloc; |
| 313 | } |
| 314 | resource->type = VME_SLAVE; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 315 | resource->entry = &allocated_image->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 316 | |
| 317 | return resource; |
| 318 | |
| 319 | err_alloc: |
| 320 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 321 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 322 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 323 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 324 | err_image: |
| 325 | err_bus: |
| 326 | return NULL; |
| 327 | } |
| 328 | EXPORT_SYMBOL(vme_slave_request); |
| 329 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 330 | int vme_slave_set(struct vme_resource *resource, int enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 331 | unsigned long long vme_base, unsigned long long size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 332 | dma_addr_t buf_base, u32 aspace, u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 333 | { |
| 334 | struct vme_bridge *bridge = find_bridge(resource); |
| 335 | struct vme_slave_resource *image; |
| 336 | int retval; |
| 337 | |
| 338 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 339 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 340 | return -EINVAL; |
| 341 | } |
| 342 | |
| 343 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 344 | |
| 345 | if (bridge->slave_set == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 346 | printk(KERN_ERR "Function not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 347 | return -ENOSYS; |
| 348 | } |
| 349 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 350 | if (!(((image->address_attr & aspace) == aspace) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 351 | ((image->cycle_attr & cycle) == cycle))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 352 | printk(KERN_ERR "Invalid attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | } |
| 355 | |
| 356 | retval = vme_check_window(aspace, vme_base, size); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 357 | if (retval) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 358 | return retval; |
| 359 | |
| 360 | return bridge->slave_set(image, enabled, vme_base, size, buf_base, |
| 361 | aspace, cycle); |
| 362 | } |
| 363 | EXPORT_SYMBOL(vme_slave_set); |
| 364 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 365 | int vme_slave_get(struct vme_resource *resource, int *enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 366 | unsigned long long *vme_base, unsigned long long *size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 367 | dma_addr_t *buf_base, u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 368 | { |
| 369 | struct vme_bridge *bridge = find_bridge(resource); |
| 370 | struct vme_slave_resource *image; |
| 371 | |
| 372 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 373 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 378 | |
Emilio G. Cota | 51a569f | 2009-08-10 16:52:42 +0200 | [diff] [blame] | 379 | if (bridge->slave_get == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 380 | printk(KERN_ERR "vme_slave_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 381 | return -EINVAL; |
| 382 | } |
| 383 | |
| 384 | return bridge->slave_get(image, enabled, vme_base, size, buf_base, |
| 385 | aspace, cycle); |
| 386 | } |
| 387 | EXPORT_SYMBOL(vme_slave_get); |
| 388 | |
| 389 | void vme_slave_free(struct vme_resource *resource) |
| 390 | { |
| 391 | struct vme_slave_resource *slave_image; |
| 392 | |
| 393 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 394 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 395 | return; |
| 396 | } |
| 397 | |
| 398 | slave_image = list_entry(resource->entry, struct vme_slave_resource, |
| 399 | list); |
| 400 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 401 | printk(KERN_ERR "Can't find slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
| 405 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 406 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 407 | if (slave_image->locked == 0) |
| 408 | printk(KERN_ERR "Image is already free\n"); |
| 409 | |
| 410 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 411 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 412 | |
| 413 | /* Free up resource memory */ |
| 414 | kfree(resource); |
| 415 | } |
| 416 | EXPORT_SYMBOL(vme_slave_free); |
| 417 | |
| 418 | /* |
| 419 | * Request a master image with specific attributes, return some unique |
| 420 | * identifier. |
| 421 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 422 | struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, |
| 423 | u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 424 | { |
| 425 | struct vme_bridge *bridge; |
| 426 | struct list_head *master_pos = NULL; |
| 427 | struct vme_master_resource *allocated_image = NULL; |
| 428 | struct vme_master_resource *master_image = NULL; |
| 429 | struct vme_resource *resource = NULL; |
| 430 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 431 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 432 | if (bridge == NULL) { |
| 433 | printk(KERN_ERR "Can't find VME bus\n"); |
| 434 | goto err_bus; |
| 435 | } |
| 436 | |
| 437 | /* Loop through master resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 438 | list_for_each(master_pos, &bridge->master_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 439 | master_image = list_entry(master_pos, |
| 440 | struct vme_master_resource, list); |
| 441 | |
| 442 | if (master_image == NULL) { |
| 443 | printk(KERN_WARNING "Registered NULL master resource\n"); |
| 444 | continue; |
| 445 | } |
| 446 | |
| 447 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 448 | spin_lock(&master_image->lock); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 449 | if (((master_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 450 | ((master_image->cycle_attr & cycle) == cycle) && |
| 451 | ((master_image->width_attr & dwidth) == dwidth) && |
| 452 | (master_image->locked == 0)) { |
| 453 | |
| 454 | master_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 455 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 456 | allocated_image = master_image; |
| 457 | break; |
| 458 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 459 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* Check to see if we found a resource */ |
| 463 | if (allocated_image == NULL) { |
| 464 | printk(KERN_ERR "Can't find a suitable resource\n"); |
| 465 | goto err_image; |
| 466 | } |
| 467 | |
| 468 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 469 | if (resource == NULL) { |
| 470 | printk(KERN_ERR "Unable to allocate resource structure\n"); |
| 471 | goto err_alloc; |
| 472 | } |
| 473 | resource->type = VME_MASTER; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 474 | resource->entry = &allocated_image->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 475 | |
| 476 | return resource; |
| 477 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 478 | err_alloc: |
| 479 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 480 | spin_lock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 481 | master_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 482 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 483 | err_image: |
| 484 | err_bus: |
| 485 | return NULL; |
| 486 | } |
| 487 | EXPORT_SYMBOL(vme_master_request); |
| 488 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 489 | int vme_master_set(struct vme_resource *resource, int enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 490 | unsigned long long vme_base, unsigned long long size, u32 aspace, |
| 491 | u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 492 | { |
| 493 | struct vme_bridge *bridge = find_bridge(resource); |
| 494 | struct vme_master_resource *image; |
| 495 | int retval; |
| 496 | |
| 497 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 498 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 499 | return -EINVAL; |
| 500 | } |
| 501 | |
| 502 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 503 | |
| 504 | if (bridge->master_set == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 505 | printk(KERN_WARNING "vme_master_set not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 506 | return -EINVAL; |
| 507 | } |
| 508 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 509 | if (!(((image->address_attr & aspace) == aspace) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 510 | ((image->cycle_attr & cycle) == cycle) && |
| 511 | ((image->width_attr & dwidth) == dwidth))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 512 | printk(KERN_WARNING "Invalid attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 513 | return -EINVAL; |
| 514 | } |
| 515 | |
| 516 | retval = vme_check_window(aspace, vme_base, size); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 517 | if (retval) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 518 | return retval; |
| 519 | |
| 520 | return bridge->master_set(image, enabled, vme_base, size, aspace, |
| 521 | cycle, dwidth); |
| 522 | } |
| 523 | EXPORT_SYMBOL(vme_master_set); |
| 524 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 525 | int vme_master_get(struct vme_resource *resource, int *enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 526 | unsigned long long *vme_base, unsigned long long *size, u32 *aspace, |
| 527 | u32 *cycle, u32 *dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 528 | { |
| 529 | struct vme_bridge *bridge = find_bridge(resource); |
| 530 | struct vme_master_resource *image; |
| 531 | |
| 532 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 533 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 534 | return -EINVAL; |
| 535 | } |
| 536 | |
| 537 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 538 | |
Emilio G. Cota | 51a569f | 2009-08-10 16:52:42 +0200 | [diff] [blame] | 539 | if (bridge->master_get == NULL) { |
Julia Lawall | c103830 | 2014-12-07 20:20:53 +0100 | [diff] [blame] | 540 | printk(KERN_WARNING "%s not supported\n", __func__); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 541 | return -EINVAL; |
| 542 | } |
| 543 | |
| 544 | return bridge->master_get(image, enabled, vme_base, size, aspace, |
| 545 | cycle, dwidth); |
| 546 | } |
| 547 | EXPORT_SYMBOL(vme_master_get); |
| 548 | |
| 549 | /* |
| 550 | * Read data out of VME space into a buffer. |
| 551 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 552 | ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 553 | loff_t offset) |
| 554 | { |
| 555 | struct vme_bridge *bridge = find_bridge(resource); |
| 556 | struct vme_master_resource *image; |
| 557 | size_t length; |
| 558 | |
| 559 | if (bridge->master_read == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 560 | printk(KERN_WARNING "Reading from resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 561 | return -EINVAL; |
| 562 | } |
| 563 | |
| 564 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 565 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 566 | return -EINVAL; |
| 567 | } |
| 568 | |
| 569 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 570 | |
| 571 | length = vme_get_size(resource); |
| 572 | |
| 573 | if (offset > length) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 574 | printk(KERN_WARNING "Invalid Offset\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 575 | return -EFAULT; |
| 576 | } |
| 577 | |
| 578 | if ((offset + count) > length) |
| 579 | count = length - offset; |
| 580 | |
| 581 | return bridge->master_read(image, buf, count, offset); |
| 582 | |
| 583 | } |
| 584 | EXPORT_SYMBOL(vme_master_read); |
| 585 | |
| 586 | /* |
| 587 | * Write data out to VME space from a buffer. |
| 588 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 589 | ssize_t vme_master_write(struct vme_resource *resource, void *buf, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 590 | size_t count, loff_t offset) |
| 591 | { |
| 592 | struct vme_bridge *bridge = find_bridge(resource); |
| 593 | struct vme_master_resource *image; |
| 594 | size_t length; |
| 595 | |
| 596 | if (bridge->master_write == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 597 | printk(KERN_WARNING "Writing to resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 598 | return -EINVAL; |
| 599 | } |
| 600 | |
| 601 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 602 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 603 | return -EINVAL; |
| 604 | } |
| 605 | |
| 606 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 607 | |
| 608 | length = vme_get_size(resource); |
| 609 | |
| 610 | if (offset > length) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 611 | printk(KERN_WARNING "Invalid Offset\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 612 | return -EFAULT; |
| 613 | } |
| 614 | |
| 615 | if ((offset + count) > length) |
| 616 | count = length - offset; |
| 617 | |
| 618 | return bridge->master_write(image, buf, count, offset); |
| 619 | } |
| 620 | EXPORT_SYMBOL(vme_master_write); |
| 621 | |
| 622 | /* |
| 623 | * Perform RMW cycle to provided location. |
| 624 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 625 | unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 626 | unsigned int compare, unsigned int swap, loff_t offset) |
| 627 | { |
| 628 | struct vme_bridge *bridge = find_bridge(resource); |
| 629 | struct vme_master_resource *image; |
| 630 | |
| 631 | if (bridge->master_rmw == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 632 | printk(KERN_WARNING "Writing to resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 633 | return -EINVAL; |
| 634 | } |
| 635 | |
| 636 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 637 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 638 | return -EINVAL; |
| 639 | } |
| 640 | |
| 641 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 642 | |
| 643 | return bridge->master_rmw(image, mask, compare, swap, offset); |
| 644 | } |
| 645 | EXPORT_SYMBOL(vme_master_rmw); |
| 646 | |
Dmitry Kalinkin | c74a804 | 2015-02-26 18:53:10 +0300 | [diff] [blame] | 647 | int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma) |
| 648 | { |
| 649 | struct vme_master_resource *image; |
| 650 | phys_addr_t phys_addr; |
| 651 | unsigned long vma_size; |
| 652 | |
| 653 | if (resource->type != VME_MASTER) { |
| 654 | pr_err("Not a master resource\n"); |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | |
| 658 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 659 | phys_addr = image->bus_resource.start + (vma->vm_pgoff << PAGE_SHIFT); |
| 660 | vma_size = vma->vm_end - vma->vm_start; |
| 661 | |
| 662 | if (phys_addr + vma_size > image->bus_resource.end + 1) { |
| 663 | pr_err("Map size cannot exceed the window size\n"); |
| 664 | return -EFAULT; |
| 665 | } |
| 666 | |
| 667 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 668 | |
| 669 | return vm_iomap_memory(vma, phys_addr, vma->vm_end - vma->vm_start); |
| 670 | } |
| 671 | EXPORT_SYMBOL(vme_master_mmap); |
| 672 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 673 | void vme_master_free(struct vme_resource *resource) |
| 674 | { |
| 675 | struct vme_master_resource *master_image; |
| 676 | |
| 677 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 678 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | master_image = list_entry(resource->entry, struct vme_master_resource, |
| 683 | list); |
| 684 | if (master_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 685 | printk(KERN_ERR "Can't find master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 686 | return; |
| 687 | } |
| 688 | |
| 689 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 690 | spin_lock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 691 | if (master_image->locked == 0) |
| 692 | printk(KERN_ERR "Image is already free\n"); |
| 693 | |
| 694 | master_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 695 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 696 | |
| 697 | /* Free up resource memory */ |
| 698 | kfree(resource); |
| 699 | } |
| 700 | EXPORT_SYMBOL(vme_master_free); |
| 701 | |
| 702 | /* |
| 703 | * Request a DMA controller with specific attributes, return some unique |
| 704 | * identifier. |
| 705 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 706 | struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 707 | { |
| 708 | struct vme_bridge *bridge; |
| 709 | struct list_head *dma_pos = NULL; |
| 710 | struct vme_dma_resource *allocated_ctrlr = NULL; |
| 711 | struct vme_dma_resource *dma_ctrlr = NULL; |
| 712 | struct vme_resource *resource = NULL; |
| 713 | |
| 714 | /* XXX Not checking resource attributes */ |
| 715 | printk(KERN_ERR "No VME resource Attribute tests done\n"); |
| 716 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 717 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 718 | if (bridge == NULL) { |
| 719 | printk(KERN_ERR "Can't find VME bus\n"); |
| 720 | goto err_bus; |
| 721 | } |
| 722 | |
| 723 | /* Loop through DMA resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 724 | list_for_each(dma_pos, &bridge->dma_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 725 | dma_ctrlr = list_entry(dma_pos, |
| 726 | struct vme_dma_resource, list); |
| 727 | |
| 728 | if (dma_ctrlr == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 729 | printk(KERN_ERR "Registered NULL DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 730 | continue; |
| 731 | } |
| 732 | |
Martyn Welch | 4f723df | 2010-02-18 15:12:58 +0000 | [diff] [blame] | 733 | /* Find an unlocked and compatible controller */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 734 | mutex_lock(&dma_ctrlr->mtx); |
Martyn Welch | 4f723df | 2010-02-18 15:12:58 +0000 | [diff] [blame] | 735 | if (((dma_ctrlr->route_attr & route) == route) && |
| 736 | (dma_ctrlr->locked == 0)) { |
| 737 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 738 | dma_ctrlr->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 739 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 740 | allocated_ctrlr = dma_ctrlr; |
| 741 | break; |
| 742 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 743 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* Check to see if we found a resource */ |
| 747 | if (allocated_ctrlr == NULL) |
| 748 | goto err_ctrlr; |
| 749 | |
| 750 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 751 | if (resource == NULL) { |
| 752 | printk(KERN_WARNING "Unable to allocate resource structure\n"); |
| 753 | goto err_alloc; |
| 754 | } |
| 755 | resource->type = VME_DMA; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 756 | resource->entry = &allocated_ctrlr->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 757 | |
| 758 | return resource; |
| 759 | |
| 760 | err_alloc: |
| 761 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 762 | mutex_lock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 763 | dma_ctrlr->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 764 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 765 | err_ctrlr: |
| 766 | err_bus: |
| 767 | return NULL; |
| 768 | } |
Martyn Welch | 58e5079 | 2009-10-29 16:35:20 +0000 | [diff] [blame] | 769 | EXPORT_SYMBOL(vme_dma_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 770 | |
| 771 | /* |
| 772 | * Start new list |
| 773 | */ |
| 774 | struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) |
| 775 | { |
| 776 | struct vme_dma_resource *ctrlr; |
| 777 | struct vme_dma_list *dma_list; |
| 778 | |
| 779 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 780 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 781 | return NULL; |
| 782 | } |
| 783 | |
| 784 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 785 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 786 | dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL); |
| 787 | if (dma_list == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 788 | printk(KERN_ERR "Unable to allocate memory for new DMA list\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 789 | return NULL; |
| 790 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 791 | INIT_LIST_HEAD(&dma_list->entries); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 792 | dma_list->parent = ctrlr; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 793 | mutex_init(&dma_list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 794 | |
| 795 | return dma_list; |
| 796 | } |
| 797 | EXPORT_SYMBOL(vme_new_dma_list); |
| 798 | |
| 799 | /* |
| 800 | * Create "Pattern" type attributes |
| 801 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 802 | struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 803 | { |
| 804 | struct vme_dma_attr *attributes; |
| 805 | struct vme_dma_pattern *pattern_attr; |
| 806 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 807 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
| 808 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 809 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 810 | goto err_attr; |
| 811 | } |
| 812 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 813 | pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); |
| 814 | if (pattern_attr == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 815 | printk(KERN_ERR "Unable to allocate memory for pattern attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 816 | goto err_pat; |
| 817 | } |
| 818 | |
| 819 | attributes->type = VME_DMA_PATTERN; |
| 820 | attributes->private = (void *)pattern_attr; |
| 821 | |
| 822 | pattern_attr->pattern = pattern; |
| 823 | pattern_attr->type = type; |
| 824 | |
| 825 | return attributes; |
| 826 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 827 | err_pat: |
| 828 | kfree(attributes); |
| 829 | err_attr: |
| 830 | return NULL; |
| 831 | } |
| 832 | EXPORT_SYMBOL(vme_dma_pattern_attribute); |
| 833 | |
| 834 | /* |
| 835 | * Create "PCI" type attributes |
| 836 | */ |
| 837 | struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) |
| 838 | { |
| 839 | struct vme_dma_attr *attributes; |
| 840 | struct vme_dma_pci *pci_attr; |
| 841 | |
| 842 | /* XXX Run some sanity checks here */ |
| 843 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 844 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
| 845 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 846 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 847 | goto err_attr; |
| 848 | } |
| 849 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 850 | pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); |
| 851 | if (pci_attr == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 852 | printk(KERN_ERR "Unable to allocate memory for PCI attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 853 | goto err_pci; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | |
| 858 | attributes->type = VME_DMA_PCI; |
| 859 | attributes->private = (void *)pci_attr; |
| 860 | |
| 861 | pci_attr->address = address; |
| 862 | |
| 863 | return attributes; |
| 864 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 865 | err_pci: |
| 866 | kfree(attributes); |
| 867 | err_attr: |
| 868 | return NULL; |
| 869 | } |
| 870 | EXPORT_SYMBOL(vme_dma_pci_attribute); |
| 871 | |
| 872 | /* |
| 873 | * Create "VME" type attributes |
| 874 | */ |
| 875 | struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 876 | u32 aspace, u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 877 | { |
| 878 | struct vme_dma_attr *attributes; |
| 879 | struct vme_dma_vme *vme_attr; |
| 880 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 881 | attributes = kmalloc( |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 882 | sizeof(struct vme_dma_attr), GFP_KERNEL); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 883 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 884 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 885 | goto err_attr; |
| 886 | } |
| 887 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 888 | vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); |
| 889 | if (vme_attr == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 890 | printk(KERN_ERR "Unable to allocate memory for VME attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 891 | goto err_vme; |
| 892 | } |
| 893 | |
| 894 | attributes->type = VME_DMA_VME; |
| 895 | attributes->private = (void *)vme_attr; |
| 896 | |
| 897 | vme_attr->address = address; |
| 898 | vme_attr->aspace = aspace; |
| 899 | vme_attr->cycle = cycle; |
| 900 | vme_attr->dwidth = dwidth; |
| 901 | |
| 902 | return attributes; |
| 903 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 904 | err_vme: |
| 905 | kfree(attributes); |
| 906 | err_attr: |
| 907 | return NULL; |
| 908 | } |
| 909 | EXPORT_SYMBOL(vme_dma_vme_attribute); |
| 910 | |
| 911 | /* |
| 912 | * Free attribute |
| 913 | */ |
| 914 | void vme_dma_free_attribute(struct vme_dma_attr *attributes) |
| 915 | { |
| 916 | kfree(attributes->private); |
| 917 | kfree(attributes); |
| 918 | } |
| 919 | EXPORT_SYMBOL(vme_dma_free_attribute); |
| 920 | |
| 921 | int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, |
| 922 | struct vme_dma_attr *dest, size_t count) |
| 923 | { |
| 924 | struct vme_bridge *bridge = list->parent->parent; |
| 925 | int retval; |
| 926 | |
| 927 | if (bridge->dma_list_add == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 928 | printk(KERN_WARNING "Link List DMA generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 929 | return -EINVAL; |
| 930 | } |
| 931 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 932 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 933 | printk(KERN_ERR "Link List already submitted\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 934 | return -EINVAL; |
| 935 | } |
| 936 | |
| 937 | retval = bridge->dma_list_add(list, src, dest, count); |
| 938 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 939 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 940 | |
| 941 | return retval; |
| 942 | } |
| 943 | EXPORT_SYMBOL(vme_dma_list_add); |
| 944 | |
| 945 | int vme_dma_list_exec(struct vme_dma_list *list) |
| 946 | { |
| 947 | struct vme_bridge *bridge = list->parent->parent; |
| 948 | int retval; |
| 949 | |
| 950 | if (bridge->dma_list_exec == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 951 | printk(KERN_ERR "Link List DMA execution not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 952 | return -EINVAL; |
| 953 | } |
| 954 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 955 | mutex_lock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 956 | |
| 957 | retval = bridge->dma_list_exec(list); |
| 958 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 959 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 960 | |
| 961 | return retval; |
| 962 | } |
| 963 | EXPORT_SYMBOL(vme_dma_list_exec); |
| 964 | |
| 965 | int vme_dma_list_free(struct vme_dma_list *list) |
| 966 | { |
| 967 | struct vme_bridge *bridge = list->parent->parent; |
| 968 | int retval; |
| 969 | |
| 970 | if (bridge->dma_list_empty == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 971 | printk(KERN_WARNING "Emptying of Link Lists not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 972 | return -EINVAL; |
| 973 | } |
| 974 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 975 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 976 | printk(KERN_ERR "Link List in use\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 977 | return -EINVAL; |
| 978 | } |
| 979 | |
| 980 | /* |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 981 | * Empty out all of the entries from the DMA list. We need to go to the |
| 982 | * low level driver as DMA entries are driver specific. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 983 | */ |
| 984 | retval = bridge->dma_list_empty(list); |
| 985 | if (retval) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 986 | printk(KERN_ERR "Unable to empty link-list entries\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 987 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 988 | return retval; |
| 989 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 990 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 991 | kfree(list); |
| 992 | |
| 993 | return retval; |
| 994 | } |
| 995 | EXPORT_SYMBOL(vme_dma_list_free); |
| 996 | |
| 997 | int vme_dma_free(struct vme_resource *resource) |
| 998 | { |
| 999 | struct vme_dma_resource *ctrlr; |
| 1000 | |
| 1001 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1002 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
| 1006 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 1007 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1008 | if (!mutex_trylock(&ctrlr->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1009 | printk(KERN_ERR "Resource busy, can't free\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1010 | return -EBUSY; |
| 1011 | } |
| 1012 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1013 | if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1014 | printk(KERN_WARNING "Resource still processing transfers\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1015 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1016 | return -EBUSY; |
| 1017 | } |
| 1018 | |
| 1019 | ctrlr->locked = 0; |
| 1020 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1021 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1022 | |
Martyn Welch | fd5c256 | 2013-06-06 12:29:16 +0100 | [diff] [blame] | 1023 | kfree(resource); |
| 1024 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1025 | return 0; |
| 1026 | } |
| 1027 | EXPORT_SYMBOL(vme_dma_free); |
| 1028 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1029 | void vme_bus_error_handler(struct vme_bridge *bridge, |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 1030 | unsigned long long address, int am) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1031 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1032 | struct list_head *handler_pos = NULL; |
| 1033 | struct vme_error_handler *handler; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1034 | int handler_triggered = 0; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1035 | u32 aspace = vme_get_aspace(am); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1036 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1037 | list_for_each(handler_pos, &bridge->vme_error_handlers) { |
| 1038 | handler = list_entry(handler_pos, struct vme_error_handler, |
| 1039 | list); |
| 1040 | if ((aspace == handler->aspace) && |
| 1041 | (address >= handler->start) && |
| 1042 | (address < handler->end)) { |
| 1043 | if (!handler->num_errors) |
| 1044 | handler->first_error = address; |
| 1045 | if (handler->num_errors != UINT_MAX) |
| 1046 | handler->num_errors++; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1047 | handler_triggered = 1; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1048 | } |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1049 | } |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1050 | |
| 1051 | if (!handler_triggered) |
| 1052 | dev_err(bridge->parent, |
| 1053 | "Unhandled VME access error at address 0x%llx\n", |
| 1054 | address); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1055 | } |
| 1056 | EXPORT_SYMBOL(vme_bus_error_handler); |
| 1057 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1058 | struct vme_error_handler *vme_register_error_handler( |
| 1059 | struct vme_bridge *bridge, u32 aspace, |
| 1060 | unsigned long long address, size_t len) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1061 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1062 | struct vme_error_handler *handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1063 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1064 | handler = kmalloc(sizeof(*handler), GFP_KERNEL); |
| 1065 | if (!handler) |
| 1066 | return NULL; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1067 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1068 | handler->aspace = aspace; |
| 1069 | handler->start = address; |
| 1070 | handler->end = address + len; |
| 1071 | handler->num_errors = 0; |
| 1072 | handler->first_error = 0; |
| 1073 | list_add_tail(&handler->list, &bridge->vme_error_handlers); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1074 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1075 | return handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1076 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1077 | EXPORT_SYMBOL(vme_register_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1078 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1079 | void vme_unregister_error_handler(struct vme_error_handler *handler) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1080 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1081 | list_del(&handler->list); |
| 1082 | kfree(handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1083 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1084 | EXPORT_SYMBOL(vme_unregister_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1085 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1086 | void vme_irq_handler(struct vme_bridge *bridge, int level, int statid) |
| 1087 | { |
| 1088 | void (*call)(int, int, void *); |
| 1089 | void *priv_data; |
| 1090 | |
| 1091 | call = bridge->irq[level - 1].callback[statid].func; |
| 1092 | priv_data = bridge->irq[level - 1].callback[statid].priv_data; |
| 1093 | |
| 1094 | if (call != NULL) |
| 1095 | call(level, statid, priv_data); |
| 1096 | else |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1097 | printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n", |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1098 | level, statid); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1099 | } |
| 1100 | EXPORT_SYMBOL(vme_irq_handler); |
| 1101 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1102 | int vme_irq_request(struct vme_dev *vdev, int level, int statid, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1103 | void (*callback)(int, int, void *), |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1104 | void *priv_data) |
| 1105 | { |
| 1106 | struct vme_bridge *bridge; |
| 1107 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1108 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1109 | if (bridge == NULL) { |
| 1110 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1111 | return -EINVAL; |
| 1112 | } |
| 1113 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1114 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1115 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1119 | if (bridge->irq_set == NULL) { |
| 1120 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1124 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1125 | |
| 1126 | if (bridge->irq[level - 1].callback[statid].func) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1127 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1128 | printk(KERN_WARNING "VME Interrupt already taken\n"); |
| 1129 | return -EBUSY; |
| 1130 | } |
| 1131 | |
| 1132 | bridge->irq[level - 1].count++; |
| 1133 | bridge->irq[level - 1].callback[statid].priv_data = priv_data; |
| 1134 | bridge->irq[level - 1].callback[statid].func = callback; |
| 1135 | |
| 1136 | /* Enable IRQ level */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1137 | bridge->irq_set(bridge, level, 1, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1138 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1139 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1140 | |
| 1141 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1142 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1143 | EXPORT_SYMBOL(vme_irq_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1144 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1145 | void vme_irq_free(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1146 | { |
| 1147 | struct vme_bridge *bridge; |
| 1148 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1149 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1150 | if (bridge == NULL) { |
| 1151 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1152 | return; |
| 1153 | } |
| 1154 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1155 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1156 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1157 | return; |
| 1158 | } |
| 1159 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1160 | if (bridge->irq_set == NULL) { |
| 1161 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1162 | return; |
| 1163 | } |
| 1164 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1165 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1166 | |
| 1167 | bridge->irq[level - 1].count--; |
| 1168 | |
| 1169 | /* Disable IRQ level if no more interrupts attached at this level*/ |
| 1170 | if (bridge->irq[level - 1].count == 0) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1171 | bridge->irq_set(bridge, level, 0, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1172 | |
| 1173 | bridge->irq[level - 1].callback[statid].func = NULL; |
| 1174 | bridge->irq[level - 1].callback[statid].priv_data = NULL; |
| 1175 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1176 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1177 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1178 | EXPORT_SYMBOL(vme_irq_free); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1179 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1180 | int vme_irq_generate(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1181 | { |
| 1182 | struct vme_bridge *bridge; |
| 1183 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1184 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1185 | if (bridge == NULL) { |
| 1186 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1187 | return -EINVAL; |
| 1188 | } |
| 1189 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1190 | if ((level < 1) || (level > 7)) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1191 | printk(KERN_WARNING "Invalid interrupt level\n"); |
| 1192 | return -EINVAL; |
| 1193 | } |
| 1194 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1195 | if (bridge->irq_generate == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1196 | printk(KERN_WARNING "Interrupt generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1197 | return -EINVAL; |
| 1198 | } |
| 1199 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1200 | return bridge->irq_generate(bridge, level, statid); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1201 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1202 | EXPORT_SYMBOL(vme_irq_generate); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1203 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1204 | /* |
| 1205 | * Request the location monitor, return resource or NULL |
| 1206 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1207 | struct vme_resource *vme_lm_request(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1208 | { |
| 1209 | struct vme_bridge *bridge; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1210 | struct list_head *lm_pos = NULL; |
| 1211 | struct vme_lm_resource *allocated_lm = NULL; |
| 1212 | struct vme_lm_resource *lm = NULL; |
| 1213 | struct vme_resource *resource = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1214 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1215 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1216 | if (bridge == NULL) { |
| 1217 | printk(KERN_ERR "Can't find VME bus\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1218 | goto err_bus; |
| 1219 | } |
| 1220 | |
| 1221 | /* Loop through DMA resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1222 | list_for_each(lm_pos, &bridge->lm_resources) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1223 | lm = list_entry(lm_pos, |
| 1224 | struct vme_lm_resource, list); |
| 1225 | |
| 1226 | if (lm == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1227 | printk(KERN_ERR "Registered NULL Location Monitor resource\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1228 | continue; |
| 1229 | } |
| 1230 | |
| 1231 | /* Find an unlocked controller */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1232 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1233 | if (lm->locked == 0) { |
| 1234 | lm->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1235 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1236 | allocated_lm = lm; |
| 1237 | break; |
| 1238 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1239 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | /* Check to see if we found a resource */ |
| 1243 | if (allocated_lm == NULL) |
| 1244 | goto err_lm; |
| 1245 | |
| 1246 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 1247 | if (resource == NULL) { |
| 1248 | printk(KERN_ERR "Unable to allocate resource structure\n"); |
| 1249 | goto err_alloc; |
| 1250 | } |
| 1251 | resource->type = VME_LM; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1252 | resource->entry = &allocated_lm->list; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1253 | |
| 1254 | return resource; |
| 1255 | |
| 1256 | err_alloc: |
| 1257 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1258 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1259 | lm->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1260 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1261 | err_lm: |
| 1262 | err_bus: |
| 1263 | return NULL; |
| 1264 | } |
| 1265 | EXPORT_SYMBOL(vme_lm_request); |
| 1266 | |
| 1267 | int vme_lm_count(struct vme_resource *resource) |
| 1268 | { |
| 1269 | struct vme_lm_resource *lm; |
| 1270 | |
| 1271 | if (resource->type != VME_LM) { |
| 1272 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1273 | return -EINVAL; |
| 1274 | } |
| 1275 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1276 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1277 | |
| 1278 | return lm->monitors; |
| 1279 | } |
| 1280 | EXPORT_SYMBOL(vme_lm_count); |
| 1281 | |
| 1282 | int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1283 | u32 aspace, u32 cycle) |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1284 | { |
| 1285 | struct vme_bridge *bridge = find_bridge(resource); |
| 1286 | struct vme_lm_resource *lm; |
| 1287 | |
| 1288 | if (resource->type != VME_LM) { |
| 1289 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1290 | return -EINVAL; |
| 1291 | } |
| 1292 | |
| 1293 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1294 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1295 | if (bridge->lm_set == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1296 | printk(KERN_ERR "vme_lm_set not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1297 | return -EINVAL; |
| 1298 | } |
| 1299 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1300 | return bridge->lm_set(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1301 | } |
| 1302 | EXPORT_SYMBOL(vme_lm_set); |
| 1303 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1304 | int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1305 | u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1306 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1307 | struct vme_bridge *bridge = find_bridge(resource); |
| 1308 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1309 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1310 | if (resource->type != VME_LM) { |
| 1311 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1315 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1316 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1317 | if (bridge->lm_get == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1318 | printk(KERN_ERR "vme_lm_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1319 | return -EINVAL; |
| 1320 | } |
| 1321 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1322 | return bridge->lm_get(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1323 | } |
| 1324 | EXPORT_SYMBOL(vme_lm_get); |
| 1325 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1326 | int vme_lm_attach(struct vme_resource *resource, int monitor, |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1327 | void (*callback)(void *), void *data) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1328 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1329 | struct vme_bridge *bridge = find_bridge(resource); |
| 1330 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1331 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1332 | if (resource->type != VME_LM) { |
| 1333 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1334 | return -EINVAL; |
| 1335 | } |
| 1336 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1337 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1338 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1339 | if (bridge->lm_attach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1340 | printk(KERN_ERR "vme_lm_attach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1341 | return -EINVAL; |
| 1342 | } |
| 1343 | |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1344 | return bridge->lm_attach(lm, monitor, callback, data); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1345 | } |
| 1346 | EXPORT_SYMBOL(vme_lm_attach); |
| 1347 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1348 | int vme_lm_detach(struct vme_resource *resource, int monitor) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1349 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1350 | struct vme_bridge *bridge = find_bridge(resource); |
| 1351 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1352 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1353 | if (resource->type != VME_LM) { |
| 1354 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1355 | return -EINVAL; |
| 1356 | } |
| 1357 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1358 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1359 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1360 | if (bridge->lm_detach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1361 | printk(KERN_ERR "vme_lm_detach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1362 | return -EINVAL; |
| 1363 | } |
| 1364 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1365 | return bridge->lm_detach(lm, monitor); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1366 | } |
| 1367 | EXPORT_SYMBOL(vme_lm_detach); |
| 1368 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1369 | void vme_lm_free(struct vme_resource *resource) |
| 1370 | { |
| 1371 | struct vme_lm_resource *lm; |
| 1372 | |
| 1373 | if (resource->type != VME_LM) { |
| 1374 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1379 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1380 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1381 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1382 | /* XXX |
| 1383 | * Check to see that there aren't any callbacks still attached, if |
| 1384 | * there are we should probably be detaching them! |
| 1385 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1386 | |
| 1387 | lm->locked = 0; |
| 1388 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1389 | mutex_unlock(&lm->mtx); |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1390 | |
| 1391 | kfree(resource); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1392 | } |
| 1393 | EXPORT_SYMBOL(vme_lm_free); |
| 1394 | |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1395 | int vme_slot_num(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1396 | { |
| 1397 | struct vme_bridge *bridge; |
| 1398 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1399 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1400 | if (bridge == NULL) { |
| 1401 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1402 | return -EINVAL; |
| 1403 | } |
| 1404 | |
| 1405 | if (bridge->slot_get == NULL) { |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1406 | printk(KERN_WARNING "vme_slot_num not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1407 | return -EINVAL; |
| 1408 | } |
| 1409 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1410 | return bridge->slot_get(bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1411 | } |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1412 | EXPORT_SYMBOL(vme_slot_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1413 | |
Martyn Welch | 978f47d | 2013-11-08 11:58:34 +0000 | [diff] [blame] | 1414 | int vme_bus_num(struct vme_dev *vdev) |
| 1415 | { |
| 1416 | struct vme_bridge *bridge; |
| 1417 | |
| 1418 | bridge = vdev->bridge; |
| 1419 | if (bridge == NULL) { |
| 1420 | pr_err("Can't find VME bus\n"); |
| 1421 | return -EINVAL; |
| 1422 | } |
| 1423 | |
| 1424 | return bridge->num; |
| 1425 | } |
| 1426 | EXPORT_SYMBOL(vme_bus_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1427 | |
| 1428 | /* - Bridge Registration --------------------------------------------------- */ |
| 1429 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1430 | static void vme_dev_release(struct device *dev) |
| 1431 | { |
| 1432 | kfree(dev_to_vme_dev(dev)); |
| 1433 | } |
| 1434 | |
Aaron Sierra | 326071b | 2016-04-24 15:11:38 -0500 | [diff] [blame] | 1435 | /* Common bridge initialization */ |
| 1436 | struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge) |
| 1437 | { |
| 1438 | INIT_LIST_HEAD(&bridge->vme_error_handlers); |
| 1439 | INIT_LIST_HEAD(&bridge->master_resources); |
| 1440 | INIT_LIST_HEAD(&bridge->slave_resources); |
| 1441 | INIT_LIST_HEAD(&bridge->dma_resources); |
| 1442 | INIT_LIST_HEAD(&bridge->lm_resources); |
| 1443 | mutex_init(&bridge->irq_mtx); |
| 1444 | |
| 1445 | return bridge; |
| 1446 | } |
| 1447 | EXPORT_SYMBOL(vme_init_bridge); |
| 1448 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1449 | int vme_register_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1450 | { |
| 1451 | int i; |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1452 | int ret = -1; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1453 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1454 | mutex_lock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1455 | for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) { |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1456 | if ((vme_bus_numbers & (1 << i)) == 0) { |
| 1457 | vme_bus_numbers |= (1 << i); |
| 1458 | bridge->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1459 | INIT_LIST_HEAD(&bridge->devices); |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1460 | list_add_tail(&bridge->bus_list, &vme_bus_list); |
| 1461 | ret = 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1465 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1466 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1467 | return ret; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1468 | } |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1469 | EXPORT_SYMBOL(vme_register_bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1470 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1471 | void vme_unregister_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1472 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1473 | struct vme_dev *vdev; |
| 1474 | struct vme_dev *tmp; |
| 1475 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1476 | mutex_lock(&vme_buses_lock); |
| 1477 | vme_bus_numbers &= ~(1 << bridge->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1478 | list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) { |
| 1479 | list_del(&vdev->drv_list); |
| 1480 | list_del(&vdev->bridge_list); |
| 1481 | device_unregister(&vdev->dev); |
| 1482 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1483 | list_del(&bridge->bus_list); |
| 1484 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1485 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1486 | EXPORT_SYMBOL(vme_unregister_bridge); |
| 1487 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1488 | /* - Driver Registration --------------------------------------------------- */ |
| 1489 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1490 | static int __vme_register_driver_bus(struct vme_driver *drv, |
| 1491 | struct vme_bridge *bridge, unsigned int ndevs) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1492 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1493 | int err; |
| 1494 | unsigned int i; |
| 1495 | struct vme_dev *vdev; |
| 1496 | struct vme_dev *tmp; |
| 1497 | |
| 1498 | for (i = 0; i < ndevs; i++) { |
| 1499 | vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL); |
| 1500 | if (!vdev) { |
| 1501 | err = -ENOMEM; |
| 1502 | goto err_devalloc; |
| 1503 | } |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1504 | vdev->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1505 | vdev->bridge = bridge; |
| 1506 | vdev->dev.platform_data = drv; |
| 1507 | vdev->dev.release = vme_dev_release; |
| 1508 | vdev->dev.parent = bridge->parent; |
| 1509 | vdev->dev.bus = &vme_bus_type; |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1510 | dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num, |
| 1511 | vdev->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1512 | |
| 1513 | err = device_register(&vdev->dev); |
| 1514 | if (err) |
| 1515 | goto err_reg; |
| 1516 | |
| 1517 | if (vdev->dev.platform_data) { |
| 1518 | list_add_tail(&vdev->drv_list, &drv->devices); |
| 1519 | list_add_tail(&vdev->bridge_list, &bridge->devices); |
| 1520 | } else |
| 1521 | device_unregister(&vdev->dev); |
| 1522 | } |
| 1523 | return 0; |
| 1524 | |
| 1525 | err_reg: |
Emilio G. Cota | def1820 | 2013-02-13 13:47:54 -0500 | [diff] [blame] | 1526 | put_device(&vdev->dev); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1527 | kfree(vdev); |
| 1528 | err_devalloc: |
| 1529 | list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) { |
| 1530 | list_del(&vdev->drv_list); |
| 1531 | list_del(&vdev->bridge_list); |
| 1532 | device_unregister(&vdev->dev); |
| 1533 | } |
| 1534 | return err; |
| 1535 | } |
| 1536 | |
| 1537 | static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1538 | { |
| 1539 | struct vme_bridge *bridge; |
| 1540 | int err = 0; |
| 1541 | |
| 1542 | mutex_lock(&vme_buses_lock); |
| 1543 | list_for_each_entry(bridge, &vme_bus_list, bus_list) { |
| 1544 | /* |
| 1545 | * This cannot cause trouble as we already have vme_buses_lock |
| 1546 | * and if the bridge is removed, it will have to go through |
| 1547 | * vme_unregister_bridge() to do it (which calls remove() on |
| 1548 | * the bridge which in turn tries to acquire vme_buses_lock and |
Manohar Vanga | c26f611 | 2011-11-04 11:12:29 +0100 | [diff] [blame] | 1549 | * will have to wait). |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1550 | */ |
| 1551 | err = __vme_register_driver_bus(drv, bridge, ndevs); |
| 1552 | if (err) |
| 1553 | break; |
| 1554 | } |
| 1555 | mutex_unlock(&vme_buses_lock); |
| 1556 | return err; |
| 1557 | } |
| 1558 | |
| 1559 | int vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1560 | { |
| 1561 | int err; |
| 1562 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1563 | drv->driver.name = drv->name; |
| 1564 | drv->driver.bus = &vme_bus_type; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1565 | INIT_LIST_HEAD(&drv->devices); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1566 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1567 | err = driver_register(&drv->driver); |
| 1568 | if (err) |
| 1569 | return err; |
| 1570 | |
| 1571 | err = __vme_register_driver(drv, ndevs); |
| 1572 | if (err) |
| 1573 | driver_unregister(&drv->driver); |
| 1574 | |
| 1575 | return err; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1576 | } |
| 1577 | EXPORT_SYMBOL(vme_register_driver); |
| 1578 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1579 | void vme_unregister_driver(struct vme_driver *drv) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1580 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1581 | struct vme_dev *dev, *dev_tmp; |
| 1582 | |
| 1583 | mutex_lock(&vme_buses_lock); |
| 1584 | list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) { |
| 1585 | list_del(&dev->drv_list); |
| 1586 | list_del(&dev->bridge_list); |
| 1587 | device_unregister(&dev->dev); |
| 1588 | } |
| 1589 | mutex_unlock(&vme_buses_lock); |
| 1590 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1591 | driver_unregister(&drv->driver); |
| 1592 | } |
| 1593 | EXPORT_SYMBOL(vme_unregister_driver); |
| 1594 | |
| 1595 | /* - Bus Registration ------------------------------------------------------ */ |
| 1596 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1597 | static int vme_bus_match(struct device *dev, struct device_driver *drv) |
| 1598 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1599 | struct vme_driver *vme_drv; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1600 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1601 | vme_drv = container_of(drv, struct vme_driver, driver); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1602 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1603 | if (dev->platform_data == vme_drv) { |
| 1604 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1605 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1606 | if (vme_drv->match && vme_drv->match(vdev)) |
| 1607 | return 1; |
| 1608 | |
| 1609 | dev->platform_data = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1610 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | static int vme_bus_probe(struct device *dev) |
| 1615 | { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1616 | int retval = -ENODEV; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1617 | struct vme_driver *driver; |
| 1618 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1619 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1620 | driver = dev->platform_data; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1621 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1622 | if (driver->probe != NULL) |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1623 | retval = driver->probe(vdev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1624 | |
| 1625 | return retval; |
| 1626 | } |
| 1627 | |
Stefano Babic | 5af94e6 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 1628 | static int vme_bus_remove(struct device *dev) |
| 1629 | { |
| 1630 | int retval = -ENODEV; |
| 1631 | struct vme_driver *driver; |
| 1632 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
| 1633 | |
| 1634 | driver = dev->platform_data; |
| 1635 | |
| 1636 | if (driver->remove != NULL) |
| 1637 | retval = driver->remove(vdev); |
| 1638 | |
| 1639 | return retval; |
| 1640 | } |
| 1641 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1642 | struct bus_type vme_bus_type = { |
| 1643 | .name = "vme", |
| 1644 | .match = vme_bus_match, |
| 1645 | .probe = vme_bus_probe, |
Stefano Babic | 5af94e6 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 1646 | .remove = vme_bus_remove, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1647 | }; |
| 1648 | EXPORT_SYMBOL(vme_bus_type); |
| 1649 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1650 | static int __init vme_init(void) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1651 | { |
| 1652 | return bus_register(&vme_bus_type); |
| 1653 | } |
Aaron Sierra | c326cc0 | 2013-12-09 09:54:42 -0600 | [diff] [blame] | 1654 | subsys_initcall(vme_init); |