- more 2.6.17 port work (still does not build)
[linux-flexiantxendom0-3.2.10.git] / drivers / dma / testclient.c
1 /*
2  * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59
16  * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called COPYING.
20  */
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/device.h>
24 #include <linux/dmaengine.h>
25 #include <linux/delay.h>
26 #include <asm/io.h>
27
28 /* MODULE API */
29
30 static volatile u8 *buffer1;
31 static volatile u8 *buffer2;
32
33 struct dma_client *test_dma_client;
34 struct dma_chan *test_dma_chan;
35 static dma_cookie_t cookie;
36
37 void
38 test_added_chan(void)
39 {
40         int i;
41
42         printk("buffer1 = %p\n", buffer1);
43         printk("buffer2 = %p\n", buffer2);
44         for (i = 0; i < 20; i+=4)
45                 printk("%u %u %u %u\n", buffer2[i], buffer2[i+1], buffer2[i+2], buffer2[i+3]);
46
47 //      for (i = 0; i < 10; i++) {
48         cookie = dma_async_memcpy_buf_to_buf(test_dma_chan,
49                 (void *)buffer2,
50                 (void *)buffer1,
51                 2000);
52         dma_async_memcpy_issue_pending(test_dma_chan);
53 //      }
54 //      printk("dma cookie = %i\n", cookie);
55         if (dma_async_memcpy_complete(test_dma_chan, cookie, NULL, NULL) == DMA_IN_PROGRESS)
56                 printk("DMA cookie == IN PROGRESS\n");
57         else
58                 printk("DMA cookie == SUCCESS\n");
59 #if 0
60         for (i = 0; i < 1000; i++) {
61                 if (buffer2[1] != 0)
62                         break;
63                 mdelay(1);
64         }
65         printk("i = %d\n", i);
66         for (i = 0; i < 20; i+=4)
67                 printk("%u %u %u %u\n", buffer2[i], buffer2[i+1], buffer2[i+2], buffer2[i+3]);
68         for (i = 0; i < 20; i+=4)
69                 printk("%u %u %u %u\n", buffer1[i], buffer1[i+1], buffer1[i+2], buffer1[i+3]);
70 #endif
71 }
72
73 void test_dma_event(struct dma_client *client, struct dma_chan *chan, enum dma_event event)
74 {
75         switch (event) {
76         case DMA_RESOURCE_ADDED:
77                 test_dma_chan = chan;
78                 test_added_chan();
79                 break;
80         case DMA_RESOURCE_REMOVED:
81                 test_dma_chan = NULL;
82                 break;
83         default:
84                 break;
85         }
86 }
87
88 static int __init
89 testclient_init_module(void)
90 {
91         int i;
92
93         buffer1 = kmalloc(sizeof(u8) * 2000, SLAB_KERNEL);
94         buffer2 = kmalloc(sizeof(u8) * 2000, SLAB_KERNEL);
95
96         memset((void *)buffer2, 0, 2000);
97         for (i = 0; i < 2000; i++)
98                 buffer1[i] = i;
99
100         test_dma_client = dma_async_client_register(test_dma_event);
101         if (!test_dma_client) {
102                 printk(KERN_ERR "Could not register dma client!\n");
103                 return 0;
104         }
105
106         dma_async_client_chan_request(test_dma_client, 1);
107
108         return 0;
109 }
110
111 module_init(testclient_init_module);
112
113 static void __exit
114 testclient_exit_module(void)
115 {
116         int i;
117         for (i = 0; i < 20; i+=4)
118                 printk("%u %u %u %u\n", buffer2[i], buffer2[i+1], buffer2[i+2], buffer2[i+3]);
119
120         if (test_dma_chan) {
121                 if (dma_async_memcpy_complete(test_dma_chan, cookie, NULL, NULL) == DMA_SUCCESS)
122                         printk("DMA cookie == SUCCESS\n");
123                 else
124                         printk("DMA cookie == IN PROGRESS\n");
125         }
126
127         dma_async_client_unregister(test_dma_client);
128
129         kfree ((void*)buffer1);
130         kfree ((void*)buffer2);
131 }
132
133 module_exit(testclient_exit_module);
134
135 MODULE_LICENSE("GPL");