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 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 79 | /** |
| 80 | * vme_free_consistent - Allocate contiguous memory. |
| 81 | * @resource: Pointer to VME resource. |
| 82 | * @size: Size of allocation required. |
| 83 | * @dma: Pointer to variable to store physical address of allocation. |
| 84 | * |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 85 | * Allocate a contiguous block of memory for use by the driver. This is used to |
| 86 | * create the buffers for the slave windows. |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 87 | * |
| 88 | * Return: Virtual address of allocation on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 89 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 90 | void *vme_alloc_consistent(struct vme_resource *resource, size_t size, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 91 | dma_addr_t *dma) |
| 92 | { |
| 93 | struct vme_bridge *bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 94 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 95 | if (resource == NULL) { |
| 96 | printk(KERN_ERR "No resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | bridge = find_bridge(resource); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 101 | if (bridge == NULL) { |
| 102 | printk(KERN_ERR "Can't find bridge\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 103 | return NULL; |
| 104 | } |
| 105 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 106 | if (bridge->parent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 107 | printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 108 | return NULL; |
| 109 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 110 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 111 | if (bridge->alloc_consistent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 112 | printk(KERN_ERR "alloc_consistent not supported by bridge %s\n", |
| 113 | bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | return bridge->alloc_consistent(bridge->parent, size, dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 118 | } |
| 119 | EXPORT_SYMBOL(vme_alloc_consistent); |
| 120 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 121 | /** |
| 122 | * vme_free_consistent - Free previously allocated memory. |
| 123 | * @resource: Pointer to VME resource. |
| 124 | * @size: Size of allocation to free. |
| 125 | * @vaddr: Virtual address of allocation. |
| 126 | * @dma: Physical address of allocation. |
| 127 | * |
| 128 | * Free previously allocated block of contiguous memory. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 129 | */ |
| 130 | void vme_free_consistent(struct vme_resource *resource, size_t size, |
| 131 | void *vaddr, dma_addr_t dma) |
| 132 | { |
| 133 | struct vme_bridge *bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 134 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 135 | if (resource == NULL) { |
| 136 | printk(KERN_ERR "No resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
| 140 | bridge = find_bridge(resource); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 141 | if (bridge == NULL) { |
| 142 | printk(KERN_ERR "Can't find bridge\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 146 | if (bridge->parent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 147 | printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 148 | return; |
| 149 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 150 | |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 151 | if (bridge->free_consistent == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 152 | printk(KERN_ERR "free_consistent not supported by bridge %s\n", |
| 153 | bridge->name); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 154 | return; |
| 155 | } |
| 156 | |
| 157 | bridge->free_consistent(bridge->parent, size, vaddr, dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 158 | } |
| 159 | EXPORT_SYMBOL(vme_free_consistent); |
| 160 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 161 | /** |
| 162 | * vme_get_size - Helper function returning size of a VME window |
| 163 | * @resource: Pointer to VME slave or master resource. |
| 164 | * |
| 165 | * Determine the size of the VME window provided. This is a helper |
| 166 | * function, wrappering the call to vme_master_get or vme_slave_get |
| 167 | * depending on the type of window resource handed to it. |
| 168 | * |
| 169 | * Return: Size of the window on success, zero on failure. |
| 170 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 171 | size_t vme_get_size(struct vme_resource *resource) |
| 172 | { |
| 173 | int enabled, retval; |
| 174 | unsigned long long base, size; |
| 175 | dma_addr_t buf_base; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 176 | u32 aspace, cycle, dwidth; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 177 | |
| 178 | switch (resource->type) { |
| 179 | case VME_MASTER: |
| 180 | retval = vme_master_get(resource, &enabled, &base, &size, |
| 181 | &aspace, &cycle, &dwidth); |
Martyn Welch | 6ad3756 | 2016-10-21 17:36:19 +0100 | [diff] [blame] | 182 | if (retval) |
| 183 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 184 | |
| 185 | return size; |
| 186 | break; |
| 187 | case VME_SLAVE: |
| 188 | retval = vme_slave_get(resource, &enabled, &base, &size, |
| 189 | &buf_base, &aspace, &cycle); |
Martyn Welch | 6ad3756 | 2016-10-21 17:36:19 +0100 | [diff] [blame] | 190 | if (retval) |
| 191 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 192 | |
| 193 | return size; |
| 194 | break; |
| 195 | case VME_DMA: |
| 196 | return 0; |
| 197 | break; |
| 198 | default: |
| 199 | printk(KERN_ERR "Unknown resource type\n"); |
| 200 | return 0; |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | EXPORT_SYMBOL(vme_get_size); |
| 205 | |
Dmitry Kalinkin | ef73f88 | 2015-05-28 15:07:04 +0300 | [diff] [blame] | 206 | int vme_check_window(u32 aspace, unsigned long long vme_base, |
| 207 | unsigned long long size) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 208 | { |
| 209 | int retval = 0; |
| 210 | |
| 211 | switch (aspace) { |
| 212 | case VME_A16: |
| 213 | if (((vme_base + size) > VME_A16_MAX) || |
| 214 | (vme_base > VME_A16_MAX)) |
| 215 | retval = -EFAULT; |
| 216 | break; |
| 217 | case VME_A24: |
| 218 | if (((vme_base + size) > VME_A24_MAX) || |
| 219 | (vme_base > VME_A24_MAX)) |
| 220 | retval = -EFAULT; |
| 221 | break; |
| 222 | case VME_A32: |
| 223 | if (((vme_base + size) > VME_A32_MAX) || |
| 224 | (vme_base > VME_A32_MAX)) |
| 225 | retval = -EFAULT; |
| 226 | break; |
| 227 | case VME_A64: |
Dmitry Kalinkin | e7fd80c | 2015-05-28 15:07:03 +0300 | [diff] [blame] | 228 | if ((size != 0) && (vme_base > U64_MAX + 1 - size)) |
| 229 | retval = -EFAULT; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 230 | break; |
| 231 | case VME_CRCSR: |
| 232 | if (((vme_base + size) > VME_CRCSR_MAX) || |
| 233 | (vme_base > VME_CRCSR_MAX)) |
| 234 | retval = -EFAULT; |
| 235 | break; |
| 236 | case VME_USER1: |
| 237 | case VME_USER2: |
| 238 | case VME_USER3: |
| 239 | case VME_USER4: |
| 240 | /* User Defined */ |
| 241 | break; |
| 242 | default: |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 243 | printk(KERN_ERR "Invalid address space\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 244 | retval = -EINVAL; |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | return retval; |
| 249 | } |
Dmitry Kalinkin | ef73f88 | 2015-05-28 15:07:04 +0300 | [diff] [blame] | 250 | EXPORT_SYMBOL(vme_check_window); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 251 | |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 252 | static u32 vme_get_aspace(int am) |
| 253 | { |
| 254 | switch (am) { |
| 255 | case 0x29: |
| 256 | case 0x2D: |
| 257 | return VME_A16; |
| 258 | case 0x38: |
| 259 | case 0x39: |
| 260 | case 0x3A: |
| 261 | case 0x3B: |
| 262 | case 0x3C: |
| 263 | case 0x3D: |
| 264 | case 0x3E: |
| 265 | case 0x3F: |
| 266 | return VME_A24; |
| 267 | case 0x8: |
| 268 | case 0x9: |
| 269 | case 0xA: |
| 270 | case 0xB: |
| 271 | case 0xC: |
| 272 | case 0xD: |
| 273 | case 0xE: |
| 274 | case 0xF: |
| 275 | return VME_A32; |
| 276 | case 0x0: |
| 277 | case 0x1: |
| 278 | case 0x3: |
| 279 | return VME_A64; |
| 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 285 | /** |
| 286 | * vme_slave_request - Request a VME slave window resource. |
| 287 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 288 | * @address: Required VME address space. |
| 289 | * @cycle: Required VME data transfer cycle type. |
| 290 | * |
| 291 | * Request use of a VME window resource capable of being set for the requested |
| 292 | * address space and data transfer cycle. |
| 293 | * |
| 294 | * Return: Pointer to VME resource on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 295 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 296 | struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, |
| 297 | u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 298 | { |
| 299 | struct vme_bridge *bridge; |
| 300 | struct list_head *slave_pos = NULL; |
| 301 | struct vme_slave_resource *allocated_image = NULL; |
| 302 | struct vme_slave_resource *slave_image = NULL; |
| 303 | struct vme_resource *resource = NULL; |
| 304 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 305 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 306 | if (bridge == NULL) { |
| 307 | printk(KERN_ERR "Can't find VME bus\n"); |
| 308 | goto err_bus; |
| 309 | } |
| 310 | |
| 311 | /* Loop through slave resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 312 | list_for_each(slave_pos, &bridge->slave_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 313 | slave_image = list_entry(slave_pos, |
| 314 | struct vme_slave_resource, list); |
| 315 | |
| 316 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 317 | printk(KERN_ERR "Registered NULL Slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 318 | continue; |
| 319 | } |
| 320 | |
| 321 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 322 | mutex_lock(&slave_image->mtx); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 323 | if (((slave_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 324 | ((slave_image->cycle_attr & cycle) == cycle) && |
| 325 | (slave_image->locked == 0)) { |
| 326 | |
| 327 | slave_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 328 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 329 | allocated_image = slave_image; |
| 330 | break; |
| 331 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 332 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* No free image */ |
| 336 | if (allocated_image == NULL) |
| 337 | goto err_image; |
| 338 | |
| 339 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 340 | if (!resource) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 341 | goto err_alloc; |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 342 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 343 | resource->type = VME_SLAVE; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 344 | resource->entry = &allocated_image->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 345 | |
| 346 | return resource; |
| 347 | |
| 348 | err_alloc: |
| 349 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 350 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 351 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 352 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 353 | err_image: |
| 354 | err_bus: |
| 355 | return NULL; |
| 356 | } |
| 357 | EXPORT_SYMBOL(vme_slave_request); |
| 358 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 359 | /** |
| 360 | * vme_slave_set - Set VME slave window configuration. |
| 361 | * @resource: Pointer to VME slave resource. |
| 362 | * @enabled: State to which the window should be configured. |
| 363 | * @vme_base: Base address for the window. |
| 364 | * @size: Size of the VME window. |
| 365 | * @buf_base: Based address of buffer used to provide VME slave window storage. |
| 366 | * @aspace: VME address space for the VME window. |
| 367 | * @cycle: VME data transfer cycle type for the VME window. |
| 368 | * |
| 369 | * Set configuration for provided VME slave window. |
| 370 | * |
| 371 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 372 | * device, if an invalid resource has been provided or invalid |
| 373 | * attributes are provided. Hardware specific errors may also be |
| 374 | * returned. |
| 375 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 376 | int vme_slave_set(struct vme_resource *resource, int enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 377 | unsigned long long vme_base, unsigned long long size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 378 | dma_addr_t buf_base, u32 aspace, u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 379 | { |
| 380 | struct vme_bridge *bridge = find_bridge(resource); |
| 381 | struct vme_slave_resource *image; |
| 382 | int retval; |
| 383 | |
| 384 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 385 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 386 | return -EINVAL; |
| 387 | } |
| 388 | |
| 389 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 390 | |
| 391 | if (bridge->slave_set == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 392 | printk(KERN_ERR "Function not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 393 | return -ENOSYS; |
| 394 | } |
| 395 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 396 | if (!(((image->address_attr & aspace) == aspace) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 397 | ((image->cycle_attr & cycle) == cycle))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 398 | printk(KERN_ERR "Invalid attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 399 | return -EINVAL; |
| 400 | } |
| 401 | |
| 402 | retval = vme_check_window(aspace, vme_base, size); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 403 | if (retval) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 404 | return retval; |
| 405 | |
| 406 | return bridge->slave_set(image, enabled, vme_base, size, buf_base, |
| 407 | aspace, cycle); |
| 408 | } |
| 409 | EXPORT_SYMBOL(vme_slave_set); |
| 410 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 411 | /** |
| 412 | * vme_slave_get - Retrieve VME slave window configuration. |
| 413 | * @resource: Pointer to VME slave resource. |
| 414 | * @enabled: Pointer to variable for storing state. |
| 415 | * @vme_base: Pointer to variable for storing window base address. |
| 416 | * @size: Pointer to variable for storing window size. |
| 417 | * @buf_base: Pointer to variable for storing slave buffer base address. |
| 418 | * @aspace: Pointer to variable for storing VME address space. |
| 419 | * @cycle: Pointer to variable for storing VME data transfer cycle type. |
| 420 | * |
| 421 | * Return configuration for provided VME slave window. |
| 422 | * |
| 423 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 424 | * device or if an invalid resource has been provided. |
| 425 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 426 | int vme_slave_get(struct vme_resource *resource, int *enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 427 | unsigned long long *vme_base, unsigned long long *size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 428 | dma_addr_t *buf_base, u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 429 | { |
| 430 | struct vme_bridge *bridge = find_bridge(resource); |
| 431 | struct vme_slave_resource *image; |
| 432 | |
| 433 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 434 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 439 | |
Emilio G. Cota | 51a569f | 2009-08-10 16:52:42 +0200 | [diff] [blame] | 440 | if (bridge->slave_get == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 441 | printk(KERN_ERR "vme_slave_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 442 | return -EINVAL; |
| 443 | } |
| 444 | |
| 445 | return bridge->slave_get(image, enabled, vme_base, size, buf_base, |
| 446 | aspace, cycle); |
| 447 | } |
| 448 | EXPORT_SYMBOL(vme_slave_get); |
| 449 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 450 | /** |
| 451 | * vme_slave_free - Free VME slave window |
| 452 | * @resource: Pointer to VME slave resource. |
| 453 | * |
| 454 | * Free the provided slave resource so that it may be reallocated. |
| 455 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 456 | void vme_slave_free(struct vme_resource *resource) |
| 457 | { |
| 458 | struct vme_slave_resource *slave_image; |
| 459 | |
| 460 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 461 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | |
| 465 | slave_image = list_entry(resource->entry, struct vme_slave_resource, |
| 466 | list); |
| 467 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 468 | printk(KERN_ERR "Can't find slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 469 | return; |
| 470 | } |
| 471 | |
| 472 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 473 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 474 | if (slave_image->locked == 0) |
| 475 | printk(KERN_ERR "Image is already free\n"); |
| 476 | |
| 477 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 478 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 479 | |
| 480 | /* Free up resource memory */ |
| 481 | kfree(resource); |
| 482 | } |
| 483 | EXPORT_SYMBOL(vme_slave_free); |
| 484 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 485 | /** |
| 486 | * vme_master_request - Request a VME master window resource. |
| 487 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 488 | * @address: Required VME address space. |
| 489 | * @cycle: Required VME data transfer cycle type. |
| 490 | * @dwidth: Required VME data transfer width. |
| 491 | * |
| 492 | * Request use of a VME window resource capable of being set for the requested |
| 493 | * address space, data transfer cycle and width. |
| 494 | * |
| 495 | * Return: Pointer to VME resource on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 496 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 497 | struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, |
| 498 | u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 499 | { |
| 500 | struct vme_bridge *bridge; |
| 501 | struct list_head *master_pos = NULL; |
| 502 | struct vme_master_resource *allocated_image = NULL; |
| 503 | struct vme_master_resource *master_image = NULL; |
| 504 | struct vme_resource *resource = NULL; |
| 505 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 506 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 507 | if (bridge == NULL) { |
| 508 | printk(KERN_ERR "Can't find VME bus\n"); |
| 509 | goto err_bus; |
| 510 | } |
| 511 | |
| 512 | /* Loop through master resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 513 | list_for_each(master_pos, &bridge->master_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 514 | master_image = list_entry(master_pos, |
| 515 | struct vme_master_resource, list); |
| 516 | |
| 517 | if (master_image == NULL) { |
| 518 | printk(KERN_WARNING "Registered NULL master resource\n"); |
| 519 | continue; |
| 520 | } |
| 521 | |
| 522 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 523 | spin_lock(&master_image->lock); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 524 | if (((master_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 525 | ((master_image->cycle_attr & cycle) == cycle) && |
| 526 | ((master_image->width_attr & dwidth) == dwidth) && |
| 527 | (master_image->locked == 0)) { |
| 528 | |
| 529 | master_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 530 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 531 | allocated_image = master_image; |
| 532 | break; |
| 533 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 534 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* Check to see if we found a resource */ |
| 538 | if (allocated_image == NULL) { |
| 539 | printk(KERN_ERR "Can't find a suitable resource\n"); |
| 540 | goto err_image; |
| 541 | } |
| 542 | |
| 543 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 544 | if (!resource) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 545 | goto err_alloc; |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 546 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 547 | resource->type = VME_MASTER; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 548 | resource->entry = &allocated_image->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 549 | |
| 550 | return resource; |
| 551 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 552 | err_alloc: |
| 553 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 554 | spin_lock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 555 | master_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 556 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 557 | err_image: |
| 558 | err_bus: |
| 559 | return NULL; |
| 560 | } |
| 561 | EXPORT_SYMBOL(vme_master_request); |
| 562 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 563 | /** |
| 564 | * vme_master_set - Set VME master window configuration. |
| 565 | * @resource: Pointer to VME master resource. |
| 566 | * @enabled: State to which the window should be configured. |
| 567 | * @vme_base: Base address for the window. |
| 568 | * @size: Size of the VME window. |
| 569 | * @aspace: VME address space for the VME window. |
| 570 | * @cycle: VME data transfer cycle type for the VME window. |
| 571 | * @dwidth: VME data transfer width for the VME window. |
| 572 | * |
| 573 | * Set configuration for provided VME master window. |
| 574 | * |
| 575 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 576 | * device, if an invalid resource has been provided or invalid |
| 577 | * attributes are provided. Hardware specific errors may also be |
| 578 | * returned. |
| 579 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 580 | int vme_master_set(struct vme_resource *resource, int enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 581 | unsigned long long vme_base, unsigned long long size, u32 aspace, |
| 582 | u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 583 | { |
| 584 | struct vme_bridge *bridge = find_bridge(resource); |
| 585 | struct vme_master_resource *image; |
| 586 | int retval; |
| 587 | |
| 588 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 589 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 590 | return -EINVAL; |
| 591 | } |
| 592 | |
| 593 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 594 | |
| 595 | if (bridge->master_set == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 596 | printk(KERN_WARNING "vme_master_set not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 597 | return -EINVAL; |
| 598 | } |
| 599 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 600 | if (!(((image->address_attr & aspace) == aspace) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 601 | ((image->cycle_attr & cycle) == cycle) && |
| 602 | ((image->width_attr & dwidth) == dwidth))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 603 | printk(KERN_WARNING "Invalid attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
| 606 | |
| 607 | retval = vme_check_window(aspace, vme_base, size); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 608 | if (retval) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 609 | return retval; |
| 610 | |
| 611 | return bridge->master_set(image, enabled, vme_base, size, aspace, |
| 612 | cycle, dwidth); |
| 613 | } |
| 614 | EXPORT_SYMBOL(vme_master_set); |
| 615 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 616 | /** |
| 617 | * vme_master_get - Retrieve VME master window configuration. |
| 618 | * @resource: Pointer to VME master resource. |
| 619 | * @enabled: Pointer to variable for storing state. |
| 620 | * @vme_base: Pointer to variable for storing window base address. |
| 621 | * @size: Pointer to variable for storing window size. |
| 622 | * @aspace: Pointer to variable for storing VME address space. |
| 623 | * @cycle: Pointer to variable for storing VME data transfer cycle type. |
| 624 | * @dwidth: Pointer to variable for storing VME data transfer width. |
| 625 | * |
| 626 | * Return configuration for provided VME master window. |
| 627 | * |
| 628 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 629 | * device or if an invalid resource has been provided. |
| 630 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 631 | int vme_master_get(struct vme_resource *resource, int *enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 632 | unsigned long long *vme_base, unsigned long long *size, u32 *aspace, |
| 633 | u32 *cycle, u32 *dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 634 | { |
| 635 | struct vme_bridge *bridge = find_bridge(resource); |
| 636 | struct vme_master_resource *image; |
| 637 | |
| 638 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 639 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 640 | return -EINVAL; |
| 641 | } |
| 642 | |
| 643 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 644 | |
Emilio G. Cota | 51a569f | 2009-08-10 16:52:42 +0200 | [diff] [blame] | 645 | if (bridge->master_get == NULL) { |
Julia Lawall | c103830 | 2014-12-07 20:20:53 +0100 | [diff] [blame] | 646 | printk(KERN_WARNING "%s not supported\n", __func__); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 647 | return -EINVAL; |
| 648 | } |
| 649 | |
| 650 | return bridge->master_get(image, enabled, vme_base, size, aspace, |
| 651 | cycle, dwidth); |
| 652 | } |
| 653 | EXPORT_SYMBOL(vme_master_get); |
| 654 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 655 | /** |
| 656 | * vme_master_write - Read data from VME space into a buffer. |
| 657 | * @resource: Pointer to VME master resource. |
| 658 | * @buf: Pointer to buffer where data should be transferred. |
| 659 | * @count: Number of bytes to transfer. |
| 660 | * @offset: Offset into VME master window at which to start transfer. |
| 661 | * |
| 662 | * Perform read of count bytes of data from location on VME bus which maps into |
| 663 | * the VME master window at offset to buf. |
| 664 | * |
| 665 | * Return: Number of bytes read, -EINVAL if resource is not a VME master |
| 666 | * resource or read operation is not supported. -EFAULT returned if |
| 667 | * invalid offset is provided. Hardware specific errors may also be |
| 668 | * returned. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 669 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 670 | 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] | 671 | loff_t offset) |
| 672 | { |
| 673 | struct vme_bridge *bridge = find_bridge(resource); |
| 674 | struct vme_master_resource *image; |
| 675 | size_t length; |
| 676 | |
| 677 | if (bridge->master_read == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 678 | printk(KERN_WARNING "Reading from resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | } |
| 681 | |
| 682 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 683 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 684 | return -EINVAL; |
| 685 | } |
| 686 | |
| 687 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 688 | |
| 689 | length = vme_get_size(resource); |
| 690 | |
| 691 | if (offset > length) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 692 | printk(KERN_WARNING "Invalid Offset\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 693 | return -EFAULT; |
| 694 | } |
| 695 | |
| 696 | if ((offset + count) > length) |
| 697 | count = length - offset; |
| 698 | |
| 699 | return bridge->master_read(image, buf, count, offset); |
| 700 | |
| 701 | } |
| 702 | EXPORT_SYMBOL(vme_master_read); |
| 703 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 704 | /** |
| 705 | * vme_master_write - Write data out to VME space from a buffer. |
| 706 | * @resource: Pointer to VME master resource. |
| 707 | * @buf: Pointer to buffer holding data to transfer. |
| 708 | * @count: Number of bytes to transfer. |
| 709 | * @offset: Offset into VME master window at which to start transfer. |
| 710 | * |
| 711 | * Perform write of count bytes of data from buf to location on VME bus which |
| 712 | * maps into the VME master window at offset. |
| 713 | * |
| 714 | * Return: Number of bytes written, -EINVAL if resource is not a VME master |
| 715 | * resource or write operation is not supported. -EFAULT returned if |
| 716 | * invalid offset is provided. Hardware specific errors may also be |
| 717 | * returned. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 718 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 719 | ssize_t vme_master_write(struct vme_resource *resource, void *buf, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 720 | size_t count, loff_t offset) |
| 721 | { |
| 722 | struct vme_bridge *bridge = find_bridge(resource); |
| 723 | struct vme_master_resource *image; |
| 724 | size_t length; |
| 725 | |
| 726 | if (bridge->master_write == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 727 | printk(KERN_WARNING "Writing to resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 728 | return -EINVAL; |
| 729 | } |
| 730 | |
| 731 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 732 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 733 | return -EINVAL; |
| 734 | } |
| 735 | |
| 736 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 737 | |
| 738 | length = vme_get_size(resource); |
| 739 | |
| 740 | if (offset > length) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 741 | printk(KERN_WARNING "Invalid Offset\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 742 | return -EFAULT; |
| 743 | } |
| 744 | |
| 745 | if ((offset + count) > length) |
| 746 | count = length - offset; |
| 747 | |
| 748 | return bridge->master_write(image, buf, count, offset); |
| 749 | } |
| 750 | EXPORT_SYMBOL(vme_master_write); |
| 751 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 752 | /** |
| 753 | * vme_master_rmw - Perform read-modify-write cycle. |
| 754 | * @resource: Pointer to VME master resource. |
| 755 | * @mask: Bits to be compared and swapped in operation. |
| 756 | * @compare: Bits to be compared with data read from offset. |
| 757 | * @swap: Bits to be swapped in data read from offset. |
| 758 | * @offset: Offset into VME master window at which to perform operation. |
| 759 | * |
| 760 | * Perform read-modify-write cycle on provided location: |
| 761 | * - Location on VME bus is read. |
| 762 | * - Bits selected by mask are compared with compare. |
| 763 | * - Where a selected bit matches that in compare and are selected in swap, |
| 764 | * the bit is swapped. |
| 765 | * - Result written back to location on VME bus. |
| 766 | * |
| 767 | * Return: Bytes written on success, -EINVAL if resource is not a VME master |
| 768 | * resource or RMW operation is not supported. Hardware specific |
| 769 | * errors may also be returned. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 770 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 771 | unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 772 | unsigned int compare, unsigned int swap, loff_t offset) |
| 773 | { |
| 774 | struct vme_bridge *bridge = find_bridge(resource); |
| 775 | struct vme_master_resource *image; |
| 776 | |
| 777 | if (bridge->master_rmw == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 778 | printk(KERN_WARNING "Writing to resource not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 779 | return -EINVAL; |
| 780 | } |
| 781 | |
| 782 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 783 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 784 | return -EINVAL; |
| 785 | } |
| 786 | |
| 787 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 788 | |
| 789 | return bridge->master_rmw(image, mask, compare, swap, offset); |
| 790 | } |
| 791 | EXPORT_SYMBOL(vme_master_rmw); |
| 792 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 793 | /** |
| 794 | * vme_master_mmap - Mmap region of VME master window. |
| 795 | * @resource: Pointer to VME master resource. |
| 796 | * @vma: Pointer to definition of user mapping. |
| 797 | * |
| 798 | * Memory map a region of the VME master window into user space. |
| 799 | * |
| 800 | * Return: Zero on success, -EINVAL if resource is not a VME master |
| 801 | * resource or -EFAULT if map exceeds window size. Other generic mmap |
| 802 | * errors may also be returned. |
| 803 | */ |
Dmitry Kalinkin | c74a804 | 2015-02-26 18:53:10 +0300 | [diff] [blame] | 804 | int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma) |
| 805 | { |
| 806 | struct vme_master_resource *image; |
| 807 | phys_addr_t phys_addr; |
| 808 | unsigned long vma_size; |
| 809 | |
| 810 | if (resource->type != VME_MASTER) { |
| 811 | pr_err("Not a master resource\n"); |
| 812 | return -EINVAL; |
| 813 | } |
| 814 | |
| 815 | image = list_entry(resource->entry, struct vme_master_resource, list); |
| 816 | phys_addr = image->bus_resource.start + (vma->vm_pgoff << PAGE_SHIFT); |
| 817 | vma_size = vma->vm_end - vma->vm_start; |
| 818 | |
| 819 | if (phys_addr + vma_size > image->bus_resource.end + 1) { |
| 820 | pr_err("Map size cannot exceed the window size\n"); |
| 821 | return -EFAULT; |
| 822 | } |
| 823 | |
| 824 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 825 | |
| 826 | return vm_iomap_memory(vma, phys_addr, vma->vm_end - vma->vm_start); |
| 827 | } |
| 828 | EXPORT_SYMBOL(vme_master_mmap); |
| 829 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 830 | /** |
| 831 | * vme_master_free - Free VME master window |
| 832 | * @resource: Pointer to VME master resource. |
| 833 | * |
| 834 | * Free the provided master resource so that it may be reallocated. |
| 835 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 836 | void vme_master_free(struct vme_resource *resource) |
| 837 | { |
| 838 | struct vme_master_resource *master_image; |
| 839 | |
| 840 | if (resource->type != VME_MASTER) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 841 | printk(KERN_ERR "Not a master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 842 | return; |
| 843 | } |
| 844 | |
| 845 | master_image = list_entry(resource->entry, struct vme_master_resource, |
| 846 | list); |
| 847 | if (master_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 848 | printk(KERN_ERR "Can't find master resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | |
| 852 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 853 | spin_lock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 854 | if (master_image->locked == 0) |
| 855 | printk(KERN_ERR "Image is already free\n"); |
| 856 | |
| 857 | master_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 858 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 859 | |
| 860 | /* Free up resource memory */ |
| 861 | kfree(resource); |
| 862 | } |
| 863 | EXPORT_SYMBOL(vme_master_free); |
| 864 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 865 | /** |
| 866 | * vme_dma_request - Request a DMA controller. |
| 867 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 868 | * @route: Required src/destination combination. |
| 869 | * |
| 870 | * Request a VME DMA controller with capability to perform transfers bewteen |
| 871 | * requested source/destination combination. |
| 872 | * |
| 873 | * Return: Pointer to VME DMA resource on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 874 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 875 | struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 876 | { |
| 877 | struct vme_bridge *bridge; |
| 878 | struct list_head *dma_pos = NULL; |
| 879 | struct vme_dma_resource *allocated_ctrlr = NULL; |
| 880 | struct vme_dma_resource *dma_ctrlr = NULL; |
| 881 | struct vme_resource *resource = NULL; |
| 882 | |
| 883 | /* XXX Not checking resource attributes */ |
| 884 | printk(KERN_ERR "No VME resource Attribute tests done\n"); |
| 885 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 886 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 887 | if (bridge == NULL) { |
| 888 | printk(KERN_ERR "Can't find VME bus\n"); |
| 889 | goto err_bus; |
| 890 | } |
| 891 | |
| 892 | /* Loop through DMA resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 893 | list_for_each(dma_pos, &bridge->dma_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 894 | dma_ctrlr = list_entry(dma_pos, |
| 895 | struct vme_dma_resource, list); |
| 896 | |
| 897 | if (dma_ctrlr == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 898 | printk(KERN_ERR "Registered NULL DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 899 | continue; |
| 900 | } |
| 901 | |
Martyn Welch | 4f723df | 2010-02-18 15:12:58 +0000 | [diff] [blame] | 902 | /* Find an unlocked and compatible controller */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 903 | mutex_lock(&dma_ctrlr->mtx); |
Martyn Welch | 4f723df | 2010-02-18 15:12:58 +0000 | [diff] [blame] | 904 | if (((dma_ctrlr->route_attr & route) == route) && |
| 905 | (dma_ctrlr->locked == 0)) { |
| 906 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 907 | dma_ctrlr->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 908 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 909 | allocated_ctrlr = dma_ctrlr; |
| 910 | break; |
| 911 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 912 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* Check to see if we found a resource */ |
| 916 | if (allocated_ctrlr == NULL) |
| 917 | goto err_ctrlr; |
| 918 | |
| 919 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 920 | if (!resource) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 921 | goto err_alloc; |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 922 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 923 | resource->type = VME_DMA; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 924 | resource->entry = &allocated_ctrlr->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 925 | |
| 926 | return resource; |
| 927 | |
| 928 | err_alloc: |
| 929 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 930 | mutex_lock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 931 | dma_ctrlr->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 932 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 933 | err_ctrlr: |
| 934 | err_bus: |
| 935 | return NULL; |
| 936 | } |
Martyn Welch | 58e5079 | 2009-10-29 16:35:20 +0000 | [diff] [blame] | 937 | EXPORT_SYMBOL(vme_dma_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 938 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 939 | /** |
| 940 | * vme_new_dma_list - Create new VME DMA list. |
| 941 | * @resource: Pointer to VME DMA resource. |
| 942 | * |
| 943 | * Create a new VME DMA list. It is the responsibility of the user to free |
| 944 | * the list once it is no longer required with vme_dma_list_free(). |
| 945 | * |
| 946 | * Return: Pointer to new VME DMA list, NULL on allocation failure or invalid |
| 947 | * VME DMA resource. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 948 | */ |
| 949 | struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) |
| 950 | { |
| 951 | struct vme_dma_resource *ctrlr; |
| 952 | struct vme_dma_list *dma_list; |
| 953 | |
| 954 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 955 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 956 | return NULL; |
| 957 | } |
| 958 | |
| 959 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 960 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 961 | dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 962 | if (!dma_list) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 963 | return NULL; |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 964 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 965 | INIT_LIST_HEAD(&dma_list->entries); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 966 | dma_list->parent = ctrlr; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 967 | mutex_init(&dma_list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 968 | |
| 969 | return dma_list; |
| 970 | } |
| 971 | EXPORT_SYMBOL(vme_new_dma_list); |
| 972 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 973 | /** |
| 974 | * vme_dma_pattern_attribute - Create "Pattern" type VME DMA list attribute. |
| 975 | * @pattern: Value to use used as pattern |
| 976 | * @type: Type of pattern to be written. |
| 977 | * |
| 978 | * Create VME DMA list attribute for pattern generation. It is the |
| 979 | * responsibility of the user to free used attributes using |
| 980 | * vme_dma_free_attribute(). |
| 981 | * |
| 982 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 983 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 984 | struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 985 | { |
| 986 | struct vme_dma_attr *attributes; |
| 987 | struct vme_dma_pattern *pattern_attr; |
| 988 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 989 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 990 | if (!attributes) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 991 | goto err_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 992 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 993 | pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 994 | if (!pattern_attr) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 995 | goto err_pat; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 996 | |
| 997 | attributes->type = VME_DMA_PATTERN; |
| 998 | attributes->private = (void *)pattern_attr; |
| 999 | |
| 1000 | pattern_attr->pattern = pattern; |
| 1001 | pattern_attr->type = type; |
| 1002 | |
| 1003 | return attributes; |
| 1004 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1005 | err_pat: |
| 1006 | kfree(attributes); |
| 1007 | err_attr: |
| 1008 | return NULL; |
| 1009 | } |
| 1010 | EXPORT_SYMBOL(vme_dma_pattern_attribute); |
| 1011 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1012 | /** |
| 1013 | * vme_dma_pci_attribute - Create "PCI" type VME DMA list attribute. |
| 1014 | * @address: PCI base address for DMA transfer. |
| 1015 | * |
| 1016 | * Create VME DMA list attribute pointing to a location on PCI for DMA |
| 1017 | * transfers. It is the responsibility of the user to free used attributes |
| 1018 | * using vme_dma_free_attribute(). |
| 1019 | * |
| 1020 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1021 | */ |
| 1022 | struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) |
| 1023 | { |
| 1024 | struct vme_dma_attr *attributes; |
| 1025 | struct vme_dma_pci *pci_attr; |
| 1026 | |
| 1027 | /* XXX Run some sanity checks here */ |
| 1028 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1029 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1030 | if (!attributes) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1031 | goto err_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1032 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1033 | pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1034 | if (!pci_attr) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1035 | goto err_pci; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1036 | |
| 1037 | attributes->type = VME_DMA_PCI; |
| 1038 | attributes->private = (void *)pci_attr; |
| 1039 | |
| 1040 | pci_attr->address = address; |
| 1041 | |
| 1042 | return attributes; |
| 1043 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1044 | err_pci: |
| 1045 | kfree(attributes); |
| 1046 | err_attr: |
| 1047 | return NULL; |
| 1048 | } |
| 1049 | EXPORT_SYMBOL(vme_dma_pci_attribute); |
| 1050 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1051 | /** |
| 1052 | * vme_dma_vme_attribute - Create "VME" type VME DMA list attribute. |
| 1053 | * @address: VME base address for DMA transfer. |
| 1054 | * @aspace: VME address space to use for DMA transfer. |
| 1055 | * @cycle: VME bus cycle to use for DMA transfer. |
| 1056 | * @dwidth: VME data width to use for DMA transfer. |
| 1057 | * |
| 1058 | * Create VME DMA list attribute pointing to a location on the VME bus for DMA |
| 1059 | * transfers. It is the responsibility of the user to free used attributes |
| 1060 | * using vme_dma_free_attribute(). |
| 1061 | * |
| 1062 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1063 | */ |
| 1064 | struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1065 | u32 aspace, u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1066 | { |
| 1067 | struct vme_dma_attr *attributes; |
| 1068 | struct vme_dma_vme *vme_attr; |
| 1069 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1070 | attributes = kmalloc( |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1071 | sizeof(struct vme_dma_attr), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1072 | if (!attributes) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1073 | goto err_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1074 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1075 | vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1076 | if (!vme_attr) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1077 | goto err_vme; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1078 | |
| 1079 | attributes->type = VME_DMA_VME; |
| 1080 | attributes->private = (void *)vme_attr; |
| 1081 | |
| 1082 | vme_attr->address = address; |
| 1083 | vme_attr->aspace = aspace; |
| 1084 | vme_attr->cycle = cycle; |
| 1085 | vme_attr->dwidth = dwidth; |
| 1086 | |
| 1087 | return attributes; |
| 1088 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1089 | err_vme: |
| 1090 | kfree(attributes); |
| 1091 | err_attr: |
| 1092 | return NULL; |
| 1093 | } |
| 1094 | EXPORT_SYMBOL(vme_dma_vme_attribute); |
| 1095 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1096 | /** |
| 1097 | * vme_dma_free_attribute - Free DMA list attribute. |
| 1098 | * @attributes: Pointer to DMA list attribute. |
| 1099 | * |
| 1100 | * Free VME DMA list attribute. VME DMA list attributes can be safely freed |
| 1101 | * once vme_dma_list_add() has returned. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1102 | */ |
| 1103 | void vme_dma_free_attribute(struct vme_dma_attr *attributes) |
| 1104 | { |
| 1105 | kfree(attributes->private); |
| 1106 | kfree(attributes); |
| 1107 | } |
| 1108 | EXPORT_SYMBOL(vme_dma_free_attribute); |
| 1109 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1110 | /** |
| 1111 | * vme_dma_list_add - Add enty to a VME DMA list. |
| 1112 | * @list: Pointer to VME list. |
| 1113 | * @src: Pointer to DMA list attribute to use as source. |
| 1114 | * @dest: Pointer to DMA list attribute to use as destination. |
| 1115 | * @count: Number of bytes to transfer. |
| 1116 | * |
| 1117 | * Add an entry to the provided VME DMA list. Entry requires pointers to source |
| 1118 | * and destination DMA attributes and a count. |
| 1119 | * |
| 1120 | * Please note, the attributes supported as source and destinations for |
| 1121 | * transfers are hardware dependent. |
| 1122 | * |
| 1123 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 1124 | * device or if the link list has already been submitted for execution. |
| 1125 | * Hardware specific errors also possible. |
| 1126 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1127 | int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, |
| 1128 | struct vme_dma_attr *dest, size_t count) |
| 1129 | { |
| 1130 | struct vme_bridge *bridge = list->parent->parent; |
| 1131 | int retval; |
| 1132 | |
| 1133 | if (bridge->dma_list_add == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1134 | printk(KERN_WARNING "Link List DMA generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1135 | return -EINVAL; |
| 1136 | } |
| 1137 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1138 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1139 | printk(KERN_ERR "Link List already submitted\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1140 | return -EINVAL; |
| 1141 | } |
| 1142 | |
| 1143 | retval = bridge->dma_list_add(list, src, dest, count); |
| 1144 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1145 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1146 | |
| 1147 | return retval; |
| 1148 | } |
| 1149 | EXPORT_SYMBOL(vme_dma_list_add); |
| 1150 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1151 | /** |
| 1152 | * vme_dma_list_exec - Queue a VME DMA list for execution. |
| 1153 | * @list: Pointer to VME list. |
| 1154 | * |
| 1155 | * Queue the provided VME DMA list for execution. The call will return once the |
| 1156 | * list has been executed. |
| 1157 | * |
| 1158 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 1159 | * device. Hardware specific errors also possible. |
| 1160 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1161 | int vme_dma_list_exec(struct vme_dma_list *list) |
| 1162 | { |
| 1163 | struct vme_bridge *bridge = list->parent->parent; |
| 1164 | int retval; |
| 1165 | |
| 1166 | if (bridge->dma_list_exec == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1167 | printk(KERN_ERR "Link List DMA execution not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1168 | return -EINVAL; |
| 1169 | } |
| 1170 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1171 | mutex_lock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1172 | |
| 1173 | retval = bridge->dma_list_exec(list); |
| 1174 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1175 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1176 | |
| 1177 | return retval; |
| 1178 | } |
| 1179 | EXPORT_SYMBOL(vme_dma_list_exec); |
| 1180 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1181 | /** |
| 1182 | * vme_dma_list_free - Free a VME DMA list. |
| 1183 | * @list: Pointer to VME list. |
| 1184 | * |
| 1185 | * Free the provided DMA list and all its entries. |
| 1186 | * |
| 1187 | * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource |
| 1188 | * is still in use. Hardware specific errors also possible. |
| 1189 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1190 | int vme_dma_list_free(struct vme_dma_list *list) |
| 1191 | { |
| 1192 | struct vme_bridge *bridge = list->parent->parent; |
| 1193 | int retval; |
| 1194 | |
| 1195 | if (bridge->dma_list_empty == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1196 | printk(KERN_WARNING "Emptying of Link Lists not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1197 | return -EINVAL; |
| 1198 | } |
| 1199 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1200 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1201 | printk(KERN_ERR "Link List in use\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1202 | return -EINVAL; |
| 1203 | } |
| 1204 | |
| 1205 | /* |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1206 | * Empty out all of the entries from the DMA list. We need to go to the |
| 1207 | * low level driver as DMA entries are driver specific. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1208 | */ |
| 1209 | retval = bridge->dma_list_empty(list); |
| 1210 | if (retval) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1211 | printk(KERN_ERR "Unable to empty link-list entries\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1212 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1213 | return retval; |
| 1214 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1215 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1216 | kfree(list); |
| 1217 | |
| 1218 | return retval; |
| 1219 | } |
| 1220 | EXPORT_SYMBOL(vme_dma_list_free); |
| 1221 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1222 | /** |
| 1223 | * vme_dma_free - Free a VME DMA resource. |
| 1224 | * @resource: Pointer to VME DMA resource. |
| 1225 | * |
| 1226 | * Free the provided DMA resource so that it may be reallocated. |
| 1227 | * |
| 1228 | * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource |
| 1229 | * is still active. |
| 1230 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1231 | int vme_dma_free(struct vme_resource *resource) |
| 1232 | { |
| 1233 | struct vme_dma_resource *ctrlr; |
| 1234 | |
| 1235 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1236 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1237 | return -EINVAL; |
| 1238 | } |
| 1239 | |
| 1240 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 1241 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1242 | if (!mutex_trylock(&ctrlr->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1243 | printk(KERN_ERR "Resource busy, can't free\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1244 | return -EBUSY; |
| 1245 | } |
| 1246 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1247 | if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1248 | printk(KERN_WARNING "Resource still processing transfers\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1249 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1250 | return -EBUSY; |
| 1251 | } |
| 1252 | |
| 1253 | ctrlr->locked = 0; |
| 1254 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1255 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1256 | |
Martyn Welch | fd5c256 | 2013-06-06 12:29:16 +0100 | [diff] [blame] | 1257 | kfree(resource); |
| 1258 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1259 | return 0; |
| 1260 | } |
| 1261 | EXPORT_SYMBOL(vme_dma_free); |
| 1262 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1263 | void vme_bus_error_handler(struct vme_bridge *bridge, |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 1264 | unsigned long long address, int am) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1265 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1266 | struct list_head *handler_pos = NULL; |
| 1267 | struct vme_error_handler *handler; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1268 | int handler_triggered = 0; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1269 | u32 aspace = vme_get_aspace(am); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1270 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1271 | list_for_each(handler_pos, &bridge->vme_error_handlers) { |
| 1272 | handler = list_entry(handler_pos, struct vme_error_handler, |
| 1273 | list); |
| 1274 | if ((aspace == handler->aspace) && |
| 1275 | (address >= handler->start) && |
| 1276 | (address < handler->end)) { |
| 1277 | if (!handler->num_errors) |
| 1278 | handler->first_error = address; |
| 1279 | if (handler->num_errors != UINT_MAX) |
| 1280 | handler->num_errors++; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1281 | handler_triggered = 1; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1282 | } |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1283 | } |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1284 | |
| 1285 | if (!handler_triggered) |
| 1286 | dev_err(bridge->parent, |
| 1287 | "Unhandled VME access error at address 0x%llx\n", |
| 1288 | address); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1289 | } |
| 1290 | EXPORT_SYMBOL(vme_bus_error_handler); |
| 1291 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1292 | struct vme_error_handler *vme_register_error_handler( |
| 1293 | struct vme_bridge *bridge, u32 aspace, |
| 1294 | unsigned long long address, size_t len) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1295 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1296 | struct vme_error_handler *handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1297 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1298 | handler = kmalloc(sizeof(*handler), GFP_KERNEL); |
| 1299 | if (!handler) |
| 1300 | return NULL; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1301 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1302 | handler->aspace = aspace; |
| 1303 | handler->start = address; |
| 1304 | handler->end = address + len; |
| 1305 | handler->num_errors = 0; |
| 1306 | handler->first_error = 0; |
| 1307 | list_add_tail(&handler->list, &bridge->vme_error_handlers); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1308 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1309 | return handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1310 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1311 | EXPORT_SYMBOL(vme_register_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1312 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1313 | void vme_unregister_error_handler(struct vme_error_handler *handler) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1314 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1315 | list_del(&handler->list); |
| 1316 | kfree(handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1317 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1318 | EXPORT_SYMBOL(vme_unregister_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1319 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1320 | void vme_irq_handler(struct vme_bridge *bridge, int level, int statid) |
| 1321 | { |
| 1322 | void (*call)(int, int, void *); |
| 1323 | void *priv_data; |
| 1324 | |
| 1325 | call = bridge->irq[level - 1].callback[statid].func; |
| 1326 | priv_data = bridge->irq[level - 1].callback[statid].priv_data; |
| 1327 | |
| 1328 | if (call != NULL) |
| 1329 | call(level, statid, priv_data); |
| 1330 | else |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1331 | printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n", |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1332 | level, statid); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1333 | } |
| 1334 | EXPORT_SYMBOL(vme_irq_handler); |
| 1335 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1336 | /** |
| 1337 | * vme_irq_request - Request a specific VME interrupt. |
| 1338 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1339 | * @level: Interrupt priority being requested. |
| 1340 | * @statid: Interrupt vector being requested. |
| 1341 | * @callback: Pointer to callback function called when VME interrupt/vector |
| 1342 | * received. |
| 1343 | * @priv_data: Generic pointer that will be passed to the callback function. |
| 1344 | * |
| 1345 | * Request callback to be attached as a handler for VME interrupts with provided |
| 1346 | * level and statid. |
| 1347 | * |
| 1348 | * Return: Zero on success, -EINVAL on invalid vme device, level or if the |
| 1349 | * function is not supported, -EBUSY if the level/statid combination is |
| 1350 | * already in use. Hardware specific errors also possible. |
| 1351 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1352 | int vme_irq_request(struct vme_dev *vdev, int level, int statid, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1353 | void (*callback)(int, int, void *), |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1354 | void *priv_data) |
| 1355 | { |
| 1356 | struct vme_bridge *bridge; |
| 1357 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1358 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1359 | if (bridge == NULL) { |
| 1360 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1361 | return -EINVAL; |
| 1362 | } |
| 1363 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1364 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1365 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1366 | return -EINVAL; |
| 1367 | } |
| 1368 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1369 | if (bridge->irq_set == NULL) { |
| 1370 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1374 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1375 | |
| 1376 | if (bridge->irq[level - 1].callback[statid].func) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1377 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1378 | printk(KERN_WARNING "VME Interrupt already taken\n"); |
| 1379 | return -EBUSY; |
| 1380 | } |
| 1381 | |
| 1382 | bridge->irq[level - 1].count++; |
| 1383 | bridge->irq[level - 1].callback[statid].priv_data = priv_data; |
| 1384 | bridge->irq[level - 1].callback[statid].func = callback; |
| 1385 | |
| 1386 | /* Enable IRQ level */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1387 | bridge->irq_set(bridge, level, 1, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1388 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1389 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1392 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1393 | EXPORT_SYMBOL(vme_irq_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1394 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1395 | /** |
| 1396 | * vme_irq_free - Free a VME interrupt. |
| 1397 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1398 | * @level: Interrupt priority of interrupt being freed. |
| 1399 | * @statid: Interrupt vector of interrupt being freed. |
| 1400 | * |
| 1401 | * Remove previously attached callback from VME interrupt priority/vector. |
| 1402 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1403 | void vme_irq_free(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1404 | { |
| 1405 | struct vme_bridge *bridge; |
| 1406 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1407 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1408 | if (bridge == NULL) { |
| 1409 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1410 | return; |
| 1411 | } |
| 1412 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1413 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1414 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1415 | return; |
| 1416 | } |
| 1417 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1418 | if (bridge->irq_set == NULL) { |
| 1419 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1420 | return; |
| 1421 | } |
| 1422 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1423 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1424 | |
| 1425 | bridge->irq[level - 1].count--; |
| 1426 | |
| 1427 | /* Disable IRQ level if no more interrupts attached at this level*/ |
| 1428 | if (bridge->irq[level - 1].count == 0) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1429 | bridge->irq_set(bridge, level, 0, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1430 | |
| 1431 | bridge->irq[level - 1].callback[statid].func = NULL; |
| 1432 | bridge->irq[level - 1].callback[statid].priv_data = NULL; |
| 1433 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1434 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1435 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1436 | EXPORT_SYMBOL(vme_irq_free); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1437 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1438 | /** |
| 1439 | * vme_irq_generate - Generate VME interrupt. |
| 1440 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1441 | * @level: Interrupt priority at which to assert the interrupt. |
| 1442 | * @statid: Interrupt vector to associate with the interrupt. |
| 1443 | * |
| 1444 | * Generate a VME interrupt of the provided level and with the provided |
| 1445 | * statid. |
| 1446 | * |
| 1447 | * Return: Zero on success, -EINVAL on invalid vme device, level or if the |
| 1448 | * function is not supported. Hardware specific errors also possible. |
| 1449 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1450 | int vme_irq_generate(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1451 | { |
| 1452 | struct vme_bridge *bridge; |
| 1453 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1454 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1455 | if (bridge == NULL) { |
| 1456 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1457 | return -EINVAL; |
| 1458 | } |
| 1459 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1460 | if ((level < 1) || (level > 7)) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1461 | printk(KERN_WARNING "Invalid interrupt level\n"); |
| 1462 | return -EINVAL; |
| 1463 | } |
| 1464 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1465 | if (bridge->irq_generate == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1466 | printk(KERN_WARNING "Interrupt generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1467 | return -EINVAL; |
| 1468 | } |
| 1469 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1470 | return bridge->irq_generate(bridge, level, statid); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1471 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1472 | EXPORT_SYMBOL(vme_irq_generate); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1473 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1474 | /** |
| 1475 | * vme_lm_request - Request a VME location monitor |
| 1476 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1477 | * |
| 1478 | * Allocate a location monitor resource to the driver. A location monitor |
| 1479 | * allows the driver to monitor accesses to a contiguous number of |
| 1480 | * addresses on the VME bus. |
| 1481 | * |
| 1482 | * Return: Pointer to a VME resource on success or NULL on failure. |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1483 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1484 | struct vme_resource *vme_lm_request(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1485 | { |
| 1486 | struct vme_bridge *bridge; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1487 | struct list_head *lm_pos = NULL; |
| 1488 | struct vme_lm_resource *allocated_lm = NULL; |
| 1489 | struct vme_lm_resource *lm = NULL; |
| 1490 | struct vme_resource *resource = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1491 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1492 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1493 | if (bridge == NULL) { |
| 1494 | printk(KERN_ERR "Can't find VME bus\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1495 | goto err_bus; |
| 1496 | } |
| 1497 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1498 | /* Loop through LM resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1499 | list_for_each(lm_pos, &bridge->lm_resources) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1500 | lm = list_entry(lm_pos, |
| 1501 | struct vme_lm_resource, list); |
| 1502 | |
| 1503 | if (lm == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1504 | printk(KERN_ERR "Registered NULL Location Monitor resource\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1505 | continue; |
| 1506 | } |
| 1507 | |
| 1508 | /* Find an unlocked controller */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1509 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1510 | if (lm->locked == 0) { |
| 1511 | lm->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1512 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1513 | allocated_lm = lm; |
| 1514 | break; |
| 1515 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1516 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /* Check to see if we found a resource */ |
| 1520 | if (allocated_lm == NULL) |
| 1521 | goto err_lm; |
| 1522 | |
| 1523 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1524 | if (!resource) |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1525 | goto err_alloc; |
Markus Elfring | 94eefcc | 2017-08-24 21:38:20 +0200 | [diff] [blame^] | 1526 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1527 | resource->type = VME_LM; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1528 | resource->entry = &allocated_lm->list; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1529 | |
| 1530 | return resource; |
| 1531 | |
| 1532 | err_alloc: |
| 1533 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1534 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1535 | lm->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1536 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1537 | err_lm: |
| 1538 | err_bus: |
| 1539 | return NULL; |
| 1540 | } |
| 1541 | EXPORT_SYMBOL(vme_lm_request); |
| 1542 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1543 | /** |
| 1544 | * vme_lm_count - Determine number of VME Addresses monitored |
| 1545 | * @resource: Pointer to VME location monitor resource. |
| 1546 | * |
| 1547 | * The number of contiguous addresses monitored is hardware dependent. |
| 1548 | * Return the number of contiguous addresses monitored by the |
| 1549 | * location monitor. |
| 1550 | * |
| 1551 | * Return: Count of addresses monitored or -EINVAL when provided with an |
| 1552 | * invalid location monitor resource. |
| 1553 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1554 | int vme_lm_count(struct vme_resource *resource) |
| 1555 | { |
| 1556 | struct vme_lm_resource *lm; |
| 1557 | |
| 1558 | if (resource->type != VME_LM) { |
| 1559 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1560 | return -EINVAL; |
| 1561 | } |
| 1562 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1563 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1564 | |
| 1565 | return lm->monitors; |
| 1566 | } |
| 1567 | EXPORT_SYMBOL(vme_lm_count); |
| 1568 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1569 | /** |
| 1570 | * vme_lm_set - Configure location monitor |
| 1571 | * @resource: Pointer to VME location monitor resource. |
| 1572 | * @lm_base: Base address to monitor. |
| 1573 | * @aspace: VME address space to monitor. |
| 1574 | * @cycle: VME bus cycle type to monitor. |
| 1575 | * |
| 1576 | * Set the base address, address space and cycle type of accesses to be |
| 1577 | * monitored by the location monitor. |
| 1578 | * |
| 1579 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1580 | * monitor resource or function is not supported. Hardware specific |
| 1581 | * errors may also be returned. |
| 1582 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1583 | 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] | 1584 | u32 aspace, u32 cycle) |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1585 | { |
| 1586 | struct vme_bridge *bridge = find_bridge(resource); |
| 1587 | struct vme_lm_resource *lm; |
| 1588 | |
| 1589 | if (resource->type != VME_LM) { |
| 1590 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1591 | return -EINVAL; |
| 1592 | } |
| 1593 | |
| 1594 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1595 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1596 | if (bridge->lm_set == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1597 | printk(KERN_ERR "vme_lm_set not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1601 | return bridge->lm_set(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1602 | } |
| 1603 | EXPORT_SYMBOL(vme_lm_set); |
| 1604 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1605 | /** |
| 1606 | * vme_lm_get - Retrieve location monitor settings |
| 1607 | * @resource: Pointer to VME location monitor resource. |
| 1608 | * @lm_base: Pointer used to output the base address monitored. |
| 1609 | * @aspace: Pointer used to output the address space monitored. |
| 1610 | * @cycle: Pointer used to output the VME bus cycle type monitored. |
| 1611 | * |
| 1612 | * Retrieve the base address, address space and cycle type of accesses to |
| 1613 | * be monitored by the location monitor. |
| 1614 | * |
| 1615 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1616 | * monitor resource or function is not supported. Hardware specific |
| 1617 | * errors may also be returned. |
| 1618 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1619 | 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] | 1620 | u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1621 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1622 | struct vme_bridge *bridge = find_bridge(resource); |
| 1623 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1624 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1625 | if (resource->type != VME_LM) { |
| 1626 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1627 | return -EINVAL; |
| 1628 | } |
| 1629 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1630 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1631 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1632 | if (bridge->lm_get == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1633 | printk(KERN_ERR "vme_lm_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1634 | return -EINVAL; |
| 1635 | } |
| 1636 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1637 | return bridge->lm_get(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1638 | } |
| 1639 | EXPORT_SYMBOL(vme_lm_get); |
| 1640 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1641 | /** |
| 1642 | * vme_lm_attach - Provide callback for location monitor address |
| 1643 | * @resource: Pointer to VME location monitor resource. |
| 1644 | * @monitor: Offset to which callback should be attached. |
| 1645 | * @callback: Pointer to callback function called when triggered. |
| 1646 | * @data: Generic pointer that will be passed to the callback function. |
| 1647 | * |
| 1648 | * Attach a callback to the specificed offset into the location monitors |
| 1649 | * monitored addresses. A generic pointer is provided to allow data to be |
| 1650 | * passed to the callback when called. |
| 1651 | * |
| 1652 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1653 | * monitor resource or function is not supported. Hardware specific |
| 1654 | * errors may also be returned. |
| 1655 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1656 | int vme_lm_attach(struct vme_resource *resource, int monitor, |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1657 | void (*callback)(void *), void *data) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1658 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1659 | struct vme_bridge *bridge = find_bridge(resource); |
| 1660 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1661 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1662 | if (resource->type != VME_LM) { |
| 1663 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1664 | return -EINVAL; |
| 1665 | } |
| 1666 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1667 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1668 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1669 | if (bridge->lm_attach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1670 | printk(KERN_ERR "vme_lm_attach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1671 | return -EINVAL; |
| 1672 | } |
| 1673 | |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1674 | return bridge->lm_attach(lm, monitor, callback, data); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1675 | } |
| 1676 | EXPORT_SYMBOL(vme_lm_attach); |
| 1677 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1678 | /** |
| 1679 | * vme_lm_detach - Remove callback for location monitor address |
| 1680 | * @resource: Pointer to VME location monitor resource. |
| 1681 | * @monitor: Offset to which callback should be removed. |
| 1682 | * |
| 1683 | * Remove the callback associated with the specificed offset into the |
| 1684 | * location monitors monitored addresses. |
| 1685 | * |
| 1686 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1687 | * monitor resource or function is not supported. Hardware specific |
| 1688 | * errors may also be returned. |
| 1689 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1690 | int vme_lm_detach(struct vme_resource *resource, int monitor) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1691 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1692 | struct vme_bridge *bridge = find_bridge(resource); |
| 1693 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1694 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1695 | if (resource->type != VME_LM) { |
| 1696 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1697 | return -EINVAL; |
| 1698 | } |
| 1699 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1700 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1701 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1702 | if (bridge->lm_detach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1703 | printk(KERN_ERR "vme_lm_detach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1704 | return -EINVAL; |
| 1705 | } |
| 1706 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1707 | return bridge->lm_detach(lm, monitor); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1708 | } |
| 1709 | EXPORT_SYMBOL(vme_lm_detach); |
| 1710 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1711 | /** |
| 1712 | * vme_lm_free - Free allocated VME location monitor |
| 1713 | * @resource: Pointer to VME location monitor resource. |
| 1714 | * |
| 1715 | * Free allocation of a VME location monitor. |
| 1716 | * |
| 1717 | * WARNING: This function currently expects that any callbacks that have |
| 1718 | * been attached to the location monitor have been removed. |
| 1719 | * |
| 1720 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1721 | * monitor resource. |
| 1722 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1723 | void vme_lm_free(struct vme_resource *resource) |
| 1724 | { |
| 1725 | struct vme_lm_resource *lm; |
| 1726 | |
| 1727 | if (resource->type != VME_LM) { |
| 1728 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1733 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1734 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1735 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1736 | /* XXX |
| 1737 | * Check to see that there aren't any callbacks still attached, if |
| 1738 | * there are we should probably be detaching them! |
| 1739 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1740 | |
| 1741 | lm->locked = 0; |
| 1742 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1743 | mutex_unlock(&lm->mtx); |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1744 | |
| 1745 | kfree(resource); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1746 | } |
| 1747 | EXPORT_SYMBOL(vme_lm_free); |
| 1748 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1749 | /** |
| 1750 | * vme_slot_num - Retrieve slot ID |
| 1751 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1752 | * |
| 1753 | * Retrieve the slot ID associated with the provided VME device. |
| 1754 | * |
| 1755 | * Return: The slot ID on success, -EINVAL if VME bridge cannot be determined |
| 1756 | * or the function is not supported. Hardware specific errors may also |
| 1757 | * be returned. |
| 1758 | */ |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1759 | int vme_slot_num(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1760 | { |
| 1761 | struct vme_bridge *bridge; |
| 1762 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1763 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1764 | if (bridge == NULL) { |
| 1765 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1766 | return -EINVAL; |
| 1767 | } |
| 1768 | |
| 1769 | if (bridge->slot_get == NULL) { |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1770 | printk(KERN_WARNING "vme_slot_num not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1771 | return -EINVAL; |
| 1772 | } |
| 1773 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1774 | return bridge->slot_get(bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1775 | } |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1776 | EXPORT_SYMBOL(vme_slot_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1777 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1778 | /** |
| 1779 | * vme_bus_num - Retrieve bus number |
| 1780 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1781 | * |
| 1782 | * Retrieve the bus enumeration associated with the provided VME device. |
| 1783 | * |
| 1784 | * Return: The bus number on success, -EINVAL if VME bridge cannot be |
| 1785 | * determined. |
| 1786 | */ |
Martyn Welch | 978f47d | 2013-11-08 11:58:34 +0000 | [diff] [blame] | 1787 | int vme_bus_num(struct vme_dev *vdev) |
| 1788 | { |
| 1789 | struct vme_bridge *bridge; |
| 1790 | |
| 1791 | bridge = vdev->bridge; |
| 1792 | if (bridge == NULL) { |
| 1793 | pr_err("Can't find VME bus\n"); |
| 1794 | return -EINVAL; |
| 1795 | } |
| 1796 | |
| 1797 | return bridge->num; |
| 1798 | } |
| 1799 | EXPORT_SYMBOL(vme_bus_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1800 | |
| 1801 | /* - Bridge Registration --------------------------------------------------- */ |
| 1802 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1803 | static void vme_dev_release(struct device *dev) |
| 1804 | { |
| 1805 | kfree(dev_to_vme_dev(dev)); |
| 1806 | } |
| 1807 | |
Aaron Sierra | 326071b | 2016-04-24 15:11:38 -0500 | [diff] [blame] | 1808 | /* Common bridge initialization */ |
| 1809 | struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge) |
| 1810 | { |
| 1811 | INIT_LIST_HEAD(&bridge->vme_error_handlers); |
| 1812 | INIT_LIST_HEAD(&bridge->master_resources); |
| 1813 | INIT_LIST_HEAD(&bridge->slave_resources); |
| 1814 | INIT_LIST_HEAD(&bridge->dma_resources); |
| 1815 | INIT_LIST_HEAD(&bridge->lm_resources); |
| 1816 | mutex_init(&bridge->irq_mtx); |
| 1817 | |
| 1818 | return bridge; |
| 1819 | } |
| 1820 | EXPORT_SYMBOL(vme_init_bridge); |
| 1821 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1822 | int vme_register_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1823 | { |
| 1824 | int i; |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1825 | int ret = -1; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1826 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1827 | mutex_lock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1828 | for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) { |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1829 | if ((vme_bus_numbers & (1 << i)) == 0) { |
| 1830 | vme_bus_numbers |= (1 << i); |
| 1831 | bridge->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1832 | INIT_LIST_HEAD(&bridge->devices); |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1833 | list_add_tail(&bridge->bus_list, &vme_bus_list); |
| 1834 | ret = 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1835 | break; |
| 1836 | } |
| 1837 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1838 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1839 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1840 | return ret; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1841 | } |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1842 | EXPORT_SYMBOL(vme_register_bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1843 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1844 | void vme_unregister_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1845 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1846 | struct vme_dev *vdev; |
| 1847 | struct vme_dev *tmp; |
| 1848 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1849 | mutex_lock(&vme_buses_lock); |
| 1850 | vme_bus_numbers &= ~(1 << bridge->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1851 | list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) { |
| 1852 | list_del(&vdev->drv_list); |
| 1853 | list_del(&vdev->bridge_list); |
| 1854 | device_unregister(&vdev->dev); |
| 1855 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1856 | list_del(&bridge->bus_list); |
| 1857 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1858 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1859 | EXPORT_SYMBOL(vme_unregister_bridge); |
| 1860 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1861 | /* - Driver Registration --------------------------------------------------- */ |
| 1862 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1863 | static int __vme_register_driver_bus(struct vme_driver *drv, |
| 1864 | struct vme_bridge *bridge, unsigned int ndevs) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1865 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1866 | int err; |
| 1867 | unsigned int i; |
| 1868 | struct vme_dev *vdev; |
| 1869 | struct vme_dev *tmp; |
| 1870 | |
| 1871 | for (i = 0; i < ndevs; i++) { |
| 1872 | vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL); |
| 1873 | if (!vdev) { |
| 1874 | err = -ENOMEM; |
| 1875 | goto err_devalloc; |
| 1876 | } |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1877 | vdev->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1878 | vdev->bridge = bridge; |
| 1879 | vdev->dev.platform_data = drv; |
| 1880 | vdev->dev.release = vme_dev_release; |
| 1881 | vdev->dev.parent = bridge->parent; |
| 1882 | vdev->dev.bus = &vme_bus_type; |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1883 | dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num, |
| 1884 | vdev->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1885 | |
| 1886 | err = device_register(&vdev->dev); |
| 1887 | if (err) |
| 1888 | goto err_reg; |
| 1889 | |
| 1890 | if (vdev->dev.platform_data) { |
| 1891 | list_add_tail(&vdev->drv_list, &drv->devices); |
| 1892 | list_add_tail(&vdev->bridge_list, &bridge->devices); |
| 1893 | } else |
| 1894 | device_unregister(&vdev->dev); |
| 1895 | } |
| 1896 | return 0; |
| 1897 | |
| 1898 | err_reg: |
Emilio G. Cota | def1820 | 2013-02-13 13:47:54 -0500 | [diff] [blame] | 1899 | put_device(&vdev->dev); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1900 | kfree(vdev); |
| 1901 | err_devalloc: |
| 1902 | list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) { |
| 1903 | list_del(&vdev->drv_list); |
| 1904 | list_del(&vdev->bridge_list); |
| 1905 | device_unregister(&vdev->dev); |
| 1906 | } |
| 1907 | return err; |
| 1908 | } |
| 1909 | |
| 1910 | static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1911 | { |
| 1912 | struct vme_bridge *bridge; |
| 1913 | int err = 0; |
| 1914 | |
| 1915 | mutex_lock(&vme_buses_lock); |
| 1916 | list_for_each_entry(bridge, &vme_bus_list, bus_list) { |
| 1917 | /* |
| 1918 | * This cannot cause trouble as we already have vme_buses_lock |
| 1919 | * and if the bridge is removed, it will have to go through |
| 1920 | * vme_unregister_bridge() to do it (which calls remove() on |
| 1921 | * the bridge which in turn tries to acquire vme_buses_lock and |
Manohar Vanga | c26f611 | 2011-11-04 11:12:29 +0100 | [diff] [blame] | 1922 | * will have to wait). |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1923 | */ |
| 1924 | err = __vme_register_driver_bus(drv, bridge, ndevs); |
| 1925 | if (err) |
| 1926 | break; |
| 1927 | } |
| 1928 | mutex_unlock(&vme_buses_lock); |
| 1929 | return err; |
| 1930 | } |
| 1931 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1932 | /** |
| 1933 | * vme_register_driver - Register a VME driver |
| 1934 | * @drv: Pointer to VME driver structure to register. |
| 1935 | * @ndevs: Maximum number of devices to allow to be enumerated. |
| 1936 | * |
| 1937 | * Register a VME device driver with the VME subsystem. |
| 1938 | * |
| 1939 | * Return: Zero on success, error value on registration failure. |
| 1940 | */ |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1941 | int vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1942 | { |
| 1943 | int err; |
| 1944 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1945 | drv->driver.name = drv->name; |
| 1946 | drv->driver.bus = &vme_bus_type; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1947 | INIT_LIST_HEAD(&drv->devices); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1948 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1949 | err = driver_register(&drv->driver); |
| 1950 | if (err) |
| 1951 | return err; |
| 1952 | |
| 1953 | err = __vme_register_driver(drv, ndevs); |
| 1954 | if (err) |
| 1955 | driver_unregister(&drv->driver); |
| 1956 | |
| 1957 | return err; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1958 | } |
| 1959 | EXPORT_SYMBOL(vme_register_driver); |
| 1960 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1961 | /** |
| 1962 | * vme_unregister_driver - Unregister a VME driver |
| 1963 | * @drv: Pointer to VME driver structure to unregister. |
| 1964 | * |
| 1965 | * Unregister a VME device driver from the VME subsystem. |
| 1966 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1967 | void vme_unregister_driver(struct vme_driver *drv) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1968 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1969 | struct vme_dev *dev, *dev_tmp; |
| 1970 | |
| 1971 | mutex_lock(&vme_buses_lock); |
| 1972 | list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) { |
| 1973 | list_del(&dev->drv_list); |
| 1974 | list_del(&dev->bridge_list); |
| 1975 | device_unregister(&dev->dev); |
| 1976 | } |
| 1977 | mutex_unlock(&vme_buses_lock); |
| 1978 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1979 | driver_unregister(&drv->driver); |
| 1980 | } |
| 1981 | EXPORT_SYMBOL(vme_unregister_driver); |
| 1982 | |
| 1983 | /* - Bus Registration ------------------------------------------------------ */ |
| 1984 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1985 | static int vme_bus_match(struct device *dev, struct device_driver *drv) |
| 1986 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1987 | struct vme_driver *vme_drv; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1988 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1989 | vme_drv = container_of(drv, struct vme_driver, driver); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1990 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1991 | if (dev->platform_data == vme_drv) { |
| 1992 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1993 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1994 | if (vme_drv->match && vme_drv->match(vdev)) |
| 1995 | return 1; |
| 1996 | |
| 1997 | dev->platform_data = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1998 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1999 | return 0; |
| 2000 | } |
| 2001 | |
| 2002 | static int vme_bus_probe(struct device *dev) |
| 2003 | { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2004 | int retval = -ENODEV; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2005 | struct vme_driver *driver; |
| 2006 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2007 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2008 | driver = dev->platform_data; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2009 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 2010 | if (driver->probe != NULL) |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 2011 | retval = driver->probe(vdev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2012 | |
| 2013 | return retval; |
| 2014 | } |
| 2015 | |
Stefano Babic | 9797484 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 2016 | static int vme_bus_remove(struct device *dev) |
| 2017 | { |
| 2018 | int retval = -ENODEV; |
| 2019 | struct vme_driver *driver; |
| 2020 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
| 2021 | |
| 2022 | driver = dev->platform_data; |
| 2023 | |
| 2024 | if (driver->remove != NULL) |
| 2025 | retval = driver->remove(vdev); |
| 2026 | |
| 2027 | return retval; |
| 2028 | } |
| 2029 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2030 | struct bus_type vme_bus_type = { |
| 2031 | .name = "vme", |
| 2032 | .match = vme_bus_match, |
| 2033 | .probe = vme_bus_probe, |
Stefano Babic | 9797484 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 2034 | .remove = vme_bus_remove, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2035 | }; |
| 2036 | EXPORT_SYMBOL(vme_bus_type); |
| 2037 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 2038 | static int __init vme_init(void) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2039 | { |
| 2040 | return bus_register(&vme_bus_type); |
| 2041 | } |
Aaron Sierra | c326cc0 | 2013-12-09 09:54:42 -0600 | [diff] [blame] | 2042 | subsys_initcall(vme_init); |