Commit | Line | Data |
---|---|---|
88a7e859 KM |
1 | /* |
2 | * Copyright (c) 1988 University of Utah. | |
3 | * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
6 | * This code is derived from software contributed to Berkeley by | |
7 | * the Systems Programming Group of the University of Utah Computer | |
8 | * Science Department. | |
9 | * | |
10 | * %sccs.include.redist.c% | |
11 | * | |
6d41ccdb | 12 | * from: Utah $Hdr: mem.c 1.14 90/10/12$ |
88a7e859 | 13 | * |
38a01dbe | 14 | * @(#)mem.c 7.11 (Berkeley) %G% |
88a7e859 KM |
15 | */ |
16 | ||
17 | /* | |
18 | * Memory special file | |
19 | */ | |
20 | ||
38a01dbe KB |
21 | #include <sys/param.h> |
22 | #include <sys/conf.h> | |
23 | #include <sys/buf.h> | |
24 | #include <sys/systm.h> | |
25 | #include <sys/malloc.h> | |
88a7e859 | 26 | |
38a01dbe | 27 | #include <machine/cpu.h> |
88a7e859 | 28 | |
38a01dbe KB |
29 | #include <vm/vm_param.h> |
30 | #include <vm/lock.h> | |
31 | #include <vm/vm_prot.h> | |
32 | #include <vm/pmap.h> | |
22d09b27 | 33 | |
88a7e859 KM |
34 | /*ARGSUSED*/ |
35 | mmrw(dev, uio, flags) | |
36 | dev_t dev; | |
37 | struct uio *uio; | |
38 | int flags; | |
39 | { | |
40 | register int o; | |
41 | register u_int c, v; | |
42 | register struct iovec *iov; | |
43 | int error = 0; | |
44 | caddr_t zbuf = NULL; | |
45 | extern u_int lowram; | |
46 | ||
47 | while (uio->uio_resid > 0 && error == 0) { | |
48 | iov = uio->uio_iov; | |
49 | if (iov->iov_len == 0) { | |
50 | uio->uio_iov++; | |
51 | uio->uio_iovcnt--; | |
52 | if (uio->uio_iovcnt < 0) | |
53 | panic("mmrw"); | |
54 | continue; | |
55 | } | |
56 | switch (minor(dev)) { | |
57 | ||
58 | /* minor device 0 is physical memory */ | |
59 | case 0: | |
60 | v = uio->uio_offset; | |
61 | #ifndef DEBUG | |
62 | /* allow reads only in RAM (except for DEBUG) */ | |
63 | if (v >= 0xFFFFFFFC || v < lowram) | |
22d09b27 | 64 | return (EFAULT); |
88a7e859 | 65 | #endif |
14ca419d | 66 | pmap_enter(kernel_pmap, (vm_offset_t)vmmap, |
a63f11d3 KM |
67 | trunc_page(v), uio->uio_rw == UIO_READ ? |
68 | VM_PROT_READ : VM_PROT_WRITE, TRUE); | |
88a7e859 KM |
69 | o = (int)uio->uio_offset & PGOFSET; |
70 | c = (u_int)(NBPG - ((int)iov->iov_base & PGOFSET)); | |
479c0df7 JSP |
71 | c = min(c, (u_int)(NBPG - o)); |
72 | c = min(c, (u_int)iov->iov_len); | |
88a7e859 | 73 | error = uiomove((caddr_t)&vmmap[o], (int)c, uio); |
14ca419d | 74 | pmap_remove(kernel_pmap, (vm_offset_t)vmmap, |
a63f11d3 | 75 | (vm_offset_t)&vmmap[NBPG]); |
88a7e859 KM |
76 | continue; |
77 | ||
78 | /* minor device 1 is kernel memory */ | |
79 | case 1: | |
479c0df7 | 80 | c = min(iov->iov_len, MAXPHYS); |
88a7e859 KM |
81 | if (!kernacc((caddr_t)uio->uio_offset, c, |
82 | uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) | |
22d09b27 | 83 | return (EFAULT); |
88a7e859 KM |
84 | error = uiomove((caddr_t)uio->uio_offset, (int)c, uio); |
85 | continue; | |
86 | ||
87 | /* minor device 2 is EOF/RATHOLE */ | |
88 | case 2: | |
809c377f MK |
89 | if (uio->uio_rw == UIO_WRITE) |
90 | uio->uio_resid = 0; | |
91 | return (0); | |
88a7e859 KM |
92 | |
93 | /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */ | |
94 | case 12: | |
95 | if (uio->uio_rw == UIO_WRITE) { | |
96 | c = iov->iov_len; | |
97 | break; | |
98 | } | |
99 | if (zbuf == NULL) { | |
100 | zbuf = (caddr_t) | |
101 | malloc(CLBYTES, M_TEMP, M_WAITOK); | |
102 | bzero(zbuf, CLBYTES); | |
103 | } | |
479c0df7 | 104 | c = min(iov->iov_len, CLBYTES); |
88a7e859 KM |
105 | error = uiomove(zbuf, (int)c, uio); |
106 | continue; | |
107 | ||
108 | default: | |
109 | return (ENXIO); | |
110 | } | |
111 | if (error) | |
112 | break; | |
113 | iov->iov_base += c; | |
114 | iov->iov_len -= c; | |
115 | uio->uio_offset += c; | |
116 | uio->uio_resid -= c; | |
117 | } | |
118 | if (zbuf) | |
119 | free(zbuf, M_TEMP); | |
120 | return (error); | |
88a7e859 | 121 | } |