1.\" $NetBSD: x86_64_get_mtrr.2,v 1.3 2002/10/01 16:02:43 wiz Exp $ 2.\" 3.\" Copyright (c) 2001 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd November 10, 2001 38.Dt X86_64_GET_MTRR 3 x86_64 39.Os 40.Sh NAME 41.Nm x86_64_get_mtrr , 42.Nm x86_64_set_mtrr 43.Nd access Memory Type Range Registers 44.Sh LIBRARY 45.Lb libx86_64 46.Sh SYNOPSIS 47.Fd #include \*[Lt]sys/types.h\*[Gt] 48.Fd #include \*[Lt]machine/sysarch.h\*[Gt] 49.Fd #include \*[Lt]machine/mtrr.h\*[Gt] 50.Ft int 51.Fn x86_64_get_mtrr "struct mtrr *mtrrp" "int *n" 52.Ft int 53.Fn x86_64_set_mtrr "struct mtrr *mtrrp" "int *n" 54.Sh DESCRIPTION 55These functions provide an interface to the MTRR registers found on 56686-class processors for controlling processor access to memory ranges. 57This is most useful for accessing devices such as video accelerators on 58.Xr pci 4 59and 60.Xr agp 4 61busses. 62For example, enabling write-combining allows bus-write transfers 63to be combined into a larger transfer before bursting over the bus. 64This can increase performance of write operations 2.5 times or more. 65.Pp 66.Fa mtrrp 67is a pointer to one or more mtrr structures, as described below. 68The 69.Fa n 70argument is a pointer to an integer containing the number of structures 71pointed to by 72.Fa mtrrp . 73For 74.Fn x86_64_set_mtrr 75the integer pointed to by 76.Fa n 77will be updated to reflect the actual number of MTRRs successfully set. 78For 79.Fn x86_64_get_mtrr 80no more than 81.Fa n 82structures will be copied out, and the integer value pointed to by 83.Fa n 84will be updated to reflect the actual number of valid structures retrieved. 85A 86.Dv NULL 87argument to 88.Fa mtrrp 89will result in just the number of MTRRs available being returned 90in the integer pointed to by 91.Fa n . 92.Pp 93The argument 94.Fa mtrrp 95has the following structure: 96.Bd -literal 97struct mtrr { 98 uint64_t base; 99 uint64_t len; 100 uint8_t type; 101 int flags; 102 pid_t owner; 103}; 104.Ed 105.Pp 106The location of the mapping is described by its physical base address 107.Em base 108and length 109.Em len . 110Valid values for 111.Em type 112are: 113.Pp 114.Bl -tag -offset indent -width MTRR_TYPE_UNDEF1 -compact 115.It MTRR_TYPE_UC 116uncached memory 117.It MTRR_TYPE_WC 118use write-combining 119.It MTRR_TYPE_WT 120use write-through caching 121.It MTRR_TYPE_WP 122write-protected memory 123.It MTRR_TYPE_WB 124use write-back caching 125.El 126.Pp 127Valid values for 128.Em flags 129are: 130.Pp 131.Bl -tag -offset indent -width MTRR_PRIVATE -compact 132.It MTRR_PRIVATE 133own range, reset the MTRR when the current process exits 134.It MTRR_FIXED 135use fixed range MTRR 136.It MTRR_VALID 137entry is valid 138.El 139.Pp 140The 141.Em owner 142member the PID of the user process which claims the mapping. 143It is only valid if MTRR_PRIVATE is set in 144.Em flags . 145To clear/reset MTRRs, use a 146.Em flags 147field without MTRR_VALID set. 148.Sh RETURN VALUES 149Upon successful completion zero is returned, otherwise \-1 is returned 150on failure, and the global variable 151.Va errno 152is set to indicate the error. 153The integer value pointed to by 154.Fa n 155will be container the number of successfully processed mtrr structures 156in both cases. 157.Sh ERRORS 158.Bl -tag -width [EINVAL] 159.It Bq Er ENOSYS 160The currently running kernel or CPU has no MTRR support. 161.It Bq Er EINVAL 162The currently running kernel has no MTRR support, or one of the mtrr 163structures pointed to by 164.Fa mtrrp 165is invalid. 166.It Bq Er EBUSY 167No unused MTRRs are available. 168.El 169.Sh HISTORY 170The 171.Fn x86_64_get_mtrr 172and 173.Fn x86_64_set_mtrr 174were derived from their i386 counterparts, which appeared in 175.Nx 1.6 . 176