Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1517b039 authored by Takashi Saito's avatar Takashi Saito Committed by Mauro Carvalho Chehab
Browse files

[media] v4l: vsp1: Add display list support



Display lists contain lists of registers and associated values to be
applied atomically by the hardware. They lower the pressure on interrupt
processing delays when reprogramming the device as settings can be
prepared well in advance and queued to the hardware without waiting for
the end of the current frame.

Display list support is currently limited to the DRM pipeline.

Signed-off-by: default avatarKoji Matsuoka <koji.matsuoka.xm@renesas.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 7f2d50f8
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
vsp1-y					:= vsp1_drv.o vsp1_entity.o vsp1_pipe.o
vsp1-y					:= vsp1_drv.o vsp1_entity.o vsp1_pipe.o
vsp1-y					+= vsp1_drm.o vsp1_video.o
vsp1-y					+= vsp1_dl.o vsp1_drm.o vsp1_video.o
vsp1-y					+= vsp1_rpf.o vsp1_rwpf.o vsp1_wpf.o
vsp1-y					+= vsp1_rpf.o vsp1_rwpf.o vsp1_wpf.o
vsp1-y					+= vsp1_hsit.o vsp1_lif.o vsp1_lut.o
vsp1-y					+= vsp1_hsit.o vsp1_lif.o vsp1_lut.o
vsp1-y					+= vsp1_bru.o vsp1_sru.o vsp1_uds.o
vsp1-y					+= vsp1_bru.o vsp1_sru.o vsp1_uds.o
+17 −0
Original line number Original line Diff line number Diff line
@@ -26,7 +26,9 @@
struct clk;
struct clk;
struct device;
struct device;


struct vsp1_dl;
struct vsp1_drm;
struct vsp1_drm;
struct vsp1_entity;
struct vsp1_platform_data;
struct vsp1_platform_data;
struct vsp1_bru;
struct vsp1_bru;
struct vsp1_hsit;
struct vsp1_hsit;
@@ -80,12 +82,17 @@ struct vsp1_device {
	struct v4l2_device v4l2_dev;
	struct v4l2_device v4l2_dev;
	struct media_device media_dev;
	struct media_device media_dev;
	struct media_entity_operations media_ops;
	struct media_entity_operations media_ops;

	struct vsp1_drm *drm;
	struct vsp1_drm *drm;

	bool use_dl;
};
};


int vsp1_device_get(struct vsp1_device *vsp1);
int vsp1_device_get(struct vsp1_device *vsp1);
void vsp1_device_put(struct vsp1_device *vsp1);
void vsp1_device_put(struct vsp1_device *vsp1);


int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index);

static inline u32 vsp1_read(struct vsp1_device *vsp1, u32 reg)
static inline u32 vsp1_read(struct vsp1_device *vsp1, u32 reg)
{
{
	return ioread32(vsp1->mmio + reg);
	return ioread32(vsp1->mmio + reg);
@@ -96,4 +103,14 @@ static inline void vsp1_write(struct vsp1_device *vsp1, u32 reg, u32 data)
	iowrite32(data, vsp1->mmio + reg);
	iowrite32(data, vsp1->mmio + reg);
}
}


#include "vsp1_dl.h"

static inline void vsp1_mod_write(struct vsp1_entity *e, u32 reg, u32 data)
{
	if (e->vsp1->use_dl)
		vsp1_dl_add(e, reg, data);
	else
		vsp1_write(e->vsp1, reg, data);
}

#endif /* __VSP1_H__ */
#endif /* __VSP1_H__ */
+1 −1
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@


static inline void vsp1_bru_write(struct vsp1_bru *bru, u32 reg, u32 data)
static inline void vsp1_bru_write(struct vsp1_bru *bru, u32 reg, u32 data)
{
{
	vsp1_write(bru->entity.vsp1, reg, data);
	vsp1_mod_write(&bru->entity, reg, data);
}
}


/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
+305 −0
Original line number Original line Diff line number Diff line
/*
 * vsp1_dl.h  --  R-Car VSP1 Display List
 *
 * Copyright (C) 2015 Renesas Corporation
 *
 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/gfp.h>
#include <linux/slab.h>

#include "vsp1.h"
#include "vsp1_dl.h"
#include "vsp1_pipe.h"

/*
 * Global resources
 *
 * - Display-related interrupts (can be used for vblank evasion ?)
 * - Display-list enable
 * - Header-less for WPF0
 * - DL swap
 */

#define VSP1_DL_BODY_SIZE		(2 * 4 * 256)
#define VSP1_DL_NUM_LISTS		3

