2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <html xmlns="http://www.w3.org/1999/xhtml">
7 <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9 <title>Physical Memory Protection — Freedom Metal v201905 documentation</title>
10 <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
11 <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
12 <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
13 <script type="text/javascript" src="../_static/jquery.js"></script>
14 <script type="text/javascript" src="../_static/underscore.js"></script>
15 <script type="text/javascript" src="../_static/doctools.js"></script>
16 <link rel="index" title="Index" href="../genindex.html" />
17 <link rel="search" title="Search" href="../search.html" />
18 <link rel="next" title="Standard I/O" href="tty.html" />
19 <link rel="prev" title="Instruction Tightly Integrated Memory" href="itim.html" />
21 <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
24 <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
29 <div class="document">
30 <div class="documentwrapper">
31 <div class="bodywrapper">
34 <div class="body" role="main">
36 <div class="section" id="physical-memory-protection">
37 <h1>Physical Memory Protection<a class="headerlink" href="#physical-memory-protection" title="Permalink to this headline">¶</a></h1>
38 <p>Physical Memory Protection (PMP) is a part of the RISC-V Privileged Architecture
39 Specification which discribes the interface for a standard RISC-V memory
41 <p>The PMP defines a finite number of PMP regions which can be individually configured
42 to enforce access permissions to a range of addresses in memory. Each PMP region
43 is configurable with the following options:</p>
46 <em class="property">struct </em><code class="descname">metal_pmp_config</code><br /></dt>
47 <dd><p>Configuration for a PMP region. </p>
48 <div class="breathe-sectiondef docutils container">
49 <p class="breathe-sectiondef-title rubric">Public Types</p>
52 <em class="property">enum </em><code class="descname">metal_pmp_locked</code><br /></dt>
53 <dd><p>Sets whether the PMP region is locked. </p>
54 <p><em>Values:</em></p>
55 <dl class="enumerator">
57 <code class="descname">METAL_PMP_UNLOCKED</code> = 0<br /></dt>
60 <dl class="enumerator">
62 <code class="descname">METAL_PMP_LOCKED</code> = 1<br /></dt>
68 <div class="breathe-sectiondef docutils container">
69 <p class="breathe-sectiondef-title rubric">Public Members</p>
72 int <code class="descname">R</code><br /></dt>
73 <dd><p>Sets whether reads to the PMP region succeed. </p>
78 int <code class="descname">W</code><br /></dt>
79 <dd><p>Sets whether writes to the PMP region succeed. </p>
84 int <code class="descname">X</code><br /></dt>
85 <dd><p>Sets whether the PMP region is executable. </p>
90 <a class="reference internal" href="../apiref/pmp.html#_CPPv322metal_pmp_address_mode" title="metal_pmp_address_mode">metal_pmp_address_mode</a> <code class="descname">A</code><br /></dt>
91 <dd><p>Sets the addressing mode of the PMP region. </p>
97 <div class="section" id="initializing-the-pmp">
98 <h2>Initializing the PMP<a class="headerlink" href="#initializing-the-pmp" title="Permalink to this headline">¶</a></h2>
99 <p>All PMP-related functions first depend on having a handle to the PMP device:</p>
100 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span> <span class="n">metal_pmp</span> <span class="o">*</span><span class="n">pmp</span> <span class="o">=</span> <span class="n">metal_pmp_get_device</span><span class="p">();</span>
101 <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">pmp</span><span class="p">)</span> <span class="p">{</span>
102 <span class="cm">/* Failed to get PMP device handle */</span>
103 <span class="p">}</span>
106 <p>PMP initialization is optional and has the effect of disabling all PMP regions,
108 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="n">metal_pmp_init</span><span class="p">(</span><span class="n">pmp</span><span class="p">);</span>
111 <p>The number of PMP regions available can be retrieved from the PMP device handle:</p>
114 <em class="property">struct </em><code class="descname">metal_pmp</code><br /></dt>
115 <dd><p>A handle for the PMP device. </p>
119 <div class="section" id="configuring-a-pmp-region">
120 <h2>Configuring a PMP Region<a class="headerlink" href="#configuring-a-pmp-region" title="Permalink to this headline">¶</a></h2>
121 <p>Freedom Metal has a set of APIs for configuring a PMP region. The most generic of these
123 <dl class="function">
124 <dt id="_CPPv320metal_pmp_set_regionP9metal_pmpj16metal_pmp_config6size_t">
125 <span id="_CPPv220metal_pmp_set_regionP9metal_pmpj16metal_pmp_config6size_t"></span><span id="metal_pmp_set_region__metal_pmpP.unsigned-i.metal_pmp_config.s"></span><span class="target" id="pmp_8h_1acdbdbc7cc2727d4ae10205617aee3013"></span>int <code class="descname">metal_pmp_set_region</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="../apiref/pmp.html#_CPPv39metal_pmp" title="metal_pmp">metal_pmp</a> *<em>pmp</em>, unsigned int <em>region</em>, <em class="property">struct</em> <a class="reference internal" href="../apiref/pmp.html#_CPPv316metal_pmp_config" title="metal_pmp_config">metal_pmp_config</a> <em>config</em>, size_t <em>address</em><span class="sig-paren">)</span><br /></dt>
126 <dd><p>Configure a PMP region. </p>
127 <p><dl class="docutils">
128 <dt><strong>Return</strong></dt>
129 <dd>0 upon success </dd>
130 <dt><strong>Parameters</strong></dt>
131 <dd><ul class="breatheparameterlist first last simple">
132 <li><code class="docutils literal notranslate"><span class="pre">pmp</span></code>: The PMP device handle </li>
133 <li><code class="docutils literal notranslate"><span class="pre">region</span></code>: The PMP region to configure </li>
134 <li><code class="docutils literal notranslate"><span class="pre">config</span></code>: The desired configuration of the PMP region </li>
135 <li><code class="docutils literal notranslate"><span class="pre">address</span></code>: The desired address of the PMP region </li>
142 <p>This function allows for the configuration of all PMP region settings.</p>
143 <p>Additional APIs are provided for granularly changing individual PMP region settings.
145 <dl class="function">
147 int <code class="descname">metal_pmp_set_address</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="../apiref/pmp.html#_CPPv39metal_pmp" title="metal_pmp">metal_pmp</a> *<em>pmp</em>, unsigned int <em>region</em>, size_t <em>address</em><span class="sig-paren">)</span><br /></dt>
148 <dd><p>Set the address for a PMP region. </p>
149 <p><dl class="docutils">
150 <dt><strong>Return</strong></dt>
151 <dd>0 if the address is successfully set </dd>
152 <dt><strong>Parameters</strong></dt>
153 <dd><ul class="breatheparameterlist first last simple">
154 <li><code class="docutils literal notranslate"><span class="pre">pmp</span></code>: The PMP device handle </li>
155 <li><code class="docutils literal notranslate"><span class="pre">region</span></code>: The PMP region to set </li>
156 <li><code class="docutils literal notranslate"><span class="pre">address</span></code>: The desired address of the PMP region </li>
163 <dl class="function">
165 int <code class="descname">metal_pmp_lock</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="../apiref/pmp.html#_CPPv39metal_pmp" title="metal_pmp">metal_pmp</a> *<em>pmp</em>, unsigned int <em>region</em><span class="sig-paren">)</span><br /></dt>
166 <dd><p>Lock a PMP region. </p>
167 <p><dl class="docutils">
168 <dt><strong>Return</strong></dt>
169 <dd>0 if the region is successfully locked </dd>
170 <dt><strong>Parameters</strong></dt>
171 <dd><ul class="breatheparameterlist first last simple">
172 <li><code class="docutils literal notranslate"><span class="pre">pmp</span></code>: The PMP device handle </li>
173 <li><code class="docutils literal notranslate"><span class="pre">region</span></code>: The PMP region to lock </li>
180 <dl class="function">
182 int <code class="descname">metal_pmp_set_writeable</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="../apiref/pmp.html#_CPPv39metal_pmp" title="metal_pmp">metal_pmp</a> *<em>pmp</em>, unsigned int <em>region</em>, int <em>W</em><span class="sig-paren">)</span><br /></dt>
183 <dd><p>Set the writable bit for a PMP region. </p>
184 <p><dl class="docutils">
185 <dt><strong>Return</strong></dt>
186 <dd>0 if the writable bit is successfully set </dd>
187 <dt><strong>Parameters</strong></dt>
188 <dd><ul class="breatheparameterlist first last simple">
189 <li><code class="docutils literal notranslate"><span class="pre">pmp</span></code>: The PMP device handle </li>
190 <li><code class="docutils literal notranslate"><span class="pre">region</span></code>: The PMP region to set </li>
191 <li><code class="docutils literal notranslate"><span class="pre">W</span></code>: The desired value of the writable bit </li>
198 <p>Additional documentation for this API is provided in <a class="reference internal" href="../apiref/pmp.html"><span class="doc">the PMP API reference</span></a>.</p>
199 <p>The RISC-V specification allows implementation of PMP to hard-wire the configuration
200 values of PMP regions. In these cases, attempts to configure these PMP regions will
203 <div class="section" id="handling-pmp-access-faults">
204 <h2>Handling PMP Access Faults<a class="headerlink" href="#handling-pmp-access-faults" title="Permalink to this headline">¶</a></h2>
205 <p>Attempted memory accesses which the PMP is configured to prevent trigger a
206 CPU exception. These exceptions can be handled by installing a CPU exception
207 handler for exception codes related to memory access faults.</p>
208 <p>Additional documentation about creating and registering exception handlers can
209 be found in <a class="reference internal" href="exceptions.html"><span class="doc">the Exception Handlers Developer Guide</span></a>.</p>
211 <div class="section" id="additional-documentation">
212 <h2>Additional Documentation<a class="headerlink" href="#additional-documentation" title="Permalink to this headline">¶</a></h2>
213 <p>Additional documentation about the Physical Memory Protection system and fault
214 handling on RISC-V systems can be found in
215 <a class="reference external" href="https://riscv.org/specifications/privileged-isa/">The RISC-V Privileged ISA Specification v1.10</a>.</p>
224 <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
225 <div class="sphinxsidebarwrapper">
226 <h1 class="logo"><a href="../index.html">Freedom Metal</a></h1>
237 <li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to Freedom Metal</a></li>
238 <li class="toctree-l1 current"><a class="reference internal" href="../devguide.html">Developer Guide</a><ul class="current">
239 <li class="toctree-l2"><a class="reference internal" href="exceptions.html">Exception Handlers</a></li>
240 <li class="toctree-l2"><a class="reference internal" href="fe310-g000-pll.html">FE310-G00 PLL</a></li>
241 <li class="toctree-l2"><a class="reference internal" href="interrupts.html">Interrupt Handlers</a></li>
242 <li class="toctree-l2"><a class="reference internal" href="itim.html">Instruction Tightly Integrated Memory</a></li>
243 <li class="toctree-l2 current"><a class="current reference internal" href="#">Physical Memory Protection</a></li>
244 <li class="toctree-l2"><a class="reference internal" href="tty.html">Standard I/O</a></li>
247 <li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li>
250 <div class="relations">
251 <h3>Related Topics</h3>
253 <li><a href="../index.html">Documentation overview</a><ul>
254 <li><a href="../devguide.html">Developer Guide</a><ul>
255 <li>Previous: <a href="itim.html" title="previous chapter">Instruction Tightly Integrated Memory</a></li>
256 <li>Next: <a href="tty.html" title="next chapter">Standard I/O</a></li>
261 <div id="searchbox" style="display: none" role="search">
262 <h3>Quick search</h3>
263 <div class="searchformwrapper">
264 <form class="search" action="../search.html" method="get">
265 <input type="text" name="q" />
266 <input type="submit" value="Go" />
267 <input type="hidden" name="check_keywords" value="yes" />
268 <input type="hidden" name="area" value="default" />
272 <script type="text/javascript">$('#searchbox').show(0);</script>
275 <div class="clearer"></div>
278 ©2019, SiFive Inc..
281 Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a>
282 & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a>
285 <a href="../_sources/devguide/pmps.rst.txt"
286 rel="nofollow">Page source</a>