11#include "mlir/IR/Builders.h"
12#include "mlir/IR/DialectImplementation.h"
13#include "llvm/ADT/TypeSwitch.h"
14#include "llvm/Support/MathExtras.h"
20#define GET_TYPEDEF_CLASSES
21#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
23LogicalResult PortType::verify(function_ref<InFlightDiagnostic()> emitError,
24 uint32_t addr_width, uint32_t data_width,
25 uint32_t write_id_width, uint32_t read_id_width,
26 uint32_t user_width, WindowSetAttr windows,
27 uint32_t outstanding_writes,
28 uint32_t outstanding_reads) {
30 return emitError() <<
"port 'addr_width' must be at most 64, got "
32 if (data_width < 8 || data_width > 1024 || !llvm::isPowerOf2_32(data_width))
33 return emitError() <<
"port 'data_width' must be a power of two between 8 "
38 for (WindowAttr window : windows.getWindows())
39 if (window.getLast() >> addr_width)
40 return emitError() <<
"port window " << window
41 <<
" does not fit in an 'addr_width' of "
43 if (write_id_width > 32)
44 return emitError() <<
"port 'write_id_width' must be at most 32, got "
46 if (read_id_width > 32)
47 return emitError() <<
"port 'read_id_width' must be at most 32, got "
50 if (outstanding_writes > (uint64_t{1} << write_id_width))
51 return emitError() <<
"port 'outstanding_writes' must be at most "
52 << (uint64_t{1} << write_id_width)
53 <<
" for a 'write_id_width' of " << write_id_width
54 <<
", got " << outstanding_writes;
55 if (outstanding_reads > (uint64_t{1} << read_id_width))
56 return emitError() <<
"port 'outstanding_reads' must be at most "
57 << (uint64_t{1} << read_id_width)
58 <<
" for a 'read_id_width' of " << read_id_width
59 <<
", got " << outstanding_reads;
64 MLIRContext *ctx = port.getContext();
65 auto field = [&](StringRef name,
unsigned width) {
66 return hw::StructType::FieldInfo{StringAttr::get(ctx, name),
67 IntegerType::get(ctx, width)};
70 auto addressFields = [&](
unsigned idWidth) {
71 return SmallVector<hw::StructType::FieldInfo>{
73 field(
"addr", port.getAddrWidth()),
82 field(
"user", port.getUserWidth())};
85 SmallVector<hw::StructType::FieldInfo> fields;
88 fields = addressFields(port.getWriteIdWidth());
91 fields = addressFields(port.getReadIdWidth());
94 fields = {field(
"data", port.getDataWidth()),
95 field(
"strb", port.getDataWidth() / 8), field(
"last",
kLastWidth),
96 field(
"user", port.getUserWidth())};
99 fields = {field(
"id", port.getWriteIdWidth()), field(
"resp",
kRespWidth),
100 field(
"user", port.getUserWidth())};
103 fields = {field(
"id", port.getReadIdWidth()),
104 field(
"data", port.getDataWidth()), field(
"resp",
kRespWidth),
105 field(
"last",
kLastWidth), field(
"user", port.getUserWidth())};
108 return hw::StructType::get(ctx, fields);
111void AXI4Dialect::registerTypes() {
113#define GET_TYPEDEF_LIST
114#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
constexpr unsigned kRespWidth
constexpr unsigned kProtWidth
constexpr unsigned kLastWidth
constexpr unsigned kQosWidth
hw::StructType getChannelPayloadType(PortType port, AXI4Channel channel)
Build the hw.struct payload type for one channel of an !axi4.port.
constexpr unsigned kRegionWidth
AXI4Channel
The five AXI4 channels.
constexpr unsigned kBurstWidth
constexpr unsigned kLenWidth
constexpr unsigned kSizeWidth
constexpr unsigned kCacheWidth
constexpr unsigned kLockWidth
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.