struct vsp1_dl_entry {
	u32 addr;
	u32 data;
} __attribute__((__packed__));

struct vsp1_dl_list {
	size_t size;
	int reg_count;

	bool in_use;

	struct vsp1_dl_entry *body;
	dma_addr_t dma;
};

/**
 * struct vsp1_dl - Display List manager
 * @vsp1: the VSP1 device
 * @lock: protects the active, queued and pending lists
 * @lists.all: array of all allocate display lists
 * @lists.active: list currently being processed (loaded) by hardware
 * @lists.queued: list queued to the hardware (written to the DL registers)
 * @lists.pending: list waiting to be queued to the hardware
 * @lists.write: list being written to by software
 */
struct vsp1_dl {
	struct vsp1_device *vsp1;

	spinlock_t lock;

	size_t size;
	dma_addr_t dma;
	void *mem;

	struct {
		struct vsp1_dl_list all[VSP1_DL_NUM_LISTS];

		struct vsp1_dl_list *active;
		struct vsp1_dl_list *queued;
		struct vsp1_dl_list *pending;
		struct vsp1_dl_list *write;
	} lists;
};

/* -----------------------------------------------------------------------------
 * Display List Transaction Management
 */

static void vsp1_dl_free_list(struct vsp1_dl_list *list)
{
	if (!list)
		return;

	list->in_use = false;
}

void vsp1_dl_reset(struct vsp1_dl *dl)
{
	unsigned int i;

	dl->lists.active = NULL;
	dl->lists.queued = NULL;
	dl->lists.pending = NULL;
	dl->lists.write = NULL;

	for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i)
		dl->lists.all[i].in_use = false;
}

void vsp1_dl_begin(struct vsp1_dl *dl)
{
	struct vsp1_dl_list *list = NULL;
	unsigned long flags;
	unsigned int i;

	spin_lock_irqsave(&dl->lock, flags);

	for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i) {
		if (!dl->lists.all[i].in_use) {
			list = &dl->lists.all[i];
			break;
		}
	}

	if (!list) {
		list = dl->lists.pending;
		dl->lists.pending = NULL;
	}

	spin_unlock_irqrestore(&dl->lock, flags);

	dl->lists.write = list;

	list->in_use = true;
	list->reg_count = 0;
}

void vsp1_dl_add(struct vsp1_entity *e, u32 reg, u32 data)
{
	struct vsp1_pipeline *pipe = to_vsp1_pipeline(&e->subdev.entity);
	struct vsp1_dl *dl = pipe->dl;
	struct vsp1_dl_list *list = dl->lists.write;

	list->body[list->reg_count].addr = reg;
	list->body[list->reg_count].data = data;
	list->reg_count++;
}

void vsp1_dl_commit(struct vsp1_dl *dl)
{
	struct vsp1_device *vsp1 = dl->vsp1;
	struct vsp1_dl_list *list;
	unsigned long flags;
	bool update;

	list = dl->lists.write;
	dl->lists.write = NULL;

	spin_lock_irqsave(&dl->lock, flags);

	/* Once the UPD bit has been set the hardware can start processing the
	 * display list at any time and we can't touch the address and size
	 * registers. In that case mark the update as pending, it will be
	 * queued up to the hardware by the frame end interrupt handler.
	 */
	update = !!(vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD);
	if (update) {
		vsp1_dl_free_list(dl->lists.pending);
		dl->lists.pending = list;
		goto done;
	}

	/* Program the hardware with the display list body address and size.
	 * The UPD bit will be cleared by the device when the display list is
	 * processed.
	 */
	vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), list->dma);
	vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD |
		   (list->reg_count * 8));

	vsp1_dl_free_list(dl->lists.queued);
	dl->lists.queued = list;

done:
	spin_unlock_irqrestore(&dl->lock, flags);
}

/* -----------------------------------------------------------------------------
 * Interrupt Handling
 */

void vsp1_dl_irq_display_start(struct vsp1_dl *dl)
{
	spin_lock(&dl->lock);

	/* The display start interrupt signals the end of the display list
	 * processing by the device. The active display list, if any, won't be
	 * accessed anymore and can be reused.
	 */
	if (dl->lists.active) {
		vsp1_dl_free_list(dl->lists.active);
		dl->lists.active = NULL;
	}

	spin_unlock(&dl->lock);
}

