Fletchgen
The Fletcher Design Generator
mmio.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <fletcher/arrow-utils.h>
18 #include <cerata/api.h>
19 #include <string>
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 #include <unordered_map>
24 
25 #include "fletchgen/axi4_lite.h"
26 
27 namespace fletchgen {
28 
29 using cerata::Component;
30 using cerata::Instance;
31 using cerata::Node;
32 using cerata::Literal;
33 using cerata::Port;
34 using cerata::Parameter;
35 using cerata::PortArray;
36 using cerata::integer;
37 using cerata::Type;
38 using cerata::ClockDomain;
39 
41 constexpr char MMIO_DEFAULT[] = "fletchgen_mmio_default";
43 constexpr char MMIO_BATCH[] = "fletchgen_mmio_batch";
45 constexpr char MMIO_BUFFER[] = "fletchgen_mmio_buffer";
47 constexpr char MMIO_KERNEL[] = "fletchgen_mmio_kernel";
49 constexpr char MMIO_PROFILE[] = "fletchgen_mmio_profile";
50 
52 enum class MmioFunction {
53  DEFAULT,
54  BATCH,
55  BUFFER,
56  KERNEL,
57  PROFILE
58 };
59 
61 enum class MmioBehavior {
62  CONTROL,
63  STATUS,
64  STROBE,
65 };
66 
68 struct MmioReg {
70  MmioReg() = default;
74  std::string name,
75  std::string desc,
76  uint32_t width,
77  uint32_t index = 0,
78  std::optional<uint32_t> addr = std::nullopt,
79  std::optional<uint64_t> init = std::nullopt)
80  : function(function),
82  name(std::move(name)),
83  desc(std::move(desc)),
84  width(width),
85  index(index),
86  addr(addr),
87  init(init) {}
90  std::string name;
91  std::string desc;
92  uint32_t width = 1;
93  uint32_t index = 0;
94  std::optional<uint32_t> addr = std::nullopt;
95  std::optional<uint64_t> init = std::nullopt;
96  std::unordered_map<std::string, std::string> meta;
97 };
98 
100 bool ExposeToKernel(MmioFunction fun);
101 
105 struct MmioPort : public Port {
107  MmioPort(const std::string &name,
108  Port::Dir dir,
109  const MmioReg &reg,
110  const std::shared_ptr<ClockDomain> &domain = cerata::default_domain());
114  std::shared_ptr<Object> Copy() const override;
115 };
116 
118 std::shared_ptr<MmioPort> mmio_port(Port::Dir dir, const MmioReg &reg,
119  const std::shared_ptr<ClockDomain> &domain = cerata::default_domain());
120 
130 std::string GenerateVhdmmioYaml(const std::vector<std::vector<MmioReg> *> &regs,
131  Axi4LiteSpec axi_spec,
132  std::optional<size_t *> next_addr = std::nullopt);
133 
145 std::shared_ptr<Component> mmio(const std::vector<fletcher::RecordBatchDescription> &batches,
146  const std::vector<MmioReg> &regs,
147  Axi4LiteSpec axi_spec);
148 
149 } // namespace fletchgen
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
std::shared_ptr< MmioPort > mmio_port(Port::Dir dir, const MmioReg &reg, const std::shared_ptr< ClockDomain > &domain)
Create an mmio port.
Definition: mmio.cc:58
constexpr char MMIO_BATCH[]
Fletchgen metadata for mmio-controlled buffer address ports.
Definition: mmio.h:43
constexpr char MMIO_DEFAULT[]
Fletchgen metadata for mmio-controlled buffer address ports.
Definition: mmio.h:41
constexpr char MMIO_PROFILE[]
Fletchgen metadata for mmio-controlled profiling ports.
Definition: mmio.h:49
MmioBehavior
Register access behavior enumeration.
Definition: mmio.h:61
@ STATUS
Register contents is controlled by hardware kernel.
@ CONTROL
Register contents is controlled by host software.
@ STROBE
Register contents is asserted for one cycle by host software.
constexpr char MMIO_KERNEL[]
Fletchgen metadata for mmio-controlled kernel ports.
Definition: mmio.h:47
MmioFunction
Register intended use enumeration.
Definition: mmio.h:52
@ BUFFER
Registers for buffer addresses.
@ KERNEL
Registers for the kernel.
@ BATCH
Registers for RecordBatch metadata.
@ PROFILE
Register for the profiler.
@ DEFAULT
Default registers.
constexpr char MMIO_BUFFER[]
Fletchgen metadata for mmio-controlled buffer address ports.
Definition: mmio.h:45
bool ExposeToKernel(MmioFunction fun)
Return true if an mmio register's function must cause it to be exposed to the user kernel.
Definition: mmio.cc:165
std::string GenerateVhdmmioYaml(const std::vector< std::vector< MmioReg > * > &regs, Axi4LiteSpec axi_spec, std::optional< size_t * > next_addr)
Returns a YAML string for the vhdmmio tool based on a set of registers.
Definition: mmio.cc:99
std::shared_ptr< Component > mmio(const std::vector< fletcher::RecordBatchDescription > &batches, const std::vector< MmioReg > &regs, Axi4LiteSpec axi_spec)
Generate the MMIO component for the nucleus.
Definition: mmio.cc:62
AXI4-lite bus specification.
Definition: axi4_lite.h:29
A port on the vhdmmio component. Remembers what register spec it came from.
Definition: mmio.h:105
std::shared_ptr< Object > Copy() const override
Make a copy of this MmioPort.
Definition: mmio.cc:54
MmioReg reg
The Mmio register this port will represent.
Definition: mmio.h:112
MmioPort(const std::string &name, Port::Dir dir, const MmioReg &reg, const std::shared_ptr< ClockDomain > &domain=cerata::default_domain())
MmioPort constructor.
Definition: mmio.cc:50
Structure to represent an MMIO register.
Definition: mmio.h:68
std::optional< uint64_t > init
Optional initial value.
Definition: mmio.h:95
std::string desc
Register description.
Definition: mmio.h:91
MmioBehavior behavior
Register access behavior.
Definition: mmio.h:89
uint32_t index
LSB start index at that address.
Definition: mmio.h:93
MmioFunction function
Register intended use.
Definition: mmio.h:88
uint32_t width
Bit width.
Definition: mmio.h:92
MmioReg()=default
MmioReg default constructor.
MmioReg(MmioFunction function, MmioBehavior behavior, std::string name, std::string desc, uint32_t width, uint32_t index=0, std::optional< uint32_t > addr=std::nullopt, std::optional< uint64_t > init=std::nullopt)
MmioReg constructor.
Definition: mmio.h:72
std::string name
Register mame.
Definition: mmio.h:90
std::unordered_map< std::string, std::string > meta
Metadata.
Definition: mmio.h:96
std::optional< uint32_t > addr
Optional address.
Definition: mmio.h:94