Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx: (63 commits)
ARM: PL08x: cleanup comments
Update CONFIG_MD_RAID6_PQ to CONFIG_RAID6_PQ in drivers/dma/iop-adma.c
ARM: PL08x: fix a warning
Fix dmaengine_submit() return type
dmaengine: at_hdmac: fix race while monitoring channel status
dmaengine: at_hdmac: flags located in first descriptor
dmaengine: at_hdmac: use subsys_initcall instead of module_init
dmaengine: at_hdmac: no need set ACK in new descriptor
dmaengine: at_hdmac: trivial add precision to unmapping comment
dmaengine: at_hdmac: use dma_address to program DMA hardware
pch_dma: support new device ML7213 IOH
ARM: PL08x: prevent dma_set_runtime_config() reconfiguring memcpy channels
ARM: PL08x: allow dma_set_runtime_config() to return errors
ARM: PL08x: fix locking between prepare function and submit function
ARM: PL08x: introduce 'phychan_hold' to hold on to physical channels
ARM: PL08x: put txd's on the pending list in pl08x_tx_submit()
ARM: PL08x: rename 'desc_list' as 'pend_list'
ARM: PL08x: implement unmapping of memcpy buffers
ARM: PL08x: store prep_* flags in async_tx structure
ARM: PL08x: shrink srcbus/dstbus in txd structure
...

