Initial import from FreeBSD RELENG_4:
[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. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)mem.4       5.3 (Berkeley) 5/2/91
33 .\" $FreeBSD: src/share/man/man4/mem.4,v 1.7.2.5 2002/02/27 03:39:23 dd Exp $
34 .\"
35 .Dd May 2, 1991
36 .Dt MEM 4
37 .Os
38 .Sh NAME
39 .Nm mem ,
40 .Nm kmem
41 .Nd memory files
42 .Sh DESCRIPTION
43 The special file
44 .Nm /dev/mem
45 is an interface to the physical memory of the computer.
46 Byte offsets in this file are interpreted as physical memory addresses.
47 Reading and writing this file is equivalent to reading and writing
48 memory itself.
49 Only offsets within the bounds of
50 .Nm /dev/mem
51 are allowed.
52 .Pp
53 Kernel virtual memory is accessed through the interface
54 .Nm /dev/kmem
55 in the same manner as
56 .Nm /dev/mem .
57 Only kernel virtual addresses that are currently mapped to memory are allowed.
58 .Pp
59 On
60 .Tn ISA
61 the
62 .Tn I/O
63 memory space begins at physical address 0x000a0000
64 and runs to 0x00100000.
65 The
66 per-process data
67 size
68 for the current process
69 is
70 .Dv UPAGES
71 long, and ends at virtual
72 address 0xf0000000.
73 .Sh IOCTL INTERFACE
74 Several architectures allow attributes to be associated with ranges of physical
75 memory.  These attributes can be manipulated via
76 .Fn ioctl
77 calls performed on
78 .Nm /dev/mem .
79 Declarations and data types are to be found in
80 .Pa <sys/memrange.h>
81 .Pp
82 The specific attributes, and number of programmable ranges may vary between
83 architectures.  The full set of supported attributes is:
84 .Bl -tag -width indent
85 .It MDF_UNCACHEABLE
86 The region is not cached.
87 .It MDF_WRITECOMBINE
88 Writes to the region may be combined or performed out of order.
89 .It MDF_WRITETHROUGH
90 Writes to the region are committed synchronously.
91 .It MDF_WRITEBACK
92 Writes to the region are committed asynchronously.
93 .It MDF_WRITEPROTECT
94 The region cannot be written to.
95 .El
96 .Pp
97 Memory ranges are described by
98 .Fa struct mem_range_desc :
99 .Bd -literal -offset indent
100 u_int64_t       mr_base;        /\(** physical base address \(**/
101 u_int64_t       mr_len;         /\(** physical length of region \(**/
102 int             mr_flags;       /\(** attributes of region \(**/
103 char            mr_owner[8];
104 .Ed
105 .Pp
106 In addition to the region attributes listed above, the following flags
107 may also be set in the
108 .Fa mr_flags
109 field:
110 .Bl -tag -width indent
111 .It MDF_FIXBASE
112 The region's base address cannot be changed.
113 .It MDF_FIXLEN
114 The region's length cannot be changed.
115 .It MDF_FIRMWARE
116 The region is believed to have been established by the system firmare.
117 .It MDF_ACTIVE
118 The region is currently active.
119 .It MDF_BOGUS
120 We believe the region to be invalid or otherwise erroneous.
121 .It MDF_FIXACTIVE
122 The region cannot be disabled.
123 .It MDF_BUSY
124 The region is currently owned by another process and may not be
125 altered.
126 .El
127 .Pp
128 Operations are performed using
129 .Fa struct mem_range_op :
130 .Bd -literal -offset indent
131 struct mem_range_desc   *mo_desc;
132 int                     mo_arg[2];
133 .Ed
134 .Pp
135 The
136 .Fa MEMRANGE_GET
137 ioctl is used to retrieve current memory range attributes.
138 If
139 .Fa mo_arg[0]
140 is set to 0, it will be updated with the total number of memory range
141 descriptors.  If greater than 0, the array at
142 .Fa mo_desc
143 will be filled with a corresponding number of descriptor structures,
144 or the maximum, whichever is less.
145 .Pp
146 The
147 .Fa MEMRANGE_SET
148 ioctl is used to add, alter and remove memory range attributes.  A range
149 with the MDF_FIXACTIVE flag may not be removed; a range with the MDF_BUSY
150 flag may not be removed or updated.
151 .Pp
152 .Fa mo_arg[0]
153 should be set to MEMRANGE_SET_UPDATE to update an existing
154 or establish a new range, or to MEMRANGE_SET_REMOVE to remove a range.
155 .Sh RETURN VALUES
156 .Bl -tag -width Er
157 .It Bq Er EOPNOTSUPP
158 Memory range operations are not supported on this architecture.
159 .It Bq Er ENXIO
160 No memory range descriptors are available (eg. firmware has not enabled
161 any).
162 .It Bq Er EINVAL
163 The memory range supplied as an argument is invalid or overlaps another
164 range in a fashion not supported by this architecture.
165 .It Bq Er EBUSY
166 An attempt to remove or update a range failed because the range is busy.
167 .It Bq Er ENOSPC
168 An attempt to create a new range failed due to a shortage of hardware
169 resources (eg. descriptor slots).
170 .It Bq Er ENOENT
171 An attempt to remove a range failed because no range matches the descriptor
172 base/length supplued.
173 .It Bq Er EPERM
174 An attempt to remove a range failed because the range is permanently
175 enabled.
176 .El
177 .Sh BUGS
178 Busy range attributes are not yet managed correctly.
179 .Sh FILES
180 .Bl -tag -width /dev/kmem -compact
181 .It Pa /dev/mem
182 .It Pa /dev/kmem
183 .El
184 .Sh SEE ALSO
185 .Xr memcontrol 8
186 .Sh HISTORY
187 The
188 .Nm ,
189 .Nm kmem
190 files appeared in
191 .At v6 .
192 The ioctl interface for memory range attributes was added in
193 .Fx 3.2 .