2019-05-20 07:19:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
btcx-risc.c
|
|
|
|
|
|
|
|
bt848/bt878/cx2388x risc code generator.
|
|
|
|
|
|
|
|
(c) 2000-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-10-14 09:33:25 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/videodev2.h>
|
2020-06-09 04:32:38 +00:00
|
|
|
#include <linux/pgtable.h>
|
2020-06-09 04:32:42 +00:00
|
|
|
#include <asm/page.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "btcx-risc.h"
|
|
|
|
|
2014-12-12 13:27:56 +00:00
|
|
|
static unsigned int btcx_debug;
|
|
|
|
module_param(btcx_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(btcx_debug,"debug messages, default is 0 (no)");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-10-14 09:33:25 +00:00
|
|
|
#define dprintk(fmt, arg...) do { \
|
|
|
|
if (btcx_debug) \
|
|
|
|
printk(KERN_DEBUG pr_fmt("%s: " fmt), \
|
|
|
|
__func__, ##arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* ---------------------------------------------------------- */
|
|
|
|
/* allocate/free risc memory */
|
|
|
|
|
|
|
|
static int memcnt;
|
|
|
|
|
|
|
|
void btcx_riscmem_free(struct pci_dev *pci,
|
|
|
|
struct btcx_riscmem *risc)
|
|
|
|
{
|
|
|
|
if (NULL == risc->cpu)
|
|
|
|
return;
|
2016-10-14 09:33:25 +00:00
|
|
|
|
|
|
|
memcnt--;
|
|
|
|
dprintk("btcx: riscmem free [%d] dma=%lx\n",
|
|
|
|
memcnt, (unsigned long)risc->dma);
|
|
|
|
|
media: bt8xx: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'bt878_mem_alloc()' (bt878.c), GFP_KERNEL can
be used because it is only called from the probe function (i.e.
'bt878_probe()') and no lock is taken.
When memory is allocated in 'btcx_riscmem_alloc()' (btcx-risc.c),
GFP_KERNEL can be used because all the callers either already use
GFP_KERNEL or are called from a probe function or are called from a
.buf_prepare function.
The 4 callers are all in 'bttv-risc.c'.
- bttv_risc_packed() and bttv_risc_planar(): only called from
'videobuf_queue_ops''s '.buf_prepare' functions.
The call chains are:
.buf_prepare (in 'bttv-driver.c')
--> buffer_prepare (in 'bttv-driver.c')
--> bttv_prepare_buffer
--> bttv_buffer_risc
--> bttv_risc_packed (x8 times)
--> bttv_risc_planar (x6 times)
.buf_prepare (in 'bttv-vbi.c')
--> vbi_buffer_prepare (in 'bttv-vbi.c')
--> bttv_risc_packed (x2 times)
- bttv_risc_overlay(): already uses GFP_KERNEL
- bttv_risc_init_main(): only called from the 'bttv_probe()' probe
function and no spin_lock is taken in the between
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-07-27 13:51:37 +00:00
|
|
|
dma_free_coherent(&pci->dev, risc->size, risc->cpu, risc->dma);
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(risc,0,sizeof(*risc));
|
|
|
|
}
|
|
|
|
|
|
|
|
int btcx_riscmem_alloc(struct pci_dev *pci,
|
|
|
|
struct btcx_riscmem *risc,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
2008-05-21 03:31:51 +00:00
|
|
|
__le32 *cpu;
|
2008-08-22 20:01:45 +00:00
|
|
|
dma_addr_t dma = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (NULL != risc->cpu && risc->size < size)
|
|
|
|
btcx_riscmem_free(pci,risc);
|
|
|
|
if (NULL == risc->cpu) {
|
media: bt8xx: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'bt878_mem_alloc()' (bt878.c), GFP_KERNEL can
be used because it is only called from the probe function (i.e.
'bt878_probe()') and no lock is taken.
When memory is allocated in 'btcx_riscmem_alloc()' (btcx-risc.c),
GFP_KERNEL can be used because all the callers either already use
GFP_KERNEL or are called from a probe function or are called from a
.buf_prepare function.
The 4 callers are all in 'bttv-risc.c'.
- bttv_risc_packed() and bttv_risc_planar(): only called from
'videobuf_queue_ops''s '.buf_prepare' functions.
The call chains are:
.buf_prepare (in 'bttv-driver.c')
--> buffer_prepare (in 'bttv-driver.c')
--> bttv_prepare_buffer
--> bttv_buffer_risc
--> bttv_risc_packed (x8 times)
--> bttv_risc_planar (x6 times)
.buf_prepare (in 'bttv-vbi.c')
--> vbi_buffer_prepare (in 'bttv-vbi.c')
--> bttv_risc_packed (x2 times)
- bttv_risc_overlay(): already uses GFP_KERNEL
- bttv_risc_init_main(): only called from the 'bttv_probe()' probe
function and no spin_lock is taken in the between
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-07-27 13:51:37 +00:00
|
|
|
cpu = dma_alloc_coherent(&pci->dev, size, &dma, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (NULL == cpu)
|
|
|
|
return -ENOMEM;
|
|
|
|
risc->cpu = cpu;
|
|
|
|
risc->dma = dma;
|
|
|
|
risc->size = size;
|
2016-10-14 09:33:25 +00:00
|
|
|
|
|
|
|
memcnt++;
|
|
|
|
dprintk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
|
|
|
|
memcnt, (unsigned long)dma, cpu, size);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------- */
|
|
|
|
/* screen overlay helpers */
|
|
|
|
|
|
|
|
int
|
|
|
|
btcx_screen_clips(int swidth, int sheight, struct v4l2_rect *win,
|
|
|
|
struct v4l2_clip *clips, unsigned int n)
|
|
|
|
{
|
|
|
|
if (win->left < 0) {
|
|
|
|
/* left */
|
|
|
|
clips[n].c.left = 0;
|
|
|
|
clips[n].c.top = 0;
|
|
|
|
clips[n].c.width = -win->left;
|
|
|
|
clips[n].c.height = win->height;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (win->left + win->width > swidth) {
|
|
|
|
/* right */
|
|
|
|
clips[n].c.left = swidth - win->left;
|
|
|
|
clips[n].c.top = 0;
|
|
|
|
clips[n].c.width = win->width - clips[n].c.left;
|
|
|
|
clips[n].c.height = win->height;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (win->top < 0) {
|
|
|
|
/* top */
|
|
|
|
clips[n].c.left = 0;
|
|
|
|
clips[n].c.top = 0;
|
|
|
|
clips[n].c.width = win->width;
|
|
|
|
clips[n].c.height = -win->top;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (win->top + win->height > sheight) {
|
|
|
|
/* bottom */
|
|
|
|
clips[n].c.left = 0;
|
|
|
|
clips[n].c.top = sheight - win->top;
|
|
|
|
clips[n].c.width = win->width;
|
|
|
|
clips[n].c.height = win->height - clips[n].c.top;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips, unsigned int n, int mask)
|
|
|
|
{
|
|
|
|
s32 nx,nw,dx;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* fixup window */
|
|
|
|
nx = (win->left + mask) & ~mask;
|
|
|
|
nw = (win->width) & ~mask;
|
|
|
|
if (nx + nw > win->left + win->width)
|
|
|
|
nw -= mask+1;
|
|
|
|
dx = nx - win->left;
|
|
|
|
win->left = nx;
|
|
|
|
win->width = nw;
|
2016-10-14 09:33:25 +00:00
|
|
|
dprintk("btcx: window align %dx%d+%d+%d [dx=%d]\n",
|
|
|
|
win->width, win->height, win->left, win->top, dx);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* fixup clips */
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nx = (clips[i].c.left-dx) & ~mask;
|
|
|
|
nw = (clips[i].c.width) & ~mask;
|
|
|
|
if (nx + nw < clips[i].c.left-dx + clips[i].c.width)
|
|
|
|
nw += mask+1;
|
|
|
|
clips[i].c.left = nx;
|
|
|
|
clips[i].c.width = nw;
|
2016-10-14 09:33:25 +00:00
|
|
|
dprintk("btcx: clip align %dx%d+%d+%d\n",
|
|
|
|
clips[i].c.width, clips[i].c.height,
|
|
|
|
clips[i].c.left, clips[i].c.top);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips)
|
|
|
|
{
|
|
|
|
int i,j,n;
|
|
|
|
|
|
|
|
if (nclips < 2)
|
|
|
|
return;
|
|
|
|
for (i = nclips-2; i >= 0; i--) {
|
|
|
|
for (n = 0, j = 0; j <= i; j++) {
|
|
|
|
if (clips[j].c.left > clips[j+1].c.left) {
|
2015-06-10 16:33:45 +00:00
|
|
|
swap(clips[j], clips[j + 1]);
|
2005-04-16 22:20:36 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 == n)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-03 20:11:54 +00:00
|
|
|
btcx_calc_skips(int line, int width, int *maxy,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct btcx_skiplist *skips, unsigned int *nskips,
|
|
|
|
const struct v4l2_clip *clips, unsigned int nclips)
|
|
|
|
{
|
|
|
|
unsigned int clip,skip;
|
2008-09-03 20:11:54 +00:00
|
|
|
int end, maxline;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
skip=0;
|
|
|
|
maxline = 9999;
|
|
|
|
for (clip = 0; clip < nclips; clip++) {
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (clips[clip].c.left + clips[clip].c.width <= 0)
|
|
|
|
continue;
|
|
|
|
if (clips[clip].c.left > (signed)width)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* vertical range */
|
|
|
|
if (line > clips[clip].c.top+clips[clip].c.height-1)
|
|
|
|
continue;
|
|
|
|
if (line < clips[clip].c.top) {
|
|
|
|
if (maxline > clips[clip].c.top-1)
|
|
|
|
maxline = clips[clip].c.top-1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (maxline > clips[clip].c.top+clips[clip].c.height-1)
|
|
|
|
maxline = clips[clip].c.top+clips[clip].c.height-1;
|
|
|
|
|
|
|
|
/* horizontal range */
|
|
|
|
if (0 == skip || clips[clip].c.left > skips[skip-1].end) {
|
|
|
|
/* new one */
|
|
|
|
skips[skip].start = clips[clip].c.left;
|
|
|
|
if (skips[skip].start < 0)
|
|
|
|
skips[skip].start = 0;
|
|
|
|
skips[skip].end = clips[clip].c.left + clips[clip].c.width;
|
|
|
|
if (skips[skip].end > width)
|
|
|
|
skips[skip].end = width;
|
|
|
|
skip++;
|
|
|
|
} else {
|
|
|
|
/* overlaps -- expand last one */
|
|
|
|
end = clips[clip].c.left + clips[clip].c.width;
|
|
|
|
if (skips[skip-1].end < end)
|
|
|
|
skips[skip-1].end = end;
|
|
|
|
if (skips[skip-1].end > width)
|
|
|
|
skips[skip-1].end = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*nskips = skip;
|
|
|
|
*maxy = maxline;
|
|
|
|
|
2014-12-12 13:27:56 +00:00
|
|
|
if (btcx_debug) {
|
2016-10-14 09:33:25 +00:00
|
|
|
dprintk("btcx: skips line %d-%d:", line, maxline);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (skip = 0; skip < *nskips; skip++) {
|
2016-10-14 09:33:25 +00:00
|
|
|
pr_cont(" %d-%d", skips[skip].start, skips[skip].end);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-10-14 09:33:25 +00:00
|
|
|
pr_cont("\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|