source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_pipe_linux.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 4.1 KB
Line 
1/* $ZEL: sis1100_pipe_linux.c,v 1.2 2004/05/27 23:10:27 wuestner Exp $ */
2
3/*
4 * Copyright (c) 2001-2004
5 * Peter Wuestner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "sis1100_sc.h"
30
31int
32sis1100_read_pipe(struct sis1100_softc* sc, struct sis1100_pipe* control)
33{
34 struct sis1100_pipelist* list;
35 struct sis1100_dmabuf dmabuf;
36 int i, error, balance=0, res=0, num;
37
38 list=kmalloc(control->num*sizeof(struct sis1100_pipelist), GFP_USER);
39 if (!list) return ENOMEM;
40
41 if (copy_from_user(list, control->list,
42 control->num*sizeof(struct sis1100_pipelist))) {
43 kfree(list);
44 return EFAULT;
45 }
46
47 /* how many bytes do we have to read? */
48 dmabuf.size=0;
49 for (i=0; i<control->num; i++) {
50 if (!list[i].head&0x400) dmabuf.size+=sizeof(u_int32_t);
51 }
52
53 if (dmabuf.size) {
54 dmabuf.cpu_addr=pci_alloc_consistent(sc->pcidev,
55 dmabuf.size, &dmabuf.dma_handle);
56 if (!dmabuf.cpu_addr) {
57 kfree(list);
58 return ENOMEM;
59 }
60 } else {
61 dmabuf.size=0;
62 dmabuf.dma_handle=0;
63 }
64
65 down(&sc->sem_hw);
66 sis1100writereg(sc, rd_pipe_buf, dmabuf.dma_handle);
67 sis1100writereg(sc, rd_pipe_blen, dmabuf.size);
68
69 sis1100_disable_irq(sc, 0, irq_prot_end);
70
71 sis1100writereg(sc, t_hdr, 0); /* avoid premature start */
72 for (i=0; i<control->num; i++) {
73 u_int32_t head;
74
75 sis1100writereg(sc, t_am, list[i].am);
76 sis1100writereg(sc, t_adl, list[i].addr);
77
78 head=(list[i].head&0x0f3f0400) /* be, remote space and w/r */
79 |0x00400001; /* local space 1, am, start */
80
81 if (list[i].head&0x400) { /* write request */
82 sis1100writereg(sc, t_dal, list[i].data);
83 head&=~0x00400000; /* no pipeline mode */
84 }
85 sis1100writereg(sc, t_hdr, head);
86 }
87
88 sc->got_irqs=0;
89 sis1100_enable_irq(sc, 0, irq_prot_end);
90
91 res=wait_event_interruptible(
92 sc->local_wait,
93 ((balance=sis1100readreg(sc, p_balance))==0)
94 );
95
96 sis1100_disable_irq(sc, 0, irq_prot_end);
97
98 error=sis1100readreg(sc, prot_error);
99 if (!balance) sis1100writereg(sc, p_balance, 0);
100
101 if (error||res) {
102 /*printk(KERN_INFO
103 "sis1100_read_pipe: error=0x%0x, res=%d\n", error, res);
104 dump_glink_status(sc, "after pipe", 1);*/
105 sis1100_flush_fifo(sc, "pipe", 1);
106 }
107 num=dmabuf.size-sis1100readreg(sc, rd_pipe_blen);
108 up(&sc->sem_hw);
109
110 control->error=error;
111 control->num=num;
112
113 kfree(list);
114 if (copy_to_user(control->data, dmabuf.cpu_addr, dmabuf.size)) {
115 /*mem_map_unreserve(virt_to_page(dmabuf.cpu_addr));*/
116 pci_free_consistent(sc->pcidev, dmabuf.size,
117 dmabuf.cpu_addr, dmabuf.dma_handle);
118 res=EFAULT;
119 }
120 if (dmabuf.size)
121 pci_free_consistent(sc->pcidev, dmabuf.size, dmabuf.cpu_addr,
122 dmabuf.dma_handle);
123
124 return res;
125}
Note: See TracBrowser for help on using the repository browser.