-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ESI][Runtime] MMIO service support (#6034)
Service C++ interface, Python wrapping, and cosim support for MMIO. Also adds the basic service framework.
- Loading branch information
Showing
14 changed files
with
342 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// REQUIRES: esi-cosim, esi-runtime | ||
// RUN: esi-cosim-runner.py --exec %s.py %s | ||
|
||
// Test the low level cosim MMIO functionality. This test has 1024 64-bit | ||
// registers as a memory. It is an error to write to register 0. | ||
|
||
import Cosim_DpiPkg::*; | ||
|
||
module top( | ||
input logic clk, | ||
input logic rst | ||
); | ||
|
||
// MMIO read: address channel. | ||
logic arvalid; | ||
logic arready; | ||
logic [31:0] araddr; | ||
|
||
// MMIO read: data response channel. | ||
reg rvalid; | ||
logic rready; | ||
reg [31:0] rdata; | ||
reg [1:0] rresp; | ||
|
||
// MMIO write: address channel. | ||
logic awvalid; | ||
reg awready; | ||
logic [31:0] awaddr; | ||
|
||
// MMIO write: data channel. | ||
logic wvalid; | ||
reg wready; | ||
logic [31:0] wdata; | ||
|
||
// MMIO write: write response channel. | ||
reg bvalid; | ||
logic bready; | ||
reg [1:0] bresp; | ||
|
||
Cosim_MMIO mmio ( | ||
.clk(clk), | ||
.rst(rst), | ||
.arvalid(arvalid), | ||
.arready(arready), | ||
.araddr(araddr), | ||
.rvalid(rvalid), | ||
.rready(rready), | ||
.rdata(rdata), | ||
.rresp(rresp), | ||
.awvalid(awvalid), | ||
.awready(awready), | ||
.awaddr(awaddr), | ||
.wvalid(wvalid), | ||
.wready(wready), | ||
.wdata(wdata), | ||
.bvalid(bvalid), | ||
.bready(bready), | ||
.bresp(bresp) | ||
); | ||
|
||
reg [31:0] regs [1023:0]; | ||
|
||
assign arready = 1; | ||
assign rdata = regs[araddr >> 3]; | ||
assign rresp = araddr == 0 ? 3 : 0; | ||
always@(posedge clk) begin | ||
if (rst) begin | ||
rvalid <= 0; | ||
end else begin | ||
if (arvalid) | ||
rvalid <= 1; | ||
if (rready && rvalid) | ||
rvalid <= 0; | ||
end | ||
end | ||
|
||
wire write = awvalid && wvalid && !bvalid; | ||
assign awready = write; | ||
assign wready = write; | ||
always@(posedge clk) begin | ||
if (rst) begin | ||
bvalid <= 0; | ||
end else begin | ||
if (bvalid && bready) | ||
bvalid <= 0; | ||
if (write) begin | ||
bvalid <= 1; | ||
bresp <= awaddr == 0 ? 3 : 0; | ||
regs[awaddr >> 3] <= wdata; | ||
end | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import esiaccel | ||
import os | ||
import sys | ||
|
||
conn = f"{sys.argv[1]}:{sys.argv[2]}" | ||
|
||
acc = esiaccel.Accelerator.connect("cosim", conn) | ||
mmio = acc.get_service_mmio() | ||
|
||
r = mmio.read(40) | ||
print(f"data resp: 0x{r:x}") | ||
|
||
try: | ||
mmio.read(0) | ||
assert False, "above should have thrown exception" | ||
except Exception: | ||
print("caught expected exception") | ||
|
||
mmio.write(32, 86) | ||
r = mmio.read(32) | ||
print(f"data resp: 0x{r:x}") | ||
assert r == 86 | ||
|
||
try: | ||
mmio.write(0, 44) | ||
assert False, "above should have thrown exception" | ||
except Exception: | ||
print("caught expected exception") | ||
|
||
# Crashes with "magic num not found", which is expected since this isn't | ||
# supported yet. | ||
# acc.sysinfo().esi_version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Don't treat the Python files in this directory as tests. | ||
config.suffixes.remove('.py') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===- StdServices.h - ESI standard services C++ API ------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The APIs in this backend are all optionally implemented. The lower level | ||
// ones, however, are strongly recommended. 'Services' here refers to ESI | ||
// services. These are standard APIs into the standard ESI services. | ||
// | ||
// DO NOT EDIT! | ||
// This file is distributed as part of an ESI package. The source for this file | ||
// should always be modified within CIRCT. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// NOLINTNEXTLINE(llvm-header-guard) | ||
#ifndef ESI_RUNTIME_STDSERVICES_H | ||
#define ESI_RUNTIME_STDSERVICES_H | ||
|
||
#include "esi/Accelerator.h" | ||
|
||
#include <cstdint> | ||
|
||
namespace esi { | ||
namespace services { | ||
|
||
/// Information about the Accelerator system. | ||
class SysInfo : public Service { | ||
public: | ||
virtual ~SysInfo() = default; | ||
|
||
/// Get the ESI version number to check version compatibility. | ||
virtual uint32_t esiVersion() const = 0; | ||
|
||
/// Return the JSON-formatted system manifest. | ||
virtual std::string rawJsonManifest() const = 0; | ||
}; | ||
|
||
class MMIO : public Service { | ||
public: | ||
virtual ~MMIO() = default; | ||
virtual uint64_t read(uint32_t addr) const = 0; | ||
virtual void write(uint32_t addr, uint64_t data) = 0; | ||
}; | ||
|
||
/// Implement the SysInfo API for a standard MMIO protocol. | ||
class MMIOSysInfo final : public SysInfo { | ||
public: | ||
MMIOSysInfo(const MMIO *); | ||
|
||
/// Get the ESI version number to check version compatibility. | ||
uint32_t esiVersion() const override; | ||
|
||
/// Return the JSON-formatted system manifest. | ||
std::string rawJsonManifest() const override; | ||
|
||
private: | ||
const MMIO *mmio; | ||
}; | ||
|
||
} // namespace services | ||
} // namespace esi | ||
|
||
#endif // ESI_RUNTIME_STDSERVICES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===- StdServices.cpp - implementations of std services ------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// DO NOT EDIT! | ||
// This file is distributed as part of an ESI package. The source for this file | ||
// should always be modified within CIRCT | ||
// (lib/dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp). | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "esi/StdServices.h" | ||
|
||
#include <stdexcept> | ||
|
||
using namespace esi; | ||
using namespace esi::services; | ||
|
||
MMIOSysInfo::MMIOSysInfo(const MMIO *mmio) : mmio(mmio) {} | ||
|
||
uint32_t MMIOSysInfo::esiVersion() const { | ||
uint32_t hi = mmio->read(MagicNumOffset); | ||
uint32_t lo = mmio->read(MagicNumOffset + 4); | ||
if (hi != MagicNumberHi || lo != MagicNumberLo) | ||
throw std::runtime_error("ESI magic number not found"); | ||
return mmio->read(VersionNumberOffset); | ||
} | ||
|
||
std::string MMIOSysInfo::rawJsonManifest() const { return ""; } |
Oops, something went wrong.