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