lkml.org 
[lkml]   [2002]   [Feb]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] meye driver update
This patch (+ BK changeset) converts the meye driver to the
new DMA API.

Linus, please apply, this patch is necessary for the driver
to be used in 2.5. Once the v4l2 patches get in, I'll submit
a larger update.

Marcelo, please put this on the queue for the next -pre1, this
patch has some minor improvements over the old one.

Stelian.

ChangeSet@1.332, 2002-02-15 16:35:31+01:00, stelian@popies.net
Convert to the new DMA API and allocate separate DMA pages instead of one big buffer.

diff -Nru a/drivers/media/video/meye.c b/drivers/media/video/meye.c
--- a/drivers/media/video/meye.c Fri Feb 15 16:36:44 2002
+++ b/drivers/media/video/meye.c Fri Feb 15 16:36:44 2002
@@ -142,25 +142,6 @@
return ret;
}

-static inline unsigned long uvirt_to_bus(unsigned long adr) {
- unsigned long kva, ret;
-
- kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
- ret = virt_to_bus((void *)kva);
- MDEBUG(printk("uv2b(%lx-->%lx)\n", adr, ret));
- return ret;
-}
-
-static inline unsigned long kvirt_to_bus(unsigned long adr) {
- unsigned long va, kva, ret;
-
- va = VMALLOC_VMADDR(adr);
- kva = uvirt_to_kva(pgd_offset_k(va), va);
- ret = virt_to_bus((void *)kva);
- MDEBUG(printk("kv2b(%lx-->%lx)\n", adr, ret));
- return ret;
-}
-
/* Here we want the physical address of the memory.
* This is used when initializing the contents of the
* area and marking the pages as reserved.
@@ -209,31 +190,64 @@
}

/* return a page table pointing to N pages of locked memory */
-static void *ptable_alloc(int npages, u32 *pt_addr) {
+static int ptable_alloc(void) {
+ u32 *pt;
int i;
- void *vmem;
- u32 *ptable;
- unsigned long adr;
-
- vmem = rvmalloc((npages + 1) * PAGE_SIZE);
- if (!vmem)
- return NULL;
-
- adr = (unsigned long)vmem;
- ptable = (u32 *)(vmem + npages * PAGE_SIZE);
- for (i = 0; i < npages; i++) {
- ptable[i] = (u32) kvirt_to_bus(adr);
- adr += PAGE_SIZE;
+
+ memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
+
+ meye.mchip_ptable[MCHIP_NB_PAGES] = pci_alloc_consistent(meye.mchip_dev,
+ PAGE_SIZE,
+ &meye.mchip_dmahandle);
+ if (!meye.mchip_ptable[MCHIP_NB_PAGES])
+ return -1;
+
+ pt = (u32 *)meye.mchip_ptable[MCHIP_NB_PAGES];
+ for (i = 0; i < MCHIP_NB_PAGES; i++) {
+ meye.mchip_ptable[i] = pci_alloc_consistent(meye.mchip_dev,
+ PAGE_SIZE,
+ pt);
+ if (!meye.mchip_ptable[i])
+ return -1;
+ pt++;
}
+ return 0;
+}
+
+static void ptable_free(void) {
+ u32 *pt;
+ int i;

- *pt_addr = (u32) kvirt_to_bus(adr);
- return vmem;
+ pt = (u32 *)meye.mchip_ptable[MCHIP_NB_PAGES];
+ for (i = 0; i < MCHIP_NB_PAGES; i++)
+ if (meye.mchip_ptable[i])
+ pci_free_consistent(meye.mchip_dev,
+ PAGE_SIZE,
+ meye.mchip_ptable[i], *pt);
+
+ if (meye.mchip_ptable[MCHIP_NB_PAGES])
+ pci_free_consistent(meye.mchip_dev,
+ PAGE_SIZE,
+ meye.mchip_ptable[MCHIP_NB_PAGES],
+ meye.mchip_dmahandle);
+
+ memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
+ meye.mchip_dmahandle = 0;
}

-static void ptable_free(void *vmem, int npages) {
- rvfree(vmem, (npages + 1) * PAGE_SIZE);
+/* copy data from ptable into buf */
+static void ptable_copy(u8 *buf, int start, int size, int pt_pages) {
+ int i;
+
+ for (i = 0; i < (size / PAGE_SIZE) * PAGE_SIZE; i += PAGE_SIZE) {
+ memcpy(buf + i, meye.mchip_ptable[start++], PAGE_SIZE);
+ if (start >= pt_pages)
+ start = 0;
+ }
+ memcpy(buf + i, meye.mchip_ptable[start], size % PAGE_SIZE);
}

+
/****************************************************************************/
/* JPEG tables at different qualities to load into the VRJ chip */
/****************************************************************************/
@@ -587,29 +601,23 @@

/* setup for DMA transfers - also zeros the framebuffer */
static int mchip_dma_alloc(void) {
- if (!meye.mchip_fbuffer) {
- meye.mchip_fbuffer = ptable_alloc(MCHIP_NB_PAGES,
- &meye.mchip_ptaddr);
- if (!meye.mchip_fbuffer)
+ if (!meye.mchip_dmahandle)
+ if (ptable_alloc())
return -1;
- }
return 0;
}

/* frees the DMA buffer */
static void mchip_dma_free(void) {
- if (meye.mchip_fbuffer) {
- ptable_free(meye.mchip_fbuffer, MCHIP_NB_PAGES);
- meye.mchip_fbuffer = 0;
- meye.mchip_ptaddr = 0;
- }
+ if (meye.mchip_dmahandle)
+ ptable_free();
}

/* sets the DMA parameters into the chip */
static void mchip_dma_setup(void) {
int i;

- mchip_set(MCHIP_MM_PT_ADDR, meye.mchip_ptaddr);
+ mchip_set(MCHIP_MM_PT_ADDR, meye.mchip_dmahandle);
for (i = 0; i < 4; i++)
mchip_set(MCHIP_MM_FIR(i), 0);
meye.mchip_fnum = 0;
@@ -658,59 +666,40 @@
meye.mchip_fnum %= 4;
}

-
/* read one frame from the framebuffer assuming it was captured using
a uncompressed transfer */
-static void mchip_cont_read_frame(u32 v, u8 *buf, int size) {
+static void mchip_cont_read_frame(u32 v, u8 *buf, int size) {
int pt_id;
- int avail;

pt_id = (v >> 17) & 0x3FF;
- avail = MCHIP_NB_PAGES - pt_id;

- if (size > avail*PAGE_SIZE) {
- memcpy(buf, meye.mchip_fbuffer + pt_id * PAGE_SIZE,
- avail * PAGE_SIZE);
- memcpy(buf +avail * PAGE_SIZE, meye.mchip_fbuffer,
- size - avail * PAGE_SIZE);
- }
- else
- memcpy(buf, meye.mchip_fbuffer + pt_id * PAGE_SIZE, size);
+ ptable_copy(buf, pt_id, size, MCHIP_NB_PAGES);
+
}

/* read a compressed frame from the framebuffer */
static int mchip_comp_read_frame(u32 v, u8 *buf, int size) {
int pt_start, pt_end, trailer;
- int fsize, fsize2;
+ int fsize;
int i;

pt_start = (v >> 19) & 0xFF;
pt_end = (v >> 11) & 0xFF;
trailer = (v >> 1) & 0x3FF;

- if (pt_end < pt_start) {
- fsize = (MCHIP_NB_PAGES_MJPEG - pt_start) * PAGE_SIZE;
- fsize2 = pt_end * PAGE_SIZE + trailer * 4;
- if (fsize + fsize2 > size) {
- printk(KERN_WARNING "meye: oversized compressed frame %d %d\n",
- fsize, fsize2);
- return -1;
- } else {
- memcpy(buf, meye.mchip_fbuffer + pt_start * PAGE_SIZE,
- fsize);
- memcpy(buf + fsize, meye.mchip_fbuffer, fsize2);
- fsize += fsize2;
- }
- } else {
+ if (pt_end < pt_start)
+ fsize = (MCHIP_NB_PAGES_MJPEG - pt_start) * PAGE_SIZE +
+ pt_end * PAGE_SIZE + trailer * 4;
+ else
fsize = (pt_end - pt_start) * PAGE_SIZE + trailer * 4;
- if (fsize > size) {
- printk(KERN_WARNING "meye: oversized compressed frame %d\n",
- fsize);
- return -1;
- } else
- memcpy(buf, meye.mchip_fbuffer + pt_start * PAGE_SIZE,
- fsize);
+
+ if (fsize > size) {
+ printk(KERN_WARNING "meye: oversized compressed frame %d\n",
+ fsize);
+ return -1;
}
+
+ ptable_copy(buf, pt_start, fsize, MCHIP_NB_PAGES_MJPEG);


#ifdef MEYE_JPEG_CORRECTION
diff -Nru a/drivers/media/video/meye.h b/drivers/media/video/meye.h
--- a/drivers/media/video/meye.h Fri Feb 15 16:36:44 2002
+++ b/drivers/media/video/meye.h Fri Feb 15 16:36:44 2002
@@ -29,7 +29,7 @@
#define _MEYE_PRIV_H_

#define MEYE_DRIVER_MAJORVERSION 1
-#define MEYE_DRIVER_MINORVERSION 1
+#define MEYE_DRIVER_MINORVERSION 2

/****************************************************************************/
/* Motion JPEG chip registers */
@@ -292,8 +292,8 @@
u8 mchip_fnum; /* current mchip frame number */

unsigned char *mchip_mmregs; /* mchip: memory mapped registers */
- unsigned char *mchip_fbuffer; /* mchip: framebuffer */
- u32 mchip_ptaddr; /* mchip: pointer to framebuffer */
+ u8 *mchip_ptable[MCHIP_NB_PAGES+1];/* mchip: ptable + ptable toc */
+ dma_addr_t mchip_dmahandle; /* mchip: dma handle to ptable toc */

unsigned char *grab_fbuffer; /* capture framebuffer */
/* list of buffers */

================================================================

This BitKeeper patch contains the following changesets:
+
## Wrapped with gzip_uu ##


begin 664 bkpatch3256
M'XL(``TK;3P``]58:7/;-A#]3/R*;3+M2-8%\-019>*8&D=-Y6CDIIVVR7`H
M$HPX$8\A*:=IE?_>!2A9DDV?:3Z$UI@TN+MX>/MV`?DIO,UYUE?R@B]#-R9/
MX562%WTE3=*0Y^V8%S@T2Q(<ZBR2B'>*,`Z352?/O,[\8V<9QJN_6VK;(&@V
M=0MO`1<\R_L*:VN7(\7GE/>5V>CT[2_',T*&0SA9N/$'?LX+&`Y)D607[M+/
M7[C%8IG$[2)SXSSBA=OVDFA]:;I6*57QQV"61@USS4RJ6VN/^8RY.N,^5?6N
MJ9.+,$M>1!BJG>:K-O=7UR(P365H3-=:MZ<:Q`;$JJE`U0Y^F`',[&M&7V,-
MROJ4PH:9%SM&H*%"BY*7\/\B/R$>G"0Q\E=@9"@6'&+^">S),1Q/Q^#&/KC+
M9>*Y!8><IVXF'L3;U/W`<PAC1.KZD`20Q!SFX0>8KX*`9VWR&C1+,W0RW1%/
M6@^\"*$N)<]Q,DQI]8+]+!3)[T3<#]W.1>CS!)\_\[:W8Z#'J,;6NLH,?6T8
MKNNYNN6KZMRCK(+INT,R@QF:1I%4G?:L1^);7,>G6<;:UX+`ZJE=CVO!W`R,
M!P%<7`6H8@JH5/_-BQ+E\.T(_KK0)J5,TWIKW>J:5%:->5@S6I^:M]2,Q:#5
M5;^KJBDU]09:V2?YP2J8WI*]1]24S70DKT=LE:G`R%C<5)(7;A%ZB*V`M'#G
M2^[()=0NDM"OP[]$66&_.DJ+@?#3@6GHJ)K`+/*.*!&/<E[4)*3(6X2I4\9H
M`FU"'O[#D^#ZRWI]4/I>&?]K<O)J/'7.7CK3X]/1^7L80NJ%)1S'2^(\1/K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/DPQ.5_*+P%]S[FJVB(:9L'ON63_P"_
'M#-V&!$`````
`
end
--
Stelian Pop <stelian.pop@fr.alcove.com>
Alcove - http://www.alcove.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:24    [W:0.039 / U:6.736 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site