+996 -846
+8
arch/arm/plat-nomadik/include/plat/ste_dma40.h
··· 13 13 #include <linux/workqueue.h> 14 14 #include <linux/interrupt.h> 15 15 16 + /* 17 + * Maxium size for a single dma descriptor 18 + * Size is limited to 16 bits. 19 + * Size is in the units of addr-widths (1,2,4,8 bytes) 20 + * Larger transfers will be split up to multiple linked desc 21 + */ 22 + #define STEDMA40_MAX_SEG_SIZE 0xFFFF 23 + 16 24 /* dev types for memcpy */ 17 25 #define STEDMA40_DEV_DST_MEMORY (-1) 18 26 #define STEDMA40_DEV_SRC_MEMORY (-1)
+7 -2
drivers/dma/Kconfig
··· 200 200 platform_data for a dma-pl330 device. 201 201 202 202 config PCH_DMA 203 - tristate "Topcliff (Intel EG20T) PCH DMA support" 203 + tristate "Intel EG20T PCH / OKI SEMICONDUCTOR ML7213 IOH DMA support" 204 204 depends on PCI && X86 205 205 select DMA_ENGINE 206 206 help 207 - Enable support for the Topcliff (Intel EG20T) PCH DMA engine. 207 + Enable support for Intel EG20T PCH DMA engine. 208 + 209 + This driver also can be used for OKI SEMICONDUCTOR ML7213 IOH(Input/ 210 + Output Hub) which is for IVI(In-Vehicle Infotainment) use. 211 + ML7213 is companion chip for Intel Atom E6xx series. 212 + ML7213 is completely compatible for Intel EG20T PCH. 208 213 209 214 config IMX_SDMA 210 215 tristate "i.MX SDMA support"
+535 -637
drivers/dma/amba-pl08x.c
··· 19 19 * this program; if not, write to the Free Software Foundation, Inc., 59 20 20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 21 * 22 - * The full GNU General Public License is iin this distribution in the 23 - * file called COPYING. 22 + * The full GNU General Public License is in this distribution in the file 23 + * called COPYING. 24 24 * 25 25 * Documentation: ARM DDI 0196G == PL080 26 - * Documentation: ARM DDI 0218E == PL081 26 + * Documentation: ARM DDI 0218E == PL081 27 27 * 28 - * PL080 & PL081 both have 16 sets of DMA signals that can be routed to 29 - * any channel. 28 + * PL080 & PL081 both have 16 sets of DMA signals that can be routed to any 29 + * channel. 30 30 * 31 31 * The PL080 has 8 channels available for simultaneous use, and the PL081 32 32 * has only two channels. So on these DMA controllers the number of channels ··· 53 53 * 54 54 * ASSUMES default (little) endianness for DMA transfers 55 55 * 56 - * Only DMAC flow control is implemented 56 + * The PL08x has two flow control settings: 57 + * - DMAC flow control: the transfer size defines the number of transfers 58 + * which occur for the current LLI entry, and the DMAC raises TC at the 59 + * end of every LLI entry. Observed behaviour shows the DMAC listening 60 + * to both the BREQ and SREQ signals (contrary to documented), 61 + * transferring data if either is active. The LBREQ and LSREQ signals 62 + * are ignored. 63 + * 64 + * - Peripheral flow control: the transfer size is ignored (and should be 65 + * zero). The data is transferred from the current LLI entry, until 66 + * after the final transfer signalled by LBREQ or LSREQ. The DMAC 67 + * will then move to the next LLI entry. 68 + * 69 + * Only the former works sanely with scatter lists, so we only implement 70 + * the DMAC flow control method. However, peripherals which use the LBREQ 71 + * and LSREQ signals (eg, MMCI) are unable to use this mode, which through 72 + * these hardware restrictions prevents them from using scatter DMA. 57 73 * 58 74 * Global TODO: 59 75 * - Break out common code from arch/arm/mach-s3c64xx and share ··· 77 61 #include <linux/device.h> 78 62 #include <linux/init.h> 79 63 #include <linux/module.h> 80 - #include <linux/pci.h> 81 64 #include <linux/interrupt.h> 82 65 #include <linux/slab.h> 83 66 #include <linux/dmapool.h> 84 - #include <linux/amba/bus.h> 85 67 #include <linux/dmaengine.h> 68 + #include <linux/amba/bus.h> 86 69 #include <linux/amba/pl08x.h> 87 70 #include <linux/debugfs.h> 88 71 #include <linux/seq_file.h> 89 72 90 73 #include <asm/hardware/pl080.h> 91 - #include <asm/dma.h> 92 - #include <asm/mach/dma.h> 93 - #include <asm/atomic.h> 94 - #include <asm/processor.h> 95 - #include <asm/cacheflush.h> 96 74 97 75 #define DRIVER_NAME "pl08xdmac" 98 76 99 77 /** 100 - * struct vendor_data - vendor-specific config parameters 101 - * for PL08x derivates 102 - * @name: the name of this specific variant 78 + * struct vendor_data - vendor-specific config parameters for PL08x derivatives 103 79 * @channels: the number of channels available in this variant 104 - * @dualmaster: whether this version supports dual AHB masters 105 - * or not. 80 + * @dualmaster: whether this version supports dual AHB masters or not. 106 81 */ 107 82 struct vendor_data { 108 - char *name; 109 83 u8 channels; 110 84 bool dualmaster; 111 85 }; 112 86 113 87 /* 114 88 * PL08X private data structures 115 - * An LLI struct - see pl08x TRM 116 - * Note that next uses bit[0] as a bus bit, 117 - * start & end do not - their bus bit info 118 - * is in cctl 89 + * An LLI struct - see PL08x TRM. Note that next uses bit[0] as a bus bit, 90 + * start & end do not - their bus bit info is in cctl. Also note that these 91 + * are fixed 32-bit quantities. 119 92 */ 120 - struct lli { 121 - dma_addr_t src; 122 - dma_addr_t dst; 123 - dma_addr_t next; 93 + struct pl08x_lli { 94 + u32 src; 95 + u32 dst; 96 + u32 lli; 124 97 u32 cctl; 125 98 }; 126 99 ··· 124 119 * @phy_chans: array of data for the physical channels 125 120 * @pool: a pool for the LLI descriptors 126 121 * @pool_ctr: counter of LLIs in the pool 122 + * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI fetches 123 + * @mem_buses: set to indicate memory transfers on AHB2. 127 124 * @lock: a spinlock for this struct 128 125 */ 129 126 struct pl08x_driver_data { ··· 133 126 struct dma_device memcpy; 134 127 void __iomem *base; 135 128 struct amba_device *adev; 136 - struct vendor_data *vd; 129 + const struct vendor_data *vd; 137 130 struct pl08x_platform_data *pd; 138 131 struct pl08x_phy_chan *phy_chans; 139 132 struct dma_pool *pool; 140 133 int pool_ctr; 134 + u8 lli_buses; 135 + u8 mem_buses; 141 136 spinlock_t lock; 142 137 }; 143 138 ··· 161 152 /* Size (bytes) of each LLI buffer allocated for one transfer */ 162 153 # define PL08X_LLI_TSFR_SIZE 0x2000 163 154 164 - /* Maximimum times we call dma_pool_alloc on this pool without freeing */ 155 + /* Maximum times we call dma_pool_alloc on this pool without freeing */ 165 156 #define PL08X_MAX_ALLOCS 0x40 166 - #define MAX_NUM_TSFR_LLIS (PL08X_LLI_TSFR_SIZE/sizeof(struct lli)) 157 + #define MAX_NUM_TSFR_LLIS (PL08X_LLI_TSFR_SIZE/sizeof(struct pl08x_lli)) 167 158 #define PL08X_ALIGN 8 168 159 169 160 static inline struct pl08x_dma_chan *to_pl08x_chan(struct dma_chan *chan) 170 161 { 171 162 return container_of(chan, struct pl08x_dma_chan, chan); 163 + } 164 + 165 + static inline struct pl08x_txd *to_pl08x_txd(struct dma_async_tx_descriptor *tx) 166 + { 167 + return container_of(tx, struct pl08x_txd, tx); 172 168 } 173 169 174 170 /* ··· 191 177 192 178 /* 193 179 * Set the initial DMA register values i.e. those for the first LLI 194 - * The next lli pointer and the configuration interrupt bit have 195 - * been set when the LLIs were constructed 180 + * The next LLI pointer and the configuration interrupt bit have 181 + * been set when the LLIs were constructed. Poke them into the hardware 182 + * and start the transfer. 196 183 */ 197 - static void pl08x_set_cregs(struct pl08x_driver_data *pl08x, 198 - struct pl08x_phy_chan *ch) 184 + static void pl08x_start_txd(struct pl08x_dma_chan *plchan, 185 + struct pl08x_txd *txd) 199 186 { 200 - /* Wait for channel inactive */ 201 - while (pl08x_phy_channel_busy(ch)) 202 - ; 203 - 204 - dev_vdbg(&pl08x->adev->dev, 205 - "WRITE channel %d: csrc=%08x, cdst=%08x, " 206 - "cctl=%08x, clli=%08x, ccfg=%08x\n", 207 - ch->id, 208 - ch->csrc, 209 - ch->cdst, 210 - ch->cctl, 211 - ch->clli, 212 - ch->ccfg); 213 - 214 - writel(ch->csrc, ch->base + PL080_CH_SRC_ADDR); 215 - writel(ch->cdst, ch->base + PL080_CH_DST_ADDR); 216 - writel(ch->clli, ch->base + PL080_CH_LLI); 217 - writel(ch->cctl, ch->base + PL080_CH_CONTROL); 218 - writel(ch->ccfg, ch->base + PL080_CH_CONFIG); 219 - } 220 - 221 - static inline void pl08x_config_phychan_for_txd(struct pl08x_dma_chan *plchan) 222 - { 223 - struct pl08x_channel_data *cd = plchan->cd; 187 + struct pl08x_driver_data *pl08x = plchan->host; 224 188 struct pl08x_phy_chan *phychan = plchan->phychan; 225 - struct pl08x_txd *txd = plchan->at; 226 - 227 - /* Copy the basic control register calculated at transfer config */ 228 - phychan->csrc = txd->csrc; 229 - phychan->cdst = txd->cdst; 230 - phychan->clli = txd->clli; 231 - phychan->cctl = txd->cctl; 232 - 233 - /* Assign the signal to the proper control registers */ 234 - phychan->ccfg = cd->ccfg; 235 - phychan->ccfg &= ~PL080_CONFIG_SRC_SEL_MASK; 236 - phychan->ccfg &= ~PL080_CONFIG_DST_SEL_MASK; 237 - /* If it wasn't set from AMBA, ignore it */ 238 - if (txd->direction == DMA_TO_DEVICE) 239 - /* Select signal as destination */ 240 - phychan->ccfg |= 241 - (phychan->signal << PL080_CONFIG_DST_SEL_SHIFT); 242 - else if (txd->direction == DMA_FROM_DEVICE) 243 - /* Select signal as source */ 244 - phychan->ccfg |= 245 - (phychan->signal << PL080_CONFIG_SRC_SEL_SHIFT); 246 - /* Always enable error interrupts */ 247 - phychan->ccfg |= PL080_CONFIG_ERR_IRQ_MASK; 248 - /* Always enable terminal interrupts */ 249 - phychan->ccfg |= PL080_CONFIG_TC_IRQ_MASK; 250 - } 251 - 252 - /* 253 - * Enable the DMA channel 254 - * Assumes all other configuration bits have been set 255 - * as desired before this code is called 256 - */ 257 - static void pl08x_enable_phy_chan(struct pl08x_driver_data *pl08x, 258 - struct pl08x_phy_chan *ch) 259 - { 189 + struct pl08x_lli *lli = &txd->llis_va[0]; 260 190 u32 val; 261 191 262 - /* 263 - * Do not access config register until channel shows as disabled 264 - */ 265 - while (readl(pl08x->base + PL080_EN_CHAN) & (1 << ch->id)) 266 - ; 192 + plchan->at = txd; 267 193 268 - /* 269 - * Do not access config register until channel shows as inactive 270 - */ 271 - val = readl(ch->base + PL080_CH_CONFIG); 194 + /* Wait for channel inactive */ 195 + while (pl08x_phy_channel_busy(phychan)) 196 + cpu_relax(); 197 + 198 + dev_vdbg(&pl08x->adev->dev, 199 + "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, " 200 + "clli=0x%08x, cctl=0x%08x, ccfg=0x%08x\n", 201 + phychan->id, lli->src, lli->dst, lli->lli, lli->cctl, 202 + txd->ccfg); 203 + 204 + writel(lli->src, phychan->base + PL080_CH_SRC_ADDR); 205 + writel(lli->dst, phychan->base + PL080_CH_DST_ADDR); 206 + writel(lli->lli, phychan->base + PL080_CH_LLI); 207 + writel(lli->cctl, phychan->base + PL080_CH_CONTROL); 208 + writel(txd->ccfg, phychan->base + PL080_CH_CONFIG); 209 + 210 + /* Enable the DMA channel */ 211 + /* Do not access config register until channel shows as disabled */ 212 + while (readl(pl08x->base + PL080_EN_CHAN) & (1 << phychan->id)) 213 + cpu_relax(); 214 + 215 + /* Do not access config register until channel shows as inactive */ 216 + val = readl(phychan->base + PL080_CH_CONFIG); 272 217 while ((val & PL080_CONFIG_ACTIVE) || (val & PL080_CONFIG_ENABLE)) 273 - val = readl(ch->base + PL080_CH_CONFIG); 218 + val = readl(phychan->base + PL080_CH_CONFIG); 274 219 275 - writel(val | PL080_CONFIG_ENABLE, ch->base + PL080_CH_CONFIG); 220 + writel(val | PL080_CONFIG_ENABLE, phychan->base + PL080_CH_CONFIG); 276 221 } 277 222 278 223 /* ··· 239 266 * 240 267 * Disabling individual channels could lose data. 241 268 * 242 - * Disable the peripheral DMA after disabling the DMAC 243 - * in order to allow the DMAC FIFO to drain, and 244 - * hence allow the channel to show inactive 245 - * 269 + * Disable the peripheral DMA after disabling the DMAC in order to allow 270 + * the DMAC FIFO to drain, and hence allow the channel to show inactive 246 271 */ 247 272 static void pl08x_pause_phy_chan(struct pl08x_phy_chan *ch) 248 273 { ··· 253 282 254 283 /* Wait for channel inactive */ 255 284 while (pl08x_phy_channel_busy(ch)) 256 - ; 285 + cpu_relax(); 257 286 } 258 287 259 288 static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch) ··· 304 333 static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan) 305 334 { 306 335 struct pl08x_phy_chan *ch; 307 - struct pl08x_txd *txdi = NULL; 308 336 struct pl08x_txd *txd; 309 337 unsigned long flags; 310 - u32 bytes = 0; 338 + size_t bytes = 0; 311 339 312 340 spin_lock_irqsave(&plchan->lock, flags); 313 - 314 341 ch = plchan->phychan; 315 342 txd = plchan->at; 316 343 317 344 /* 318 - * Next follow the LLIs to get the number of pending bytes in the 319 - * currently active transaction. 345 + * Follow the LLIs to get the number of remaining 346 + * bytes in the currently active transaction. 320 347 */ 321 348 if (ch && txd) { 322 - struct lli *llis_va = txd->llis_va; 323 - struct lli *llis_bus = (struct lli *) txd->llis_bus; 324 - u32 clli = readl(ch->base + PL080_CH_LLI); 349 + u32 clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2; 325 350 326 - /* First get the bytes in the current active LLI */ 351 + /* First get the remaining bytes in the active transfer */ 327 352 bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL)); 328 353 329 354 if (clli) { 330 - int i = 0; 355 + struct pl08x_lli *llis_va = txd->llis_va; 356 + dma_addr_t llis_bus = txd->llis_bus; 357 + int index; 331 358 332 - /* Forward to the LLI pointed to by clli */ 333 - while ((clli != (u32) &(llis_bus[i])) && 334 - (i < MAX_NUM_TSFR_LLIS)) 335 - i++; 359 + BUG_ON(clli < llis_bus || clli >= llis_bus + 360 + sizeof(struct pl08x_lli) * MAX_NUM_TSFR_LLIS); 336 361 337 - while (clli) { 338 - bytes += get_bytes_in_cctl(llis_va[i].cctl); 362 + /* 363 + * Locate the next LLI - as this is an array, 364 + * it's simple maths to find. 365 + */ 366 + index = (clli - llis_bus) / sizeof(struct pl08x_lli); 367 + 368 + for (; index < MAX_NUM_TSFR_LLIS; index++) { 369 + bytes += get_bytes_in_cctl(llis_va[index].cctl); 370 + 339 371 /* 340 - * A clli of 0x00000000 will terminate the 341 - * LLI list 372 + * A LLI pointer of 0 terminates the LLI list 342 373 */ 343 - clli = llis_va[i].next; 344 - i++; 374 + if (!llis_va[index].lli) 375 + break; 345 376 } 346 377 } 347 378 } 348 379 349 380 /* Sum up all queued transactions */ 350 - if (!list_empty(&plchan->desc_list)) { 351 - list_for_each_entry(txdi, &plchan->desc_list, node) { 381 + if (!list_empty(&plchan->pend_list)) { 382 + struct pl08x_txd *txdi; 383 + list_for_each_entry(txdi, &plchan->pend_list, node) { 352 384 bytes += txdi->len; 353 385 } 354 - 355 386 } 356 387 357 388 spin_unlock_irqrestore(&plchan->lock, flags); ··· 363 390 364 391 /* 365 392 * Allocate a physical channel for a virtual channel 393 + * 394 + * Try to locate a physical channel to be used for this transfer. If all 395 + * are taken return NULL and the requester will have to cope by using 396 + * some fallback PIO mode or retrying later. 366 397 */ 367 398 static struct pl08x_phy_chan * 368 399 pl08x_get_phy_channel(struct pl08x_driver_data *pl08x, ··· 376 399 unsigned long flags; 377 400 int i; 378 401 379 - /* 380 - * Try to locate a physical channel to be used for 381 - * this transfer. If all are taken return NULL and 382 - * the requester will have to cope by using some fallback 383 - * PIO mode or retrying later. 384 - */ 385 402 for (i = 0; i < pl08x->vd->channels; i++) { 386 403 ch = &pl08x->phy_chans[i]; 387 404 ··· 436 465 } 437 466 438 467 static inline u32 pl08x_cctl_bits(u32 cctl, u8 srcwidth, u8 dstwidth, 439 - u32 tsize) 468 + size_t tsize) 440 469 { 441 470 u32 retbits = cctl; 442 471 443 - /* Remove all src, dst and transfersize bits */ 472 + /* Remove all src, dst and transfer size bits */ 444 473 retbits &= ~PL080_CONTROL_DWIDTH_MASK; 445 474 retbits &= ~PL080_CONTROL_SWIDTH_MASK; 446 475 retbits &= ~PL080_CONTROL_TRANSFER_SIZE_MASK; ··· 480 509 return retbits; 481 510 } 482 511 512 + struct pl08x_lli_build_data { 513 + struct pl08x_txd *txd; 514 + struct pl08x_driver_data *pl08x; 515 + struct pl08x_bus_data srcbus; 516 + struct pl08x_bus_data dstbus; 517 + size_t remainder; 518 + }; 519 + 483 520 /* 484 - * Autoselect a master bus to use for the transfer 485 - * this prefers the destination bus if both available 486 - * if fixed address on one bus the other will be chosen 521 + * Autoselect a master bus to use for the transfer this prefers the 522 + * destination bus if both available if fixed address on one bus the 523 + * other will be chosen 487 524 */ 488 - void pl08x_choose_master_bus(struct pl08x_bus_data *src_bus, 489 - struct pl08x_bus_data *dst_bus, struct pl08x_bus_data **mbus, 490 - struct pl08x_bus_data **sbus, u32 cctl) 525 + static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd, 526 + struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl) 491 527 { 492 528 if (!(cctl & PL080_CONTROL_DST_INCR)) { 493 - *mbus = src_bus; 494 - *sbus = dst_bus; 529 + *mbus = &bd->srcbus; 530 + *sbus = &bd->dstbus; 495 531 } else if (!(cctl & PL080_CONTROL_SRC_INCR)) { 496 - *mbus = dst_bus; 497 - *sbus = src_bus; 532 + *mbus = &bd->dstbus; 533 + *sbus = &bd->srcbus; 498 534 } else { 499 - if (dst_bus->buswidth == 4) { 500 - *mbus = dst_bus; 501 - *sbus = src_bus; 502 - } else if (src_bus->buswidth == 4) { 503 - *mbus = src_bus; 504 - *sbus = dst_bus; 505 - } else if (dst_bus->buswidth == 2) { 506 - *mbus = dst_bus; 507 - *sbus = src_bus; 508 - } else if (src_bus->buswidth == 2) { 509 - *mbus = src_bus; 510 - *sbus = dst_bus; 535 + if (bd->dstbus.buswidth == 4) { 536 + *mbus = &bd->dstbus; 537 + *sbus = &bd->srcbus; 538 + } else if (bd->srcbus.buswidth == 4) { 539 + *mbus = &bd->srcbus; 540 + *sbus = &bd->dstbus; 541 + } else if (bd->dstbus.buswidth == 2) { 542 + *mbus = &bd->dstbus; 543 + *sbus = &bd->srcbus; 544 + } else if (bd->srcbus.buswidth == 2) { 545 + *mbus = &bd->srcbus; 546 + *sbus = &bd->dstbus; 511 547 } else { 512 - /* src_bus->buswidth == 1 */ 513 - *mbus = dst_bus; 514 - *sbus = src_bus; 548 + /* bd->srcbus.buswidth == 1 */ 549 + *mbus = &bd->dstbus; 550 + *sbus = &bd->srcbus; 515 551 } 516 552 } 517 553 } 518 554 519 555 /* 520 - * Fills in one LLI for a certain transfer descriptor 521 - * and advance the counter 556 + * Fills in one LLI for a certain transfer descriptor and advance the counter 522 557 */ 523 - int pl08x_fill_lli_for_desc(struct pl08x_driver_data *pl08x, 524 - struct pl08x_txd *txd, int num_llis, int len, 525 - u32 cctl, u32 *remainder) 558 + static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd, 559 + int num_llis, int len, u32 cctl) 526 560 { 527 - struct lli *llis_va = txd->llis_va; 528 - struct lli *llis_bus = (struct lli *) txd->llis_bus; 561 + struct pl08x_lli *llis_va = bd->txd->llis_va; 562 + dma_addr_t llis_bus = bd->txd->llis_bus; 529 563 530 564 BUG_ON(num_llis >= MAX_NUM_TSFR_LLIS); 531 565 532 - llis_va[num_llis].cctl = cctl; 533 - llis_va[num_llis].src = txd->srcbus.addr; 534 - llis_va[num_llis].dst = txd->dstbus.addr; 535 - 536 - /* 537 - * On versions with dual masters, you can optionally AND on 538 - * PL080_LLI_LM_AHB2 to the LLI to tell the hardware to read 539 - * in new LLIs with that controller, but we always try to 540 - * choose AHB1 to point into memory. The idea is to have AHB2 541 - * fixed on the peripheral and AHB1 messing around in the 542 - * memory. So we don't manipulate this bit currently. 543 - */ 544 - 545 - llis_va[num_llis].next = 546 - (dma_addr_t)((u32) &(llis_bus[num_llis + 1])); 566 + llis_va[num_llis].cctl = cctl; 567 + llis_va[num_llis].src = bd->srcbus.addr; 568 + llis_va[num_llis].dst = bd->dstbus.addr; 569 + llis_va[num_llis].lli = llis_bus + (num_llis + 1) * sizeof(struct pl08x_lli); 570 + if (bd->pl08x->lli_buses & PL08X_AHB2) 571 + llis_va[num_llis].lli |= PL080_LLI_LM_AHB2; 547 572 548 573 if (cctl & PL080_CONTROL_SRC_INCR) 549 - txd->srcbus.addr += len; 574 + bd->srcbus.addr += len; 550 575 if (cctl & PL080_CONTROL_DST_INCR) 551 - txd->dstbus.addr += len; 576 + bd->dstbus.addr += len; 552 577 553 - *remainder -= len; 578 + BUG_ON(bd->remainder < len); 554 579 555 - return num_llis + 1; 580 + bd->remainder -= len; 556 581 } 557 582 558 583 /* 559 - * Return number of bytes to fill to boundary, or len 584 + * Return number of bytes to fill to boundary, or len. 585 + * This calculation works for any value of addr. 560 586 */ 561 - static inline u32 pl08x_pre_boundary(u32 addr, u32 len) 587 + static inline size_t pl08x_pre_boundary(u32 addr, size_t len) 562 588 { 563 - u32 boundary; 589 + size_t boundary_len = PL08X_BOUNDARY_SIZE - 590 + (addr & (PL08X_BOUNDARY_SIZE - 1)); 564 591 565 - boundary = ((addr >> PL08X_BOUNDARY_SHIFT) + 1) 566 - << PL08X_BOUNDARY_SHIFT; 567 - 568 - if (boundary < addr + len) 569 - return boundary - addr; 570 - else 571 - return len; 592 + return min(boundary_len, len); 572 593 } 573 594 574 595 /* ··· 571 608 static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x, 572 609 struct pl08x_txd *txd) 573 610 { 574 - struct pl08x_channel_data *cd = txd->cd; 575 611 struct pl08x_bus_data *mbus, *sbus; 576 - u32 remainder; 612 + struct pl08x_lli_build_data bd; 577 613 int num_llis = 0; 578 614 u32 cctl; 579 - int max_bytes_per_lli; 580 - int total_bytes = 0; 581 - struct lli *llis_va; 582 - struct lli *llis_bus; 583 - 584 - if (!txd) { 585 - dev_err(&pl08x->adev->dev, "%s no descriptor\n", __func__); 586 - return 0; 587 - } 615 + size_t max_bytes_per_lli; 616 + size_t total_bytes = 0; 617 + struct pl08x_lli *llis_va; 588 618 589 619 txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, 590 620 &txd->llis_bus); ··· 588 632 589 633 pl08x->pool_ctr++; 590 634 591 - /* 592 - * Initialize bus values for this transfer 593 - * from the passed optimal values 594 - */ 595 - if (!cd) { 596 - dev_err(&pl08x->adev->dev, "%s no channel data\n", __func__); 597 - return 0; 598 - } 635 + /* Get the default CCTL */ 636 + cctl = txd->cctl; 599 637 600 - /* Get the default CCTL from the platform data */ 601 - cctl = cd->cctl; 602 - 603 - /* 604 - * On the PL080 we have two bus masters and we 605 - * should select one for source and one for 606 - * destination. We try to use AHB2 for the 607 - * bus which does not increment (typically the 608 - * peripheral) else we just choose something. 609 - */ 610 - cctl &= ~(PL080_CONTROL_DST_AHB2 | PL080_CONTROL_SRC_AHB2); 611 - if (pl08x->vd->dualmaster) { 612 - if (cctl & PL080_CONTROL_SRC_INCR) 613 - /* Source increments, use AHB2 for destination */ 614 - cctl |= PL080_CONTROL_DST_AHB2; 615 - else if (cctl & PL080_CONTROL_DST_INCR) 616 - /* Destination increments, use AHB2 for source */ 617 - cctl |= PL080_CONTROL_SRC_AHB2; 618 - else 619 - /* Just pick something, source AHB1 dest AHB2 */ 620 - cctl |= PL080_CONTROL_DST_AHB2; 621 - } 638 + bd.txd = txd; 639 + bd.pl08x = pl08x; 640 + bd.srcbus.addr = txd->src_addr; 641 + bd.dstbus.addr = txd->dst_addr; 622 642 623 643 /* Find maximum width of the source bus */ 624 - txd->srcbus.maxwidth = 644 + bd.srcbus.maxwidth = 625 645 pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_SWIDTH_MASK) >> 626 646 PL080_CONTROL_SWIDTH_SHIFT); 627 647 628 648 /* Find maximum width of the destination bus */ 629 - txd->dstbus.maxwidth = 649 + bd.dstbus.maxwidth = 630 650 pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >> 631 651 PL080_CONTROL_DWIDTH_SHIFT); 632 652 633 653 /* Set up the bus widths to the maximum */ 634 - txd->srcbus.buswidth = txd->srcbus.maxwidth; 635 - txd->dstbus.buswidth = txd->dstbus.maxwidth; 654 + bd.srcbus.buswidth = bd.srcbus.maxwidth; 655 + bd.dstbus.buswidth = bd.dstbus.maxwidth; 636 656 dev_vdbg(&pl08x->adev->dev, 637 657 "%s source bus is %d bytes wide, dest bus is %d bytes wide\n", 638 - __func__, txd->srcbus.buswidth, txd->dstbus.buswidth); 658 + __func__, bd.srcbus.buswidth, bd.dstbus.buswidth); 639 659 640 660 641 661 /* 642 662 * Bytes transferred == tsize * MIN(buswidths), not max(buswidths) 643 663 */ 644 - max_bytes_per_lli = min(txd->srcbus.buswidth, txd->dstbus.buswidth) * 664 + max_bytes_per_lli = min(bd.srcbus.buswidth, bd.dstbus.buswidth) * 645 665 PL080_CONTROL_TRANSFER_SIZE_MASK; 646 666 dev_vdbg(&pl08x->adev->dev, 647 - "%s max bytes per lli = %d\n", 667 + "%s max bytes per lli = %zu\n", 648 668 __func__, max_bytes_per_lli); 649 669 650 670 /* We need to count this down to zero */ 651 - remainder = txd->len; 671 + bd.remainder = txd->len; 652 672 dev_vdbg(&pl08x->adev->dev, 653 - "%s remainder = %d\n", 654 - __func__, remainder); 673 + "%s remainder = %zu\n", 674 + __func__, bd.remainder); 655 675 656 676 /* 657 677 * Choose bus to align to 658 678 * - prefers destination bus if both available 659 679 * - if fixed address on one bus chooses other 660 - * - modifies cctl to choose an apropriate master 661 680 */ 662 - pl08x_choose_master_bus(&txd->srcbus, &txd->dstbus, 663 - &mbus, &sbus, cctl); 664 - 665 - 666 - /* 667 - * The lowest bit of the LLI register 668 - * is also used to indicate which master to 669 - * use for reading the LLIs. 670 - */ 681 + pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl); 671 682 672 683 if (txd->len < mbus->buswidth) { 673 - /* 674 - * Less than a bus width available 675 - * - send as single bytes 676 - */ 677 - while (remainder) { 684 + /* Less than a bus width available - send as single bytes */ 685 + while (bd.remainder) { 678 686 dev_vdbg(&pl08x->adev->dev, 679 687 "%s single byte LLIs for a transfer of " 680 - "less than a bus width (remain %08x)\n", 681 - __func__, remainder); 688 + "less than a bus width (remain 0x%08x)\n", 689 + __func__, bd.remainder); 682 690 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 683 - num_llis = 684 - pl08x_fill_lli_for_desc(pl08x, txd, num_llis, 1, 685 - cctl, &remainder); 691 + pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); 686 692 total_bytes++; 687 693 } 688 694 } else { 689 - /* 690 - * Make one byte LLIs until master bus is aligned 691 - * - slave will then be aligned also 692 - */ 695 + /* Make one byte LLIs until master bus is aligned */ 693 696 while ((mbus->addr) % (mbus->buswidth)) { 694 697 dev_vdbg(&pl08x->adev->dev, 695 698 "%s adjustment lli for less than bus width " 696 - "(remain %08x)\n", 697 - __func__, remainder); 699 + "(remain 0x%08x)\n", 700 + __func__, bd.remainder); 698 701 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 699 - num_llis = pl08x_fill_lli_for_desc 700 - (pl08x, txd, num_llis, 1, cctl, &remainder); 702 + pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); 701 703 total_bytes++; 702 704 } 703 705 704 706 /* 705 - * Master now aligned 707 + * Master now aligned 706 708 * - if slave is not then we must set its width down 707 709 */ 708 710 if (sbus->addr % sbus->buswidth) { ··· 675 761 * Make largest possible LLIs until less than one bus 676 762 * width left 677 763 */ 678 - while (remainder > (mbus->buswidth - 1)) { 679 - int lli_len, target_len; 680 - int tsize; 681 - int odd_bytes; 764 + while (bd.remainder > (mbus->buswidth - 1)) { 765 + size_t lli_len, target_len, tsize, odd_bytes; 682 766 683 767 /* 684 768 * If enough left try to send max possible, 685 769 * otherwise try to send the remainder 686 770 */ 687 - target_len = remainder; 688 - if (remainder > max_bytes_per_lli) 689 - target_len = max_bytes_per_lli; 771 + target_len = min(bd.remainder, max_bytes_per_lli); 690 772 691 773 /* 692 - * Set bus lengths for incrementing busses 693 - * to number of bytes which fill to next memory 694 - * boundary 774 + * Set bus lengths for incrementing buses to the 775 + * number of bytes which fill to next memory boundary, 776 + * limiting on the target length calculated above. 695 777 */ 696 778 if (cctl & PL080_CONTROL_SRC_INCR) 697 - txd->srcbus.fill_bytes = 698 - pl08x_pre_boundary( 699 - txd->srcbus.addr, 700 - remainder); 779 + bd.srcbus.fill_bytes = 780 + pl08x_pre_boundary(bd.srcbus.addr, 781 + target_len); 701 782 else 702 - txd->srcbus.fill_bytes = 703 - max_bytes_per_lli; 783 + bd.srcbus.fill_bytes = target_len; 704 784 705 785 if (cctl & PL080_CONTROL_DST_INCR) 706 - txd->dstbus.fill_bytes = 707 - pl08x_pre_boundary( 708 - txd->dstbus.addr, 709 - remainder); 786 + bd.dstbus.fill_bytes = 787 + pl08x_pre_boundary(bd.dstbus.addr, 788 + target_len); 710 789 else 711 - txd->dstbus.fill_bytes = 712 - max_bytes_per_lli; 790 + bd.dstbus.fill_bytes = target_len; 713 791 714 - /* 715 - * Find the nearest 716 - */ 717 - lli_len = min(txd->srcbus.fill_bytes, 718 - txd->dstbus.fill_bytes); 792 + /* Find the nearest */ 793 + lli_len = min(bd.srcbus.fill_bytes, 794 + bd.dstbus.fill_bytes); 719 795 720 - BUG_ON(lli_len > remainder); 796 + BUG_ON(lli_len > bd.remainder); 721 797 722 798 if (lli_len <= 0) { 723 799 dev_err(&pl08x->adev->dev, 724 - "%s lli_len is %d, <= 0\n", 800 + "%s lli_len is %zu, <= 0\n", 725 801 __func__, lli_len); 726 802 return 0; 727 803 } 728 804 729 805 if (lli_len == target_len) { 730 806 /* 731 - * Can send what we wanted 732 - */ 733 - /* 734 - * Maintain alignment 807 + * Can send what we wanted. 808 + * Maintain alignment 735 809 */ 736 810 lli_len = (lli_len/mbus->buswidth) * 737 811 mbus->buswidth; ··· 727 825 } else { 728 826 /* 729 827 * So now we know how many bytes to transfer 730 - * to get to the nearest boundary 731 - * The next lli will past the boundary 732 - * - however we may be working to a boundary 733 - * on the slave bus 734 - * We need to ensure the master stays aligned 828 + * to get to the nearest boundary. The next 829 + * LLI will past the boundary. However, we 830 + * may be working to a boundary on the slave 831 + * bus. We need to ensure the master stays 832 + * aligned, and that we are working in 833 + * multiples of the bus widths. 735 834 */ 736 835 odd_bytes = lli_len % mbus->buswidth; 737 - /* 738 - * - and that we are working in multiples 739 - * of the bus widths 740 - */ 741 836 lli_len -= odd_bytes; 742 837 743 838 } ··· 754 855 755 856 if (target_len != lli_len) { 756 857 dev_vdbg(&pl08x->adev->dev, 757 - "%s can't send what we want. Desired %08x, lli of %08x bytes in txd of %08x\n", 858 + "%s can't send what we want. Desired 0x%08zx, lli of 0x%08zx bytes in txd of 0x%08zx\n", 758 859 __func__, target_len, lli_len, txd->len); 759 860 } 760 861 761 862 cctl = pl08x_cctl_bits(cctl, 762 - txd->srcbus.buswidth, 763 - txd->dstbus.buswidth, 863 + bd.srcbus.buswidth, 864 + bd.dstbus.buswidth, 764 865 tsize); 765 866 766 867 dev_vdbg(&pl08x->adev->dev, 767 - "%s fill lli with single lli chunk of size %08x (remainder %08x)\n", 768 - __func__, lli_len, remainder); 769 - num_llis = pl08x_fill_lli_for_desc(pl08x, txd, 770 - num_llis, lli_len, cctl, 771 - &remainder); 868 + "%s fill lli with single lli chunk of size 0x%08zx (remainder 0x%08zx)\n", 869 + __func__, lli_len, bd.remainder); 870 + pl08x_fill_lli_for_desc(&bd, num_llis++, 871 + lli_len, cctl); 772 872 total_bytes += lli_len; 773 873 } 774 874 775 875 776 876 if (odd_bytes) { 777 877 /* 778 - * Creep past the boundary, 779 - * maintaining master alignment 878 + * Creep past the boundary, maintaining 879 + * master alignment 780 880 */ 781 881 int j; 782 882 for (j = 0; (j < mbus->buswidth) 783 - && (remainder); j++) { 883 + && (bd.remainder); j++) { 784 884 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 785 885 dev_vdbg(&pl08x->adev->dev, 786 - "%s align with boundardy, single byte (remain %08x)\n", 787 - __func__, remainder); 788 - num_llis = 789 - pl08x_fill_lli_for_desc(pl08x, 790 - txd, num_llis, 1, 791 - cctl, &remainder); 886 + "%s align with boundary, single byte (remain 0x%08zx)\n", 887 + __func__, bd.remainder); 888 + pl08x_fill_lli_for_desc(&bd, 889 + num_llis++, 1, cctl); 792 890 total_bytes++; 793 891 } 794 892 } ··· 794 898 /* 795 899 * Send any odd bytes 796 900 */ 797 - if (remainder < 0) { 798 - dev_err(&pl08x->adev->dev, "%s remainder not fitted 0x%08x bytes\n", 799 - __func__, remainder); 800 - return 0; 801 - } 802 - 803 - while (remainder) { 901 + while (bd.remainder) { 804 902 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 805 903 dev_vdbg(&pl08x->adev->dev, 806 - "%s align with boundardy, single odd byte (remain %d)\n", 807 - __func__, remainder); 808 - num_llis = pl08x_fill_lli_for_desc(pl08x, txd, num_llis, 809 - 1, cctl, &remainder); 904 + "%s align with boundary, single odd byte (remain %zu)\n", 905 + __func__, bd.remainder); 906 + pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl); 810 907 total_bytes++; 811 908 } 812 909 } 813 910 if (total_bytes != txd->len) { 814 911 dev_err(&pl08x->adev->dev, 815 - "%s size of encoded lli:s don't match total txd, transferred 0x%08x from size 0x%08x\n", 912 + "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n", 816 913 __func__, total_bytes, txd->len); 817 914 return 0; 818 915 } ··· 816 927 __func__, (u32) MAX_NUM_TSFR_LLIS); 817 928 return 0; 818 929 } 819 - /* 820 - * Decide whether this is a loop or a terminated transfer 821 - */ 930 + 822 931 llis_va = txd->llis_va; 823 - llis_bus = (struct lli *) txd->llis_bus; 824 - 825 - if (cd->circular_buffer) { 826 - /* 827 - * Loop the circular buffer so that the next element 828 - * points back to the beginning of the LLI. 829 - */ 830 - llis_va[num_llis - 1].next = 831 - (dma_addr_t)((unsigned int)&(llis_bus[0])); 832 - } else { 833 - /* 834 - * On non-circular buffers, the final LLI terminates 835 - * the LLI. 836 - */ 837 - llis_va[num_llis - 1].next = 0; 838 - /* 839 - * The final LLI element shall also fire an interrupt 840 - */ 841 - llis_va[num_llis - 1].cctl |= PL080_CONTROL_TC_IRQ_EN; 842 - } 843 - 844 - /* Now store the channel register values */ 845 - txd->csrc = llis_va[0].src; 846 - txd->cdst = llis_va[0].dst; 847 - if (num_llis > 1) 848 - txd->clli = llis_va[0].next; 849 - else 850 - txd->clli = 0; 851 - 852 - txd->cctl = llis_va[0].cctl; 853 - /* ccfg will be set at physical channel allocation time */ 932 + /* The final LLI terminates the LLI. */ 933 + llis_va[num_llis - 1].lli = 0; 934 + /* The final LLI element shall also fire an interrupt. */ 935 + llis_va[num_llis - 1].cctl |= PL080_CONTROL_TC_IRQ_EN; 854 936 855 937 #ifdef VERBOSE_DEBUG 856 938 { ··· 829 969 830 970 for (i = 0; i < num_llis; i++) { 831 971 dev_vdbg(&pl08x->adev->dev, 832 - "lli %d @%p: csrc=%08x, cdst=%08x, cctl=%08x, clli=%08x\n", 972 + "lli %d @%p: csrc=0x%08x, cdst=0x%08x, cctl=0x%08x, clli=0x%08x\n", 833 973 i, 834 974 &llis_va[i], 835 975 llis_va[i].src, 836 976 llis_va[i].dst, 837 977 llis_va[i].cctl, 838 - llis_va[i].next 978 + llis_va[i].lli 839 979 ); 840 980 } 841 981 } ··· 848 988 static void pl08x_free_txd(struct pl08x_driver_data *pl08x, 849 989 struct pl08x_txd *txd) 850 990 { 851 - if (!txd) 852 - dev_err(&pl08x->adev->dev, 853 - "%s no descriptor to free\n", 854 - __func__); 855 - 856 991 /* Free the LLI */ 857 - dma_pool_free(pl08x->pool, txd->llis_va, 858 - txd->llis_bus); 992 + dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus); 859 993 860 994 pl08x->pool_ctr--; 861 995 ··· 862 1008 struct pl08x_txd *txdi = NULL; 863 1009 struct pl08x_txd *next; 864 1010 865 - if (!list_empty(&plchan->desc_list)) { 1011 + if (!list_empty(&plchan->pend_list)) { 866 1012 list_for_each_entry_safe(txdi, 867 - next, &plchan->desc_list, node) { 1013 + next, &plchan->pend_list, node) { 868 1014 list_del(&txdi->node); 869 1015 pl08x_free_txd(pl08x, txdi); 870 1016 } 871 - 872 1017 } 873 1018 } 874 1019 ··· 922 1069 return -EBUSY; 923 1070 } 924 1071 ch->signal = ret; 1072 + 1073 + /* Assign the flow control signal to this channel */ 1074 + if (txd->direction == DMA_TO_DEVICE) 1075 + txd->ccfg |= ch->signal << PL080_CONFIG_DST_SEL_SHIFT; 1076 + else if (txd->direction == DMA_FROM_DEVICE) 1077 + txd->ccfg |= ch->signal << PL080_CONFIG_SRC_SEL_SHIFT; 925 1078 } 926 1079 927 1080 dev_dbg(&pl08x->adev->dev, "allocated physical channel %d and signal %d for xfer on %s\n", ··· 935 1076 ch->signal, 936 1077 plchan->name); 937 1078 1079 + plchan->phychan_hold++; 938 1080 plchan->phychan = ch; 939 1081 940 1082 return 0; 941 1083 } 942 1084 1085 + static void release_phy_channel(struct pl08x_dma_chan *plchan) 1086 + { 1087 + struct pl08x_driver_data *pl08x = plchan->host; 1088 + 1089 + if ((plchan->phychan->signal >= 0) && pl08x->pd->put_signal) { 1090 + pl08x->pd->put_signal(plchan); 1091 + plchan->phychan->signal = -1; 1092 + } 1093 + pl08x_put_phy_channel(pl08x, plchan->phychan); 1094 + plchan->phychan = NULL; 1095 + } 1096 + 943 1097 static dma_cookie_t pl08x_tx_submit(struct dma_async_tx_descriptor *tx) 944 1098 { 945 1099 struct pl08x_dma_chan *plchan = to_pl08x_chan(tx->chan); 1100 + struct pl08x_txd *txd = to_pl08x_txd(tx); 1101 + unsigned long flags; 946 1102 947 - atomic_inc(&plchan->last_issued); 948 - tx->cookie = atomic_read(&plchan->last_issued); 949 - /* This unlock follows the lock in the prep() function */ 950 - spin_unlock_irqrestore(&plchan->lock, plchan->lockflags); 1103 + spin_lock_irqsave(&plchan->lock, flags); 1104 + 1105 + plchan->chan.cookie += 1; 1106 + if (plchan->chan.cookie < 0) 1107 + plchan->chan.cookie = 1; 1108 + tx->cookie = plchan->chan.cookie; 1109 + 1110 + /* Put this onto the pending list */ 1111 + list_add_tail(&txd->node, &plchan->pend_list); 1112 + 1113 + /* 1114 + * If there was no physical channel available for this memcpy, 1115 + * stack the request up and indicate that the channel is waiting 1116 + * for a free physical channel. 1117 + */ 1118 + if (!plchan->slave && !plchan->phychan) { 1119 + /* Do this memcpy whenever there is a channel ready */ 1120 + plchan->state = PL08X_CHAN_WAITING; 1121 + plchan->waiting = txd; 1122 + } else { 1123 + plchan->phychan_hold--; 1124 + } 1125 + 1126 + spin_unlock_irqrestore(&plchan->lock, flags); 951 1127 952 1128 return tx->cookie; 953 1129 } ··· 996 1102 } 997 1103 998 1104 /* 999 - * Code accessing dma_async_is_complete() in a tight loop 1000 - * may give problems - could schedule where indicated. 1001 - * If slaves are relying on interrupts to signal completion this 1002 - * function must not be called with interrupts disabled 1105 + * Code accessing dma_async_is_complete() in a tight loop may give problems. 1106 + * If slaves are relying on interrupts to signal completion this function 1107 + * must not be called with interrupts disabled. 1003 1108 */ 1004 1109 static enum dma_status 1005 1110 pl08x_dma_tx_status(struct dma_chan *chan, ··· 1011 1118 enum dma_status ret; 1012 1119 u32 bytesleft = 0; 1013 1120 1014 - last_used = atomic_read(&plchan->last_issued); 1121 + last_used = plchan->chan.cookie; 1015 1122 last_complete = plchan->lc; 1016 1123 1017 1124 ret = dma_async_is_complete(cookie, last_complete, last_used); ··· 1021 1128 } 1022 1129 1023 1130 /* 1024 - * schedule(); could be inserted here 1025 - */ 1026 - 1027 - /* 1028 1131 * This cookie not complete yet 1029 1132 */ 1030 - last_used = atomic_read(&plchan->last_issued); 1133 + last_used = plchan->chan.cookie; 1031 1134 last_complete = plchan->lc; 1032 1135 1033 1136 /* Get number of bytes left in the active transactions and queue */ ··· 1088 1199 }, 1089 1200 }; 1090 1201 1091 - static void dma_set_runtime_config(struct dma_chan *chan, 1092 - struct dma_slave_config *config) 1202 + static int dma_set_runtime_config(struct dma_chan *chan, 1203 + struct dma_slave_config *config) 1093 1204 { 1094 1205 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1095 1206 struct pl08x_driver_data *pl08x = plchan->host; 1096 1207 struct pl08x_channel_data *cd = plchan->cd; 1097 1208 enum dma_slave_buswidth addr_width; 1209 + dma_addr_t addr; 1098 1210 u32 maxburst; 1099 1211 u32 cctl = 0; 1100 - /* Mask out all except src and dst channel */ 1101 - u32 ccfg = cd->ccfg & 0x000003DEU; 1102 - int i = 0; 1212 + int i; 1213 + 1214 + if (!plchan->slave) 1215 + return -EINVAL; 1103 1216 1104 1217 /* Transfer direction */ 1105 1218 plchan->runtime_direction = config->direction; 1106 1219 if (config->direction == DMA_TO_DEVICE) { 1107 - plchan->runtime_addr = config->dst_addr; 1108 - cctl |= PL080_CONTROL_SRC_INCR; 1109 - ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1220 + addr = config->dst_addr; 1110 1221 addr_width = config->dst_addr_width; 1111 1222 maxburst = config->dst_maxburst; 1112 1223 } else if (config->direction == DMA_FROM_DEVICE) { 1113 - plchan->runtime_addr = config->src_addr; 1114 - cctl |= PL080_CONTROL_DST_INCR; 1115 - ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1224 + addr = config->src_addr; 1116 1225 addr_width = config->src_addr_width; 1117 1226 maxburst = config->src_maxburst; 1118 1227 } else { 1119 1228 dev_err(&pl08x->adev->dev, 1120 1229 "bad runtime_config: alien transfer direction\n"); 1121 - return; 1230 + return -EINVAL; 1122 1231 } 1123 1232 1124 1233 switch (addr_width) { ··· 1135 1248 default: 1136 1249 dev_err(&pl08x->adev->dev, 1137 1250 "bad runtime_config: alien address width\n"); 1138 - return; 1251 + return -EINVAL; 1139 1252 } 1140 1253 1141 1254 /* 1142 1255 * Now decide on a maxburst: 1143 - * If this channel will only request single transfers, set 1144 - * this down to ONE element. 1256 + * If this channel will only request single transfers, set this 1257 + * down to ONE element. Also select one element if no maxburst 1258 + * is specified. 1145 1259 */ 1146 - if (plchan->cd->single) { 1260 + if (plchan->cd->single || maxburst == 0) { 1147 1261 cctl |= (PL080_BSIZE_1 << PL080_CONTROL_SB_SIZE_SHIFT) | 1148 1262 (PL080_BSIZE_1 << PL080_CONTROL_DB_SIZE_SHIFT); 1149 1263 } else { 1150 - while (i < ARRAY_SIZE(burst_sizes)) { 1264 + for (i = 0; i < ARRAY_SIZE(burst_sizes); i++) 1151 1265 if (burst_sizes[i].burstwords <= maxburst) 1152 1266 break; 1153 - i++; 1154 - } 1155 1267 cctl |= burst_sizes[i].reg; 1156 1268 } 1157 1269 1158 - /* Access the cell in privileged mode, non-bufferable, non-cacheable */ 1159 - cctl &= ~PL080_CONTROL_PROT_MASK; 1160 - cctl |= PL080_CONTROL_PROT_SYS; 1270 + plchan->runtime_addr = addr; 1161 1271 1162 1272 /* Modify the default channel data to fit PrimeCell request */ 1163 1273 cd->cctl = cctl; 1164 - cd->ccfg = ccfg; 1165 1274 1166 1275 dev_dbg(&pl08x->adev->dev, 1167 1276 "configured channel %s (%s) for %s, data width %d, " 1168 - "maxburst %d words, LE, CCTL=%08x, CCFG=%08x\n", 1277 + "maxburst %d words, LE, CCTL=0x%08x\n", 1169 1278 dma_chan_name(chan), plchan->name, 1170 1279 (config->direction == DMA_FROM_DEVICE) ? "RX" : "TX", 1171 1280 addr_width, 1172 1281 maxburst, 1173 - cctl, ccfg); 1282 + cctl); 1283 + 1284 + return 0; 1174 1285 } 1175 1286 1176 1287 /* ··· 1178 1293 static void pl08x_issue_pending(struct dma_chan *chan) 1179 1294 { 1180 1295 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1181 - struct pl08x_driver_data *pl08x = plchan->host; 1182 1296 unsigned long flags; 1183 1297 1184 1298 spin_lock_irqsave(&plchan->lock, flags); 1185 - /* Something is already active */ 1186 - if (plchan->at) { 1187 - spin_unlock_irqrestore(&plchan->lock, flags); 1188 - return; 1299 + /* Something is already active, or we're waiting for a channel... */ 1300 + if (plchan->at || plchan->state == PL08X_CHAN_WAITING) { 1301 + spin_unlock_irqrestore(&plchan->lock, flags); 1302 + return; 1189 1303 } 1190 1304 1191 - /* Didn't get a physical channel so waiting for it ... */ 1192 - if (plchan->state == PL08X_CHAN_WAITING) 1193 - return; 1194 - 1195 1305 /* Take the first element in the queue and execute it */ 1196 - if (!list_empty(&plchan->desc_list)) { 1306 + if (!list_empty(&plchan->pend_list)) { 1197 1307 struct pl08x_txd *next; 1198 1308 1199 - next = list_first_entry(&plchan->desc_list, 1309 + next = list_first_entry(&plchan->pend_list, 1200 1310 struct pl08x_txd, 1201 1311 node); 1202 1312 list_del(&next->node); 1203 - plchan->at = next; 1204 1313 plchan->state = PL08X_CHAN_RUNNING; 1205 1314 1206 - /* Configure the physical channel for the active txd */ 1207 - pl08x_config_phychan_for_txd(plchan); 1208 - pl08x_set_cregs(pl08x, plchan->phychan); 1209 - pl08x_enable_phy_chan(pl08x, plchan->phychan); 1315 + pl08x_start_txd(plchan, next); 1210 1316 } 1211 1317 1212 1318 spin_unlock_irqrestore(&plchan->lock, flags); ··· 1206 1330 static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan, 1207 1331 struct pl08x_txd *txd) 1208 1332 { 1209 - int num_llis; 1210 1333 struct pl08x_driver_data *pl08x = plchan->host; 1211 - int ret; 1334 + unsigned long flags; 1335 + int num_llis, ret; 1212 1336 1213 1337 num_llis = pl08x_fill_llis_for_desc(pl08x, txd); 1214 - 1215 - if (!num_llis) 1338 + if (!num_llis) { 1339 + kfree(txd); 1216 1340 return -EINVAL; 1341 + } 1217 1342 1218 - spin_lock_irqsave(&plchan->lock, plchan->lockflags); 1219 - 1220 - /* 1221 - * If this device is not using a circular buffer then 1222 - * queue this new descriptor for transfer. 1223 - * The descriptor for a circular buffer continues 1224 - * to be used until the channel is freed. 1225 - */ 1226 - if (txd->cd->circular_buffer) 1227 - dev_err(&pl08x->adev->dev, 1228 - "%s attempting to queue a circular buffer\n", 1229 - __func__); 1230 - else 1231 - list_add_tail(&txd->node, 1232 - &plchan->desc_list); 1343 + spin_lock_irqsave(&plchan->lock, flags); 1233 1344 1234 1345 /* 1235 1346 * See if we already have a physical channel allocated, ··· 1225 1362 ret = prep_phy_channel(plchan, txd); 1226 1363 if (ret) { 1227 1364 /* 1228 - * No physical channel available, we will 1229 - * stack up the memcpy channels until there is a channel 1230 - * available to handle it whereas slave transfers may 1231 - * have been denied due to platform channel muxing restrictions 1232 - * and since there is no guarantee that this will ever be 1233 - * resolved, and since the signal must be aquired AFTER 1234 - * aquiring the physical channel, we will let them be NACK:ed 1235 - * with -EBUSY here. The drivers can alway retry the prep() 1236 - * call if they are eager on doing this using DMA. 1365 + * No physical channel was available. 1366 + * 1367 + * memcpy transfers can be sorted out at submission time. 1368 + * 1369 + * Slave transfers may have been denied due to platform 1370 + * channel muxing restrictions. Since there is no guarantee 1371 + * that this will ever be resolved, and the signal must be 1372 + * acquired AFTER acquiring the physical channel, we will let 1373 + * them be NACK:ed with -EBUSY here. The drivers can retry 1374 + * the prep() call if they are eager on doing this using DMA. 1237 1375 */ 1238 1376 if (plchan->slave) { 1239 1377 pl08x_free_txd_list(pl08x, plchan); 1240 - spin_unlock_irqrestore(&plchan->lock, plchan->lockflags); 1378 + pl08x_free_txd(pl08x, txd); 1379 + spin_unlock_irqrestore(&plchan->lock, flags); 1241 1380 return -EBUSY; 1242 1381 } 1243 - /* Do this memcpy whenever there is a channel ready */ 1244 - plchan->state = PL08X_CHAN_WAITING; 1245 - plchan->waiting = txd; 1246 1382 } else 1247 1383 /* 1248 - * Else we're all set, paused and ready to roll, 1249 - * status will switch to PL08X_CHAN_RUNNING when 1250 - * we call issue_pending(). If there is something 1251 - * running on the channel already we don't change 1252 - * its state. 1384 + * Else we're all set, paused and ready to roll, status 1385 + * will switch to PL08X_CHAN_RUNNING when we call 1386 + * issue_pending(). If there is something running on the 1387 + * channel already we don't change its state. 1253 1388 */ 1254 1389 if (plchan->state == PL08X_CHAN_IDLE) 1255 1390 plchan->state = PL08X_CHAN_PAUSED; 1256 1391 1257 - /* 1258 - * Notice that we leave plchan->lock locked on purpose: 1259 - * it will be unlocked in the subsequent tx_submit() 1260 - * call. This is a consequence of the current API. 1261 - */ 1392 + spin_unlock_irqrestore(&plchan->lock, flags); 1262 1393 1263 1394 return 0; 1395 + } 1396 + 1397 + /* 1398 + * Given the source and destination available bus masks, select which 1399 + * will be routed to each port. We try to have source and destination 1400 + * on separate ports, but always respect the allowable settings. 1401 + */ 1402 + static u32 pl08x_select_bus(struct pl08x_driver_data *pl08x, u8 src, u8 dst) 1403 + { 1404 + u32 cctl = 0; 1405 + 1406 + if (!(dst & PL08X_AHB1) || ((dst & PL08X_AHB2) && (src & PL08X_AHB1))) 1407 + cctl |= PL080_CONTROL_DST_AHB2; 1408 + if (!(src & PL08X_AHB1) || ((src & PL08X_AHB2) && !(dst & PL08X_AHB2))) 1409 + cctl |= PL080_CONTROL_SRC_AHB2; 1410 + 1411 + return cctl; 1412 + } 1413 + 1414 + static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan, 1415 + unsigned long flags) 1416 + { 1417 + struct pl08x_txd *txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); 1418 + 1419 + if (txd) { 1420 + dma_async_tx_descriptor_init(&txd->tx, &plchan->chan); 1421 + txd->tx.flags = flags; 1422 + txd->tx.tx_submit = pl08x_tx_submit; 1423 + INIT_LIST_HEAD(&txd->node); 1424 + 1425 + /* Always enable error and terminal interrupts */ 1426 + txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK | 1427 + PL080_CONFIG_TC_IRQ_MASK; 1428 + } 1429 + return txd; 1264 1430 } 1265 1431 1266 1432 /* ··· 1304 1412 struct pl08x_txd *txd; 1305 1413 int ret; 1306 1414 1307 - txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); 1415 + txd = pl08x_get_txd(plchan, flags); 1308 1416 if (!txd) { 1309 1417 dev_err(&pl08x->adev->dev, 1310 1418 "%s no memory for descriptor\n", __func__); 1311 1419 return NULL; 1312 1420 } 1313 1421 1314 - dma_async_tx_descriptor_init(&txd->tx, chan); 1315 1422 txd->direction = DMA_NONE; 1316 - txd->srcbus.addr = src; 1317 - txd->dstbus.addr = dest; 1318 - 1319 - /* Set platform data for m2m */ 1320 - txd->cd = &pl08x->pd->memcpy_channel; 1321 - /* Both to be incremented or the code will break */ 1322 - txd->cd->cctl |= PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR; 1323 - txd->tx.tx_submit = pl08x_tx_submit; 1324 - txd->tx.callback = NULL; 1325 - txd->tx.callback_param = NULL; 1423 + txd->src_addr = src; 1424 + txd->dst_addr = dest; 1326 1425 txd->len = len; 1327 1426 1328 - INIT_LIST_HEAD(&txd->node); 1427 + /* Set platform data for m2m */ 1428 + txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1429 + txd->cctl = pl08x->pd->memcpy_channel.cctl & 1430 + ~(PL080_CONTROL_DST_AHB2 | PL080_CONTROL_SRC_AHB2); 1431 + 1432 + /* Both to be incremented or the code will break */ 1433 + txd->cctl |= PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR; 1434 + 1435 + if (pl08x->vd->dualmaster) 1436 + txd->cctl |= pl08x_select_bus(pl08x, 1437 + pl08x->mem_buses, pl08x->mem_buses); 1438 + 1329 1439 ret = pl08x_prep_channel_resources(plchan, txd); 1330 1440 if (ret) 1331 1441 return NULL; 1332 - /* 1333 - * NB: the channel lock is held at this point so tx_submit() 1334 - * must be called in direct succession. 1335 - */ 1336 1442 1337 1443 return &txd->tx; 1338 1444 } 1339 1445 1340 - struct dma_async_tx_descriptor *pl08x_prep_slave_sg( 1446 + static struct dma_async_tx_descriptor *pl08x_prep_slave_sg( 1341 1447 struct dma_chan *chan, struct scatterlist *sgl, 1342 1448 unsigned int sg_len, enum dma_data_direction direction, 1343 1449 unsigned long flags) ··· 1343 1453 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1344 1454 struct pl08x_driver_data *pl08x = plchan->host; 1345 1455 struct pl08x_txd *txd; 1456 + u8 src_buses, dst_buses; 1346 1457 int ret; 1347 1458 1348 1459 /* ··· 1358 1467 dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n", 1359 1468 __func__, sgl->length, plchan->name); 1360 1469 1361 - txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); 1470 + txd = pl08x_get_txd(plchan, flags); 1362 1471 if (!txd) { 1363 1472 dev_err(&pl08x->adev->dev, "%s no txd\n", __func__); 1364 1473 return NULL; 1365 1474 } 1366 - 1367 - dma_async_tx_descriptor_init(&txd->tx, chan); 1368 1475 1369 1476 if (direction != plchan->runtime_direction) 1370 1477 dev_err(&pl08x->adev->dev, "%s DMA setup does not match " ··· 1375 1486 * channel target address dynamically at runtime. 1376 1487 */ 1377 1488 txd->direction = direction; 1489 + txd->len = sgl->length; 1490 + 1491 + txd->cctl = plchan->cd->cctl & 1492 + ~(PL080_CONTROL_SRC_AHB2 | PL080_CONTROL_DST_AHB2 | 1493 + PL080_CONTROL_SRC_INCR | PL080_CONTROL_DST_INCR | 1494 + PL080_CONTROL_PROT_MASK); 1495 + 1496 + /* Access the cell in privileged mode, non-bufferable, non-cacheable */ 1497 + txd->cctl |= PL080_CONTROL_PROT_SYS; 1498 + 1378 1499 if (direction == DMA_TO_DEVICE) { 1379 - txd->srcbus.addr = sgl->dma_address; 1500 + txd->ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1501 + txd->cctl |= PL080_CONTROL_SRC_INCR; 1502 + txd->src_addr = sgl->dma_address; 1380 1503 if (plchan->runtime_addr) 1381 - txd->dstbus.addr = plchan->runtime_addr; 1504 + txd->dst_addr = plchan->runtime_addr; 1382 1505 else 1383 - txd->dstbus.addr = plchan->cd->addr; 1506 + txd->dst_addr = plchan->cd->addr; 1507 + src_buses = pl08x->mem_buses; 1508 + dst_buses = plchan->cd->periph_buses; 1384 1509 } else if (direction == DMA_FROM_DEVICE) { 1510 + txd->ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1511 + txd->cctl |= PL080_CONTROL_DST_INCR; 1385 1512 if (plchan->runtime_addr) 1386 - txd->srcbus.addr = plchan->runtime_addr; 1513 + txd->src_addr = plchan->runtime_addr; 1387 1514 else 1388 - txd->srcbus.addr = plchan->cd->addr; 1389 - txd->dstbus.addr = sgl->dma_address; 1515 + txd->src_addr = plchan->cd->addr; 1516 + txd->dst_addr = sgl->dma_address; 1517 + src_buses = plchan->cd->periph_buses; 1518 + dst_buses = pl08x->mem_buses; 1390 1519 } else { 1391 1520 dev_err(&pl08x->adev->dev, 1392 1521 "%s direction unsupported\n", __func__); 1393 1522 return NULL; 1394 1523 } 1395 - txd->cd = plchan->cd; 1396 - txd->tx.tx_submit = pl08x_tx_submit; 1397 - txd->tx.callback = NULL; 1398 - txd->tx.callback_param = NULL; 1399 - txd->len = sgl->length; 1400 - INIT_LIST_HEAD(&txd->node); 1524 + 1525 + txd->cctl |= pl08x_select_bus(pl08x, src_buses, dst_buses); 1401 1526 1402 1527 ret = pl08x_prep_channel_resources(plchan, txd); 1403 1528 if (ret) 1404 1529 return NULL; 1405 - /* 1406 - * NB: the channel lock is held at this point so tx_submit() 1407 - * must be called in direct succession. 1408 - */ 1409 1530 1410 1531 return &txd->tx; 1411 1532 } ··· 1430 1531 1431 1532 /* Controls applicable to inactive channels */ 1432 1533 if (cmd == DMA_SLAVE_CONFIG) { 1433 - dma_set_runtime_config(chan, 1434 - (struct dma_slave_config *) 1435 - arg); 1436 - return 0; 1534 + return dma_set_runtime_config(chan, 1535 + (struct dma_slave_config *)arg); 1437 1536 } 1438 1537 1439 1538 /* ··· 1455 1558 * Mark physical channel as free and free any slave 1456 1559 * signal 1457 1560 */ 1458 - if ((plchan->phychan->signal >= 0) && 1459 - pl08x->pd->put_signal) { 1460 - pl08x->pd->put_signal(plchan); 1461 - plchan->phychan->signal = -1; 1462 - } 1463 - pl08x_put_phy_channel(pl08x, plchan->phychan); 1464 - plchan->phychan = NULL; 1561 + release_phy_channel(plchan); 1465 1562 } 1466 - /* Stop any pending tasklet */ 1467 - tasklet_disable(&plchan->tasklet); 1468 1563 /* Dequeue jobs and free LLIs */ 1469 1564 if (plchan->at) { 1470 1565 pl08x_free_txd(pl08x, plchan->at); ··· 1498 1609 1499 1610 /* 1500 1611 * Just check that the device is there and active 1501 - * TODO: turn this bit on/off depending on the number of 1502 - * physical channels actually used, if it is zero... well 1503 - * shut it off. That will save some power. Cut the clock 1504 - * at the same time. 1612 + * TODO: turn this bit on/off depending on the number of physical channels 1613 + * actually used, if it is zero... well shut it off. That will save some 1614 + * power. Cut the clock at the same time. 1505 1615 */ 1506 1616 static void pl08x_ensure_on(struct pl08x_driver_data *pl08x) 1507 1617 { ··· 1508 1620 1509 1621 val = readl(pl08x->base + PL080_CONFIG); 1510 1622 val &= ~(PL080_CONFIG_M2_BE | PL080_CONFIG_M1_BE | PL080_CONFIG_ENABLE); 1511 - /* We implictly clear bit 1 and that means little-endian mode */ 1623 + /* We implicitly clear bit 1 and that means little-endian mode */ 1512 1624 val |= PL080_CONFIG_ENABLE; 1513 1625 writel(val, pl08x->base + PL080_CONFIG); 1626 + } 1627 + 1628 + static void pl08x_unmap_buffers(struct pl08x_txd *txd) 1629 + { 1630 + struct device *dev = txd->tx.chan->device->dev; 1631 + 1632 + if (!(txd->tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) { 1633 + if (txd->tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE) 1634 + dma_unmap_single(dev, txd->src_addr, txd->len, 1635 + DMA_TO_DEVICE); 1636 + else 1637 + dma_unmap_page(dev, txd->src_addr, txd->len, 1638 + DMA_TO_DEVICE); 1639 + } 1640 + if (!(txd->tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 1641 + if (txd->tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE) 1642 + dma_unmap_single(dev, txd->dst_addr, txd->len, 1643 + DMA_FROM_DEVICE); 1644 + else 1645 + dma_unmap_page(dev, txd->dst_addr, txd->len, 1646 + DMA_FROM_DEVICE); 1647 + } 1514 1648 } 1515 1649 1516 1650 static void pl08x_tasklet(unsigned long data) 1517 1651 { 1518 1652 struct pl08x_dma_chan *plchan = (struct pl08x_dma_chan *) data; 1519 - struct pl08x_phy_chan *phychan = plchan->phychan; 1520 1653 struct pl08x_driver_data *pl08x = plchan->host; 1654 + struct pl08x_txd *txd; 1655 + unsigned long flags; 1521 1656 1522 - if (!plchan) 1523 - BUG(); 1657 + spin_lock_irqsave(&plchan->lock, flags); 1524 1658 1525 - spin_lock(&plchan->lock); 1659 + txd = plchan->at; 1660 + plchan->at = NULL; 1526 1661 1527 - if (plchan->at) { 1528 - dma_async_tx_callback callback = 1529 - plchan->at->tx.callback; 1530 - void *callback_param = 1531 - plchan->at->tx.callback_param; 1532 - 1533 - /* 1534 - * Update last completed 1535 - */ 1536 - plchan->lc = 1537 - (plchan->at->tx.cookie); 1538 - 1539 - /* 1540 - * Callback to signal completion 1541 - */ 1542 - if (callback) 1543 - callback(callback_param); 1544 - 1545 - /* 1546 - * Device callbacks should NOT clear 1547 - * the current transaction on the channel 1548 - * Linus: sometimes they should? 1549 - */ 1550 - if (!plchan->at) 1551 - BUG(); 1552 - 1553 - /* 1554 - * Free the descriptor if it's not for a device 1555 - * using a circular buffer 1556 - */ 1557 - if (!plchan->at->cd->circular_buffer) { 1558 - pl08x_free_txd(pl08x, plchan->at); 1559 - plchan->at = NULL; 1560 - } 1561 - /* 1562 - * else descriptor for circular 1563 - * buffers only freed when 1564 - * client has disabled dma 1565 - */ 1662 + if (txd) { 1663 + /* Update last completed */ 1664 + plchan->lc = txd->tx.cookie; 1566 1665 } 1567 - /* 1568 - * If a new descriptor is queued, set it up 1569 - * plchan->at is NULL here 1570 - */ 1571 - if (!list_empty(&plchan->desc_list)) { 1666 + 1667 + /* If a new descriptor is queued, set it up plchan->at is NULL here */ 1668 + if (!list_empty(&plchan->pend_list)) { 1572 1669 struct pl08x_txd *next; 1573 1670 1574 - next = list_first_entry(&plchan->desc_list, 1671 + next = list_first_entry(&plchan->pend_list, 1575 1672 struct pl08x_txd, 1576 1673 node); 1577 1674 list_del(&next->node); 1578 - plchan->at = next; 1579 - /* Configure the physical channel for the next txd */ 1580 - pl08x_config_phychan_for_txd(plchan); 1581 - pl08x_set_cregs(pl08x, plchan->phychan); 1582 - pl08x_enable_phy_chan(pl08x, plchan->phychan); 1675 + 1676 + pl08x_start_txd(plchan, next); 1677 + } else if (plchan->phychan_hold) { 1678 + /* 1679 + * This channel is still in use - we have a new txd being 1680 + * prepared and will soon be queued. Don't give up the 1681 + * physical channel. 1682 + */ 1583 1683 } else { 1584 1684 struct pl08x_dma_chan *waiting = NULL; 1585 1685 ··· 1575 1699 * No more jobs, so free up the physical channel 1576 1700 * Free any allocated signal on slave transfers too 1577 1701 */ 1578 - if ((phychan->signal >= 0) && pl08x->pd->put_signal) { 1579 - pl08x->pd->put_signal(plchan); 1580 - phychan->signal = -1; 1581 - } 1582 - pl08x_put_phy_channel(pl08x, phychan); 1583 - plchan->phychan = NULL; 1702 + release_phy_channel(plchan); 1584 1703 plchan->state = PL08X_CHAN_IDLE; 1585 1704 1586 1705 /* 1587 - * And NOW before anyone else can grab that free:d 1588 - * up physical channel, see if there is some memcpy 1589 - * pending that seriously needs to start because of 1590 - * being stacked up while we were choking the 1591 - * physical channels with data. 1706 + * And NOW before anyone else can grab that free:d up 1707 + * physical channel, see if there is some memcpy pending 1708 + * that seriously needs to start because of being stacked 1709 + * up while we were choking the physical channels with data. 1592 1710 */ 1593 1711 list_for_each_entry(waiting, &pl08x->memcpy.channels, 1594 1712 chan.device_node) { ··· 1594 1724 ret = prep_phy_channel(waiting, 1595 1725 waiting->waiting); 1596 1726 BUG_ON(ret); 1727 + waiting->phychan_hold--; 1597 1728 waiting->state = PL08X_CHAN_RUNNING; 1598 1729 waiting->waiting = NULL; 1599 1730 pl08x_issue_pending(&waiting->chan); ··· 1603 1732 } 1604 1733 } 1605 1734 1606 - spin_unlock(&plchan->lock); 1735 + spin_unlock_irqrestore(&plchan->lock, flags); 1736 + 1737 + if (txd) { 1738 + dma_async_tx_callback callback = txd->tx.callback; 1739 + void *callback_param = txd->tx.callback_param; 1740 + 1741 + /* Don't try to unmap buffers on slave channels */ 1742 + if (!plchan->slave) 1743 + pl08x_unmap_buffers(txd); 1744 + 1745 + /* Free the descriptor */ 1746 + spin_lock_irqsave(&plchan->lock, flags); 1747 + pl08x_free_txd(pl08x, txd); 1748 + spin_unlock_irqrestore(&plchan->lock, flags); 1749 + 1750 + /* Callback to signal completion */ 1751 + if (callback) 1752 + callback(callback_param); 1753 + } 1607 1754 } 1608 1755 1609 1756 static irqreturn_t pl08x_irq(int irq, void *dev) ··· 1633 1744 1634 1745 val = readl(pl08x->base + PL080_ERR_STATUS); 1635 1746 if (val) { 1636 - /* 1637 - * An error interrupt (on one or more channels) 1638 - */ 1747 + /* An error interrupt (on one or more channels) */ 1639 1748 dev_err(&pl08x->adev->dev, 1640 1749 "%s error interrupt, register value 0x%08x\n", 1641 1750 __func__, val); ··· 1657 1770 mask |= (1 << i); 1658 1771 } 1659 1772 } 1660 - /* 1661 - * Clear only the terminal interrupts on channels we processed 1662 - */ 1773 + /* Clear only the terminal interrupts on channels we processed */ 1663 1774 writel(mask, pl08x->base + PL080_TC_CLEAR); 1664 1775 1665 1776 return mask ? IRQ_HANDLED : IRQ_NONE; ··· 1676 1791 int i; 1677 1792 1678 1793 INIT_LIST_HEAD(&dmadev->channels); 1794 + 1679 1795 /* 1680 1796 * Register as many many memcpy as we have physical channels, 1681 1797 * we won't always be able to use all but the code will have ··· 1705 1819 return -ENOMEM; 1706 1820 } 1707 1821 } 1822 + if (chan->cd->circular_buffer) { 1823 + dev_err(&pl08x->adev->dev, 1824 + "channel %s: circular buffers not supported\n", 1825 + chan->name); 1826 + kfree(chan); 1827 + continue; 1828 + } 1708 1829 dev_info(&pl08x->adev->dev, 1709 1830 "initialize virtual channel \"%s\"\n", 1710 1831 chan->name); 1711 1832 1712 1833 chan->chan.device = dmadev; 1713 - atomic_set(&chan->last_issued, 0); 1714 - chan->lc = atomic_read(&chan->last_issued); 1834 + chan->chan.cookie = 0; 1835 + chan->lc = 0; 1715 1836 1716 1837 spin_lock_init(&chan->lock); 1717 - INIT_LIST_HEAD(&chan->desc_list); 1838 + INIT_LIST_HEAD(&chan->pend_list); 1718 1839 tasklet_init(&chan->tasklet, pl08x_tasklet, 1719 1840 (unsigned long) chan); 1720 1841 ··· 1791 1898 seq_printf(s, "CHANNEL:\tSTATE:\n"); 1792 1899 seq_printf(s, "--------\t------\n"); 1793 1900 list_for_each_entry(chan, &pl08x->memcpy.channels, chan.device_node) { 1794 - seq_printf(s, "%s\t\t\%s\n", chan->name, 1901 + seq_printf(s, "%s\t\t%s\n", chan->name, 1795 1902 pl08x_state_str(chan->state)); 1796 1903 } 1797 1904 ··· 1799 1906 seq_printf(s, "CHANNEL:\tSTATE:\n"); 1800 1907 seq_printf(s, "--------\t------\n"); 1801 1908 list_for_each_entry(chan, &pl08x->slave.channels, chan.device_node) { 1802 - seq_printf(s, "%s\t\t\%s\n", chan->name, 1909 + seq_printf(s, "%s\t\t%s\n", chan->name, 1803 1910 pl08x_state_str(chan->state)); 1804 1911 } 1805 1912 ··· 1835 1942 static int pl08x_probe(struct amba_device *adev, struct amba_id *id) 1836 1943 { 1837 1944 struct pl08x_driver_data *pl08x; 1838 - struct vendor_data *vd = id->data; 1945 + const struct vendor_data *vd = id->data; 1839 1946 int ret = 0; 1840 1947 int i; 1841 1948 ··· 1883 1990 pl08x->adev = adev; 1884 1991 pl08x->vd = vd; 1885 1992 1993 + /* By default, AHB1 only. If dualmaster, from platform */ 1994 + pl08x->lli_buses = PL08X_AHB1; 1995 + pl08x->mem_buses = PL08X_AHB1; 1996 + if (pl08x->vd->dualmaster) { 1997 + pl08x->lli_buses = pl08x->pd->lli_buses; 1998 + pl08x->mem_buses = pl08x->pd->mem_buses; 1999 + } 2000 + 1886 2001 /* A DMA memory pool for LLIs, align on 1-byte boundary */ 1887 2002 pl08x->pool = dma_pool_create(DRIVER_NAME, &pl08x->adev->dev, 1888 2003 PL08X_LLI_TSFR_SIZE, PL08X_ALIGN, 0); ··· 1910 2009 /* Turn on the PL08x */ 1911 2010 pl08x_ensure_on(pl08x); 1912 2011 1913 - /* 1914 - * Attach the interrupt handler 1915 - */ 2012 + /* Attach the interrupt handler */ 1916 2013 writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR); 1917 2014 writel(0x000000FF, pl08x->base + PL080_TC_CLEAR); 1918 2015 1919 2016 ret = request_irq(adev->irq[0], pl08x_irq, IRQF_DISABLED, 1920 - vd->name, pl08x); 2017 + DRIVER_NAME, pl08x); 1921 2018 if (ret) { 1922 2019 dev_err(&adev->dev, "%s failed to request interrupt %d\n", 1923 2020 __func__, adev->irq[0]); ··· 1986 2087 1987 2088 amba_set_drvdata(adev, pl08x); 1988 2089 init_pl08x_debugfs(pl08x); 1989 - dev_info(&pl08x->adev->dev, "ARM(R) %s DMA block initialized @%08x\n", 1990 - vd->name, adev->res.start); 2090 + dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n", 2091 + amba_part(adev), amba_rev(adev), 2092 + (unsigned long long)adev->res.start, adev->irq[0]); 1991 2093 return 0; 1992 2094 1993 2095 out_no_slave_reg: ··· 2015 2115 2016 2116 /* PL080 has 8 channels and the PL080 have just 2 */ 2017 2117 static struct vendor_data vendor_pl080 = { 2018 - .name = "PL080", 2019 2118 .channels = 8, 2020 2119 .dualmaster = true, 2021 2120 }; 2022 2121 2023 2122 static struct vendor_data vendor_pl081 = { 2024 - .name = "PL081", 2025 2123 .channels = 2, 2026 2124 .dualmaster = false, 2027 2125 }; ··· 2058 2160 retval = amba_driver_register(&pl08x_amba_driver); 2059 2161 if (retval) 2060 2162 printk(KERN_WARNING DRIVER_NAME 2061 - "failed to register as an amba device (%d)\n", 2163 + "failed to register as an AMBA device (%d)\n", 2062 2164 retval); 2063 2165 return retval; 2064 2166 }
+9 -10
drivers/dma/at_hdmac.c
··· 253 253 /* move myself to free_list */ 254 254 list_move(&desc->desc_node, &atchan->free_list); 255 255 256 - /* unmap dma addresses */ 256 + /* unmap dma addresses (not on slave channels) */ 257 257 if (!atchan->chan_common.private) { 258 258 struct device *parent = chan2parent(&atchan->chan_common); 259 259 if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) { ··· 583 583 desc->lli.ctrlb = ctrlb; 584 584 585 585 desc->txd.cookie = 0; 586 - async_tx_ack(&desc->txd); 587 586 588 587 if (!first) { 589 588 first = desc; ··· 603 604 /* set end-of-link to the last link descriptor of list*/ 604 605 set_desc_eol(desc); 605 606 606 - desc->txd.flags = flags; /* client is in control of this ack */ 607 + first->txd.flags = flags; /* client is in control of this ack */ 607 608 608 609 return &first->txd; 609 610 ··· 669 670 if (!desc) 670 671 goto err_desc_get; 671 672 672 - mem = sg_phys(sg); 673 + mem = sg_dma_address(sg); 673 674 len = sg_dma_len(sg); 674 675 mem_width = 2; 675 676 if (unlikely(mem & 3 || len & 3)) ··· 711 712 if (!desc) 712 713 goto err_desc_get; 713 714 714 - mem = sg_phys(sg); 715 + mem = sg_dma_address(sg); 715 716 len = sg_dma_len(sg); 716 717 mem_width = 2; 717 718 if (unlikely(mem & 3 || len & 3)) ··· 748 749 first->txd.cookie = -EBUSY; 749 750 first->len = total_len; 750 751 751 - /* last link descriptor of list is responsible of flags */ 752 - prev->txd.flags = flags; /* client is in control of this ack */ 752 + /* first link descriptor of list is responsible of flags */ 753 + first->txd.flags = flags; /* client is in control of this ack */ 753 754 754 755 return &first->txd; 755 756 ··· 853 854 854 855 dev_vdbg(chan2dev(chan), "issue_pending\n"); 855 856 857 + spin_lock_bh(&atchan->lock); 856 858 if (!atc_chan_is_enabled(atchan)) { 857 - spin_lock_bh(&atchan->lock); 858 859 atc_advance_work(atchan); 859 - spin_unlock_bh(&atchan->lock); 860 860 } 861 + spin_unlock_bh(&atchan->lock); 861 862 } 862 863 863 864 /** ··· 1209 1210 { 1210 1211 return platform_driver_probe(&at_dma_driver, at_dma_probe); 1211 1212 } 1212 - module_init(at_dma_init); 1213 + subsys_initcall(at_dma_init); 1213 1214 1214 1215 static void __exit at_dma_exit(void) 1215 1216 {
+3 -1
drivers/dma/fsldma.c
··· 1 1 /* 2 2 * Freescale MPC85xx, MPC83xx DMA Engine support 3 3 * 4 - * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved. 4 + * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. All rights reserved. 5 5 * 6 6 * Author: 7 7 * Zhang Wei <wei.zhang@freescale.com>, Jul 2007 ··· 1323 1323 fdev->common.device_prep_slave_sg = fsl_dma_prep_slave_sg; 1324 1324 fdev->common.device_control = fsl_dma_device_control; 1325 1325 fdev->common.dev = &op->dev; 1326 + 1327 + dma_set_mask(&(op->dev), DMA_BIT_MASK(36)); 1326 1328 1327 1329 dev_set_drvdata(&op->dev, fdev); 1328 1330
+24 -9
drivers/dma/intel_mid_dma.c
··· 664 664 /*calculate CTL_LO*/ 665 665 ctl_lo.ctl_lo = 0; 666 666 ctl_lo.ctlx.int_en = 1; 667 - ctl_lo.ctlx.dst_tr_width = mids->dma_slave.dst_addr_width; 668 - ctl_lo.ctlx.src_tr_width = mids->dma_slave.src_addr_width; 669 667 ctl_lo.ctlx.dst_msize = mids->dma_slave.src_maxburst; 670 668 ctl_lo.ctlx.src_msize = mids->dma_slave.dst_maxburst; 669 + 670 + /* 671 + * Here we need some translation from "enum dma_slave_buswidth" 672 + * to the format for our dma controller 673 + * standard intel_mid_dmac's format 674 + * 1 Byte 0b000 675 + * 2 Bytes 0b001 676 + * 4 Bytes 0b010 677 + */ 678 + ctl_lo.ctlx.dst_tr_width = mids->dma_slave.dst_addr_width / 2; 679 + ctl_lo.ctlx.src_tr_width = mids->dma_slave.src_addr_width / 2; 671 680 672 681 if (mids->cfg_mode == LNW_DMA_MEM_TO_MEM) { 673 682 ctl_lo.ctlx.tt_fc = 0; ··· 755 746 BUG_ON(!mids); 756 747 757 748 if (!midc->dma->pimr_mask) { 758 - pr_debug("MDMA: SG list is not supported by this controller\n"); 759 - return NULL; 749 + /* We can still handle sg list with only one item */ 750 + if (sg_len == 1) { 751 + txd = intel_mid_dma_prep_memcpy(chan, 752 + mids->dma_slave.dst_addr, 753 + mids->dma_slave.src_addr, 754 + sgl->length, 755 + flags); 756 + return txd; 757 + } else { 758 + pr_warn("MDMA: SG list is not supported by this controller\n"); 759 + return NULL; 760 + } 760 761 } 761 762 762 763 pr_debug("MDMA: SG Length = %d, direction = %d, Flags = %#lx\n", ··· 777 758 pr_err("MDMA: Prep memcpy failed\n"); 778 759 return NULL; 779 760 } 761 + 780 762 desc = to_intel_mid_dma_desc(txd); 781 763 desc->dirn = direction; 782 764 ctl_lo.ctl_lo = desc->ctl_lo; ··· 1041 1021 1042 1022 /*DMA Interrupt*/ 1043 1023 pr_debug("MDMA:Got an interrupt on irq %d\n", irq); 1044 - if (!mid) { 1045 - pr_err("ERR_MDMA:null pointer mid\n"); 1046 - return -EINVAL; 1047 - } 1048 - 1049 1024 pr_debug("MDMA: Status %x, Mask %x\n", tfr_status, mid->intr_mask); 1050 1025 tfr_status &= mid->intr_mask; 1051 1026 if (tfr_status) {
+2 -2
drivers/dma/iop-adma.c
··· 1261 1261 return err; 1262 1262 } 1263 1263 1264 - #ifdef CONFIG_MD_RAID6_PQ 1264 + #ifdef CONFIG_RAID6_PQ 1265 1265 static int __devinit 1266 1266 iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device) 1267 1267 { ··· 1584 1584 1585 1585 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask) && 1586 1586 dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) { 1587 - #ifdef CONFIG_MD_RAID6_PQ 1587 + #ifdef CONFIG_RAID6_PQ 1588 1588 ret = iop_adma_pq_zero_sum_self_test(adev); 1589 1589 dev_dbg(&pdev->dev, "pq self test returned %d\n", ret); 1590 1590 #else
+14 -5
drivers/dma/pch_dma.c
··· 1 1 /* 2 2 * Topcliff PCH DMA controller driver 3 3 * Copyright (c) 2010 Intel Corporation 4 + * Copyright (C) 2011 OKI SEMICONDUCTOR CO., LTD. 4 5 * 5 6 * This program is free software; you can redistribute it and/or modify 6 7 * it under the terms of the GNU General Public License version 2 as ··· 922 921 } 923 922 924 923 /* PCI Device ID of DMA device */ 925 - #define PCI_DEVICE_ID_PCH_DMA_8CH 0x8810 926 - #define PCI_DEVICE_ID_PCH_DMA_4CH 0x8815 924 + #define PCI_VENDOR_ID_ROHM 0x10DB 925 + #define PCI_DEVICE_ID_EG20T_PCH_DMA_8CH 0x8810 926 + #define PCI_DEVICE_ID_EG20T_PCH_DMA_4CH 0x8815 927 + #define PCI_DEVICE_ID_ML7213_DMA1_8CH 0x8026 928 + #define PCI_DEVICE_ID_ML7213_DMA2_8CH 0x802B 929 + #define PCI_DEVICE_ID_ML7213_DMA3_4CH 0x8034 927 930 928 931 static const struct pci_device_id pch_dma_id_table[] = { 929 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_8CH), 8 }, 930 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_4CH), 4 }, 932 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_EG20T_PCH_DMA_8CH), 8 }, 933 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_EG20T_PCH_DMA_4CH), 4 }, 934 + { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_DMA1_8CH), 8}, /* UART Video */ 935 + { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_DMA2_8CH), 8}, /* PCMIF SPI */ 936 + { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_DMA3_4CH), 4}, /* FPGA */ 931 937 { 0, }, 932 938 }; 933 939 ··· 962 954 module_init(pch_dma_init); 963 955 module_exit(pch_dma_exit); 964 956 965 - MODULE_DESCRIPTION("Topcliff PCH DMA controller driver"); 957 + MODULE_DESCRIPTION("Intel EG20T PCH / OKI SEMICONDUCTOR ML7213 IOH " 958 + "DMA controller driver"); 966 959 MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); 967 960 MODULE_LICENSE("GPL v2");
+152 -39
drivers/dma/ste_dma40.c
··· 1 1 /* 2 - * Copyright (C) ST-Ericsson SA 2007-2010 2 + * Copyright (C) Ericsson AB 2007-2008 3 + * Copyright (C) ST-Ericsson SA 2008-2010 3 4 * Author: Per Forlin <per.forlin@stericsson.com> for ST-Ericsson 4 5 * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson 5 6 * License terms: GNU General Public License (GPL) version 2 ··· 555 554 return d; 556 555 } 557 556 558 - /* Support functions for logical channels */ 557 + static int d40_psize_2_burst_size(bool is_log, int psize) 558 + { 559 + if (is_log) { 560 + if (psize == STEDMA40_PSIZE_LOG_1) 561 + return 1; 562 + } else { 563 + if (psize == STEDMA40_PSIZE_PHY_1) 564 + return 1; 565 + } 559 566 567 + return 2 << psize; 568 + } 569 + 570 + /* 571 + * The dma only supports transmitting packages up to 572 + * STEDMA40_MAX_SEG_SIZE << data_width. Calculate the total number of 573 + * dma elements required to send the entire sg list 574 + */ 575 + static int d40_size_2_dmalen(int size, u32 data_width1, u32 data_width2) 576 + { 577 + int dmalen; 578 + u32 max_w = max(data_width1, data_width2); 579 + u32 min_w = min(data_width1, data_width2); 580 + u32 seg_max = ALIGN(STEDMA40_MAX_SEG_SIZE << min_w, 1 << max_w); 581 + 582 + if (seg_max > STEDMA40_MAX_SEG_SIZE) 583 + seg_max -= (1 << max_w); 584 + 585 + if (!IS_ALIGNED(size, 1 << max_w)) 586 + return -EINVAL; 587 + 588 + if (size <= seg_max) 589 + dmalen = 1; 590 + else { 591 + dmalen = size / seg_max; 592 + if (dmalen * seg_max < size) 593 + dmalen++; 594 + } 595 + return dmalen; 596 + } 597 + 598 + static int d40_sg_2_dmalen(struct scatterlist *sgl, int sg_len, 599 + u32 data_width1, u32 data_width2) 600 + { 601 + struct scatterlist *sg; 602 + int i; 603 + int len = 0; 604 + int ret; 605 + 606 + for_each_sg(sgl, sg, sg_len, i) { 607 + ret = d40_size_2_dmalen(sg_dma_len(sg), 608 + data_width1, data_width2); 609 + if (ret < 0) 610 + return ret; 611 + len += ret; 612 + } 613 + return len; 614 + } 615 + 616 + /* Support functions for logical channels */ 560 617 561 618 static int d40_channel_execute_command(struct d40_chan *d40c, 562 619 enum d40_command command) ··· 1300 1241 res = -EINVAL; 1301 1242 } 1302 1243 1244 + if (d40_psize_2_burst_size(is_log, conf->src_info.psize) * 1245 + (1 << conf->src_info.data_width) != 1246 + d40_psize_2_burst_size(is_log, conf->dst_info.psize) * 1247 + (1 << conf->dst_info.data_width)) { 1248 + /* 1249 + * The DMAC hardware only supports 1250 + * src (burst x width) == dst (burst x width) 1251 + */ 1252 + 1253 + dev_err(&d40c->chan.dev->device, 1254 + "[%s] src (burst x width) != dst (burst x width)\n", 1255 + __func__); 1256 + res = -EINVAL; 1257 + } 1258 + 1303 1259 return res; 1304 1260 } 1305 1261 ··· 1712 1638 if (d40d == NULL) 1713 1639 goto err; 1714 1640 1715 - d40d->lli_len = sgl_len; 1641 + d40d->lli_len = d40_sg_2_dmalen(sgl_dst, sgl_len, 1642 + d40c->dma_cfg.src_info.data_width, 1643 + d40c->dma_cfg.dst_info.data_width); 1644 + if (d40d->lli_len < 0) { 1645 + dev_err(&d40c->chan.dev->device, 1646 + "[%s] Unaligned size\n", __func__); 1647 + goto err; 1648 + } 1649 + 1716 1650 d40d->lli_current = 0; 1717 1651 d40d->txd.flags = dma_flags; 1718 1652 1719 1653 if (d40c->log_num != D40_PHY_CHAN) { 1720 1654 1721 - if (d40_pool_lli_alloc(d40d, sgl_len, true) < 0) { 1655 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, true) < 0) { 1722 1656 dev_err(&d40c->chan.dev->device, 1723 1657 "[%s] Out of memory\n", __func__); 1724 1658 goto err; ··· 1736 1654 sgl_len, 1737 1655 d40d->lli_log.src, 1738 1656 d40c->log_def.lcsp1, 1739 - d40c->dma_cfg.src_info.data_width); 1657 + d40c->dma_cfg.src_info.data_width, 1658 + d40c->dma_cfg.dst_info.data_width); 1740 1659 1741 1660 (void) d40_log_sg_to_lli(sgl_dst, 1742 1661 sgl_len, 1743 1662 d40d->lli_log.dst, 1744 1663 d40c->log_def.lcsp3, 1745 - d40c->dma_cfg.dst_info.data_width); 1664 + d40c->dma_cfg.dst_info.data_width, 1665 + d40c->dma_cfg.src_info.data_width); 1746 1666 } else { 1747 - if (d40_pool_lli_alloc(d40d, sgl_len, false) < 0) { 1667 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, false) < 0) { 1748 1668 dev_err(&d40c->chan.dev->device, 1749 1669 "[%s] Out of memory\n", __func__); 1750 1670 goto err; ··· 1759 1675 virt_to_phys(d40d->lli_phy.src), 1760 1676 d40c->src_def_cfg, 1761 1677 d40c->dma_cfg.src_info.data_width, 1678 + d40c->dma_cfg.dst_info.data_width, 1762 1679 d40c->dma_cfg.src_info.psize); 1763 1680 1764 1681 if (res < 0) ··· 1772 1687 virt_to_phys(d40d->lli_phy.dst), 1773 1688 d40c->dst_def_cfg, 1774 1689 d40c->dma_cfg.dst_info.data_width, 1690 + d40c->dma_cfg.src_info.data_width, 1775 1691 d40c->dma_cfg.dst_info.psize); 1776 1692 1777 1693 if (res < 0) ··· 1912 1826 struct d40_chan *d40c = container_of(chan, struct d40_chan, 1913 1827 chan); 1914 1828 unsigned long flags; 1915 - int err = 0; 1916 1829 1917 1830 if (d40c->phy_chan == NULL) { 1918 1831 dev_err(&d40c->chan.dev->device, ··· 1929 1844 } 1930 1845 1931 1846 d40d->txd.flags = dma_flags; 1847 + d40d->lli_len = d40_size_2_dmalen(size, 1848 + d40c->dma_cfg.src_info.data_width, 1849 + d40c->dma_cfg.dst_info.data_width); 1850 + if (d40d->lli_len < 0) { 1851 + dev_err(&d40c->chan.dev->device, 1852 + "[%s] Unaligned size\n", __func__); 1853 + goto err; 1854 + } 1855 + 1932 1856 1933 1857 dma_async_tx_descriptor_init(&d40d->txd, chan); 1934 1858 ··· 1945 1851 1946 1852 if (d40c->log_num != D40_PHY_CHAN) { 1947 1853 1948 - if (d40_pool_lli_alloc(d40d, 1, true) < 0) { 1854 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, true) < 0) { 1949 1855 dev_err(&d40c->chan.dev->device, 1950 1856 "[%s] Out of memory\n", __func__); 1951 1857 goto err; 1952 1858 } 1953 - d40d->lli_len = 1; 1954 1859 d40d->lli_current = 0; 1955 1860 1956 - d40_log_fill_lli(d40d->lli_log.src, 1957 - src, 1958 - size, 1959 - d40c->log_def.lcsp1, 1960 - d40c->dma_cfg.src_info.data_width, 1961 - true); 1861 + if (d40_log_buf_to_lli(d40d->lli_log.src, 1862 + src, 1863 + size, 1864 + d40c->log_def.lcsp1, 1865 + d40c->dma_cfg.src_info.data_width, 1866 + d40c->dma_cfg.dst_info.data_width, 1867 + true) == NULL) 1868 + goto err; 1962 1869 1963 - d40_log_fill_lli(d40d->lli_log.dst, 1964 - dst, 1965 - size, 1966 - d40c->log_def.lcsp3, 1967 - d40c->dma_cfg.dst_info.data_width, 1968 - true); 1870 + if (d40_log_buf_to_lli(d40d->lli_log.dst, 1871 + dst, 1872 + size, 1873 + d40c->log_def.lcsp3, 1874 + d40c->dma_cfg.dst_info.data_width, 1875 + d40c->dma_cfg.src_info.data_width, 1876 + true) == NULL) 1877 + goto err; 1969 1878 1970 1879 } else { 1971 1880 1972 - if (d40_pool_lli_alloc(d40d, 1, false) < 0) { 1881 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, false) < 0) { 1973 1882 dev_err(&d40c->chan.dev->device, 1974 1883 "[%s] Out of memory\n", __func__); 1975 1884 goto err; 1976 1885 } 1977 1886 1978 - err = d40_phy_fill_lli(d40d->lli_phy.src, 1887 + if (d40_phy_buf_to_lli(d40d->lli_phy.src, 1979 1888 src, 1980 1889 size, 1981 1890 d40c->dma_cfg.src_info.psize, ··· 1986 1889 d40c->src_def_cfg, 1987 1890 true, 1988 1891 d40c->dma_cfg.src_info.data_width, 1989 - false); 1990 - if (err) 1991 - goto err_fill_lli; 1892 + d40c->dma_cfg.dst_info.data_width, 1893 + false) == NULL) 1894 + goto err; 1992 1895 1993 - err = d40_phy_fill_lli(d40d->lli_phy.dst, 1896 + if (d40_phy_buf_to_lli(d40d->lli_phy.dst, 1994 1897 dst, 1995 1898 size, 1996 1899 d40c->dma_cfg.dst_info.psize, ··· 1998 1901 d40c->dst_def_cfg, 1999 1902 true, 2000 1903 d40c->dma_cfg.dst_info.data_width, 2001 - false); 2002 - 2003 - if (err) 2004 - goto err_fill_lli; 1904 + d40c->dma_cfg.src_info.data_width, 1905 + false) == NULL) 1906 + goto err; 2005 1907 2006 1908 (void) dma_map_single(d40c->base->dev, d40d->lli_phy.src, 2007 1909 d40d->lli_pool.size, DMA_TO_DEVICE); ··· 2009 1913 spin_unlock_irqrestore(&d40c->lock, flags); 2010 1914 return &d40d->txd; 2011 1915 2012 - err_fill_lli: 2013 - dev_err(&d40c->chan.dev->device, 2014 - "[%s] Failed filling in PHY LLI\n", __func__); 2015 1916 err: 2016 1917 if (d40d) 2017 1918 d40_desc_free(d40c, d40d); ··· 2038 1945 dma_addr_t dev_addr = 0; 2039 1946 int total_size; 2040 1947 2041 - if (d40_pool_lli_alloc(d40d, sg_len, true) < 0) { 1948 + d40d->lli_len = d40_sg_2_dmalen(sgl, sg_len, 1949 + d40c->dma_cfg.src_info.data_width, 1950 + d40c->dma_cfg.dst_info.data_width); 1951 + if (d40d->lli_len < 0) { 1952 + dev_err(&d40c->chan.dev->device, 1953 + "[%s] Unaligned size\n", __func__); 1954 + return -EINVAL; 1955 + } 1956 + 1957 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, true) < 0) { 2042 1958 dev_err(&d40c->chan.dev->device, 2043 1959 "[%s] Out of memory\n", __func__); 2044 1960 return -ENOMEM; 2045 1961 } 2046 1962 2047 - d40d->lli_len = sg_len; 2048 1963 d40d->lli_current = 0; 2049 1964 2050 1965 if (direction == DMA_FROM_DEVICE) ··· 2094 1993 dma_addr_t dst_dev_addr; 2095 1994 int res; 2096 1995 2097 - if (d40_pool_lli_alloc(d40d, sgl_len, false) < 0) { 1996 + d40d->lli_len = d40_sg_2_dmalen(sgl, sgl_len, 1997 + d40c->dma_cfg.src_info.data_width, 1998 + d40c->dma_cfg.dst_info.data_width); 1999 + if (d40d->lli_len < 0) { 2000 + dev_err(&d40c->chan.dev->device, 2001 + "[%s] Unaligned size\n", __func__); 2002 + return -EINVAL; 2003 + } 2004 + 2005 + if (d40_pool_lli_alloc(d40d, d40d->lli_len, false) < 0) { 2098 2006 dev_err(&d40c->chan.dev->device, 2099 2007 "[%s] Out of memory\n", __func__); 2100 2008 return -ENOMEM; 2101 2009 } 2102 2010 2103 - d40d->lli_len = sgl_len; 2104 2011 d40d->lli_current = 0; 2105 2012 2106 2013 if (direction == DMA_FROM_DEVICE) { ··· 2133 2024 virt_to_phys(d40d->lli_phy.src), 2134 2025 d40c->src_def_cfg, 2135 2026 d40c->dma_cfg.src_info.data_width, 2027 + d40c->dma_cfg.dst_info.data_width, 2136 2028 d40c->dma_cfg.src_info.psize); 2137 2029 if (res < 0) 2138 2030 return res; ··· 2145 2035 virt_to_phys(d40d->lli_phy.dst), 2146 2036 d40c->dst_def_cfg, 2147 2037 d40c->dma_cfg.dst_info.data_width, 2038 + d40c->dma_cfg.src_info.data_width, 2148 2039 d40c->dma_cfg.dst_info.psize); 2149 2040 if (res < 0) 2150 2041 return res; ··· 2355 2244 psize = STEDMA40_PSIZE_PHY_8; 2356 2245 else if (config_maxburst >= 4) 2357 2246 psize = STEDMA40_PSIZE_PHY_4; 2247 + else if (config_maxburst >= 2) 2248 + psize = STEDMA40_PSIZE_PHY_2; 2358 2249 else 2359 2250 psize = STEDMA40_PSIZE_PHY_1; 2360 2251 }
+172 -74
drivers/dma/ste_dma40_ll.c
··· 1 1 /* 2 2 * Copyright (C) ST-Ericsson SA 2007-2010 3 - * Author: Per Friden <per.friden@stericsson.com> for ST-Ericsson 3 + * Author: Per Forlin <per.forlin@stericsson.com> for ST-Ericsson 4 4 * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson 5 5 * License terms: GNU General Public License (GPL) version 2 6 6 */ ··· 122 122 *dst_cfg = dst; 123 123 } 124 124 125 - int d40_phy_fill_lli(struct d40_phy_lli *lli, 126 - dma_addr_t data, 127 - u32 data_size, 128 - int psize, 129 - dma_addr_t next_lli, 130 - u32 reg_cfg, 131 - bool term_int, 132 - u32 data_width, 133 - bool is_device) 125 + static int d40_phy_fill_lli(struct d40_phy_lli *lli, 126 + dma_addr_t data, 127 + u32 data_size, 128 + int psize, 129 + dma_addr_t next_lli, 130 + u32 reg_cfg, 131 + bool term_int, 132 + u32 data_width, 133 + bool is_device) 134 134 { 135 135 int num_elems; 136 136 ··· 138 138 num_elems = 1; 139 139 else 140 140 num_elems = 2 << psize; 141 - 142 - /* 143 - * Size is 16bit. data_width is 8, 16, 32 or 64 bit 144 - * Block large than 64 KiB must be split. 145 - */ 146 - if (data_size > (0xffff << data_width)) 147 - return -EINVAL; 148 141 149 142 /* Must be aligned */ 150 143 if (!IS_ALIGNED(data, 0x1 << data_width)) ··· 180 187 return 0; 181 188 } 182 189 190 + static int d40_seg_size(int size, int data_width1, int data_width2) 191 + { 192 + u32 max_w = max(data_width1, data_width2); 193 + u32 min_w = min(data_width1, data_width2); 194 + u32 seg_max = ALIGN(STEDMA40_MAX_SEG_SIZE << min_w, 1 << max_w); 195 + 196 + if (seg_max > STEDMA40_MAX_SEG_SIZE) 197 + seg_max -= (1 << max_w); 198 + 199 + if (size <= seg_max) 200 + return size; 201 + 202 + if (size <= 2 * seg_max) 203 + return ALIGN(size / 2, 1 << max_w); 204 + 205 + return seg_max; 206 + } 207 + 208 + struct d40_phy_lli *d40_phy_buf_to_lli(struct d40_phy_lli *lli, 209 + dma_addr_t addr, 210 + u32 size, 211 + int psize, 212 + dma_addr_t lli_phys, 213 + u32 reg_cfg, 214 + bool term_int, 215 + u32 data_width1, 216 + u32 data_width2, 217 + bool is_device) 218 + { 219 + int err; 220 + dma_addr_t next = lli_phys; 221 + int size_rest = size; 222 + int size_seg = 0; 223 + 224 + do { 225 + size_seg = d40_seg_size(size_rest, data_width1, data_width2); 226 + size_rest -= size_seg; 227 + 228 + if (term_int && size_rest == 0) 229 + next = 0; 230 + else 231 + next = ALIGN(next + sizeof(struct d40_phy_lli), 232 + D40_LLI_ALIGN); 233 + 234 + err = d40_phy_fill_lli(lli, 235 + addr, 236 + size_seg, 237 + psize, 238 + next, 239 + reg_cfg, 240 + !next, 241 + data_width1, 242 + is_device); 243 + 244 + if (err) 245 + goto err; 246 + 247 + lli++; 248 + if (!is_device) 249 + addr += size_seg; 250 + } while (size_rest); 251 + 252 + return lli; 253 + 254 + err: 255 + return NULL; 256 + } 257 + 183 258 int d40_phy_sg_to_lli(struct scatterlist *sg, 184 259 int sg_len, 185 260 dma_addr_t target, 186 - struct d40_phy_lli *lli, 261 + struct d40_phy_lli *lli_sg, 187 262 dma_addr_t lli_phys, 188 263 u32 reg_cfg, 189 - u32 data_width, 264 + u32 data_width1, 265 + u32 data_width2, 190 266 int psize) 191 267 { 192 268 int total_size = 0; 193 269 int i; 194 270 struct scatterlist *current_sg = sg; 195 - dma_addr_t next_lli_phys; 196 271 dma_addr_t dst; 197 - int err = 0; 272 + struct d40_phy_lli *lli = lli_sg; 273 + dma_addr_t l_phys = lli_phys; 198 274 199 275 for_each_sg(sg, current_sg, sg_len, i) { 200 276 201 277 total_size += sg_dma_len(current_sg); 202 - 203 - /* If this scatter list entry is the last one, no next link */ 204 - if (sg_len - 1 == i) 205 - next_lli_phys = 0; 206 - else 207 - next_lli_phys = ALIGN(lli_phys + (i + 1) * 208 - sizeof(struct d40_phy_lli), 209 - D40_LLI_ALIGN); 210 278 211 279 if (target) 212 280 dst = target; 213 281 else 214 282 dst = sg_phys(current_sg); 215 283 216 - err = d40_phy_fill_lli(&lli[i], 217 - dst, 218 - sg_dma_len(current_sg), 219 - psize, 220 - next_lli_phys, 221 - reg_cfg, 222 - !next_lli_phys, 223 - data_width, 224 - target == dst); 225 - if (err) 226 - goto err; 284 + l_phys = ALIGN(lli_phys + (lli - lli_sg) * 285 + sizeof(struct d40_phy_lli), D40_LLI_ALIGN); 286 + 287 + lli = d40_phy_buf_to_lli(lli, 288 + dst, 289 + sg_dma_len(current_sg), 290 + psize, 291 + l_phys, 292 + reg_cfg, 293 + sg_len - 1 == i, 294 + data_width1, 295 + data_width2, 296 + target == dst); 297 + if (lli == NULL) 298 + return -EINVAL; 227 299 } 228 300 229 301 return total_size; 230 - err: 231 - return err; 232 302 } 233 303 234 304 ··· 371 315 writel(lli_dst->lcsp13, &lcla[1].lcsp13); 372 316 } 373 317 374 - void d40_log_fill_lli(struct d40_log_lli *lli, 375 - dma_addr_t data, u32 data_size, 376 - u32 reg_cfg, 377 - u32 data_width, 378 - bool addr_inc) 318 + static void d40_log_fill_lli(struct d40_log_lli *lli, 319 + dma_addr_t data, u32 data_size, 320 + u32 reg_cfg, 321 + u32 data_width, 322 + bool addr_inc) 379 323 { 380 324 lli->lcsp13 = reg_cfg; 381 325 382 326 /* The number of elements to transfer */ 383 327 lli->lcsp02 = ((data_size >> data_width) << 384 328 D40_MEM_LCSP0_ECNT_POS) & D40_MEM_LCSP0_ECNT_MASK; 329 + 330 + BUG_ON((data_size >> data_width) > STEDMA40_MAX_SEG_SIZE); 331 + 385 332 /* 16 LSBs address of the current element */ 386 333 lli->lcsp02 |= data & D40_MEM_LCSP0_SPTR_MASK; 387 334 /* 16 MSBs address of the current element */ ··· 407 348 int total_size = 0; 408 349 struct scatterlist *current_sg = sg; 409 350 int i; 351 + struct d40_log_lli *lli_src = lli->src; 352 + struct d40_log_lli *lli_dst = lli->dst; 410 353 411 354 for_each_sg(sg, current_sg, sg_len, i) { 412 355 total_size += sg_dma_len(current_sg); 413 356 414 357 if (direction == DMA_TO_DEVICE) { 415 - d40_log_fill_lli(&lli->src[i], 416 - sg_phys(current_sg), 417 - sg_dma_len(current_sg), 418 - lcsp->lcsp1, src_data_width, 419 - true); 420 - d40_log_fill_lli(&lli->dst[i], 421 - dev_addr, 422 - sg_dma_len(current_sg), 423 - lcsp->lcsp3, dst_data_width, 424 - false); 358 + lli_src = 359 + d40_log_buf_to_lli(lli_src, 360 + sg_phys(current_sg), 361 + sg_dma_len(current_sg), 362 + lcsp->lcsp1, src_data_width, 363 + dst_data_width, 364 + true); 365 + lli_dst = 366 + d40_log_buf_to_lli(lli_dst, 367 + dev_addr, 368 + sg_dma_len(current_sg), 369 + lcsp->lcsp3, dst_data_width, 370 + src_data_width, 371 + false); 425 372 } else { 426 - d40_log_fill_lli(&lli->dst[i], 427 - sg_phys(current_sg), 428 - sg_dma_len(current_sg), 429 - lcsp->lcsp3, dst_data_width, 430 - true); 431 - d40_log_fill_lli(&lli->src[i], 432 - dev_addr, 433 - sg_dma_len(current_sg), 434 - lcsp->lcsp1, src_data_width, 435 - false); 373 + lli_dst = 374 + d40_log_buf_to_lli(lli_dst, 375 + sg_phys(current_sg), 376 + sg_dma_len(current_sg), 377 + lcsp->lcsp3, dst_data_width, 378 + src_data_width, 379 + true); 380 + lli_src = 381 + d40_log_buf_to_lli(lli_src, 382 + dev_addr, 383 + sg_dma_len(current_sg), 384 + lcsp->lcsp1, src_data_width, 385 + dst_data_width, 386 + false); 436 387 } 437 388 } 438 389 return total_size; 390 + } 391 + 392 + struct d40_log_lli *d40_log_buf_to_lli(struct d40_log_lli *lli_sg, 393 + dma_addr_t addr, 394 + int size, 395 + u32 lcsp13, /* src or dst*/ 396 + u32 data_width1, 397 + u32 data_width2, 398 + bool addr_inc) 399 + { 400 + struct d40_log_lli *lli = lli_sg; 401 + int size_rest = size; 402 + int size_seg = 0; 403 + 404 + do { 405 + size_seg = d40_seg_size(size_rest, data_width1, data_width2); 406 + size_rest -= size_seg; 407 + 408 + d40_log_fill_lli(lli, 409 + addr, 410 + size_seg, 411 + lcsp13, data_width1, 412 + addr_inc); 413 + if (addr_inc) 414 + addr += size_seg; 415 + lli++; 416 + } while (size_rest); 417 + 418 + return lli; 439 419 } 440 420 441 421 int d40_log_sg_to_lli(struct scatterlist *sg, 442 422 int sg_len, 443 423 struct d40_log_lli *lli_sg, 444 424 u32 lcsp13, /* src or dst*/ 445 - u32 data_width) 425 + u32 data_width1, u32 data_width2) 446 426 { 447 427 int total_size = 0; 448 428 struct scatterlist *current_sg = sg; 449 429 int i; 430 + struct d40_log_lli *lli = lli_sg; 450 431 451 432 for_each_sg(sg, current_sg, sg_len, i) { 452 433 total_size += sg_dma_len(current_sg); 453 - 454 - d40_log_fill_lli(&lli_sg[i], 455 - sg_phys(current_sg), 456 - sg_dma_len(current_sg), 457 - lcsp13, data_width, 458 - true); 434 + lli = d40_log_buf_to_lli(lli, 435 + sg_phys(current_sg), 436 + sg_dma_len(current_sg), 437 + lcsp13, 438 + data_width1, data_width2, true); 459 439 } 460 440 return total_size; 461 441 }
+19 -17
drivers/dma/ste_dma40_ll.h
··· 292 292 struct d40_phy_lli *lli, 293 293 dma_addr_t lli_phys, 294 294 u32 reg_cfg, 295 - u32 data_width, 295 + u32 data_width1, 296 + u32 data_width2, 296 297 int psize); 297 298 298 - int d40_phy_fill_lli(struct d40_phy_lli *lli, 299 - dma_addr_t data, 300 - u32 data_size, 301 - int psize, 302 - dma_addr_t next_lli, 303 - u32 reg_cfg, 304 - bool term_int, 305 - u32 data_width, 306 - bool is_device); 299 + struct d40_phy_lli *d40_phy_buf_to_lli(struct d40_phy_lli *lli, 300 + dma_addr_t data, 301 + u32 data_size, 302 + int psize, 303 + dma_addr_t next_lli, 304 + u32 reg_cfg, 305 + bool term_int, 306 + u32 data_width1, 307 + u32 data_width2, 308 + bool is_device); 307 309 308 310 void d40_phy_lli_write(void __iomem *virtbase, 309 311 u32 phy_chan_num, ··· 314 312 315 313 /* Logical channels */ 316 314 317 - void d40_log_fill_lli(struct d40_log_lli *lli, 318 - dma_addr_t data, 319 - u32 data_size, 320 - u32 reg_cfg, 321 - u32 data_width, 322 - bool addr_inc); 315 + struct d40_log_lli *d40_log_buf_to_lli(struct d40_log_lli *lli_sg, 316 + dma_addr_t addr, 317 + int size, 318 + u32 lcsp13, /* src or dst*/ 319 + u32 data_width1, u32 data_width2, 320 + bool addr_inc); 323 321 324 322 int d40_log_sg_to_dev(struct scatterlist *sg, 325 323 int sg_len, ··· 334 332 int sg_len, 335 333 struct d40_log_lli *lli_sg, 336 334 u32 lcsp13, /* src or dst*/ 337 - u32 data_width); 335 + u32 data_width1, u32 data_width2); 338 336 339 337 void d40_log_lli_lcpa_write(struct d40_log_lli_full *lcpa, 340 338 struct d40_log_lli *lli_dst,
+50 -49
include/linux/amba/pl08x.h
··· 12 12 * 13 13 * Please credit ARM.com 14 14 * Documentation: ARM DDI 0196D 15 - * 16 15 */ 17 16 18 17 #ifndef AMBA_PL08X_H ··· 20 21 /* We need sizes of structs from this header */ 21 22 #include <linux/dmaengine.h> 22 23 #include <linux/interrupt.h> 24 + 25 + struct pl08x_lli; 26 + struct pl08x_driver_data; 27 + 28 + /* Bitmasks for selecting AHB ports for DMA transfers */ 29 + enum { 30 + PL08X_AHB1 = (1 << 0), 31 + PL08X_AHB2 = (1 << 1) 32 + }; 23 33 24 34 /** 25 35 * struct pl08x_channel_data - data structure to pass info between ··· 54 46 * @circular_buffer: whether the buffer passed in is circular and 55 47 * shall simply be looped round round (like a record baby round 56 48 * round round round) 57 - * @single: the device connected to this channel will request single 58 - * DMA transfers, not bursts. (Bursts are default.) 49 + * @single: the device connected to this channel will request single DMA 50 + * transfers, not bursts. (Bursts are default.) 51 + * @periph_buses: the device connected to this channel is accessible via 52 + * these buses (use PL08X_AHB1 | PL08X_AHB2). 59 53 */ 60 54 struct pl08x_channel_data { 61 55 char *bus_id; ··· 65 55 int max_signal; 66 56 u32 muxval; 67 57 u32 cctl; 68 - u32 ccfg; 69 58 dma_addr_t addr; 70 59 bool circular_buffer; 71 60 bool single; 61 + u8 periph_buses; 72 62 }; 73 63 74 64 /** ··· 77 67 * @addr: current address 78 68 * @maxwidth: the maximum width of a transfer on this bus 79 69 * @buswidth: the width of this bus in bytes: 1, 2 or 4 80 - * @fill_bytes: bytes required to fill to the next bus memory 81 - * boundary 70 + * @fill_bytes: bytes required to fill to the next bus memory boundary 82 71 */ 83 72 struct pl08x_bus_data { 84 73 dma_addr_t addr; 85 74 u8 maxwidth; 86 75 u8 buswidth; 87 - u32 fill_bytes; 76 + size_t fill_bytes; 88 77 }; 89 78 90 79 /** 91 80 * struct pl08x_phy_chan - holder for the physical channels 92 81 * @id: physical index to this channel 93 82 * @lock: a lock to use when altering an instance of this struct 94 - * @signal: the physical signal (aka channel) serving this 95 - * physical channel right now 96 - * @serving: the virtual channel currently being served by this 97 - * physical channel 83 + * @signal: the physical signal (aka channel) serving this physical channel 84 + * right now 85 + * @serving: the virtual channel currently being served by this physical 86 + * channel 98 87 */ 99 88 struct pl08x_phy_chan { 100 89 unsigned int id; ··· 101 92 spinlock_t lock; 102 93 int signal; 103 94 struct pl08x_dma_chan *serving; 104 - u32 csrc; 105 - u32 cdst; 106 - u32 clli; 107 - u32 cctl; 108 - u32 ccfg; 109 95 }; 110 96 111 97 /** ··· 112 108 struct dma_async_tx_descriptor tx; 113 109 struct list_head node; 114 110 enum dma_data_direction direction; 115 - struct pl08x_bus_data srcbus; 116 - struct pl08x_bus_data dstbus; 117 - int len; 111 + dma_addr_t src_addr; 112 + dma_addr_t dst_addr; 113 + size_t len; 118 114 dma_addr_t llis_bus; 119 - void *llis_va; 120 - struct pl08x_channel_data *cd; 121 - bool active; 115 + struct pl08x_lli *llis_va; 116 + /* Default cctl value for LLIs */ 117 + u32 cctl; 122 118 /* 123 119 * Settings to be put into the physical channel when we 124 - * trigger this txd 120 + * trigger this txd. Other registers are in llis_va[0]. 125 121 */ 126 - u32 csrc; 127 - u32 cdst; 128 - u32 clli; 129 - u32 cctl; 122 + u32 ccfg; 130 123 }; 131 124 132 125 /** 133 - * struct pl08x_dma_chan_state - holds the PL08x specific virtual 134 - * channel states 126 + * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel 127 + * states 135 128 * @PL08X_CHAN_IDLE: the channel is idle 136 129 * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport 137 130 * channel and is running a transfer on it ··· 148 147 * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel 149 148 * @chan: wrappped abstract channel 150 149 * @phychan: the physical channel utilized by this channel, if there is one 150 + * @phychan_hold: if non-zero, hold on to the physical channel even if we 151 + * have no pending entries 151 152 * @tasklet: tasklet scheduled by the IRQ to handle actual work etc 152 153 * @name: name of channel 153 154 * @cd: channel platform data ··· 157 154 * @runtime_direction: current direction of this channel according to 158 155 * runtime config 159 156 * @lc: last completed transaction on this channel 160 - * @desc_list: queued transactions pending on this channel 157 + * @pend_list: queued transactions pending on this channel 161 158 * @at: active transaction on this channel 162 - * @lockflags: sometimes we let a lock last between two function calls, 163 - * especially prep/submit, and then we need to store the IRQ flags 164 - * in the channel state, here 165 159 * @lock: a lock for this channel data 166 160 * @host: a pointer to the host (internal use) 167 161 * @state: whether the channel is idle, paused, running etc 168 162 * @slave: whether this channel is a device (slave) or for memcpy 169 - * @waiting: a TX descriptor on this channel which is waiting for 170 - * a physical channel to become available 163 + * @waiting: a TX descriptor on this channel which is waiting for a physical 164 + * channel to become available 171 165 */ 172 166 struct pl08x_dma_chan { 173 167 struct dma_chan chan; 174 168 struct pl08x_phy_chan *phychan; 169 + int phychan_hold; 175 170 struct tasklet_struct tasklet; 176 171 char *name; 177 172 struct pl08x_channel_data *cd; 178 173 dma_addr_t runtime_addr; 179 174 enum dma_data_direction runtime_direction; 180 - atomic_t last_issued; 181 175 dma_cookie_t lc; 182 - struct list_head desc_list; 176 + struct list_head pend_list; 183 177 struct pl08x_txd *at; 184 - unsigned long lockflags; 185 178 spinlock_t lock; 186 - void *host; 179 + struct pl08x_driver_data *host; 187 180 enum pl08x_dma_chan_state state; 188 181 bool slave; 189 182 struct pl08x_txd *waiting; 190 183 }; 191 184 192 185 /** 193 - * struct pl08x_platform_data - the platform configuration for the 194 - * PL08x PrimeCells. 186 + * struct pl08x_platform_data - the platform configuration for the PL08x 187 + * PrimeCells. 195 188 * @slave_channels: the channels defined for the different devices on the 196 189 * platform, all inclusive, including multiplexed channels. The available 197 - * physical channels will be multiplexed around these signals as they 198 - * are requested, just enumerate all possible channels. 199 - * @get_signal: request a physical signal to be used for a DMA 200 - * transfer immediately: if there is some multiplexing or similar blocking 201 - * the use of the channel the transfer can be denied by returning 202 - * less than zero, else it returns the allocated signal number 190 + * physical channels will be multiplexed around these signals as they are 191 + * requested, just enumerate all possible channels. 192 + * @get_signal: request a physical signal to be used for a DMA transfer 193 + * immediately: if there is some multiplexing or similar blocking the use 194 + * of the channel the transfer can be denied by returning less than zero, 195 + * else it returns the allocated signal number 203 196 * @put_signal: indicate to the platform that this physical signal is not 204 197 * running any DMA transfer and multiplexing can be recycled 205 - * @bus_bit_lli: Bit[0] of the address indicated which AHB bus master the 206 - * LLI addresses are on 0/1 Master 1/2. 198 + * @lli_buses: buses which LLIs can be fetched from: PL08X_AHB1 | PL08X_AHB2 199 + * @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2 207 200 */ 208 201 struct pl08x_platform_data { 209 202 struct pl08x_channel_data *slave_channels; ··· 207 208 struct pl08x_channel_data memcpy_channel; 208 209 int (*get_signal)(struct pl08x_dma_chan *); 209 210 void (*put_signal)(struct pl08x_dma_chan *); 211 + u8 lli_buses; 212 + u8 mem_buses; 210 213 }; 211 214 212 215 #ifdef CONFIG_AMBA_PL08X
+1 -1
include/linux/dmaengine.h
··· 532 532 return dmaengine_device_control(chan, DMA_RESUME, 0); 533 533 } 534 534 535 - static inline int dmaengine_submit(struct dma_async_tx_descriptor *desc) 535 + static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc) 536 536 { 537 537 return desc->tx_submit(desc); 538 538 }