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