source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_mmap.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.4 KB
Line 
1/* $ZEL: sis1100_mmap.c,v 1.4 2004/05/27 23:10:27 wuestner Exp $ */
2
3/*
4 * Copyright (c) 2001-2004
5 * Matthias Drochner, 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/*
32 * this is a macro because of different types used by linux and BSD
33 */
34#define _sis1100_mmap(sc, fd, offset, base, size) \
35 switch (fd->subdev) { \
36 case sis1100_subdev_remote: \
37 if (!sc->rem_size) { \
38 pINFO(sc, "mmap: remote space not mapped.");\
39 LINUX_RETURN(ENOTTY); \
40 } \
41 base=sc->rem_addr; \
42 size=sc->rem_size; \
43 break; \
44 case sis1100_subdev_ctrl: \
45 base=sc->reg_addr; \
46 size=sc->reg_size; \
47 break; \
48 case sis1100_subdev_ram: /* nobreak */ \
49 case sis1100_subdev_dsp: \
50 size=0; \
51 }
52
53#ifdef __NetBSD__
54
55paddr_t
56sis1100_mmap(dev_t handle, off_t off, int prot)
57{
58 struct sis1100_softc* sc = SIS1100SC(handle);
59 struct sis1100_fdata* fd = SIS1100FD(handle);
60
61 u_int32_t size=0;
62 bus_addr_t base=0;
63 if ((fd->subdev!=sis1100_subdev_ctrl) || (off<sc->reg_size)) {
64 _sis1100_mmap(sc, fd, off, base, size)
65 return i386_btop(base+off);
66 } else { /* dma space for pipeline read */
67 if (fd->mmapdma.valid && (off>=fd->mmapdma.off) &&
68 (off-fd->mmapdma.off<fd->mmapdma.size)) {
69 paddr_t addr=bus_dmamem_mmap(fd->mmapdma.dmat,
70 &fd->mmapdma.segs, 1,
71 off-fd->mmapdma.off,
72 VM_PROT_READ|VM_PROT_WRITE,
73 BUS_DMA_WAITOK|BUS_DMA_COHERENT);
74 return addr;
75 } else {
76 return -1;
77 }
78 }
79}
80
81#elif __linux__
82
83#undef USE_PCI_MMAP
84
85int
86sis1100_mmap(struct file * file, struct vm_area_struct * vma)
87{
88 struct sis1100_softc *sc = SIS1100SC(file);
89 struct sis1100_fdata *fd = SIS1100FD(file);
90
91 u_int32_t size=0;
92 int error;
93 u_long base=0;
94
95 _sis1100_mmap(sc, fd, vma->vm_pgoff, base, size)
96
97 /* offset in bytes + size of mapping */
98 if ((vma->vm_pgoff<<PAGE_SHIFT)+(vma->vm_end-vma->vm_start)>
99 PAGE_ALIGN(size))
100 return -EINVAL;
101#ifdef USE_PCI_MMAP
102 /* this does only work if base is a multiple of PAGE_SIZE */
103 vma->vm_pgoff+=base>>PAGE_SHIFT;
104 if ((error=pci_mmap_page_range(sc->pcidev, vma, pci_mmap_mem, 0))<0)
105 return error;
106#else
107 vma->vm_flags |= VM_RESERVED;
108 vma->vm_flags |= VM_IO;
109
110 if ((error=io_remap_page_range(
111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
112 vma,
113#endif
114 vma->vm_start, base+(vma->vm_pgoff<<PAGE_SHIFT),
115 vma->vm_end-vma->vm_start, vma->vm_page_prot))!=0)
116 return error;
117#endif
118
119 return 0;
120}
121#endif
Note: See TracBrowser for help on using the repository browser.