mem.4: Change RETURN VALUES -> ERRORS.
[dragonfly.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: src/share/man/man4/mem.4,v 1.7.2.5 2002/02/27 03:39:23 dd Exp $
30 .\"
31 .Dd May 2, 1991
32 .Dt MEM 4
33 .Os
34 .Sh NAME
35 .Nm mem ,
36 .Nm kmem
37 .Nd memory files
38 .Sh DESCRIPTION
39 The special file
40 .Pa /dev/mem
41 is an interface to the physical memory of the computer.
42 Byte offsets in this file are interpreted as physical memory addresses.
43 Reading and writing this file is equivalent to reading and writing
44 memory itself.
45 Only offsets within the bounds of
46 .Pa /dev/mem
47 are allowed.
48 .Pp
49 Kernel virtual memory is accessed through the interface
50 .Pa /dev/kmem
51 in the same manner as
52 .Pa /dev/mem .
53 Only kernel virtual addresses that are currently mapped to memory are allowed.
54 .Pp
55 On
56 .Tn ISA
57 the
58 .Tn I/O
59 memory space begins at physical address 0x000a0000
60 and runs to 0x00100000.
61 The
62 per-process data
63 size
64 for the current process
65 is
66 .Dv UPAGES
67 long, and ends at virtual
68 address 0xf0000000.
69 .Sh IOCTL INTERFACE
70 Several architectures allow attributes to be associated with ranges of physical
71 memory.
72 These attributes can be manipulated via
73 .Fn ioctl
74 calls performed on
75 .Pa /dev/mem .
76 Declarations and data types are to be found in
77 .In sys/memrange.h .
78 .Pp
79 The specific attributes, and number of programmable ranges may vary between
80 architectures.
81 The full set of supported attributes is:
82 .Bl -tag -width indent
83 .It Dv MDF_UNCACHEABLE
84 The region is not cached.
85 .It Dv MDF_WRITECOMBINE
86 Writes to the region may be combined or performed out of order.
87 .It Dv MDF_WRITETHROUGH
88 Writes to the region are committed synchronously.
89 .It Dv MDF_WRITEBACK
90 Writes to the region are committed asynchronously.
91 .It Dv MDF_WRITEPROTECT
92 The region cannot be written to.
93 .El
94 .Pp
95 Memory ranges are described by
96 .Vt struct mem_range_desc :
97 .Bd -literal -offset indent
98 u_int64_t       mr_base;        /\(** physical base address \(**/
99 u_int64_t       mr_len;         /\(** physical length of region \(**/
100 int             mr_flags;       /\(** attributes of region \(**/
101 char            mr_owner[8];
102 .Ed
103 .Pp
104 In addition to the region attributes listed above, the following flags
105 may also be set in the
106 .Fa mr_flags
107 field:
108 .Bl -tag -width indent
109 .It Dv MDF_FIXBASE
110 The region's base address cannot be changed.
111 .It Dv MDF_FIXLEN
112 The region's length cannot be changed.
113 .It Dv MDF_FIRMWARE
114 The region is believed to have been established by the system firmware.
115 .It Dv MDF_ACTIVE
116 The region is currently active.
117 .It Dv MDF_BOGUS
118 We believe the region to be invalid or otherwise erroneous.
119 .It Dv MDF_FIXACTIVE
120 The region cannot be disabled.
121 .It Dv MDF_BUSY
122 The region is currently owned by another process and may not be
123 altered.
124 .El
125 .Pp
126 Operations are performed using
127 .Fa struct mem_range_op :
128 .Bd -literal -offset indent
129 struct mem_range_desc   *mo_desc;
130 int                     mo_arg[2];
131 .Ed
132 .Pp
133 The
134 .Dv MEMRANGE_GET
135 ioctl is used to retrieve current memory range attributes.
136 If
137 .Va mo_arg[0]
138 is set to 0, it will be updated with the total number of memory range
139 descriptors.
140 If greater than 0, the array at
141 .Va mo_desc
142 will be filled with a corresponding number of descriptor structures,
143 or the maximum, whichever is less.
144 .Pp
145 The
146 .Dv MEMRANGE_SET
147 ioctl is used to add, alter and remove memory range attributes.  A range
148 with the
149 .Dv MDF_FIXACTIVE
150 flag may not be removed; a range with the
151 .Dv MDF_BUSY
152 flag may not be removed or updated.
153 .Pp
154 .Va mo_arg[0]
155 should be set to
156 .Dv MEMRANGE_SET_UPDATE
157 to update an existing or establish a new range, or to
158 .Dv MEMRANGE_SET_REMOVE
159 to remove a range.
160 .Sh FILES
161 .Bl -tag -width /dev/kmem -compact
162 .It Pa /dev/mem
163 .It Pa /dev/kmem
164 .El
165 .Sh ERRORS
166 .Bl -tag -width Er
167 .It Bq Er EOPNOTSUPP
168 Memory range operations are not supported on this architecture.
169 .It Bq Er ENXIO
170 No memory range descriptors are available (eg. firmware has not enabled
171 any).
172 .It Bq Er EINVAL
173 The memory range supplied as an argument is invalid or overlaps another
174 range in a fashion not supported by this architecture.
175 .It Bq Er EBUSY
176 An attempt to remove or update a range failed because the range is busy.
177 .It Bq Er ENOSPC
178 An attempt to create a new range failed due to a shortage of hardware
179 resources (eg. descriptor slots).
180 .It Bq Er ENOENT
181 An attempt to remove a range failed because no range matches the descriptor
182 base/length supplied.
183 .It Bq Er EPERM
184 An attempt to remove a range failed because the range is permanently
185 enabled.
186 .El
187 .Sh SEE ALSO
188 .Xr memcontrol 8
189 .Sh HISTORY
190 The
191 .Nm mem
192 and
193 .Nm kmem
194 files appeared in
195 .At v6 .
196 The ioctl interface for memory range attributes was added in
197 .Fx 3.2 .
198 .Sh BUGS
199 Busy range attributes are not yet managed correctly.