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 | |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 211 | if (vme_base + size < size) |
| 212 | return -EINVAL; |
| 213 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 214 | switch (aspace) { |
| 215 | case VME_A16: |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 216 | if (vme_base + size > VME_A16_MAX) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 217 | retval = -EFAULT; |
| 218 | break; |
| 219 | case VME_A24: |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 220 | if (vme_base + size > VME_A24_MAX) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 221 | retval = -EFAULT; |
| 222 | break; |
| 223 | case VME_A32: |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 224 | if (vme_base + size > VME_A32_MAX) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 225 | retval = -EFAULT; |
| 226 | break; |
| 227 | case VME_A64: |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 228 | /* The VME_A64_MAX limit is actually U64_MAX + 1 */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 229 | break; |
| 230 | case VME_CRCSR: |
Dan Carpenter | bd14798 | 2017-09-30 14:27:41 +0300 | [diff] [blame^] | 231 | if (vme_base + size > VME_CRCSR_MAX) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 232 | retval = -EFAULT; |
| 233 | break; |
| 234 | case VME_USER1: |
| 235 | case VME_USER2: |
| 236 | case VME_USER3: |
| 237 | case VME_USER4: |
| 238 | /* User Defined */ |
| 239 | break; |
| 240 | default: |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 241 | printk(KERN_ERR "Invalid address space\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 242 | retval = -EINVAL; |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | return retval; |
| 247 | } |
Dmitry Kalinkin | ef73f88 | 2015-05-28 15:07:04 +0300 | [diff] [blame] | 248 | EXPORT_SYMBOL(vme_check_window); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 249 | |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 250 | static u32 vme_get_aspace(int am) |
| 251 | { |
| 252 | switch (am) { |
| 253 | case 0x29: |
| 254 | case 0x2D: |
| 255 | return VME_A16; |
| 256 | case 0x38: |
| 257 | case 0x39: |
| 258 | case 0x3A: |
| 259 | case 0x3B: |
| 260 | case 0x3C: |
| 261 | case 0x3D: |
| 262 | case 0x3E: |
| 263 | case 0x3F: |
| 264 | return VME_A24; |
| 265 | case 0x8: |
| 266 | case 0x9: |
| 267 | case 0xA: |
| 268 | case 0xB: |
| 269 | case 0xC: |
| 270 | case 0xD: |
| 271 | case 0xE: |
| 272 | case 0xF: |
| 273 | return VME_A32; |
| 274 | case 0x0: |
| 275 | case 0x1: |
| 276 | case 0x3: |
| 277 | return VME_A64; |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 283 | /** |
| 284 | * vme_slave_request - Request a VME slave window resource. |
| 285 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 286 | * @address: Required VME address space. |
| 287 | * @cycle: Required VME data transfer cycle type. |
| 288 | * |
| 289 | * Request use of a VME window resource capable of being set for the requested |
| 290 | * address space and data transfer cycle. |
| 291 | * |
| 292 | * Return: Pointer to VME resource on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 293 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 294 | struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, |
| 295 | u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 296 | { |
| 297 | struct vme_bridge *bridge; |
| 298 | struct list_head *slave_pos = NULL; |
| 299 | struct vme_slave_resource *allocated_image = NULL; |
| 300 | struct vme_slave_resource *slave_image = NULL; |
| 301 | struct vme_resource *resource = NULL; |
| 302 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 303 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 304 | if (bridge == NULL) { |
| 305 | printk(KERN_ERR "Can't find VME bus\n"); |
| 306 | goto err_bus; |
| 307 | } |
| 308 | |
| 309 | /* Loop through slave resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 310 | list_for_each(slave_pos, &bridge->slave_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 311 | slave_image = list_entry(slave_pos, |
| 312 | struct vme_slave_resource, list); |
| 313 | |
| 314 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 315 | printk(KERN_ERR "Registered NULL Slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 316 | continue; |
| 317 | } |
| 318 | |
| 319 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 320 | mutex_lock(&slave_image->mtx); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 321 | if (((slave_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 322 | ((slave_image->cycle_attr & cycle) == cycle) && |
| 323 | (slave_image->locked == 0)) { |
| 324 | |
| 325 | slave_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 326 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 327 | allocated_image = slave_image; |
| 328 | break; |
| 329 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 330 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* No free image */ |
| 334 | if (allocated_image == NULL) |
| 335 | goto err_image; |
| 336 | |
| 337 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 338 | if (resource == NULL) { |
| 339 | printk(KERN_WARNING "Unable to allocate resource structure\n"); |
| 340 | goto err_alloc; |
| 341 | } |
| 342 | resource->type = VME_SLAVE; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 343 | resource->entry = &allocated_image->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 344 | |
| 345 | return resource; |
| 346 | |
| 347 | err_alloc: |
| 348 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 349 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 350 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 351 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 352 | err_image: |
| 353 | err_bus: |
| 354 | return NULL; |
| 355 | } |
| 356 | EXPORT_SYMBOL(vme_slave_request); |
| 357 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 358 | /** |
| 359 | * vme_slave_set - Set VME slave window configuration. |
| 360 | * @resource: Pointer to VME slave resource. |
| 361 | * @enabled: State to which the window should be configured. |
| 362 | * @vme_base: Base address for the window. |
| 363 | * @size: Size of the VME window. |
| 364 | * @buf_base: Based address of buffer used to provide VME slave window storage. |
| 365 | * @aspace: VME address space for the VME window. |
| 366 | * @cycle: VME data transfer cycle type for the VME window. |
| 367 | * |
| 368 | * Set configuration for provided VME slave window. |
| 369 | * |
| 370 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 371 | * device, if an invalid resource has been provided or invalid |
| 372 | * attributes are provided. Hardware specific errors may also be |
| 373 | * returned. |
| 374 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 375 | int vme_slave_set(struct vme_resource *resource, int enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 376 | unsigned long long vme_base, unsigned long long size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 377 | dma_addr_t buf_base, u32 aspace, u32 cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 378 | { |
| 379 | struct vme_bridge *bridge = find_bridge(resource); |
| 380 | struct vme_slave_resource *image; |
| 381 | int retval; |
| 382 | |
| 383 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 384 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 385 | return -EINVAL; |
| 386 | } |
| 387 | |
| 388 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 389 | |
| 390 | if (bridge->slave_set == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 391 | printk(KERN_ERR "Function not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 392 | return -ENOSYS; |
| 393 | } |
| 394 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 395 | if (!(((image->address_attr & aspace) == aspace) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 396 | ((image->cycle_attr & cycle) == cycle))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 397 | printk(KERN_ERR "Invalid attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 398 | return -EINVAL; |
| 399 | } |
| 400 | |
| 401 | retval = vme_check_window(aspace, vme_base, size); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 402 | if (retval) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 403 | return retval; |
| 404 | |
| 405 | return bridge->slave_set(image, enabled, vme_base, size, buf_base, |
| 406 | aspace, cycle); |
| 407 | } |
| 408 | EXPORT_SYMBOL(vme_slave_set); |
| 409 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 410 | /** |
| 411 | * vme_slave_get - Retrieve VME slave window configuration. |
| 412 | * @resource: Pointer to VME slave resource. |
| 413 | * @enabled: Pointer to variable for storing state. |
| 414 | * @vme_base: Pointer to variable for storing window base address. |
| 415 | * @size: Pointer to variable for storing window size. |
| 416 | * @buf_base: Pointer to variable for storing slave buffer base address. |
| 417 | * @aspace: Pointer to variable for storing VME address space. |
| 418 | * @cycle: Pointer to variable for storing VME data transfer cycle type. |
| 419 | * |
| 420 | * Return configuration for provided VME slave window. |
| 421 | * |
| 422 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 423 | * device or if an invalid resource has been provided. |
| 424 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 425 | int vme_slave_get(struct vme_resource *resource, int *enabled, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 426 | unsigned long long *vme_base, unsigned long long *size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 427 | dma_addr_t *buf_base, u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 428 | { |
| 429 | struct vme_bridge *bridge = find_bridge(resource); |
| 430 | struct vme_slave_resource *image; |
| 431 | |
| 432 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 433 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 434 | return -EINVAL; |
| 435 | } |
| 436 | |
| 437 | image = list_entry(resource->entry, struct vme_slave_resource, list); |
| 438 | |
Emilio G. Cota | 51a569f | 2009-08-10 16:52:42 +0200 | [diff] [blame] | 439 | if (bridge->slave_get == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 440 | printk(KERN_ERR "vme_slave_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 441 | return -EINVAL; |
| 442 | } |
| 443 | |
| 444 | return bridge->slave_get(image, enabled, vme_base, size, buf_base, |
| 445 | aspace, cycle); |
| 446 | } |
| 447 | EXPORT_SYMBOL(vme_slave_get); |
| 448 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 449 | /** |
| 450 | * vme_slave_free - Free VME slave window |
| 451 | * @resource: Pointer to VME slave resource. |
| 452 | * |
| 453 | * Free the provided slave resource so that it may be reallocated. |
| 454 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 455 | void vme_slave_free(struct vme_resource *resource) |
| 456 | { |
| 457 | struct vme_slave_resource *slave_image; |
| 458 | |
| 459 | if (resource->type != VME_SLAVE) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 460 | printk(KERN_ERR "Not a slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | |
| 464 | slave_image = list_entry(resource->entry, struct vme_slave_resource, |
| 465 | list); |
| 466 | if (slave_image == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 467 | printk(KERN_ERR "Can't find slave resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | |
| 471 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 472 | mutex_lock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 473 | if (slave_image->locked == 0) |
| 474 | printk(KERN_ERR "Image is already free\n"); |
| 475 | |
| 476 | slave_image->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 477 | mutex_unlock(&slave_image->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 478 | |
| 479 | /* Free up resource memory */ |
| 480 | kfree(resource); |
| 481 | } |
| 482 | EXPORT_SYMBOL(vme_slave_free); |
| 483 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 484 | /** |
| 485 | * vme_master_request - Request a VME master window resource. |
| 486 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 487 | * @address: Required VME address space. |
| 488 | * @cycle: Required VME data transfer cycle type. |
| 489 | * @dwidth: Required VME data transfer width. |
| 490 | * |
| 491 | * Request use of a VME window resource capable of being set for the requested |
| 492 | * address space, data transfer cycle and width. |
| 493 | * |
| 494 | * Return: Pointer to VME resource on success, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 495 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 496 | struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, |
| 497 | u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 498 | { |
| 499 | struct vme_bridge *bridge; |
| 500 | struct list_head *master_pos = NULL; |
| 501 | struct vme_master_resource *allocated_image = NULL; |
| 502 | struct vme_master_resource *master_image = NULL; |
| 503 | struct vme_resource *resource = NULL; |
| 504 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 505 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 506 | if (bridge == NULL) { |
| 507 | printk(KERN_ERR "Can't find VME bus\n"); |
| 508 | goto err_bus; |
| 509 | } |
| 510 | |
| 511 | /* Loop through master resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 512 | list_for_each(master_pos, &bridge->master_resources) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 513 | master_image = list_entry(master_pos, |
| 514 | struct vme_master_resource, list); |
| 515 | |
| 516 | if (master_image == NULL) { |
| 517 | printk(KERN_WARNING "Registered NULL master resource\n"); |
| 518 | continue; |
| 519 | } |
| 520 | |
| 521 | /* Find an unlocked and compatible image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 522 | spin_lock(&master_image->lock); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 523 | if (((master_image->address_attr & address) == address) && |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 524 | ((master_image->cycle_attr & cycle) == cycle) && |
| 525 | ((master_image->width_attr & dwidth) == dwidth) && |
| 526 | (master_image->locked == 0)) { |
| 527 | |
| 528 | master_image->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 529 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 530 | allocated_image = master_image; |
| 531 | break; |
| 532 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 533 | spin_unlock(&master_image->lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* Check to see if we found a resource */ |
| 537 | if (allocated_image == NULL) { |
| 538 | printk(KERN_ERR "Can't find a suitable resource\n"); |
| 539 | goto err_image; |
| 540 | } |
| 541 | |
| 542 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 543 | if (resource == NULL) { |
| 544 | printk(KERN_ERR "Unable to allocate resource structure\n"); |
| 545 | goto err_alloc; |
| 546 | } |
| 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); |
| 920 | if (resource == NULL) { |
| 921 | printk(KERN_WARNING "Unable to allocate resource structure\n"); |
| 922 | goto err_alloc; |
| 923 | } |
| 924 | resource->type = VME_DMA; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 925 | resource->entry = &allocated_ctrlr->list; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 926 | |
| 927 | return resource; |
| 928 | |
| 929 | err_alloc: |
| 930 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 931 | mutex_lock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 932 | dma_ctrlr->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 933 | mutex_unlock(&dma_ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 934 | err_ctrlr: |
| 935 | err_bus: |
| 936 | return NULL; |
| 937 | } |
Martyn Welch | 58e5079 | 2009-10-29 16:35:20 +0000 | [diff] [blame] | 938 | EXPORT_SYMBOL(vme_dma_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 939 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 940 | /** |
| 941 | * vme_new_dma_list - Create new VME DMA list. |
| 942 | * @resource: Pointer to VME DMA resource. |
| 943 | * |
| 944 | * Create a new VME DMA list. It is the responsibility of the user to free |
| 945 | * the list once it is no longer required with vme_dma_list_free(). |
| 946 | * |
| 947 | * Return: Pointer to new VME DMA list, NULL on allocation failure or invalid |
| 948 | * VME DMA resource. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 949 | */ |
| 950 | struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) |
| 951 | { |
| 952 | struct vme_dma_resource *ctrlr; |
| 953 | struct vme_dma_list *dma_list; |
| 954 | |
| 955 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 956 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 957 | return NULL; |
| 958 | } |
| 959 | |
| 960 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 961 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 962 | dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL); |
| 963 | if (dma_list == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 964 | printk(KERN_ERR "Unable to allocate memory for new DMA list\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 965 | return NULL; |
| 966 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 967 | INIT_LIST_HEAD(&dma_list->entries); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 968 | dma_list->parent = ctrlr; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 969 | mutex_init(&dma_list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 970 | |
| 971 | return dma_list; |
| 972 | } |
| 973 | EXPORT_SYMBOL(vme_new_dma_list); |
| 974 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 975 | /** |
| 976 | * vme_dma_pattern_attribute - Create "Pattern" type VME DMA list attribute. |
| 977 | * @pattern: Value to use used as pattern |
| 978 | * @type: Type of pattern to be written. |
| 979 | * |
| 980 | * Create VME DMA list attribute for pattern generation. It is the |
| 981 | * responsibility of the user to free used attributes using |
| 982 | * vme_dma_free_attribute(). |
| 983 | * |
| 984 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 985 | */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 986 | struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 987 | { |
| 988 | struct vme_dma_attr *attributes; |
| 989 | struct vme_dma_pattern *pattern_attr; |
| 990 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 991 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
| 992 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 993 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 994 | goto err_attr; |
| 995 | } |
| 996 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 997 | pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); |
| 998 | if (pattern_attr == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 999 | printk(KERN_ERR "Unable to allocate memory for pattern attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1000 | goto err_pat; |
| 1001 | } |
| 1002 | |
| 1003 | attributes->type = VME_DMA_PATTERN; |
| 1004 | attributes->private = (void *)pattern_attr; |
| 1005 | |
| 1006 | pattern_attr->pattern = pattern; |
| 1007 | pattern_attr->type = type; |
| 1008 | |
| 1009 | return attributes; |
| 1010 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1011 | err_pat: |
| 1012 | kfree(attributes); |
| 1013 | err_attr: |
| 1014 | return NULL; |
| 1015 | } |
| 1016 | EXPORT_SYMBOL(vme_dma_pattern_attribute); |
| 1017 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1018 | /** |
| 1019 | * vme_dma_pci_attribute - Create "PCI" type VME DMA list attribute. |
| 1020 | * @address: PCI base address for DMA transfer. |
| 1021 | * |
| 1022 | * Create VME DMA list attribute pointing to a location on PCI for DMA |
| 1023 | * transfers. It is the responsibility of the user to free used attributes |
| 1024 | * using vme_dma_free_attribute(). |
| 1025 | * |
| 1026 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1027 | */ |
| 1028 | struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) |
| 1029 | { |
| 1030 | struct vme_dma_attr *attributes; |
| 1031 | struct vme_dma_pci *pci_attr; |
| 1032 | |
| 1033 | /* XXX Run some sanity checks here */ |
| 1034 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1035 | attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); |
| 1036 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1037 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1038 | goto err_attr; |
| 1039 | } |
| 1040 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1041 | pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); |
| 1042 | if (pci_attr == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1043 | printk(KERN_ERR "Unable to allocate memory for PCI attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1044 | goto err_pci; |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | |
| 1049 | attributes->type = VME_DMA_PCI; |
| 1050 | attributes->private = (void *)pci_attr; |
| 1051 | |
| 1052 | pci_attr->address = address; |
| 1053 | |
| 1054 | return attributes; |
| 1055 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1056 | err_pci: |
| 1057 | kfree(attributes); |
| 1058 | err_attr: |
| 1059 | return NULL; |
| 1060 | } |
| 1061 | EXPORT_SYMBOL(vme_dma_pci_attribute); |
| 1062 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1063 | /** |
| 1064 | * vme_dma_vme_attribute - Create "VME" type VME DMA list attribute. |
| 1065 | * @address: VME base address for DMA transfer. |
| 1066 | * @aspace: VME address space to use for DMA transfer. |
| 1067 | * @cycle: VME bus cycle to use for DMA transfer. |
| 1068 | * @dwidth: VME data width to use for DMA transfer. |
| 1069 | * |
| 1070 | * Create VME DMA list attribute pointing to a location on the VME bus for DMA |
| 1071 | * transfers. It is the responsibility of the user to free used attributes |
| 1072 | * using vme_dma_free_attribute(). |
| 1073 | * |
| 1074 | * Return: Pointer to VME DMA attribute, NULL on failure. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1075 | */ |
| 1076 | struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1077 | u32 aspace, u32 cycle, u32 dwidth) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1078 | { |
| 1079 | struct vme_dma_attr *attributes; |
| 1080 | struct vme_dma_vme *vme_attr; |
| 1081 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1082 | attributes = kmalloc( |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1083 | sizeof(struct vme_dma_attr), GFP_KERNEL); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1084 | if (attributes == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1085 | printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1086 | goto err_attr; |
| 1087 | } |
| 1088 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1089 | vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); |
| 1090 | if (vme_attr == NULL) { |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1091 | printk(KERN_ERR "Unable to allocate memory for VME attributes\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1092 | goto err_vme; |
| 1093 | } |
| 1094 | |
| 1095 | attributes->type = VME_DMA_VME; |
| 1096 | attributes->private = (void *)vme_attr; |
| 1097 | |
| 1098 | vme_attr->address = address; |
| 1099 | vme_attr->aspace = aspace; |
| 1100 | vme_attr->cycle = cycle; |
| 1101 | vme_attr->dwidth = dwidth; |
| 1102 | |
| 1103 | return attributes; |
| 1104 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1105 | err_vme: |
| 1106 | kfree(attributes); |
| 1107 | err_attr: |
| 1108 | return NULL; |
| 1109 | } |
| 1110 | EXPORT_SYMBOL(vme_dma_vme_attribute); |
| 1111 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1112 | /** |
| 1113 | * vme_dma_free_attribute - Free DMA list attribute. |
| 1114 | * @attributes: Pointer to DMA list attribute. |
| 1115 | * |
| 1116 | * Free VME DMA list attribute. VME DMA list attributes can be safely freed |
| 1117 | * once vme_dma_list_add() has returned. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1118 | */ |
| 1119 | void vme_dma_free_attribute(struct vme_dma_attr *attributes) |
| 1120 | { |
| 1121 | kfree(attributes->private); |
| 1122 | kfree(attributes); |
| 1123 | } |
| 1124 | EXPORT_SYMBOL(vme_dma_free_attribute); |
| 1125 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1126 | /** |
| 1127 | * vme_dma_list_add - Add enty to a VME DMA list. |
| 1128 | * @list: Pointer to VME list. |
| 1129 | * @src: Pointer to DMA list attribute to use as source. |
| 1130 | * @dest: Pointer to DMA list attribute to use as destination. |
| 1131 | * @count: Number of bytes to transfer. |
| 1132 | * |
| 1133 | * Add an entry to the provided VME DMA list. Entry requires pointers to source |
| 1134 | * and destination DMA attributes and a count. |
| 1135 | * |
| 1136 | * Please note, the attributes supported as source and destinations for |
| 1137 | * transfers are hardware dependent. |
| 1138 | * |
| 1139 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 1140 | * device or if the link list has already been submitted for execution. |
| 1141 | * Hardware specific errors also possible. |
| 1142 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1143 | int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, |
| 1144 | struct vme_dma_attr *dest, size_t count) |
| 1145 | { |
| 1146 | struct vme_bridge *bridge = list->parent->parent; |
| 1147 | int retval; |
| 1148 | |
| 1149 | if (bridge->dma_list_add == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1150 | printk(KERN_WARNING "Link List DMA generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1151 | return -EINVAL; |
| 1152 | } |
| 1153 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1154 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1155 | printk(KERN_ERR "Link List already submitted\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | |
| 1159 | retval = bridge->dma_list_add(list, src, dest, count); |
| 1160 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1161 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1162 | |
| 1163 | return retval; |
| 1164 | } |
| 1165 | EXPORT_SYMBOL(vme_dma_list_add); |
| 1166 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1167 | /** |
| 1168 | * vme_dma_list_exec - Queue a VME DMA list for execution. |
| 1169 | * @list: Pointer to VME list. |
| 1170 | * |
| 1171 | * Queue the provided VME DMA list for execution. The call will return once the |
| 1172 | * list has been executed. |
| 1173 | * |
| 1174 | * Return: Zero on success, -EINVAL if operation is not supported on this |
| 1175 | * device. Hardware specific errors also possible. |
| 1176 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1177 | int vme_dma_list_exec(struct vme_dma_list *list) |
| 1178 | { |
| 1179 | struct vme_bridge *bridge = list->parent->parent; |
| 1180 | int retval; |
| 1181 | |
| 1182 | if (bridge->dma_list_exec == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1183 | printk(KERN_ERR "Link List DMA execution not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1184 | return -EINVAL; |
| 1185 | } |
| 1186 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1187 | mutex_lock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1188 | |
| 1189 | retval = bridge->dma_list_exec(list); |
| 1190 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1191 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1192 | |
| 1193 | return retval; |
| 1194 | } |
| 1195 | EXPORT_SYMBOL(vme_dma_list_exec); |
| 1196 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1197 | /** |
| 1198 | * vme_dma_list_free - Free a VME DMA list. |
| 1199 | * @list: Pointer to VME list. |
| 1200 | * |
| 1201 | * Free the provided DMA list and all its entries. |
| 1202 | * |
| 1203 | * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource |
| 1204 | * is still in use. Hardware specific errors also possible. |
| 1205 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1206 | int vme_dma_list_free(struct vme_dma_list *list) |
| 1207 | { |
| 1208 | struct vme_bridge *bridge = list->parent->parent; |
| 1209 | int retval; |
| 1210 | |
| 1211 | if (bridge->dma_list_empty == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1212 | printk(KERN_WARNING "Emptying of Link Lists not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1213 | return -EINVAL; |
| 1214 | } |
| 1215 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1216 | if (!mutex_trylock(&list->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1217 | printk(KERN_ERR "Link List in use\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1218 | return -EINVAL; |
| 1219 | } |
| 1220 | |
| 1221 | /* |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1222 | * Empty out all of the entries from the DMA list. We need to go to the |
| 1223 | * low level driver as DMA entries are driver specific. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1224 | */ |
| 1225 | retval = bridge->dma_list_empty(list); |
| 1226 | if (retval) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1227 | printk(KERN_ERR "Unable to empty link-list entries\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1228 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1229 | return retval; |
| 1230 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1231 | mutex_unlock(&list->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1232 | kfree(list); |
| 1233 | |
| 1234 | return retval; |
| 1235 | } |
| 1236 | EXPORT_SYMBOL(vme_dma_list_free); |
| 1237 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1238 | /** |
| 1239 | * vme_dma_free - Free a VME DMA resource. |
| 1240 | * @resource: Pointer to VME DMA resource. |
| 1241 | * |
| 1242 | * Free the provided DMA resource so that it may be reallocated. |
| 1243 | * |
| 1244 | * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource |
| 1245 | * is still active. |
| 1246 | */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1247 | int vme_dma_free(struct vme_resource *resource) |
| 1248 | { |
| 1249 | struct vme_dma_resource *ctrlr; |
| 1250 | |
| 1251 | if (resource->type != VME_DMA) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1252 | printk(KERN_ERR "Not a DMA resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1253 | return -EINVAL; |
| 1254 | } |
| 1255 | |
| 1256 | ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); |
| 1257 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1258 | if (!mutex_trylock(&ctrlr->mtx)) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1259 | printk(KERN_ERR "Resource busy, can't free\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1260 | return -EBUSY; |
| 1261 | } |
| 1262 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1263 | if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1264 | printk(KERN_WARNING "Resource still processing transfers\n"); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1265 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1266 | return -EBUSY; |
| 1267 | } |
| 1268 | |
| 1269 | ctrlr->locked = 0; |
| 1270 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1271 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1272 | |
Martyn Welch | fd5c256 | 2013-06-06 12:29:16 +0100 | [diff] [blame] | 1273 | kfree(resource); |
| 1274 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1275 | return 0; |
| 1276 | } |
| 1277 | EXPORT_SYMBOL(vme_dma_free); |
| 1278 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1279 | void vme_bus_error_handler(struct vme_bridge *bridge, |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 1280 | unsigned long long address, int am) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1281 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1282 | struct list_head *handler_pos = NULL; |
| 1283 | struct vme_error_handler *handler; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1284 | int handler_triggered = 0; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1285 | u32 aspace = vme_get_aspace(am); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1286 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1287 | list_for_each(handler_pos, &bridge->vme_error_handlers) { |
| 1288 | handler = list_entry(handler_pos, struct vme_error_handler, |
| 1289 | list); |
| 1290 | if ((aspace == handler->aspace) && |
| 1291 | (address >= handler->start) && |
| 1292 | (address < handler->end)) { |
| 1293 | if (!handler->num_errors) |
| 1294 | handler->first_error = address; |
| 1295 | if (handler->num_errors != UINT_MAX) |
| 1296 | handler->num_errors++; |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1297 | handler_triggered = 1; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1298 | } |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1299 | } |
Dmitry Kalinkin | 448535a | 2015-09-18 02:01:45 +0300 | [diff] [blame] | 1300 | |
| 1301 | if (!handler_triggered) |
| 1302 | dev_err(bridge->parent, |
| 1303 | "Unhandled VME access error at address 0x%llx\n", |
| 1304 | address); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1305 | } |
| 1306 | EXPORT_SYMBOL(vme_bus_error_handler); |
| 1307 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1308 | struct vme_error_handler *vme_register_error_handler( |
| 1309 | struct vme_bridge *bridge, u32 aspace, |
| 1310 | unsigned long long address, size_t len) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1311 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1312 | struct vme_error_handler *handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1313 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1314 | handler = kmalloc(sizeof(*handler), GFP_KERNEL); |
| 1315 | if (!handler) |
| 1316 | return NULL; |
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 | handler->aspace = aspace; |
| 1319 | handler->start = address; |
| 1320 | handler->end = address + len; |
| 1321 | handler->num_errors = 0; |
| 1322 | handler->first_error = 0; |
| 1323 | list_add_tail(&handler->list, &bridge->vme_error_handlers); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1324 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1325 | return handler; |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1326 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1327 | EXPORT_SYMBOL(vme_register_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1328 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1329 | void vme_unregister_error_handler(struct vme_error_handler *handler) |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1330 | { |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1331 | list_del(&handler->list); |
| 1332 | kfree(handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1333 | } |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1334 | EXPORT_SYMBOL(vme_unregister_error_handler); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 1335 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1336 | void vme_irq_handler(struct vme_bridge *bridge, int level, int statid) |
| 1337 | { |
| 1338 | void (*call)(int, int, void *); |
| 1339 | void *priv_data; |
| 1340 | |
| 1341 | call = bridge->irq[level - 1].callback[statid].func; |
| 1342 | priv_data = bridge->irq[level - 1].callback[statid].priv_data; |
| 1343 | |
| 1344 | if (call != NULL) |
| 1345 | call(level, statid, priv_data); |
| 1346 | else |
Aaron Sierra | f56c3d4 | 2016-04-21 11:18:22 -0500 | [diff] [blame] | 1347 | printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n", |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1348 | level, statid); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1349 | } |
| 1350 | EXPORT_SYMBOL(vme_irq_handler); |
| 1351 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1352 | /** |
| 1353 | * vme_irq_request - Request a specific VME interrupt. |
| 1354 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1355 | * @level: Interrupt priority being requested. |
| 1356 | * @statid: Interrupt vector being requested. |
| 1357 | * @callback: Pointer to callback function called when VME interrupt/vector |
| 1358 | * received. |
| 1359 | * @priv_data: Generic pointer that will be passed to the callback function. |
| 1360 | * |
| 1361 | * Request callback to be attached as a handler for VME interrupts with provided |
| 1362 | * level and statid. |
| 1363 | * |
| 1364 | * Return: Zero on success, -EINVAL on invalid vme device, level or if the |
| 1365 | * function is not supported, -EBUSY if the level/statid combination is |
| 1366 | * already in use. Hardware specific errors also possible. |
| 1367 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1368 | int vme_irq_request(struct vme_dev *vdev, int level, int statid, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1369 | void (*callback)(int, int, void *), |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1370 | void *priv_data) |
| 1371 | { |
| 1372 | struct vme_bridge *bridge; |
| 1373 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1374 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1375 | if (bridge == NULL) { |
| 1376 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1377 | return -EINVAL; |
| 1378 | } |
| 1379 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1380 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1381 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1382 | return -EINVAL; |
| 1383 | } |
| 1384 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1385 | if (bridge->irq_set == NULL) { |
| 1386 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1387 | return -EINVAL; |
| 1388 | } |
| 1389 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1390 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1391 | |
| 1392 | if (bridge->irq[level - 1].callback[statid].func) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1393 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1394 | printk(KERN_WARNING "VME Interrupt already taken\n"); |
| 1395 | return -EBUSY; |
| 1396 | } |
| 1397 | |
| 1398 | bridge->irq[level - 1].count++; |
| 1399 | bridge->irq[level - 1].callback[statid].priv_data = priv_data; |
| 1400 | bridge->irq[level - 1].callback[statid].func = callback; |
| 1401 | |
| 1402 | /* Enable IRQ level */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1403 | bridge->irq_set(bridge, level, 1, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1404 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1405 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1406 | |
| 1407 | return 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1408 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1409 | EXPORT_SYMBOL(vme_irq_request); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1410 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1411 | /** |
| 1412 | * vme_irq_free - Free a VME interrupt. |
| 1413 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1414 | * @level: Interrupt priority of interrupt being freed. |
| 1415 | * @statid: Interrupt vector of interrupt being freed. |
| 1416 | * |
| 1417 | * Remove previously attached callback from VME interrupt priority/vector. |
| 1418 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1419 | void vme_irq_free(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1420 | { |
| 1421 | struct vme_bridge *bridge; |
| 1422 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1423 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1424 | if (bridge == NULL) { |
| 1425 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1426 | return; |
| 1427 | } |
| 1428 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1429 | if ((level < 1) || (level > 7)) { |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1430 | printk(KERN_ERR "Invalid interrupt level\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1431 | return; |
| 1432 | } |
| 1433 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1434 | if (bridge->irq_set == NULL) { |
| 1435 | printk(KERN_ERR "Configuring interrupts not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1436 | return; |
| 1437 | } |
| 1438 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1439 | mutex_lock(&bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1440 | |
| 1441 | bridge->irq[level - 1].count--; |
| 1442 | |
| 1443 | /* Disable IRQ level if no more interrupts attached at this level*/ |
| 1444 | if (bridge->irq[level - 1].count == 0) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1445 | bridge->irq_set(bridge, level, 0, 1); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1446 | |
| 1447 | bridge->irq[level - 1].callback[statid].func = NULL; |
| 1448 | bridge->irq[level - 1].callback[statid].priv_data = NULL; |
| 1449 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1450 | mutex_unlock(&bridge->irq_mtx); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1451 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1452 | EXPORT_SYMBOL(vme_irq_free); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1453 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1454 | /** |
| 1455 | * vme_irq_generate - Generate VME interrupt. |
| 1456 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1457 | * @level: Interrupt priority at which to assert the interrupt. |
| 1458 | * @statid: Interrupt vector to associate with the interrupt. |
| 1459 | * |
| 1460 | * Generate a VME interrupt of the provided level and with the provided |
| 1461 | * statid. |
| 1462 | * |
| 1463 | * Return: Zero on success, -EINVAL on invalid vme device, level or if the |
| 1464 | * function is not supported. Hardware specific errors also possible. |
| 1465 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1466 | int vme_irq_generate(struct vme_dev *vdev, int level, int statid) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1467 | { |
| 1468 | struct vme_bridge *bridge; |
| 1469 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1470 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1471 | if (bridge == NULL) { |
| 1472 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1473 | return -EINVAL; |
| 1474 | } |
| 1475 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1476 | if ((level < 1) || (level > 7)) { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1477 | printk(KERN_WARNING "Invalid interrupt level\n"); |
| 1478 | return -EINVAL; |
| 1479 | } |
| 1480 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1481 | if (bridge->irq_generate == NULL) { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1482 | printk(KERN_WARNING "Interrupt generation not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1483 | return -EINVAL; |
| 1484 | } |
| 1485 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1486 | return bridge->irq_generate(bridge, level, statid); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1487 | } |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 1488 | EXPORT_SYMBOL(vme_irq_generate); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1489 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1490 | /** |
| 1491 | * vme_lm_request - Request a VME location monitor |
| 1492 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1493 | * |
| 1494 | * Allocate a location monitor resource to the driver. A location monitor |
| 1495 | * allows the driver to monitor accesses to a contiguous number of |
| 1496 | * addresses on the VME bus. |
| 1497 | * |
| 1498 | * Return: Pointer to a VME resource on success or NULL on failure. |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1499 | */ |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1500 | struct vme_resource *vme_lm_request(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1501 | { |
| 1502 | struct vme_bridge *bridge; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1503 | struct list_head *lm_pos = NULL; |
| 1504 | struct vme_lm_resource *allocated_lm = NULL; |
| 1505 | struct vme_lm_resource *lm = NULL; |
| 1506 | struct vme_resource *resource = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1507 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1508 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1509 | if (bridge == NULL) { |
| 1510 | printk(KERN_ERR "Can't find VME bus\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1511 | goto err_bus; |
| 1512 | } |
| 1513 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1514 | /* Loop through LM resources */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1515 | list_for_each(lm_pos, &bridge->lm_resources) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1516 | lm = list_entry(lm_pos, |
| 1517 | struct vme_lm_resource, list); |
| 1518 | |
| 1519 | if (lm == NULL) { |
Greg Kroah-Hartman | 25958ce | 2012-04-25 11:25:46 -0700 | [diff] [blame] | 1520 | printk(KERN_ERR "Registered NULL Location Monitor resource\n"); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1521 | continue; |
| 1522 | } |
| 1523 | |
| 1524 | /* Find an unlocked controller */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1525 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1526 | if (lm->locked == 0) { |
| 1527 | lm->locked = 1; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1528 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1529 | allocated_lm = lm; |
| 1530 | break; |
| 1531 | } |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1532 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /* Check to see if we found a resource */ |
| 1536 | if (allocated_lm == NULL) |
| 1537 | goto err_lm; |
| 1538 | |
| 1539 | resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); |
| 1540 | if (resource == NULL) { |
| 1541 | printk(KERN_ERR "Unable to allocate resource structure\n"); |
| 1542 | goto err_alloc; |
| 1543 | } |
| 1544 | resource->type = VME_LM; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1545 | resource->entry = &allocated_lm->list; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1546 | |
| 1547 | return resource; |
| 1548 | |
| 1549 | err_alloc: |
| 1550 | /* Unlock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1551 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1552 | lm->locked = 0; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1553 | mutex_unlock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1554 | err_lm: |
| 1555 | err_bus: |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | EXPORT_SYMBOL(vme_lm_request); |
| 1559 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1560 | /** |
| 1561 | * vme_lm_count - Determine number of VME Addresses monitored |
| 1562 | * @resource: Pointer to VME location monitor resource. |
| 1563 | * |
| 1564 | * The number of contiguous addresses monitored is hardware dependent. |
| 1565 | * Return the number of contiguous addresses monitored by the |
| 1566 | * location monitor. |
| 1567 | * |
| 1568 | * Return: Count of addresses monitored or -EINVAL when provided with an |
| 1569 | * invalid location monitor resource. |
| 1570 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1571 | int vme_lm_count(struct vme_resource *resource) |
| 1572 | { |
| 1573 | struct vme_lm_resource *lm; |
| 1574 | |
| 1575 | if (resource->type != VME_LM) { |
| 1576 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1577 | return -EINVAL; |
| 1578 | } |
| 1579 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1580 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1581 | |
| 1582 | return lm->monitors; |
| 1583 | } |
| 1584 | EXPORT_SYMBOL(vme_lm_count); |
| 1585 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1586 | /** |
| 1587 | * vme_lm_set - Configure location monitor |
| 1588 | * @resource: Pointer to VME location monitor resource. |
| 1589 | * @lm_base: Base address to monitor. |
| 1590 | * @aspace: VME address space to monitor. |
| 1591 | * @cycle: VME bus cycle type to monitor. |
| 1592 | * |
| 1593 | * Set the base address, address space and cycle type of accesses to be |
| 1594 | * monitored by the location monitor. |
| 1595 | * |
| 1596 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1597 | * monitor resource or function is not supported. Hardware specific |
| 1598 | * errors may also be returned. |
| 1599 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1600 | 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] | 1601 | u32 aspace, u32 cycle) |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1602 | { |
| 1603 | struct vme_bridge *bridge = find_bridge(resource); |
| 1604 | struct vme_lm_resource *lm; |
| 1605 | |
| 1606 | if (resource->type != VME_LM) { |
| 1607 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1608 | return -EINVAL; |
| 1609 | } |
| 1610 | |
| 1611 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1612 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1613 | if (bridge->lm_set == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1614 | printk(KERN_ERR "vme_lm_set not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1615 | return -EINVAL; |
| 1616 | } |
| 1617 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1618 | return bridge->lm_set(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1619 | } |
| 1620 | EXPORT_SYMBOL(vme_lm_set); |
| 1621 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1622 | /** |
| 1623 | * vme_lm_get - Retrieve location monitor settings |
| 1624 | * @resource: Pointer to VME location monitor resource. |
| 1625 | * @lm_base: Pointer used to output the base address monitored. |
| 1626 | * @aspace: Pointer used to output the address space monitored. |
| 1627 | * @cycle: Pointer used to output the VME bus cycle type monitored. |
| 1628 | * |
| 1629 | * Retrieve the base address, address space and cycle type of accesses to |
| 1630 | * be monitored by the location monitor. |
| 1631 | * |
| 1632 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1633 | * monitor resource or function is not supported. Hardware specific |
| 1634 | * errors may also be returned. |
| 1635 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1636 | 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] | 1637 | u32 *aspace, u32 *cycle) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1638 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1639 | struct vme_bridge *bridge = find_bridge(resource); |
| 1640 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1641 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1642 | if (resource->type != VME_LM) { |
| 1643 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1647 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1648 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1649 | if (bridge->lm_get == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1650 | printk(KERN_ERR "vme_lm_get not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1651 | return -EINVAL; |
| 1652 | } |
| 1653 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1654 | return bridge->lm_get(lm, lm_base, aspace, cycle); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1655 | } |
| 1656 | EXPORT_SYMBOL(vme_lm_get); |
| 1657 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1658 | /** |
| 1659 | * vme_lm_attach - Provide callback for location monitor address |
| 1660 | * @resource: Pointer to VME location monitor resource. |
| 1661 | * @monitor: Offset to which callback should be attached. |
| 1662 | * @callback: Pointer to callback function called when triggered. |
| 1663 | * @data: Generic pointer that will be passed to the callback function. |
| 1664 | * |
| 1665 | * Attach a callback to the specificed offset into the location monitors |
| 1666 | * monitored addresses. A generic pointer is provided to allow data to be |
| 1667 | * passed to the callback when called. |
| 1668 | * |
| 1669 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1670 | * monitor resource or function is not supported. Hardware specific |
| 1671 | * errors may also be returned. |
| 1672 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1673 | int vme_lm_attach(struct vme_resource *resource, int monitor, |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1674 | void (*callback)(void *), void *data) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1675 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1676 | struct vme_bridge *bridge = find_bridge(resource); |
| 1677 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1678 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1679 | if (resource->type != VME_LM) { |
| 1680 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1684 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1685 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1686 | if (bridge->lm_attach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1687 | printk(KERN_ERR "vme_lm_attach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1688 | return -EINVAL; |
| 1689 | } |
| 1690 | |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 1691 | return bridge->lm_attach(lm, monitor, callback, data); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1692 | } |
| 1693 | EXPORT_SYMBOL(vme_lm_attach); |
| 1694 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1695 | /** |
| 1696 | * vme_lm_detach - Remove callback for location monitor address |
| 1697 | * @resource: Pointer to VME location monitor resource. |
| 1698 | * @monitor: Offset to which callback should be removed. |
| 1699 | * |
| 1700 | * Remove the callback associated with the specificed offset into the |
| 1701 | * location monitors monitored addresses. |
| 1702 | * |
| 1703 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1704 | * monitor resource or function is not supported. Hardware specific |
| 1705 | * errors may also be returned. |
| 1706 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1707 | int vme_lm_detach(struct vme_resource *resource, int monitor) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1708 | { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1709 | struct vme_bridge *bridge = find_bridge(resource); |
| 1710 | struct vme_lm_resource *lm; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1711 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1712 | if (resource->type != VME_LM) { |
| 1713 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1714 | return -EINVAL; |
| 1715 | } |
| 1716 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1717 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1718 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1719 | if (bridge->lm_detach == NULL) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1720 | printk(KERN_ERR "vme_lm_detach not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1721 | return -EINVAL; |
| 1722 | } |
| 1723 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1724 | return bridge->lm_detach(lm, monitor); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1725 | } |
| 1726 | EXPORT_SYMBOL(vme_lm_detach); |
| 1727 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1728 | /** |
| 1729 | * vme_lm_free - Free allocated VME location monitor |
| 1730 | * @resource: Pointer to VME location monitor resource. |
| 1731 | * |
| 1732 | * Free allocation of a VME location monitor. |
| 1733 | * |
| 1734 | * WARNING: This function currently expects that any callbacks that have |
| 1735 | * been attached to the location monitor have been removed. |
| 1736 | * |
| 1737 | * Return: Zero on success, -EINVAL when provided with an invalid location |
| 1738 | * monitor resource. |
| 1739 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1740 | void vme_lm_free(struct vme_resource *resource) |
| 1741 | { |
| 1742 | struct vme_lm_resource *lm; |
| 1743 | |
| 1744 | if (resource->type != VME_LM) { |
| 1745 | printk(KERN_ERR "Not a Location Monitor resource\n"); |
| 1746 | return; |
| 1747 | } |
| 1748 | |
| 1749 | lm = list_entry(resource->entry, struct vme_lm_resource, list); |
| 1750 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1751 | mutex_lock(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1752 | |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1753 | /* XXX |
| 1754 | * Check to see that there aren't any callbacks still attached, if |
| 1755 | * there are we should probably be detaching them! |
| 1756 | */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1757 | |
| 1758 | lm->locked = 0; |
| 1759 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1760 | mutex_unlock(&lm->mtx); |
Martyn Welch | 8be9226 | 2009-10-29 16:35:08 +0000 | [diff] [blame] | 1761 | |
| 1762 | kfree(resource); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1763 | } |
| 1764 | EXPORT_SYMBOL(vme_lm_free); |
| 1765 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1766 | /** |
| 1767 | * vme_slot_num - Retrieve slot ID |
| 1768 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1769 | * |
| 1770 | * Retrieve the slot ID associated with the provided VME device. |
| 1771 | * |
| 1772 | * Return: The slot ID on success, -EINVAL if VME bridge cannot be determined |
| 1773 | * or the function is not supported. Hardware specific errors may also |
| 1774 | * be returned. |
| 1775 | */ |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1776 | int vme_slot_num(struct vme_dev *vdev) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1777 | { |
| 1778 | struct vme_bridge *bridge; |
| 1779 | |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 1780 | bridge = vdev->bridge; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1781 | if (bridge == NULL) { |
| 1782 | printk(KERN_ERR "Can't find VME bus\n"); |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
| 1786 | if (bridge->slot_get == NULL) { |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1787 | printk(KERN_WARNING "vme_slot_num not supported\n"); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1788 | return -EINVAL; |
| 1789 | } |
| 1790 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1791 | return bridge->slot_get(bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1792 | } |
Martyn Welch | d7729f0 | 2013-11-08 11:58:35 +0000 | [diff] [blame] | 1793 | EXPORT_SYMBOL(vme_slot_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1794 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1795 | /** |
| 1796 | * vme_bus_num - Retrieve bus number |
| 1797 | * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. |
| 1798 | * |
| 1799 | * Retrieve the bus enumeration associated with the provided VME device. |
| 1800 | * |
| 1801 | * Return: The bus number on success, -EINVAL if VME bridge cannot be |
| 1802 | * determined. |
| 1803 | */ |
Martyn Welch | 978f47d | 2013-11-08 11:58:34 +0000 | [diff] [blame] | 1804 | int vme_bus_num(struct vme_dev *vdev) |
| 1805 | { |
| 1806 | struct vme_bridge *bridge; |
| 1807 | |
| 1808 | bridge = vdev->bridge; |
| 1809 | if (bridge == NULL) { |
| 1810 | pr_err("Can't find VME bus\n"); |
| 1811 | return -EINVAL; |
| 1812 | } |
| 1813 | |
| 1814 | return bridge->num; |
| 1815 | } |
| 1816 | EXPORT_SYMBOL(vme_bus_num); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1817 | |
| 1818 | /* - Bridge Registration --------------------------------------------------- */ |
| 1819 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1820 | static void vme_dev_release(struct device *dev) |
| 1821 | { |
| 1822 | kfree(dev_to_vme_dev(dev)); |
| 1823 | } |
| 1824 | |
Aaron Sierra | 326071b | 2016-04-24 15:11:38 -0500 | [diff] [blame] | 1825 | /* Common bridge initialization */ |
| 1826 | struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge) |
| 1827 | { |
| 1828 | INIT_LIST_HEAD(&bridge->vme_error_handlers); |
| 1829 | INIT_LIST_HEAD(&bridge->master_resources); |
| 1830 | INIT_LIST_HEAD(&bridge->slave_resources); |
| 1831 | INIT_LIST_HEAD(&bridge->dma_resources); |
| 1832 | INIT_LIST_HEAD(&bridge->lm_resources); |
| 1833 | mutex_init(&bridge->irq_mtx); |
| 1834 | |
| 1835 | return bridge; |
| 1836 | } |
| 1837 | EXPORT_SYMBOL(vme_init_bridge); |
| 1838 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1839 | int vme_register_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1840 | { |
| 1841 | int i; |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1842 | int ret = -1; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1843 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1844 | mutex_lock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1845 | for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) { |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1846 | if ((vme_bus_numbers & (1 << i)) == 0) { |
| 1847 | vme_bus_numbers |= (1 << i); |
| 1848 | bridge->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1849 | INIT_LIST_HEAD(&bridge->devices); |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1850 | list_add_tail(&bridge->bus_list, &vme_bus_list); |
| 1851 | ret = 0; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1852 | break; |
| 1853 | } |
| 1854 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1855 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1856 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1857 | return ret; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1858 | } |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1859 | EXPORT_SYMBOL(vme_register_bridge); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1860 | |
Manohar Vanga | 5b93c2a | 2011-11-04 11:12:30 +0100 | [diff] [blame] | 1861 | void vme_unregister_bridge(struct vme_bridge *bridge) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1862 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1863 | struct vme_dev *vdev; |
| 1864 | struct vme_dev *tmp; |
| 1865 | |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1866 | mutex_lock(&vme_buses_lock); |
| 1867 | vme_bus_numbers &= ~(1 << bridge->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1868 | list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) { |
| 1869 | list_del(&vdev->drv_list); |
| 1870 | list_del(&vdev->bridge_list); |
| 1871 | device_unregister(&vdev->dev); |
| 1872 | } |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 1873 | list_del(&bridge->bus_list); |
| 1874 | mutex_unlock(&vme_buses_lock); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1875 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1876 | EXPORT_SYMBOL(vme_unregister_bridge); |
| 1877 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1878 | /* - Driver Registration --------------------------------------------------- */ |
| 1879 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1880 | static int __vme_register_driver_bus(struct vme_driver *drv, |
| 1881 | struct vme_bridge *bridge, unsigned int ndevs) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1882 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1883 | int err; |
| 1884 | unsigned int i; |
| 1885 | struct vme_dev *vdev; |
| 1886 | struct vme_dev *tmp; |
| 1887 | |
| 1888 | for (i = 0; i < ndevs; i++) { |
| 1889 | vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL); |
| 1890 | if (!vdev) { |
| 1891 | err = -ENOMEM; |
| 1892 | goto err_devalloc; |
| 1893 | } |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1894 | vdev->num = i; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1895 | vdev->bridge = bridge; |
| 1896 | vdev->dev.platform_data = drv; |
| 1897 | vdev->dev.release = vme_dev_release; |
| 1898 | vdev->dev.parent = bridge->parent; |
| 1899 | vdev->dev.bus = &vme_bus_type; |
Manohar Vanga | a916a39 | 2011-09-26 11:27:17 +0200 | [diff] [blame] | 1900 | dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num, |
| 1901 | vdev->num); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1902 | |
| 1903 | err = device_register(&vdev->dev); |
| 1904 | if (err) |
| 1905 | goto err_reg; |
| 1906 | |
| 1907 | if (vdev->dev.platform_data) { |
| 1908 | list_add_tail(&vdev->drv_list, &drv->devices); |
| 1909 | list_add_tail(&vdev->bridge_list, &bridge->devices); |
| 1910 | } else |
| 1911 | device_unregister(&vdev->dev); |
| 1912 | } |
| 1913 | return 0; |
| 1914 | |
| 1915 | err_reg: |
Emilio G. Cota | def1820 | 2013-02-13 13:47:54 -0500 | [diff] [blame] | 1916 | put_device(&vdev->dev); |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1917 | kfree(vdev); |
| 1918 | err_devalloc: |
| 1919 | list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) { |
| 1920 | list_del(&vdev->drv_list); |
| 1921 | list_del(&vdev->bridge_list); |
| 1922 | device_unregister(&vdev->dev); |
| 1923 | } |
| 1924 | return err; |
| 1925 | } |
| 1926 | |
| 1927 | static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1928 | { |
| 1929 | struct vme_bridge *bridge; |
| 1930 | int err = 0; |
| 1931 | |
| 1932 | mutex_lock(&vme_buses_lock); |
| 1933 | list_for_each_entry(bridge, &vme_bus_list, bus_list) { |
| 1934 | /* |
| 1935 | * This cannot cause trouble as we already have vme_buses_lock |
| 1936 | * and if the bridge is removed, it will have to go through |
| 1937 | * vme_unregister_bridge() to do it (which calls remove() on |
| 1938 | * the bridge which in turn tries to acquire vme_buses_lock and |
Manohar Vanga | c26f611 | 2011-11-04 11:12:29 +0100 | [diff] [blame] | 1939 | * will have to wait). |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1940 | */ |
| 1941 | err = __vme_register_driver_bus(drv, bridge, ndevs); |
| 1942 | if (err) |
| 1943 | break; |
| 1944 | } |
| 1945 | mutex_unlock(&vme_buses_lock); |
| 1946 | return err; |
| 1947 | } |
| 1948 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1949 | /** |
| 1950 | * vme_register_driver - Register a VME driver |
| 1951 | * @drv: Pointer to VME driver structure to register. |
| 1952 | * @ndevs: Maximum number of devices to allow to be enumerated. |
| 1953 | * |
| 1954 | * Register a VME device driver with the VME subsystem. |
| 1955 | * |
| 1956 | * Return: Zero on success, error value on registration failure. |
| 1957 | */ |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1958 | int vme_register_driver(struct vme_driver *drv, unsigned int ndevs) |
| 1959 | { |
| 1960 | int err; |
| 1961 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1962 | drv->driver.name = drv->name; |
| 1963 | drv->driver.bus = &vme_bus_type; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1964 | INIT_LIST_HEAD(&drv->devices); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1965 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1966 | err = driver_register(&drv->driver); |
| 1967 | if (err) |
| 1968 | return err; |
| 1969 | |
| 1970 | err = __vme_register_driver(drv, ndevs); |
| 1971 | if (err) |
| 1972 | driver_unregister(&drv->driver); |
| 1973 | |
| 1974 | return err; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1975 | } |
| 1976 | EXPORT_SYMBOL(vme_register_driver); |
| 1977 | |
Martyn Welch | b5bc980 | 2017-03-04 00:34:29 +0000 | [diff] [blame] | 1978 | /** |
| 1979 | * vme_unregister_driver - Unregister a VME driver |
| 1980 | * @drv: Pointer to VME driver structure to unregister. |
| 1981 | * |
| 1982 | * Unregister a VME device driver from the VME subsystem. |
| 1983 | */ |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 1984 | void vme_unregister_driver(struct vme_driver *drv) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1985 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 1986 | struct vme_dev *dev, *dev_tmp; |
| 1987 | |
| 1988 | mutex_lock(&vme_buses_lock); |
| 1989 | list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) { |
| 1990 | list_del(&dev->drv_list); |
| 1991 | list_del(&dev->bridge_list); |
| 1992 | device_unregister(&dev->dev); |
| 1993 | } |
| 1994 | mutex_unlock(&vme_buses_lock); |
| 1995 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1996 | driver_unregister(&drv->driver); |
| 1997 | } |
| 1998 | EXPORT_SYMBOL(vme_unregister_driver); |
| 1999 | |
| 2000 | /* - Bus Registration ------------------------------------------------------ */ |
| 2001 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2002 | static int vme_bus_match(struct device *dev, struct device_driver *drv) |
| 2003 | { |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2004 | struct vme_driver *vme_drv; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2005 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2006 | vme_drv = container_of(drv, struct vme_driver, driver); |
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 | if (dev->platform_data == vme_drv) { |
| 2009 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2010 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2011 | if (vme_drv->match && vme_drv->match(vdev)) |
| 2012 | return 1; |
| 2013 | |
| 2014 | dev->platform_data = NULL; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2015 | } |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2016 | return 0; |
| 2017 | } |
| 2018 | |
| 2019 | static int vme_bus_probe(struct device *dev) |
| 2020 | { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2021 | int retval = -ENODEV; |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2022 | struct vme_driver *driver; |
| 2023 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2024 | |
Manohar Vanga | 5d6abf3 | 2011-09-26 11:27:16 +0200 | [diff] [blame] | 2025 | driver = dev->platform_data; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2026 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 2027 | if (driver->probe != NULL) |
Manohar Vanga | 8f966dc | 2011-09-26 11:27:15 +0200 | [diff] [blame] | 2028 | retval = driver->probe(vdev); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2029 | |
| 2030 | return retval; |
| 2031 | } |
| 2032 | |
Stefano Babic | 9797484 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 2033 | static int vme_bus_remove(struct device *dev) |
| 2034 | { |
| 2035 | int retval = -ENODEV; |
| 2036 | struct vme_driver *driver; |
| 2037 | struct vme_dev *vdev = dev_to_vme_dev(dev); |
| 2038 | |
| 2039 | driver = dev->platform_data; |
| 2040 | |
| 2041 | if (driver->remove != NULL) |
| 2042 | retval = driver->remove(vdev); |
| 2043 | |
| 2044 | return retval; |
| 2045 | } |
| 2046 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2047 | struct bus_type vme_bus_type = { |
| 2048 | .name = "vme", |
| 2049 | .match = vme_bus_match, |
| 2050 | .probe = vme_bus_probe, |
Stefano Babic | 9797484 | 2017-01-20 10:38:20 -0500 | [diff] [blame] | 2051 | .remove = vme_bus_remove, |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2052 | }; |
| 2053 | EXPORT_SYMBOL(vme_bus_type); |
| 2054 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 2055 | static int __init vme_init(void) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2056 | { |
| 2057 | return bus_register(&vme_bus_type); |
| 2058 | } |
Aaron Sierra | c326cc0 | 2013-12-09 09:54:42 -0600 | [diff] [blame] | 2059 | subsys_initcall(vme_init); |