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