source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_write_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_write_block.c,v 1.2 2004/05/27 23:10:38 wuestner Exp $ */
2
3/*
4 * Copyright (c) 2003-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
35int
36sis1100_write_block(struct sis1100_softc* sc, struct sis1100_fdata* fd,
37 int size, int fifo, size_t num, size_t* num_written, int space,
38 int32_t am, u_int32_t addr, const u_int8_t* data, u_int32_t* error)
39{
40 if (!num) {*error=0; *num_written=0; return 0;}
41 if (sc->remote_hw==sis1100_hw_invalid) return ENXIO;
42
43 if (!ACCESS_OK((u_int8_t*)data, num*size, 1)) return EFAULT;
44
45 if (num==1) {
46 u_int32_t val;
47 switch (size) {
48#ifdef __NetBSD__
49 case 1: val=fubyte(data); break;
50 case 2: val=fusword(data); break;
51 case 4: val=fuword(data); break;
52#elif __linux__
53 case 1: __get_user(val, (u_int8_t*)data); break;
54 case 2: __get_user(val, (u_int16_t*)data); break;
55 case 4: __get_user(val, (u_int32_t*)data); break;
56#endif
57 default: val=0;
58 }
59 *error=sis1100_tmp_write(sc, addr, am, size, space, val);
60 *num_written=1;
61 return 0;
62 } else {
63 int res;
64 if ((size==4)&&fd->mindmalen_w&&(num>=fd->mindmalen_w)) {
65 res=sis1100_write_dma(sc, fd, addr, am, size,
66 space, fifo, num, num_written, data, error);
67 } else {
68 res=sis1100_write_loop(sc, fd, addr, am, size,
69 space, fifo, num, num_written, data, error);
70 }
71 return res;
72 }
73}
Note: See TracBrowser for help on using the repository browser.