source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_pipe_netbsd.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: 5.1 KB
Line 
1/* $ZEL: sis1100_pipe_netbsd.c,v 1.2 2004/05/27 23:10:28 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 mmapdma dmabuf;
36 int rsegs, i, error, balance=0, res=0, num, s;
37
38 list=malloc(control->num*sizeof(struct sis1100_pipelist),
39 M_IOCTLOPS, M_WAITOK);
40 if (!list) return ENOMEM;
41
42 if (copyin(control->list, list,
43 control->num*sizeof(struct sis1100_pipelist))) {
44 free(list, M_IOCTLOPS);
45 res=EFAULT;
46 goto raus_malloc;
47 }
48
49 /* how many bytes do we have to read? */
50/*
51 dmabuf.size=0;
52 for (i=0; i<control->num; i++) {
53 if (!list[i].head&0x400) dmabuf.size+=sizeof(u_int32_t);
54 }
55*/
56 dmabuf.size=control->num;
57
58 dmabuf.dmat=sc->sc_dmat;
59 res=bus_dmamem_alloc(dmabuf.dmat, dmabuf.size, 0, 0,
60 &dmabuf.segs, 1, &rsegs, BUS_DMA_WAITOK);
61 if (res) {
62 pINFO(sc, "pipe: dmamem_alloc(%ld) failed", dmabuf.size);
63 goto raus_malloc;
64 }
65 res=bus_dmamem_map(dmabuf.dmat, &dmabuf.segs, 1,
66 dmabuf.size, &dmabuf.kva,
67 BUS_DMA_WAITOK|BUS_DMA_COHERENT);
68 if (res) {
69 pINFO(sc, "pipe: bus_dmamem_map(%ld) failed", dmabuf.size);
70 goto raus_bus_dmamem_alloc;
71 }
72 res=bus_dmamap_create(dmabuf.dmat, dmabuf.size, 1,
73 dmabuf.size, 0, BUS_DMA_WAITOK, &dmabuf.dm);
74 if (res) {
75 pINFO(sc, "pipe: bus_dmamap_create(%ld) failed", dmabuf.size);
76 goto raus_bus_dmamem_map;
77 }
78 res=bus_dmamap_load(dmabuf.dmat, dmabuf.dm, dmabuf.kva,
79 dmabuf.size, NULL, BUS_DMA_WAITOK);
80 if (res) {
81 pINFO(sc, "pipe: bus_dmamap_load(%ld) failed", dmabuf.size);
82 goto raus_bus_dmamap_create;
83 }
84
85 bus_dmamap_sync(dmabuf.dmat, dmabuf.dm, 0, dmabuf.size, BUS_DMASYNC_PREREAD);
86 SEM_LOCK(sc->sem_hw);
87 sis1100writereg(sc, rd_pipe_buf, dmabuf.segs.ds_addr);
88 sis1100writereg(sc, rd_pipe_blen, dmabuf.size);
89
90 sis1100_disable_irq(sc, 0, irq_prot_end);
91
92 sis1100writereg(sc, t_hdr, 0); /* avoid premature start */
93 for (i=0; i<control->num; i++) {
94 u_int32_t head;
95
96 sis1100writereg(sc, t_am, list[i].am);
97 sis1100writereg(sc, t_adl, list[i].addr);
98
99 head=(list[i].head&0x0f3f0400) /* be, remote space and w/r */
100 |0x00400001; /* local space 1, am, start */
101
102 if (list[i].head&0x400) { /* write request */
103 sis1100writereg(sc, t_dal, list[i].data);
104 head&=~0x00400000; /* no pipeline mode */
105 }
106 sis1100writereg(sc, t_hdr, head);
107 }
108
109 sc->got_irqs=0;
110 sis1100_enable_irq(sc, 0, irq_prot_end);
111
112 s = splbio();
113 while (!(res||((balance=sis1100readreg(sc, p_balance))==0))) {
114 res = tsleep(&sc->local_wait, PCATCH, "pipe", 10*hz);
115 }
116 splx(s);
117
118 sis1100_disable_irq(sc, 0, irq_prot_end);
119
120 error=sis1100readreg(sc, prot_error);
121 if (!balance) sis1100writereg(sc, p_balance, 0);
122
123 if (error||res) {
124 /*printk(KERN_INFO
125 "sis1100_read_pipe: error=0x%0x, res=%d\n", error, res);
126 dump_glink_status(sc, "after pipe", 1);*/
127 sis1100_flush_fifo(sc, "pipe", 1);
128 }
129 num=dmabuf.size-sis1100readreg(sc, rd_pipe_blen);
130 SEM_UNLOCK(sc->sem_hw);
131 bus_dmamap_sync(dmabuf.dmat, dmabuf.dm, 0, dmabuf.size, BUS_DMASYNC_POSTREAD);
132
133 control->error=error;
134 control->num=num;
135
136 if (copyout(dmabuf.kva, control->data, num)) {
137 res=EFAULT;
138 goto raus_bus_dmamap_load;
139 }
140
141raus_bus_dmamap_load:
142 bus_dmamap_unload(dmabuf.dmat, dmabuf.dm);
143raus_bus_dmamap_create:
144 bus_dmamap_destroy(dmabuf.dmat, dmabuf.dm);
145raus_bus_dmamem_map:
146 bus_dmamem_unmap(dmabuf.dmat, dmabuf.kva, dmabuf.size);
147raus_bus_dmamem_alloc:
148 bus_dmamem_free(dmabuf.dmat, &dmabuf.segs, 1);
149raus_malloc:
150 free(list, M_IOCTLOPS);
151
152 return res;
153}
Note: See TracBrowser for help on using the repository browser.