2019-05-27 13:55:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-07-31 15:28:17 +07:00
|
|
|
/*
|
|
|
|
* VME Bridge Framework
|
|
|
|
*
|
2010-02-18 22:12:52 +07:00
|
|
|
* Author: Martyn Welch <martyn.welch@ge.com>
|
|
|
|
* Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
|
2009-07-31 15:28:17 +07:00
|
|
|
*
|
|
|
|
* Based on work by Tom Armistead and Ajit Prem
|
|
|
|
* Copyright 2004 Motorola Inc.
|
|
|
|
*/
|
|
|
|
|
2016-07-04 01:05:56 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/export.h>
|
2009-07-31 15:28:17 +07:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/syscalls.h>
|
2009-08-11 22:20:22 +07:00
|
|
|
#include <linux/mutex.h>
|
2009-07-31 15:28:17 +07:00
|
|
|
#include <linux/spinlock.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2012-04-27 02:34:58 +07:00
|
|
|
#include <linux/vme.h>
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
#include "vme_bridge.h"
|
|
|
|
|
2011-08-12 17:30:48 +07:00
|
|
|
/* Bitmask and list of registered buses both protected by common mutex */
|
2009-07-31 15:28:17 +07:00
|
|
|
static unsigned int vme_bus_numbers;
|
2011-08-12 17:30:48 +07:00
|
|
|
static LIST_HEAD(vme_bus_list);
|
|
|
|
static DEFINE_MUTEX(vme_buses_lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
static int __init vme_init(void);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
static struct vme_dev *dev_to_vme_dev(struct device *dev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2011-09-26 16:27:15 +07:00
|
|
|
return container_of(dev, struct vme_dev, dev);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the bridge that the resource is associated with.
|
|
|
|
*/
|
|
|
|
static struct vme_bridge *find_bridge(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
/* Get list to search */
|
|
|
|
switch (resource->type) {
|
|
|
|
case VME_MASTER:
|
|
|
|
return list_entry(resource->entry, struct vme_master_resource,
|
|
|
|
list)->parent;
|
|
|
|
break;
|
|
|
|
case VME_SLAVE:
|
|
|
|
return list_entry(resource->entry, struct vme_slave_resource,
|
|
|
|
list)->parent;
|
|
|
|
break;
|
|
|
|
case VME_DMA:
|
|
|
|
return list_entry(resource->entry, struct vme_dma_resource,
|
|
|
|
list)->parent;
|
|
|
|
break;
|
2009-08-11 23:44:56 +07:00
|
|
|
case VME_LM:
|
|
|
|
return list_entry(resource->entry, struct vme_lm_resource,
|
|
|
|
list)->parent;
|
|
|
|
break;
|
2009-07-31 15:28:17 +07:00
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Unknown resource type\n");
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_free_consistent - Allocate contiguous memory.
|
|
|
|
* @resource: Pointer to VME resource.
|
|
|
|
* @size: Size of allocation required.
|
|
|
|
* @dma: Pointer to variable to store physical address of allocation.
|
|
|
|
*
|
2009-07-31 15:28:17 +07:00
|
|
|
* Allocate a contiguous block of memory for use by the driver. This is used to
|
|
|
|
* create the buffers for the slave windows.
|
2017-03-04 07:34:29 +07:00
|
|
|
*
|
|
|
|
* Return: Virtual address of allocation on success, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
|
2009-07-31 15:28:17 +07:00
|
|
|
dma_addr_t *dma)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!resource) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "No resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge = find_bridge(resource);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Can't find bridge\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->parent) {
|
2012-04-26 01:25:46 +07:00
|
|
|
printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
|
2011-08-10 16:33:46 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->alloc_consistent) {
|
2012-04-26 01:25:46 +07:00
|
|
|
printk(KERN_ERR "alloc_consistent not supported by bridge %s\n",
|
|
|
|
bridge->name);
|
2009-07-31 15:28:17 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-10 16:33:46 +07:00
|
|
|
return bridge->alloc_consistent(bridge->parent, size, dma);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_alloc_consistent);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_free_consistent - Free previously allocated memory.
|
|
|
|
* @resource: Pointer to VME resource.
|
|
|
|
* @size: Size of allocation to free.
|
|
|
|
* @vaddr: Virtual address of allocation.
|
|
|
|
* @dma: Physical address of allocation.
|
|
|
|
*
|
|
|
|
* Free previously allocated block of contiguous memory.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
void vme_free_consistent(struct vme_resource *resource, size_t size,
|
|
|
|
void *vaddr, dma_addr_t dma)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!resource) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "No resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge = find_bridge(resource);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Can't find bridge\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->parent) {
|
2012-04-26 01:25:46 +07:00
|
|
|
printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
|
2011-08-10 16:33:46 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->free_consistent) {
|
2012-04-26 01:25:46 +07:00
|
|
|
printk(KERN_ERR "free_consistent not supported by bridge %s\n",
|
|
|
|
bridge->name);
|
2011-08-10 16:33:46 +07:00
|
|
|
return;
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-08-10 16:33:46 +07:00
|
|
|
bridge->free_consistent(bridge->parent, size, vaddr, dma);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_free_consistent);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_get_size - Helper function returning size of a VME window
|
|
|
|
* @resource: Pointer to VME slave or master resource.
|
|
|
|
*
|
|
|
|
* Determine the size of the VME window provided. This is a helper
|
|
|
|
* function, wrappering the call to vme_master_get or vme_slave_get
|
|
|
|
* depending on the type of window resource handed to it.
|
|
|
|
*
|
|
|
|
* Return: Size of the window on success, zero on failure.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
size_t vme_get_size(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
int enabled, retval;
|
|
|
|
unsigned long long base, size;
|
|
|
|
dma_addr_t buf_base;
|
2011-12-02 00:06:29 +07:00
|
|
|
u32 aspace, cycle, dwidth;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
switch (resource->type) {
|
|
|
|
case VME_MASTER:
|
|
|
|
retval = vme_master_get(resource, &enabled, &base, &size,
|
|
|
|
&aspace, &cycle, &dwidth);
|
2016-10-21 23:36:19 +07:00
|
|
|
if (retval)
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return size;
|
|
|
|
break;
|
|
|
|
case VME_SLAVE:
|
|
|
|
retval = vme_slave_get(resource, &enabled, &base, &size,
|
|
|
|
&buf_base, &aspace, &cycle);
|
2016-10-21 23:36:19 +07:00
|
|
|
if (retval)
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return size;
|
|
|
|
break;
|
|
|
|
case VME_DMA:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Unknown resource type\n");
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_get_size);
|
|
|
|
|
2015-05-28 19:07:04 +07:00
|
|
|
int vme_check_window(u32 aspace, unsigned long long vme_base,
|
|
|
|
unsigned long long size)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
2017-09-30 18:27:41 +07:00
|
|
|
if (vme_base + size < size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
switch (aspace) {
|
|
|
|
case VME_A16:
|
2017-09-30 18:27:41 +07:00
|
|
|
if (vme_base + size > VME_A16_MAX)
|
2009-07-31 15:28:17 +07:00
|
|
|
retval = -EFAULT;
|
|
|
|
break;
|
|
|
|
case VME_A24:
|
2017-09-30 18:27:41 +07:00
|
|
|
if (vme_base + size > VME_A24_MAX)
|
2009-07-31 15:28:17 +07:00
|
|
|
retval = -EFAULT;
|
|
|
|
break;
|
|
|
|
case VME_A32:
|
2017-09-30 18:27:41 +07:00
|
|
|
if (vme_base + size > VME_A32_MAX)
|
2009-07-31 15:28:17 +07:00
|
|
|
retval = -EFAULT;
|
|
|
|
break;
|
|
|
|
case VME_A64:
|
2017-09-30 18:27:41 +07:00
|
|
|
/* The VME_A64_MAX limit is actually U64_MAX + 1 */
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
case VME_CRCSR:
|
2017-09-30 18:27:41 +07:00
|
|
|
if (vme_base + size > VME_CRCSR_MAX)
|
2009-07-31 15:28:17 +07:00
|
|
|
retval = -EFAULT;
|
|
|
|
break;
|
|
|
|
case VME_USER1:
|
|
|
|
case VME_USER2:
|
|
|
|
case VME_USER3:
|
|
|
|
case VME_USER4:
|
|
|
|
/* User Defined */
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Invalid address space\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2015-05-28 19:07:04 +07:00
|
|
|
EXPORT_SYMBOL(vme_check_window);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2015-09-18 06:01:43 +07:00
|
|
|
static u32 vme_get_aspace(int am)
|
|
|
|
{
|
|
|
|
switch (am) {
|
|
|
|
case 0x29:
|
|
|
|
case 0x2D:
|
|
|
|
return VME_A16;
|
|
|
|
case 0x38:
|
|
|
|
case 0x39:
|
|
|
|
case 0x3A:
|
|
|
|
case 0x3B:
|
|
|
|
case 0x3C:
|
|
|
|
case 0x3D:
|
|
|
|
case 0x3E:
|
|
|
|
case 0x3F:
|
|
|
|
return VME_A24;
|
|
|
|
case 0x8:
|
|
|
|
case 0x9:
|
|
|
|
case 0xA:
|
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
|
|
|
case 0xE:
|
|
|
|
case 0xF:
|
|
|
|
return VME_A32;
|
|
|
|
case 0x0:
|
|
|
|
case 0x1:
|
|
|
|
case 0x3:
|
|
|
|
return VME_A64;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_slave_request - Request a VME slave window resource.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @address: Required VME address space.
|
|
|
|
* @cycle: Required VME data transfer cycle type.
|
|
|
|
*
|
|
|
|
* Request use of a VME window resource capable of being set for the requested
|
|
|
|
* address space and data transfer cycle.
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME resource on success, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2011-12-02 00:06:29 +07:00
|
|
|
struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address,
|
|
|
|
u32 cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
struct list_head *slave_pos = NULL;
|
|
|
|
struct vme_slave_resource *allocated_image = NULL;
|
|
|
|
struct vme_slave_resource *slave_image = NULL;
|
|
|
|
struct vme_resource *resource = NULL;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
goto err_bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop through slave resources */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_for_each(slave_pos, &bridge->slave_resources) {
|
2009-07-31 15:28:17 +07:00
|
|
|
slave_image = list_entry(slave_pos,
|
|
|
|
struct vme_slave_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!slave_image) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Registered NULL Slave resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find an unlocked and compatible image */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&slave_image->mtx);
|
2009-12-15 15:43:02 +07:00
|
|
|
if (((slave_image->address_attr & address) == address) &&
|
2009-07-31 15:28:17 +07:00
|
|
|
((slave_image->cycle_attr & cycle) == cycle) &&
|
|
|
|
(slave_image->locked == 0)) {
|
|
|
|
|
|
|
|
slave_image->locked = 1;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
allocated_image = slave_image;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No free image */
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!allocated_image)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_image;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
resource = kmalloc(sizeof(*resource), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!resource)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_alloc;
|
2017-08-25 02:38:20 +07:00
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
resource->type = VME_SLAVE;
|
2010-11-12 18:14:07 +07:00
|
|
|
resource->entry = &allocated_image->list;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
slave_image->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
err_image:
|
|
|
|
err_bus:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_slave_request);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_slave_set - Set VME slave window configuration.
|
|
|
|
* @resource: Pointer to VME slave resource.
|
|
|
|
* @enabled: State to which the window should be configured.
|
|
|
|
* @vme_base: Base address for the window.
|
|
|
|
* @size: Size of the VME window.
|
|
|
|
* @buf_base: Based address of buffer used to provide VME slave window storage.
|
|
|
|
* @aspace: VME address space for the VME window.
|
|
|
|
* @cycle: VME data transfer cycle type for the VME window.
|
|
|
|
*
|
|
|
|
* Set configuration for provided VME slave window.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device, if an invalid resource has been provided or invalid
|
|
|
|
* attributes are provided. Hardware specific errors may also be
|
|
|
|
* returned.
|
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
int vme_slave_set(struct vme_resource *resource, int enabled,
|
2009-07-31 15:28:17 +07:00
|
|
|
unsigned long long vme_base, unsigned long long size,
|
2011-12-02 00:06:29 +07:00
|
|
|
dma_addr_t buf_base, u32 aspace, u32 cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_slave_resource *image;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (resource->type != VME_SLAVE) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a slave resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_slave_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->slave_set) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Function not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
if (!(((image->address_attr & aspace) == aspace) &&
|
2009-07-31 15:28:17 +07:00
|
|
|
((image->cycle_attr & cycle) == cycle))) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Invalid attributes\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = vme_check_window(aspace, vme_base, size);
|
2009-12-15 15:43:02 +07:00
|
|
|
if (retval)
|
2009-07-31 15:28:17 +07:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
return bridge->slave_set(image, enabled, vme_base, size, buf_base,
|
|
|
|
aspace, cycle);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_slave_set);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_slave_get - Retrieve VME slave window configuration.
|
|
|
|
* @resource: Pointer to VME slave resource.
|
|
|
|
* @enabled: Pointer to variable for storing state.
|
|
|
|
* @vme_base: Pointer to variable for storing window base address.
|
|
|
|
* @size: Pointer to variable for storing window size.
|
|
|
|
* @buf_base: Pointer to variable for storing slave buffer base address.
|
|
|
|
* @aspace: Pointer to variable for storing VME address space.
|
|
|
|
* @cycle: Pointer to variable for storing VME data transfer cycle type.
|
|
|
|
*
|
|
|
|
* Return configuration for provided VME slave window.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device or if an invalid resource has been provided.
|
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
int vme_slave_get(struct vme_resource *resource, int *enabled,
|
2009-07-31 15:28:17 +07:00
|
|
|
unsigned long long *vme_base, unsigned long long *size,
|
2011-12-02 00:06:29 +07:00
|
|
|
dma_addr_t *buf_base, u32 *aspace, u32 *cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_slave_resource *image;
|
|
|
|
|
|
|
|
if (resource->type != VME_SLAVE) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a slave resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_slave_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->slave_get) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "vme_slave_get not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bridge->slave_get(image, enabled, vme_base, size, buf_base,
|
|
|
|
aspace, cycle);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_slave_get);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_slave_free - Free VME slave window
|
|
|
|
* @resource: Pointer to VME slave resource.
|
|
|
|
*
|
|
|
|
* Free the provided slave resource so that it may be reallocated.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
void vme_slave_free(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_slave_resource *slave_image;
|
|
|
|
|
|
|
|
if (resource->type != VME_SLAVE) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a slave resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
slave_image = list_entry(resource->entry, struct vme_slave_resource,
|
|
|
|
list);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!slave_image) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Can't find slave resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
if (slave_image->locked == 0)
|
|
|
|
printk(KERN_ERR "Image is already free\n");
|
|
|
|
|
|
|
|
slave_image->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&slave_image->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
/* Free up resource memory */
|
|
|
|
kfree(resource);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_slave_free);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_request - Request a VME master window resource.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @address: Required VME address space.
|
|
|
|
* @cycle: Required VME data transfer cycle type.
|
|
|
|
* @dwidth: Required VME data transfer width.
|
|
|
|
*
|
|
|
|
* Request use of a VME window resource capable of being set for the requested
|
|
|
|
* address space, data transfer cycle and width.
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME resource on success, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2011-12-02 00:06:29 +07:00
|
|
|
struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address,
|
|
|
|
u32 cycle, u32 dwidth)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
struct list_head *master_pos = NULL;
|
|
|
|
struct vme_master_resource *allocated_image = NULL;
|
|
|
|
struct vme_master_resource *master_image = NULL;
|
|
|
|
struct vme_resource *resource = NULL;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
goto err_bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop through master resources */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_for_each(master_pos, &bridge->master_resources) {
|
2009-07-31 15:28:17 +07:00
|
|
|
master_image = list_entry(master_pos,
|
|
|
|
struct vme_master_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!master_image) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_WARNING "Registered NULL master resource\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find an unlocked and compatible image */
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&master_image->lock);
|
2009-12-15 15:43:02 +07:00
|
|
|
if (((master_image->address_attr & address) == address) &&
|
2009-07-31 15:28:17 +07:00
|
|
|
((master_image->cycle_attr & cycle) == cycle) &&
|
|
|
|
((master_image->width_attr & dwidth) == dwidth) &&
|
|
|
|
(master_image->locked == 0)) {
|
|
|
|
|
|
|
|
master_image->locked = 1;
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
allocated_image = master_image;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if we found a resource */
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!allocated_image) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find a suitable resource\n");
|
|
|
|
goto err_image;
|
|
|
|
}
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
resource = kmalloc(sizeof(*resource), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!resource)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_alloc;
|
2017-08-25 02:38:20 +07:00
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
resource->type = VME_MASTER;
|
2010-11-12 18:14:07 +07:00
|
|
|
resource->entry = &allocated_image->list;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
master_image->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
err_image:
|
|
|
|
err_bus:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_request);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_set - Set VME master window configuration.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @enabled: State to which the window should be configured.
|
|
|
|
* @vme_base: Base address for the window.
|
|
|
|
* @size: Size of the VME window.
|
|
|
|
* @aspace: VME address space for the VME window.
|
|
|
|
* @cycle: VME data transfer cycle type for the VME window.
|
|
|
|
* @dwidth: VME data transfer width for the VME window.
|
|
|
|
*
|
|
|
|
* Set configuration for provided VME master window.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device, if an invalid resource has been provided or invalid
|
|
|
|
* attributes are provided. Hardware specific errors may also be
|
|
|
|
* returned.
|
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
int vme_master_set(struct vme_resource *resource, int enabled,
|
2011-12-02 00:06:29 +07:00
|
|
|
unsigned long long vme_base, unsigned long long size, u32 aspace,
|
|
|
|
u32 cycle, u32 dwidth)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->master_set) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "vme_master_set not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
if (!(((image->address_attr & aspace) == aspace) &&
|
2009-07-31 15:28:17 +07:00
|
|
|
((image->cycle_attr & cycle) == cycle) &&
|
|
|
|
((image->width_attr & dwidth) == dwidth))) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Invalid attributes\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = vme_check_window(aspace, vme_base, size);
|
2009-12-15 15:43:02 +07:00
|
|
|
if (retval)
|
2009-07-31 15:28:17 +07:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
return bridge->master_set(image, enabled, vme_base, size, aspace,
|
|
|
|
cycle, dwidth);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_set);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_get - Retrieve VME master window configuration.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @enabled: Pointer to variable for storing state.
|
|
|
|
* @vme_base: Pointer to variable for storing window base address.
|
|
|
|
* @size: Pointer to variable for storing window size.
|
|
|
|
* @aspace: Pointer to variable for storing VME address space.
|
|
|
|
* @cycle: Pointer to variable for storing VME data transfer cycle type.
|
|
|
|
* @dwidth: Pointer to variable for storing VME data transfer width.
|
|
|
|
*
|
|
|
|
* Return configuration for provided VME master window.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device or if an invalid resource has been provided.
|
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
int vme_master_get(struct vme_resource *resource, int *enabled,
|
2011-12-02 00:06:29 +07:00
|
|
|
unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
|
|
|
|
u32 *cycle, u32 *dwidth)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->master_get) {
|
2014-12-08 02:20:53 +07:00
|
|
|
printk(KERN_WARNING "%s not supported\n", __func__);
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bridge->master_get(image, enabled, vme_base, size, aspace,
|
|
|
|
cycle, dwidth);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_get);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_write - Read data from VME space into a buffer.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @buf: Pointer to buffer where data should be transferred.
|
|
|
|
* @count: Number of bytes to transfer.
|
|
|
|
* @offset: Offset into VME master window at which to start transfer.
|
|
|
|
*
|
|
|
|
* Perform read of count bytes of data from location on VME bus which maps into
|
|
|
|
* the VME master window at offset to buf.
|
|
|
|
*
|
|
|
|
* Return: Number of bytes read, -EINVAL if resource is not a VME master
|
|
|
|
* resource or read operation is not supported. -EFAULT returned if
|
|
|
|
* invalid offset is provided. Hardware specific errors may also be
|
|
|
|
* returned.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
|
2009-07-31 15:28:17 +07:00
|
|
|
loff_t offset)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
size_t length;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->master_read) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Reading from resource not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
|
|
|
|
length = vme_get_size(resource);
|
|
|
|
|
|
|
|
if (offset > length) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Invalid Offset\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((offset + count) > length)
|
|
|
|
count = length - offset;
|
|
|
|
|
|
|
|
return bridge->master_read(image, buf, count, offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_read);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_write - Write data out to VME space from a buffer.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @buf: Pointer to buffer holding data to transfer.
|
|
|
|
* @count: Number of bytes to transfer.
|
|
|
|
* @offset: Offset into VME master window at which to start transfer.
|
|
|
|
*
|
|
|
|
* Perform write of count bytes of data from buf to location on VME bus which
|
|
|
|
* maps into the VME master window at offset.
|
|
|
|
*
|
|
|
|
* Return: Number of bytes written, -EINVAL if resource is not a VME master
|
|
|
|
* resource or write operation is not supported. -EFAULT returned if
|
|
|
|
* invalid offset is provided. Hardware specific errors may also be
|
|
|
|
* returned.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
ssize_t vme_master_write(struct vme_resource *resource, void *buf,
|
2009-07-31 15:28:17 +07:00
|
|
|
size_t count, loff_t offset)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
size_t length;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->master_write) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Writing to resource not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
|
|
|
|
length = vme_get_size(resource);
|
|
|
|
|
|
|
|
if (offset > length) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Invalid Offset\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((offset + count) > length)
|
|
|
|
count = length - offset;
|
|
|
|
|
|
|
|
return bridge->master_write(image, buf, count, offset);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_write);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_rmw - Perform read-modify-write cycle.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @mask: Bits to be compared and swapped in operation.
|
|
|
|
* @compare: Bits to be compared with data read from offset.
|
|
|
|
* @swap: Bits to be swapped in data read from offset.
|
|
|
|
* @offset: Offset into VME master window at which to perform operation.
|
|
|
|
*
|
|
|
|
* Perform read-modify-write cycle on provided location:
|
|
|
|
* - Location on VME bus is read.
|
|
|
|
* - Bits selected by mask are compared with compare.
|
|
|
|
* - Where a selected bit matches that in compare and are selected in swap,
|
|
|
|
* the bit is swapped.
|
|
|
|
* - Result written back to location on VME bus.
|
|
|
|
*
|
|
|
|
* Return: Bytes written on success, -EINVAL if resource is not a VME master
|
|
|
|
* resource or RMW operation is not supported. Hardware specific
|
|
|
|
* errors may also be returned.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask,
|
2009-07-31 15:28:17 +07:00
|
|
|
unsigned int compare, unsigned int swap, loff_t offset)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->master_rmw) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Writing to resource not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
|
|
|
|
return bridge->master_rmw(image, mask, compare, swap, offset);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_rmw);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_mmap - Mmap region of VME master window.
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
* @vma: Pointer to definition of user mapping.
|
|
|
|
*
|
|
|
|
* Memory map a region of the VME master window into user space.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if resource is not a VME master
|
|
|
|
* resource or -EFAULT if map exceeds window size. Other generic mmap
|
|
|
|
* errors may also be returned.
|
|
|
|
*/
|
2015-02-26 22:53:10 +07:00
|
|
|
int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct vme_master_resource *image;
|
|
|
|
phys_addr_t phys_addr;
|
|
|
|
unsigned long vma_size;
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
|
|
|
pr_err("Not a master resource\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = list_entry(resource->entry, struct vme_master_resource, list);
|
|
|
|
phys_addr = image->bus_resource.start + (vma->vm_pgoff << PAGE_SHIFT);
|
|
|
|
vma_size = vma->vm_end - vma->vm_start;
|
|
|
|
|
|
|
|
if (phys_addr + vma_size > image->bus_resource.end + 1) {
|
|
|
|
pr_err("Map size cannot exceed the window size\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
|
|
|
|
|
|
|
return vm_iomap_memory(vma, phys_addr, vma->vm_end - vma->vm_start);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_mmap);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_master_free - Free VME master window
|
|
|
|
* @resource: Pointer to VME master resource.
|
|
|
|
*
|
|
|
|
* Free the provided master resource so that it may be reallocated.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
void vme_master_free(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_master_resource *master_image;
|
|
|
|
|
|
|
|
if (resource->type != VME_MASTER) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
master_image = list_entry(resource->entry, struct vme_master_resource,
|
|
|
|
list);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!master_image) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Can't find master resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
if (master_image->locked == 0)
|
|
|
|
printk(KERN_ERR "Image is already free\n");
|
|
|
|
|
|
|
|
master_image->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&master_image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
/* Free up resource memory */
|
|
|
|
kfree(resource);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_master_free);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_request - Request a DMA controller.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @route: Required src/destination combination.
|
|
|
|
*
|
|
|
|
* Request a VME DMA controller with capability to perform transfers bewteen
|
|
|
|
* requested source/destination combination.
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME DMA resource on success, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2011-12-02 00:06:29 +07:00
|
|
|
struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
struct list_head *dma_pos = NULL;
|
|
|
|
struct vme_dma_resource *allocated_ctrlr = NULL;
|
|
|
|
struct vme_dma_resource *dma_ctrlr = NULL;
|
|
|
|
struct vme_resource *resource = NULL;
|
|
|
|
|
|
|
|
/* XXX Not checking resource attributes */
|
|
|
|
printk(KERN_ERR "No VME resource Attribute tests done\n");
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
goto err_bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop through DMA resources */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_for_each(dma_pos, &bridge->dma_resources) {
|
2009-07-31 15:28:17 +07:00
|
|
|
dma_ctrlr = list_entry(dma_pos,
|
|
|
|
struct vme_dma_resource, list);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!dma_ctrlr) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Registered NULL DMA resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:12:58 +07:00
|
|
|
/* Find an unlocked and compatible controller */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&dma_ctrlr->mtx);
|
2010-02-18 22:12:58 +07:00
|
|
|
if (((dma_ctrlr->route_attr & route) == route) &&
|
|
|
|
(dma_ctrlr->locked == 0)) {
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
dma_ctrlr->locked = 1;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&dma_ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
allocated_ctrlr = dma_ctrlr;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&dma_ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if we found a resource */
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!allocated_ctrlr)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_ctrlr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
resource = kmalloc(sizeof(*resource), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!resource)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_alloc;
|
2017-08-25 02:38:20 +07:00
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
resource->type = VME_DMA;
|
2010-11-12 18:14:07 +07:00
|
|
|
resource->entry = &allocated_ctrlr->list;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&dma_ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
dma_ctrlr->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&dma_ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
err_ctrlr:
|
|
|
|
err_bus:
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-29 23:35:20 +07:00
|
|
|
EXPORT_SYMBOL(vme_dma_request);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_new_dma_list - Create new VME DMA list.
|
|
|
|
* @resource: Pointer to VME DMA resource.
|
|
|
|
*
|
|
|
|
* Create a new VME DMA list. It is the responsibility of the user to free
|
|
|
|
* the list once it is no longer required with vme_dma_list_free().
|
|
|
|
*
|
|
|
|
* Return: Pointer to new VME DMA list, NULL on allocation failure or invalid
|
|
|
|
* VME DMA resource.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_dma_list *dma_list;
|
|
|
|
|
|
|
|
if (resource->type != VME_DMA) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a DMA resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
dma_list = kmalloc(sizeof(*dma_list), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!dma_list)
|
2009-07-31 15:28:17 +07:00
|
|
|
return NULL;
|
2017-08-25 02:38:20 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
INIT_LIST_HEAD(&dma_list->entries);
|
2017-08-25 03:04:45 +07:00
|
|
|
dma_list->parent = list_entry(resource->entry,
|
|
|
|
struct vme_dma_resource,
|
|
|
|
list);
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_init(&dma_list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return dma_list;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_new_dma_list);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_pattern_attribute - Create "Pattern" type VME DMA list attribute.
|
|
|
|
* @pattern: Value to use used as pattern
|
|
|
|
* @type: Type of pattern to be written.
|
|
|
|
*
|
|
|
|
* Create VME DMA list attribute for pattern generation. It is the
|
|
|
|
* responsibility of the user to free used attributes using
|
|
|
|
* vme_dma_free_attribute().
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME DMA attribute, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
2011-12-02 00:06:29 +07:00
|
|
|
struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_dma_attr *attributes;
|
|
|
|
struct vme_dma_pattern *pattern_attr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!attributes)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_attr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
pattern_attr = kmalloc(sizeof(*pattern_attr), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!pattern_attr)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_pat;
|
|
|
|
|
|
|
|
attributes->type = VME_DMA_PATTERN;
|
|
|
|
attributes->private = (void *)pattern_attr;
|
|
|
|
|
|
|
|
pattern_attr->pattern = pattern;
|
|
|
|
pattern_attr->type = type;
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
|
|
|
|
err_pat:
|
|
|
|
kfree(attributes);
|
|
|
|
err_attr:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_pattern_attribute);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_pci_attribute - Create "PCI" type VME DMA list attribute.
|
|
|
|
* @address: PCI base address for DMA transfer.
|
|
|
|
*
|
|
|
|
* Create VME DMA list attribute pointing to a location on PCI for DMA
|
|
|
|
* transfers. It is the responsibility of the user to free used attributes
|
|
|
|
* using vme_dma_free_attribute().
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME DMA attribute, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address)
|
|
|
|
{
|
|
|
|
struct vme_dma_attr *attributes;
|
|
|
|
struct vme_dma_pci *pci_attr;
|
|
|
|
|
|
|
|
/* XXX Run some sanity checks here */
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!attributes)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_attr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
pci_attr = kmalloc(sizeof(*pci_attr), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!pci_attr)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_pci;
|
|
|
|
|
|
|
|
attributes->type = VME_DMA_PCI;
|
|
|
|
attributes->private = (void *)pci_attr;
|
|
|
|
|
|
|
|
pci_attr->address = address;
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
|
|
|
|
err_pci:
|
|
|
|
kfree(attributes);
|
|
|
|
err_attr:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_pci_attribute);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_vme_attribute - Create "VME" type VME DMA list attribute.
|
|
|
|
* @address: VME base address for DMA transfer.
|
|
|
|
* @aspace: VME address space to use for DMA transfer.
|
|
|
|
* @cycle: VME bus cycle to use for DMA transfer.
|
|
|
|
* @dwidth: VME data width to use for DMA transfer.
|
|
|
|
*
|
|
|
|
* Create VME DMA list attribute pointing to a location on the VME bus for DMA
|
|
|
|
* transfers. It is the responsibility of the user to free used attributes
|
|
|
|
* using vme_dma_free_attribute().
|
|
|
|
*
|
|
|
|
* Return: Pointer to VME DMA attribute, NULL on failure.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address,
|
2011-12-02 00:06:29 +07:00
|
|
|
u32 aspace, u32 cycle, u32 dwidth)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_dma_attr *attributes;
|
|
|
|
struct vme_dma_vme *vme_attr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!attributes)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_attr;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
vme_attr = kmalloc(sizeof(*vme_attr), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!vme_attr)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_vme;
|
|
|
|
|
|
|
|
attributes->type = VME_DMA_VME;
|
|
|
|
attributes->private = (void *)vme_attr;
|
|
|
|
|
|
|
|
vme_attr->address = address;
|
|
|
|
vme_attr->aspace = aspace;
|
|
|
|
vme_attr->cycle = cycle;
|
|
|
|
vme_attr->dwidth = dwidth;
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
|
|
|
|
err_vme:
|
|
|
|
kfree(attributes);
|
|
|
|
err_attr:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_vme_attribute);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_free_attribute - Free DMA list attribute.
|
|
|
|
* @attributes: Pointer to DMA list attribute.
|
|
|
|
*
|
|
|
|
* Free VME DMA list attribute. VME DMA list attributes can be safely freed
|
|
|
|
* once vme_dma_list_add() has returned.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
void vme_dma_free_attribute(struct vme_dma_attr *attributes)
|
|
|
|
{
|
|
|
|
kfree(attributes->private);
|
|
|
|
kfree(attributes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_free_attribute);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_list_add - Add enty to a VME DMA list.
|
|
|
|
* @list: Pointer to VME list.
|
|
|
|
* @src: Pointer to DMA list attribute to use as source.
|
|
|
|
* @dest: Pointer to DMA list attribute to use as destination.
|
|
|
|
* @count: Number of bytes to transfer.
|
|
|
|
*
|
|
|
|
* Add an entry to the provided VME DMA list. Entry requires pointers to source
|
|
|
|
* and destination DMA attributes and a count.
|
|
|
|
*
|
|
|
|
* Please note, the attributes supported as source and destinations for
|
|
|
|
* transfers are hardware dependent.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device or if the link list has already been submitted for execution.
|
|
|
|
* Hardware specific errors also possible.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
|
|
|
|
struct vme_dma_attr *dest, size_t count)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = list->parent->parent;
|
|
|
|
int retval;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->dma_list_add) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Link List DMA generation not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
if (!mutex_trylock(&list->mtx)) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Link List already submitted\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = bridge->dma_list_add(list, src, dest, count);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_list_add);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_list_exec - Queue a VME DMA list for execution.
|
|
|
|
* @list: Pointer to VME list.
|
|
|
|
*
|
|
|
|
* Queue the provided VME DMA list for execution. The call will return once the
|
|
|
|
* list has been executed.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL if operation is not supported on this
|
|
|
|
* device. Hardware specific errors also possible.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
int vme_dma_list_exec(struct vme_dma_list *list)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = list->parent->parent;
|
|
|
|
int retval;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->dma_list_exec) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Link List DMA execution not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
retval = bridge->dma_list_exec(list);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_list_exec);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_list_free - Free a VME DMA list.
|
|
|
|
* @list: Pointer to VME list.
|
|
|
|
*
|
|
|
|
* Free the provided DMA list and all its entries.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource
|
|
|
|
* is still in use. Hardware specific errors also possible.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
int vme_dma_list_free(struct vme_dma_list *list)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = list->parent->parent;
|
|
|
|
int retval;
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->dma_list_empty) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Emptying of Link Lists not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
if (!mutex_trylock(&list->mtx)) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Link List in use\n");
|
2017-10-24 13:27:40 +07:00
|
|
|
return -EBUSY;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-04-21 23:18:22 +07:00
|
|
|
* Empty out all of the entries from the DMA list. We need to go to the
|
|
|
|
* low level driver as DMA entries are driver specific.
|
2009-07-31 15:28:17 +07:00
|
|
|
*/
|
|
|
|
retval = bridge->dma_list_empty(list);
|
|
|
|
if (retval) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Unable to empty link-list entries\n");
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
return retval;
|
|
|
|
}
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&list->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
kfree(list);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_list_free);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_dma_free - Free a VME DMA resource.
|
|
|
|
* @resource: Pointer to VME DMA resource.
|
|
|
|
*
|
|
|
|
* Free the provided DMA resource so that it may be reallocated.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource
|
|
|
|
* is still active.
|
|
|
|
*/
|
2009-07-31 15:28:17 +07:00
|
|
|
int vme_dma_free(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_dma_resource *ctrlr;
|
|
|
|
|
|
|
|
if (resource->type != VME_DMA) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Not a DMA resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
if (!mutex_trylock(&ctrlr->mtx)) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_ERR "Resource busy, can't free\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Resource still processing transfers\n");
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrlr->locked = 0;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&ctrlr->mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2013-06-06 18:29:16 +07:00
|
|
|
kfree(resource);
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_dma_free);
|
|
|
|
|
2015-09-18 06:01:42 +07:00
|
|
|
void vme_bus_error_handler(struct vme_bridge *bridge,
|
2015-09-18 06:01:43 +07:00
|
|
|
unsigned long long address, int am)
|
2015-09-18 06:01:42 +07:00
|
|
|
{
|
2015-09-18 06:01:44 +07:00
|
|
|
struct list_head *handler_pos = NULL;
|
|
|
|
struct vme_error_handler *handler;
|
2015-09-18 06:01:45 +07:00
|
|
|
int handler_triggered = 0;
|
2015-09-18 06:01:44 +07:00
|
|
|
u32 aspace = vme_get_aspace(am);
|
|
|
|
|
|
|
|
list_for_each(handler_pos, &bridge->vme_error_handlers) {
|
|
|
|
handler = list_entry(handler_pos, struct vme_error_handler,
|
|
|
|
list);
|
|
|
|
if ((aspace == handler->aspace) &&
|
|
|
|
(address >= handler->start) &&
|
|
|
|
(address < handler->end)) {
|
|
|
|
if (!handler->num_errors)
|
|
|
|
handler->first_error = address;
|
|
|
|
if (handler->num_errors != UINT_MAX)
|
|
|
|
handler->num_errors++;
|
2015-09-18 06:01:45 +07:00
|
|
|
handler_triggered = 1;
|
2015-09-18 06:01:44 +07:00
|
|
|
}
|
2015-09-18 06:01:42 +07:00
|
|
|
}
|
2015-09-18 06:01:45 +07:00
|
|
|
|
|
|
|
if (!handler_triggered)
|
|
|
|
dev_err(bridge->parent,
|
|
|
|
"Unhandled VME access error at address 0x%llx\n",
|
|
|
|
address);
|
2015-09-18 06:01:42 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_bus_error_handler);
|
|
|
|
|
2015-09-18 06:01:44 +07:00
|
|
|
struct vme_error_handler *vme_register_error_handler(
|
|
|
|
struct vme_bridge *bridge, u32 aspace,
|
|
|
|
unsigned long long address, size_t len)
|
2015-09-18 06:01:42 +07:00
|
|
|
{
|
2015-09-18 06:01:44 +07:00
|
|
|
struct vme_error_handler *handler;
|
2015-09-18 06:01:42 +07:00
|
|
|
|
2017-12-12 19:51:53 +07:00
|
|
|
handler = kmalloc(sizeof(*handler), GFP_ATOMIC);
|
2015-09-18 06:01:44 +07:00
|
|
|
if (!handler)
|
|
|
|
return NULL;
|
2015-09-18 06:01:42 +07:00
|
|
|
|
2015-09-18 06:01:44 +07:00
|
|
|
handler->aspace = aspace;
|
|
|
|
handler->start = address;
|
|
|
|
handler->end = address + len;
|
|
|
|
handler->num_errors = 0;
|
|
|
|
handler->first_error = 0;
|
|
|
|
list_add_tail(&handler->list, &bridge->vme_error_handlers);
|
2015-09-18 06:01:42 +07:00
|
|
|
|
2015-09-18 06:01:44 +07:00
|
|
|
return handler;
|
2015-09-18 06:01:42 +07:00
|
|
|
}
|
2015-09-18 06:01:44 +07:00
|
|
|
EXPORT_SYMBOL(vme_register_error_handler);
|
2015-09-18 06:01:42 +07:00
|
|
|
|
2015-09-18 06:01:44 +07:00
|
|
|
void vme_unregister_error_handler(struct vme_error_handler *handler)
|
2015-09-18 06:01:42 +07:00
|
|
|
{
|
2015-09-18 06:01:44 +07:00
|
|
|
list_del(&handler->list);
|
|
|
|
kfree(handler);
|
2015-09-18 06:01:42 +07:00
|
|
|
}
|
2015-09-18 06:01:44 +07:00
|
|
|
EXPORT_SYMBOL(vme_unregister_error_handler);
|
2015-09-18 06:01:42 +07:00
|
|
|
|
2009-10-29 23:34:54 +07:00
|
|
|
void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
|
|
|
|
{
|
|
|
|
void (*call)(int, int, void *);
|
|
|
|
void *priv_data;
|
|
|
|
|
|
|
|
call = bridge->irq[level - 1].callback[statid].func;
|
|
|
|
priv_data = bridge->irq[level - 1].callback[statid].priv_data;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (call)
|
2009-10-29 23:34:54 +07:00
|
|
|
call(level, statid, priv_data);
|
|
|
|
else
|
2016-04-21 23:18:22 +07:00
|
|
|
printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n",
|
2012-04-26 01:25:46 +07:00
|
|
|
level, statid);
|
2009-10-29 23:34:54 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_irq_handler);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_irq_request - Request a specific VME interrupt.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @level: Interrupt priority being requested.
|
|
|
|
* @statid: Interrupt vector being requested.
|
|
|
|
* @callback: Pointer to callback function called when VME interrupt/vector
|
|
|
|
* received.
|
|
|
|
* @priv_data: Generic pointer that will be passed to the callback function.
|
|
|
|
*
|
|
|
|
* Request callback to be attached as a handler for VME interrupts with provided
|
|
|
|
* level and statid.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL on invalid vme device, level or if the
|
|
|
|
* function is not supported, -EBUSY if the level/statid combination is
|
|
|
|
* already in use. Hardware specific errors also possible.
|
|
|
|
*/
|
2011-09-26 16:27:15 +07:00
|
|
|
int vme_irq_request(struct vme_dev *vdev, int level, int statid,
|
2010-02-18 22:13:05 +07:00
|
|
|
void (*callback)(int, int, void *),
|
2009-07-31 15:28:17 +07:00
|
|
|
void *priv_data)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
if ((level < 1) || (level > 7)) {
|
2009-10-29 23:34:54 +07:00
|
|
|
printk(KERN_ERR "Invalid interrupt level\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->irq_set) {
|
2009-10-29 23:34:54 +07:00
|
|
|
printk(KERN_ERR "Configuring interrupts not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&bridge->irq_mtx);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
|
|
|
if (bridge->irq[level - 1].callback[statid].func) {
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&bridge->irq_mtx);
|
2009-10-29 23:34:54 +07:00
|
|
|
printk(KERN_WARNING "VME Interrupt already taken\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->irq[level - 1].count++;
|
|
|
|
bridge->irq[level - 1].callback[statid].priv_data = priv_data;
|
|
|
|
bridge->irq[level - 1].callback[statid].func = callback;
|
|
|
|
|
|
|
|
/* Enable IRQ level */
|
2010-02-18 22:13:05 +07:00
|
|
|
bridge->irq_set(bridge, level, 1, 1);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&bridge->irq_mtx);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-10-29 23:34:54 +07:00
|
|
|
EXPORT_SYMBOL(vme_irq_request);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_irq_free - Free a VME interrupt.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @level: Interrupt priority of interrupt being freed.
|
|
|
|
* @statid: Interrupt vector of interrupt being freed.
|
|
|
|
*
|
|
|
|
* Remove previously attached callback from VME interrupt priority/vector.
|
|
|
|
*/
|
2011-09-26 16:27:15 +07:00
|
|
|
void vme_irq_free(struct vme_dev *vdev, int level, int statid)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
if ((level < 1) || (level > 7)) {
|
2009-10-29 23:34:54 +07:00
|
|
|
printk(KERN_ERR "Invalid interrupt level\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->irq_set) {
|
2009-10-29 23:34:54 +07:00
|
|
|
printk(KERN_ERR "Configuring interrupts not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&bridge->irq_mtx);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
|
|
|
bridge->irq[level - 1].count--;
|
|
|
|
|
|
|
|
/* Disable IRQ level if no more interrupts attached at this level*/
|
|
|
|
if (bridge->irq[level - 1].count == 0)
|
2010-02-18 22:13:05 +07:00
|
|
|
bridge->irq_set(bridge, level, 0, 1);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
|
|
|
bridge->irq[level - 1].callback[statid].func = NULL;
|
|
|
|
bridge->irq[level - 1].callback[statid].priv_data = NULL;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&bridge->irq_mtx);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-10-29 23:34:54 +07:00
|
|
|
EXPORT_SYMBOL(vme_irq_free);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_irq_generate - Generate VME interrupt.
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
* @level: Interrupt priority at which to assert the interrupt.
|
|
|
|
* @statid: Interrupt vector to associate with the interrupt.
|
|
|
|
*
|
|
|
|
* Generate a VME interrupt of the provided level and with the provided
|
|
|
|
* statid.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL on invalid vme device, level or if the
|
|
|
|
* function is not supported. Hardware specific errors also possible.
|
|
|
|
*/
|
2011-09-26 16:27:15 +07:00
|
|
|
int vme_irq_generate(struct vme_dev *vdev, int level, int statid)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
if ((level < 1) || (level > 7)) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_WARNING "Invalid interrupt level\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->irq_generate) {
|
2009-12-15 15:43:02 +07:00
|
|
|
printk(KERN_WARNING "Interrupt generation not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
return bridge->irq_generate(bridge, level, statid);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-10-29 23:34:54 +07:00
|
|
|
EXPORT_SYMBOL(vme_irq_generate);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_request - Request a VME location monitor
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
*
|
|
|
|
* Allocate a location monitor resource to the driver. A location monitor
|
|
|
|
* allows the driver to monitor accesses to a contiguous number of
|
|
|
|
* addresses on the VME bus.
|
|
|
|
*
|
|
|
|
* Return: Pointer to a VME resource on success or NULL on failure.
|
2009-08-11 23:44:56 +07:00
|
|
|
*/
|
2011-09-26 16:27:15 +07:00
|
|
|
struct vme_resource *vme_lm_request(struct vme_dev *vdev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
2009-08-11 23:44:56 +07:00
|
|
|
struct list_head *lm_pos = NULL;
|
|
|
|
struct vme_lm_resource *allocated_lm = NULL;
|
|
|
|
struct vme_lm_resource *lm = NULL;
|
|
|
|
struct vme_resource *resource = NULL;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
2009-08-11 23:44:56 +07:00
|
|
|
goto err_bus;
|
|
|
|
}
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/* Loop through LM resources */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_for_each(lm_pos, &bridge->lm_resources) {
|
2009-08-11 23:44:56 +07:00
|
|
|
lm = list_entry(lm_pos,
|
|
|
|
struct vme_lm_resource, list);
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!lm) {
|
2012-04-26 01:25:46 +07:00
|
|
|
printk(KERN_ERR "Registered NULL Location Monitor resource\n");
|
2009-08-11 23:44:56 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find an unlocked controller */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
if (lm->locked == 0) {
|
|
|
|
lm->locked = 1;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
allocated_lm = lm;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if we found a resource */
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!allocated_lm)
|
2009-08-11 23:44:56 +07:00
|
|
|
goto err_lm;
|
|
|
|
|
2017-08-25 02:52:00 +07:00
|
|
|
resource = kmalloc(sizeof(*resource), GFP_KERNEL);
|
2017-08-25 02:38:20 +07:00
|
|
|
if (!resource)
|
2009-08-11 23:44:56 +07:00
|
|
|
goto err_alloc;
|
2017-08-25 02:38:20 +07:00
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
resource->type = VME_LM;
|
2010-11-12 18:14:07 +07:00
|
|
|
resource->entry = &allocated_lm->list;
|
2009-08-11 23:44:56 +07:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
/* Unlock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
lm->locked = 0;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
err_lm:
|
|
|
|
err_bus:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_request);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_count - Determine number of VME Addresses monitored
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
*
|
|
|
|
* The number of contiguous addresses monitored is hardware dependent.
|
|
|
|
* Return the number of contiguous addresses monitored by the
|
|
|
|
* location monitor.
|
|
|
|
*
|
|
|
|
* Return: Count of addresses monitored or -EINVAL when provided with an
|
|
|
|
* invalid location monitor resource.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
int vme_lm_count(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_lm_resource *lm;
|
|
|
|
|
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
|
|
|
return lm->monitors;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_count);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_set - Configure location monitor
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
* @lm_base: Base address to monitor.
|
|
|
|
* @aspace: VME address space to monitor.
|
|
|
|
* @cycle: VME bus cycle type to monitor.
|
|
|
|
*
|
|
|
|
* Set the base address, address space and cycle type of accesses to be
|
|
|
|
* monitored by the location monitor.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL when provided with an invalid location
|
|
|
|
* monitor resource or function is not supported. Hardware specific
|
|
|
|
* errors may also be returned.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base,
|
2011-12-02 00:06:29 +07:00
|
|
|
u32 aspace, u32 cycle)
|
2009-08-11 23:44:56 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_lm_resource *lm;
|
|
|
|
|
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->lm_set) {
|
2009-08-11 23:44:56 +07:00
|
|
|
printk(KERN_ERR "vme_lm_set not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-10-29 23:35:08 +07:00
|
|
|
return bridge->lm_set(lm, lm_base, aspace, cycle);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_set);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_get - Retrieve location monitor settings
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
* @lm_base: Pointer used to output the base address monitored.
|
|
|
|
* @aspace: Pointer used to output the address space monitored.
|
|
|
|
* @cycle: Pointer used to output the VME bus cycle type monitored.
|
|
|
|
*
|
|
|
|
* Retrieve the base address, address space and cycle type of accesses to
|
|
|
|
* be monitored by the location monitor.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL when provided with an invalid location
|
|
|
|
* monitor resource or function is not supported. Hardware specific
|
|
|
|
* errors may also be returned.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base,
|
2011-12-02 00:06:29 +07:00
|
|
|
u32 *aspace, u32 *cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-11 23:44:56 +07:00
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_lm_resource *lm;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->lm_get) {
|
2009-08-11 23:44:56 +07:00
|
|
|
printk(KERN_ERR "vme_lm_get not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
return bridge->lm_get(lm, lm_base, aspace, cycle);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_get);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_attach - Provide callback for location monitor address
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
* @monitor: Offset to which callback should be attached.
|
|
|
|
* @callback: Pointer to callback function called when triggered.
|
|
|
|
* @data: Generic pointer that will be passed to the callback function.
|
|
|
|
*
|
|
|
|
* Attach a callback to the specificed offset into the location monitors
|
|
|
|
* monitored addresses. A generic pointer is provided to allow data to be
|
|
|
|
* passed to the callback when called.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL when provided with an invalid location
|
|
|
|
* monitor resource or function is not supported. Hardware specific
|
|
|
|
* errors may also be returned.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
int vme_lm_attach(struct vme_resource *resource, int monitor,
|
2016-04-30 04:41:02 +07:00
|
|
|
void (*callback)(void *), void *data)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-11 23:44:56 +07:00
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_lm_resource *lm;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->lm_attach) {
|
2009-08-11 23:44:56 +07:00
|
|
|
printk(KERN_ERR "vme_lm_attach not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-04-30 04:41:02 +07:00
|
|
|
return bridge->lm_attach(lm, monitor, callback, data);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_attach);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_detach - Remove callback for location monitor address
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
* @monitor: Offset to which callback should be removed.
|
|
|
|
*
|
|
|
|
* Remove the callback associated with the specificed offset into the
|
|
|
|
* location monitors monitored addresses.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL when provided with an invalid location
|
|
|
|
* monitor resource or function is not supported. Hardware specific
|
|
|
|
* errors may also be returned.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
int vme_lm_detach(struct vme_resource *resource, int monitor)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-11 23:44:56 +07:00
|
|
|
struct vme_bridge *bridge = find_bridge(resource);
|
|
|
|
struct vme_lm_resource *lm;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->lm_detach) {
|
2009-08-11 23:44:56 +07:00
|
|
|
printk(KERN_ERR "vme_lm_detach not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:44:56 +07:00
|
|
|
return bridge->lm_detach(lm, monitor);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_detach);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_lm_free - Free allocated VME location monitor
|
|
|
|
* @resource: Pointer to VME location monitor resource.
|
|
|
|
*
|
|
|
|
* Free allocation of a VME location monitor.
|
|
|
|
*
|
|
|
|
* WARNING: This function currently expects that any callbacks that have
|
|
|
|
* been attached to the location monitor have been removed.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, -EINVAL when provided with an invalid location
|
|
|
|
* monitor resource.
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
void vme_lm_free(struct vme_resource *resource)
|
|
|
|
{
|
|
|
|
struct vme_lm_resource *lm;
|
|
|
|
|
|
|
|
if (resource->type != VME_LM) {
|
|
|
|
printk(KERN_ERR "Not a Location Monitor resource\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lm = list_entry(resource->entry, struct vme_lm_resource, list);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2009-08-11 23:44:56 +07:00
|
|
|
|
2009-10-29 23:35:08 +07:00
|
|
|
/* XXX
|
|
|
|
* Check to see that there aren't any callbacks still attached, if
|
|
|
|
* there are we should probably be detaching them!
|
|
|
|
*/
|
2009-08-11 23:44:56 +07:00
|
|
|
|
|
|
|
lm->locked = 0;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2009-10-29 23:35:08 +07:00
|
|
|
|
|
|
|
kfree(resource);
|
2009-08-11 23:44:56 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_lm_free);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_slot_num - Retrieve slot ID
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
*
|
|
|
|
* Retrieve the slot ID associated with the provided VME device.
|
|
|
|
*
|
|
|
|
* Return: The slot ID on success, -EINVAL if VME bridge cannot be determined
|
|
|
|
* or the function is not supported. Hardware specific errors may also
|
|
|
|
* be returned.
|
|
|
|
*/
|
2013-11-08 18:58:35 +07:00
|
|
|
int vme_slot_num(struct vme_dev *vdev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
2011-09-26 16:27:15 +07:00
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2009-07-31 15:28:17 +07:00
|
|
|
printk(KERN_ERR "Can't find VME bus\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge->slot_get) {
|
2013-11-08 18:58:35 +07:00
|
|
|
printk(KERN_WARNING "vme_slot_num not supported\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
return bridge->slot_get(bridge);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2013-11-08 18:58:35 +07:00
|
|
|
EXPORT_SYMBOL(vme_slot_num);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_bus_num - Retrieve bus number
|
|
|
|
* @vdev: Pointer to VME device struct vme_dev assigned to driver instance.
|
|
|
|
*
|
|
|
|
* Retrieve the bus enumeration associated with the provided VME device.
|
|
|
|
*
|
|
|
|
* Return: The bus number on success, -EINVAL if VME bridge cannot be
|
|
|
|
* determined.
|
|
|
|
*/
|
2013-11-08 18:58:34 +07:00
|
|
|
int vme_bus_num(struct vme_dev *vdev)
|
|
|
|
{
|
|
|
|
struct vme_bridge *bridge;
|
|
|
|
|
|
|
|
bridge = vdev->bridge;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (!bridge) {
|
2013-11-08 18:58:34 +07:00
|
|
|
pr_err("Can't find VME bus\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bridge->num;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_bus_num);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
/* - Bridge Registration --------------------------------------------------- */
|
|
|
|
|
2011-11-04 17:12:30 +07:00
|
|
|
static void vme_dev_release(struct device *dev)
|
|
|
|
{
|
|
|
|
kfree(dev_to_vme_dev(dev));
|
|
|
|
}
|
|
|
|
|
2016-04-25 03:11:38 +07:00
|
|
|
/* Common bridge initialization */
|
|
|
|
struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&bridge->vme_error_handlers);
|
|
|
|
INIT_LIST_HEAD(&bridge->master_resources);
|
|
|
|
INIT_LIST_HEAD(&bridge->slave_resources);
|
|
|
|
INIT_LIST_HEAD(&bridge->dma_resources);
|
|
|
|
INIT_LIST_HEAD(&bridge->lm_resources);
|
|
|
|
mutex_init(&bridge->irq_mtx);
|
|
|
|
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_init_bridge);
|
|
|
|
|
2011-11-04 17:12:30 +07:00
|
|
|
int vme_register_bridge(struct vme_bridge *bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
int i;
|
2011-08-12 17:30:48 +07:00
|
|
|
int ret = -1;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-08-12 17:30:48 +07:00
|
|
|
mutex_lock(&vme_buses_lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) {
|
2011-08-12 17:30:48 +07:00
|
|
|
if ((vme_bus_numbers & (1 << i)) == 0) {
|
|
|
|
vme_bus_numbers |= (1 << i);
|
|
|
|
bridge->num = i;
|
2011-09-26 16:27:16 +07:00
|
|
|
INIT_LIST_HEAD(&bridge->devices);
|
2011-08-12 17:30:48 +07:00
|
|
|
list_add_tail(&bridge->bus_list, &vme_bus_list);
|
|
|
|
ret = 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-12 17:30:48 +07:00
|
|
|
mutex_unlock(&vme_buses_lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-08-12 17:30:48 +07:00
|
|
|
return ret;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2011-11-04 17:12:30 +07:00
|
|
|
EXPORT_SYMBOL(vme_register_bridge);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-11-04 17:12:30 +07:00
|
|
|
void vme_unregister_bridge(struct vme_bridge *bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
struct vme_dev *vdev;
|
|
|
|
struct vme_dev *tmp;
|
|
|
|
|
2011-08-12 17:30:48 +07:00
|
|
|
mutex_lock(&vme_buses_lock);
|
|
|
|
vme_bus_numbers &= ~(1 << bridge->num);
|
2011-09-26 16:27:16 +07:00
|
|
|
list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
|
|
|
|
list_del(&vdev->drv_list);
|
|
|
|
list_del(&vdev->bridge_list);
|
|
|
|
device_unregister(&vdev->dev);
|
|
|
|
}
|
2011-08-12 17:30:48 +07:00
|
|
|
list_del(&bridge->bus_list);
|
|
|
|
mutex_unlock(&vme_buses_lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2011-09-26 16:27:16 +07:00
|
|
|
EXPORT_SYMBOL(vme_unregister_bridge);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
/* - Driver Registration --------------------------------------------------- */
|
|
|
|
|
|
|
|
static int __vme_register_driver_bus(struct vme_driver *drv,
|
|
|
|
struct vme_bridge *bridge, unsigned int ndevs)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned int i;
|
|
|
|
struct vme_dev *vdev;
|
|
|
|
struct vme_dev *tmp;
|
|
|
|
|
|
|
|
for (i = 0; i < ndevs; i++) {
|
2017-08-25 02:52:00 +07:00
|
|
|
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
|
2011-09-26 16:27:16 +07:00
|
|
|
if (!vdev) {
|
|
|
|
err = -ENOMEM;
|
2011-09-01 16:15:24 +07:00
|
|
|
goto err_devalloc;
|
|
|
|
}
|
2011-09-26 16:27:17 +07:00
|
|
|
vdev->num = i;
|
2011-09-26 16:27:15 +07:00
|
|
|
vdev->bridge = bridge;
|
2011-09-26 16:27:16 +07:00
|
|
|
vdev->dev.platform_data = drv;
|
|
|
|
vdev->dev.release = vme_dev_release;
|
2011-09-26 16:27:15 +07:00
|
|
|
vdev->dev.parent = bridge->parent;
|
|
|
|
vdev->dev.bus = &vme_bus_type;
|
2011-09-26 16:27:17 +07:00
|
|
|
dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num,
|
|
|
|
vdev->num);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
err = device_register(&vdev->dev);
|
|
|
|
if (err)
|
2009-07-31 15:28:17 +07:00
|
|
|
goto err_reg;
|
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
if (vdev->dev.platform_data) {
|
|
|
|
list_add_tail(&vdev->drv_list, &drv->devices);
|
|
|
|
list_add_tail(&vdev->bridge_list, &bridge->devices);
|
|
|
|
} else
|
|
|
|
device_unregister(&vdev->dev);
|
|
|
|
}
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
err_reg:
|
2013-02-14 01:47:54 +07:00
|
|
|
put_device(&vdev->dev);
|
2011-09-01 16:15:24 +07:00
|
|
|
err_devalloc:
|
2011-09-26 16:27:16 +07:00
|
|
|
list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) {
|
|
|
|
list_del(&vdev->drv_list);
|
|
|
|
list_del(&vdev->bridge_list);
|
2011-09-26 16:27:15 +07:00
|
|
|
device_unregister(&vdev->dev);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2011-09-26 16:27:16 +07:00
|
|
|
return err;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
struct vme_bridge *bridge;
|
|
|
|
int err = 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
mutex_lock(&vme_buses_lock);
|
|
|
|
list_for_each_entry(bridge, &vme_bus_list, bus_list) {
|
|
|
|
/*
|
|
|
|
* This cannot cause trouble as we already have vme_buses_lock
|
|
|
|
* and if the bridge is removed, it will have to go through
|
|
|
|
* vme_unregister_bridge() to do it (which calls remove() on
|
|
|
|
* the bridge which in turn tries to acquire vme_buses_lock and
|
2011-11-04 17:12:29 +07:00
|
|
|
* will have to wait).
|
2011-09-26 16:27:16 +07:00
|
|
|
*/
|
|
|
|
err = __vme_register_driver_bus(drv, bridge, ndevs);
|
|
|
|
if (err)
|
|
|
|
break;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2011-09-26 16:27:16 +07:00
|
|
|
mutex_unlock(&vme_buses_lock);
|
|
|
|
return err;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_register_driver - Register a VME driver
|
|
|
|
* @drv: Pointer to VME driver structure to register.
|
|
|
|
* @ndevs: Maximum number of devices to allow to be enumerated.
|
|
|
|
*
|
|
|
|
* Register a VME device driver with the VME subsystem.
|
|
|
|
*
|
|
|
|
* Return: Zero on success, error value on registration failure.
|
|
|
|
*/
|
2011-09-26 16:27:16 +07:00
|
|
|
int vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
int err;
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
drv->driver.name = drv->name;
|
|
|
|
drv->driver.bus = &vme_bus_type;
|
2011-09-26 16:27:16 +07:00
|
|
|
INIT_LIST_HEAD(&drv->devices);
|
|
|
|
|
|
|
|
err = driver_register(&drv->driver);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
err = __vme_register_driver(drv, ndevs);
|
|
|
|
if (err)
|
|
|
|
driver_unregister(&drv->driver);
|
|
|
|
|
|
|
|
return err;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_register_driver);
|
|
|
|
|
2017-03-04 07:34:29 +07:00
|
|
|
/**
|
|
|
|
* vme_unregister_driver - Unregister a VME driver
|
|
|
|
* @drv: Pointer to VME driver structure to unregister.
|
|
|
|
*
|
|
|
|
* Unregister a VME device driver from the VME subsystem.
|
|
|
|
*/
|
2009-12-15 15:43:02 +07:00
|
|
|
void vme_unregister_driver(struct vme_driver *drv)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
struct vme_dev *dev, *dev_tmp;
|
|
|
|
|
|
|
|
mutex_lock(&vme_buses_lock);
|
|
|
|
list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) {
|
|
|
|
list_del(&dev->drv_list);
|
|
|
|
list_del(&dev->bridge_list);
|
|
|
|
device_unregister(&dev->dev);
|
|
|
|
}
|
|
|
|
mutex_unlock(&vme_buses_lock);
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
driver_unregister(&drv->driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vme_unregister_driver);
|
|
|
|
|
|
|
|
/* - Bus Registration ------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int vme_bus_match(struct device *dev, struct device_driver *drv)
|
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
struct vme_driver *vme_drv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
vme_drv = container_of(drv, struct vme_driver, driver);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
if (dev->platform_data == vme_drv) {
|
|
|
|
struct vme_dev *vdev = dev_to_vme_dev(dev);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
if (vme_drv->match && vme_drv->match(vdev))
|
|
|
|
return 1;
|
2009-08-06 15:43:07 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
dev->platform_data = NULL;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vme_bus_probe(struct device *dev)
|
|
|
|
{
|
2011-09-26 16:27:16 +07:00
|
|
|
struct vme_driver *driver;
|
|
|
|
struct vme_dev *vdev = dev_to_vme_dev(dev);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-09-26 16:27:16 +07:00
|
|
|
driver = dev->platform_data;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (driver->probe)
|
2017-08-25 03:32:14 +07:00
|
|
|
return driver->probe(vdev);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2017-08-25 03:32:14 +07:00
|
|
|
return -ENODEV;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2017-01-20 22:38:20 +07:00
|
|
|
static int vme_bus_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct vme_driver *driver;
|
|
|
|
struct vme_dev *vdev = dev_to_vme_dev(dev);
|
|
|
|
|
|
|
|
driver = dev->platform_data;
|
2017-08-25 03:24:38 +07:00
|
|
|
if (driver->remove)
|
2017-08-25 03:32:14 +07:00
|
|
|
return driver->remove(vdev);
|
2017-01-20 22:38:20 +07:00
|
|
|
|
2017-08-25 03:32:14 +07:00
|
|
|
return -ENODEV;
|
2017-01-20 22:38:20 +07:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
struct bus_type vme_bus_type = {
|
|
|
|
.name = "vme",
|
|
|
|
.match = vme_bus_match,
|
|
|
|
.probe = vme_bus_probe,
|
2017-01-20 22:38:20 +07:00
|
|
|
.remove = vme_bus_remove,
|
2009-07-31 15:28:17 +07:00
|
|
|
};
|
|
|
|
EXPORT_SYMBOL(vme_bus_type);
|
|
|
|
|
2009-12-15 15:43:02 +07:00
|
|
|
static int __init vme_init(void)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
return bus_register(&vme_bus_type);
|
|
|
|
}
|
2013-12-09 22:54:42 +07:00
|
|
|
subsys_initcall(vme_init);
|