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