void vsp1_dl_irq_frame_end(struct vsp1_dl *dl)
{
	struct vsp1_device *vsp1 = dl->vsp1;

	spin_lock(&dl->lock);

	/* The UPD bit set indicates that the commit operation raced with the
	 * interrupt and occurred after the frame end event and UPD clear but
	 * before interrupt processing. The hardware hasn't taken the update
	 * into account yet, we'll thus skip one frame and retry.
	 */
	if (vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD)
		goto done;

	/* The device starts processing the queued display list right after the
	 * frame end interrupt. The display list thus becomes active.
	 */
	if (dl->lists.queued) {
		WARN_ON(dl->lists.active);
		dl->lists.active = dl->lists.queued;
		dl->lists.queued = NULL;
	}

	/* Now that the UPD bit has been cleared we can queue the next display
	 * list to the hardware if one has been prepared.
	 */
	if (dl->lists.pending) {
		struct vsp1_dl_list *list = dl->lists.pending;

		vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), list->dma);
		vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD |
			   (list->reg_count * 8));

		dl->lists.queued = list;
		dl->lists.pending = NULL;
	}

done:
	spin_unlock(&dl->lock);
}

/* -----------------------------------------------------------------------------
 * Hardware Setup
 */

void vsp1_dl_setup(struct vsp1_device *vsp1)
{
	u32 ctrl = (256 << VI6_DL_CTRL_AR_WAIT_SHIFT)
		 | VI6_DL_CTRL_DC2 | VI6_DL_CTRL_DC1 | VI6_DL_CTRL_DC0
		 | VI6_DL_CTRL_DLE;

	/* The DRM pipeline operates with header-less display lists in
	 * Continuous Frame Mode.
	 */
	if (vsp1->drm)
		ctrl |= VI6_DL_CTRL_CFM0 | VI6_DL_CTRL_NH0;

	vsp1_write(vsp1, VI6_DL_CTRL, ctrl);
	vsp1_write(vsp1, VI6_DL_SWAP, VI6_DL_SWAP_LWS);
}

/* -----------------------------------------------------------------------------
 * Initialization and Cleanup
 */

struct vsp1_dl *vsp1_dl_create(struct vsp1_device *vsp1)
{
	struct vsp1_dl *dl;
	unsigned int i;

	dl = kzalloc(sizeof(*dl), GFP_KERNEL);
	if (!dl)
		return NULL;

	spin_lock_init(&dl->lock);

	dl->vsp1 = vsp1;
	dl->size = VSP1_DL_BODY_SIZE * ARRAY_SIZE(dl->lists.all);

	dl->mem = dma_alloc_writecombine(vsp1->dev, dl->size, &dl->dma,
					 GFP_KERNEL);
	if (!dl->mem) {
		kfree(dl);
		return NULL;
	}

	for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i) {
		struct vsp1_dl_list *list = &dl->lists.all[i];

		list->size = VSP1_DL_BODY_SIZE;
		list->reg_count = 0;
		list->in_use = false;
		list->dma = dl->dma + VSP1_DL_BODY_SIZE * i;
		list->body = dl->mem + VSP1_DL_BODY_SIZE * i;
	}

	return dl;
}

void vsp1_dl_destroy(struct vsp1_dl *dl)
{
	dma_free_writecombine(dl->vsp1->dev, dl->size, dl->mem, dl->dma);
	kfree(dl);
}
+42 −0
Original line number Original line Diff line number Diff line
/*
 * vsp1_dl.h  --  R-Car VSP1 Display List
 *
 * Copyright (C) 2015 Renesas Corporation
 *
 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */
#ifndef __VSP1_DL_H__
#define __VSP1_DL_H__

#include "vsp1_entity.h"

struct vsp1_device;
struct vsp1_dl;

struct vsp1_dl *vsp1_dl_create(struct vsp1_device *vsp1);
void vsp1_dl_destroy(struct vsp1_dl *dl);

void vsp1_dl_setup(struct vsp1_device *vsp1);

void vsp1_dl_reset(struct vsp1_dl *dl);
void vsp1_dl_begin(struct vsp1_dl *dl);
void vsp1_dl_add(struct vsp1_entity *e, u32 reg, u32 data);
void vsp1_dl_commit(struct vsp1_dl *dl);

void vsp1_dl_irq_display_start(struct vsp1_dl *dl);
void vsp1_dl_irq_frame_end(struct vsp1_dl *dl);

static inline void vsp1_dl_mod_write(struct vsp1_entity *e, u32 reg, u32 data)
{
	if (e->vsp1->use_dl)
		vsp1_dl_add(e, reg, data);
	else
		vsp1_write(e->vsp1, reg, data);
}

#endif /* __VSP1_DL_H__ */
Loading