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 | * | |
12 | * from: Utah $Hdr: mem.c 1.13 89/10/08$ | |
13 | * | |
809c377f | 14 | * @(#)mem.c 7.4 (Berkeley) %G% |
88a7e859 KM |
15 | */ |
16 | ||
17 | /* | |
18 | * Memory special file | |
19 | */ | |
20 | ||
809c377f MK |
21 | #include "param.h" |
22 | #include "conf.h" | |
23 | #include "buf.h" | |
24 | #include "systm.h" | |
25 | #include "malloc.h" | |
88a7e859 | 26 | |
b28b3a13 | 27 | #include "../include/cpu.h" |
88a7e859 | 28 | |
b28b3a13 | 29 | #include "vm/vm_param.h" |
809c377f MK |
30 | #include "vm/lock.h" |
31 | #include "vm/vm_statistics.h" | |
b28b3a13 KB |
32 | #include "vm/pmap.h" |
33 | #include "vm/vm_prot.h" | |
22d09b27 | 34 | |
88a7e859 KM |
35 | /*ARGSUSED*/ |
36 | mmrw(dev, uio, flags) | |
37 | dev_t dev; | |
38 | struct uio *uio; | |
39 | int flags; | |
40 | { | |
41 | register int o; | |
42 | register u_int c, v; | |
43 | register struct iovec *iov; | |
44 | int error = 0; | |
45 | caddr_t zbuf = NULL; | |
46 | extern u_int lowram; | |
47 | ||
48 | while (uio->uio_resid > 0 && error == 0) { | |
49 | iov = uio->uio_iov; | |
50 | if (iov->iov_len == 0) { | |
51 | uio->uio_iov++; | |
52 | uio->uio_iovcnt--; | |
53 | if (uio->uio_iovcnt < 0) | |
54 | panic("mmrw"); | |
55 | continue; | |
56 | } | |
57 | switch (minor(dev)) { | |
58 | ||
59 | /* minor device 0 is physical memory */ | |
60 | case 0: | |
61 | v = uio->uio_offset; | |
62 | #ifndef DEBUG | |
63 | /* allow reads only in RAM (except for DEBUG) */ | |
64 | if (v >= 0xFFFFFFFC || v < lowram) | |
22d09b27 | 65 | return (EFAULT); |
88a7e859 | 66 | #endif |
22d09b27 KM |
67 | pmap_enter(pmap_kernel(), vmmap, v, |
68 | uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE, | |
69 | TRUE); | |
88a7e859 KM |
70 | o = (int)uio->uio_offset & PGOFSET; |
71 | c = (u_int)(NBPG - ((int)iov->iov_base & PGOFSET)); | |
72 | c = MIN(c, (u_int)(NBPG - o)); | |
73 | c = MIN(c, (u_int)iov->iov_len); | |
74 | error = uiomove((caddr_t)&vmmap[o], (int)c, uio); | |
22d09b27 | 75 | pmap_remove(pmap_kernel(), vmmap, &vmmap[NBPG]); |
88a7e859 KM |
76 | continue; |
77 | ||
78 | /* minor device 1 is kernel memory */ | |
79 | case 1: | |
22d09b27 | 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 | } | |
104 | c = MIN(iov->iov_len, CLBYTES); | |
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 | } |