1 MTRR (Memory Type Range Register) control
6 On Intel P6 family processors (Pentium Pro, Pentium II and later)
7 the Memory Type Range Registers (MTRRs) may be used to control
8 processor access to memory ranges. This is most useful when you have
9 a video (VGA) card on a PCI or AGP bus. Enabling write-combining
10 allows bus write transfers to be combined into a larger transfer
11 before bursting over the PCI/AGP bus. This can increase performance
12 of image write operations 2.5 times or more.
14 The Cyrix 6x86, 6x86MX and M II processors have Address Range
15 Registers (ARRs) which provide a similar functionality to MTRRs. For
16 these, the ARRs are used to emulate the MTRRs.
18 The AMD K6-2 (stepping 8 and above) and K6-3 processors have two
19 MTRRs. These are supported.
21 The Centaur C6 (WinChip) has 8 MCRs, allowing write-combining. These
24 The CONFIG_MTRR option creates a /proc/mtrr file which may be used
25 to manipulate your MTRRs. Typically the X server should use
26 this. This should have a reasonably generic interface so that
27 similar control registers on other processors can be easily
31 There are two interfaces to /proc/mtrr: one is an ASCII interface
32 which allows you to read and write. The other is an ioctl()
33 interface. The ASCII interface is meant for administration. The
34 ioctl() interface is meant for C programmes (i.e. the X server). The
35 interfaces are described below, with sample commands and C code.
37 ===============================================================================
38 Reading MTRRs from the shell:
41 reg00: base=0x00000000 ( 0MB), size= 128MB: write-back, count=1
42 reg01: base=0x08000000 ( 128MB), size= 64MB: write-back, count=1
43 ===============================================================================
44 Creating MTRRs from the C-shell:
45 # echo "base=0xf8000000 size=0x400000 type=write-combining" >! /proc/mtrr
47 # echo "base=0xf8000000 size=0x400000 type=write-combining" >| /proc/mtrr
49 And the result thereof:
51 reg00: base=0x00000000 ( 0MB), size= 128MB: write-back, count=1
52 reg01: base=0x08000000 ( 128MB), size= 64MB: write-back, count=1
53 reg02: base=0xf8000000 (3968MB), size= 4MB: write-combining, count=1
55 This is for video RAM at base address 0xf8000000 and size 4 megabytes. To
56 find out your base address, you need to look at the output of your X
57 server, which tells you where the linear framebuffer address is. A
58 typical line that you may get is:
60 (--) S3: PCI: 968 rev 0, Linear FB @ 0xf8000000
62 Note that you should only use the value from the X server, as it may
63 move the framebuffer base address, so the only value you can trust is
64 that reported by the X server.
66 To find out the size of your framebuffer (what, you don't actually
67 know?), the following line will tell you:
69 (--) S3: videoram: 4096k
71 That's 4 megabytes, which is 0x400000 bytes (in hexadecimal).
72 A patch is being written for XFree86 which will make this automatic:
73 in other words the X server will manipulate /proc/mtrr using the
74 ioctl() interface, so users won't have to do anything. If you use a
75 commercial X server, lobby your vendor to add support for MTRRs.
76 ===============================================================================
77 Creating overlapping MTRRs:
79 %echo "base=0xfb000000 size=0x1000000 type=write-combining" >/proc/mtrr
80 %echo "base=0xfb000000 size=0x1000 type=uncachable" >/proc/mtrr
82 And the results: cat /proc/mtrr
83 reg00: base=0x00000000 ( 0MB), size= 64MB: write-back, count=1
84 reg01: base=0xfb000000 (4016MB), size= 16MB: write-combining, count=1
85 reg02: base=0xfb000000 (4016MB), size= 4kB: uncachable, count=1
87 Some cards (especially Voodoo Graphics boards) need this 4 kB area
88 excluded from the beginning of the region because it is used for
91 NOTE: You can only create type=uncachable region, if the first
92 region that you created is type=write-combining.
93 ===============================================================================
94 Removing MTRRs from the C-shell:
95 % echo "disable=2" >! /proc/mtrr
97 % echo "disable=2" >| /proc/mtrr
98 ===============================================================================
99 Reading MTRRs from a C programme using ioctl()'s:
103 Source file for mtrr-show (example programme to show MTRRs using ioctl()'s)
105 Copyright (C) 1997-1998 Richard Gooch
107 This program is free software; you can redistribute it and/or modify
108 it under the terms of the GNU General Public License as published by
109 the Free Software Foundation; either version 2 of the License, or
110 (at your option) any later version.
112 This program is distributed in the hope that it will be useful,
113 but WITHOUT ANY WARRANTY; without even the implied warranty of
114 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
115 GNU General Public License for more details.
117 You should have received a copy of the GNU General Public License
118 along with this program; if not, write to the Free Software
119 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
121 Richard Gooch may be reached by email at rgooch@atnf.csiro.au
122 The postal address is:
123 Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
127 This programme will use an ioctl() on /proc/mtrr to show the current MTRR
128 settings. This is an alternative to reading /proc/mtrr.
131 Written by Richard Gooch 17-DEC-1997
133 Last updated by Richard Gooch 2-MAY-1998
139 #include <sys/types.h>
140 #include <sys/stat.h>
142 #include <sys/ioctl.h>
144 #define MTRR_NEED_STRINGS
145 #include <asm/mtrr.h>
149 #define ERRSTRING strerror (errno)
155 struct mtrr_gentry gentry;
157 if ( ( fd = open ("/proc/mtrr", O_RDONLY, 0) ) == -1 )
161 fputs ("/proc/mtrr not found: not supported or you don't have a PPro?\n",
165 fprintf (stderr, "Error opening /proc/mtrr\t%s\n", ERRSTRING);
168 for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &gentry) == 0;
173 fprintf (stderr, "Register: %u disabled\n", gentry.regnum);
176 fprintf (stderr, "Register: %u base: 0x%lx size: 0x%lx type: %s\n",
177 gentry.regnum, gentry.base, gentry.size,
178 mtrr_strings[gentry.type]);
180 if (errno == EINVAL) exit (0);
181 fprintf (stderr, "Error doing ioctl(2) on /dev/mtrr\t%s\n", ERRSTRING);
183 } /* End Function main */
184 ===============================================================================
185 Creating MTRRs from a C programme using ioctl()'s:
189 Source file for mtrr-add (example programme to add an MTRRs using ioctl())
191 Copyright (C) 1997-1998 Richard Gooch
193 This program is free software; you can redistribute it and/or modify
194 it under the terms of the GNU General Public License as published by
195 the Free Software Foundation; either version 2 of the License, or
196 (at your option) any later version.
198 This program is distributed in the hope that it will be useful,
199 but WITHOUT ANY WARRANTY; without even the implied warranty of
200 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
201 GNU General Public License for more details.
203 You should have received a copy of the GNU General Public License
204 along with this program; if not, write to the Free Software
205 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
207 Richard Gooch may be reached by email at rgooch@atnf.csiro.au
208 The postal address is:
209 Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
213 This programme will use an ioctl() on /proc/mtrr to add an entry. The first
214 available mtrr is used. This is an alternative to writing /proc/mtrr.
217 Written by Richard Gooch 17-DEC-1997
219 Last updated by Richard Gooch 2-MAY-1998
227 #include <sys/types.h>
228 #include <sys/stat.h>
230 #include <sys/ioctl.h>
232 #define MTRR_NEED_STRINGS
233 #include <asm/mtrr.h>
237 #define ERRSTRING strerror (errno)
240 int main (int argc, char **argv)
243 struct mtrr_sentry sentry;
247 fprintf (stderr, "Usage:\tmtrr-add base size type\n");
250 sentry.base = strtoul (argv[1], NULL, 0);
251 sentry.size = strtoul (argv[2], NULL, 0);
252 for (sentry.type = 0; sentry.type < MTRR_NUM_TYPES; ++sentry.type)
254 if (strcmp (argv[3], mtrr_strings[sentry.type]) == 0) break;
256 if (sentry.type >= MTRR_NUM_TYPES)
258 fprintf (stderr, "Illegal type: \"%s\"\n", argv[3]);
261 if ( ( fd = open ("/proc/mtrr", O_WRONLY, 0) ) == -1 )
265 fputs ("/proc/mtrr not found: not supported or you don't have a PPro?\n",
269 fprintf (stderr, "Error opening /proc/mtrr\t%s\n", ERRSTRING);
272 if (ioctl (fd, MTRRIOC_ADD_ENTRY, &sentry) == -1)
274 fprintf (stderr, "Error doing ioctl(2) on /dev/mtrr\t%s\n", ERRSTRING);
277 fprintf (stderr, "Sleeping for 5 seconds so you can see the new entry\n");
280 fputs ("I've just closed /proc/mtrr so now the new entry should be gone\n",
282 } /* End Function main */
283 ===============================================================================