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