CIRCT 24.0.0git
Loading...
Searching...
No Matches
AXI4Types.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "mlir/IR/Builders.h"
12#include "mlir/IR/DialectImplementation.h"
13#include "llvm/ADT/TypeSwitch.h"
14#include "llvm/Support/MathExtras.h"
15
16using namespace circt;
17using namespace axi4;
18using namespace mlir;
19
20#define GET_TYPEDEF_CLASSES
21#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
22
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) {
29 if (addr_width > 64)
30 return emitError() << "port 'addr_width' must be at most 64, got "
31 << addr_width;
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 "
34 "and 1024, got "
35 << data_width;
36 if (write_id_width > 32)
37 return emitError() << "port 'write_id_width' must be at most 32, got "
38 << write_id_width;
39 if (read_id_width > 32)
40 return emitError() << "port 'read_id_width' must be at most 32, got "
41 << read_id_width;
42 // Bounds computed in 64 bits to avoid 32-bit overflow if ID widths are 32.
43 if (outstanding_writes > (uint64_t{1} << write_id_width))
44 return emitError() << "port 'outstanding_writes' must be at most "
45 << (uint64_t{1} << write_id_width)
46 << " for a 'write_id_width' of " << write_id_width
47 << ", got " << outstanding_writes;
48 if (outstanding_reads > (uint64_t{1} << read_id_width))
49 return emitError() << "port 'outstanding_reads' must be at most "
50 << (uint64_t{1} << read_id_width)
51 << " for a 'read_id_width' of " << read_id_width
52 << ", got " << outstanding_reads;
53 return success();
54}
55
56hw::StructType axi4::getChannelPayloadType(PortType port, AXI4Channel channel) {
57 MLIRContext *ctx = port.getContext();
58 auto field = [&](StringRef name, unsigned width) {
59 return hw::StructType::FieldInfo{StringAttr::get(ctx, name),
60 IntegerType::get(ctx, width)};
61 };
62 // Address channels differ only in which ID width they carry.
63 auto addressFields = [&](unsigned idWidth) {
64 return SmallVector<hw::StructType::FieldInfo>{
65 field("id", idWidth),
66 field("addr", port.getAddrWidth()),
67 field("len", kLenWidth),
68 field("size", kSizeWidth),
69 field("burst", kBurstWidth),
70 field("lock", kLockWidth),
71 field("cache", kCacheWidth),
72 field("prot", kProtWidth),
73 field("qos", kQosWidth),
74 field("region", kRegionWidth),
75 field("user", port.getUserWidth())};
76 };
77
78 SmallVector<hw::StructType::FieldInfo> fields;
79 switch (channel) {
80 case AXI4Channel::AW:
81 fields = addressFields(port.getWriteIdWidth());
82 break;
83 case AXI4Channel::AR:
84 fields = addressFields(port.getReadIdWidth());
85 break;
86 case AXI4Channel::W:
87 fields = {field("data", port.getDataWidth()),
88 field("strb", port.getDataWidth() / 8), field("last", kLastWidth),
89 field("user", port.getUserWidth())};
90 break;
91 case AXI4Channel::B:
92 fields = {field("id", port.getWriteIdWidth()), field("resp", kRespWidth),
93 field("user", port.getUserWidth())};
94 break;
95 case AXI4Channel::R:
96 fields = {field("id", port.getReadIdWidth()),
97 field("data", port.getDataWidth()), field("resp", kRespWidth),
98 field("last", kLastWidth), field("user", port.getUserWidth())};
99 break;
100 }
101 return hw::StructType::get(ctx, fields);
102}
103
104void AXI4Dialect::registerTypes() {
105 addTypes<
106#define GET_TYPEDEF_LIST
107#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
108 >();
109}
constexpr unsigned kRespWidth
Definition AXI4Types.h:35
constexpr unsigned kProtWidth
Definition AXI4Types.h:32
constexpr unsigned kLastWidth
Definition AXI4Types.h:36
constexpr unsigned kQosWidth
Definition AXI4Types.h:33
hw::StructType getChannelPayloadType(PortType port, AXI4Channel channel)
Build the hw.struct payload type for one channel of an !axi4.port.
Definition AXI4Types.cpp:56
constexpr unsigned kRegionWidth
Definition AXI4Types.h:34
AXI4Channel
The five AXI4 channels.
Definition AXI4Types.h:24
constexpr unsigned kBurstWidth
Definition AXI4Types.h:29
constexpr unsigned kLenWidth
Definition AXI4Types.h:27
constexpr unsigned kSizeWidth
Definition AXI4Types.h:28
constexpr unsigned kCacheWidth
Definition AXI4Types.h:31
constexpr unsigned kLockWidth
Definition AXI4Types.h:30
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.