Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Support for the Tundra TSI148 VME-PCI Bridge Chip |
| 3 | * |
Martyn Welch | 66bd8db | 2010-02-18 15:12:52 +0000 | [diff] [blame] | 4 | * Author: Martyn Welch <martyn.welch@ge.com> |
| 5 | * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 6 | * |
| 7 | * Based on work by Tom Armistead and Ajit Prem |
| 8 | * Copyright 2004 Motorola Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | */ |
| 15 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/proc_fs.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/poll.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/spinlock.h> |
Greg Kroah-Hartman | 6af783c | 2009-10-12 15:00:08 -0700 | [diff] [blame] | 27 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 29 | #include <linux/time.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/uaccess.h> |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 32 | #include <linux/byteorder/generic.h> |
Greg Kroah-Hartman | db3b9e9 | 2012-04-26 12:34:58 -0700 | [diff] [blame] | 33 | #include <linux/vme.h> |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 34 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 35 | #include "../vme_bridge.h" |
| 36 | #include "vme_tsi148.h" |
| 37 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 38 | static int tsi148_probe(struct pci_dev *, const struct pci_device_id *); |
| 39 | static void tsi148_remove(struct pci_dev *); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 40 | |
| 41 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 42 | /* Module parameter */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 43 | static bool err_chk; |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 44 | static int geoid; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 45 | |
Vincent Bossier | 584721c | 2011-06-03 10:07:39 +0100 | [diff] [blame] | 46 | static const char driver_name[] = "vme_tsi148"; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 47 | |
Jingoo Han | c3a09c1 | 2013-12-03 08:29:48 +0900 | [diff] [blame] | 48 | static const struct pci_device_id tsi148_ids[] = { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 49 | { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_TSI148) }, |
| 50 | { }, |
| 51 | }; |
| 52 | |
| 53 | static struct pci_driver tsi148_driver = { |
| 54 | .name = driver_name, |
| 55 | .id_table = tsi148_ids, |
| 56 | .probe = tsi148_probe, |
| 57 | .remove = tsi148_remove, |
| 58 | }; |
| 59 | |
| 60 | static void reg_join(unsigned int high, unsigned int low, |
| 61 | unsigned long long *variable) |
| 62 | { |
| 63 | *variable = (unsigned long long)high << 32; |
| 64 | *variable |= (unsigned long long)low; |
| 65 | } |
| 66 | |
| 67 | static void reg_split(unsigned long long variable, unsigned int *high, |
| 68 | unsigned int *low) |
| 69 | { |
| 70 | *low = (unsigned int)variable & 0xFFFFFFFF; |
| 71 | *high = (unsigned int)(variable >> 32); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Wakes up DMA queue. |
| 76 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 77 | static u32 tsi148_DMA_irqhandler(struct tsi148_driver *bridge, |
| 78 | int channel_mask) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 79 | { |
| 80 | u32 serviced = 0; |
| 81 | |
| 82 | if (channel_mask & TSI148_LCSR_INTS_DMA0S) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 83 | wake_up(&bridge->dma_queue[0]); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 84 | serviced |= TSI148_LCSR_INTC_DMA0C; |
| 85 | } |
| 86 | if (channel_mask & TSI148_LCSR_INTS_DMA1S) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 87 | wake_up(&bridge->dma_queue[1]); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 88 | serviced |= TSI148_LCSR_INTC_DMA1C; |
| 89 | } |
| 90 | |
| 91 | return serviced; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Wake up location monitor queue |
| 96 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 97 | static u32 tsi148_LM_irqhandler(struct tsi148_driver *bridge, u32 stat) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | u32 serviced = 0; |
| 101 | |
| 102 | for (i = 0; i < 4; i++) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 103 | if (stat & TSI148_LCSR_INTS_LMS[i]) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 104 | /* We only enable interrupts if the callback is set */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 105 | bridge->lm_callback[i](i); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 106 | serviced |= TSI148_LCSR_INTC_LMC[i]; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return serviced; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Wake up mail box queue. |
| 115 | * |
| 116 | * XXX This functionality is not exposed up though API. |
| 117 | */ |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 118 | static u32 tsi148_MB_irqhandler(struct vme_bridge *tsi148_bridge, u32 stat) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 119 | { |
| 120 | int i; |
| 121 | u32 val; |
| 122 | u32 serviced = 0; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 123 | struct tsi148_driver *bridge; |
| 124 | |
| 125 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 126 | |
| 127 | for (i = 0; i < 4; i++) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 128 | if (stat & TSI148_LCSR_INTS_MBS[i]) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 129 | val = ioread32be(bridge->base + TSI148_GCSR_MBOX[i]); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 130 | dev_err(tsi148_bridge->parent, "VME Mailbox %d received" |
| 131 | ": 0x%x\n", i, val); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 132 | serviced |= TSI148_LCSR_INTC_MBC[i]; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return serviced; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Display error & status message when PERR (PCI) exception interrupt occurs. |
| 141 | */ |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 142 | static u32 tsi148_PERR_irqhandler(struct vme_bridge *tsi148_bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 143 | { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 144 | struct tsi148_driver *bridge; |
| 145 | |
| 146 | bridge = tsi148_bridge->driver_priv; |
| 147 | |
| 148 | dev_err(tsi148_bridge->parent, "PCI Exception at address: 0x%08x:%08x, " |
| 149 | "attributes: %08x\n", |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 150 | ioread32be(bridge->base + TSI148_LCSR_EDPAU), |
| 151 | ioread32be(bridge->base + TSI148_LCSR_EDPAL), |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 152 | ioread32be(bridge->base + TSI148_LCSR_EDPAT)); |
| 153 | |
| 154 | dev_err(tsi148_bridge->parent, "PCI-X attribute reg: %08x, PCI-X split " |
| 155 | "completion reg: %08x\n", |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 156 | ioread32be(bridge->base + TSI148_LCSR_EDPXA), |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 157 | ioread32be(bridge->base + TSI148_LCSR_EDPXS)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 158 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 159 | iowrite32be(TSI148_LCSR_EDPAT_EDPCL, bridge->base + TSI148_LCSR_EDPAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 160 | |
| 161 | return TSI148_LCSR_INTC_PERRC; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Save address and status when VME error interrupt occurs. |
| 166 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 167 | static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 168 | { |
| 169 | unsigned int error_addr_high, error_addr_low; |
| 170 | unsigned long long error_addr; |
| 171 | u32 error_attrib; |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 172 | int error_am; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 173 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 174 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 175 | bridge = tsi148_bridge->driver_priv; |
| 176 | |
| 177 | error_addr_high = ioread32be(bridge->base + TSI148_LCSR_VEAU); |
| 178 | error_addr_low = ioread32be(bridge->base + TSI148_LCSR_VEAL); |
| 179 | error_attrib = ioread32be(bridge->base + TSI148_LCSR_VEAT); |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 180 | error_am = (error_attrib & TSI148_LCSR_VEAT_AM_M) >> 8; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 181 | |
| 182 | reg_join(error_addr_high, error_addr_low, &error_addr); |
| 183 | |
| 184 | /* Check for exception register overflow (we have lost error data) */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 185 | if (error_attrib & TSI148_LCSR_VEAT_VEOF) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 186 | dev_err(tsi148_bridge->parent, "VME Bus Exception Overflow " |
| 187 | "Occurred\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 190 | if (err_chk) |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 191 | vme_bus_error_handler(tsi148_bridge, error_addr, error_am); |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 192 | else |
Martyn Welch | e31c51e | 2013-06-11 11:20:17 +0100 | [diff] [blame] | 193 | dev_err(tsi148_bridge->parent, |
| 194 | "VME Bus Error at address: 0x%llx, attributes: %08x\n", |
| 195 | error_addr, error_attrib); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 196 | |
| 197 | /* Clear Status */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 198 | iowrite32be(TSI148_LCSR_VEAT_VESCL, bridge->base + TSI148_LCSR_VEAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 199 | |
| 200 | return TSI148_LCSR_INTC_VERRC; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Wake up IACK queue. |
| 205 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 206 | static u32 tsi148_IACK_irqhandler(struct tsi148_driver *bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 207 | { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 208 | wake_up(&bridge->iack_queue); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 209 | |
| 210 | return TSI148_LCSR_INTC_IACKC; |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Calling VME bus interrupt callback if provided. |
| 215 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 216 | static u32 tsi148_VIRQ_irqhandler(struct vme_bridge *tsi148_bridge, |
| 217 | u32 stat) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 218 | { |
| 219 | int vec, i, serviced = 0; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 220 | struct tsi148_driver *bridge; |
| 221 | |
| 222 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 223 | |
| 224 | for (i = 7; i > 0; i--) { |
| 225 | if (stat & (1 << i)) { |
| 226 | /* |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 227 | * Note: Even though the registers are defined as |
| 228 | * 32-bits in the spec, we only want to issue 8-bit |
| 229 | * IACK cycles on the bus, read from offset 3. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 230 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 231 | vec = ioread8(bridge->base + TSI148_LCSR_VIACK[i] + 3); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 232 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 233 | vme_irq_handler(tsi148_bridge, i, vec); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 234 | |
| 235 | serviced |= (1 << i); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return serviced; |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Top level interrupt handler. Clears appropriate interrupt status bits and |
| 244 | * then calls appropriate sub handler(s). |
| 245 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 246 | static irqreturn_t tsi148_irqhandler(int irq, void *ptr) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 247 | { |
| 248 | u32 stat, enable, serviced = 0; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 249 | struct vme_bridge *tsi148_bridge; |
| 250 | struct tsi148_driver *bridge; |
| 251 | |
| 252 | tsi148_bridge = ptr; |
| 253 | |
| 254 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 255 | |
| 256 | /* Determine which interrupts are unmasked and set */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 257 | enable = ioread32be(bridge->base + TSI148_LCSR_INTEO); |
| 258 | stat = ioread32be(bridge->base + TSI148_LCSR_INTS); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 259 | |
| 260 | /* Only look at unmasked interrupts */ |
| 261 | stat &= enable; |
| 262 | |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 263 | if (unlikely(!stat)) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 264 | return IRQ_NONE; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 265 | |
| 266 | /* Call subhandlers as appropriate */ |
| 267 | /* DMA irqs */ |
| 268 | if (stat & (TSI148_LCSR_INTS_DMA1S | TSI148_LCSR_INTS_DMA0S)) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 269 | serviced |= tsi148_DMA_irqhandler(bridge, stat); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 270 | |
| 271 | /* Location monitor irqs */ |
| 272 | if (stat & (TSI148_LCSR_INTS_LM3S | TSI148_LCSR_INTS_LM2S | |
| 273 | TSI148_LCSR_INTS_LM1S | TSI148_LCSR_INTS_LM0S)) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 274 | serviced |= tsi148_LM_irqhandler(bridge, stat); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 275 | |
| 276 | /* Mail box irqs */ |
| 277 | if (stat & (TSI148_LCSR_INTS_MB3S | TSI148_LCSR_INTS_MB2S | |
| 278 | TSI148_LCSR_INTS_MB1S | TSI148_LCSR_INTS_MB0S)) |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 279 | serviced |= tsi148_MB_irqhandler(tsi148_bridge, stat); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 280 | |
| 281 | /* PCI bus error */ |
| 282 | if (stat & TSI148_LCSR_INTS_PERRS) |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 283 | serviced |= tsi148_PERR_irqhandler(tsi148_bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 284 | |
| 285 | /* VME bus error */ |
| 286 | if (stat & TSI148_LCSR_INTS_VERRS) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 287 | serviced |= tsi148_VERR_irqhandler(tsi148_bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 288 | |
| 289 | /* IACK irq */ |
| 290 | if (stat & TSI148_LCSR_INTS_IACKS) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 291 | serviced |= tsi148_IACK_irqhandler(bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 292 | |
| 293 | /* VME bus irqs */ |
| 294 | if (stat & (TSI148_LCSR_INTS_IRQ7S | TSI148_LCSR_INTS_IRQ6S | |
| 295 | TSI148_LCSR_INTS_IRQ5S | TSI148_LCSR_INTS_IRQ4S | |
| 296 | TSI148_LCSR_INTS_IRQ3S | TSI148_LCSR_INTS_IRQ2S | |
| 297 | TSI148_LCSR_INTS_IRQ1S)) |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 298 | serviced |= tsi148_VIRQ_irqhandler(tsi148_bridge, stat); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 299 | |
| 300 | /* Clear serviced interrupts */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 301 | iowrite32be(serviced, bridge->base + TSI148_LCSR_INTC); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 302 | |
| 303 | return IRQ_HANDLED; |
| 304 | } |
| 305 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 306 | static int tsi148_irq_init(struct vme_bridge *tsi148_bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 307 | { |
| 308 | int result; |
| 309 | unsigned int tmp; |
| 310 | struct pci_dev *pdev; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 311 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 312 | |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 313 | pdev = to_pci_dev(tsi148_bridge->parent); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 314 | |
| 315 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 316 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 317 | INIT_LIST_HEAD(&tsi148_bridge->vme_error_handlers); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 318 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 319 | mutex_init(&tsi148_bridge->irq_mtx); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 320 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 321 | result = request_irq(pdev->irq, |
| 322 | tsi148_irqhandler, |
| 323 | IRQF_SHARED, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 324 | driver_name, tsi148_bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 325 | if (result) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 326 | dev_err(tsi148_bridge->parent, "Can't get assigned pci irq " |
| 327 | "vector %02X\n", pdev->irq); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 328 | return result; |
| 329 | } |
| 330 | |
| 331 | /* Enable and unmask interrupts */ |
| 332 | tmp = TSI148_LCSR_INTEO_DMA1EO | TSI148_LCSR_INTEO_DMA0EO | |
| 333 | TSI148_LCSR_INTEO_MB3EO | TSI148_LCSR_INTEO_MB2EO | |
| 334 | TSI148_LCSR_INTEO_MB1EO | TSI148_LCSR_INTEO_MB0EO | |
| 335 | TSI148_LCSR_INTEO_PERREO | TSI148_LCSR_INTEO_VERREO | |
| 336 | TSI148_LCSR_INTEO_IACKEO; |
| 337 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 338 | /* This leaves the following interrupts masked. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 339 | * TSI148_LCSR_INTEO_VIEEO |
| 340 | * TSI148_LCSR_INTEO_SYSFLEO |
| 341 | * TSI148_LCSR_INTEO_ACFLEO |
| 342 | */ |
| 343 | |
| 344 | /* Don't enable Location Monitor interrupts here - they will be |
| 345 | * enabled when the location monitors are properly configured and |
| 346 | * a callback has been attached. |
| 347 | * TSI148_LCSR_INTEO_LM0EO |
| 348 | * TSI148_LCSR_INTEO_LM1EO |
| 349 | * TSI148_LCSR_INTEO_LM2EO |
| 350 | * TSI148_LCSR_INTEO_LM3EO |
| 351 | */ |
| 352 | |
| 353 | /* Don't enable VME interrupts until we add a handler, else the board |
| 354 | * will respond to it and we don't want that unless it knows how to |
| 355 | * properly deal with it. |
| 356 | * TSI148_LCSR_INTEO_IRQ7EO |
| 357 | * TSI148_LCSR_INTEO_IRQ6EO |
| 358 | * TSI148_LCSR_INTEO_IRQ5EO |
| 359 | * TSI148_LCSR_INTEO_IRQ4EO |
| 360 | * TSI148_LCSR_INTEO_IRQ3EO |
| 361 | * TSI148_LCSR_INTEO_IRQ2EO |
| 362 | * TSI148_LCSR_INTEO_IRQ1EO |
| 363 | */ |
| 364 | |
| 365 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO); |
| 366 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Emilio G. Cota | a82ad05 | 2010-11-12 11:14:47 +0000 | [diff] [blame] | 371 | static void tsi148_irq_exit(struct vme_bridge *tsi148_bridge, |
| 372 | struct pci_dev *pdev) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 373 | { |
Emilio G. Cota | a82ad05 | 2010-11-12 11:14:47 +0000 | [diff] [blame] | 374 | struct tsi148_driver *bridge = tsi148_bridge->driver_priv; |
| 375 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 376 | /* Turn off interrupts */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 377 | iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEO); |
| 378 | iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 379 | |
| 380 | /* Clear all interrupts */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 381 | iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_INTC); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 382 | |
| 383 | /* Detach interrupt handler */ |
Emilio G. Cota | a82ad05 | 2010-11-12 11:14:47 +0000 | [diff] [blame] | 384 | free_irq(pdev->irq, tsi148_bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* |
| 388 | * Check to see if an IACk has been received, return true (1) or false (0). |
| 389 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 390 | static int tsi148_iack_received(struct tsi148_driver *bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 391 | { |
| 392 | u32 tmp; |
| 393 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 394 | tmp = ioread32be(bridge->base + TSI148_LCSR_VICR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 395 | |
| 396 | if (tmp & TSI148_LCSR_VICR_IRQS) |
| 397 | return 0; |
| 398 | else |
| 399 | return 1; |
| 400 | } |
| 401 | |
| 402 | /* |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 403 | * Configure VME interrupt |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 404 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 405 | static void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 406 | int state, int sync) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 407 | { |
Martyn Welch | 7515502 | 2009-08-11 13:50:49 +0100 | [diff] [blame] | 408 | struct pci_dev *pdev; |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 409 | u32 tmp; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 410 | struct tsi148_driver *bridge; |
| 411 | |
| 412 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 413 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 414 | /* We need to do the ordering differently for enabling and disabling */ |
| 415 | if (state == 0) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 416 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 417 | tmp &= ~TSI148_LCSR_INTEN_IRQEN[level - 1]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 418 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | df45517 | 2009-08-05 17:38:31 +0100 | [diff] [blame] | 419 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 420 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | df45517 | 2009-08-05 17:38:31 +0100 | [diff] [blame] | 421 | tmp &= ~TSI148_LCSR_INTEO_IRQEO[level - 1]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 422 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | 7515502 | 2009-08-11 13:50:49 +0100 | [diff] [blame] | 423 | |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 424 | if (sync != 0) { |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 425 | pdev = to_pci_dev(tsi148_bridge->parent); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 426 | synchronize_irq(pdev->irq); |
| 427 | } |
| 428 | } else { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 429 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 430 | tmp |= TSI148_LCSR_INTEO_IRQEO[level - 1]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 431 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 432 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 433 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 434 | tmp |= TSI148_LCSR_INTEN_IRQEN[level - 1]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 435 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 436 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Generate a VME bus interrupt at the requested level & vector. Wait for |
| 441 | * interrupt to be acked. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 442 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 443 | static int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level, |
| 444 | int statid) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 445 | { |
| 446 | u32 tmp; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 447 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 448 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 449 | bridge = tsi148_bridge->driver_priv; |
| 450 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 451 | mutex_lock(&bridge->vme_int); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 452 | |
| 453 | /* Read VICR register */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 454 | tmp = ioread32be(bridge->base + TSI148_LCSR_VICR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 455 | |
| 456 | /* Set Status/ID */ |
| 457 | tmp = (tmp & ~TSI148_LCSR_VICR_STID_M) | |
| 458 | (statid & TSI148_LCSR_VICR_STID_M); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 459 | iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 460 | |
| 461 | /* Assert VMEbus IRQ */ |
| 462 | tmp = tmp | TSI148_LCSR_VICR_IRQL[level]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 463 | iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 464 | |
| 465 | /* XXX Consider implementing a timeout? */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 466 | wait_event_interruptible(bridge->iack_queue, |
| 467 | tsi148_iack_received(bridge)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 468 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 469 | mutex_unlock(&bridge->vme_int); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | /* |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 475 | * Initialize a slave window with the requested attributes. |
| 476 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 477 | static int tsi148_slave_set(struct vme_slave_resource *image, int enabled, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 478 | unsigned long long vme_base, unsigned long long size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 479 | dma_addr_t pci_base, u32 aspace, u32 cycle) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 480 | { |
| 481 | unsigned int i, addr = 0, granularity = 0; |
| 482 | unsigned int temp_ctl = 0; |
| 483 | unsigned int vme_base_low, vme_base_high; |
| 484 | unsigned int vme_bound_low, vme_bound_high; |
| 485 | unsigned int pci_offset_low, pci_offset_high; |
| 486 | unsigned long long vme_bound, pci_offset; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 487 | struct vme_bridge *tsi148_bridge; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 488 | struct tsi148_driver *bridge; |
| 489 | |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 490 | tsi148_bridge = image->parent; |
| 491 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 492 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 493 | i = image->number; |
| 494 | |
| 495 | switch (aspace) { |
| 496 | case VME_A16: |
| 497 | granularity = 0x10; |
| 498 | addr |= TSI148_LCSR_ITAT_AS_A16; |
| 499 | break; |
| 500 | case VME_A24: |
| 501 | granularity = 0x1000; |
| 502 | addr |= TSI148_LCSR_ITAT_AS_A24; |
| 503 | break; |
| 504 | case VME_A32: |
| 505 | granularity = 0x10000; |
| 506 | addr |= TSI148_LCSR_ITAT_AS_A32; |
| 507 | break; |
| 508 | case VME_A64: |
| 509 | granularity = 0x10000; |
| 510 | addr |= TSI148_LCSR_ITAT_AS_A64; |
| 511 | break; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 512 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 513 | dev_err(tsi148_bridge->parent, "Invalid address space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 514 | return -EINVAL; |
| 515 | break; |
| 516 | } |
| 517 | |
| 518 | /* Convert 64-bit variables to 2x 32-bit variables */ |
| 519 | reg_split(vme_base, &vme_base_high, &vme_base_low); |
| 520 | |
| 521 | /* |
| 522 | * Bound address is a valid address for the window, adjust |
| 523 | * accordingly |
| 524 | */ |
| 525 | vme_bound = vme_base + size - granularity; |
| 526 | reg_split(vme_bound, &vme_bound_high, &vme_bound_low); |
| 527 | pci_offset = (unsigned long long)pci_base - vme_base; |
| 528 | reg_split(pci_offset, &pci_offset_high, &pci_offset_low); |
| 529 | |
| 530 | if (vme_base_low & (granularity - 1)) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 531 | dev_err(tsi148_bridge->parent, "Invalid VME base alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 532 | return -EINVAL; |
| 533 | } |
| 534 | if (vme_bound_low & (granularity - 1)) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 535 | dev_err(tsi148_bridge->parent, "Invalid VME bound alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 536 | return -EINVAL; |
| 537 | } |
| 538 | if (pci_offset_low & (granularity - 1)) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 539 | dev_err(tsi148_bridge->parent, "Invalid PCI Offset " |
| 540 | "alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 541 | return -EINVAL; |
| 542 | } |
| 543 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 544 | /* Disable while we are mucking around */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 545 | temp_ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 546 | TSI148_LCSR_OFFSET_ITAT); |
| 547 | temp_ctl &= ~TSI148_LCSR_ITAT_EN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 548 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 549 | TSI148_LCSR_OFFSET_ITAT); |
| 550 | |
| 551 | /* Setup mapping */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 552 | iowrite32be(vme_base_high, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 553 | TSI148_LCSR_OFFSET_ITSAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 554 | iowrite32be(vme_base_low, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 555 | TSI148_LCSR_OFFSET_ITSAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 556 | iowrite32be(vme_bound_high, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 557 | TSI148_LCSR_OFFSET_ITEAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 558 | iowrite32be(vme_bound_low, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 559 | TSI148_LCSR_OFFSET_ITEAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 560 | iowrite32be(pci_offset_high, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 561 | TSI148_LCSR_OFFSET_ITOFU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 562 | iowrite32be(pci_offset_low, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 563 | TSI148_LCSR_OFFSET_ITOFL); |
| 564 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 565 | /* Setup 2eSST speeds */ |
| 566 | temp_ctl &= ~TSI148_LCSR_ITAT_2eSSTM_M; |
| 567 | switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { |
| 568 | case VME_2eSST160: |
| 569 | temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_160; |
| 570 | break; |
| 571 | case VME_2eSST267: |
| 572 | temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_267; |
| 573 | break; |
| 574 | case VME_2eSST320: |
| 575 | temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_320; |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | /* Setup cycle types */ |
| 580 | temp_ctl &= ~(0x1F << 7); |
| 581 | if (cycle & VME_BLT) |
| 582 | temp_ctl |= TSI148_LCSR_ITAT_BLT; |
| 583 | if (cycle & VME_MBLT) |
| 584 | temp_ctl |= TSI148_LCSR_ITAT_MBLT; |
| 585 | if (cycle & VME_2eVME) |
| 586 | temp_ctl |= TSI148_LCSR_ITAT_2eVME; |
| 587 | if (cycle & VME_2eSST) |
| 588 | temp_ctl |= TSI148_LCSR_ITAT_2eSST; |
| 589 | if (cycle & VME_2eSSTB) |
| 590 | temp_ctl |= TSI148_LCSR_ITAT_2eSSTB; |
| 591 | |
| 592 | /* Setup address space */ |
| 593 | temp_ctl &= ~TSI148_LCSR_ITAT_AS_M; |
| 594 | temp_ctl |= addr; |
| 595 | |
| 596 | temp_ctl &= ~0xF; |
| 597 | if (cycle & VME_SUPER) |
| 598 | temp_ctl |= TSI148_LCSR_ITAT_SUPR ; |
| 599 | if (cycle & VME_USER) |
| 600 | temp_ctl |= TSI148_LCSR_ITAT_NPRIV; |
| 601 | if (cycle & VME_PROG) |
| 602 | temp_ctl |= TSI148_LCSR_ITAT_PGM; |
| 603 | if (cycle & VME_DATA) |
| 604 | temp_ctl |= TSI148_LCSR_ITAT_DATA; |
| 605 | |
| 606 | /* Write ctl reg without enable */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 607 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 608 | TSI148_LCSR_OFFSET_ITAT); |
| 609 | |
| 610 | if (enabled) |
| 611 | temp_ctl |= TSI148_LCSR_ITAT_EN; |
| 612 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 613 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 614 | TSI148_LCSR_OFFSET_ITAT); |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | * Get slave window configuration. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 621 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 622 | static int tsi148_slave_get(struct vme_slave_resource *image, int *enabled, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 623 | unsigned long long *vme_base, unsigned long long *size, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 624 | dma_addr_t *pci_base, u32 *aspace, u32 *cycle) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 625 | { |
| 626 | unsigned int i, granularity = 0, ctl = 0; |
| 627 | unsigned int vme_base_low, vme_base_high; |
| 628 | unsigned int vme_bound_low, vme_bound_high; |
| 629 | unsigned int pci_offset_low, pci_offset_high; |
| 630 | unsigned long long vme_bound, pci_offset; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 631 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 632 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 633 | bridge = image->parent->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 634 | |
| 635 | i = image->number; |
| 636 | |
| 637 | /* Read registers */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 638 | ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 639 | TSI148_LCSR_OFFSET_ITAT); |
| 640 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 641 | vme_base_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 642 | TSI148_LCSR_OFFSET_ITSAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 643 | vme_base_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 644 | TSI148_LCSR_OFFSET_ITSAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 645 | vme_bound_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 646 | TSI148_LCSR_OFFSET_ITEAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 647 | vme_bound_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 648 | TSI148_LCSR_OFFSET_ITEAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 649 | pci_offset_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 650 | TSI148_LCSR_OFFSET_ITOFU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 651 | pci_offset_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 652 | TSI148_LCSR_OFFSET_ITOFL); |
| 653 | |
| 654 | /* Convert 64-bit variables to 2x 32-bit variables */ |
| 655 | reg_join(vme_base_high, vme_base_low, vme_base); |
| 656 | reg_join(vme_bound_high, vme_bound_low, &vme_bound); |
| 657 | reg_join(pci_offset_high, pci_offset_low, &pci_offset); |
| 658 | |
Joe Schultz | 098ced8 | 2014-04-03 14:47:55 -0500 | [diff] [blame] | 659 | *pci_base = (dma_addr_t)(*vme_base + pci_offset); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 660 | |
| 661 | *enabled = 0; |
| 662 | *aspace = 0; |
| 663 | *cycle = 0; |
| 664 | |
| 665 | if (ctl & TSI148_LCSR_ITAT_EN) |
| 666 | *enabled = 1; |
| 667 | |
| 668 | if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A16) { |
| 669 | granularity = 0x10; |
| 670 | *aspace |= VME_A16; |
| 671 | } |
| 672 | if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A24) { |
| 673 | granularity = 0x1000; |
| 674 | *aspace |= VME_A24; |
| 675 | } |
| 676 | if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A32) { |
| 677 | granularity = 0x10000; |
| 678 | *aspace |= VME_A32; |
| 679 | } |
| 680 | if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A64) { |
| 681 | granularity = 0x10000; |
| 682 | *aspace |= VME_A64; |
| 683 | } |
| 684 | |
| 685 | /* Need granularity before we set the size */ |
| 686 | *size = (unsigned long long)((vme_bound - *vme_base) + granularity); |
| 687 | |
| 688 | |
| 689 | if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_160) |
| 690 | *cycle |= VME_2eSST160; |
| 691 | if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_267) |
| 692 | *cycle |= VME_2eSST267; |
| 693 | if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_320) |
| 694 | *cycle |= VME_2eSST320; |
| 695 | |
| 696 | if (ctl & TSI148_LCSR_ITAT_BLT) |
| 697 | *cycle |= VME_BLT; |
| 698 | if (ctl & TSI148_LCSR_ITAT_MBLT) |
| 699 | *cycle |= VME_MBLT; |
| 700 | if (ctl & TSI148_LCSR_ITAT_2eVME) |
| 701 | *cycle |= VME_2eVME; |
| 702 | if (ctl & TSI148_LCSR_ITAT_2eSST) |
| 703 | *cycle |= VME_2eSST; |
| 704 | if (ctl & TSI148_LCSR_ITAT_2eSSTB) |
| 705 | *cycle |= VME_2eSSTB; |
| 706 | |
| 707 | if (ctl & TSI148_LCSR_ITAT_SUPR) |
| 708 | *cycle |= VME_SUPER; |
| 709 | if (ctl & TSI148_LCSR_ITAT_NPRIV) |
| 710 | *cycle |= VME_USER; |
| 711 | if (ctl & TSI148_LCSR_ITAT_PGM) |
| 712 | *cycle |= VME_PROG; |
| 713 | if (ctl & TSI148_LCSR_ITAT_DATA) |
| 714 | *cycle |= VME_DATA; |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | /* |
| 720 | * Allocate and map PCI Resource |
| 721 | */ |
| 722 | static int tsi148_alloc_resource(struct vme_master_resource *image, |
| 723 | unsigned long long size) |
| 724 | { |
| 725 | unsigned long long existing_size; |
| 726 | int retval = 0; |
| 727 | struct pci_dev *pdev; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 728 | struct vme_bridge *tsi148_bridge; |
| 729 | |
| 730 | tsi148_bridge = image->parent; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 731 | |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 732 | pdev = to_pci_dev(tsi148_bridge->parent); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 733 | |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 734 | existing_size = (unsigned long long)(image->bus_resource.end - |
| 735 | image->bus_resource.start); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 736 | |
| 737 | /* If the existing size is OK, return */ |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 738 | if ((size != 0) && (existing_size == (size - 1))) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 739 | return 0; |
| 740 | |
| 741 | if (existing_size != 0) { |
| 742 | iounmap(image->kern_base); |
| 743 | image->kern_base = NULL; |
Ilia Mirkin | 794a894 | 2011-03-13 00:29:13 -0500 | [diff] [blame] | 744 | kfree(image->bus_resource.name); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 745 | release_resource(&image->bus_resource); |
| 746 | memset(&image->bus_resource, 0, sizeof(struct resource)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 749 | /* Exit here if size is zero */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 750 | if (size == 0) |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 751 | return 0; |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 752 | |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 753 | if (image->bus_resource.name == NULL) { |
Julia Lawall | 0aa3f13 | 2010-05-30 22:27:46 +0200 | [diff] [blame] | 754 | image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 755 | if (image->bus_resource.name == NULL) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 756 | dev_err(tsi148_bridge->parent, "Unable to allocate " |
| 757 | "memory for resource name\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 758 | retval = -ENOMEM; |
| 759 | goto err_name; |
| 760 | } |
| 761 | } |
| 762 | |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 763 | sprintf((char *)image->bus_resource.name, "%s.%d", tsi148_bridge->name, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 764 | image->number); |
| 765 | |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 766 | image->bus_resource.start = 0; |
| 767 | image->bus_resource.end = (unsigned long)size; |
| 768 | image->bus_resource.flags = IORESOURCE_MEM; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 769 | |
| 770 | retval = pci_bus_alloc_resource(pdev->bus, |
Dmitry Kalinkin | da5ae8a | 2015-07-08 17:42:17 +0300 | [diff] [blame] | 771 | &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 772 | 0, NULL, NULL); |
| 773 | if (retval) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 774 | dev_err(tsi148_bridge->parent, "Failed to allocate mem " |
| 775 | "resource for window %d size 0x%lx start 0x%lx\n", |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 776 | image->number, (unsigned long)size, |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 777 | (unsigned long)image->bus_resource.start); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 778 | goto err_resource; |
| 779 | } |
| 780 | |
| 781 | image->kern_base = ioremap_nocache( |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 782 | image->bus_resource.start, size); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 783 | if (image->kern_base == NULL) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 784 | dev_err(tsi148_bridge->parent, "Failed to remap resource\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 785 | retval = -ENOMEM; |
| 786 | goto err_remap; |
| 787 | } |
| 788 | |
| 789 | return 0; |
| 790 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 791 | err_remap: |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 792 | release_resource(&image->bus_resource); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 793 | err_resource: |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 794 | kfree(image->bus_resource.name); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 795 | memset(&image->bus_resource, 0, sizeof(struct resource)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 796 | err_name: |
| 797 | return retval; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Free and unmap PCI Resource |
| 802 | */ |
| 803 | static void tsi148_free_resource(struct vme_master_resource *image) |
| 804 | { |
| 805 | iounmap(image->kern_base); |
| 806 | image->kern_base = NULL; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 807 | release_resource(&image->bus_resource); |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 808 | kfree(image->bus_resource.name); |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 809 | memset(&image->bus_resource, 0, sizeof(struct resource)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* |
| 813 | * Set the attributes of an outbound window. |
| 814 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 815 | static int tsi148_master_set(struct vme_master_resource *image, int enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 816 | unsigned long long vme_base, unsigned long long size, u32 aspace, |
| 817 | u32 cycle, u32 dwidth) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 818 | { |
| 819 | int retval = 0; |
| 820 | unsigned int i; |
| 821 | unsigned int temp_ctl = 0; |
| 822 | unsigned int pci_base_low, pci_base_high; |
| 823 | unsigned int pci_bound_low, pci_bound_high; |
| 824 | unsigned int vme_offset_low, vme_offset_high; |
| 825 | unsigned long long pci_bound, vme_offset, pci_base; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 826 | struct vme_bridge *tsi148_bridge; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 827 | struct tsi148_driver *bridge; |
Joe Schultz | 226572b | 2014-04-03 14:48:16 -0500 | [diff] [blame] | 828 | struct pci_bus_region region; |
| 829 | struct pci_dev *pdev; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 830 | |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 831 | tsi148_bridge = image->parent; |
| 832 | |
| 833 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 834 | |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 835 | pdev = to_pci_dev(tsi148_bridge->parent); |
Joe Schultz | 226572b | 2014-04-03 14:48:16 -0500 | [diff] [blame] | 836 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 837 | /* Verify input data */ |
| 838 | if (vme_base & 0xFFFF) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 839 | dev_err(tsi148_bridge->parent, "Invalid VME Window " |
| 840 | "alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 841 | retval = -EINVAL; |
| 842 | goto err_window; |
| 843 | } |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 844 | |
| 845 | if ((size == 0) && (enabled != 0)) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 846 | dev_err(tsi148_bridge->parent, "Size must be non-zero for " |
| 847 | "enabled windows\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 848 | retval = -EINVAL; |
| 849 | goto err_window; |
| 850 | } |
| 851 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 852 | spin_lock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 853 | |
| 854 | /* Let's allocate the resource here rather than further up the stack as |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 855 | * it avoids pushing loads of bus dependent stuff up the stack. If size |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 856 | * is zero, any existing resource will be freed. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 857 | */ |
| 858 | retval = tsi148_alloc_resource(image, size); |
| 859 | if (retval) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 860 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 861 | dev_err(tsi148_bridge->parent, "Unable to allocate memory for " |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 862 | "resource\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 863 | goto err_res; |
| 864 | } |
| 865 | |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 866 | if (size == 0) { |
| 867 | pci_base = 0; |
| 868 | pci_bound = 0; |
| 869 | vme_offset = 0; |
| 870 | } else { |
Joe Schultz | 226572b | 2014-04-03 14:48:16 -0500 | [diff] [blame] | 871 | pcibios_resource_to_bus(pdev->bus, ®ion, |
| 872 | &image->bus_resource); |
| 873 | pci_base = region.start; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 874 | |
Martyn Welch | 59c2290 | 2009-10-29 16:35:01 +0000 | [diff] [blame] | 875 | /* |
| 876 | * Bound address is a valid address for the window, adjust |
| 877 | * according to window granularity. |
| 878 | */ |
| 879 | pci_bound = pci_base + (size - 0x10000); |
| 880 | vme_offset = vme_base - pci_base; |
| 881 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 882 | |
| 883 | /* Convert 64-bit variables to 2x 32-bit variables */ |
| 884 | reg_split(pci_base, &pci_base_high, &pci_base_low); |
| 885 | reg_split(pci_bound, &pci_bound_high, &pci_bound_low); |
| 886 | reg_split(vme_offset, &vme_offset_high, &vme_offset_low); |
| 887 | |
| 888 | if (pci_base_low & 0xFFFF) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 889 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 890 | dev_err(tsi148_bridge->parent, "Invalid PCI base alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 891 | retval = -EINVAL; |
| 892 | goto err_gran; |
| 893 | } |
| 894 | if (pci_bound_low & 0xFFFF) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 895 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 896 | dev_err(tsi148_bridge->parent, "Invalid PCI bound alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 897 | retval = -EINVAL; |
| 898 | goto err_gran; |
| 899 | } |
| 900 | if (vme_offset_low & 0xFFFF) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 901 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 902 | dev_err(tsi148_bridge->parent, "Invalid VME Offset " |
| 903 | "alignment\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 904 | retval = -EINVAL; |
| 905 | goto err_gran; |
| 906 | } |
| 907 | |
| 908 | i = image->number; |
| 909 | |
| 910 | /* Disable while we are mucking around */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 911 | temp_ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 912 | TSI148_LCSR_OFFSET_OTAT); |
| 913 | temp_ctl &= ~TSI148_LCSR_OTAT_EN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 914 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 915 | TSI148_LCSR_OFFSET_OTAT); |
| 916 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 917 | /* Setup 2eSST speeds */ |
| 918 | temp_ctl &= ~TSI148_LCSR_OTAT_2eSSTM_M; |
| 919 | switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { |
| 920 | case VME_2eSST160: |
| 921 | temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_160; |
| 922 | break; |
| 923 | case VME_2eSST267: |
| 924 | temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_267; |
| 925 | break; |
| 926 | case VME_2eSST320: |
| 927 | temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_320; |
| 928 | break; |
| 929 | } |
| 930 | |
| 931 | /* Setup cycle types */ |
| 932 | if (cycle & VME_BLT) { |
| 933 | temp_ctl &= ~TSI148_LCSR_OTAT_TM_M; |
| 934 | temp_ctl |= TSI148_LCSR_OTAT_TM_BLT; |
| 935 | } |
| 936 | if (cycle & VME_MBLT) { |
| 937 | temp_ctl &= ~TSI148_LCSR_OTAT_TM_M; |
| 938 | temp_ctl |= TSI148_LCSR_OTAT_TM_MBLT; |
| 939 | } |
| 940 | if (cycle & VME_2eVME) { |
| 941 | temp_ctl &= ~TSI148_LCSR_OTAT_TM_M; |
| 942 | temp_ctl |= TSI148_LCSR_OTAT_TM_2eVME; |
| 943 | } |
| 944 | if (cycle & VME_2eSST) { |
| 945 | temp_ctl &= ~TSI148_LCSR_OTAT_TM_M; |
| 946 | temp_ctl |= TSI148_LCSR_OTAT_TM_2eSST; |
| 947 | } |
| 948 | if (cycle & VME_2eSSTB) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 949 | dev_warn(tsi148_bridge->parent, "Currently not setting " |
| 950 | "Broadcast Select Registers\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 951 | temp_ctl &= ~TSI148_LCSR_OTAT_TM_M; |
| 952 | temp_ctl |= TSI148_LCSR_OTAT_TM_2eSSTB; |
| 953 | } |
| 954 | |
| 955 | /* Setup data width */ |
| 956 | temp_ctl &= ~TSI148_LCSR_OTAT_DBW_M; |
| 957 | switch (dwidth) { |
| 958 | case VME_D16: |
| 959 | temp_ctl |= TSI148_LCSR_OTAT_DBW_16; |
| 960 | break; |
| 961 | case VME_D32: |
| 962 | temp_ctl |= TSI148_LCSR_OTAT_DBW_32; |
| 963 | break; |
| 964 | default: |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 965 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 966 | dev_err(tsi148_bridge->parent, "Invalid data width\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 967 | retval = -EINVAL; |
| 968 | goto err_dwidth; |
| 969 | } |
| 970 | |
| 971 | /* Setup address space */ |
| 972 | temp_ctl &= ~TSI148_LCSR_OTAT_AMODE_M; |
| 973 | switch (aspace) { |
| 974 | case VME_A16: |
| 975 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_A16; |
| 976 | break; |
| 977 | case VME_A24: |
| 978 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_A24; |
| 979 | break; |
| 980 | case VME_A32: |
| 981 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_A32; |
| 982 | break; |
| 983 | case VME_A64: |
| 984 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_A64; |
| 985 | break; |
| 986 | case VME_CRCSR: |
| 987 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_CRCSR; |
| 988 | break; |
| 989 | case VME_USER1: |
| 990 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER1; |
| 991 | break; |
| 992 | case VME_USER2: |
| 993 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER2; |
| 994 | break; |
| 995 | case VME_USER3: |
| 996 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER3; |
| 997 | break; |
| 998 | case VME_USER4: |
| 999 | temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER4; |
| 1000 | break; |
| 1001 | default: |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1002 | spin_unlock(&image->lock); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1003 | dev_err(tsi148_bridge->parent, "Invalid address space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1004 | retval = -EINVAL; |
| 1005 | goto err_aspace; |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | temp_ctl &= ~(3<<4); |
| 1010 | if (cycle & VME_SUPER) |
| 1011 | temp_ctl |= TSI148_LCSR_OTAT_SUP; |
| 1012 | if (cycle & VME_PROG) |
| 1013 | temp_ctl |= TSI148_LCSR_OTAT_PGM; |
| 1014 | |
| 1015 | /* Setup mapping */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1016 | iowrite32be(pci_base_high, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1017 | TSI148_LCSR_OFFSET_OTSAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1018 | iowrite32be(pci_base_low, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1019 | TSI148_LCSR_OFFSET_OTSAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1020 | iowrite32be(pci_bound_high, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1021 | TSI148_LCSR_OFFSET_OTEAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1022 | iowrite32be(pci_bound_low, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1023 | TSI148_LCSR_OFFSET_OTEAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1024 | iowrite32be(vme_offset_high, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1025 | TSI148_LCSR_OFFSET_OTOFU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1026 | iowrite32be(vme_offset_low, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1027 | TSI148_LCSR_OFFSET_OTOFL); |
| 1028 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1029 | /* Write ctl reg without enable */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1030 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1031 | TSI148_LCSR_OFFSET_OTAT); |
| 1032 | |
| 1033 | if (enabled) |
| 1034 | temp_ctl |= TSI148_LCSR_OTAT_EN; |
| 1035 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1036 | iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1037 | TSI148_LCSR_OFFSET_OTAT); |
| 1038 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1039 | spin_unlock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1040 | return 0; |
| 1041 | |
| 1042 | err_aspace: |
| 1043 | err_dwidth: |
| 1044 | err_gran: |
| 1045 | tsi148_free_resource(image); |
| 1046 | err_res: |
| 1047 | err_window: |
| 1048 | return retval; |
| 1049 | |
| 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * Set the attributes of an outbound window. |
| 1054 | * |
| 1055 | * XXX Not parsing prefetch information. |
| 1056 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1057 | static int __tsi148_master_get(struct vme_master_resource *image, int *enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1058 | unsigned long long *vme_base, unsigned long long *size, u32 *aspace, |
| 1059 | u32 *cycle, u32 *dwidth) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1060 | { |
| 1061 | unsigned int i, ctl; |
| 1062 | unsigned int pci_base_low, pci_base_high; |
| 1063 | unsigned int pci_bound_low, pci_bound_high; |
| 1064 | unsigned int vme_offset_low, vme_offset_high; |
| 1065 | |
| 1066 | unsigned long long pci_base, pci_bound, vme_offset; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1067 | struct tsi148_driver *bridge; |
| 1068 | |
| 1069 | bridge = image->parent->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1070 | |
| 1071 | i = image->number; |
| 1072 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1073 | ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1074 | TSI148_LCSR_OFFSET_OTAT); |
| 1075 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1076 | pci_base_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1077 | TSI148_LCSR_OFFSET_OTSAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1078 | pci_base_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1079 | TSI148_LCSR_OFFSET_OTSAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1080 | pci_bound_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1081 | TSI148_LCSR_OFFSET_OTEAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1082 | pci_bound_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1083 | TSI148_LCSR_OFFSET_OTEAL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1084 | vme_offset_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1085 | TSI148_LCSR_OFFSET_OTOFU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1086 | vme_offset_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1087 | TSI148_LCSR_OFFSET_OTOFL); |
| 1088 | |
| 1089 | /* Convert 64-bit variables to 2x 32-bit variables */ |
| 1090 | reg_join(pci_base_high, pci_base_low, &pci_base); |
| 1091 | reg_join(pci_bound_high, pci_bound_low, &pci_bound); |
| 1092 | reg_join(vme_offset_high, vme_offset_low, &vme_offset); |
| 1093 | |
| 1094 | *vme_base = pci_base + vme_offset; |
| 1095 | *size = (unsigned long long)(pci_bound - pci_base) + 0x10000; |
| 1096 | |
| 1097 | *enabled = 0; |
| 1098 | *aspace = 0; |
| 1099 | *cycle = 0; |
| 1100 | *dwidth = 0; |
| 1101 | |
| 1102 | if (ctl & TSI148_LCSR_OTAT_EN) |
| 1103 | *enabled = 1; |
| 1104 | |
| 1105 | /* Setup address space */ |
| 1106 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A16) |
| 1107 | *aspace |= VME_A16; |
| 1108 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A24) |
| 1109 | *aspace |= VME_A24; |
| 1110 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A32) |
| 1111 | *aspace |= VME_A32; |
| 1112 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A64) |
| 1113 | *aspace |= VME_A64; |
| 1114 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_CRCSR) |
| 1115 | *aspace |= VME_CRCSR; |
| 1116 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER1) |
| 1117 | *aspace |= VME_USER1; |
| 1118 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER2) |
| 1119 | *aspace |= VME_USER2; |
| 1120 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER3) |
| 1121 | *aspace |= VME_USER3; |
| 1122 | if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER4) |
| 1123 | *aspace |= VME_USER4; |
| 1124 | |
| 1125 | /* Setup 2eSST speeds */ |
| 1126 | if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_160) |
| 1127 | *cycle |= VME_2eSST160; |
| 1128 | if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_267) |
| 1129 | *cycle |= VME_2eSST267; |
| 1130 | if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_320) |
| 1131 | *cycle |= VME_2eSST320; |
| 1132 | |
| 1133 | /* Setup cycle types */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1134 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_SCT) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1135 | *cycle |= VME_SCT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1136 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_BLT) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1137 | *cycle |= VME_BLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1138 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_MBLT) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1139 | *cycle |= VME_MBLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1140 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eVME) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1141 | *cycle |= VME_2eVME; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1142 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSST) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1143 | *cycle |= VME_2eSST; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1144 | if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSSTB) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1145 | *cycle |= VME_2eSSTB; |
| 1146 | |
| 1147 | if (ctl & TSI148_LCSR_OTAT_SUP) |
| 1148 | *cycle |= VME_SUPER; |
| 1149 | else |
| 1150 | *cycle |= VME_USER; |
| 1151 | |
| 1152 | if (ctl & TSI148_LCSR_OTAT_PGM) |
| 1153 | *cycle |= VME_PROG; |
| 1154 | else |
| 1155 | *cycle |= VME_DATA; |
| 1156 | |
| 1157 | /* Setup data width */ |
| 1158 | if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_16) |
| 1159 | *dwidth = VME_D16; |
| 1160 | if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_32) |
| 1161 | *dwidth = VME_D32; |
| 1162 | |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1167 | static int tsi148_master_get(struct vme_master_resource *image, int *enabled, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1168 | unsigned long long *vme_base, unsigned long long *size, u32 *aspace, |
| 1169 | u32 *cycle, u32 *dwidth) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1170 | { |
| 1171 | int retval; |
| 1172 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1173 | spin_lock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1174 | |
| 1175 | retval = __tsi148_master_get(image, enabled, vme_base, size, aspace, |
| 1176 | cycle, dwidth); |
| 1177 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1178 | spin_unlock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1179 | |
| 1180 | return retval; |
| 1181 | } |
| 1182 | |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1183 | static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1184 | size_t count, loff_t offset) |
| 1185 | { |
| 1186 | int retval, enabled; |
| 1187 | unsigned long long vme_base, size; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1188 | u32 aspace, cycle, dwidth; |
Dmitry Kalinkin | d3337eb | 2015-10-05 06:59:17 +0300 | [diff] [blame] | 1189 | struct vme_error_handler *handler = NULL; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1190 | struct vme_bridge *tsi148_bridge; |
Jingoo Han | 4e8764d | 2013-08-19 16:40:15 +0900 | [diff] [blame] | 1191 | void __iomem *addr = image->kern_base + offset; |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1192 | unsigned int done = 0; |
| 1193 | unsigned int count32; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1194 | |
| 1195 | tsi148_bridge = image->parent; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1196 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1197 | spin_lock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1198 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1199 | if (err_chk) { |
| 1200 | __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, |
| 1201 | &cycle, &dwidth); |
| 1202 | handler = vme_register_error_handler(tsi148_bridge, aspace, |
| 1203 | vme_base + offset, count); |
| 1204 | if (!handler) { |
| 1205 | spin_unlock(&image->lock); |
| 1206 | return -ENOMEM; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1210 | /* The following code handles VME address alignment. We cannot use |
Martyn Welch | a2a720e | 2014-02-06 13:35:36 +0000 | [diff] [blame] | 1211 | * memcpy_xxx here because it may cut data transfers in to 8-bit |
| 1212 | * cycles when D16 or D32 cycles are required on the VME bus. |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1213 | * On the other hand, the bridge itself assures that the maximum data |
| 1214 | * cycle configured for the transfer is used and splits it |
| 1215 | * automatically for non-aligned addresses, so we don't want the |
| 1216 | * overhead of needlessly forcing small transfers for the entire cycle. |
| 1217 | */ |
| 1218 | if ((uintptr_t)addr & 0x1) { |
| 1219 | *(u8 *)buf = ioread8(addr); |
| 1220 | done += 1; |
| 1221 | if (done == count) |
| 1222 | goto out; |
| 1223 | } |
Martyn Welch | f0342e6 | 2014-02-07 15:48:56 +0000 | [diff] [blame] | 1224 | if ((uintptr_t)(addr + done) & 0x2) { |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1225 | if ((count - done) < 2) { |
| 1226 | *(u8 *)(buf + done) = ioread8(addr + done); |
| 1227 | done += 1; |
| 1228 | goto out; |
| 1229 | } else { |
| 1230 | *(u16 *)(buf + done) = ioread16(addr + done); |
| 1231 | done += 2; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | count32 = (count - done) & ~0x3; |
Martyn Welch | a2a720e | 2014-02-06 13:35:36 +0000 | [diff] [blame] | 1236 | while (done < count32) { |
| 1237 | *(u32 *)(buf + done) = ioread32(addr + done); |
| 1238 | done += 4; |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | if ((count - done) & 0x2) { |
| 1242 | *(u16 *)(buf + done) = ioread16(addr + done); |
| 1243 | done += 2; |
| 1244 | } |
| 1245 | if ((count - done) & 0x1) { |
| 1246 | *(u8 *)(buf + done) = ioread8(addr + done); |
| 1247 | done += 1; |
| 1248 | } |
| 1249 | |
| 1250 | out: |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1251 | retval = count; |
| 1252 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1253 | if (err_chk) { |
| 1254 | if (handler->num_errors) { |
| 1255 | dev_err(image->parent->parent, |
| 1256 | "First VME read error detected an at address 0x%llx\n", |
| 1257 | handler->first_error); |
| 1258 | retval = handler->first_error - (vme_base + offset); |
| 1259 | } |
| 1260 | vme_unregister_error_handler(handler); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1263 | spin_unlock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1264 | |
| 1265 | return retval; |
| 1266 | } |
| 1267 | |
| 1268 | |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1269 | static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1270 | size_t count, loff_t offset) |
| 1271 | { |
| 1272 | int retval = 0, enabled; |
| 1273 | unsigned long long vme_base, size; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1274 | u32 aspace, cycle, dwidth; |
Jingoo Han | 4e8764d | 2013-08-19 16:40:15 +0900 | [diff] [blame] | 1275 | void __iomem *addr = image->kern_base + offset; |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1276 | unsigned int done = 0; |
| 1277 | unsigned int count32; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1278 | |
Dmitry Kalinkin | d3337eb | 2015-10-05 06:59:17 +0300 | [diff] [blame] | 1279 | struct vme_error_handler *handler = NULL; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1280 | struct vme_bridge *tsi148_bridge; |
| 1281 | struct tsi148_driver *bridge; |
| 1282 | |
| 1283 | tsi148_bridge = image->parent; |
| 1284 | |
| 1285 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1286 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1287 | spin_lock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1288 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1289 | if (err_chk) { |
| 1290 | __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, |
| 1291 | &cycle, &dwidth); |
| 1292 | handler = vme_register_error_handler(tsi148_bridge, aspace, |
| 1293 | vme_base + offset, count); |
| 1294 | if (!handler) { |
| 1295 | spin_unlock(&image->lock); |
| 1296 | return -ENOMEM; |
| 1297 | } |
| 1298 | } |
| 1299 | |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1300 | /* Here we apply for the same strategy we do in master_read |
Martyn Welch | a2a720e | 2014-02-06 13:35:36 +0000 | [diff] [blame] | 1301 | * function in order to assure the correct cycles. |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1302 | */ |
| 1303 | if ((uintptr_t)addr & 0x1) { |
| 1304 | iowrite8(*(u8 *)buf, addr); |
| 1305 | done += 1; |
| 1306 | if (done == count) |
| 1307 | goto out; |
| 1308 | } |
Martyn Welch | f0342e6 | 2014-02-07 15:48:56 +0000 | [diff] [blame] | 1309 | if ((uintptr_t)(addr + done) & 0x2) { |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1310 | if ((count - done) < 2) { |
| 1311 | iowrite8(*(u8 *)(buf + done), addr + done); |
| 1312 | done += 1; |
| 1313 | goto out; |
| 1314 | } else { |
| 1315 | iowrite16(*(u16 *)(buf + done), addr + done); |
| 1316 | done += 2; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | count32 = (count - done) & ~0x3; |
Martyn Welch | a2a720e | 2014-02-06 13:35:36 +0000 | [diff] [blame] | 1321 | while (done < count32) { |
| 1322 | iowrite32(*(u32 *)(buf + done), addr + done); |
| 1323 | done += 4; |
Martyn Welch | 363e2e6 | 2012-07-19 17:48:46 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | if ((count - done) & 0x2) { |
| 1327 | iowrite16(*(u16 *)(buf + done), addr + done); |
| 1328 | done += 2; |
| 1329 | } |
| 1330 | if ((count - done) & 0x1) { |
| 1331 | iowrite8(*(u8 *)(buf + done), addr + done); |
| 1332 | done += 1; |
| 1333 | } |
| 1334 | |
| 1335 | out: |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1336 | retval = count; |
| 1337 | |
| 1338 | /* |
| 1339 | * Writes are posted. We need to do a read on the VME bus to flush out |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1340 | * all of the writes before we check for errors. We can't guarantee |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1341 | * that reading the data we have just written is safe. It is believed |
| 1342 | * that there isn't any read, write re-ordering, so we can read any |
| 1343 | * location in VME space, so lets read the Device ID from the tsi148's |
| 1344 | * own registers as mapped into CR/CSR space. |
| 1345 | * |
| 1346 | * We check for saved errors in the written address range/space. |
| 1347 | */ |
| 1348 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1349 | if (err_chk) { |
| 1350 | ioread16(bridge->flush_image->kern_base + 0x7F000); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1351 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 1352 | if (handler->num_errors) { |
| 1353 | dev_warn(tsi148_bridge->parent, |
| 1354 | "First VME write error detected an at address 0x%llx\n", |
| 1355 | handler->first_error); |
| 1356 | retval = handler->first_error - (vme_base + offset); |
| 1357 | } |
| 1358 | vme_unregister_error_handler(handler); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1359 | } |
| 1360 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1361 | spin_unlock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1362 | |
| 1363 | return retval; |
| 1364 | } |
| 1365 | |
| 1366 | /* |
| 1367 | * Perform an RMW cycle on the VME bus. |
| 1368 | * |
| 1369 | * Requires a previously configured master window, returns final value. |
| 1370 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1371 | static unsigned int tsi148_master_rmw(struct vme_master_resource *image, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1372 | unsigned int mask, unsigned int compare, unsigned int swap, |
| 1373 | loff_t offset) |
| 1374 | { |
| 1375 | unsigned long long pci_addr; |
| 1376 | unsigned int pci_addr_high, pci_addr_low; |
| 1377 | u32 tmp, result; |
| 1378 | int i; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1379 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1380 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1381 | bridge = image->parent->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1382 | |
| 1383 | /* Find the PCI address that maps to the desired VME address */ |
| 1384 | i = image->number; |
| 1385 | |
| 1386 | /* Locking as we can only do one of these at a time */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1387 | mutex_lock(&bridge->vme_rmw); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1388 | |
| 1389 | /* Lock image */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1390 | spin_lock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1391 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1392 | pci_addr_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1393 | TSI148_LCSR_OFFSET_OTSAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1394 | pci_addr_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1395 | TSI148_LCSR_OFFSET_OTSAL); |
| 1396 | |
| 1397 | reg_join(pci_addr_high, pci_addr_low, &pci_addr); |
| 1398 | reg_split(pci_addr + offset, &pci_addr_high, &pci_addr_low); |
| 1399 | |
| 1400 | /* Configure registers */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1401 | iowrite32be(mask, bridge->base + TSI148_LCSR_RMWEN); |
| 1402 | iowrite32be(compare, bridge->base + TSI148_LCSR_RMWC); |
| 1403 | iowrite32be(swap, bridge->base + TSI148_LCSR_RMWS); |
| 1404 | iowrite32be(pci_addr_high, bridge->base + TSI148_LCSR_RMWAU); |
| 1405 | iowrite32be(pci_addr_low, bridge->base + TSI148_LCSR_RMWAL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1406 | |
| 1407 | /* Enable RMW */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1408 | tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1409 | tmp |= TSI148_LCSR_VMCTRL_RMWEN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1410 | iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1411 | |
| 1412 | /* Kick process off with a read to the required address. */ |
| 1413 | result = ioread32be(image->kern_base + offset); |
| 1414 | |
| 1415 | /* Disable RMW */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1416 | tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1417 | tmp &= ~TSI148_LCSR_VMCTRL_RMWEN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1418 | iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1419 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1420 | spin_unlock(&image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1421 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1422 | mutex_unlock(&bridge->vme_rmw); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1423 | |
| 1424 | return result; |
| 1425 | } |
| 1426 | |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1427 | static int tsi148_dma_set_vme_src_attributes(struct device *dev, __be32 *attr, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1428 | u32 aspace, u32 cycle, u32 dwidth) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1429 | { |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1430 | u32 val; |
| 1431 | |
| 1432 | val = be32_to_cpu(*attr); |
| 1433 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1434 | /* Setup 2eSST speeds */ |
| 1435 | switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { |
| 1436 | case VME_2eSST160: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1437 | val |= TSI148_LCSR_DSAT_2eSSTM_160; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1438 | break; |
| 1439 | case VME_2eSST267: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1440 | val |= TSI148_LCSR_DSAT_2eSSTM_267; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1441 | break; |
| 1442 | case VME_2eSST320: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1443 | val |= TSI148_LCSR_DSAT_2eSSTM_320; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | /* Setup cycle types */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1448 | if (cycle & VME_SCT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1449 | val |= TSI148_LCSR_DSAT_TM_SCT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1450 | |
| 1451 | if (cycle & VME_BLT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1452 | val |= TSI148_LCSR_DSAT_TM_BLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1453 | |
| 1454 | if (cycle & VME_MBLT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1455 | val |= TSI148_LCSR_DSAT_TM_MBLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1456 | |
| 1457 | if (cycle & VME_2eVME) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1458 | val |= TSI148_LCSR_DSAT_TM_2eVME; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1459 | |
| 1460 | if (cycle & VME_2eSST) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1461 | val |= TSI148_LCSR_DSAT_TM_2eSST; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1462 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1463 | if (cycle & VME_2eSSTB) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1464 | dev_err(dev, "Currently not setting Broadcast Select " |
| 1465 | "Registers\n"); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1466 | val |= TSI148_LCSR_DSAT_TM_2eSSTB; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /* Setup data width */ |
| 1470 | switch (dwidth) { |
| 1471 | case VME_D16: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1472 | val |= TSI148_LCSR_DSAT_DBW_16; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1473 | break; |
| 1474 | case VME_D32: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1475 | val |= TSI148_LCSR_DSAT_DBW_32; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1476 | break; |
| 1477 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1478 | dev_err(dev, "Invalid data width\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1479 | return -EINVAL; |
| 1480 | } |
| 1481 | |
| 1482 | /* Setup address space */ |
| 1483 | switch (aspace) { |
| 1484 | case VME_A16: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1485 | val |= TSI148_LCSR_DSAT_AMODE_A16; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1486 | break; |
| 1487 | case VME_A24: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1488 | val |= TSI148_LCSR_DSAT_AMODE_A24; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1489 | break; |
| 1490 | case VME_A32: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1491 | val |= TSI148_LCSR_DSAT_AMODE_A32; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1492 | break; |
| 1493 | case VME_A64: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1494 | val |= TSI148_LCSR_DSAT_AMODE_A64; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1495 | break; |
| 1496 | case VME_CRCSR: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1497 | val |= TSI148_LCSR_DSAT_AMODE_CRCSR; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1498 | break; |
| 1499 | case VME_USER1: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1500 | val |= TSI148_LCSR_DSAT_AMODE_USER1; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1501 | break; |
| 1502 | case VME_USER2: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1503 | val |= TSI148_LCSR_DSAT_AMODE_USER2; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1504 | break; |
| 1505 | case VME_USER3: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1506 | val |= TSI148_LCSR_DSAT_AMODE_USER3; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1507 | break; |
| 1508 | case VME_USER4: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1509 | val |= TSI148_LCSR_DSAT_AMODE_USER4; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1510 | break; |
| 1511 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1512 | dev_err(dev, "Invalid address space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1513 | return -EINVAL; |
| 1514 | break; |
| 1515 | } |
| 1516 | |
| 1517 | if (cycle & VME_SUPER) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1518 | val |= TSI148_LCSR_DSAT_SUP; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1519 | if (cycle & VME_PROG) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1520 | val |= TSI148_LCSR_DSAT_PGM; |
| 1521 | |
| 1522 | *attr = cpu_to_be32(val); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1523 | |
| 1524 | return 0; |
| 1525 | } |
| 1526 | |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1527 | static int tsi148_dma_set_vme_dest_attributes(struct device *dev, __be32 *attr, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1528 | u32 aspace, u32 cycle, u32 dwidth) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1529 | { |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1530 | u32 val; |
| 1531 | |
| 1532 | val = be32_to_cpu(*attr); |
| 1533 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1534 | /* Setup 2eSST speeds */ |
| 1535 | switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { |
| 1536 | case VME_2eSST160: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1537 | val |= TSI148_LCSR_DDAT_2eSSTM_160; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1538 | break; |
| 1539 | case VME_2eSST267: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1540 | val |= TSI148_LCSR_DDAT_2eSSTM_267; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1541 | break; |
| 1542 | case VME_2eSST320: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1543 | val |= TSI148_LCSR_DDAT_2eSSTM_320; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1544 | break; |
| 1545 | } |
| 1546 | |
| 1547 | /* Setup cycle types */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1548 | if (cycle & VME_SCT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1549 | val |= TSI148_LCSR_DDAT_TM_SCT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1550 | |
| 1551 | if (cycle & VME_BLT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1552 | val |= TSI148_LCSR_DDAT_TM_BLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1553 | |
| 1554 | if (cycle & VME_MBLT) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1555 | val |= TSI148_LCSR_DDAT_TM_MBLT; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1556 | |
| 1557 | if (cycle & VME_2eVME) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1558 | val |= TSI148_LCSR_DDAT_TM_2eVME; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1559 | |
| 1560 | if (cycle & VME_2eSST) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1561 | val |= TSI148_LCSR_DDAT_TM_2eSST; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1562 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1563 | if (cycle & VME_2eSSTB) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1564 | dev_err(dev, "Currently not setting Broadcast Select " |
| 1565 | "Registers\n"); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1566 | val |= TSI148_LCSR_DDAT_TM_2eSSTB; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /* Setup data width */ |
| 1570 | switch (dwidth) { |
| 1571 | case VME_D16: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1572 | val |= TSI148_LCSR_DDAT_DBW_16; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1573 | break; |
| 1574 | case VME_D32: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1575 | val |= TSI148_LCSR_DDAT_DBW_32; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1576 | break; |
| 1577 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1578 | dev_err(dev, "Invalid data width\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1579 | return -EINVAL; |
| 1580 | } |
| 1581 | |
| 1582 | /* Setup address space */ |
| 1583 | switch (aspace) { |
| 1584 | case VME_A16: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1585 | val |= TSI148_LCSR_DDAT_AMODE_A16; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1586 | break; |
| 1587 | case VME_A24: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1588 | val |= TSI148_LCSR_DDAT_AMODE_A24; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1589 | break; |
| 1590 | case VME_A32: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1591 | val |= TSI148_LCSR_DDAT_AMODE_A32; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1592 | break; |
| 1593 | case VME_A64: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1594 | val |= TSI148_LCSR_DDAT_AMODE_A64; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1595 | break; |
| 1596 | case VME_CRCSR: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1597 | val |= TSI148_LCSR_DDAT_AMODE_CRCSR; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1598 | break; |
| 1599 | case VME_USER1: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1600 | val |= TSI148_LCSR_DDAT_AMODE_USER1; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1601 | break; |
| 1602 | case VME_USER2: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1603 | val |= TSI148_LCSR_DDAT_AMODE_USER2; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1604 | break; |
| 1605 | case VME_USER3: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1606 | val |= TSI148_LCSR_DDAT_AMODE_USER3; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1607 | break; |
| 1608 | case VME_USER4: |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1609 | val |= TSI148_LCSR_DDAT_AMODE_USER4; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1610 | break; |
| 1611 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1612 | dev_err(dev, "Invalid address space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1613 | return -EINVAL; |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | if (cycle & VME_SUPER) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1618 | val |= TSI148_LCSR_DDAT_SUP; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1619 | if (cycle & VME_PROG) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1620 | val |= TSI148_LCSR_DDAT_PGM; |
| 1621 | |
| 1622 | *attr = cpu_to_be32(val); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1623 | |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | /* |
| 1628 | * Add a link list descriptor to the list |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1629 | * |
| 1630 | * Note: DMA engine expects the DMA descriptor to be big endian. |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1631 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1632 | static int tsi148_dma_list_add(struct vme_dma_list *list, |
| 1633 | struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1634 | { |
| 1635 | struct tsi148_dma_entry *entry, *prev; |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1636 | u32 address_high, address_low, val; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1637 | struct vme_dma_pattern *pattern_attr; |
| 1638 | struct vme_dma_pci *pci_attr; |
| 1639 | struct vme_dma_vme *vme_attr; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1640 | int retval = 0; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1641 | struct vme_bridge *tsi148_bridge; |
| 1642 | |
| 1643 | tsi148_bridge = list->parent->parent; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1644 | |
Martyn Welch | bb9ea89 | 2010-02-18 16:22:13 +0000 | [diff] [blame] | 1645 | /* Descriptor must be aligned on 64-bit boundaries */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1646 | entry = kmalloc(sizeof(struct tsi148_dma_entry), GFP_KERNEL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1647 | if (entry == NULL) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1648 | dev_err(tsi148_bridge->parent, "Failed to allocate memory for " |
| 1649 | "dma resource structure\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1650 | retval = -ENOMEM; |
| 1651 | goto err_mem; |
| 1652 | } |
| 1653 | |
| 1654 | /* Test descriptor alignment */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1655 | if ((unsigned long)&entry->descriptor & 0x7) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1656 | dev_err(tsi148_bridge->parent, "Descriptor not aligned to 8 " |
| 1657 | "byte boundary as required: %p\n", |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1658 | &entry->descriptor); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1659 | retval = -EINVAL; |
| 1660 | goto err_align; |
| 1661 | } |
| 1662 | |
| 1663 | /* Given we are going to fill out the structure, we probably don't |
| 1664 | * need to zero it, but better safe than sorry for now. |
| 1665 | */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1666 | memset(&entry->descriptor, 0, sizeof(struct tsi148_dma_descriptor)); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1667 | |
| 1668 | /* Fill out source part */ |
| 1669 | switch (src->type) { |
| 1670 | case VME_DMA_PATTERN: |
Kulikov Vasiliy | c4d82fb | 2010-06-29 14:16:20 +0400 | [diff] [blame] | 1671 | pattern_attr = src->private; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1672 | |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1673 | entry->descriptor.dsal = cpu_to_be32(pattern_attr->pattern); |
| 1674 | |
| 1675 | val = TSI148_LCSR_DSAT_TYP_PAT; |
| 1676 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1677 | /* Default behaviour is 32 bit pattern */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1678 | if (pattern_attr->type & VME_DMA_PATTERN_BYTE) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1679 | val |= TSI148_LCSR_DSAT_PSZ; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1680 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1681 | /* It seems that the default behaviour is to increment */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1682 | if ((pattern_attr->type & VME_DMA_PATTERN_INCREMENT) == 0) |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1683 | val |= TSI148_LCSR_DSAT_NIN; |
| 1684 | entry->descriptor.dsat = cpu_to_be32(val); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1685 | break; |
| 1686 | case VME_DMA_PCI: |
Kulikov Vasiliy | c4d82fb | 2010-06-29 14:16:20 +0400 | [diff] [blame] | 1687 | pci_attr = src->private; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1688 | |
| 1689 | reg_split((unsigned long long)pci_attr->address, &address_high, |
| 1690 | &address_low); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1691 | entry->descriptor.dsau = cpu_to_be32(address_high); |
| 1692 | entry->descriptor.dsal = cpu_to_be32(address_low); |
| 1693 | entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_PCI); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1694 | break; |
| 1695 | case VME_DMA_VME: |
Kulikov Vasiliy | c4d82fb | 2010-06-29 14:16:20 +0400 | [diff] [blame] | 1696 | vme_attr = src->private; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1697 | |
| 1698 | reg_split((unsigned long long)vme_attr->address, &address_high, |
| 1699 | &address_low); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1700 | entry->descriptor.dsau = cpu_to_be32(address_high); |
| 1701 | entry->descriptor.dsal = cpu_to_be32(address_low); |
| 1702 | entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_VME); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1703 | |
| 1704 | retval = tsi148_dma_set_vme_src_attributes( |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1705 | tsi148_bridge->parent, &entry->descriptor.dsat, |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1706 | vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth); |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1707 | if (retval < 0) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1708 | goto err_source; |
| 1709 | break; |
| 1710 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1711 | dev_err(tsi148_bridge->parent, "Invalid source type\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1712 | retval = -EINVAL; |
| 1713 | goto err_source; |
| 1714 | break; |
| 1715 | } |
| 1716 | |
| 1717 | /* Assume last link - this will be over-written by adding another */ |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1718 | entry->descriptor.dnlau = cpu_to_be32(0); |
| 1719 | entry->descriptor.dnlal = cpu_to_be32(TSI148_LCSR_DNLAL_LLA); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1720 | |
| 1721 | /* Fill out destination part */ |
| 1722 | switch (dest->type) { |
| 1723 | case VME_DMA_PCI: |
Kulikov Vasiliy | c4d82fb | 2010-06-29 14:16:20 +0400 | [diff] [blame] | 1724 | pci_attr = dest->private; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1725 | |
| 1726 | reg_split((unsigned long long)pci_attr->address, &address_high, |
| 1727 | &address_low); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1728 | entry->descriptor.ddau = cpu_to_be32(address_high); |
| 1729 | entry->descriptor.ddal = cpu_to_be32(address_low); |
| 1730 | entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_PCI); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1731 | break; |
| 1732 | case VME_DMA_VME: |
Kulikov Vasiliy | c4d82fb | 2010-06-29 14:16:20 +0400 | [diff] [blame] | 1733 | vme_attr = dest->private; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1734 | |
| 1735 | reg_split((unsigned long long)vme_attr->address, &address_high, |
| 1736 | &address_low); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1737 | entry->descriptor.ddau = cpu_to_be32(address_high); |
| 1738 | entry->descriptor.ddal = cpu_to_be32(address_low); |
| 1739 | entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_VME); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1740 | |
| 1741 | retval = tsi148_dma_set_vme_dest_attributes( |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1742 | tsi148_bridge->parent, &entry->descriptor.ddat, |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1743 | vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth); |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1744 | if (retval < 0) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1745 | goto err_dest; |
| 1746 | break; |
| 1747 | default: |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1748 | dev_err(tsi148_bridge->parent, "Invalid destination type\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1749 | retval = -EINVAL; |
| 1750 | goto err_dest; |
| 1751 | break; |
| 1752 | } |
| 1753 | |
| 1754 | /* Fill out count */ |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1755 | entry->descriptor.dcnt = cpu_to_be32((u32)count); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1756 | |
| 1757 | /* Add to list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1758 | list_add_tail(&entry->list, &list->entries); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1759 | |
Dmitry Kalinkin | b2383c9 | 2015-05-28 15:07:00 +0300 | [diff] [blame] | 1760 | entry->dma_handle = dma_map_single(tsi148_bridge->parent, |
| 1761 | &entry->descriptor, |
| 1762 | sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE); |
| 1763 | if (dma_mapping_error(tsi148_bridge->parent, entry->dma_handle)) { |
| 1764 | dev_err(tsi148_bridge->parent, "DMA mapping error\n"); |
| 1765 | retval = -EINVAL; |
| 1766 | goto err_dma; |
| 1767 | } |
| 1768 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1769 | /* Fill out previous descriptors "Next Address" */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1770 | if (entry->list.prev != &list->entries) { |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1771 | reg_split((unsigned long long)entry->dma_handle, &address_high, |
| 1772 | &address_low); |
Dmitry Kalinkin | b2383c9 | 2015-05-28 15:07:00 +0300 | [diff] [blame] | 1773 | prev = list_entry(entry->list.prev, struct tsi148_dma_entry, |
| 1774 | list); |
Dmitry Kalinkin | f656eaee | 2015-05-28 15:06:59 +0300 | [diff] [blame] | 1775 | prev->descriptor.dnlau = cpu_to_be32(address_high); |
| 1776 | prev->descriptor.dnlal = cpu_to_be32(address_low); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1777 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | return 0; |
| 1781 | |
Dmitry Kalinkin | b2383c9 | 2015-05-28 15:07:00 +0300 | [diff] [blame] | 1782 | err_dma: |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1783 | err_dest: |
| 1784 | err_source: |
| 1785 | err_align: |
| 1786 | kfree(entry); |
| 1787 | err_mem: |
| 1788 | return retval; |
| 1789 | } |
| 1790 | |
| 1791 | /* |
| 1792 | * Check to see if the provided DMA channel is busy. |
| 1793 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1794 | static int tsi148_dma_busy(struct vme_bridge *tsi148_bridge, int channel) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1795 | { |
| 1796 | u32 tmp; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1797 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1798 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1799 | bridge = tsi148_bridge->driver_priv; |
| 1800 | |
| 1801 | tmp = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1802 | TSI148_LCSR_OFFSET_DSTA); |
| 1803 | |
| 1804 | if (tmp & TSI148_LCSR_DSTA_BSY) |
| 1805 | return 0; |
| 1806 | else |
| 1807 | return 1; |
| 1808 | |
| 1809 | } |
| 1810 | |
| 1811 | /* |
| 1812 | * Execute a previously generated link list |
| 1813 | * |
| 1814 | * XXX Need to provide control register configuration. |
| 1815 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1816 | static int tsi148_dma_list_exec(struct vme_dma_list *list) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1817 | { |
| 1818 | struct vme_dma_resource *ctrlr; |
Dmitry Kalinkin | 75c66b6 | 2015-05-28 15:07:01 +0300 | [diff] [blame] | 1819 | int channel, retval; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1820 | struct tsi148_dma_entry *entry; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1821 | u32 bus_addr_high, bus_addr_low; |
| 1822 | u32 val, dctlreg = 0; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1823 | struct vme_bridge *tsi148_bridge; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1824 | struct tsi148_driver *bridge; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1825 | |
| 1826 | ctrlr = list->parent; |
| 1827 | |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1828 | tsi148_bridge = ctrlr->parent; |
| 1829 | |
| 1830 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1831 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1832 | mutex_lock(&ctrlr->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1833 | |
| 1834 | channel = ctrlr->number; |
| 1835 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1836 | if (!list_empty(&ctrlr->running)) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1837 | /* |
| 1838 | * XXX We have an active DMA transfer and currently haven't |
| 1839 | * sorted out the mechanism for "pending" DMA transfers. |
| 1840 | * Return busy. |
| 1841 | */ |
| 1842 | /* Need to add to pending here */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1843 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1844 | return -EBUSY; |
| 1845 | } else { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1846 | list_add(&list->list, &ctrlr->running); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1847 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1848 | |
| 1849 | /* Get first bus address and write into registers */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1850 | entry = list_first_entry(&list->entries, struct tsi148_dma_entry, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1851 | list); |
| 1852 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1853 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1854 | |
Martyn Welch | 3abc48a | 2012-03-22 13:27:29 +0000 | [diff] [blame] | 1855 | reg_split(entry->dma_handle, &bus_addr_high, &bus_addr_low); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1856 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1857 | iowrite32be(bus_addr_high, bridge->base + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1858 | TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAU); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1859 | iowrite32be(bus_addr_low, bridge->base + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1860 | TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAL); |
| 1861 | |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1862 | dctlreg = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] + |
| 1863 | TSI148_LCSR_OFFSET_DCTL); |
| 1864 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1865 | /* Start the operation */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1866 | iowrite32be(dctlreg | TSI148_LCSR_DCTL_DGO, bridge->base + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1867 | TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL); |
| 1868 | |
Dmitry Kalinkin | 75c66b6 | 2015-05-28 15:07:01 +0300 | [diff] [blame] | 1869 | retval = wait_event_interruptible(bridge->dma_queue[channel], |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1870 | tsi148_dma_busy(ctrlr->parent, channel)); |
Martyn Welch | ac1a4f2 | 2012-03-22 13:27:30 +0000 | [diff] [blame] | 1871 | |
Dmitry Kalinkin | 75c66b6 | 2015-05-28 15:07:01 +0300 | [diff] [blame] | 1872 | if (retval) { |
| 1873 | iowrite32be(dctlreg | TSI148_LCSR_DCTL_ABT, bridge->base + |
| 1874 | TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL); |
| 1875 | /* Wait for the operation to abort */ |
| 1876 | wait_event(bridge->dma_queue[channel], |
| 1877 | tsi148_dma_busy(ctrlr->parent, channel)); |
| 1878 | retval = -EINTR; |
| 1879 | goto exit; |
| 1880 | } |
| 1881 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1882 | /* |
| 1883 | * Read status register, this register is valid until we kick off a |
| 1884 | * new transfer. |
| 1885 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1886 | val = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1887 | TSI148_LCSR_OFFSET_DSTA); |
| 1888 | |
| 1889 | if (val & TSI148_LCSR_DSTA_VBE) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1890 | dev_err(tsi148_bridge->parent, "DMA Error. DSTA=%08X\n", val); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1891 | retval = -EIO; |
| 1892 | } |
| 1893 | |
Dmitry Kalinkin | 75c66b6 | 2015-05-28 15:07:01 +0300 | [diff] [blame] | 1894 | exit: |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1895 | /* Remove list from running list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1896 | mutex_lock(&ctrlr->mtx); |
| 1897 | list_del(&list->list); |
| 1898 | mutex_unlock(&ctrlr->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1899 | |
| 1900 | return retval; |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Clean up a previously generated link list |
| 1905 | * |
| 1906 | * We have a separate function, don't assume that the chain can't be reused. |
| 1907 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1908 | static int tsi148_dma_list_empty(struct vme_dma_list *list) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1909 | { |
| 1910 | struct list_head *pos, *temp; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1911 | struct tsi148_dma_entry *entry; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1912 | |
Martyn Welch | 3abc48a | 2012-03-22 13:27:29 +0000 | [diff] [blame] | 1913 | struct vme_bridge *tsi148_bridge = list->parent->parent; |
| 1914 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1915 | /* detach and free each entry */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1916 | list_for_each_safe(pos, temp, &list->entries) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1917 | list_del(pos); |
| 1918 | entry = list_entry(pos, struct tsi148_dma_entry, list); |
Martyn Welch | 3abc48a | 2012-03-22 13:27:29 +0000 | [diff] [blame] | 1919 | |
| 1920 | dma_unmap_single(tsi148_bridge->parent, entry->dma_handle, |
| 1921 | sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1922 | kfree(entry); |
| 1923 | } |
| 1924 | |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 1925 | return 0; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | /* |
| 1929 | * All 4 location monitors reside at the same base - this is therefore a |
| 1930 | * system wide configuration. |
| 1931 | * |
| 1932 | * This does not enable the LM monitor - that should be done when the first |
| 1933 | * callback is attached and disabled when the last callback is removed. |
| 1934 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 1935 | static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 1936 | u32 aspace, u32 cycle) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1937 | { |
| 1938 | u32 lm_base_high, lm_base_low, lm_ctl = 0; |
| 1939 | int i; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1940 | struct vme_bridge *tsi148_bridge; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1941 | struct tsi148_driver *bridge; |
| 1942 | |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1943 | tsi148_bridge = lm->parent; |
| 1944 | |
| 1945 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1946 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1947 | mutex_lock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1948 | |
| 1949 | /* If we already have a callback attached, we can't move it! */ |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 1950 | for (i = 0; i < lm->monitors; i++) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1951 | if (bridge->lm_callback[i] != NULL) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1952 | mutex_unlock(&lm->mtx); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1953 | dev_err(tsi148_bridge->parent, "Location monitor " |
| 1954 | "callback attached, can't reset\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1955 | return -EBUSY; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | switch (aspace) { |
| 1960 | case VME_A16: |
| 1961 | lm_ctl |= TSI148_LCSR_LMAT_AS_A16; |
| 1962 | break; |
| 1963 | case VME_A24: |
| 1964 | lm_ctl |= TSI148_LCSR_LMAT_AS_A24; |
| 1965 | break; |
| 1966 | case VME_A32: |
| 1967 | lm_ctl |= TSI148_LCSR_LMAT_AS_A32; |
| 1968 | break; |
| 1969 | case VME_A64: |
| 1970 | lm_ctl |= TSI148_LCSR_LMAT_AS_A64; |
| 1971 | break; |
| 1972 | default: |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1973 | mutex_unlock(&lm->mtx); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 1974 | dev_err(tsi148_bridge->parent, "Invalid address space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1975 | return -EINVAL; |
| 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | if (cycle & VME_SUPER) |
| 1980 | lm_ctl |= TSI148_LCSR_LMAT_SUPR ; |
| 1981 | if (cycle & VME_USER) |
| 1982 | lm_ctl |= TSI148_LCSR_LMAT_NPRIV; |
| 1983 | if (cycle & VME_PROG) |
| 1984 | lm_ctl |= TSI148_LCSR_LMAT_PGM; |
| 1985 | if (cycle & VME_DATA) |
| 1986 | lm_ctl |= TSI148_LCSR_LMAT_DATA; |
| 1987 | |
| 1988 | reg_split(lm_base, &lm_base_high, &lm_base_low); |
| 1989 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 1990 | iowrite32be(lm_base_high, bridge->base + TSI148_LCSR_LMBAU); |
| 1991 | iowrite32be(lm_base_low, bridge->base + TSI148_LCSR_LMBAL); |
| 1992 | iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1993 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 1994 | mutex_unlock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1995 | |
| 1996 | return 0; |
| 1997 | } |
| 1998 | |
| 1999 | /* Get configuration of the callback monitor and return whether it is enabled |
| 2000 | * or disabled. |
| 2001 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 2002 | static int tsi148_lm_get(struct vme_lm_resource *lm, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 2003 | unsigned long long *lm_base, u32 *aspace, u32 *cycle) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2004 | { |
| 2005 | u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2006 | struct tsi148_driver *bridge; |
| 2007 | |
| 2008 | bridge = lm->parent->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2009 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2010 | mutex_lock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2011 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2012 | lm_base_high = ioread32be(bridge->base + TSI148_LCSR_LMBAU); |
| 2013 | lm_base_low = ioread32be(bridge->base + TSI148_LCSR_LMBAL); |
| 2014 | lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2015 | |
| 2016 | reg_join(lm_base_high, lm_base_low, lm_base); |
| 2017 | |
| 2018 | if (lm_ctl & TSI148_LCSR_LMAT_EN) |
| 2019 | enabled = 1; |
| 2020 | |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2021 | if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A16) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2022 | *aspace |= VME_A16; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2023 | |
| 2024 | if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A24) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2025 | *aspace |= VME_A24; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2026 | |
| 2027 | if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A32) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2028 | *aspace |= VME_A32; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2029 | |
| 2030 | if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A64) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2031 | *aspace |= VME_A64; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2032 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2033 | |
| 2034 | if (lm_ctl & TSI148_LCSR_LMAT_SUPR) |
| 2035 | *cycle |= VME_SUPER; |
| 2036 | if (lm_ctl & TSI148_LCSR_LMAT_NPRIV) |
| 2037 | *cycle |= VME_USER; |
| 2038 | if (lm_ctl & TSI148_LCSR_LMAT_PGM) |
| 2039 | *cycle |= VME_PROG; |
| 2040 | if (lm_ctl & TSI148_LCSR_LMAT_DATA) |
| 2041 | *cycle |= VME_DATA; |
| 2042 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2043 | mutex_unlock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2044 | |
| 2045 | return enabled; |
| 2046 | } |
| 2047 | |
| 2048 | /* |
| 2049 | * Attach a callback to a specific location monitor. |
| 2050 | * |
| 2051 | * Callback will be passed the monitor triggered. |
| 2052 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 2053 | static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor, |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2054 | void (*callback)(int)) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2055 | { |
| 2056 | u32 lm_ctl, tmp; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2057 | struct vme_bridge *tsi148_bridge; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2058 | struct tsi148_driver *bridge; |
| 2059 | |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2060 | tsi148_bridge = lm->parent; |
| 2061 | |
| 2062 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2063 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2064 | mutex_lock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2065 | |
| 2066 | /* Ensure that the location monitor is configured - need PGM or DATA */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2067 | lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2068 | if ((lm_ctl & (TSI148_LCSR_LMAT_PGM | TSI148_LCSR_LMAT_DATA)) == 0) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2069 | mutex_unlock(&lm->mtx); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2070 | dev_err(tsi148_bridge->parent, "Location monitor not properly " |
| 2071 | "configured\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2072 | return -EINVAL; |
| 2073 | } |
| 2074 | |
| 2075 | /* Check that a callback isn't already attached */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2076 | if (bridge->lm_callback[monitor] != NULL) { |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2077 | mutex_unlock(&lm->mtx); |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2078 | dev_err(tsi148_bridge->parent, "Existing callback attached\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2079 | return -EBUSY; |
| 2080 | } |
| 2081 | |
| 2082 | /* Attach callback */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2083 | bridge->lm_callback[monitor] = callback; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2084 | |
| 2085 | /* Enable Location Monitor interrupt */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2086 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2087 | tmp |= TSI148_LCSR_INTEN_LMEN[monitor]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2088 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2089 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2090 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2091 | tmp |= TSI148_LCSR_INTEO_LMEO[monitor]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2092 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2093 | |
| 2094 | /* Ensure that global Location Monitor Enable set */ |
| 2095 | if ((lm_ctl & TSI148_LCSR_LMAT_EN) == 0) { |
| 2096 | lm_ctl |= TSI148_LCSR_LMAT_EN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2097 | iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2098 | } |
| 2099 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2100 | mutex_unlock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2101 | |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | /* |
| 2106 | * Detach a callback function forn a specific location monitor. |
| 2107 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 2108 | static int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2109 | { |
| 2110 | u32 lm_en, tmp; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2111 | struct tsi148_driver *bridge; |
| 2112 | |
| 2113 | bridge = lm->parent->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2114 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2115 | mutex_lock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2116 | |
| 2117 | /* Disable Location Monitor and ensure previous interrupts are clear */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2118 | lm_en = ioread32be(bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2119 | lm_en &= ~TSI148_LCSR_INTEN_LMEN[monitor]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2120 | iowrite32be(lm_en, bridge->base + TSI148_LCSR_INTEN); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2121 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2122 | tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2123 | tmp &= ~TSI148_LCSR_INTEO_LMEO[monitor]; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2124 | iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2125 | |
| 2126 | iowrite32be(TSI148_LCSR_INTC_LMC[monitor], |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2127 | bridge->base + TSI148_LCSR_INTC); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2128 | |
| 2129 | /* Detach callback */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2130 | bridge->lm_callback[monitor] = NULL; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2131 | |
| 2132 | /* If all location monitors disabled, disable global Location Monitor */ |
| 2133 | if ((lm_en & (TSI148_LCSR_INTS_LM0S | TSI148_LCSR_INTS_LM1S | |
| 2134 | TSI148_LCSR_INTS_LM2S | TSI148_LCSR_INTS_LM3S)) == 0) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2135 | tmp = ioread32be(bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2136 | tmp &= ~TSI148_LCSR_LMAT_EN; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2137 | iowrite32be(tmp, bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2138 | } |
| 2139 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2140 | mutex_unlock(&lm->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2141 | |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | /* |
| 2146 | * Determine Geographical Addressing |
| 2147 | */ |
Emilio G. Cota | 5ade6c4 | 2010-11-12 11:15:00 +0000 | [diff] [blame] | 2148 | static int tsi148_slot_get(struct vme_bridge *tsi148_bridge) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2149 | { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2150 | u32 slot = 0; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2151 | struct tsi148_driver *bridge; |
| 2152 | |
| 2153 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2154 | |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2155 | if (!geoid) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2156 | slot = ioread32be(bridge->base + TSI148_LCSR_VSTAT); |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2157 | slot = slot & TSI148_LCSR_VSTAT_GA_M; |
| 2158 | } else |
| 2159 | slot = geoid; |
| 2160 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2161 | return (int)slot; |
| 2162 | } |
| 2163 | |
H Hartley Sweeten lin | 8a508ff | 2012-05-02 17:08:38 -0700 | [diff] [blame] | 2164 | static void *tsi148_alloc_consistent(struct device *parent, size_t size, |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 2165 | dma_addr_t *dma) |
| 2166 | { |
| 2167 | struct pci_dev *pdev; |
| 2168 | |
| 2169 | /* Find pci_dev container of dev */ |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 2170 | pdev = to_pci_dev(parent); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 2171 | |
| 2172 | return pci_alloc_consistent(pdev, size, dma); |
| 2173 | } |
| 2174 | |
H Hartley Sweeten lin | 8a508ff | 2012-05-02 17:08:38 -0700 | [diff] [blame] | 2175 | static void tsi148_free_consistent(struct device *parent, size_t size, |
| 2176 | void *vaddr, dma_addr_t dma) |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 2177 | { |
| 2178 | struct pci_dev *pdev; |
| 2179 | |
| 2180 | /* Find pci_dev container of dev */ |
Aaron Sierra | 177581fa | 2014-04-03 14:48:27 -0500 | [diff] [blame] | 2181 | pdev = to_pci_dev(parent); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 2182 | |
| 2183 | pci_free_consistent(pdev, size, vaddr, dma); |
| 2184 | } |
| 2185 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2186 | /* |
| 2187 | * Configure CR/CSR space |
| 2188 | * |
| 2189 | * Access to the CR/CSR can be configured at power-up. The location of the |
| 2190 | * CR/CSR registers in the CR/CSR address space is determined by the boards |
| 2191 | * Auto-ID or Geographic address. This function ensures that the window is |
| 2192 | * enabled at an offset consistent with the boards geopgraphic address. |
| 2193 | * |
| 2194 | * Each board has a 512kB window, with the highest 4kB being used for the |
| 2195 | * boards registers, this means there is a fix length 508kB window which must |
| 2196 | * be mapped onto PCI memory. |
| 2197 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2198 | static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge, |
| 2199 | struct pci_dev *pdev) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2200 | { |
| 2201 | u32 cbar, crat, vstat; |
| 2202 | u32 crcsr_bus_high, crcsr_bus_low; |
| 2203 | int retval; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2204 | struct tsi148_driver *bridge; |
| 2205 | |
| 2206 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2207 | |
| 2208 | /* Allocate mem for CR/CSR image */ |
Joe Perches | 88b2608 | 2014-08-08 14:24:53 -0700 | [diff] [blame] | 2209 | bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE, |
| 2210 | &bridge->crcsr_bus); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2211 | if (bridge->crcsr_kernel == NULL) { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2212 | dev_err(tsi148_bridge->parent, "Failed to allocate memory for " |
| 2213 | "CR/CSR image\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2214 | return -ENOMEM; |
| 2215 | } |
| 2216 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2217 | reg_split(bridge->crcsr_bus, &crcsr_bus_high, &crcsr_bus_low); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2218 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2219 | iowrite32be(crcsr_bus_high, bridge->base + TSI148_LCSR_CROU); |
| 2220 | iowrite32be(crcsr_bus_low, bridge->base + TSI148_LCSR_CROL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2221 | |
| 2222 | /* Ensure that the CR/CSR is configured at the correct offset */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2223 | cbar = ioread32be(bridge->base + TSI148_CBAR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2224 | cbar = (cbar & TSI148_CRCSR_CBAR_M)>>3; |
| 2225 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2226 | vstat = tsi148_slot_get(tsi148_bridge); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2227 | |
| 2228 | if (cbar != vstat) { |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2229 | cbar = vstat; |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2230 | dev_info(tsi148_bridge->parent, "Setting CR/CSR offset\n"); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2231 | iowrite32be(cbar<<3, bridge->base + TSI148_CBAR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2232 | } |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2233 | dev_info(tsi148_bridge->parent, "CR/CSR Offset: %d\n", cbar); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2234 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2235 | crat = ioread32be(bridge->base + TSI148_LCSR_CRAT); |
Martyn Welch | 2981795 | 2013-06-11 17:03:14 +0100 | [diff] [blame] | 2236 | if (crat & TSI148_LCSR_CRAT_EN) |
| 2237 | dev_info(tsi148_bridge->parent, "CR/CSR already enabled\n"); |
| 2238 | else { |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2239 | dev_info(tsi148_bridge->parent, "Enabling CR/CSR space\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2240 | iowrite32be(crat | TSI148_LCSR_CRAT_EN, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2241 | bridge->base + TSI148_LCSR_CRAT); |
Martyn Welch | 2981795 | 2013-06-11 17:03:14 +0100 | [diff] [blame] | 2242 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2243 | |
| 2244 | /* If we want flushed, error-checked writes, set up a window |
| 2245 | * over the CR/CSR registers. We read from here to safely flush |
| 2246 | * through VME writes. |
| 2247 | */ |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2248 | if (err_chk) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2249 | retval = tsi148_master_set(bridge->flush_image, 1, |
| 2250 | (vstat * 0x80000), 0x80000, VME_CRCSR, VME_SCT, |
| 2251 | VME_D16); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2252 | if (retval) |
Martyn Welch | 48d9356 | 2010-03-22 14:58:50 +0000 | [diff] [blame] | 2253 | dev_err(tsi148_bridge->parent, "Configuring flush image" |
| 2254 | " failed\n"); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | return 0; |
| 2258 | |
| 2259 | } |
| 2260 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2261 | static void tsi148_crcsr_exit(struct vme_bridge *tsi148_bridge, |
| 2262 | struct pci_dev *pdev) |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2263 | { |
| 2264 | u32 crat; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2265 | struct tsi148_driver *bridge; |
| 2266 | |
| 2267 | bridge = tsi148_bridge->driver_priv; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2268 | |
| 2269 | /* Turn off CR/CSR space */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2270 | crat = ioread32be(bridge->base + TSI148_LCSR_CRAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2271 | iowrite32be(crat & ~TSI148_LCSR_CRAT_EN, |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2272 | bridge->base + TSI148_LCSR_CRAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2273 | |
| 2274 | /* Free image */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2275 | iowrite32be(0, bridge->base + TSI148_LCSR_CROU); |
| 2276 | iowrite32be(0, bridge->base + TSI148_LCSR_CROL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2277 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2278 | pci_free_consistent(pdev, VME_CRCSR_BUF_SIZE, bridge->crcsr_kernel, |
| 2279 | bridge->crcsr_bus); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 2283 | { |
| 2284 | int retval, i, master_num; |
| 2285 | u32 data; |
Wei Yongjun | b49c32b | 2012-08-21 12:19:01 +0800 | [diff] [blame] | 2286 | struct list_head *pos = NULL, *n; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2287 | struct vme_bridge *tsi148_bridge; |
| 2288 | struct tsi148_driver *tsi148_device; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2289 | struct vme_master_resource *master_image; |
| 2290 | struct vme_slave_resource *slave_image; |
| 2291 | struct vme_dma_resource *dma_ctrlr; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2292 | struct vme_lm_resource *lm; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2293 | |
| 2294 | /* If we want to support more than one of each bridge, we need to |
| 2295 | * dynamically generate this so we get one per device |
| 2296 | */ |
Julia Lawall | 7a6cb0d | 2010-05-13 22:00:05 +0200 | [diff] [blame] | 2297 | tsi148_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2298 | if (tsi148_bridge == NULL) { |
| 2299 | dev_err(&pdev->dev, "Failed to allocate memory for device " |
| 2300 | "structure\n"); |
| 2301 | retval = -ENOMEM; |
| 2302 | goto err_struct; |
| 2303 | } |
| 2304 | |
Julia Lawall | 7a6cb0d | 2010-05-13 22:00:05 +0200 | [diff] [blame] | 2305 | tsi148_device = kzalloc(sizeof(struct tsi148_driver), GFP_KERNEL); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2306 | if (tsi148_device == NULL) { |
| 2307 | dev_err(&pdev->dev, "Failed to allocate memory for device " |
| 2308 | "structure\n"); |
| 2309 | retval = -ENOMEM; |
| 2310 | goto err_driver; |
| 2311 | } |
| 2312 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2313 | tsi148_bridge->driver_priv = tsi148_device; |
| 2314 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2315 | /* Enable the device */ |
| 2316 | retval = pci_enable_device(pdev); |
| 2317 | if (retval) { |
| 2318 | dev_err(&pdev->dev, "Unable to enable device\n"); |
| 2319 | goto err_enable; |
| 2320 | } |
| 2321 | |
| 2322 | /* Map Registers */ |
| 2323 | retval = pci_request_regions(pdev, driver_name); |
| 2324 | if (retval) { |
| 2325 | dev_err(&pdev->dev, "Unable to reserve resources\n"); |
| 2326 | goto err_resource; |
| 2327 | } |
| 2328 | |
| 2329 | /* map registers in BAR 0 */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2330 | tsi148_device->base = ioremap_nocache(pci_resource_start(pdev, 0), |
| 2331 | 4096); |
| 2332 | if (!tsi148_device->base) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2333 | dev_err(&pdev->dev, "Unable to remap CRG region\n"); |
| 2334 | retval = -EIO; |
| 2335 | goto err_remap; |
| 2336 | } |
| 2337 | |
| 2338 | /* Check to see if the mapping worked out */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2339 | data = ioread32(tsi148_device->base + TSI148_PCFS_ID) & 0x0000FFFF; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2340 | if (data != PCI_VENDOR_ID_TUNDRA) { |
| 2341 | dev_err(&pdev->dev, "CRG region check failed\n"); |
| 2342 | retval = -EIO; |
| 2343 | goto err_test; |
| 2344 | } |
| 2345 | |
| 2346 | /* Initialize wait queues & mutual exclusion flags */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2347 | init_waitqueue_head(&tsi148_device->dma_queue[0]); |
| 2348 | init_waitqueue_head(&tsi148_device->dma_queue[1]); |
| 2349 | init_waitqueue_head(&tsi148_device->iack_queue); |
| 2350 | mutex_init(&tsi148_device->vme_int); |
| 2351 | mutex_init(&tsi148_device->vme_rmw); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2352 | |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2353 | tsi148_bridge->parent = &pdev->dev; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2354 | strcpy(tsi148_bridge->name, driver_name); |
| 2355 | |
| 2356 | /* Setup IRQ */ |
| 2357 | retval = tsi148_irq_init(tsi148_bridge); |
| 2358 | if (retval != 0) { |
| 2359 | dev_err(&pdev->dev, "Chip Initialization failed.\n"); |
| 2360 | goto err_irq; |
| 2361 | } |
| 2362 | |
| 2363 | /* If we are going to flush writes, we need to read from the VME bus. |
| 2364 | * We need to do this safely, thus we read the devices own CR/CSR |
| 2365 | * register. To do this we must set up a window in CR/CSR space and |
| 2366 | * hence have one less master window resource available. |
| 2367 | */ |
| 2368 | master_num = TSI148_MAX_MASTER; |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2369 | if (err_chk) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2370 | master_num--; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2371 | |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 2372 | tsi148_device->flush_image = |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2373 | kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); |
| 2374 | if (tsi148_device->flush_image == NULL) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2375 | dev_err(&pdev->dev, "Failed to allocate memory for " |
| 2376 | "flush resource structure\n"); |
| 2377 | retval = -ENOMEM; |
| 2378 | goto err_master; |
| 2379 | } |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2380 | tsi148_device->flush_image->parent = tsi148_bridge; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2381 | spin_lock_init(&tsi148_device->flush_image->lock); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2382 | tsi148_device->flush_image->locked = 1; |
| 2383 | tsi148_device->flush_image->number = master_num; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2384 | memset(&tsi148_device->flush_image->bus_resource, 0, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2385 | sizeof(struct resource)); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2386 | tsi148_device->flush_image->kern_base = NULL; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | /* Add master windows to list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2390 | INIT_LIST_HEAD(&tsi148_bridge->master_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2391 | for (i = 0; i < master_num; i++) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2392 | master_image = kmalloc(sizeof(struct vme_master_resource), |
| 2393 | GFP_KERNEL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2394 | if (master_image == NULL) { |
| 2395 | dev_err(&pdev->dev, "Failed to allocate memory for " |
| 2396 | "master resource structure\n"); |
| 2397 | retval = -ENOMEM; |
| 2398 | goto err_master; |
| 2399 | } |
| 2400 | master_image->parent = tsi148_bridge; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2401 | spin_lock_init(&master_image->lock); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2402 | master_image->locked = 0; |
| 2403 | master_image->number = i; |
| 2404 | master_image->address_attr = VME_A16 | VME_A24 | VME_A32 | |
Martyn Welch | 08e03c2 | 2015-02-26 18:53:11 +0300 | [diff] [blame] | 2405 | VME_A64 | VME_CRCSR | VME_USER1 | VME_USER2 | |
| 2406 | VME_USER3 | VME_USER4; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2407 | master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT | |
| 2408 | VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 | |
| 2409 | VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER | |
| 2410 | VME_PROG | VME_DATA; |
| 2411 | master_image->width_attr = VME_D16 | VME_D32; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2412 | memset(&master_image->bus_resource, 0, |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2413 | sizeof(struct resource)); |
| 2414 | master_image->kern_base = NULL; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2415 | list_add_tail(&master_image->list, |
| 2416 | &tsi148_bridge->master_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | /* Add slave windows to list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2420 | INIT_LIST_HEAD(&tsi148_bridge->slave_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2421 | for (i = 0; i < TSI148_MAX_SLAVE; i++) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2422 | slave_image = kmalloc(sizeof(struct vme_slave_resource), |
| 2423 | GFP_KERNEL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2424 | if (slave_image == NULL) { |
| 2425 | dev_err(&pdev->dev, "Failed to allocate memory for " |
| 2426 | "slave resource structure\n"); |
| 2427 | retval = -ENOMEM; |
| 2428 | goto err_slave; |
| 2429 | } |
| 2430 | slave_image->parent = tsi148_bridge; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2431 | mutex_init(&slave_image->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2432 | slave_image->locked = 0; |
| 2433 | slave_image->number = i; |
| 2434 | slave_image->address_attr = VME_A16 | VME_A24 | VME_A32 | |
Martyn Welch | 08e03c2 | 2015-02-26 18:53:11 +0300 | [diff] [blame] | 2435 | VME_A64; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2436 | slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT | |
| 2437 | VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 | |
| 2438 | VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER | |
| 2439 | VME_PROG | VME_DATA; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2440 | list_add_tail(&slave_image->list, |
| 2441 | &tsi148_bridge->slave_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | /* Add dma engines to list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2445 | INIT_LIST_HEAD(&tsi148_bridge->dma_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2446 | for (i = 0; i < TSI148_MAX_DMA; i++) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2447 | dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), |
| 2448 | GFP_KERNEL); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2449 | if (dma_ctrlr == NULL) { |
| 2450 | dev_err(&pdev->dev, "Failed to allocate memory for " |
| 2451 | "dma resource structure\n"); |
| 2452 | retval = -ENOMEM; |
| 2453 | goto err_dma; |
| 2454 | } |
| 2455 | dma_ctrlr->parent = tsi148_bridge; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2456 | mutex_init(&dma_ctrlr->mtx); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2457 | dma_ctrlr->locked = 0; |
| 2458 | dma_ctrlr->number = i; |
Martyn Welch | 4f723df | 2010-02-18 15:12:58 +0000 | [diff] [blame] | 2459 | dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM | |
| 2460 | VME_DMA_MEM_TO_VME | VME_DMA_VME_TO_VME | |
| 2461 | VME_DMA_MEM_TO_MEM | VME_DMA_PATTERN_TO_VME | |
| 2462 | VME_DMA_PATTERN_TO_MEM; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2463 | INIT_LIST_HEAD(&dma_ctrlr->pending); |
| 2464 | INIT_LIST_HEAD(&dma_ctrlr->running); |
| 2465 | list_add_tail(&dma_ctrlr->list, |
| 2466 | &tsi148_bridge->dma_resources); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2467 | } |
| 2468 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2469 | /* Add location monitor to list */ |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2470 | INIT_LIST_HEAD(&tsi148_bridge->lm_resources); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2471 | lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); |
| 2472 | if (lm == NULL) { |
| 2473 | dev_err(&pdev->dev, "Failed to allocate memory for " |
| 2474 | "location monitor resource structure\n"); |
| 2475 | retval = -ENOMEM; |
| 2476 | goto err_lm; |
| 2477 | } |
| 2478 | lm->parent = tsi148_bridge; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2479 | mutex_init(&lm->mtx); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2480 | lm->locked = 0; |
| 2481 | lm->number = 1; |
| 2482 | lm->monitors = 4; |
Emilio G. Cota | 886953e | 2010-11-12 11:14:07 +0000 | [diff] [blame] | 2483 | list_add_tail(&lm->list, &tsi148_bridge->lm_resources); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2484 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2485 | tsi148_bridge->slave_get = tsi148_slave_get; |
| 2486 | tsi148_bridge->slave_set = tsi148_slave_set; |
| 2487 | tsi148_bridge->master_get = tsi148_master_get; |
| 2488 | tsi148_bridge->master_set = tsi148_master_set; |
| 2489 | tsi148_bridge->master_read = tsi148_master_read; |
| 2490 | tsi148_bridge->master_write = tsi148_master_write; |
| 2491 | tsi148_bridge->master_rmw = tsi148_master_rmw; |
| 2492 | tsi148_bridge->dma_list_add = tsi148_dma_list_add; |
| 2493 | tsi148_bridge->dma_list_exec = tsi148_dma_list_exec; |
| 2494 | tsi148_bridge->dma_list_empty = tsi148_dma_list_empty; |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 2495 | tsi148_bridge->irq_set = tsi148_irq_set; |
| 2496 | tsi148_bridge->irq_generate = tsi148_irq_generate; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2497 | tsi148_bridge->lm_set = tsi148_lm_set; |
| 2498 | tsi148_bridge->lm_get = tsi148_lm_get; |
| 2499 | tsi148_bridge->lm_attach = tsi148_lm_attach; |
| 2500 | tsi148_bridge->lm_detach = tsi148_lm_detach; |
| 2501 | tsi148_bridge->slot_get = tsi148_slot_get; |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 2502 | tsi148_bridge->alloc_consistent = tsi148_alloc_consistent; |
| 2503 | tsi148_bridge->free_consistent = tsi148_free_consistent; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2504 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2505 | data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2506 | dev_info(&pdev->dev, "Board is%s the VME system controller\n", |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2507 | (data & TSI148_LCSR_VSTAT_SCONS) ? "" : " not"); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2508 | if (!geoid) |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2509 | dev_info(&pdev->dev, "VME geographical address is %d\n", |
| 2510 | data & TSI148_LCSR_VSTAT_GA_M); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2511 | else |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2512 | dev_info(&pdev->dev, "VME geographical address is set to %d\n", |
| 2513 | geoid); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2514 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2515 | dev_info(&pdev->dev, "VME Write and flush and error check is %s\n", |
| 2516 | err_chk ? "enabled" : "disabled"); |
| 2517 | |
Wei Yongjun | 0686ab7 | 2013-06-19 10:42:35 +0800 | [diff] [blame] | 2518 | retval = tsi148_crcsr_init(tsi148_bridge, pdev); |
| 2519 | if (retval) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2520 | dev_err(&pdev->dev, "CR/CSR configuration failed.\n"); |
| 2521 | goto err_crcsr; |
Martyn Welch | 4839737 | 2010-03-22 14:58:43 +0000 | [diff] [blame] | 2522 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2523 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2524 | retval = vme_register_bridge(tsi148_bridge); |
| 2525 | if (retval != 0) { |
| 2526 | dev_err(&pdev->dev, "Chip Registration failed.\n"); |
| 2527 | goto err_reg; |
| 2528 | } |
| 2529 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2530 | pci_set_drvdata(pdev, tsi148_bridge); |
| 2531 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2532 | /* Clear VME bus "board fail", and "power-up reset" lines */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2533 | data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2534 | data &= ~TSI148_LCSR_VSTAT_BRDFL; |
| 2535 | data |= TSI148_LCSR_VSTAT_CPURST; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2536 | iowrite32be(data, tsi148_device->base + TSI148_LCSR_VSTAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2537 | |
| 2538 | return 0; |
| 2539 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2540 | err_reg: |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2541 | tsi148_crcsr_exit(tsi148_bridge, pdev); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2542 | err_crcsr: |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2543 | err_lm: |
| 2544 | /* resources are stored in link list */ |
Wei Yongjun | b49c32b | 2012-08-21 12:19:01 +0800 | [diff] [blame] | 2545 | list_for_each_safe(pos, n, &tsi148_bridge->lm_resources) { |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 2546 | lm = list_entry(pos, struct vme_lm_resource, list); |
| 2547 | list_del(pos); |
| 2548 | kfree(lm); |
| 2549 | } |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2550 | err_dma: |
| 2551 | /* resources are stored in link list */ |
Wei Yongjun | b49c32b | 2012-08-21 12:19:01 +0800 | [diff] [blame] | 2552 | list_for_each_safe(pos, n, &tsi148_bridge->dma_resources) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2553 | dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); |
| 2554 | list_del(pos); |
| 2555 | kfree(dma_ctrlr); |
| 2556 | } |
| 2557 | err_slave: |
| 2558 | /* resources are stored in link list */ |
Wei Yongjun | b49c32b | 2012-08-21 12:19:01 +0800 | [diff] [blame] | 2559 | list_for_each_safe(pos, n, &tsi148_bridge->slave_resources) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2560 | slave_image = list_entry(pos, struct vme_slave_resource, list); |
| 2561 | list_del(pos); |
| 2562 | kfree(slave_image); |
| 2563 | } |
| 2564 | err_master: |
| 2565 | /* resources are stored in link list */ |
Wei Yongjun | b49c32b | 2012-08-21 12:19:01 +0800 | [diff] [blame] | 2566 | list_for_each_safe(pos, n, &tsi148_bridge->master_resources) { |
Martyn Welch | 7946328 | 2010-03-22 14:58:57 +0000 | [diff] [blame] | 2567 | master_image = list_entry(pos, struct vme_master_resource, |
| 2568 | list); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2569 | list_del(pos); |
| 2570 | kfree(master_image); |
| 2571 | } |
| 2572 | |
Emilio G. Cota | a82ad05 | 2010-11-12 11:14:47 +0000 | [diff] [blame] | 2573 | tsi148_irq_exit(tsi148_bridge, pdev); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2574 | err_irq: |
| 2575 | err_test: |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2576 | iounmap(tsi148_device->base); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2577 | err_remap: |
| 2578 | pci_release_regions(pdev); |
| 2579 | err_resource: |
| 2580 | pci_disable_device(pdev); |
| 2581 | err_enable: |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2582 | kfree(tsi148_device); |
| 2583 | err_driver: |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2584 | kfree(tsi148_bridge); |
| 2585 | err_struct: |
| 2586 | return retval; |
| 2587 | |
| 2588 | } |
| 2589 | |
| 2590 | static void tsi148_remove(struct pci_dev *pdev) |
| 2591 | { |
| 2592 | struct list_head *pos = NULL; |
Emilio G. Cota | b558ba2 | 2010-11-12 11:14:34 +0000 | [diff] [blame] | 2593 | struct list_head *tmplist; |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2594 | struct vme_master_resource *master_image; |
| 2595 | struct vme_slave_resource *slave_image; |
| 2596 | struct vme_dma_resource *dma_ctrlr; |
| 2597 | int i; |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2598 | struct tsi148_driver *bridge; |
| 2599 | struct vme_bridge *tsi148_bridge = pci_get_drvdata(pdev); |
| 2600 | |
| 2601 | bridge = tsi148_bridge->driver_priv; |
| 2602 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2603 | |
| 2604 | dev_dbg(&pdev->dev, "Driver is being unloaded.\n"); |
| 2605 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2606 | /* |
| 2607 | * Shutdown all inbound and outbound windows. |
| 2608 | */ |
| 2609 | for (i = 0; i < 8; i++) { |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2610 | iowrite32be(0, bridge->base + TSI148_LCSR_IT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2611 | TSI148_LCSR_OFFSET_ITAT); |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2612 | iowrite32be(0, bridge->base + TSI148_LCSR_OT[i] + |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2613 | TSI148_LCSR_OFFSET_OTAT); |
| 2614 | } |
| 2615 | |
| 2616 | /* |
| 2617 | * Shutdown Location monitor. |
| 2618 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2619 | iowrite32be(0, bridge->base + TSI148_LCSR_LMAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2620 | |
| 2621 | /* |
| 2622 | * Shutdown CRG map. |
| 2623 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2624 | iowrite32be(0, bridge->base + TSI148_LCSR_CSRAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2625 | |
| 2626 | /* |
| 2627 | * Clear error status. |
| 2628 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2629 | iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_EDPAT); |
| 2630 | iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_VEAT); |
| 2631 | iowrite32be(0x07000700, bridge->base + TSI148_LCSR_PSTAT); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2632 | |
| 2633 | /* |
| 2634 | * Remove VIRQ interrupt (if any) |
| 2635 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2636 | if (ioread32be(bridge->base + TSI148_LCSR_VICR) & 0x800) |
| 2637 | iowrite32be(0x8000, bridge->base + TSI148_LCSR_VICR); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2638 | |
| 2639 | /* |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2640 | * Map all Interrupts to PCI INTA |
| 2641 | */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2642 | iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM1); |
| 2643 | iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM2); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2644 | |
Emilio G. Cota | a82ad05 | 2010-11-12 11:14:47 +0000 | [diff] [blame] | 2645 | tsi148_irq_exit(tsi148_bridge, pdev); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2646 | |
| 2647 | vme_unregister_bridge(tsi148_bridge); |
| 2648 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2649 | tsi148_crcsr_exit(tsi148_bridge, pdev); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2650 | |
| 2651 | /* resources are stored in link list */ |
Emilio G. Cota | b558ba2 | 2010-11-12 11:14:34 +0000 | [diff] [blame] | 2652 | list_for_each_safe(pos, tmplist, &tsi148_bridge->dma_resources) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2653 | dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); |
| 2654 | list_del(pos); |
| 2655 | kfree(dma_ctrlr); |
| 2656 | } |
| 2657 | |
| 2658 | /* resources are stored in link list */ |
Emilio G. Cota | b558ba2 | 2010-11-12 11:14:34 +0000 | [diff] [blame] | 2659 | list_for_each_safe(pos, tmplist, &tsi148_bridge->slave_resources) { |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2660 | slave_image = list_entry(pos, struct vme_slave_resource, list); |
| 2661 | list_del(pos); |
| 2662 | kfree(slave_image); |
| 2663 | } |
| 2664 | |
| 2665 | /* resources are stored in link list */ |
Emilio G. Cota | b558ba2 | 2010-11-12 11:14:34 +0000 | [diff] [blame] | 2666 | list_for_each_safe(pos, tmplist, &tsi148_bridge->master_resources) { |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2667 | master_image = list_entry(pos, struct vme_master_resource, |
| 2668 | list); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2669 | list_del(pos); |
| 2670 | kfree(master_image); |
| 2671 | } |
| 2672 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2673 | iounmap(bridge->base); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2674 | |
| 2675 | pci_release_regions(pdev); |
| 2676 | |
| 2677 | pci_disable_device(pdev); |
| 2678 | |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 2679 | kfree(tsi148_bridge->driver_priv); |
| 2680 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2681 | kfree(tsi148_bridge); |
| 2682 | } |
| 2683 | |
Wei Yongjun | 01c0714 | 2012-10-18 23:12:50 +0800 | [diff] [blame] | 2684 | module_pci_driver(tsi148_driver); |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2685 | |
| 2686 | MODULE_PARM_DESC(err_chk, "Check for VME errors on reads and writes"); |
| 2687 | module_param(err_chk, bool, 0); |
| 2688 | |
Martyn Welch | 638f199 | 2009-12-15 08:42:49 +0000 | [diff] [blame] | 2689 | MODULE_PARM_DESC(geoid, "Override geographical addressing"); |
| 2690 | module_param(geoid, int, 0); |
| 2691 | |
Martyn Welch | d22b8ed | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2692 | MODULE_DESCRIPTION("VME driver for the Tundra Tempe VME bridge"); |
| 2693 | MODULE_LICENSE("GPL"); |