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