2021-08-22 15:23:23 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-12-06 09:19:21 +08:00
|
|
|
/*
|
|
|
|
* DMM IOMMU driver support functions for TI OMAP processors.
|
|
|
|
*
|
2020-07-13 20:28:59 +08:00
|
|
|
* Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com/
|
2011-12-06 09:19:21 +08:00
|
|
|
* Author: Rob Clark <rob@ti.com>
|
|
|
|
* Andy Gross <andy.gross@ti.com>
|
|
|
|
*/
|
2015-03-06 03:31:37 +08:00
|
|
|
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2018-09-26 17:11:30 +08:00
|
|
|
#include <linux/dmaengine.h>
|
2015-03-06 03:31:37 +08:00
|
|
|
#include <linux/errno.h>
|
2011-12-06 09:19:21 +08:00
|
|
|
#include <linux/init.h>
|
2015-03-06 03:31:37 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/mm.h>
|
2011-12-06 09:19:21 +08:00
|
|
|
#include <linux/module.h>
|
2022-07-01 03:51:12 +08:00
|
|
|
#include <linux/of.h>
|
2011-12-06 09:19:21 +08:00
|
|
|
#include <linux/platform_device.h> /* platform_device() */
|
|
|
|
#include <linux/sched.h>
|
2016-05-12 00:01:45 +08:00
|
|
|
#include <linux/seq_file.h>
|
2011-12-06 09:19:21 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/time.h>
|
2015-03-06 03:31:37 +08:00
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/wait.h>
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
#include "omap_dmm_tiler.h"
|
|
|
|
#include "omap_dmm_priv.h"
|
|
|
|
|
2012-03-06 00:48:39 +08:00
|
|
|
#define DMM_DRIVER_NAME "dmm"
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* mappings for associating views to luts */
|
|
|
|
static struct tcm *containers[TILFMT_NFORMATS];
|
|
|
|
static struct dmm *omap_dmm;
|
|
|
|
|
2014-09-26 03:24:29 +08:00
|
|
|
#if defined(CONFIG_OF)
|
|
|
|
static const struct of_device_id dmm_of_match[];
|
|
|
|
#endif
|
|
|
|
|
2012-05-25 00:43:32 +08:00
|
|
|
/* global spinlock for protecting lists */
|
|
|
|
static DEFINE_SPINLOCK(list_lock);
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* Geometry table */
|
|
|
|
#define GEOM(xshift, yshift, bytes_per_pixel) { \
|
|
|
|
.x_shft = (xshift), \
|
|
|
|
.y_shft = (yshift), \
|
|
|
|
.cpp = (bytes_per_pixel), \
|
|
|
|
.slot_w = 1 << (SLOT_WIDTH_BITS - (xshift)), \
|
|
|
|
.slot_h = 1 << (SLOT_HEIGHT_BITS - (yshift)), \
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct {
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 x_shft; /* unused X-bits (as part of bpp) */
|
|
|
|
u32 y_shft; /* unused Y-bits (as part of bpp) */
|
|
|
|
u32 cpp; /* bytes/chars per pixel */
|
|
|
|
u32 slot_w; /* width of each slot (in pixels) */
|
|
|
|
u32 slot_h; /* height of each slot (in pixels) */
|
2011-12-06 09:19:21 +08:00
|
|
|
} geom[TILFMT_NFORMATS] = {
|
2015-01-11 06:02:07 +08:00
|
|
|
[TILFMT_8BIT] = GEOM(0, 0, 1),
|
|
|
|
[TILFMT_16BIT] = GEOM(0, 1, 2),
|
|
|
|
[TILFMT_32BIT] = GEOM(1, 1, 4),
|
|
|
|
[TILFMT_PAGE] = GEOM(SLOT_WIDTH_BITS, SLOT_HEIGHT_BITS, 1),
|
2011-12-06 09:19:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* lookup table for registers w/ per-engine instances */
|
2018-02-11 21:07:33 +08:00
|
|
|
static const u32 reg[][4] = {
|
2015-01-11 06:02:07 +08:00
|
|
|
[PAT_STATUS] = {DMM_PAT_STATUS__0, DMM_PAT_STATUS__1,
|
|
|
|
DMM_PAT_STATUS__2, DMM_PAT_STATUS__3},
|
|
|
|
[PAT_DESCR] = {DMM_PAT_DESCR__0, DMM_PAT_DESCR__1,
|
|
|
|
DMM_PAT_DESCR__2, DMM_PAT_DESCR__3},
|
2011-12-06 09:19:21 +08:00
|
|
|
};
|
|
|
|
|
2018-09-26 17:11:30 +08:00
|
|
|
static int dmm_dma_copy(struct dmm *dmm, dma_addr_t src, dma_addr_t dst)
|
|
|
|
{
|
|
|
|
struct dma_async_tx_descriptor *tx;
|
|
|
|
enum dma_status status;
|
|
|
|
dma_cookie_t cookie;
|
|
|
|
|
2019-07-31 17:42:32 +08:00
|
|
|
tx = dmaengine_prep_dma_memcpy(dmm->wa_dma_chan, dst, src, 4, 0);
|
2018-09-26 17:11:30 +08:00
|
|
|
if (!tx) {
|
|
|
|
dev_err(dmm->dev, "Failed to prepare DMA memcpy\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie = tx->tx_submit(tx);
|
|
|
|
if (dma_submit_error(cookie)) {
|
|
|
|
dev_err(dmm->dev, "Failed to do DMA tx_submit\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = dma_sync_wait(dmm->wa_dma_chan, cookie);
|
|
|
|
if (status != DMA_COMPLETE)
|
|
|
|
dev_err(dmm->dev, "i878 wa DMA copy failure\n");
|
|
|
|
|
|
|
|
dmaengine_terminate_all(dmm->wa_dma_chan);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 dmm_read_wa(struct dmm *dmm, u32 reg)
|
|
|
|
{
|
|
|
|
dma_addr_t src, dst;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
src = dmm->phys_base + reg;
|
|
|
|
dst = dmm->wa_dma_handle;
|
|
|
|
|
|
|
|
r = dmm_dma_copy(dmm, src, dst);
|
|
|
|
if (r) {
|
|
|
|
dev_err(dmm->dev, "sDMA read transfer timeout\n");
|
|
|
|
return readl(dmm->base + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As per i878 workaround, the DMA is used to access the DMM registers.
|
|
|
|
* Make sure that the readl is not moved by the compiler or the CPU
|
|
|
|
* earlier than the DMA finished writing the value to memory.
|
|
|
|
*/
|
|
|
|
rmb();
|
|
|
|
return readl(dmm->wa_dma_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dmm_write_wa(struct dmm *dmm, u32 val, u32 reg)
|
|
|
|
{
|
|
|
|
dma_addr_t src, dst;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
writel(val, dmm->wa_dma_data);
|
|
|
|
/*
|
|
|
|
* As per i878 workaround, the DMA is used to access the DMM registers.
|
|
|
|
* Make sure that the writel is not moved by the compiler or the CPU, so
|
|
|
|
* the data will be in place before we start the DMA to do the actual
|
|
|
|
* register write.
|
|
|
|
*/
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
src = dmm->wa_dma_handle;
|
|
|
|
dst = dmm->phys_base + reg;
|
|
|
|
|
|
|
|
r = dmm_dma_copy(dmm, src, dst);
|
|
|
|
if (r) {
|
|
|
|
dev_err(dmm->dev, "sDMA write transfer timeout\n");
|
|
|
|
writel(val, dmm->base + reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 19:31:28 +08:00
|
|
|
static u32 dmm_read(struct dmm *dmm, u32 reg)
|
|
|
|
{
|
2018-09-26 17:11:30 +08:00
|
|
|
if (dmm->dmm_workaround) {
|
|
|
|
u32 v;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dmm->wa_lock, flags);
|
|
|
|
v = dmm_read_wa(dmm, reg);
|
|
|
|
spin_unlock_irqrestore(&dmm->wa_lock, flags);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
return readl(dmm->base + reg);
|
|
|
|
}
|
2015-08-07 19:31:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dmm_write(struct dmm *dmm, u32 val, u32 reg)
|
|
|
|
{
|
2018-09-26 17:11:30 +08:00
|
|
|
if (dmm->dmm_workaround) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dmm->wa_lock, flags);
|
|
|
|
dmm_write_wa(dmm, val, reg);
|
|
|
|
spin_unlock_irqrestore(&dmm->wa_lock, flags);
|
|
|
|
} else {
|
|
|
|
writel(val, dmm->base + reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dmm_workaround_init(struct dmm *dmm)
|
|
|
|
{
|
|
|
|
dma_cap_mask_t mask;
|
|
|
|
|
|
|
|
spin_lock_init(&dmm->wa_lock);
|
|
|
|
|
|
|
|
dmm->wa_dma_data = dma_alloc_coherent(dmm->dev, sizeof(u32),
|
|
|
|
&dmm->wa_dma_handle, GFP_KERNEL);
|
|
|
|
if (!dmm->wa_dma_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dma_cap_zero(mask);
|
|
|
|
dma_cap_set(DMA_MEMCPY, mask);
|
|
|
|
|
|
|
|
dmm->wa_dma_chan = dma_request_channel(mask, NULL, NULL);
|
|
|
|
if (!dmm->wa_dma_chan) {
|
|
|
|
dma_free_coherent(dmm->dev, 4, dmm->wa_dma_data, dmm->wa_dma_handle);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dmm_workaround_uninit(struct dmm *dmm)
|
|
|
|
{
|
|
|
|
dma_release_channel(dmm->wa_dma_chan);
|
|
|
|
|
|
|
|
dma_free_coherent(dmm->dev, 4, dmm->wa_dma_data, dmm->wa_dma_handle);
|
2015-08-07 19:31:28 +08:00
|
|
|
}
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* simple allocator to grab next 16 byte aligned memory from txn */
|
|
|
|
static void *alloc_dma(struct dmm_txn *txn, size_t sz, dma_addr_t *pa)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
struct refill_engine *engine = txn->engine_handle;
|
|
|
|
|
|
|
|
/* dmm programming requires 16 byte aligned addresses */
|
|
|
|
txn->current_pa = round_up(txn->current_pa, 16);
|
|
|
|
txn->current_va = (void *)round_up((long)txn->current_va, 16);
|
|
|
|
|
|
|
|
ptr = txn->current_va;
|
|
|
|
*pa = txn->current_pa;
|
|
|
|
|
|
|
|
txn->current_pa += sz;
|
|
|
|
txn->current_va += sz;
|
|
|
|
|
|
|
|
BUG_ON((txn->current_va - engine->refill_va) > REFILL_BUFFER_SIZE);
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check status and spin until wait_mask comes true */
|
2018-02-11 21:07:33 +08:00
|
|
|
static int wait_status(struct refill_engine *engine, u32 wait_mask)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
struct dmm *dmm = engine->dmm;
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 r = 0, err, i;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
i = DMM_FIXED_RETRY_COUNT;
|
|
|
|
while (true) {
|
2015-08-07 19:31:28 +08:00
|
|
|
r = dmm_read(dmm, reg[PAT_STATUS][engine->id]);
|
2011-12-06 09:19:21 +08:00
|
|
|
err = r & DMM_PATSTATUS_ERR;
|
2017-09-29 19:49:47 +08:00
|
|
|
if (err) {
|
|
|
|
dev_err(dmm->dev,
|
|
|
|
"%s: error (engine%d). PAT_STATUS: 0x%08x\n",
|
|
|
|
__func__, engine->id, r);
|
2011-12-06 09:19:21 +08:00
|
|
|
return -EFAULT;
|
2017-09-29 19:49:47 +08:00
|
|
|
}
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if ((r & wait_mask) == wait_mask)
|
|
|
|
break;
|
|
|
|
|
2017-09-29 19:49:47 +08:00
|
|
|
if (--i == 0) {
|
|
|
|
dev_err(dmm->dev,
|
|
|
|
"%s: timeout (engine%d). PAT_STATUS: 0x%08x\n",
|
|
|
|
__func__, engine->id, r);
|
2011-12-06 09:19:21 +08:00
|
|
|
return -ETIMEDOUT;
|
2017-09-29 19:49:47 +08:00
|
|
|
}
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
static void release_engine(struct refill_engine *engine)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
|
|
|
list_add(&engine->idle_node, &omap_dmm->idle_head);
|
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
|
|
|
|
|
|
|
atomic_inc(&omap_dmm->engine_counter);
|
|
|
|
wake_up_interruptible(&omap_dmm->engine_queue);
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:14:56 +08:00
|
|
|
static irqreturn_t omap_dmm_irq_handler(int irq, void *arg)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
struct dmm *dmm = arg;
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 status = dmm_read(dmm, DMM_PAT_IRQSTATUS);
|
2011-12-06 09:19:21 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* ack IRQ */
|
2015-08-07 19:31:28 +08:00
|
|
|
dmm_write(dmm, status, DMM_PAT_IRQSTATUS);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
for (i = 0; i < dmm->num_engines; i++) {
|
2017-09-29 19:49:48 +08:00
|
|
|
if (status & DMM_IRQSTAT_ERR_MASK)
|
|
|
|
dev_err(dmm->dev,
|
|
|
|
"irq error(engine%d): IRQSTAT 0x%02x\n",
|
|
|
|
i, status & 0xff);
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
if (status & DMM_IRQSTAT_LST) {
|
|
|
|
if (dmm->engines[i].async)
|
|
|
|
release_engine(&dmm->engines[i]);
|
drm/omap: fix race conditon in DMM
The omapdrm DMM code sometimes crashes with:
WARNING: CPU: 0 PID: 1235 at lib/list_debug.c:36 __list_add+0x8c/0xbc()
list_add double add: new=e9265368, prev=e90139c4, next=e9265368.
This is caused by the code calling release_engine() twice for the same
engine.
dmm_txn_commit(wait=true) call is supposed to wait until the DMM
transaction has been finished. And it does that, but it does not wait
for the irq handler to finish.
What happens is that the irq handler is triggered, and it either wakes
up the thread that called dmm_txn_commit(), or that thread never even
slept because the transaction was finished in the HW very quickly. That
thread then continues executing, even if the irq handler is not yet
finished, and a new transaction may be initiated. If that transaction is
async (i.e. wait=false), a 'async' flag is set to true. The original irq
handler, which has yet not finished, then sees the transaction as
'async', even if it was supposed to be 'sync'.
When that happens, the irq handler does an extra release_engine() call
because it thinks it need to release the engine, leading to the crash.
This patch fixes the issue by using completion to ensure that the irq
handler has finished before a dmm_txn_commit(wait=true) may continue.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2014-12-17 20:34:23 +08:00
|
|
|
|
|
|
|
complete(&dmm->engines[i].compl);
|
2012-10-13 00:18:11 +08:00
|
|
|
}
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
status >>= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-11-07 05:49:39 +08:00
|
|
|
/*
|
2011-12-06 09:19:21 +08:00
|
|
|
* Get a handle for a DMM transaction
|
|
|
|
*/
|
|
|
|
static struct dmm_txn *dmm_txn_init(struct dmm *dmm, struct tcm *tcm)
|
|
|
|
{
|
|
|
|
struct dmm_txn *txn = NULL;
|
|
|
|
struct refill_engine *engine = NULL;
|
2012-10-13 00:18:11 +08:00
|
|
|
int ret;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
/* wait until an engine is available */
|
|
|
|
ret = wait_event_interruptible(omap_dmm->engine_queue,
|
|
|
|
atomic_add_unless(&omap_dmm->engine_counter, -1, 0));
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
/* grab an idle engine */
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
if (!list_empty(&dmm->idle_head)) {
|
|
|
|
engine = list_entry(dmm->idle_head.next, struct refill_engine,
|
|
|
|
idle_node);
|
|
|
|
list_del(&engine->idle_node);
|
|
|
|
}
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
BUG_ON(!engine);
|
|
|
|
|
|
|
|
txn = &engine->txn;
|
|
|
|
engine->tcm = tcm;
|
|
|
|
txn->engine_handle = engine;
|
|
|
|
txn->last_pat = NULL;
|
|
|
|
txn->current_va = engine->refill_va;
|
|
|
|
txn->current_pa = engine->refill_pa;
|
|
|
|
|
|
|
|
return txn;
|
|
|
|
}
|
|
|
|
|
2020-11-07 05:49:39 +08:00
|
|
|
/*
|
2011-12-06 09:19:21 +08:00
|
|
|
* Add region to DMM transaction. If pages or pages[i] is NULL, then the
|
|
|
|
* corresponding slot is cleared (ie. dummy_pa is programmed)
|
|
|
|
*/
|
2012-10-13 00:18:11 +08:00
|
|
|
static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area,
|
2018-02-11 21:07:33 +08:00
|
|
|
struct page **pages, u32 npages, u32 roll)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
2014-07-12 17:53:41 +08:00
|
|
|
dma_addr_t pat_pa = 0, data_pa = 0;
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 *data;
|
2011-12-06 09:19:21 +08:00
|
|
|
struct pat *pat;
|
|
|
|
struct refill_engine *engine = txn->engine_handle;
|
|
|
|
int columns = (1 + area->x1 - area->x0);
|
|
|
|
int rows = (1 + area->y1 - area->y0);
|
|
|
|
int i = columns*rows;
|
|
|
|
|
2016-12-12 17:57:24 +08:00
|
|
|
pat = alloc_dma(txn, sizeof(*pat), &pat_pa);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (txn->last_pat)
|
2018-02-11 21:07:33 +08:00
|
|
|
txn->last_pat->next_pa = (u32)pat_pa;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
pat->area = *area;
|
2012-12-20 04:53:38 +08:00
|
|
|
|
|
|
|
/* adjust Y coordinates based off of container parameters */
|
|
|
|
pat->area.y0 += engine->tcm->y_offset;
|
|
|
|
pat->area.y1 += engine->tcm->y_offset;
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
pat->ctrl = (struct pat_ctrl){
|
|
|
|
.start = 1,
|
|
|
|
.lut_id = engine->tcm->lut_id,
|
|
|
|
};
|
|
|
|
|
2014-07-12 17:53:41 +08:00
|
|
|
data = alloc_dma(txn, 4*i, &data_pa);
|
|
|
|
/* FIXME: what if data_pa is more than 32-bit ? */
|
|
|
|
pat->data_pa = data_pa;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
while (i--) {
|
2011-12-10 13:26:08 +08:00
|
|
|
int n = i + roll;
|
|
|
|
if (n >= npages)
|
|
|
|
n -= npages;
|
|
|
|
data[i] = (pages && pages[n]) ?
|
|
|
|
page_to_phys(pages[n]) : engine->dmm->dummy_pa;
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
txn->last_pat = pat;
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
return;
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
2020-11-07 05:49:39 +08:00
|
|
|
/*
|
2011-12-06 09:19:21 +08:00
|
|
|
* Commit the DMM transaction.
|
|
|
|
*/
|
|
|
|
static int dmm_txn_commit(struct dmm_txn *txn, bool wait)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct refill_engine *engine = txn->engine_handle;
|
|
|
|
struct dmm *dmm = engine->dmm;
|
|
|
|
|
|
|
|
if (!txn->last_pat) {
|
|
|
|
dev_err(engine->dmm->dev, "need at least one txn\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
txn->last_pat->next_pa = 0;
|
drm/omap: fix memory barrier bug in DMM driver
A DMM timeout "timed out waiting for done" has been observed on DRA7
devices. The timeout happens rarely, and only when the system is under
heavy load.
Debugging showed that the timeout can be made to happen much more
frequently by optimizing the DMM driver, so that there's almost no code
between writing the last DMM descriptors to RAM, and writing to DMM
register which starts the DMM transaction.
The current theory is that a wmb() does not properly ensure that the
data written to RAM is observable by all the components in the system.
This DMM timeout has caused interesting (and rare) bugs as the error
handling was not functioning properly (the error handling has been fixed
in previous commits):
* If a DMM timeout happened when a GEM buffer was being pinned for
display on the screen, a timeout error would be shown, but the driver
would continue programming DSS HW with broken buffer, leading to
SYNCLOST floods and possible crashes.
* If a DMM timeout happened when other user (say, video decoder) was
pinning a GEM buffer, a timeout would be shown but if the user
handled the error properly, no other issues followed.
* If a DMM timeout happened when a GEM buffer was being released, the
driver does not even notice the error, leading to crashes or hang
later.
This patch adds wmb() and readl() calls after the last bit is written to
RAM, which should ensure that the execution proceeds only after the data
is actually in RAM, and thus observable by DMM.
The read-back should not be needed. Further study is required to understand
if DMM is somehow special case and read-back is ok, or if DRA7's memory
barriers do not work correctly.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
2018-09-26 17:11:27 +08:00
|
|
|
/* ensure that the written descriptors are visible to DMM */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: the wmb() above should be enough, but there seems to be a bug
|
|
|
|
* in OMAP's memory barrier implementation, which in some rare cases may
|
|
|
|
* cause the writes not to be observable after wmb().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* read back to ensure the data is in RAM */
|
|
|
|
readl(&txn->last_pat->next_pa);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
/* write to PAT_DESCR to clear out any pending transaction */
|
2015-08-07 19:31:28 +08:00
|
|
|
dmm_write(dmm, 0x0, reg[PAT_DESCR][engine->id]);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
/* wait for engine ready: */
|
|
|
|
ret = wait_status(engine, DMM_PATSTATUS_READY);
|
|
|
|
if (ret) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
/* mark whether it is async to denote list management in IRQ handler */
|
|
|
|
engine->async = wait ? false : true;
|
drm/omap: fix race conditon in DMM
The omapdrm DMM code sometimes crashes with:
WARNING: CPU: 0 PID: 1235 at lib/list_debug.c:36 __list_add+0x8c/0xbc()
list_add double add: new=e9265368, prev=e90139c4, next=e9265368.
This is caused by the code calling release_engine() twice for the same
engine.
dmm_txn_commit(wait=true) call is supposed to wait until the DMM
transaction has been finished. And it does that, but it does not wait
for the irq handler to finish.
What happens is that the irq handler is triggered, and it either wakes
up the thread that called dmm_txn_commit(), or that thread never even
slept because the transaction was finished in the HW very quickly. That
thread then continues executing, even if the irq handler is not yet
finished, and a new transaction may be initiated. If that transaction is
async (i.e. wait=false), a 'async' flag is set to true. The original irq
handler, which has yet not finished, then sees the transaction as
'async', even if it was supposed to be 'sync'.
When that happens, the irq handler does an extra release_engine() call
because it thinks it need to release the engine, leading to the crash.
This patch fixes the issue by using completion to ensure that the irq
handler has finished before a dmm_txn_commit(wait=true) may continue.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2014-12-17 20:34:23 +08:00
|
|
|
reinit_completion(&engine->compl);
|
|
|
|
/* verify that the irq handler sees the 'async' and completion value */
|
2014-11-10 18:23:01 +08:00
|
|
|
smp_mb();
|
2012-10-13 00:18:11 +08:00
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* kick reload */
|
2015-08-07 19:31:28 +08:00
|
|
|
dmm_write(dmm, engine->refill_pa, reg[PAT_DESCR][engine->id]);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (wait) {
|
drm/omap: fix race conditon in DMM
The omapdrm DMM code sometimes crashes with:
WARNING: CPU: 0 PID: 1235 at lib/list_debug.c:36 __list_add+0x8c/0xbc()
list_add double add: new=e9265368, prev=e90139c4, next=e9265368.
This is caused by the code calling release_engine() twice for the same
engine.
dmm_txn_commit(wait=true) call is supposed to wait until the DMM
transaction has been finished. And it does that, but it does not wait
for the irq handler to finish.
What happens is that the irq handler is triggered, and it either wakes
up the thread that called dmm_txn_commit(), or that thread never even
slept because the transaction was finished in the HW very quickly. That
thread then continues executing, even if the irq handler is not yet
finished, and a new transaction may be initiated. If that transaction is
async (i.e. wait=false), a 'async' flag is set to true. The original irq
handler, which has yet not finished, then sees the transaction as
'async', even if it was supposed to be 'sync'.
When that happens, the irq handler does an extra release_engine() call
because it thinks it need to release the engine, leading to the crash.
This patch fixes the issue by using completion to ensure that the irq
handler has finished before a dmm_txn_commit(wait=true) may continue.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2014-12-17 20:34:23 +08:00
|
|
|
if (!wait_for_completion_timeout(&engine->compl,
|
2015-04-28 19:01:32 +08:00
|
|
|
msecs_to_jiffies(100))) {
|
2011-12-06 09:19:21 +08:00
|
|
|
dev_err(dmm->dev, "timed out waiting for done\n");
|
|
|
|
ret = -ETIMEDOUT;
|
2017-09-29 19:49:49 +08:00
|
|
|
goto cleanup;
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
2017-09-29 19:49:49 +08:00
|
|
|
|
|
|
|
/* Check the engine status before continue */
|
|
|
|
ret = wait_status(engine, DMM_PATSTATUS_READY |
|
|
|
|
DMM_PATSTATUS_VALID | DMM_PATSTATUS_DONE);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2012-10-13 00:18:11 +08:00
|
|
|
/* only place engine back on list if we are done with it */
|
|
|
|
if (ret || wait)
|
|
|
|
release_engine(engine);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMM programming
|
|
|
|
*/
|
2011-12-10 13:26:08 +08:00
|
|
|
static int fill(struct tcm_area *area, struct page **pages,
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 npages, u32 roll, bool wait)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct tcm_area slice, area_s;
|
|
|
|
struct dmm_txn *txn;
|
|
|
|
|
2015-04-28 19:01:34 +08:00
|
|
|
/*
|
|
|
|
* FIXME
|
|
|
|
*
|
|
|
|
* Asynchronous fill does not work reliably, as the driver does not
|
|
|
|
* handle errors in the async code paths. The fill operation may
|
|
|
|
* silently fail, leading to leaking DMM engines, which may eventually
|
|
|
|
* lead to deadlock if we run out of DMM engines.
|
|
|
|
*
|
|
|
|
* For now, always set 'wait' so that we only use sync fills. Async
|
|
|
|
* fills should be fixed, or alternatively we could decide to only
|
|
|
|
* support sync fills and so the whole async code path could be removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
wait = true;
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
txn = dmm_txn_init(omap_dmm, area->tcm);
|
|
|
|
if (IS_ERR_OR_NULL(txn))
|
2012-11-17 03:10:57 +08:00
|
|
|
return -ENOMEM;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
tcm_for_each_slice(slice, *area, area_s) {
|
|
|
|
struct pat_area p_area = {
|
|
|
|
.x0 = slice.p0.x, .y0 = slice.p0.y,
|
|
|
|
.x1 = slice.p1.x, .y1 = slice.p1.y,
|
|
|
|
};
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
dmm_txn_append(txn, &p_area, pages, npages, roll);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
2011-12-10 13:26:08 +08:00
|
|
|
roll += tcm_sizeof(slice);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = dmm_txn_commit(txn, wait);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pin/unpin
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* note: slots for which pages[i] == NULL are filled w/ dummy page
|
|
|
|
*/
|
2011-12-10 13:26:08 +08:00
|
|
|
int tiler_pin(struct tiler_block *block, struct page **pages,
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 npages, u32 roll, bool wait)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-12-10 13:26:08 +08:00
|
|
|
ret = fill(&block->area, pages, npages, roll, wait);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
tiler_unpin(block);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tiler_unpin(struct tiler_block *block)
|
|
|
|
{
|
2011-12-10 13:26:08 +08:00
|
|
|
return fill(&block->area, NULL, 0, 0, false);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve/release
|
|
|
|
*/
|
2018-02-11 21:07:33 +08:00
|
|
|
struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt, u16 w,
|
|
|
|
u16 h, u16 align)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
2018-03-29 18:40:37 +08:00
|
|
|
struct tiler_block *block;
|
2011-12-06 09:19:21 +08:00
|
|
|
u32 min_align = 128;
|
|
|
|
int ret;
|
2012-10-13 00:18:11 +08:00
|
|
|
unsigned long flags;
|
2017-02-21 15:57:12 +08:00
|
|
|
u32 slot_bytes;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
2018-03-29 18:40:37 +08:00
|
|
|
block = kzalloc(sizeof(*block), GFP_KERNEL);
|
|
|
|
if (!block)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
BUG_ON(!validfmt(fmt));
|
|
|
|
|
|
|
|
/* convert width/height to slots */
|
|
|
|
w = DIV_ROUND_UP(w, geom[fmt].slot_w);
|
|
|
|
h = DIV_ROUND_UP(h, geom[fmt].slot_h);
|
|
|
|
|
|
|
|
/* convert alignment to slots */
|
2015-08-12 16:24:38 +08:00
|
|
|
slot_bytes = geom[fmt].slot_w * geom[fmt].cpp;
|
|
|
|
min_align = max(min_align, slot_bytes);
|
|
|
|
align = (align > min_align) ? ALIGN(align, min_align) : min_align;
|
|
|
|
align /= slot_bytes;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
block->fmt = fmt;
|
|
|
|
|
2015-08-12 16:24:38 +08:00
|
|
|
ret = tcm_reserve_2d(containers[fmt], w, h, align, -1, slot_bytes,
|
|
|
|
&block->area);
|
2011-12-06 09:19:21 +08:00
|
|
|
if (ret) {
|
|
|
|
kfree(block);
|
2012-03-22 05:40:23 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add to allocation list */
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
list_add(&block->alloc_node, &omap_dmm->alloc_head);
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct tiler_block *tiler_reserve_1d(size_t size)
|
|
|
|
{
|
|
|
|
struct tiler_block *block = kzalloc(sizeof(*block), GFP_KERNEL);
|
|
|
|
int num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
2012-10-13 00:18:11 +08:00
|
|
|
unsigned long flags;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (!block)
|
2012-08-09 13:14:56 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
block->fmt = TILFMT_PAGE;
|
|
|
|
|
|
|
|
if (tcm_reserve_1d(containers[TILFMT_PAGE], num_pages,
|
|
|
|
&block->area)) {
|
|
|
|
kfree(block);
|
2012-03-22 05:40:23 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
list_add(&block->alloc_node, &omap_dmm->alloc_head);
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: if you have pin'd pages, you should have already unpin'd first! */
|
|
|
|
int tiler_release(struct tiler_block *block)
|
|
|
|
{
|
|
|
|
int ret = tcm_free(&block->area);
|
2012-10-13 00:18:11 +08:00
|
|
|
unsigned long flags;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (block->area.tcm)
|
|
|
|
dev_err(omap_dmm->dev, "failed to release block\n");
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
list_del(&block->alloc_node);
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
kfree(block);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utils
|
|
|
|
*/
|
|
|
|
|
2012-08-16 04:18:01 +08:00
|
|
|
/* calculate the tiler space address of a pixel in a view orientation...
|
|
|
|
* below description copied from the display subsystem section of TRM:
|
|
|
|
*
|
|
|
|
* When the TILER is addressed, the bits:
|
|
|
|
* [28:27] = 0x0 for 8-bit tiled
|
|
|
|
* 0x1 for 16-bit tiled
|
|
|
|
* 0x2 for 32-bit tiled
|
|
|
|
* 0x3 for page mode
|
|
|
|
* [31:29] = 0x0 for 0-degree view
|
|
|
|
* 0x1 for 180-degree view + mirroring
|
|
|
|
* 0x2 for 0-degree view + mirroring
|
|
|
|
* 0x3 for 180-degree view
|
|
|
|
* 0x4 for 270-degree view + mirroring
|
|
|
|
* 0x5 for 270-degree view
|
|
|
|
* 0x6 for 90-degree view
|
|
|
|
* 0x7 for 90-degree view + mirroring
|
|
|
|
* Otherwise the bits indicated the corresponding bit address to access
|
|
|
|
* the SDRAM.
|
|
|
|
*/
|
|
|
|
static u32 tiler_get_address(enum tiler_fmt fmt, u32 orient, u32 x, u32 y)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
u32 x_bits, y_bits, tmp, x_mask, y_mask, alignment;
|
|
|
|
|
|
|
|
x_bits = CONT_WIDTH_BITS - geom[fmt].x_shft;
|
|
|
|
y_bits = CONT_HEIGHT_BITS - geom[fmt].y_shft;
|
|
|
|
alignment = geom[fmt].x_shft + geom[fmt].y_shft;
|
|
|
|
|
|
|
|
/* validate coordinate */
|
|
|
|
x_mask = MASK(x_bits);
|
|
|
|
y_mask = MASK(y_bits);
|
|
|
|
|
2012-08-16 04:18:01 +08:00
|
|
|
if (x < 0 || x > x_mask || y < 0 || y > y_mask) {
|
|
|
|
DBG("invalid coords: %u < 0 || %u > %u || %u < 0 || %u > %u",
|
|
|
|
x, x, x_mask, y, y, y_mask);
|
2011-12-06 09:19:21 +08:00
|
|
|
return 0;
|
2012-08-16 04:18:01 +08:00
|
|
|
}
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
/* account for mirroring */
|
|
|
|
if (orient & MASK_X_INVERT)
|
|
|
|
x ^= x_mask;
|
|
|
|
if (orient & MASK_Y_INVERT)
|
|
|
|
y ^= y_mask;
|
|
|
|
|
|
|
|
/* get coordinate address */
|
|
|
|
if (orient & MASK_XY_FLIP)
|
|
|
|
tmp = ((x << y_bits) + y);
|
|
|
|
else
|
|
|
|
tmp = ((y << x_bits) + x);
|
|
|
|
|
|
|
|
return TIL_ADDR((tmp << alignment), orient, fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_addr_t tiler_ssptr(struct tiler_block *block)
|
|
|
|
{
|
|
|
|
BUG_ON(!validfmt(block->fmt));
|
|
|
|
|
2012-08-16 04:18:01 +08:00
|
|
|
return TILVIEW_8BIT + tiler_get_address(block->fmt, 0,
|
2011-12-06 09:19:21 +08:00
|
|
|
block->area.p0.x * geom[block->fmt].slot_w,
|
|
|
|
block->area.p0.y * geom[block->fmt].slot_h);
|
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
dma_addr_t tiler_tsptr(struct tiler_block *block, u32 orient,
|
|
|
|
u32 x, u32 y)
|
2012-08-16 04:18:01 +08:00
|
|
|
{
|
|
|
|
struct tcm_pt *p = &block->area.p0;
|
|
|
|
BUG_ON(!validfmt(block->fmt));
|
|
|
|
|
|
|
|
return tiler_get_address(block->fmt, orient,
|
|
|
|
(p->x * geom[block->fmt].slot_w) + x,
|
|
|
|
(p->y * geom[block->fmt].slot_h) + y);
|
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
void tiler_align(enum tiler_fmt fmt, u16 *w, u16 *h)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
BUG_ON(!validfmt(fmt));
|
|
|
|
*w = round_up(*w, geom[fmt].slot_w);
|
|
|
|
*h = round_up(*h, geom[fmt].slot_h);
|
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 tiler_stride(enum tiler_fmt fmt, u32 orient)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
BUG_ON(!validfmt(fmt));
|
|
|
|
|
2012-08-16 04:18:01 +08:00
|
|
|
if (orient & MASK_XY_FLIP)
|
|
|
|
return 1 << (CONT_HEIGHT_BITS + geom[fmt].x_shft);
|
|
|
|
else
|
|
|
|
return 1 << (CONT_WIDTH_BITS + geom[fmt].y_shft);
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
size_t tiler_size(enum tiler_fmt fmt, u16 w, u16 h)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
tiler_align(fmt, &w, &h);
|
|
|
|
return geom[fmt].cpp * w * h;
|
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
size_t tiler_vsize(enum tiler_fmt fmt, u16 w, u16 h)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
BUG_ON(!validfmt(fmt));
|
|
|
|
return round_up(geom[fmt].cpp * w, PAGE_SIZE) * h;
|
|
|
|
}
|
|
|
|
|
2018-02-11 21:07:33 +08:00
|
|
|
u32 tiler_get_cpu_cache_flags(void)
|
2014-09-26 03:24:29 +08:00
|
|
|
{
|
|
|
|
return omap_dmm->plat_data->cpu_cache_flags;
|
|
|
|
}
|
|
|
|
|
2012-10-17 13:30:03 +08:00
|
|
|
bool dmm_is_available(void)
|
2012-03-06 00:48:39 +08:00
|
|
|
{
|
|
|
|
return omap_dmm ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_dmm_remove(struct platform_device *dev)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
struct tiler_block *block, *_block;
|
|
|
|
int i;
|
2012-10-13 00:18:11 +08:00
|
|
|
unsigned long flags;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (omap_dmm) {
|
2018-09-26 17:11:29 +08:00
|
|
|
/* Disable all enabled interrupts */
|
|
|
|
dmm_write(omap_dmm, 0x7e7e7e7e, DMM_PAT_IRQENABLE_CLR);
|
|
|
|
free_irq(omap_dmm->irq, omap_dmm);
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* free all area regions */
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
list_for_each_entry_safe(block, _block, &omap_dmm->alloc_head,
|
|
|
|
alloc_node) {
|
|
|
|
list_del(&block->alloc_node);
|
|
|
|
kfree(block);
|
|
|
|
}
|
2012-10-13 00:18:11 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
for (i = 0; i < omap_dmm->num_lut; i++)
|
|
|
|
if (omap_dmm->tcm && omap_dmm->tcm[i])
|
|
|
|
omap_dmm->tcm[i]->deinit(omap_dmm->tcm[i]);
|
|
|
|
kfree(omap_dmm->tcm);
|
|
|
|
|
|
|
|
kfree(omap_dmm->engines);
|
|
|
|
if (omap_dmm->refill_va)
|
dma, mm/pat: Rename dma_*_writecombine() to dma_*_wc()
Rename dma_*_writecombine() to dma_*_wc(), so that the naming
is coherent across the various write-combining APIs. Keep the
old names for compatibility for a while, these can be removed
at a later time. A guard is left to enable backporting of the
rename, and later remove of the old mapping defines seemlessly.
Build tested successfully with allmodconfig.
The following Coccinelle SmPL patch was used for this simple
transformation:
@ rename_dma_alloc_writecombine @
expression dev, size, dma_addr, gfp;
@@
-dma_alloc_writecombine(dev, size, dma_addr, gfp)
+dma_alloc_wc(dev, size, dma_addr, gfp)
@ rename_dma_free_writecombine @
expression dev, size, cpu_addr, dma_addr;
@@
-dma_free_writecombine(dev, size, cpu_addr, dma_addr)
+dma_free_wc(dev, size, cpu_addr, dma_addr)
@ rename_dma_mmap_writecombine @
expression dev, vma, cpu_addr, dma_addr, size;
@@
-dma_mmap_writecombine(dev, vma, cpu_addr, dma_addr, size)
+dma_mmap_wc(dev, vma, cpu_addr, dma_addr, size)
We also keep the old names as compatibility helpers, and
guard against their definition to make backporting easier.
Generated-by: Coccinelle SmPL
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bhelgaas@google.com
Cc: bp@suse.de
Cc: dan.j.williams@intel.com
Cc: daniel.vetter@ffwll.ch
Cc: dhowells@redhat.com
Cc: julia.lawall@lip6.fr
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: luto@amacapital.net
Cc: mst@redhat.com
Cc: tomi.valkeinen@ti.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1453516462-4844-1-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-23 10:34:22 +08:00
|
|
|
dma_free_wc(omap_dmm->dev,
|
|
|
|
REFILL_BUFFER_SIZE * omap_dmm->num_engines,
|
|
|
|
omap_dmm->refill_va, omap_dmm->refill_pa);
|
2011-12-06 09:19:21 +08:00
|
|
|
if (omap_dmm->dummy_page)
|
|
|
|
__free_page(omap_dmm->dummy_page);
|
|
|
|
|
2018-09-26 17:11:30 +08:00
|
|
|
if (omap_dmm->dmm_workaround)
|
|
|
|
dmm_workaround_uninit(omap_dmm);
|
|
|
|
|
2012-03-06 00:48:39 +08:00
|
|
|
iounmap(omap_dmm->base);
|
2011-12-06 09:19:21 +08:00
|
|
|
kfree(omap_dmm);
|
2012-03-06 00:48:39 +08:00
|
|
|
omap_dmm = NULL;
|
2011-12-06 09:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-06 00:48:39 +08:00
|
|
|
static int omap_dmm_probe(struct platform_device *dev)
|
2011-12-06 09:19:21 +08:00
|
|
|
{
|
|
|
|
int ret = -EFAULT, i;
|
|
|
|
struct tcm_area area = {0};
|
2012-10-12 12:06:43 +08:00
|
|
|
u32 hwinfo, pat_geom;
|
2012-03-06 00:48:39 +08:00
|
|
|
struct resource *mem;
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
omap_dmm = kzalloc(sizeof(*omap_dmm), GFP_KERNEL);
|
2013-02-12 01:41:29 +08:00
|
|
|
if (!omap_dmm)
|
2011-12-06 09:19:21 +08:00
|
|
|
goto fail;
|
|
|
|
|
2012-05-25 00:43:32 +08:00
|
|
|
/* initialize lists */
|
|
|
|
INIT_LIST_HEAD(&omap_dmm->alloc_head);
|
|
|
|
INIT_LIST_HEAD(&omap_dmm->idle_head);
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
init_waitqueue_head(&omap_dmm->engine_queue);
|
|
|
|
|
2014-09-26 03:24:29 +08:00
|
|
|
if (dev->dev.of_node) {
|
|
|
|
const struct of_device_id *match;
|
|
|
|
|
|
|
|
match = of_match_node(dmm_of_match, dev->dev.of_node);
|
|
|
|
if (!match) {
|
|
|
|
dev_err(&dev->dev, "failed to find matching device node\n");
|
2017-09-24 14:01:03 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto fail;
|
2014-09-26 03:24:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
omap_dmm->plat_data = match->data;
|
|
|
|
}
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* lookup hwmod data - base address and irq */
|
2012-03-06 00:48:39 +08:00
|
|
|
mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
|
|
|
if (!mem) {
|
|
|
|
dev_err(&dev->dev, "failed to get base address resource\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-09-26 17:11:30 +08:00
|
|
|
omap_dmm->phys_base = mem->start;
|
2012-03-06 00:48:39 +08:00
|
|
|
omap_dmm->base = ioremap(mem->start, SZ_2K);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (!omap_dmm->base) {
|
2012-03-06 00:48:39 +08:00
|
|
|
dev_err(&dev->dev, "failed to get dmm base address\n");
|
2011-12-06 09:19:21 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-03-06 00:48:39 +08:00
|
|
|
omap_dmm->irq = platform_get_irq(dev, 0);
|
2022-08-10 14:27:38 +08:00
|
|
|
if (omap_dmm->irq < 0)
|
2012-03-06 00:48:39 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
omap_dmm->dev = &dev->dev;
|
|
|
|
|
2018-09-26 17:11:30 +08:00
|
|
|
if (of_machine_is_compatible("ti,dra7")) {
|
|
|
|
/*
|
|
|
|
* DRA7 Errata i878 says that MPU should not be used to access
|
|
|
|
* RAM and DMM at the same time. As it's not possible to prevent
|
|
|
|
* MPU accessing RAM, we need to access DMM via a proxy.
|
|
|
|
*/
|
|
|
|
if (!dmm_workaround_init(omap_dmm)) {
|
|
|
|
omap_dmm->dmm_workaround = true;
|
|
|
|
dev_info(&dev->dev,
|
|
|
|
"workaround for errata i878 in use\n");
|
|
|
|
} else {
|
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"failed to initialize work-around for i878\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 19:31:28 +08:00
|
|
|
hwinfo = dmm_read(omap_dmm, DMM_PAT_HWINFO);
|
2011-12-06 09:19:21 +08:00
|
|
|
omap_dmm->num_engines = (hwinfo >> 24) & 0x1F;
|
|
|
|
omap_dmm->num_lut = (hwinfo >> 16) & 0x1F;
|
|
|
|
omap_dmm->container_width = 256;
|
|
|
|
omap_dmm->container_height = 128;
|
|
|
|
|
2012-10-13 00:18:11 +08:00
|
|
|
atomic_set(&omap_dmm->engine_counter, omap_dmm->num_engines);
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* read out actual LUT width and height */
|
2015-08-07 19:31:28 +08:00
|
|
|
pat_geom = dmm_read(omap_dmm, DMM_PAT_GEOMETRY);
|
2011-12-06 09:19:21 +08:00
|
|
|
omap_dmm->lut_width = ((pat_geom >> 16) & 0xF) << 5;
|
|
|
|
omap_dmm->lut_height = ((pat_geom >> 24) & 0xF) << 5;
|
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
/* increment LUT by one if on OMAP5 */
|
|
|
|
/* LUT has twice the height, and is split into a separate container */
|
|
|
|
if (omap_dmm->lut_height != omap_dmm->container_height)
|
|
|
|
omap_dmm->num_lut++;
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* initialize DMM registers */
|
2015-08-07 19:31:28 +08:00
|
|
|
dmm_write(omap_dmm, 0x88888888, DMM_PAT_VIEW__0);
|
|
|
|
dmm_write(omap_dmm, 0x88888888, DMM_PAT_VIEW__1);
|
|
|
|
dmm_write(omap_dmm, 0x80808080, DMM_PAT_VIEW_MAP__0);
|
|
|
|
dmm_write(omap_dmm, 0x80000000, DMM_PAT_VIEW_MAP_BASE);
|
|
|
|
dmm_write(omap_dmm, 0x88888888, DMM_TILER_OR__0);
|
|
|
|
dmm_write(omap_dmm, 0x88888888, DMM_TILER_OR__1);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
omap_dmm->dummy_page = alloc_page(GFP_KERNEL | __GFP_DMA32);
|
|
|
|
if (!omap_dmm->dummy_page) {
|
2012-03-06 00:48:39 +08:00
|
|
|
dev_err(&dev->dev, "could not allocate dummy page\n");
|
2011-12-06 09:19:21 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-03-06 00:48:39 +08:00
|
|
|
|
|
|
|
/* set dma mask for device */
|
2013-06-11 01:41:59 +08:00
|
|
|
ret = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
2012-03-06 00:48:39 +08:00
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
omap_dmm->dummy_pa = page_to_phys(omap_dmm->dummy_page);
|
|
|
|
|
|
|
|
/* alloc refill memory */
|
dma, mm/pat: Rename dma_*_writecombine() to dma_*_wc()
Rename dma_*_writecombine() to dma_*_wc(), so that the naming
is coherent across the various write-combining APIs. Keep the
old names for compatibility for a while, these can be removed
at a later time. A guard is left to enable backporting of the
rename, and later remove of the old mapping defines seemlessly.
Build tested successfully with allmodconfig.
The following Coccinelle SmPL patch was used for this simple
transformation:
@ rename_dma_alloc_writecombine @
expression dev, size, dma_addr, gfp;
@@
-dma_alloc_writecombine(dev, size, dma_addr, gfp)
+dma_alloc_wc(dev, size, dma_addr, gfp)
@ rename_dma_free_writecombine @
expression dev, size, cpu_addr, dma_addr;
@@
-dma_free_writecombine(dev, size, cpu_addr, dma_addr)
+dma_free_wc(dev, size, cpu_addr, dma_addr)
@ rename_dma_mmap_writecombine @
expression dev, vma, cpu_addr, dma_addr, size;
@@
-dma_mmap_writecombine(dev, vma, cpu_addr, dma_addr, size)
+dma_mmap_wc(dev, vma, cpu_addr, dma_addr, size)
We also keep the old names as compatibility helpers, and
guard against their definition to make backporting easier.
Generated-by: Coccinelle SmPL
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bhelgaas@google.com
Cc: bp@suse.de
Cc: dan.j.williams@intel.com
Cc: daniel.vetter@ffwll.ch
Cc: dhowells@redhat.com
Cc: julia.lawall@lip6.fr
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: luto@amacapital.net
Cc: mst@redhat.com
Cc: tomi.valkeinen@ti.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1453516462-4844-1-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-23 10:34:22 +08:00
|
|
|
omap_dmm->refill_va = dma_alloc_wc(&dev->dev,
|
|
|
|
REFILL_BUFFER_SIZE * omap_dmm->num_engines,
|
|
|
|
&omap_dmm->refill_pa, GFP_KERNEL);
|
2011-12-06 09:19:21 +08:00
|
|
|
if (!omap_dmm->refill_va) {
|
2012-03-06 00:48:39 +08:00
|
|
|
dev_err(&dev->dev, "could not allocate refill memory\n");
|
2020-11-17 14:10:45 +08:00
|
|
|
ret = -ENOMEM;
|
2011-12-06 09:19:21 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* alloc engines */
|
2013-02-12 01:41:29 +08:00
|
|
|
omap_dmm->engines = kcalloc(omap_dmm->num_engines,
|
2016-12-12 17:57:24 +08:00
|
|
|
sizeof(*omap_dmm->engines), GFP_KERNEL);
|
2011-12-06 09:19:21 +08:00
|
|
|
if (!omap_dmm->engines) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < omap_dmm->num_engines; i++) {
|
|
|
|
omap_dmm->engines[i].id = i;
|
|
|
|
omap_dmm->engines[i].dmm = omap_dmm;
|
|
|
|
omap_dmm->engines[i].refill_va = omap_dmm->refill_va +
|
|
|
|
(REFILL_BUFFER_SIZE * i);
|
|
|
|
omap_dmm->engines[i].refill_pa = omap_dmm->refill_pa +
|
|
|
|
(REFILL_BUFFER_SIZE * i);
|
drm/omap: fix race conditon in DMM
The omapdrm DMM code sometimes crashes with:
WARNING: CPU: 0 PID: 1235 at lib/list_debug.c:36 __list_add+0x8c/0xbc()
list_add double add: new=e9265368, prev=e90139c4, next=e9265368.
This is caused by the code calling release_engine() twice for the same
engine.
dmm_txn_commit(wait=true) call is supposed to wait until the DMM
transaction has been finished. And it does that, but it does not wait
for the irq handler to finish.
What happens is that the irq handler is triggered, and it either wakes
up the thread that called dmm_txn_commit(), or that thread never even
slept because the transaction was finished in the HW very quickly. That
thread then continues executing, even if the irq handler is not yet
finished, and a new transaction may be initiated. If that transaction is
async (i.e. wait=false), a 'async' flag is set to true. The original irq
handler, which has yet not finished, then sees the transaction as
'async', even if it was supposed to be 'sync'.
When that happens, the irq handler does an extra release_engine() call
because it thinks it need to release the engine, leading to the crash.
This patch fixes the issue by using completion to ensure that the irq
handler has finished before a dmm_txn_commit(wait=true) may continue.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2014-12-17 20:34:23 +08:00
|
|
|
init_completion(&omap_dmm->engines[i].compl);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
list_add(&omap_dmm->engines[i].idle_node, &omap_dmm->idle_head);
|
|
|
|
}
|
|
|
|
|
2013-02-12 01:41:29 +08:00
|
|
|
omap_dmm->tcm = kcalloc(omap_dmm->num_lut, sizeof(*omap_dmm->tcm),
|
2011-12-06 09:19:21 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!omap_dmm->tcm) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init containers */
|
2012-12-20 04:53:38 +08:00
|
|
|
/* Each LUT is associated with a TCM (container manager). We use the
|
|
|
|
lut_id to denote the lut_id used to identify the correct LUT for
|
|
|
|
programming during reill operations */
|
2011-12-06 09:19:21 +08:00
|
|
|
for (i = 0; i < omap_dmm->num_lut; i++) {
|
|
|
|
omap_dmm->tcm[i] = sita_init(omap_dmm->container_width,
|
2015-08-12 16:24:38 +08:00
|
|
|
omap_dmm->container_height);
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
if (!omap_dmm->tcm[i]) {
|
2012-03-06 00:48:39 +08:00
|
|
|
dev_err(&dev->dev, "failed to allocate container\n");
|
2011-12-06 09:19:21 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
omap_dmm->tcm[i]->lut_id = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign access mode containers to applicable tcm container */
|
|
|
|
/* OMAP 4 has 1 container for all 4 views */
|
2012-12-20 04:53:38 +08:00
|
|
|
/* OMAP 5 has 2 containers, 1 for 2D and 1 for 1D */
|
2011-12-06 09:19:21 +08:00
|
|
|
containers[TILFMT_8BIT] = omap_dmm->tcm[0];
|
|
|
|
containers[TILFMT_16BIT] = omap_dmm->tcm[0];
|
|
|
|
containers[TILFMT_32BIT] = omap_dmm->tcm[0];
|
2012-12-20 04:53:38 +08:00
|
|
|
|
|
|
|
if (omap_dmm->container_height != omap_dmm->lut_height) {
|
|
|
|
/* second LUT is used for PAGE mode. Programming must use
|
|
|
|
y offset that is added to all y coordinates. LUT id is still
|
|
|
|
0, because it is the same LUT, just the upper 128 lines */
|
|
|
|
containers[TILFMT_PAGE] = omap_dmm->tcm[1];
|
|
|
|
omap_dmm->tcm[1]->y_offset = OMAP5_LUT_OFFSET;
|
|
|
|
omap_dmm->tcm[1]->lut_id = 0;
|
|
|
|
} else {
|
|
|
|
containers[TILFMT_PAGE] = omap_dmm->tcm[0];
|
|
|
|
}
|
2011-12-06 09:19:21 +08:00
|
|
|
|
|
|
|
area = (struct tcm_area) {
|
|
|
|
.tcm = NULL,
|
|
|
|
.p1.x = omap_dmm->container_width - 1,
|
|
|
|
.p1.y = omap_dmm->container_height - 1,
|
|
|
|
};
|
|
|
|
|
2018-09-26 17:11:29 +08:00
|
|
|
ret = request_irq(omap_dmm->irq, omap_dmm_irq_handler, IRQF_SHARED,
|
|
|
|
"omap_dmm_irq_handler", omap_dmm);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&dev->dev, "couldn't register IRQ %d, error %d\n",
|
|
|
|
omap_dmm->irq, ret);
|
|
|
|
omap_dmm->irq = -1;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable all interrupts for each refill engine except
|
|
|
|
* ERR_LUT_MISS<n> (which is just advisory, and we don't care
|
|
|
|
* about because we want to be able to refill live scanout
|
|
|
|
* buffers for accelerated pan/scroll) and FILL_DSC<n> which
|
|
|
|
* we just generally don't care about.
|
|
|
|
*/
|
|
|
|
dmm_write(omap_dmm, 0x7e7e7e7e, DMM_PAT_IRQENABLE_SET);
|
|
|
|
|
2011-12-06 09:19:21 +08:00
|
|
|
/* initialize all LUTs to dummy page entries */
|
|
|
|
for (i = 0; i < omap_dmm->num_lut; i++) {
|
|
|
|
area.tcm = omap_dmm->tcm[i];
|
2011-12-10 13:26:08 +08:00
|
|
|
if (fill(&area, NULL, 0, 0, true))
|
2011-12-06 09:19:21 +08:00
|
|
|
dev_err(omap_dmm->dev, "refill failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(omap_dmm->dev, "initialized all PAT entries\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2012-05-25 00:43:32 +08:00
|
|
|
if (omap_dmm_remove(dev))
|
|
|
|
dev_err(&dev->dev, "cleanup failed\n");
|
2011-12-06 09:19:21 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2011-12-16 11:05:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* debugfs support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
|
|
|
|
static const char *alphabet = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
static const char *special = ".,:;'\"`~!^-+";
|
|
|
|
|
|
|
|
static void fill_map(char **map, int xdiv, int ydiv, struct tcm_area *a,
|
|
|
|
char c, bool ovw)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = a->p0.y / ydiv; y <= a->p1.y / ydiv; y++)
|
|
|
|
for (x = a->p0.x / xdiv; x <= a->p1.x / xdiv; x++)
|
|
|
|
if (map[y][x] == ' ' || ovw)
|
|
|
|
map[y][x] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_map_pt(char **map, int xdiv, int ydiv, struct tcm_pt *p,
|
|
|
|
char c)
|
|
|
|
{
|
|
|
|
map[p->y / ydiv][p->x / xdiv] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char read_map_pt(char **map, int xdiv, int ydiv, struct tcm_pt *p)
|
|
|
|
{
|
|
|
|
return map[p->y / ydiv][p->x / xdiv];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int map_width(int xdiv, int x0, int x1)
|
|
|
|
{
|
|
|
|
return (x1 / xdiv) - (x0 / xdiv) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void text_map(char **map, int xdiv, char *nice, int yd, int x0, int x1)
|
|
|
|
{
|
|
|
|
char *p = map[yd] + (x0 / xdiv);
|
|
|
|
int w = (map_width(xdiv, x0, x1) - strlen(nice)) / 2;
|
|
|
|
if (w >= 0) {
|
|
|
|
p += w;
|
|
|
|
while (*nice)
|
|
|
|
*p++ = *nice++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void map_1d_info(char **map, int xdiv, int ydiv, char *nice,
|
|
|
|
struct tcm_area *a)
|
|
|
|
{
|
|
|
|
sprintf(nice, "%dK", tcm_sizeof(*a) * 4);
|
|
|
|
if (a->p0.y + 1 < a->p1.y) {
|
|
|
|
text_map(map, xdiv, nice, (a->p0.y + a->p1.y) / 2 / ydiv, 0,
|
|
|
|
256 - 1);
|
|
|
|
} else if (a->p0.y < a->p1.y) {
|
|
|
|
if (strlen(nice) < map_width(xdiv, a->p0.x, 256 - 1))
|
|
|
|
text_map(map, xdiv, nice, a->p0.y / ydiv,
|
|
|
|
a->p0.x + xdiv, 256 - 1);
|
|
|
|
else if (strlen(nice) < map_width(xdiv, 0, a->p1.x))
|
|
|
|
text_map(map, xdiv, nice, a->p1.y / ydiv,
|
|
|
|
0, a->p1.y - xdiv);
|
|
|
|
} else if (strlen(nice) + 1 < map_width(xdiv, a->p0.x, a->p1.x)) {
|
|
|
|
text_map(map, xdiv, nice, a->p0.y / ydiv, a->p0.x, a->p1.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void map_2d_info(char **map, int xdiv, int ydiv, char *nice,
|
|
|
|
struct tcm_area *a)
|
|
|
|
{
|
|
|
|
sprintf(nice, "(%d*%d)", tcm_awidth(*a), tcm_aheight(*a));
|
|
|
|
if (strlen(nice) + 1 < map_width(xdiv, a->p0.x, a->p1.x))
|
|
|
|
text_map(map, xdiv, nice, (a->p0.y + a->p1.y) / 2 / ydiv,
|
|
|
|
a->p0.x, a->p1.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tiler_map_show(struct seq_file *s, void *arg)
|
|
|
|
{
|
|
|
|
int xdiv = 2, ydiv = 1;
|
|
|
|
char **map = NULL, *global_map;
|
|
|
|
struct tiler_block *block;
|
|
|
|
struct tcm_area a, p;
|
|
|
|
int i;
|
|
|
|
const char *m2d = alphabet;
|
|
|
|
const char *a2d = special;
|
|
|
|
const char *m2dp = m2d, *a2dp = a2d;
|
|
|
|
char nice[128];
|
2012-03-06 00:48:38 +08:00
|
|
|
int h_adj;
|
|
|
|
int w_adj;
|
2011-12-16 11:05:17 +08:00
|
|
|
unsigned long flags;
|
2012-12-20 04:53:38 +08:00
|
|
|
int lut_idx;
|
|
|
|
|
2011-12-16 11:05:17 +08:00
|
|
|
|
2012-03-06 00:48:38 +08:00
|
|
|
if (!omap_dmm) {
|
|
|
|
/* early return if dmm/tiler device is not initialized */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
h_adj = omap_dmm->container_height / ydiv;
|
|
|
|
w_adj = omap_dmm->container_width / xdiv;
|
2012-03-06 00:48:38 +08:00
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
map = kmalloc_array(h_adj, sizeof(*map), GFP_KERNEL);
|
|
|
|
global_map = kmalloc_array(w_adj + 1, h_adj, GFP_KERNEL);
|
2011-12-16 11:05:17 +08:00
|
|
|
|
|
|
|
if (!map || !global_map)
|
|
|
|
goto error;
|
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
for (lut_idx = 0; lut_idx < omap_dmm->num_lut; lut_idx++) {
|
2013-08-22 20:42:50 +08:00
|
|
|
memset(map, 0, h_adj * sizeof(*map));
|
2012-12-20 04:53:38 +08:00
|
|
|
memset(global_map, ' ', (w_adj + 1) * h_adj);
|
2011-12-16 11:05:17 +08:00
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
for (i = 0; i < omap_dmm->container_height; i++) {
|
|
|
|
map[i] = global_map + i * (w_adj + 1);
|
|
|
|
map[i][w_adj] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&list_lock, flags);
|
|
|
|
|
|
|
|
list_for_each_entry(block, &omap_dmm->alloc_head, alloc_node) {
|
|
|
|
if (block->area.tcm == omap_dmm->tcm[lut_idx]) {
|
|
|
|
if (block->fmt != TILFMT_PAGE) {
|
|
|
|
fill_map(map, xdiv, ydiv, &block->area,
|
|
|
|
*m2dp, true);
|
|
|
|
if (!*++a2dp)
|
|
|
|
a2dp = a2d;
|
|
|
|
if (!*++m2dp)
|
|
|
|
m2dp = m2d;
|
|
|
|
map_2d_info(map, xdiv, ydiv, nice,
|
|
|
|
&block->area);
|
|
|
|
} else {
|
|
|
|
bool start = read_map_pt(map, xdiv,
|
|
|
|
ydiv, &block->area.p0) == ' ';
|
|
|
|
bool end = read_map_pt(map, xdiv, ydiv,
|
|
|
|
&block->area.p1) == ' ';
|
|
|
|
|
|
|
|
tcm_for_each_slice(a, block->area, p)
|
|
|
|
fill_map(map, xdiv, ydiv, &a,
|
|
|
|
'=', true);
|
|
|
|
fill_map_pt(map, xdiv, ydiv,
|
|
|
|
&block->area.p0,
|
2011-12-16 11:05:17 +08:00
|
|
|
start ? '<' : 'X');
|
2012-12-20 04:53:38 +08:00
|
|
|
fill_map_pt(map, xdiv, ydiv,
|
|
|
|
&block->area.p1,
|
2011-12-16 11:05:17 +08:00
|
|
|
end ? '>' : 'X');
|
2012-12-20 04:53:38 +08:00
|
|
|
map_1d_info(map, xdiv, ydiv, nice,
|
|
|
|
&block->area);
|
|
|
|
}
|
|
|
|
}
|
2011-12-16 11:05:17 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
spin_unlock_irqrestore(&list_lock, flags);
|
2011-12-16 11:05:17 +08:00
|
|
|
|
2012-12-20 04:53:38 +08:00
|
|
|
if (s) {
|
|
|
|
seq_printf(s, "CONTAINER %d DUMP BEGIN\n", lut_idx);
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
seq_printf(s, "%03d:%s\n", i, map[i]);
|
|
|
|
seq_printf(s, "CONTAINER %d DUMP END\n", lut_idx);
|
|
|
|
} else {
|
|
|
|
dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP BEGIN\n",
|
|
|
|
lut_idx);
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
dev_dbg(omap_dmm->dev, "%03d:%s\n", i, map[i]);
|
|
|
|
dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP END\n",
|
|
|
|
lut_idx);
|
|
|
|
}
|
2011-12-16 11:05:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree(map);
|
|
|
|
kfree(global_map);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-06 00:48:39 +08:00
|
|
|
|
2015-02-26 02:08:20 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2012-12-20 04:53:37 +08:00
|
|
|
static int omap_dmm_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tcm_area area;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!omap_dmm)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
area = (struct tcm_area) {
|
|
|
|
.tcm = NULL,
|
|
|
|
.p1.x = omap_dmm->container_width - 1,
|
|
|
|
.p1.y = omap_dmm->container_height - 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* initialize all LUTs to dummy page entries */
|
|
|
|
for (i = 0; i < omap_dmm->num_lut; i++) {
|
|
|
|
area.tcm = omap_dmm->tcm[i];
|
|
|
|
if (fill(&area, NULL, 0, 0, true))
|
|
|
|
dev_err(dev, "refill failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-26 02:08:20 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(omap_dmm_pm_ops, NULL, omap_dmm_resume);
|
|
|
|
|
2013-10-15 15:04:20 +08:00
|
|
|
#if defined(CONFIG_OF)
|
2014-09-26 03:24:29 +08:00
|
|
|
static const struct dmm_platform_data dmm_omap4_platform_data = {
|
|
|
|
.cpu_cache_flags = OMAP_BO_WC,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dmm_platform_data dmm_omap5_platform_data = {
|
|
|
|
.cpu_cache_flags = OMAP_BO_UNCACHED,
|
|
|
|
};
|
|
|
|
|
2013-10-15 15:04:20 +08:00
|
|
|
static const struct of_device_id dmm_of_match[] = {
|
2014-09-26 03:24:29 +08:00
|
|
|
{
|
|
|
|
.compatible = "ti,omap4-dmm",
|
|
|
|
.data = &dmm_omap4_platform_data,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "ti,omap5-dmm",
|
|
|
|
.data = &dmm_omap5_platform_data,
|
|
|
|
},
|
2013-10-15 15:04:20 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-03-06 00:48:39 +08:00
|
|
|
struct platform_driver omap_dmm_driver = {
|
|
|
|
.probe = omap_dmm_probe,
|
|
|
|
.remove = omap_dmm_remove,
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = DMM_DRIVER_NAME,
|
2013-10-15 15:04:20 +08:00
|
|
|
.of_match_table = of_match_ptr(dmm_of_match),
|
2012-12-20 04:53:37 +08:00
|
|
|
.pm = &omap_dmm_pm_ops,
|
2012-03-06 00:48:39 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_AUTHOR("Andy Gross <andy.gross@ti.com>");
|
|
|
|
MODULE_DESCRIPTION("OMAP DMM/Tiler Driver");
|