You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This manual is a work in progress and is seriously incomplete!
2
+
###########
7
3
8
4
.. py:module:: amaranth_soc.memory
9
5
10
6
The :mod:`amaranth_soc.memory` module provides primitives for organizing the address space of a bus interface.
11
7
8
+
.. testsetup::
9
+
10
+
from amaranth import *
11
+
12
+
from amaranth_soc import csr
13
+
from amaranth_soc.memory import *
14
+
15
+
.. _memory-introduction:
16
+
17
+
Introduction
18
+
============
19
+
20
+
The purpose of :class:`MemoryMap` is to provide a hierarchical description of the address space of a System-on-Chip, from its bus interconnect to the registers of its peripherals. It is composed of :ref:`resources <memory-resources>` (representing registers, memories, etc) and :ref:`windows <memory-windows>` (representing bus bridges), and may be :ref:`queried <memory-accessing-windows>` afterwards in order to enumerate its contents, or determine the address of a resource.
21
+
22
+
.. _memory-resources:
23
+
24
+
Resources
25
+
=========
26
+
27
+
A *resource* is a :class:`~amaranth.lib.wiring.Component` previously added to a :class:`MemoryMap`. Each resource occupies an unique range of addresses within the memory map, and represents a device that is a target for bus transactions.
28
+
29
+
Adding resources
30
+
++++++++++++++++
31
+
32
+
Resources are added with :meth:`MemoryMap.add_resource`, which returns a ``(start, end)`` tuple describing their address range:
The ``addr`` parameter of :meth:`MemoryMap.add_resource` and :meth:`MemoryMap.add_window` is optional.
53
+
54
+
To simplify address assignment, each :class:`MemoryMap` has an *implicit next address*, starting at 0. If a resource or a window is added without an explicit address, the implicit next address is used. In any case, the implicit next address is set to the address immediately following the newly added resource or window.
55
+
56
+
Accessing resources
57
+
+++++++++++++++++++
58
+
59
+
Memory map resources can be iterated with :meth:`MemoryMap.resources`:
60
+
61
+
.. doctest::
62
+
63
+
>>> for resource, name, (start, end) in memory_map.resources():
The resource located at a given address can be retrieved with :meth:`MemoryMap.decode_address`:
76
+
77
+
.. doctest::
78
+
79
+
>>> memory_map.decode_address(0x4) is reg_data
80
+
True
81
+
82
+
Alignment
83
+
=========
84
+
85
+
The value of :attr:`MemoryMap.alignment` constrains the layout of a memory map. If unspecified, it defaults to 0.
86
+
87
+
Each resource or window added to a memory map is placed at an address that is a multiple of ``2 ** alignment``, and its size is rounded up to a multiple of ``2 ** alignment``.
88
+
89
+
For example, the resources of this memory map are 64-bit aligned:
ValueError: Explicitly specified address 0x9 must be a multiple of 0x8 bytes
107
+
108
+
:meth:`MemoryMap.add_resource` takes an optional ``alignment`` parameter. If a value greater than :attr:`MemoryMap.alignment` is given, it becomes the alignment of this resource:
:meth:`MemoryMap.align_to` can be used to align the :ref:`implicit next address <memory-implicit-next-address>`. Its alignment is modified if a value greater than :attr:`MemoryMap.alignment` is given.
.. note:: :meth:`MemoryMap.align_to` has no effect on the size of the next resource or window.
125
+
126
+
.. _memory-windows:
127
+
128
+
Windows
129
+
=======
130
+
131
+
A *window* is a :class:`MemoryMap` nested inside another memory map. Each window occupies an unique range of addresses within the memory map, and represents a bridge to a subordinate bus.
132
+
133
+
Adding windows
134
+
++++++++++++++
135
+
136
+
Windows are added with :meth:`MemoryMap.add_window`, which returns a ``(start, end, ratio)`` tuple describing their address range:
The third value returned by :meth:`MemoryMap.add_window` represents the number of addresses that are accessed in the bus described by ``rx_window`` for one transaction in the bus described by ``memory_map``. It is 1 in this case, as both busses have the same width.
Windows can also be iterated with :meth:`MemoryMap.window_patterns`, which encodes their address ranges as bit patterns compatible with the :ref:`match operator <lang-matchop>` and the :ref:`Case block <lang-switch>`:
182
+
183
+
.. doctest::
184
+
185
+
>>> for window, (pattern, ratio) in memory_map.window_patterns():
When a memory map resource is accessed through a window, address translation may happen in three different modes.
204
+
205
+
Transparent mode
206
+
----------------
207
+
208
+
In *transparent mode*, each transaction on the primary bus results in one transaction on the subordinate bus without loss of data. This mode is selected when :meth:`MemoryMap.add_window` is given ``sparse=None``, which will fail if the window and the memory map have a different data widths.
209
+
210
+
.. note::
211
+
212
+
In practice, transparent mode is identical to other modes; it can only be used with equal data widths, which results in the same behavior regardless of the translation mode. However, it causes :meth:`MemoryMap.add_window` to fail if the data widths are different.
213
+
214
+
Sparse mode
215
+
-----------
216
+
217
+
In *sparse mode*, each transaction on the wide primary bus results in one transaction on the narrow subordinate bus. High data bits on the primary bus are ignored, and any contiguous resource on the subordinate bus becomes discontiguous on the primary bus. This mode is selected when :meth:`MemoryMap.add_window` is given ``sparse=True``.
218
+
219
+
Dense mode
220
+
----------
221
+
222
+
In *dense mode*, each transaction on the wide primary bus results in several transactions on the narrow subordinate bus, and any contiguous resource on the subordinate bus stays contiguous on the primary bus. This mode is selected when :meth:`MemoryMap.add_window` is given ``sparse=False``.
223
+
224
+
Freezing
225
+
========
226
+
227
+
The state of a memory map can become immutable by calling :meth:`MemoryMap.freeze`:
0 commit comments