2009-07-31 15:28:17 +07:00
|
|
|
/*
|
|
|
|
* Support for the Tundra Universe I/II VME-PCI Bridge Chips
|
|
|
|
*
|
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.
|
|
|
|
*
|
|
|
|
* Derived from ca91c042.c by Michael Wyrick
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock.h>
|
2009-10-13 05:00:08 +07:00
|
|
|
#include <linux/sched.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>
|
2010-03-22 21:58:57 +07:00
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.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"
|
|
|
|
#include "vme_ca91cx42.h"
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
static int ca91cx42_probe(struct pci_dev *, const struct pci_device_id *);
|
|
|
|
static void ca91cx42_remove(struct pci_dev *);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-12-15 15:42:56 +07:00
|
|
|
/* Module parameters */
|
|
|
|
static int geoid;
|
|
|
|
|
2011-06-03 16:07:39 +07:00
|
|
|
static const char driver_name[] = "vme_ca91cx42";
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2013-12-03 06:29:48 +07:00
|
|
|
static const struct pci_device_id ca91cx42_ids[] = {
|
2009-08-27 23:00:40 +07:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_CA91C142) },
|
|
|
|
{ },
|
2009-07-31 15:28:17 +07:00
|
|
|
};
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
static struct pci_driver ca91cx42_driver = {
|
|
|
|
.name = driver_name,
|
|
|
|
.id_table = ca91cx42_ids,
|
|
|
|
.probe = ca91cx42_probe,
|
|
|
|
.remove = ca91cx42_remove,
|
2009-07-31 15:28:17 +07:00
|
|
|
};
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static u32 ca91cx42_DMA_irqhandler(struct ca91cx42_driver *bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2010-11-12 18:14:07 +07:00
|
|
|
wake_up(&bridge->dma_queue);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return CA91CX42_LINT_DMA;
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static u32 ca91cx42_LM_irqhandler(struct ca91cx42_driver *bridge, u32 stat)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 serviced = 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (stat & CA91CX42_LINT_LM[i]) {
|
|
|
|
/* We only enable interrupts if the callback is set */
|
2010-02-18 22:13:05 +07:00
|
|
|
bridge->lm_callback[i](i);
|
2009-08-27 23:00:40 +07:00
|
|
|
serviced |= CA91CX42_LINT_LM[i];
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return serviced;
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* XXX This needs to be split into 4 queues */
|
2010-02-18 22:13:05 +07:00
|
|
|
static u32 ca91cx42_MB_irqhandler(struct ca91cx42_driver *bridge, int mbox_mask)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
2010-11-12 18:14:07 +07:00
|
|
|
wake_up(&bridge->mbox_queue);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return CA91CX42_LINT_MBOX;
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static u32 ca91cx42_IACK_irqhandler(struct ca91cx42_driver *bridge)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
2010-11-12 18:14:07 +07:00
|
|
|
wake_up(&bridge->iack_queue);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return CA91CX42_LINT_SW_IACK;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
static u32 ca91cx42_VERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
int val;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
val = ioread32(bridge->base + DGCS);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
if (!(val & 0x00000800)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "ca91cx42_VERR_irqhandler DMA "
|
|
|
|
"Read Error DGCS=%08X\n", val);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return CA91CX42_LINT_VERR;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
static u32 ca91cx42_LERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
|
|
|
int val;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
val = ioread32(bridge->base + DGCS);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
if (!(val & 0x00000800))
|
|
|
|
dev_err(ca91cx42_bridge->parent, "ca91cx42_LERR_irqhandler DMA "
|
|
|
|
"Read Error DGCS=%08X\n", val);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return CA91CX42_LINT_LERR;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static u32 ca91cx42_VIRQ_irqhandler(struct vme_bridge *ca91cx42_bridge,
|
|
|
|
int stat)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
int vec, i, serviced = 0;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
for (i = 7; i > 0; i--) {
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & (1 << i)) {
|
2010-02-18 22:13:05 +07:00
|
|
|
vec = ioread32(bridge->base +
|
2009-08-27 23:00:40 +07:00
|
|
|
CA91CX42_V_STATID[i]) & 0xff;
|
|
|
|
|
2009-10-29 23:34:54 +07:00
|
|
|
vme_irq_handler(ca91cx42_bridge, i, vec);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
serviced |= (1 << i);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return serviced;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static irqreturn_t ca91cx42_irqhandler(int irq, void *ptr)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
u32 stat, enable, serviced = 0;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
|
|
|
struct ca91cx42_driver *bridge;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
ca91cx42_bridge = ptr;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
|
|
|
|
|
|
|
enable = ioread32(bridge->base + LINT_EN);
|
|
|
|
stat = ioread32(bridge->base + LINT_STAT);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Only look at unmasked interrupts */
|
|
|
|
stat &= enable;
|
|
|
|
|
|
|
|
if (unlikely(!stat))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
if (stat & CA91CX42_LINT_DMA)
|
2010-02-18 22:13:05 +07:00
|
|
|
serviced |= ca91cx42_DMA_irqhandler(bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
|
|
|
|
CA91CX42_LINT_LM3))
|
2010-02-18 22:13:05 +07:00
|
|
|
serviced |= ca91cx42_LM_irqhandler(bridge, stat);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & CA91CX42_LINT_MBOX)
|
2010-02-18 22:13:05 +07:00
|
|
|
serviced |= ca91cx42_MB_irqhandler(bridge, stat);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & CA91CX42_LINT_SW_IACK)
|
2010-02-18 22:13:05 +07:00
|
|
|
serviced |= ca91cx42_IACK_irqhandler(bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & CA91CX42_LINT_VERR)
|
2010-03-22 21:58:50 +07:00
|
|
|
serviced |= ca91cx42_VERR_irqhandler(ca91cx42_bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & CA91CX42_LINT_LERR)
|
2010-03-22 21:58:50 +07:00
|
|
|
serviced |= ca91cx42_LERR_irqhandler(ca91cx42_bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (stat & (CA91CX42_LINT_VIRQ1 | CA91CX42_LINT_VIRQ2 |
|
|
|
|
CA91CX42_LINT_VIRQ3 | CA91CX42_LINT_VIRQ4 |
|
|
|
|
CA91CX42_LINT_VIRQ5 | CA91CX42_LINT_VIRQ6 |
|
|
|
|
CA91CX42_LINT_VIRQ7))
|
2010-02-18 22:13:05 +07:00
|
|
|
serviced |= ca91cx42_VIRQ_irqhandler(ca91cx42_bridge, stat);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Clear serviced interrupts */
|
2011-06-02 17:30:02 +07:00
|
|
|
iowrite32(serviced, bridge->base + LINT_STAT);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static int ca91cx42_irq_init(struct vme_bridge *ca91cx42_bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
int result, tmp;
|
|
|
|
struct pci_dev *pdev;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Need pdev */
|
2015-12-27 17:46:04 +07:00
|
|
|
pdev = to_pci_dev(ca91cx42_bridge->parent);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Disable interrupts from PCI to VME */
|
|
|
|
iowrite32(0, bridge->base + VINT_EN);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Disable PCI interrupts */
|
|
|
|
iowrite32(0, bridge->base + LINT_EN);
|
|
|
|
/* Clear Any Pending PCI Interrupts */
|
|
|
|
iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
result = request_irq(pdev->irq, ca91cx42_irqhandler, IRQF_SHARED,
|
2010-02-18 22:13:05 +07:00
|
|
|
driver_name, ca91cx42_bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (result) {
|
|
|
|
dev_err(&pdev->dev, "Can't get assigned pci irq vector %02X\n",
|
|
|
|
pdev->irq);
|
|
|
|
return result;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Ensure all interrupts are mapped to PCI Interrupt 0 */
|
|
|
|
iowrite32(0, bridge->base + LINT_MAP0);
|
|
|
|
iowrite32(0, bridge->base + LINT_MAP1);
|
|
|
|
iowrite32(0, bridge->base + LINT_MAP2);
|
|
|
|
|
|
|
|
/* Enable DMA, mailbox & LM Interrupts */
|
|
|
|
tmp = CA91CX42_LINT_MBOX3 | CA91CX42_LINT_MBOX2 | CA91CX42_LINT_MBOX1 |
|
|
|
|
CA91CX42_LINT_MBOX0 | CA91CX42_LINT_SW_IACK |
|
|
|
|
CA91CX42_LINT_VERR | CA91CX42_LINT_LERR | CA91CX42_LINT_DMA;
|
|
|
|
|
|
|
|
iowrite32(tmp, bridge->base + LINT_EN);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static void ca91cx42_irq_exit(struct ca91cx42_driver *bridge,
|
|
|
|
struct pci_dev *pdev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2013-08-26 11:04:05 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Disable interrupts from PCI to VME */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0, bridge->base + VINT_EN);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Disable PCI interrupts */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0, bridge->base + LINT_EN);
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Clear Any Pending PCI Interrupts */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2013-08-26 11:04:05 +07:00
|
|
|
ca91cx42_bridge = container_of((void *)bridge, struct vme_bridge,
|
|
|
|
driver_priv);
|
|
|
|
free_irq(pdev->irq, ca91cx42_bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2011-06-09 14:59:43 +07:00
|
|
|
static int ca91cx42_iack_received(struct ca91cx42_driver *bridge, int level)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
tmp = ioread32(bridge->base + LINT_STAT);
|
|
|
|
|
|
|
|
if (tmp & (1 << level))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/*
|
|
|
|
* Set up an VME interrupt
|
|
|
|
*/
|
2010-11-12 18:15:07 +07:00
|
|
|
static void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level,
|
|
|
|
int state, int sync)
|
2009-10-29 23:34:54 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
2009-10-29 23:34:54 +07:00
|
|
|
struct pci_dev *pdev;
|
2009-08-27 23:00:40 +07:00
|
|
|
u32 tmp;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Enable IRQ level */
|
2010-02-18 22:13:05 +07:00
|
|
|
tmp = ioread32(bridge->base + LINT_EN);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2009-10-29 23:34:54 +07:00
|
|
|
if (state == 0)
|
2009-08-27 23:00:40 +07:00
|
|
|
tmp &= ~CA91CX42_LINT_VIRQ[level];
|
2009-10-29 23:34:54 +07:00
|
|
|
else
|
|
|
|
tmp |= CA91CX42_LINT_VIRQ[level];
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(tmp, bridge->base + LINT_EN);
|
2009-10-29 23:34:54 +07:00
|
|
|
|
|
|
|
if ((state == 0) && (sync != 0)) {
|
2015-12-27 17:46:04 +07:00
|
|
|
pdev = to_pci_dev(ca91cx42_bridge->parent);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
synchronize_irq(pdev->irq);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
|
2010-02-18 22:13:05 +07:00
|
|
|
int statid)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
u32 tmp;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Universe can only generate even vectors */
|
|
|
|
if (statid & 1)
|
|
|
|
return -EINVAL;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&bridge->vme_int);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
tmp = ioread32(bridge->base + VINT_EN);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Set Status/ID */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(statid << 24, bridge->base + STATID);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Assert VMEbus IRQ */
|
|
|
|
tmp = tmp | (1 << (level + 24));
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(tmp, bridge->base + VINT_EN);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Wait for IACK */
|
2011-06-09 14:59:43 +07:00
|
|
|
wait_event_interruptible(bridge->iack_queue,
|
|
|
|
ca91cx42_iack_received(bridge, level));
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Return interrupt to low state */
|
2010-02-18 22:13:05 +07:00
|
|
|
tmp = ioread32(bridge->base + VINT_EN);
|
2009-08-27 23:00:40 +07:00
|
|
|
tmp = tmp & ~(1 << (level + 24));
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(tmp, bridge->base + VINT_EN);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&bridge->vme_int);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled,
|
2009-08-27 23:00:40 +07:00
|
|
|
unsigned long long vme_base, unsigned long long size,
|
2011-12-02 00:06:29 +07:00
|
|
|
dma_addr_t pci_base, u32 aspace, u32 cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2010-02-18 22:13:32 +07:00
|
|
|
unsigned int i, addr = 0, granularity;
|
2009-08-27 23:00:40 +07:00
|
|
|
unsigned int temp_ctl = 0;
|
|
|
|
unsigned int vme_bound, pci_offset;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
ca91cx42_bridge = image->parent;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
i = image->number;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
switch (aspace) {
|
|
|
|
case VME_A16:
|
|
|
|
addr |= CA91CX42_VSI_CTL_VAS_A16;
|
|
|
|
break;
|
|
|
|
case VME_A24:
|
|
|
|
addr |= CA91CX42_VSI_CTL_VAS_A24;
|
|
|
|
break;
|
|
|
|
case VME_A32:
|
|
|
|
addr |= CA91CX42_VSI_CTL_VAS_A32;
|
|
|
|
break;
|
|
|
|
case VME_USER1:
|
|
|
|
addr |= CA91CX42_VSI_CTL_VAS_USER1;
|
|
|
|
break;
|
|
|
|
case VME_USER2:
|
|
|
|
addr |= CA91CX42_VSI_CTL_VAS_USER2;
|
|
|
|
break;
|
|
|
|
case VME_A64:
|
|
|
|
case VME_CRCSR:
|
|
|
|
case VME_USER3:
|
|
|
|
case VME_USER4:
|
|
|
|
default:
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/*
|
|
|
|
* Bound address is a valid address for the window, adjust
|
|
|
|
* accordingly
|
|
|
|
*/
|
2010-02-18 22:13:32 +07:00
|
|
|
vme_bound = vme_base + size;
|
2009-08-27 23:00:40 +07:00
|
|
|
pci_offset = pci_base - vme_base;
|
|
|
|
|
|
|
|
if ((i == 0) || (i == 4))
|
|
|
|
granularity = 0x1000;
|
|
|
|
else
|
|
|
|
granularity = 0x10000;
|
|
|
|
|
|
|
|
if (vme_base & (granularity - 1)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid VME base "
|
|
|
|
"alignment\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (vme_bound & (granularity - 1)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid VME bound "
|
|
|
|
"alignment\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (pci_offset & (granularity - 1)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid PCI Offset "
|
|
|
|
"alignment\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
return -EINVAL;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Disable while we are mucking around */
|
2010-02-18 22:13:05 +07:00
|
|
|
temp_ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl &= ~CA91CX42_VSI_CTL_EN;
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Setup mapping */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(vme_base, bridge->base + CA91CX42_VSI_BS[i]);
|
|
|
|
iowrite32(vme_bound, bridge->base + CA91CX42_VSI_BD[i]);
|
|
|
|
iowrite32(pci_offset, bridge->base + CA91CX42_VSI_TO[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Setup address space */
|
|
|
|
temp_ctl &= ~CA91CX42_VSI_CTL_VAS_M;
|
|
|
|
temp_ctl |= addr;
|
|
|
|
|
|
|
|
/* Setup cycle types */
|
|
|
|
temp_ctl &= ~(CA91CX42_VSI_CTL_PGM_M | CA91CX42_VSI_CTL_SUPER_M);
|
|
|
|
if (cycle & VME_SUPER)
|
|
|
|
temp_ctl |= CA91CX42_VSI_CTL_SUPER_SUPR;
|
|
|
|
if (cycle & VME_USER)
|
|
|
|
temp_ctl |= CA91CX42_VSI_CTL_SUPER_NPRIV;
|
|
|
|
if (cycle & VME_PROG)
|
|
|
|
temp_ctl |= CA91CX42_VSI_CTL_PGM_PGM;
|
|
|
|
if (cycle & VME_DATA)
|
|
|
|
temp_ctl |= CA91CX42_VSI_CTL_PGM_DATA;
|
|
|
|
|
|
|
|
/* Write ctl reg without enable */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
temp_ctl |= CA91CX42_VSI_CTL_EN;
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_slave_get(struct vme_slave_resource *image, int *enabled,
|
2009-08-27 23:00:40 +07:00
|
|
|
unsigned long long *vme_base, unsigned long long *size,
|
2011-12-02 00:06:29 +07:00
|
|
|
dma_addr_t *pci_base, u32 *aspace, u32 *cycle)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
unsigned int i, granularity = 0, ctl = 0;
|
|
|
|
unsigned long long vme_bound, pci_offset;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = image->parent->driver_priv;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
i = image->number;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
if ((i == 0) || (i == 4))
|
|
|
|
granularity = 0x1000;
|
|
|
|
else
|
|
|
|
granularity = 0x10000;
|
|
|
|
|
|
|
|
/* Read Registers */
|
2010-02-18 22:13:05 +07:00
|
|
|
ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
*vme_base = ioread32(bridge->base + CA91CX42_VSI_BS[i]);
|
|
|
|
vme_bound = ioread32(bridge->base + CA91CX42_VSI_BD[i]);
|
|
|
|
pci_offset = ioread32(bridge->base + CA91CX42_VSI_TO[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
*pci_base = (dma_addr_t)vme_base + pci_offset;
|
|
|
|
*size = (unsigned long long)((vme_bound - *vme_base) + granularity);
|
|
|
|
|
|
|
|
*enabled = 0;
|
|
|
|
*aspace = 0;
|
|
|
|
*cycle = 0;
|
|
|
|
|
|
|
|
if (ctl & CA91CX42_VSI_CTL_EN)
|
|
|
|
*enabled = 1;
|
|
|
|
|
|
|
|
if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A16)
|
|
|
|
*aspace = VME_A16;
|
|
|
|
if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A24)
|
|
|
|
*aspace = VME_A24;
|
|
|
|
if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A32)
|
|
|
|
*aspace = VME_A32;
|
|
|
|
if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER1)
|
|
|
|
*aspace = VME_USER1;
|
|
|
|
if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER2)
|
|
|
|
*aspace = VME_USER2;
|
|
|
|
|
|
|
|
if (ctl & CA91CX42_VSI_CTL_SUPER_SUPR)
|
|
|
|
*cycle |= VME_SUPER;
|
|
|
|
if (ctl & CA91CX42_VSI_CTL_SUPER_NPRIV)
|
|
|
|
*cycle |= VME_USER;
|
|
|
|
if (ctl & CA91CX42_VSI_CTL_PGM_PGM)
|
|
|
|
*cycle |= VME_PROG;
|
|
|
|
if (ctl & CA91CX42_VSI_CTL_PGM_DATA)
|
|
|
|
*cycle |= VME_DATA;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and map PCI Resource
|
|
|
|
*/
|
|
|
|
static int ca91cx42_alloc_resource(struct vme_master_resource *image,
|
|
|
|
unsigned long long size)
|
|
|
|
{
|
|
|
|
unsigned long long existing_size;
|
|
|
|
int retval = 0;
|
|
|
|
struct pci_dev *pdev;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
|
|
|
|
|
|
|
ca91cx42_bridge = image->parent;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Find pci_dev container of dev */
|
|
|
|
if (ca91cx42_bridge->parent == NULL) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Dev entry NULL\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-12-27 17:46:04 +07:00
|
|
|
pdev = to_pci_dev(ca91cx42_bridge->parent);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:12 +07:00
|
|
|
existing_size = (unsigned long long)(image->bus_resource.end -
|
|
|
|
image->bus_resource.start);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* If the existing size is OK, return */
|
|
|
|
if (existing_size == (size - 1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (existing_size != 0) {
|
|
|
|
iounmap(image->kern_base);
|
|
|
|
image->kern_base = NULL;
|
2011-03-13 12:29:13 +07:00
|
|
|
kfree(image->bus_resource.name);
|
2010-11-12 18:14:07 +07:00
|
|
|
release_resource(&image->bus_resource);
|
|
|
|
memset(&image->bus_resource, 0, sizeof(struct resource));
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:12 +07:00
|
|
|
if (image->bus_resource.name == NULL) {
|
2010-05-31 03:27:46 +07:00
|
|
|
image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC);
|
2010-02-18 22:13:12 +07:00
|
|
|
if (image->bus_resource.name == NULL) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Unable to allocate "
|
|
|
|
"memory for resource name\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_name;
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:12 +07:00
|
|
|
sprintf((char *)image->bus_resource.name, "%s.%d",
|
2009-08-27 23:00:40 +07:00
|
|
|
ca91cx42_bridge->name, image->number);
|
|
|
|
|
2010-02-18 22:13:12 +07:00
|
|
|
image->bus_resource.start = 0;
|
|
|
|
image->bus_resource.end = (unsigned long)size;
|
|
|
|
image->bus_resource.flags = IORESOURCE_MEM;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
retval = pci_bus_alloc_resource(pdev->bus,
|
2015-07-08 21:42:17 +07:00
|
|
|
&image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
|
2009-08-27 23:00:40 +07:00
|
|
|
0, NULL, NULL);
|
|
|
|
if (retval) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Failed to allocate mem "
|
|
|
|
"resource for window %d size 0x%lx start 0x%lx\n",
|
2009-08-27 23:00:40 +07:00
|
|
|
image->number, (unsigned long)size,
|
2010-02-18 22:13:12 +07:00
|
|
|
(unsigned long)image->bus_resource.start);
|
2009-08-27 23:00:40 +07:00
|
|
|
goto err_resource;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
image->kern_base = ioremap_nocache(
|
2010-02-18 22:13:12 +07:00
|
|
|
image->bus_resource.start, size);
|
2009-08-27 23:00:40 +07:00
|
|
|
if (image->kern_base == NULL) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Failed to remap resource\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_remap;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_remap:
|
2010-11-12 18:14:07 +07:00
|
|
|
release_resource(&image->bus_resource);
|
2009-08-27 23:00:40 +07:00
|
|
|
err_resource:
|
2010-02-18 22:13:12 +07:00
|
|
|
kfree(image->bus_resource.name);
|
2010-11-12 18:14:07 +07:00
|
|
|
memset(&image->bus_resource, 0, sizeof(struct resource));
|
2009-08-27 23:00:40 +07:00
|
|
|
err_name:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-02-18 22:13:25 +07:00
|
|
|
* Free and unmap PCI Resource
|
|
|
|
*/
|
2009-08-27 23:00:40 +07:00
|
|
|
static void ca91cx42_free_resource(struct vme_master_resource *image)
|
|
|
|
{
|
|
|
|
iounmap(image->kern_base);
|
|
|
|
image->kern_base = NULL;
|
2010-11-12 18:14:07 +07:00
|
|
|
release_resource(&image->bus_resource);
|
2010-02-18 22:13:12 +07:00
|
|
|
kfree(image->bus_resource.name);
|
2010-11-12 18:14:07 +07:00
|
|
|
memset(&image->bus_resource, 0, sizeof(struct resource));
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_master_set(struct vme_master_resource *image, 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-08-27 23:00:40 +07:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2010-02-18 22:13:32 +07:00
|
|
|
unsigned int i, granularity = 0;
|
2009-08-27 23:00:40 +07:00
|
|
|
unsigned int temp_ctl = 0;
|
|
|
|
unsigned long long pci_bound, vme_offset, pci_base;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
ca91cx42_bridge = image->parent;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:32 +07:00
|
|
|
i = image->number;
|
|
|
|
|
|
|
|
if ((i == 0) || (i == 4))
|
|
|
|
granularity = 0x1000;
|
|
|
|
else
|
|
|
|
granularity = 0x10000;
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Verify input data */
|
2010-02-18 22:13:32 +07:00
|
|
|
if (vme_base & (granularity - 1)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
|
|
|
|
"alignment\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_window;
|
|
|
|
}
|
2010-02-18 22:13:32 +07:00
|
|
|
if (size & (granularity - 1)) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
|
|
|
|
"alignment\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_window;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let's allocate the resource here rather than further up the stack as
|
2011-03-31 08:57:33 +07:00
|
|
|
* it avoids pushing loads of bus dependent stuff up the stack
|
2009-08-27 23:00:40 +07:00
|
|
|
*/
|
|
|
|
retval = ca91cx42_alloc_resource(image, size);
|
|
|
|
if (retval) {
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Unable to allocate memory "
|
|
|
|
"for resource name\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_res;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:12 +07:00
|
|
|
pci_base = (unsigned long long)image->bus_resource.start;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bound address is a valid address for the window, adjust
|
|
|
|
* according to window granularity.
|
|
|
|
*/
|
2010-02-18 22:13:32 +07:00
|
|
|
pci_bound = pci_base + size;
|
2009-08-27 23:00:40 +07:00
|
|
|
vme_offset = vme_base - pci_base;
|
|
|
|
|
|
|
|
/* Disable while we are mucking around */
|
2010-02-18 22:13:05 +07:00
|
|
|
temp_ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl &= ~CA91CX42_LSI_CTL_EN;
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Setup cycle types */
|
|
|
|
temp_ctl &= ~CA91CX42_LSI_CTL_VCT_M;
|
|
|
|
if (cycle & VME_BLT)
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VCT_BLT;
|
|
|
|
if (cycle & VME_MBLT)
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VCT_MBLT;
|
|
|
|
|
|
|
|
/* Setup data width */
|
|
|
|
temp_ctl &= ~CA91CX42_LSI_CTL_VDW_M;
|
|
|
|
switch (dwidth) {
|
|
|
|
case VME_D8:
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VDW_D8;
|
|
|
|
break;
|
|
|
|
case VME_D16:
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VDW_D16;
|
|
|
|
break;
|
|
|
|
case VME_D32:
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VDW_D32;
|
|
|
|
break;
|
|
|
|
case VME_D64:
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VDW_D64;
|
|
|
|
break;
|
|
|
|
default:
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid data width\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_dwidth;
|
|
|
|
break;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Setup address space */
|
|
|
|
temp_ctl &= ~CA91CX42_LSI_CTL_VAS_M;
|
|
|
|
switch (aspace) {
|
2009-07-31 15:28:17 +07:00
|
|
|
case VME_A16:
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_A16;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
case VME_A24:
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_A24;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
case VME_A32:
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_A32;
|
|
|
|
break;
|
|
|
|
case VME_CRCSR:
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_CRCSR;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
case VME_USER1:
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_USER1;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
case VME_USER2:
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_VAS_USER2;
|
|
|
|
break;
|
|
|
|
case VME_A64:
|
|
|
|
case VME_USER3:
|
|
|
|
case VME_USER4:
|
|
|
|
default:
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_aspace;
|
2009-07-31 15:28:17 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
temp_ctl &= ~(CA91CX42_LSI_CTL_PGM_M | CA91CX42_LSI_CTL_SUPER_M);
|
|
|
|
if (cycle & VME_SUPER)
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_SUPER_SUPR;
|
|
|
|
if (cycle & VME_PROG)
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_PGM_PGM;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Setup mapping */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(pci_base, bridge->base + CA91CX42_LSI_BS[i]);
|
|
|
|
iowrite32(pci_bound, bridge->base + CA91CX42_LSI_BD[i]);
|
|
|
|
iowrite32(vme_offset, bridge->base + CA91CX42_LSI_TO[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Write ctl reg without enable */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
temp_ctl |= CA91CX42_LSI_CTL_EN;
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_aspace:
|
|
|
|
err_dwidth:
|
|
|
|
ca91cx42_free_resource(image);
|
|
|
|
err_res:
|
|
|
|
err_window:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int __ca91cx42_master_get(struct vme_master_resource *image,
|
|
|
|
int *enabled, unsigned long long *vme_base, unsigned long long *size,
|
2011-12-02 00:06:29 +07:00
|
|
|
u32 *aspace, u32 *cycle, u32 *dwidth)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
|
|
|
unsigned int i, ctl;
|
|
|
|
unsigned long long pci_base, pci_bound, vme_offset;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = image->parent->driver_priv;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
i = image->number;
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
pci_base = ioread32(bridge->base + CA91CX42_LSI_BS[i]);
|
|
|
|
vme_offset = ioread32(bridge->base + CA91CX42_LSI_TO[i]);
|
|
|
|
pci_bound = ioread32(bridge->base + CA91CX42_LSI_BD[i]);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
*vme_base = pci_base + vme_offset;
|
2010-02-18 22:13:32 +07:00
|
|
|
*size = (unsigned long long)(pci_bound - pci_base);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
*enabled = 0;
|
|
|
|
*aspace = 0;
|
|
|
|
*cycle = 0;
|
|
|
|
*dwidth = 0;
|
|
|
|
|
|
|
|
if (ctl & CA91CX42_LSI_CTL_EN)
|
|
|
|
*enabled = 1;
|
|
|
|
|
|
|
|
/* Setup address space */
|
|
|
|
switch (ctl & CA91CX42_LSI_CTL_VAS_M) {
|
|
|
|
case CA91CX42_LSI_CTL_VAS_A16:
|
|
|
|
*aspace = VME_A16;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VAS_A24:
|
|
|
|
*aspace = VME_A24;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VAS_A32:
|
|
|
|
*aspace = VME_A32;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VAS_CRCSR:
|
|
|
|
*aspace = VME_CRCSR;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VAS_USER1:
|
|
|
|
*aspace = VME_USER1;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VAS_USER2:
|
|
|
|
*aspace = VME_USER2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX Not sure howto check for MBLT */
|
|
|
|
/* Setup cycle types */
|
|
|
|
if (ctl & CA91CX42_LSI_CTL_VCT_BLT)
|
|
|
|
*cycle |= VME_BLT;
|
|
|
|
else
|
|
|
|
*cycle |= VME_SCT;
|
|
|
|
|
|
|
|
if (ctl & CA91CX42_LSI_CTL_SUPER_SUPR)
|
|
|
|
*cycle |= VME_SUPER;
|
|
|
|
else
|
|
|
|
*cycle |= VME_USER;
|
|
|
|
|
|
|
|
if (ctl & CA91CX42_LSI_CTL_PGM_PGM)
|
|
|
|
*cycle = VME_PROG;
|
|
|
|
else
|
|
|
|
*cycle = VME_DATA;
|
|
|
|
|
|
|
|
/* Setup data width */
|
|
|
|
switch (ctl & CA91CX42_LSI_CTL_VDW_M) {
|
|
|
|
case CA91CX42_LSI_CTL_VDW_D8:
|
|
|
|
*dwidth = VME_D8;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VDW_D16:
|
|
|
|
*dwidth = VME_D16;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VDW_D32:
|
|
|
|
*dwidth = VME_D32;
|
|
|
|
break;
|
|
|
|
case CA91CX42_LSI_CTL_VDW_D64:
|
|
|
|
*dwidth = VME_D64;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_master_get(struct vme_master_resource *image, 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-08-27 23:00:40 +07:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace,
|
|
|
|
cycle, dwidth);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static ssize_t ca91cx42_master_read(struct vme_master_resource *image,
|
|
|
|
void *buf, size_t count, loff_t offset)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
2010-02-18 22:13:32 +07:00
|
|
|
ssize_t retval;
|
2013-08-19 14:39:40 +07:00
|
|
|
void __iomem *addr = image->kern_base + offset;
|
2010-09-25 00:26:13 +07:00
|
|
|
unsigned int done = 0;
|
|
|
|
unsigned int count32;
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2014-02-06 20:35:36 +07:00
|
|
|
/* The following code handles VME address alignment. We cannot use
|
|
|
|
* memcpy_xxx here because it may cut data transfers in to 8-bit
|
|
|
|
* cycles when D16 or D32 cycles are required on the VME bus.
|
|
|
|
* On the other hand, the bridge itself assures that the maximum data
|
|
|
|
* cycle configured for the transfer is used and splits it
|
|
|
|
* automatically for non-aligned addresses, so we don't want the
|
|
|
|
* overhead of needlessly forcing small transfers for the entire cycle.
|
2010-09-25 00:26:13 +07:00
|
|
|
*/
|
2011-11-02 22:50:39 +07:00
|
|
|
if ((uintptr_t)addr & 0x1) {
|
2010-09-25 00:26:13 +07:00
|
|
|
*(u8 *)buf = ioread8(addr);
|
|
|
|
done += 1;
|
|
|
|
if (done == count)
|
|
|
|
goto out;
|
|
|
|
}
|
2014-02-07 22:48:56 +07:00
|
|
|
if ((uintptr_t)(addr + done) & 0x2) {
|
2010-09-25 00:26:13 +07:00
|
|
|
if ((count - done) < 2) {
|
|
|
|
*(u8 *)(buf + done) = ioread8(addr + done);
|
|
|
|
done += 1;
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
*(u16 *)(buf + done) = ioread16(addr + done);
|
|
|
|
done += 2;
|
|
|
|
}
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-09-25 00:26:13 +07:00
|
|
|
count32 = (count - done) & ~0x3;
|
2014-02-06 20:35:36 +07:00
|
|
|
while (done < count32) {
|
|
|
|
*(u32 *)(buf + done) = ioread32(addr + done);
|
|
|
|
done += 4;
|
2010-09-25 00:26:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((count - done) & 0x2) {
|
|
|
|
*(u16 *)(buf + done) = ioread16(addr + done);
|
|
|
|
done += 2;
|
|
|
|
}
|
|
|
|
if ((count - done) & 0x1) {
|
|
|
|
*(u8 *)(buf + done) = ioread8(addr + done);
|
|
|
|
done += 1;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
retval = count;
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
return retval;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static ssize_t ca91cx42_master_write(struct vme_master_resource *image,
|
|
|
|
void *buf, size_t count, loff_t offset)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2010-09-25 00:26:13 +07:00
|
|
|
ssize_t retval;
|
2013-08-19 14:39:40 +07:00
|
|
|
void __iomem *addr = image->kern_base + offset;
|
2010-09-25 00:26:13 +07:00
|
|
|
unsigned int done = 0;
|
|
|
|
unsigned int count32;
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&image->lock);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-09-25 00:26:13 +07:00
|
|
|
/* Here we apply for the same strategy we do in master_read
|
2014-02-06 20:35:36 +07:00
|
|
|
* function in order to assure the correct cycles.
|
2010-09-25 00:26:13 +07:00
|
|
|
*/
|
2011-11-02 22:50:39 +07:00
|
|
|
if ((uintptr_t)addr & 0x1) {
|
2010-09-25 00:26:13 +07:00
|
|
|
iowrite8(*(u8 *)buf, addr);
|
|
|
|
done += 1;
|
|
|
|
if (done == count)
|
|
|
|
goto out;
|
|
|
|
}
|
2014-02-07 22:48:56 +07:00
|
|
|
if ((uintptr_t)(addr + done) & 0x2) {
|
2010-09-25 00:26:13 +07:00
|
|
|
if ((count - done) < 2) {
|
|
|
|
iowrite8(*(u8 *)(buf + done), addr + done);
|
|
|
|
done += 1;
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
iowrite16(*(u16 *)(buf + done), addr + done);
|
|
|
|
done += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count32 = (count - done) & ~0x3;
|
2014-02-06 20:35:36 +07:00
|
|
|
while (done < count32) {
|
|
|
|
iowrite32(*(u32 *)(buf + done), addr + done);
|
|
|
|
done += 4;
|
2010-09-25 00:26:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((count - done) & 0x2) {
|
|
|
|
iowrite16(*(u16 *)(buf + done), addr + done);
|
|
|
|
done += 2;
|
|
|
|
}
|
|
|
|
if ((count - done) & 0x1) {
|
|
|
|
iowrite8(*(u8 *)(buf + done), addr + done);
|
|
|
|
done += 1;
|
|
|
|
}
|
|
|
|
out:
|
2009-08-27 23:00:40 +07:00
|
|
|
retval = count;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return retval;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
|
2010-02-18 22:13:38 +07:00
|
|
|
unsigned int mask, unsigned int compare, unsigned int swap,
|
|
|
|
loff_t offset)
|
|
|
|
{
|
2011-11-02 22:50:39 +07:00
|
|
|
u32 result;
|
|
|
|
uintptr_t pci_addr;
|
2010-02-18 22:13:38 +07:00
|
|
|
int i;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
bridge = image->parent->driver_priv;
|
|
|
|
dev = image->parent->parent;
|
|
|
|
|
|
|
|
/* Find the PCI address that maps to the desired VME address */
|
|
|
|
i = image->number;
|
|
|
|
|
|
|
|
/* Locking as we can only do one of these at a time */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&bridge->vme_rmw);
|
2010-02-18 22:13:38 +07:00
|
|
|
|
|
|
|
/* Lock image */
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock(&image->lock);
|
2010-02-18 22:13:38 +07:00
|
|
|
|
2011-11-02 22:50:39 +07:00
|
|
|
pci_addr = (uintptr_t)image->kern_base + offset;
|
2010-02-18 22:13:38 +07:00
|
|
|
|
|
|
|
/* Address must be 4-byte aligned */
|
|
|
|
if (pci_addr & 0x3) {
|
|
|
|
dev_err(dev, "RMW Address not 4-byte aligned\n");
|
2010-05-26 22:59:11 +07:00
|
|
|
result = -EINVAL;
|
|
|
|
goto out;
|
2010-02-18 22:13:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure RMW Disabled whilst configuring */
|
|
|
|
iowrite32(0, bridge->base + SCYC_CTL);
|
|
|
|
|
|
|
|
/* Configure registers */
|
|
|
|
iowrite32(mask, bridge->base + SCYC_EN);
|
|
|
|
iowrite32(compare, bridge->base + SCYC_CMP);
|
|
|
|
iowrite32(swap, bridge->base + SCYC_SWP);
|
|
|
|
iowrite32(pci_addr, bridge->base + SCYC_ADDR);
|
|
|
|
|
|
|
|
/* Enable RMW */
|
|
|
|
iowrite32(CA91CX42_SCYC_CTL_CYC_RMW, bridge->base + SCYC_CTL);
|
|
|
|
|
|
|
|
/* Kick process off with a read to the required address. */
|
|
|
|
result = ioread32(image->kern_base + offset);
|
|
|
|
|
|
|
|
/* Disable RMW */
|
|
|
|
iowrite32(0, bridge->base + SCYC_CTL);
|
|
|
|
|
2010-05-26 22:59:11 +07:00
|
|
|
out:
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_unlock(&image->lock);
|
2010-02-18 22:13:38 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&bridge->vme_rmw);
|
2010-02-18 22:13:38 +07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_dma_list_add(struct vme_dma_list *list,
|
|
|
|
struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
|
2010-02-18 22:13:25 +07:00
|
|
|
{
|
|
|
|
struct ca91cx42_dma_entry *entry, *prev;
|
|
|
|
struct vme_dma_pci *pci_attr;
|
|
|
|
struct vme_dma_vme *vme_attr;
|
|
|
|
dma_addr_t desc_ptr;
|
|
|
|
int retval = 0;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
dev = list->parent->parent->parent;
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
/* XXX descriptor must be aligned on 64-bit boundaries */
|
2010-05-12 01:26:57 +07:00
|
|
|
entry = kmalloc(sizeof(struct ca91cx42_dma_entry), GFP_KERNEL);
|
2010-02-18 22:13:25 +07:00
|
|
|
if (entry == NULL) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Failed to allocate memory for dma resource "
|
2010-02-18 22:13:25 +07:00
|
|
|
"structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test descriptor alignment */
|
2010-11-12 18:14:07 +07:00
|
|
|
if ((unsigned long)&entry->descriptor & CA91CX42_DCPP_M) {
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Descriptor not aligned to 16 byte boundary as "
|
2010-11-12 18:14:07 +07:00
|
|
|
"required: %p\n", &entry->descriptor);
|
2010-02-18 22:13:25 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_align;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
memset(&entry->descriptor, 0, sizeof(struct ca91cx42_dma_descriptor));
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
if (dest->type == VME_DMA_VME) {
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_L2V;
|
2010-06-29 17:16:16 +07:00
|
|
|
vme_attr = dest->private;
|
|
|
|
pci_attr = src->private;
|
2010-02-18 22:13:25 +07:00
|
|
|
} else {
|
2010-06-29 17:16:16 +07:00
|
|
|
vme_attr = src->private;
|
|
|
|
pci_attr = dest->private;
|
2010-02-18 22:13:25 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Check we can do fulfill required attributes */
|
2010-02-18 22:13:25 +07:00
|
|
|
if ((vme_attr->aspace & ~(VME_A16 | VME_A24 | VME_A32 | VME_USER1 |
|
|
|
|
VME_USER2)) != 0) {
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Unsupported cycle type\n");
|
2010-02-18 22:13:25 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_aspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vme_attr->cycle & ~(VME_SCT | VME_BLT | VME_SUPER | VME_USER |
|
|
|
|
VME_PROG | VME_DATA)) != 0) {
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Unsupported cycle type\n");
|
2010-02-18 22:13:25 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_cycle;
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Check to see if we can fulfill source and destination */
|
2010-02-18 22:13:25 +07:00
|
|
|
if (!(((src->type == VME_DMA_PCI) && (dest->type == VME_DMA_VME)) ||
|
|
|
|
((src->type == VME_DMA_VME) && (dest->type == VME_DMA_PCI)))) {
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Cannot perform transfer with this "
|
2010-02-18 22:13:25 +07:00
|
|
|
"source-destination combination\n");
|
|
|
|
retval = -EINVAL;
|
|
|
|
goto err_direct;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup cycle types */
|
|
|
|
if (vme_attr->cycle & VME_BLT)
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VCT_BLT;
|
|
|
|
|
|
|
|
/* Setup data width */
|
|
|
|
switch (vme_attr->dwidth) {
|
|
|
|
case VME_D8:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D8;
|
|
|
|
break;
|
|
|
|
case VME_D16:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D16;
|
|
|
|
break;
|
|
|
|
case VME_D32:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D32;
|
|
|
|
break;
|
|
|
|
case VME_D64:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D64;
|
|
|
|
break;
|
|
|
|
default:
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Invalid data width\n");
|
2010-02-18 22:13:25 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup address space */
|
|
|
|
switch (vme_attr->aspace) {
|
|
|
|
case VME_A16:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A16;
|
|
|
|
break;
|
|
|
|
case VME_A24:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A24;
|
|
|
|
break;
|
|
|
|
case VME_A32:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A32;
|
|
|
|
break;
|
|
|
|
case VME_USER1:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER1;
|
|
|
|
break;
|
|
|
|
case VME_USER2:
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER2;
|
|
|
|
break;
|
|
|
|
default:
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "Invalid address space\n");
|
2010-02-18 22:13:25 +07:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vme_attr->cycle & VME_SUPER)
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_SUPER_SUPR;
|
|
|
|
if (vme_attr->cycle & VME_PROG)
|
|
|
|
entry->descriptor.dctl |= CA91CX42_DCTL_PGM_PGM;
|
|
|
|
|
|
|
|
entry->descriptor.dtbc = count;
|
|
|
|
entry->descriptor.dla = pci_attr->address;
|
|
|
|
entry->descriptor.dva = vme_attr->address;
|
|
|
|
entry->descriptor.dcpp = CA91CX42_DCPP_NULL;
|
|
|
|
|
|
|
|
/* Add to list */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_add_tail(&entry->list, &list->entries);
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
/* Fill out previous descriptors "Next Address" */
|
2010-11-12 18:14:07 +07:00
|
|
|
if (entry->list.prev != &list->entries) {
|
2010-02-18 22:13:25 +07:00
|
|
|
prev = list_entry(entry->list.prev, struct ca91cx42_dma_entry,
|
|
|
|
list);
|
|
|
|
/* We need the bus address for the pointer */
|
2010-11-12 18:14:07 +07:00
|
|
|
desc_ptr = virt_to_bus(&entry->descriptor);
|
2010-02-18 22:13:25 +07:00
|
|
|
prev->descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_cycle:
|
|
|
|
err_aspace:
|
|
|
|
err_direct:
|
|
|
|
err_align:
|
|
|
|
kfree(entry);
|
|
|
|
err_mem:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ca91cx42_dma_busy(struct vme_bridge *ca91cx42_bridge)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
|
|
|
|
|
|
|
tmp = ioread32(bridge->base + DGCS);
|
|
|
|
|
|
|
|
if (tmp & CA91CX42_DGCS_ACT)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_dma_list_exec(struct vme_dma_list *list)
|
2010-02-18 22:13:25 +07:00
|
|
|
{
|
|
|
|
struct vme_dma_resource *ctrlr;
|
|
|
|
struct ca91cx42_dma_entry *entry;
|
2015-05-28 19:07:01 +07:00
|
|
|
int retval;
|
2010-02-18 22:13:25 +07:00
|
|
|
dma_addr_t bus_addr;
|
|
|
|
u32 val;
|
2010-03-22 21:58:50 +07:00
|
|
|
struct device *dev;
|
2010-02-18 22:13:25 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
ctrlr = list->parent;
|
|
|
|
|
|
|
|
bridge = ctrlr->parent->driver_priv;
|
2010-03-22 21:58:50 +07:00
|
|
|
dev = ctrlr->parent->parent;
|
2010-02-18 22:13:25 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&ctrlr->mtx);
|
2010-02-18 22:13:25 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
if (!(list_empty(&ctrlr->running))) {
|
2010-02-18 22:13:25 +07:00
|
|
|
/*
|
|
|
|
* XXX We have an active DMA transfer and currently haven't
|
|
|
|
* sorted out the mechanism for "pending" DMA transfers.
|
|
|
|
* Return busy.
|
|
|
|
*/
|
|
|
|
/* Need to add to pending here */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&ctrlr->mtx);
|
2010-02-18 22:13:25 +07:00
|
|
|
return -EBUSY;
|
|
|
|
} else {
|
2010-11-12 18:14:07 +07:00
|
|
|
list_add(&list->list, &ctrlr->running);
|
2010-02-18 22:13:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get first bus address and write into registers */
|
2010-11-12 18:14:07 +07:00
|
|
|
entry = list_first_entry(&list->entries, struct ca91cx42_dma_entry,
|
2010-02-18 22:13:25 +07:00
|
|
|
list);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
bus_addr = virt_to_bus(&entry->descriptor);
|
2010-02-18 22:13:25 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&ctrlr->mtx);
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
iowrite32(0, bridge->base + DTBC);
|
|
|
|
iowrite32(bus_addr & ~CA91CX42_DCPP_M, bridge->base + DCPP);
|
|
|
|
|
|
|
|
/* Start the operation */
|
|
|
|
val = ioread32(bridge->base + DGCS);
|
|
|
|
|
|
|
|
/* XXX Could set VMEbus On and Off Counters here */
|
|
|
|
val &= (CA91CX42_DGCS_VON_M | CA91CX42_DGCS_VOFF_M);
|
|
|
|
|
|
|
|
val |= (CA91CX42_DGCS_CHAIN | CA91CX42_DGCS_STOP | CA91CX42_DGCS_HALT |
|
|
|
|
CA91CX42_DGCS_DONE | CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
|
|
|
|
CA91CX42_DGCS_PERR);
|
|
|
|
|
|
|
|
iowrite32(val, bridge->base + DGCS);
|
|
|
|
|
|
|
|
val |= CA91CX42_DGCS_GO;
|
|
|
|
|
|
|
|
iowrite32(val, bridge->base + DGCS);
|
|
|
|
|
2015-05-28 19:07:01 +07:00
|
|
|
retval = wait_event_interruptible(bridge->dma_queue,
|
|
|
|
ca91cx42_dma_busy(ctrlr->parent));
|
|
|
|
|
|
|
|
if (retval) {
|
|
|
|
val = ioread32(bridge->base + DGCS);
|
|
|
|
iowrite32(val | CA91CX42_DGCS_STOP_REQ, bridge->base + DGCS);
|
|
|
|
/* Wait for the operation to abort */
|
|
|
|
wait_event(bridge->dma_queue,
|
|
|
|
ca91cx42_dma_busy(ctrlr->parent));
|
|
|
|
retval = -EINTR;
|
|
|
|
goto exit;
|
|
|
|
}
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read status register, this register is valid until we kick off a
|
|
|
|
* new transfer.
|
|
|
|
*/
|
|
|
|
val = ioread32(bridge->base + DGCS);
|
|
|
|
|
|
|
|
if (val & (CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
|
|
|
|
CA91CX42_DGCS_PERR)) {
|
|
|
|
|
2010-03-22 21:58:50 +07:00
|
|
|
dev_err(dev, "ca91c042: DMA Error. DGCS=%08X\n", val);
|
2010-02-18 22:13:25 +07:00
|
|
|
val = ioread32(bridge->base + DCTL);
|
2015-05-28 19:07:06 +07:00
|
|
|
retval = -EIO;
|
2010-02-18 22:13:25 +07:00
|
|
|
}
|
|
|
|
|
2015-05-28 19:07:01 +07:00
|
|
|
exit:
|
2010-02-18 22:13:25 +07:00
|
|
|
/* Remove list from running list */
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&ctrlr->mtx);
|
|
|
|
list_del(&list->list);
|
|
|
|
mutex_unlock(&ctrlr->mtx);
|
2010-02-18 22:13:25 +07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_dma_list_empty(struct vme_dma_list *list)
|
2010-02-18 22:13:25 +07:00
|
|
|
{
|
|
|
|
struct list_head *pos, *temp;
|
|
|
|
struct ca91cx42_dma_entry *entry;
|
|
|
|
|
|
|
|
/* detach and free each entry */
|
2010-11-12 18:14:07 +07:00
|
|
|
list_for_each_safe(pos, temp, &list->entries) {
|
2010-02-18 22:13:25 +07:00
|
|
|
list_del(pos);
|
|
|
|
entry = list_entry(pos, struct ca91cx42_dma_entry, list);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:19 +07:00
|
|
|
/*
|
|
|
|
* All 4 location monitors reside at the same base - this is therefore a
|
|
|
|
* system wide configuration.
|
|
|
|
*
|
|
|
|
* This does not enable the LM monitor - that should be done when the first
|
|
|
|
* callback is attached and disabled when the last callback is removed.
|
|
|
|
*/
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_lm_set(struct vme_lm_resource *lm,
|
2011-12-02 00:06:29 +07:00
|
|
|
unsigned long long lm_base, u32 aspace, u32 cycle)
|
2010-02-18 22:13:19 +07:00
|
|
|
{
|
|
|
|
u32 temp_base, lm_ctl = 0;
|
|
|
|
int i;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
bridge = lm->parent->driver_priv;
|
|
|
|
dev = lm->parent->parent;
|
|
|
|
|
|
|
|
/* Check the alignment of the location monitor */
|
|
|
|
temp_base = (u32)lm_base;
|
|
|
|
if (temp_base & 0xffff) {
|
|
|
|
dev_err(dev, "Location monitor must be aligned to 64KB "
|
|
|
|
"boundary");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
/* If we already have a callback attached, we can't move it! */
|
|
|
|
for (i = 0; i < lm->monitors; i++) {
|
|
|
|
if (bridge->lm_callback[i] != NULL) {
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
dev_err(dev, "Location monitor callback attached, "
|
|
|
|
"can't reset\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aspace) {
|
|
|
|
case VME_A16:
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_AS_A16;
|
|
|
|
break;
|
|
|
|
case VME_A24:
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_AS_A24;
|
|
|
|
break;
|
|
|
|
case VME_A32:
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_AS_A32;
|
|
|
|
break;
|
|
|
|
default:
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
dev_err(dev, "Invalid address space\n");
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cycle & VME_SUPER)
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_SUPR;
|
|
|
|
if (cycle & VME_USER)
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_NPRIV;
|
|
|
|
if (cycle & VME_PROG)
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_PGM;
|
|
|
|
if (cycle & VME_DATA)
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_DATA;
|
|
|
|
|
|
|
|
iowrite32(lm_base, bridge->base + LM_BS);
|
|
|
|
iowrite32(lm_ctl, bridge->base + LM_CTL);
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get configuration of the callback monitor and return whether it is enabled
|
|
|
|
* or disabled.
|
|
|
|
*/
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_lm_get(struct vme_lm_resource *lm,
|
2011-12-02 00:06:29 +07:00
|
|
|
unsigned long long *lm_base, u32 *aspace, u32 *cycle)
|
2010-02-18 22:13:19 +07:00
|
|
|
{
|
|
|
|
u32 lm_ctl, enabled = 0;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = lm->parent->driver_priv;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
*lm_base = (unsigned long long)ioread32(bridge->base + LM_BS);
|
|
|
|
lm_ctl = ioread32(bridge->base + LM_CTL);
|
|
|
|
|
|
|
|
if (lm_ctl & CA91CX42_LM_CTL_EN)
|
|
|
|
enabled = 1;
|
|
|
|
|
|
|
|
if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A16)
|
|
|
|
*aspace = VME_A16;
|
|
|
|
if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A24)
|
|
|
|
*aspace = VME_A24;
|
|
|
|
if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A32)
|
|
|
|
*aspace = VME_A32;
|
|
|
|
|
|
|
|
*cycle = 0;
|
|
|
|
if (lm_ctl & CA91CX42_LM_CTL_SUPR)
|
|
|
|
*cycle |= VME_SUPER;
|
|
|
|
if (lm_ctl & CA91CX42_LM_CTL_NPRIV)
|
|
|
|
*cycle |= VME_USER;
|
|
|
|
if (lm_ctl & CA91CX42_LM_CTL_PGM)
|
|
|
|
*cycle |= VME_PROG;
|
|
|
|
if (lm_ctl & CA91CX42_LM_CTL_DATA)
|
|
|
|
*cycle |= VME_DATA;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach a callback to a specific location monitor.
|
|
|
|
*
|
|
|
|
* Callback will be passed the monitor triggered.
|
|
|
|
*/
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
|
2010-02-18 22:13:19 +07:00
|
|
|
void (*callback)(int))
|
|
|
|
{
|
|
|
|
u32 lm_ctl, tmp;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
bridge = lm->parent->driver_priv;
|
|
|
|
dev = lm->parent->parent;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
/* Ensure that the location monitor is configured - need PGM or DATA */
|
|
|
|
lm_ctl = ioread32(bridge->base + LM_CTL);
|
|
|
|
if ((lm_ctl & (CA91CX42_LM_CTL_PGM | CA91CX42_LM_CTL_DATA)) == 0) {
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
dev_err(dev, "Location monitor not properly configured\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that a callback isn't already attached */
|
|
|
|
if (bridge->lm_callback[monitor] != NULL) {
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
dev_err(dev, "Existing callback attached\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach callback */
|
|
|
|
bridge->lm_callback[monitor] = callback;
|
|
|
|
|
|
|
|
/* Enable Location Monitor interrupt */
|
|
|
|
tmp = ioread32(bridge->base + LINT_EN);
|
|
|
|
tmp |= CA91CX42_LINT_LM[monitor];
|
|
|
|
iowrite32(tmp, bridge->base + LINT_EN);
|
|
|
|
|
|
|
|
/* Ensure that global Location Monitor Enable set */
|
|
|
|
if ((lm_ctl & CA91CX42_LM_CTL_EN) == 0) {
|
|
|
|
lm_ctl |= CA91CX42_LM_CTL_EN;
|
|
|
|
iowrite32(lm_ctl, bridge->base + LM_CTL);
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach a callback function forn a specific location monitor.
|
|
|
|
*/
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor)
|
2010-02-18 22:13:19 +07:00
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = lm->parent->driver_priv;
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_lock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
/* Disable Location Monitor and ensure previous interrupts are clear */
|
|
|
|
tmp = ioread32(bridge->base + LINT_EN);
|
|
|
|
tmp &= ~CA91CX42_LINT_LM[monitor];
|
|
|
|
iowrite32(tmp, bridge->base + LINT_EN);
|
|
|
|
|
|
|
|
iowrite32(CA91CX42_LINT_LM[monitor],
|
|
|
|
bridge->base + LINT_STAT);
|
|
|
|
|
|
|
|
/* Detach callback */
|
|
|
|
bridge->lm_callback[monitor] = NULL;
|
|
|
|
|
|
|
|
/* If all location monitors disabled, disable global Location Monitor */
|
|
|
|
if ((tmp & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
|
|
|
|
CA91CX42_LINT_LM3)) == 0) {
|
|
|
|
tmp = ioread32(bridge->base + LM_CTL);
|
|
|
|
tmp &= ~CA91CX42_LM_CTL_EN;
|
|
|
|
iowrite32(tmp, bridge->base + LM_CTL);
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_unlock(&lm->mtx);
|
2010-02-18 22:13:19 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
u32 slot = 0;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-12-15 15:42:56 +07:00
|
|
|
if (!geoid) {
|
2010-02-18 22:13:05 +07:00
|
|
|
slot = ioread32(bridge->base + VCSR_BS);
|
2009-12-15 15:42:56 +07:00
|
|
|
slot = ((slot & CA91CX42_VCSR_BS_SLOT_M) >> 27);
|
|
|
|
} else
|
|
|
|
slot = geoid;
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return (int)slot;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-03 07:12:22 +07:00
|
|
|
static void *ca91cx42_alloc_consistent(struct device *parent, size_t size,
|
2011-08-10 16:33:46 +07:00
|
|
|
dma_addr_t *dma)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
|
|
|
|
/* Find pci_dev container of dev */
|
2015-12-27 17:46:04 +07:00
|
|
|
pdev = to_pci_dev(parent);
|
2011-08-10 16:33:46 +07:00
|
|
|
|
|
|
|
return pci_alloc_consistent(pdev, size, dma);
|
|
|
|
}
|
|
|
|
|
2012-05-03 07:12:22 +07:00
|
|
|
static void ca91cx42_free_consistent(struct device *parent, size_t size,
|
|
|
|
void *vaddr, dma_addr_t dma)
|
2011-08-10 16:33:46 +07:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
|
|
|
|
/* Find pci_dev container of dev */
|
2015-12-27 17:46:04 +07:00
|
|
|
pdev = to_pci_dev(parent);
|
2011-08-10 16:33:46 +07:00
|
|
|
|
|
|
|
pci_free_consistent(pdev, size, vaddr, dma);
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/*
|
|
|
|
* Configure CR/CSR space
|
|
|
|
*
|
|
|
|
* Access to the CR/CSR can be configured at power-up. The location of the
|
|
|
|
* CR/CSR registers in the CR/CSR address space is determined by the boards
|
|
|
|
* Auto-ID or Geographic address. This function ensures that the window is
|
|
|
|
* enabled at an offset consistent with the boards geopgraphic address.
|
|
|
|
*/
|
2010-02-18 22:13:05 +07:00
|
|
|
static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge,
|
|
|
|
struct pci_dev *pdev)
|
2009-08-27 23:00:40 +07:00
|
|
|
{
|
|
|
|
unsigned int crcsr_addr;
|
|
|
|
int tmp, slot;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
slot = ca91cx42_slot_get(ca91cx42_bridge);
|
2010-02-18 22:13:45 +07:00
|
|
|
|
|
|
|
/* Write CSR Base Address if slot ID is supplied as a module param */
|
|
|
|
if (geoid)
|
|
|
|
iowrite32(geoid << 27, bridge->base + VCSR_BS);
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
dev_info(&pdev->dev, "CR/CSR Offset: %d\n", slot);
|
|
|
|
if (slot == 0) {
|
|
|
|
dev_err(&pdev->dev, "Slot number is unset, not configuring "
|
|
|
|
"CR/CSR space\n");
|
|
|
|
return -EINVAL;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Allocate mem for CR/CSR image */
|
2014-08-09 04:24:53 +07:00
|
|
|
bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
|
|
|
|
&bridge->crcsr_bus);
|
2010-02-18 22:13:05 +07:00
|
|
|
if (bridge->crcsr_kernel == NULL) {
|
2009-08-27 23:00:40 +07:00
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR "
|
|
|
|
"image\n");
|
|
|
|
return -ENOMEM;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
crcsr_addr = slot * (512 * 1024);
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(bridge->crcsr_bus - crcsr_addr, bridge->base + VCSR_TO);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
tmp = ioread32(bridge->base + VCSR_CTL);
|
2009-08-27 23:00:40 +07:00
|
|
|
tmp |= CA91CX42_VCSR_CTL_EN;
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(tmp, bridge->base + VCSR_CTL);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return 0;
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
static void ca91cx42_crcsr_exit(struct vme_bridge *ca91cx42_bridge,
|
|
|
|
struct pci_dev *pdev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2009-08-27 23:00:40 +07:00
|
|
|
u32 tmp;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Turn off CR/CSR space */
|
2010-02-18 22:13:05 +07:00
|
|
|
tmp = ioread32(bridge->base + VCSR_CTL);
|
2009-08-27 23:00:40 +07:00
|
|
|
tmp &= ~CA91CX42_VCSR_CTL_EN;
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(tmp, bridge->base + VCSR_CTL);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Free image */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0, bridge->base + VCSR_TO);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
pci_free_consistent(pdev, VME_CRCSR_BUF_SIZE, bridge->crcsr_kernel,
|
|
|
|
bridge->crcsr_bus);
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
int retval, i;
|
|
|
|
u32 data;
|
2012-08-21 11:17:34 +07:00
|
|
|
struct list_head *pos = NULL, *n;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct vme_bridge *ca91cx42_bridge;
|
|
|
|
struct ca91cx42_driver *ca91cx42_device;
|
2009-08-27 23:00:40 +07:00
|
|
|
struct vme_master_resource *master_image;
|
|
|
|
struct vme_slave_resource *slave_image;
|
|
|
|
struct vme_dma_resource *dma_ctrlr;
|
|
|
|
struct vme_lm_resource *lm;
|
|
|
|
|
|
|
|
/* We want to support more than one of each bridge so we need to
|
|
|
|
* dynamically allocate the bridge structure
|
|
|
|
*/
|
Staging: Use kcalloc or kzalloc
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,y,flags;
statement S;
type T;
@@
x =
- kmalloc
+ kcalloc
(
- y * sizeof(T),
+ y, sizeof(T),
flags);
if (x == NULL) S
-memset(x, 0, y * sizeof(T));
@@
expression x,size,flags;
statement S;
@@
-x = kmalloc(size,flags);
+x = kzalloc(size,flags);
if (x == NULL) S
-memset(x, 0, size);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
2010-05-14 03:00:05 +07:00
|
|
|
ca91cx42_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
if (ca91cx42_bridge == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for device "
|
|
|
|
"structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_struct;
|
|
|
|
}
|
2016-04-25 03:11:38 +07:00
|
|
|
vme_init_bridge(ca91cx42_bridge);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
Staging: Use kcalloc or kzalloc
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,y,flags;
statement S;
type T;
@@
x =
- kmalloc
+ kcalloc
(
- y * sizeof(T),
+ y, sizeof(T),
flags);
if (x == NULL) S
-memset(x, 0, y * sizeof(T));
@@
expression x,size,flags;
statement S;
@@
-x = kmalloc(size,flags);
+x = kzalloc(size,flags);
if (x == NULL) S
-memset(x, 0, size);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
2010-05-14 03:00:05 +07:00
|
|
|
ca91cx42_device = kzalloc(sizeof(struct ca91cx42_driver), GFP_KERNEL);
|
2010-02-18 22:13:05 +07:00
|
|
|
|
|
|
|
if (ca91cx42_device == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for device "
|
|
|
|
"structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
ca91cx42_bridge->driver_priv = ca91cx42_device;
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Enable the device */
|
|
|
|
retval = pci_enable_device(pdev);
|
|
|
|
if (retval) {
|
|
|
|
dev_err(&pdev->dev, "Unable to enable device\n");
|
|
|
|
goto err_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map Registers */
|
|
|
|
retval = pci_request_regions(pdev, driver_name);
|
|
|
|
if (retval) {
|
|
|
|
dev_err(&pdev->dev, "Unable to reserve resources\n");
|
|
|
|
goto err_resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* map registers in BAR 0 */
|
2010-02-18 22:13:05 +07:00
|
|
|
ca91cx42_device->base = ioremap_nocache(pci_resource_start(pdev, 0),
|
2009-08-27 23:00:40 +07:00
|
|
|
4096);
|
2010-02-18 22:13:05 +07:00
|
|
|
if (!ca91cx42_device->base) {
|
2009-08-27 23:00:40 +07:00
|
|
|
dev_err(&pdev->dev, "Unable to remap CRG region\n");
|
|
|
|
retval = -EIO;
|
|
|
|
goto err_remap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if the mapping worked out */
|
2010-02-18 22:13:05 +07:00
|
|
|
data = ioread32(ca91cx42_device->base + CA91CX42_PCI_ID) & 0x0000FFFF;
|
2009-08-27 23:00:40 +07:00
|
|
|
if (data != PCI_VENDOR_ID_TUNDRA) {
|
|
|
|
dev_err(&pdev->dev, "PCI_ID check failed\n");
|
|
|
|
retval = -EIO;
|
|
|
|
goto err_test;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize wait queues & mutual exclusion flags */
|
2010-11-12 18:14:07 +07:00
|
|
|
init_waitqueue_head(&ca91cx42_device->dma_queue);
|
|
|
|
init_waitqueue_head(&ca91cx42_device->iack_queue);
|
|
|
|
mutex_init(&ca91cx42_device->vme_int);
|
|
|
|
mutex_init(&ca91cx42_device->vme_rmw);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-11-12 18:14:07 +07:00
|
|
|
ca91cx42_bridge->parent = &pdev->dev;
|
2009-08-27 23:00:40 +07:00
|
|
|
strcpy(ca91cx42_bridge->name, driver_name);
|
|
|
|
|
|
|
|
/* Setup IRQ */
|
|
|
|
retval = ca91cx42_irq_init(ca91cx42_bridge);
|
|
|
|
if (retval != 0) {
|
|
|
|
dev_err(&pdev->dev, "Chip Initialization failed.\n");
|
|
|
|
goto err_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add master windows to list */
|
|
|
|
for (i = 0; i < CA91C142_MAX_MASTER; i++) {
|
|
|
|
master_image = kmalloc(sizeof(struct vme_master_resource),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (master_image == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for "
|
|
|
|
"master resource structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_master;
|
|
|
|
}
|
|
|
|
master_image->parent = ca91cx42_bridge;
|
2010-11-12 18:14:07 +07:00
|
|
|
spin_lock_init(&master_image->lock);
|
2009-08-27 23:00:40 +07:00
|
|
|
master_image->locked = 0;
|
|
|
|
master_image->number = i;
|
|
|
|
master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
|
|
|
|
VME_CRCSR | VME_USER1 | VME_USER2;
|
|
|
|
master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
|
|
|
|
VME_SUPER | VME_USER | VME_PROG | VME_DATA;
|
|
|
|
master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64;
|
2010-11-12 18:14:07 +07:00
|
|
|
memset(&master_image->bus_resource, 0,
|
2009-08-27 23:00:40 +07:00
|
|
|
sizeof(struct resource));
|
|
|
|
master_image->kern_base = NULL;
|
2010-11-12 18:14:07 +07:00
|
|
|
list_add_tail(&master_image->list,
|
|
|
|
&ca91cx42_bridge->master_resources);
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add slave windows to list */
|
|
|
|
for (i = 0; i < CA91C142_MAX_SLAVE; i++) {
|
|
|
|
slave_image = kmalloc(sizeof(struct vme_slave_resource),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (slave_image == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for "
|
|
|
|
"slave resource structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_slave;
|
|
|
|
}
|
|
|
|
slave_image->parent = ca91cx42_bridge;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_init(&slave_image->mtx);
|
2009-08-27 23:00:40 +07:00
|
|
|
slave_image->locked = 0;
|
|
|
|
slave_image->number = i;
|
|
|
|
slave_image->address_attr = VME_A24 | VME_A32 | VME_USER1 |
|
|
|
|
VME_USER2;
|
|
|
|
|
|
|
|
/* Only windows 0 and 4 support A16 */
|
|
|
|
if (i == 0 || i == 4)
|
|
|
|
slave_image->address_attr |= VME_A16;
|
|
|
|
|
|
|
|
slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
|
|
|
|
VME_SUPER | VME_USER | VME_PROG | VME_DATA;
|
2010-11-12 18:14:07 +07:00
|
|
|
list_add_tail(&slave_image->list,
|
|
|
|
&ca91cx42_bridge->slave_resources);
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
2010-02-18 22:13:25 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Add dma engines to list */
|
|
|
|
for (i = 0; i < CA91C142_MAX_DMA; i++) {
|
|
|
|
dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (dma_ctrlr == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for "
|
|
|
|
"dma resource structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_dma;
|
|
|
|
}
|
|
|
|
dma_ctrlr->parent = ca91cx42_bridge;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_init(&dma_ctrlr->mtx);
|
2009-08-27 23:00:40 +07:00
|
|
|
dma_ctrlr->locked = 0;
|
|
|
|
dma_ctrlr->number = i;
|
2010-02-18 22:12:58 +07:00
|
|
|
dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
|
|
|
|
VME_DMA_MEM_TO_VME;
|
2010-11-12 18:14:07 +07:00
|
|
|
INIT_LIST_HEAD(&dma_ctrlr->pending);
|
|
|
|
INIT_LIST_HEAD(&dma_ctrlr->running);
|
|
|
|
list_add_tail(&dma_ctrlr->list,
|
|
|
|
&ca91cx42_bridge->dma_resources);
|
2009-08-27 23:00:40 +07:00
|
|
|
}
|
2010-02-18 22:13:25 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Add location monitor to list */
|
|
|
|
lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL);
|
|
|
|
if (lm == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory for "
|
|
|
|
"location monitor resource structure\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_lm;
|
|
|
|
}
|
|
|
|
lm->parent = ca91cx42_bridge;
|
2010-11-12 18:14:07 +07:00
|
|
|
mutex_init(&lm->mtx);
|
2009-08-27 23:00:40 +07:00
|
|
|
lm->locked = 0;
|
|
|
|
lm->number = 1;
|
|
|
|
lm->monitors = 4;
|
2010-11-12 18:14:07 +07:00
|
|
|
list_add_tail(&lm->list, &ca91cx42_bridge->lm_resources);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
ca91cx42_bridge->slave_get = ca91cx42_slave_get;
|
|
|
|
ca91cx42_bridge->slave_set = ca91cx42_slave_set;
|
|
|
|
ca91cx42_bridge->master_get = ca91cx42_master_get;
|
|
|
|
ca91cx42_bridge->master_set = ca91cx42_master_set;
|
|
|
|
ca91cx42_bridge->master_read = ca91cx42_master_read;
|
|
|
|
ca91cx42_bridge->master_write = ca91cx42_master_write;
|
|
|
|
ca91cx42_bridge->master_rmw = ca91cx42_master_rmw;
|
|
|
|
ca91cx42_bridge->dma_list_add = ca91cx42_dma_list_add;
|
|
|
|
ca91cx42_bridge->dma_list_exec = ca91cx42_dma_list_exec;
|
|
|
|
ca91cx42_bridge->dma_list_empty = ca91cx42_dma_list_empty;
|
2009-10-29 23:34:54 +07:00
|
|
|
ca91cx42_bridge->irq_set = ca91cx42_irq_set;
|
|
|
|
ca91cx42_bridge->irq_generate = ca91cx42_irq_generate;
|
2009-08-27 23:00:40 +07:00
|
|
|
ca91cx42_bridge->lm_set = ca91cx42_lm_set;
|
|
|
|
ca91cx42_bridge->lm_get = ca91cx42_lm_get;
|
|
|
|
ca91cx42_bridge->lm_attach = ca91cx42_lm_attach;
|
|
|
|
ca91cx42_bridge->lm_detach = ca91cx42_lm_detach;
|
|
|
|
ca91cx42_bridge->slot_get = ca91cx42_slot_get;
|
2011-08-10 16:33:46 +07:00
|
|
|
ca91cx42_bridge->alloc_consistent = ca91cx42_alloc_consistent;
|
|
|
|
ca91cx42_bridge->free_consistent = ca91cx42_free_consistent;
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
data = ioread32(ca91cx42_device->base + MISC_CTL);
|
2009-08-27 23:00:40 +07:00
|
|
|
dev_info(&pdev->dev, "Board is%s the VME system controller\n",
|
|
|
|
(data & CA91CX42_MISC_CTL_SYSCON) ? "" : " not");
|
2010-02-18 22:13:05 +07:00
|
|
|
dev_info(&pdev->dev, "Slot ID is %d\n",
|
|
|
|
ca91cx42_slot_get(ca91cx42_bridge));
|
2009-08-27 23:00:40 +07:00
|
|
|
|
2010-03-22 21:58:57 +07:00
|
|
|
if (ca91cx42_crcsr_init(ca91cx42_bridge, pdev))
|
2009-08-27 23:00:40 +07:00
|
|
|
dev_err(&pdev->dev, "CR/CSR configuration failed.\n");
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Need to save ca91cx42_bridge pointer locally in link list for use in
|
|
|
|
* ca91cx42_remove()
|
|
|
|
*/
|
|
|
|
retval = vme_register_bridge(ca91cx42_bridge);
|
|
|
|
if (retval != 0) {
|
|
|
|
dev_err(&pdev->dev, "Chip Registration failed.\n");
|
|
|
|
goto err_reg;
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
pci_set_drvdata(pdev, ca91cx42_bridge);
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_reg:
|
2010-02-18 22:13:05 +07:00
|
|
|
ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
|
2009-08-27 23:00:40 +07:00
|
|
|
err_lm:
|
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->lm_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
lm = list_entry(pos, struct vme_lm_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(lm);
|
|
|
|
}
|
|
|
|
err_dma:
|
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->dma_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(dma_ctrlr);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
err_slave:
|
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->slave_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
slave_image = list_entry(pos, struct vme_slave_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(slave_image);
|
|
|
|
}
|
|
|
|
err_master:
|
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->master_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
master_image = list_entry(pos, struct vme_master_resource,
|
|
|
|
list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(master_image);
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
ca91cx42_irq_exit(ca91cx42_device, pdev);
|
2009-08-27 23:00:40 +07:00
|
|
|
err_irq:
|
|
|
|
err_test:
|
2010-02-18 22:13:05 +07:00
|
|
|
iounmap(ca91cx42_device->base);
|
2009-08-27 23:00:40 +07:00
|
|
|
err_remap:
|
|
|
|
pci_release_regions(pdev);
|
|
|
|
err_resource:
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
err_enable:
|
2010-02-18 22:13:05 +07:00
|
|
|
kfree(ca91cx42_device);
|
|
|
|
err_driver:
|
2009-08-27 23:00:40 +07:00
|
|
|
kfree(ca91cx42_bridge);
|
|
|
|
err_struct:
|
|
|
|
return retval;
|
2009-07-31 15:28:17 +07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:15:07 +07:00
|
|
|
static void ca91cx42_remove(struct pci_dev *pdev)
|
2009-07-31 15:28:17 +07:00
|
|
|
{
|
2012-08-21 11:17:34 +07:00
|
|
|
struct list_head *pos = NULL, *n;
|
2009-08-27 23:00:40 +07:00
|
|
|
struct vme_master_resource *master_image;
|
|
|
|
struct vme_slave_resource *slave_image;
|
|
|
|
struct vme_dma_resource *dma_ctrlr;
|
|
|
|
struct vme_lm_resource *lm;
|
2010-02-18 22:13:05 +07:00
|
|
|
struct ca91cx42_driver *bridge;
|
|
|
|
struct vme_bridge *ca91cx42_bridge = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
bridge = ca91cx42_bridge->driver_priv;
|
|
|
|
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* Turn off Ints */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0, bridge->base + LINT_EN);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* Turn off the windows */
|
2010-02-18 22:13:05 +07:00
|
|
|
iowrite32(0x00800000, bridge->base + LSI0_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI1_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI2_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI3_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI4_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI5_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI6_CTL);
|
|
|
|
iowrite32(0x00800000, bridge->base + LSI7_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI0_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI1_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI2_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI3_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI4_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI5_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI6_CTL);
|
|
|
|
iowrite32(0x00F00000, bridge->base + VSI7_CTL);
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
vme_unregister_bridge(ca91cx42_bridge);
|
2010-02-18 23:22:13 +07:00
|
|
|
|
|
|
|
ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->lm_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
lm = list_entry(pos, struct vme_lm_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(lm);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
2009-08-27 23:00:40 +07:00
|
|
|
|
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->dma_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(dma_ctrlr);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->slave_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
slave_image = list_entry(pos, struct vme_slave_resource, list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(slave_image);
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
/* resources are stored in link list */
|
2012-08-21 11:17:34 +07:00
|
|
|
list_for_each_safe(pos, n, &ca91cx42_bridge->master_resources) {
|
2009-08-27 23:00:40 +07:00
|
|
|
master_image = list_entry(pos, struct vme_master_resource,
|
|
|
|
list);
|
|
|
|
list_del(pos);
|
|
|
|
kfree(master_image);
|
|
|
|
}
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
ca91cx42_irq_exit(bridge, pdev);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2010-02-18 22:13:05 +07:00
|
|
|
iounmap(bridge->base);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
pci_release_regions(pdev);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
pci_disable_device(pdev);
|
|
|
|
|
|
|
|
kfree(ca91cx42_bridge);
|
2009-07-31 15:28:17 +07:00
|
|
|
}
|
|
|
|
|
2012-10-18 22:13:37 +07:00
|
|
|
module_pci_driver(ca91cx42_driver);
|
2009-07-31 15:28:17 +07:00
|
|
|
|
2009-12-15 15:42:56 +07:00
|
|
|
MODULE_PARM_DESC(geoid, "Override geographical addressing");
|
|
|
|
module_param(geoid, int, 0);
|
|
|
|
|
2009-08-27 23:00:40 +07:00
|
|
|
MODULE_DESCRIPTION("VME driver for the Tundra Universe II VME bridge");
|
|
|
|
MODULE_LICENSE("GPL");
|