]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/mem.4
sqlite3: Vendor import of sqlite3 3.37.1
[FreeBSD/FreeBSD.git] / share / man / man4 / mem.4
1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 .\"     @(#)mem.4       5.3 (Berkeley) 5/2/91
29 .\" $FreeBSD$
30 .\"
31 .Dd August 25, 2020
32 .Dt MEM 4
33 .Os
34 .Sh NAME
35 .Nm mem ,
36 .Nm kmem
37 .Nd memory files
38 .Sh SYNOPSIS
39 .Cd "device mem"
40 .Sh DESCRIPTION
41 The special file
42 .Pa /dev/mem
43 is an interface to the physical memory of the computer.
44 Byte offsets in this file are interpreted as physical memory addresses.
45 Reading and writing this file is equivalent to reading and writing
46 memory itself.
47 Only offsets within the bounds of
48 .Pa /dev/mem
49 are allowed.
50 .Pp
51 Kernel virtual memory is accessed through the interface
52 .Pa /dev/kmem
53 in the same manner as
54 .Pa /dev/mem .
55 Only kernel virtual addresses that are currently mapped to memory are allowed.
56 .Pp
57 On ISA the I/O memory space begins at physical address 0x000a0000
58 and runs to 0x00100000.
59 The
60 per-process data
61 size
62 for the current process
63 is
64 .Dv UPAGES
65 long, and ends at virtual
66 address 0xf0000000.
67 .Sh IOCTL INTERFACE
68 The
69 .Dv MEM_EXTRACT_PADDR
70 ioctl can be used to look up the physical address and NUMA domain of a given
71 virtual address in the calling process' address space.
72 The request is described by
73 .Bd -literal
74 struct mem_extract {
75         uint64_t        me_vaddr;       /* input */
76         uint64_t        me_paddr;       /* output */
77         int             me_domain;      /* output */
78         int             me_state;       /* output */
79 };
80 .Ed
81 .Pp
82 The ioctl returns an error if the address is not valid.
83 The information returned by
84 .Dv MEM_EXTRACT_PADDR
85 may be out of date by the time that the ioctl call returns.
86 Specifically, concurrent system calls, page faults, or system page reclamation
87 activity may have unmapped the virtual page or replaced the backing physical
88 page before the ioctl call returns.
89 Wired pages, e.g., those locked by
90 .Xr mlock 2 ,
91 will not be reclaimed by the system.
92 .Pp
93 The
94 .Fa me_state
95 field provides information about the state of the virtual page:
96 .Bl -tag -width indent
97 .It Dv ME_STATE_INVALID
98 The virtual address is invalid.
99 .It Dv ME_STATE_VALID
100 The virtual address is valid but is not mapped at the time of the ioctl call.
101 .It Dv ME_STATE_MAPPED
102 The virtual address corresponds to a physical page mapping, and the
103 .Fa me_paddr
104 and
105 .Fa me_domain
106 fields are valid.
107 .Pp
108 Several architectures allow attributes to be associated with ranges of physical
109 memory.
110 These attributes can be manipulated via
111 .Fn ioctl
112 calls performed on
113 .Pa /dev/mem .
114 Declarations and data types are to be found in
115 .In sys/memrange.h .
116 .Pp
117 The specific attributes, and number of programmable ranges may vary between
118 architectures.
119 The full set of supported attributes is:
120 .Bl -tag -width indent
121 .It Dv MDF_UNCACHEABLE
122 The region is not cached.
123 .It Dv MDF_WRITECOMBINE
124 Writes to the region may be combined or performed out of order.
125 .It Dv MDF_WRITETHROUGH
126 Writes to the region are committed synchronously.
127 .It Dv MDF_WRITEBACK
128 Writes to the region are committed asynchronously.
129 .It Dv MDF_WRITEPROTECT
130 The region cannot be written to.
131 .El
132 .Pp
133 Memory ranges are described by
134 .Bd -literal
135 struct mem_range_desc {
136         uint64_t        mr_base;        /* physical base address */
137         uint64_t        mr_len;         /* physical length of region */
138         int             mr_flags;       /* attributes of region */
139         char            mr_owner[8];
140 };
141 .Ed
142 .Pp
143 In addition to the region attributes listed above, the following flags
144 may also be set in the
145 .Fa mr_flags
146 field:
147 .Bl -tag -width indent
148 .It MDF_FIXBASE
149 The region's base address cannot be changed.
150 .It MDF_FIXLEN
151 The region's length cannot be changed.
152 .It MDF_FIRMWARE
153 The region is believed to have been established by the system firmware.
154 .It MDF_ACTIVE
155 The region is currently active.
156 .It MDF_BOGUS
157 We believe the region to be invalid or otherwise erroneous.
158 .It MDF_FIXACTIVE
159 The region cannot be disabled.
160 .It MDF_BUSY
161 The region is currently owned by another process and may not be
162 altered.
163 .El
164 .Pp
165 Operations are performed using
166 .Bd -literal
167 struct mem_range_op {
168         struct mem_range_desc   *mo_desc;
169         int                     mo_arg[2];
170 };
171 .Ed
172 .Pp
173 The
174 .Dv MEMRANGE_GET
175 ioctl is used to retrieve current memory range attributes.
176 If
177 .Va mo_arg[0]
178 is set to 0, it will be updated with the total number of memory range
179 descriptors.
180 If greater than 0, the array at
181 .Va mo_desc
182 will be filled with a corresponding number of descriptor structures,
183 or the maximum, whichever is less.
184 .Pp
185 The
186 .Dv MEMRANGE_SET
187 ioctl is used to add, alter and remove memory range attributes.
188 A range
189 with the
190 .Dv MDF_FIXACTIVE
191 flag may not be removed; a range with the
192 .Dv MDF_BUSY
193 flag may not be removed or updated.
194 .Pp
195 .Va mo_arg[0]
196 should be set to
197 .Dv MEMRANGE_SET_UPDATE
198 to update an existing or establish a new range, or to
199 .Dv MEMRANGE_SET_REMOVE
200 to remove a range.
201 .El
202 .Sh RETURN VALUES
203 .Bl -tag -width Er
204 .It Bq Er EOPNOTSUPP
205 Memory range operations are not supported on this architecture.
206 .It Bq Er ENXIO
207 No memory range descriptors are available (e.g., firmware has not enabled
208 any).
209 .It Bq Er EINVAL
210 The memory range supplied as an argument is invalid or overlaps another
211 range in a fashion not supported by this architecture.
212 .It Bq Er EBUSY
213 An attempt to remove or update a range failed because the range is busy.
214 .It Bq Er ENOSPC
215 An attempt to create a new range failed due to a shortage of hardware
216 resources (e.g., descriptor slots).
217 .It Bq Er ENOENT
218 An attempt to remove a range failed because no range matches the descriptor
219 base/length supplied.
220 .It Bq Er EPERM
221 An attempt to remove a range failed because the range is permanently
222 enabled.
223 .El
224 .Sh FILES
225 .Bl -tag -width /dev/kmem -compact
226 .It Pa /dev/mem
227 .It Pa /dev/kmem
228 .El
229 .Sh SEE ALSO
230 .Xr kvm 3 ,
231 .Xr memcontrol 8
232 .Sh HISTORY
233 The
234 .Nm mem
235 and
236 .Nm kmem
237 files appeared in
238 .At v6 .
239 The ioctl interface for memory range attributes was added in
240 .Fx 3.2 .
241 .Sh BUGS
242 Busy range attributes are not yet managed correctly.
243 .Pp
244 This device is required for all users of
245 .Xr kvm 3
246 to operate.