Annotation of sys/arch/mvmeppc/dev/mem.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: mem.c,v 1.8 2005/12/17 07:31:26 miod Exp $ */
2: /* $NetBSD: mem.c,v 1.1 1996/09/30 16:34:50 ws Exp $ */
3:
4: /*
5: * Copyright (c) 1988 University of Utah.
6: * Copyright (c) 1982, 1986, 1990, 1993
7: * The Regents of the University of California. All rights reserved.
8: *
9: * This code is derived from software contributed to Berkeley by
10: * the Systems Programming Group of the University of Utah Computer
11: * Science Department.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. Neither the name of the University nor the names of its contributors
22: * may be used to endorse or promote products derived from this software
23: * without specific prior written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35: * SUCH DAMAGE.
36: *
37: * @(#)mem.c 8.3 (Berkeley) 1/12/94
38: */
39:
40: /*
41: * Memory special file
42: */
43:
44: #include <sys/param.h>
45: #include <sys/buf.h>
46: #include <sys/systm.h>
47: #include <sys/uio.h>
48: #include <sys/malloc.h>
49:
50: #include <machine/conf.h>
51:
52: #include <uvm/uvm_extern.h>
53:
54: /*ARGSUSED*/
55: int
56: mmopen(dev, flag, mode, p)
57: dev_t dev;
58: int flag, mode;
59: struct proc *p;
60: {
61:
62: switch (minor(dev)) {
63: case 0:
64: case 1:
65: case 2:
66: case 12:
67: return (0);
68: default:
69: return (ENXIO);
70: }
71: }
72:
73: /*ARGSUSED*/
74: int
75: mmclose(dev, flag, mode, p)
76: dev_t dev;
77: int flag, mode;
78: struct proc *p;
79: {
80:
81: return 0;
82: }
83:
84: /*ARGSUSED*/
85: int
86: mmrw(dev, uio, flags)
87: dev_t dev;
88: struct uio *uio;
89: int flags;
90: {
91: vaddr_t v;
92: u_int c;
93: struct iovec *iov;
94: int error = 0;
95: static caddr_t zeropage;
96:
97: while (uio->uio_resid > 0 && error == 0) {
98: iov = uio->uio_iov;
99: if (iov->iov_len == 0) {
100: uio->uio_iov++;
101: uio->uio_iovcnt--;
102: if (uio->uio_iovcnt < 0)
103: panic("mmrw");
104: continue;
105: }
106: switch (minor(dev)) {
107:
108: /* minor device 0 is physical memory */
109: case 0:
110: v = uio->uio_offset;
111: c = uio->uio_resid;
112: /* This doesn't allow device mapping! XXX */
113: pmap_real_memory(&v, (vsize_t *)&c);
114: error = uiomove((caddr_t)v, c, uio);
115: continue;
116:
117: /* minor device 1 is kernel memory */
118: case 1:
119: v = uio->uio_offset;
120: c = min(iov->iov_len, MAXPHYS);
121: error = uiomove((caddr_t)v, c, uio);
122: continue;
123:
124: /* minor device 2 is EOF/RATHOLE */
125: case 2:
126: if (uio->uio_rw == UIO_WRITE)
127: uio->uio_resid = 0;
128: return 0;
129:
130: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
131: case 12:
132: if (uio->uio_rw == UIO_WRITE) {
133: c = iov->iov_len;
134: break;
135: }
136: if (zeropage == NULL) {
137: zeropage = (caddr_t)malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
138: bzero(zeropage, PAGE_SIZE);
139: }
140: c = min(iov->iov_len, PAGE_SIZE);
141: error = uiomove(zeropage, c, uio);
142: continue;
143:
144: default:
145: return ENXIO;
146: }
147: if (error)
148: break;
149: iov->iov_base += c;
150: iov->iov_len -= c;
151: uio->uio_offset += c;
152: uio->uio_resid -= c;
153: }
154: return error;
155: }
156:
157: paddr_t
158: mmmmap(dev, off, prot)
159: dev_t dev;
160: off_t off;
161: int prot;
162: {
163: return (-1);
164: }
165:
166: /*ARGSUSED*/
167: int
168: mmioctl(dev, cmd, data, flags, p)
169: dev_t dev;
170: u_long cmd;
171: caddr_t data;
172: int flags;
173: struct proc *p;
174: {
175: return (EOPNOTSUPP);
176: }
CVSweb