source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_read_block.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: 2.9 KB
Line 
1/* $ZEL: sis1100_read_block.c,v 1.2 2004/05/27 23:10:30 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
31#if !defined(__NetBSD__) && ! defined(__linux__)
32#error Invalid or Unknown Operating System
33#endif
34
35/*
36 * size : number of bytes per dataword (1, 2 or 4)
37 * num : number of words to be read
38 * num_read: number of words read
39 */
40
41int
42sis1100_read_block(struct sis1100_softc* sc, struct sis1100_fdata* fd,
43 int size, int fifo, size_t num, size_t* num_read, int space,
44 int32_t am, u_int32_t addr, u_int8_t* data, u_int32_t* error)
45{
46 if (!num) {*error=0; *num_read=0; return 0;}
47 if (sc->remote_hw==sis1100_hw_invalid) return ENXIO;
48
49 if (!ACCESS_OK(data, num*size, 0)) return EFAULT;
50
51 if (num==1) {
52 u_int32_t val;
53 *error=sis1100_tmp_read(sc, addr, am, size, space, &val);
54
55 switch (size) {
56#ifdef __NetBSD__
57 case 4: suword(data, val); break;
58 case 2: susword(data, val); break;
59 case 1: subyte(data, val); break;
60#elif __linux__
61 case 4: __put_user(val, (u_int32_t*)data); break;
62 case 2: __put_user(val, (u_int16_t*)data); break;
63 case 1: __put_user(val, (u_int8_t*)data); break;
64#endif
65 }
66 *num_read=!*error;
67 return 0;
68 } else {
69 int res;
70 /*if ((size==4)&&fd->mindmalen_r&&(num>=fd->mindmalen_r)) {*/
71 if (fd->mindmalen_r && (num>=fd->mindmalen_r)) {
72 res=sis1100_read_dma(sc, fd, addr, am, size,
73 space, fifo, num, num_read, data, error);
74 } else {
75 res=sis1100_read_loop(sc, fd, addr, am, size,
76 space, fifo, num, num_read, data, error);
77 }
78 return res;
79 }
80}
Note: See TracBrowser for help on using the repository browser.