~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/arch/x86/mtrr.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/arch/x86/mtrr.rst (Version linux-6.12-rc7) and /Documentation/arch/mips/mtrr.rst (Version linux-5.2.21)


  1 .. SPDX-License-Identifier: GPL-2.0               
  2                                                   
  3 =========================================         
  4 MTRR (Memory Type Range Register) control         
  5 =========================================         
  6                                                   
  7 :Authors: - Richard Gooch <rgooch@atnf.csiro.au    
  8           - Luis R. Rodriguez <mcgrof@do-not-pa    
  9                                                   
 10                                                   
 11 Phasing out MTRR use                              
 12 ====================                              
 13                                                   
 14 MTRR use is replaced on modern x86 hardware wi    
 15 drivers on Linux is now completely phased out,    
 16 arch_phys_wc_add() in combination with ioremap    
 17 non-PAT systems while a no-op but equally effe    
 18                                                   
 19 Even if Linux does not use MTRRs directly, som    
 20 set up MTRRs early before booting the OS. They    
 21 firmware may still have implemented access to     
 22 and handled by the platform firmware directly.    
 23 MTRRs is through the use of SMI handlers, one     
 24 the platform code would need uncachable access    
 25 registers. Such platform access does not need     
 26 place other than mtrr_type_lookup() to ensure     
 27 are aligned with platform MTRR setup. If MTRRs    
 28 firmware code though and the OS does not make     
 29 requests mtrr_type_lookup() should always retu    
 30                                                   
 31 For details refer to Documentation/arch/x86/pa    
 32                                                   
 33 .. tip::                                          
 34   On Intel P6 family processors (Pentium Pro,     
 35   the Memory Type Range Registers (MTRRs) may     
 36   processor access to memory ranges. This is m    
 37   a video (VGA) card on a PCI or AGP bus. Enab    
 38   allows bus write transfers to be combined in    
 39   before bursting over the PCI/AGP bus. This c    
 40   of image write operations 2.5 times or more.    
 41                                                   
 42   The Cyrix 6x86, 6x86MX and M II processors h    
 43   Registers (ARRs) which provide a similar fun    
 44   these, the ARRs are used to emulate the MTRR    
 45                                                   
 46   The AMD K6-2 (stepping 8 and above) and K6-3    
 47   MTRRs. These are supported.  The AMD Athlon     
 48   style MTRRs.                                    
 49                                                   
 50   The Centaur C6 (WinChip) has 8 MCRs, allowin    
 51   are supported.                                  
 52                                                   
 53   The VIA Cyrix III and VIA C3 CPUs offer 8 In    
 54                                                   
 55   The CONFIG_MTRR option creates a /proc/mtrr     
 56   to manipulate your MTRRs. Typically the X se    
 57   this. This should have a reasonably generic     
 58   similar control registers on other processor    
 59   supported.                                      
 60                                                   
 61 There are two interfaces to /proc/mtrr: one is    
 62 which allows you to read and write. The other     
 63 interface. The ASCII interface is meant for ad    
 64 ioctl() interface is meant for C programs (i.e    
 65 interfaces are described below, with sample co    
 66                                                   
 67                                                   
 68 Reading MTRRs from the shell                      
 69 ============================                      
 70 ::                                                
 71                                                   
 72   % cat /proc/mtrr                                
 73   reg00: base=0x00000000 (   0MB), size= 128MB    
 74   reg01: base=0x08000000 ( 128MB), size=  64MB    
 75                                                   
 76 Creating MTRRs from the C-shell::                 
 77                                                   
 78   # echo "base=0xf8000000 size=0x400000 type=w    
 79                                                   
 80 or if you use bash::                              
 81                                                   
 82   # echo "base=0xf8000000 size=0x400000 type=w    
 83                                                   
 84 And the result thereof::                          
 85                                                   
 86   % cat /proc/mtrr                                
 87   reg00: base=0x00000000 (   0MB), size= 128MB    
 88   reg01: base=0x08000000 ( 128MB), size=  64MB    
 89   reg02: base=0xf8000000 (3968MB), size=   4MB    
 90                                                   
 91 This is for video RAM at base address 0xf80000    
 92 find out your base address, you need to look a    
 93 server, which tells you where the linear frame    
 94 typical line that you may get is::                
 95                                                   
 96   (--) S3: PCI: 968 rev 0, Linear FB @ 0xf8000    
 97                                                   
 98 Note that you should only use the value from t    
 99 move the framebuffer base address, so the only    
100 that reported by the X server.                    
101                                                   
102 To find out the size of your framebuffer (what    
103 know?), the following line will tell you::        
104                                                   
105   (--) S3: videoram:  4096k                       
106                                                   
107 That's 4 megabytes, which is 0x400000 bytes (i    
108 A patch is being written for XFree86 which wil    
109 in other words the X server will manipulate /p    
110 ioctl() interface, so users won't have to do a    
111 commercial X server, lobby your vendor to add     
112                                                   
113                                                   
114 Creating overlapping MTRRs                        
115 ==========================                        
116 ::                                                
117                                                   
118   %echo "base=0xfb000000 size=0x1000000 type=w    
119   %echo "base=0xfb000000 size=0x1000 type=unca    
120                                                   
121 And the results::                                 
122                                                   
123   % cat /proc/mtrr                                
124   reg00: base=0x00000000 (   0MB), size=  64MB    
125   reg01: base=0xfb000000 (4016MB), size=  16MB    
126   reg02: base=0xfb000000 (4016MB), size=   4kB    
127                                                   
128 Some cards (especially Voodoo Graphics boards)    
129 excluded from the beginning of the region beca    
130 registers.                                        
131                                                   
132 NOTE: You can only create type=uncachable regi    
133 region that you created is type=write-combinin    
134                                                   
135                                                   
136 Removing MTRRs from the C-shel                    
137 ==============================                    
138 ::                                                
139                                                   
140   % echo "disable=2" >! /proc/mtrr                
141                                                   
142 or using bash::                                   
143                                                   
144   % echo "disable=2" >| /proc/mtrr                
145                                                   
146                                                   
147 Reading MTRRs from a C program using ioctl()'s    
148 ==============================================    
149 ::                                                
150                                                   
151   /*  mtrr-show.c                                 
152                                                   
153       Source file for mtrr-show (example progr    
154                                                   
155       Copyright (C) 1997-1998  Richard Gooch      
156                                                   
157       This program is free software; you can r    
158       it under the terms of the GNU General Pu    
159       the Free Software Foundation; either ver    
160       (at your option) any later version.         
161                                                   
162       This program is distributed in the hope     
163       but WITHOUT ANY WARRANTY; without even t    
164       MERCHANTABILITY or FITNESS FOR A PARTICU    
165       GNU General Public License for more deta    
166                                                   
167       You should have received a copy of the G    
168       along with this program; if not, write t    
169       Foundation, Inc., 675 Mass Ave, Cambridg    
170                                                   
171       Richard Gooch may be reached by email at    
172       The postal address is:                      
173         Richard Gooch, c/o ATNF, P. O. Box 76,    
174   */                                              
175                                                   
176   /*                                              
177       This program will use an ioctl() on /pro    
178       settings. This is an alternative to read    
179                                                   
180                                                   
181       Written by      Richard Gooch   17-DEC-1    
182                                                   
183       Last updated by Richard Gooch   2-MAY-19    
184                                                   
185                                                   
186   */                                              
187   #include <stdio.h>                              
188   #include <stdlib.h>                             
189   #include <string.h>                             
190   #include <sys/types.h>                          
191   #include <sys/stat.h>                           
192   #include <fcntl.h>                              
193   #include <sys/ioctl.h>                          
194   #include <errno.h>                              
195   #include <asm/mtrr.h>                           
196                                                   
197   #define TRUE 1                                  
198   #define FALSE 0                                 
199   #define ERRSTRING strerror (errno)              
200                                                   
201   static char *mtrr_strings[MTRR_NUM_TYPES] =     
202   {                                               
203       "uncachable",               /* 0 */         
204       "write-combining",          /* 1 */         
205       "?",                        /* 2 */         
206       "?",                        /* 3 */         
207       "write-through",            /* 4 */         
208       "write-protect",            /* 5 */         
209       "write-back",               /* 6 */         
210   };                                              
211                                                   
212   int main ()                                     
213   {                                               
214       int fd;                                     
215       struct mtrr_gentry gentry;                  
216                                                   
217       if ( ( fd = open ("/proc/mtrr", O_RDONLY    
218       {                                           
219     if (errno == ENOENT)                          
220     {                                             
221         fputs ("/proc/mtrr not found: not supp    
222         stderr);                                  
223         exit (1);                                 
224     }                                             
225     fprintf (stderr, "Error opening /proc/mtrr    
226     exit (2);                                     
227       }                                           
228       for (gentry.regnum = 0; ioctl (fd, MTRRI    
229     ++gentry.regnum)                              
230       {                                           
231     if (gentry.size < 1)                          
232     {                                             
233         fprintf (stderr, "Register: %u disable    
234         continue;                                 
235     }                                             
236     fprintf (stderr, "Register: %u base: 0x%lx    
237       gentry.regnum, gentry.base, gentry.size,    
238       mtrr_strings[gentry.type]);                 
239       }                                           
240       if (errno == EINVAL) exit (0);              
241       fprintf (stderr, "Error doing ioctl(2) o    
242       exit (3);                                   
243   }   /*  End Function main  */                   
244                                                   
245                                                   
246 Creating MTRRs from a C programme using ioctl(    
247 ==============================================    
248 ::                                                
249                                                   
250   /*  mtrr-add.c                                  
251                                                   
252       Source file for mtrr-add (example progra    
253                                                   
254       Copyright (C) 1997-1998  Richard Gooch      
255                                                   
256       This program is free software; you can r    
257       it under the terms of the GNU General Pu    
258       the Free Software Foundation; either ver    
259       (at your option) any later version.         
260                                                   
261       This program is distributed in the hope     
262       but WITHOUT ANY WARRANTY; without even t    
263       MERCHANTABILITY or FITNESS FOR A PARTICU    
264       GNU General Public License for more deta    
265                                                   
266       You should have received a copy of the G    
267       along with this program; if not, write t    
268       Foundation, Inc., 675 Mass Ave, Cambridg    
269                                                   
270       Richard Gooch may be reached by email at    
271       The postal address is:                      
272         Richard Gooch, c/o ATNF, P. O. Box 76,    
273   */                                              
274                                                   
275   /*                                              
276       This programme will use an ioctl() on /p    
277       available mtrr is used. This is an alter    
278                                                   
279                                                   
280       Written by      Richard Gooch   17-DEC-1    
281                                                   
282       Last updated by Richard Gooch   2-MAY-19    
283                                                   
284                                                   
285   */                                              
286   #include <stdio.h>                              
287   #include <string.h>                             
288   #include <stdlib.h>                             
289   #include <unistd.h>                             
290   #include <sys/types.h>                          
291   #include <sys/stat.h>                           
292   #include <fcntl.h>                              
293   #include <sys/ioctl.h>                          
294   #include <errno.h>                              
295   #include <asm/mtrr.h>                           
296                                                   
297   #define TRUE 1                                  
298   #define FALSE 0                                 
299   #define ERRSTRING strerror (errno)              
300                                                   
301   static char *mtrr_strings[MTRR_NUM_TYPES] =     
302   {                                               
303       "uncachable",               /* 0 */         
304       "write-combining",          /* 1 */         
305       "?",                        /* 2 */         
306       "?",                        /* 3 */         
307       "write-through",            /* 4 */         
308       "write-protect",            /* 5 */         
309       "write-back",               /* 6 */         
310   };                                              
311                                                   
312   int main (int argc, char **argv)                
313   {                                               
314       int fd;                                     
315       struct mtrr_sentry sentry;                  
316                                                   
317       if (argc != 4)                              
318       {                                           
319     fprintf (stderr, "Usage:\tmtrr-add base si    
320     exit (1);                                     
321       }                                           
322       sentry.base = strtoul (argv[1], NULL, 0)    
323       sentry.size = strtoul (argv[2], NULL, 0)    
324       for (sentry.type = 0; sentry.type < MTRR    
325       {                                           
326     if (strcmp (argv[3], mtrr_strings[sentry.t    
327       }                                           
328       if (sentry.type >= MTRR_NUM_TYPES)          
329       {                                           
330     fprintf (stderr, "Illegal type: \"%s\"\n",    
331     exit (2);                                     
332       }                                           
333       if ( ( fd = open ("/proc/mtrr", O_WRONLY    
334       {                                           
335     if (errno == ENOENT)                          
336     {                                             
337         fputs ("/proc/mtrr not found: not supp    
338         stderr);                                  
339         exit (3);                                 
340     }                                             
341     fprintf (stderr, "Error opening /proc/mtrr    
342     exit (4);                                     
343       }                                           
344       if (ioctl (fd, MTRRIOC_ADD_ENTRY, &sentr    
345       {                                           
346     fprintf (stderr, "Error doing ioctl(2) on     
347     exit (5);                                     
348       }                                           
349       fprintf (stderr, "Sleeping for 5 seconds    
350       sleep (5);                                  
351       close (fd);                                 
352       fputs ("I've just closed /proc/mtrr so n    
353       stderr);                                    
354   }   /*  End Function main  */                   
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php