patch-2.4.22 linux-2.4.22/arch/cris/drivers/examples/kiobuftest.c
Next file: linux-2.4.22/arch/cris/drivers/gpio.c
Previous file: linux-2.4.22/arch/cris/drivers/ethernet.c
Back to the patch index
Back to the overall index
- Lines: 138
- Date:
2003-08-25 04:44:39.000000000 -0700
- Orig file:
linux-2.4.21/arch/cris/drivers/examples/kiobuftest.c
- Orig date:
2001-04-06 10:42:55.000000000 -0700
diff -urN linux-2.4.21/arch/cris/drivers/examples/kiobuftest.c linux-2.4.22/arch/cris/drivers/examples/kiobuftest.c
@@ -4,18 +4,12 @@
*
* It is necessary because the pages the virtual pointers reference, might
* not exist in memory (could be mapped to the zero-page, filemapped etc)
- * and DMA cannot trigger the MMU to force them in (and would have time
+ * and DMA cannot trigger the MMU to force them in (and would have time
* contraints making it impossible to wait for it anyway).
*
- * Author: Bjorn Wesen
- *
- * $Log: kiobuftest.c,v $
- * Revision 1.2 2001/02/27 13:52:50 bjornw
- * malloc.h -> slab.h
- *
- * Revision 1.1 2001/01/19 15:57:49 bjornw
- * Example of how to do direct HW -> user-mode DMA
+ * Copyright (c) 2001, 2002, 2003 Axis Communications AB
*
+ * Author: Bjorn Wesen
*
*/
@@ -32,55 +26,55 @@
#define KIOBUFTEST_MAJOR 124 /* in the local range, experimental */
-
static ssize_t
kiobuf_read(struct file *filp, char *buf, size_t len, loff_t *ppos)
{
+ struct kiobuf *iobuf;
+ int res, i;
- struct kiobuf *iobuf;
- int res, i;
-
- /* Make a kiobuf that maps the entire length the reader has given
- * us
- */
-
- res = alloc_kiovec(1, &iobuf);
- if (res)
- return res;
-
- if((res = map_user_kiobuf(READ, iobuf, (unsigned long)buf, len))) {
- printk("map_user_kiobuf failed, return %d\n", res);
- return res;
- }
-
- /* At this point, the virtual area buf[0] -> buf[len-1] will
- * have corresponding pages mapped in physical memory and locked
- * until we unmap the kiobuf. They cannot be swapped out or moved
- * around.
- */
-
- printk("nr_pages == %d\noffset == %d\nlength == %d\n",
- iobuf->nr_pages, iobuf->offset, iobuf->length);
-
- for(i = 0; i < iobuf->nr_pages; i++) {
- printk("page_add(maplist[%d]) == 0x%x\n", i,
- page_address(iobuf->maplist[i]));
- }
-
- /* This is the place to create the necessary scatter-gather vector
- * for the DMA using the iobuf->maplist array and page_address
- * (don't forget __pa if the DMA needs the actual physical DRAM address)
- * and run it.
- */
+ /*
+ * Make a kiobuf that maps the entire length the reader has given us.
+ */
+ res = alloc_kiovec(1, &iobuf);
+ if (res)
+ return res;
+
+ if ((res = map_user_kiobuf(READ, iobuf, (unsigned long)buf, len))) {
+ printk("map_user_kiobuf failed, return %d\n", res);
+ free_kiovec(1, &iobuf);
+ return res;
+ }
+
+ /*
+ * At this point, the virtual area buf[0] -> buf[len-1] will have
+ * corresponding pages mapped in physical memory and locked until
+ * we unmap the kiobuf. They cannot be swapped out or moved around.
+ */
+
+ printk("nr_pages == %d\noffset == %d\nlength == %d\n",
+ iobuf->nr_pages, iobuf->offset, iobuf->length);
+
+ for (i = 0; i < iobuf->nr_pages; i++) {
+ printk("page_add(maplist[%d]) == 0x%x\n", i,
+ page_address(iobuf->maplist[i]));
+ }
+
+ /*
+ * This is the place to create the necessary scatter-gather vector
+ * for the DMA using the iobuf->maplist array and page_address (don't
+ * forget __pa if the DMA needs the actual physical DRAM address)
+ * and run it.
+ */
- /* Release the mapping and exit */
+ /* Release the mapping and exit */
- unmap_kiobuf(iobuf); /* The unlock_kiobuf is implicit here */
+ unmap_kiobuf(iobuf); /* The unlock_kiobuf is implicit here */
+ free_kiovec(1, &iobuf);
- return len;
+ return len;
}
@@ -97,7 +91,7 @@
/* register char device */
res = register_chrdev(KIOBUFTEST_MAJOR, "kiobuftest", &kiobuf_fops);
- if(res < 0) {
+ if (res < 0) {
printk(KERN_ERR "kiobuftest: couldn't get a major number.\n");
return res;
}
@@ -105,4 +99,11 @@
printk("Initializing kiobuf-test device\n");
}
+static void __exit
+kiobuftest_exit(void)
+{
+ unregister_chrdev(KIOBUFTEST_MAJOR, "kiobuftest");
+}
+
module_init(kiobuftest_init);
+module_exit(kiobuftest_exit);
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)