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