xref: /netbsd/lib/libarch/i386/i386_get_mtrr.2 (revision bf9ec67e)
1.\"     $NetBSD: i386_get_mtrr.2,v 1.6 2002/02/20 20:40:48 gmcgarry 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 I386_GET_MTRR 3 i386
39.Os
40.Sh NAME
41.Nm i386_get_mtrr ,
42.Nm i386_set_mtrr
43.Nd access Memory Type Range Registers
44.Sh LIBRARY
45.Lb libi386
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 i386_get_mtrr "struct mtrr *mtrrp" "int *n"
52.Ft int
53.Fn i386_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
58on
59.Xr pci 4
60and
61.Xr agp 4
62busses.  For example, enabling write-combining allows bus-write transfers
63to be combined into a larger transfer before bursting over the bus.  This
64can 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. The
68.Fa n
69argument is a pointer to an integer containing the number of structures
70pointed to by
71.Fa mtrrp .
72For
73.Fn i386_set_mtrr
74the integer pointed to by
75.Fa n
76will be updated to reflect the actual number of MTRRs successfully set.
77For
78.Fn i386_get_mtrr
79no more than
80.Fa n
81structures will be copied out, and the integer value pointed to by
82.Fa n
83will be updated to reflect the actual number of valid structures
84retrieved.
85A NULL argument to
86.Fa mtrrp
87will result in just the number of MTRRs available being returned
88in the integer pointed to by
89.Fa n .
90.Pp
91The argument
92.Fa mtrrp
93has the following structure:
94.Bd -literal
95struct mtrr {
96        uint64_t base;
97        uint64_t len;
98        uint8_t type;
99        int flags;
100        pid_t owner;
101};
102.Ed
103.Pp
104The location of the mapping is described by its physical base address
105.Em base
106and length
107.Em len .
108Valid values for
109.Em type
110are:
111.Pp
112.Bl -tag -offset indent -width MTRR_TYPE_UNDEF1 -compact
113.It MTRR_TYPE_UC
114uncached memory
115.It MTRR_TYPE_WC
116use write-combining
117.It MTRR_TYPE_WT
118use write-through caching
119.It MTRR_TYPE_WP
120write-protected memory
121.It MTRR_TYPE_WB
122use write-back caching
123.El
124.Pp
125Valid values for
126.Em flags
127are:
128.Pp
129.Bl -tag -offset indent -width MTRR_PRIVATE -compact
130.It MTRR_PRIVATE
131own range, reset the MTRR when the current process exits
132.It MTRR_FIXED
133use fixed range MTRR
134.It MTRR_VALID
135entry is valid
136.El
137.Pp
138The
139.Em owner
140member the PID of the user process which claims the mapping.  It is
141only valid if MTRR_PRIVATE is set in
142.Em flags .
143To clear/reset MTRRs, use a
144.Em flags
145field without MTRR_VALID set.
146.Sh RETURN VALUES
147Upon successful completion zero is returned, otherwise -1 is returned
148on failure, and the global variable
149.Va errno
150is set to indicate the error. The integer value pointed to by
151.Fa n
152will be container the number of successfully processed mtrr structures
153in both cases.
154.Sh ERRORS
155.Bl -tag -width [EINVAL]
156.It Bq Er ENOSYS
157The currently running kernel or CPU has no MTRR support.
158.It Bq Er EINVAL
159The currently running kernel has no MTRR support, or one of the mtrr
160structures pointed to by
161.Fa mtrrp
162is invalid.
163.It Bq Er EBUSY
164No unused MTRRs are available.
165.El
166.Sh HISTORY
167The
168.Fn i386_get_mtrr
169and
170.Fn i386_set_mtrr
171functions appeared in
172.Nx 1.6 .
173