Loading [MathJax]/jax/input/TeX/config.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ESIStdServices.cpp
Go to the documentation of this file.
1//===- ESIStdServices.cpp - ESI standard services -------------------------===//
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
14
15#include "mlir/IR/BuiltinTypes.h"
16#include "mlir/IR/ImplicitLocOpBuilder.h"
17
18#include <map>
19#include <memory>
20
21using namespace circt;
22using namespace circt::esi;
23
24/// Utility function to create a req/resp pair bundle service port.
25static ServicePortInfo createReqResp(StringAttr sym, Twine name,
26 StringRef reqName, Type reqType,
27 StringRef respName, Type respType) {
28 assert(reqType && respType);
29 auto *ctxt = reqType ? reqType.getContext() : respType.getContext();
30 auto bundle = ChannelBundleType::get(
31 ctxt,
32 {BundledChannel{StringAttr::get(ctxt, reqName), ChannelDirection::from,
33 ChannelType::get(ctxt, reqType)},
34 BundledChannel{StringAttr::get(ctxt, respName), ChannelDirection::to,
35 ChannelType::get(ctxt, respType)}},
36 /*resettable=false*/ UnitAttr());
37 return {hw::InnerRefAttr::get(sym, StringAttr::get(ctxt, name)), bundle};
38}
39
40ServicePortInfo RandomAccessMemoryDeclOp::writePortInfo() {
41 auto *ctxt = getContext();
42 auto addressType =
43 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
44 IntegerType::SignednessSemantics::Unsigned);
45
46 // Write port
47 hw::StructType writeType = hw::StructType::get(
48 ctxt,
49 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
50 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
51 getInnerType()}});
52 return createReqResp(getSymNameAttr(), "write", "req", writeType, "ack",
53 IntegerType::get(ctxt, 0));
54}
55
56ServicePortInfo RandomAccessMemoryDeclOp::readPortInfo() {
57 auto *ctxt = getContext();
58 auto addressType =
59 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
60 IntegerType::SignednessSemantics::Unsigned);
61
62 return createReqResp(getSymNameAttr(), "read", "address", addressType, "data",
63 getInnerType());
64}
65
66void RandomAccessMemoryDeclOp::getPortList(
67 SmallVectorImpl<ServicePortInfo> &ports) {
68 ports.push_back(writePortInfo());
69 ports.push_back(readPortInfo());
70}
71
72void CallServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
73 auto *ctxt = getContext();
74 ports.push_back(ServicePortInfo{
75 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
76 ChannelBundleType::get(
77 ctxt,
78 {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::from,
79 ChannelType::get(ctxt, AnyType::get(ctxt))},
80 BundledChannel{StringAttr::get(ctxt, "result"), ChannelDirection::to,
81 ChannelType::get(ctxt, AnyType::get(ctxt))}},
82 /*resettable=*/UnitAttr())});
83}
84
85void FuncServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
86 auto *ctxt = getContext();
87 ports.push_back(ServicePortInfo{
88 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
89 ChannelBundleType::get(
90 ctxt,
91 {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::to,
92 ChannelType::get(ctxt, AnyType::get(ctxt))},
93 BundledChannel{StringAttr::get(ctxt, "result"),
94 ChannelDirection::from,
95 ChannelType::get(ctxt, AnyType::get(ctxt))}},
96 /*resettable=*/UnitAttr())});
97}
98
99void MMIOServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
100 auto *ctxt = getContext();
101 // Read only port.
102 ports.push_back(ServicePortInfo{
103 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "read")),
104 ChannelBundleType::get(
105 ctxt,
107 StringAttr::get(ctxt, "offset"), ChannelDirection::to,
108 ChannelType::get(
109 ctxt,
110 IntegerType::get(
111 ctxt, 32, IntegerType::SignednessSemantics::Unsigned))},
112 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
113 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
114 /*resettable=*/UnitAttr())});
115 // Read-write port.
116 auto cmdType = hw::StructType::get(
117 ctxt, {
118 hw::StructType::FieldInfo{StringAttr::get(ctxt, "write"),
119 IntegerType::get(ctxt, 1)},
120 hw::StructType::FieldInfo{
121 StringAttr::get(ctxt, "offset"),
122 IntegerType::get(
123 ctxt, 32, IntegerType::SignednessSemantics::Unsigned)},
124 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
125 IntegerType::get(ctxt, 64)},
126 });
127 ports.push_back(ServicePortInfo{
128 hw::InnerRefAttr::get(getSymNameAttr(),
129 StringAttr::get(ctxt, "read_write")),
130 ChannelBundleType::get(
131 ctxt,
132 {BundledChannel{StringAttr::get(ctxt, "cmd"), ChannelDirection::to,
133 ChannelType::get(ctxt, cmdType)},
134 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
135 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
136 /*resettable=*/UnitAttr())});
137}
138
139ServicePortInfo HostMemServiceDeclOp::writePortInfo() {
140 auto *ctxt = getContext();
141 auto addressType =
142 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
143
144 // Write port
145 hw::StructType writeType = hw::StructType::get(
146 ctxt,
147 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
148 hw::StructType::FieldInfo{
149 StringAttr::get(ctxt, "tag"),
150 IntegerType::get(ctxt, 8,
151 IntegerType::SignednessSemantics::Unsigned)},
152 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
153 AnyType::get(ctxt)}});
154 return createReqResp(
155 getSymNameAttr(), "write", "req", writeType, "ackTag",
156 IntegerType::get(ctxt, 8, IntegerType::SignednessSemantics::Unsigned));
157}
158
159ServicePortInfo HostMemServiceDeclOp::readPortInfo() {
160 auto *ctxt = getContext();
161 auto addressType =
162 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
163
164 hw::StructType readReqType = hw::StructType::get(
165 ctxt, {
166 hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"),
167 addressType},
168 hw::StructType::FieldInfo{
169 StringAttr::get(ctxt, "tag"),
170 IntegerType::get(
171 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
172 });
173 hw::StructType readRespType = hw::StructType::get(
174 ctxt, {
175 hw::StructType::FieldInfo{
176 StringAttr::get(ctxt, "tag"),
177 IntegerType::get(
178 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
179 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
180 AnyType::get(ctxt)},
181 });
182 return createReqResp(getSymNameAttr(), "read", "req", readReqType, "resp",
183 readRespType);
184}
185
186void HostMemServiceDeclOp::getPortList(
187 SmallVectorImpl<ServicePortInfo> &ports) {
188 ports.push_back(writePortInfo());
189 ports.push_back(readPortInfo());
190}
191
192void TelemetryServiceDeclOp::getPortList(
193 SmallVectorImpl<ServicePortInfo> &ports) {
194 auto *ctxt = getContext();
195 ports.push_back(ServicePortInfo{
196 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "report")),
197 ChannelBundleType::get(
198 ctxt,
199 {BundledChannel{StringAttr::get(ctxt, "get"), ChannelDirection::to,
200 ChannelType::get(ctxt, IntegerType::get(ctxt, 1))},
201 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
202 ChannelType::get(ctxt, AnyType::get(ctxt))}},
203 /*resettable=*/UnitAttr())});
204}
assert(baseType &&"element must be base type")
static ServicePortInfo createReqResp(StringAttr sym, Twine name, StringRef reqName, Type reqType, StringRef respName, Type respType)
Utility function to create a req/resp pair bundle service port.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Describes a service port.
Definition ESIOps.h:31