Skip to content

Commit

Permalink
feat!: rollup rework
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Jan 10, 2024
1 parent e8cafb4 commit 9f3c65d
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 275 deletions.
2 changes: 1 addition & 1 deletion lib/grpc-interfaces
3 changes: 0 additions & 3 deletions src/cartesi-machine-tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,6 @@ local function build_machine(test_name)
rollup = {
rx_buffer = { start = 0x60000000, length = 2 << 20 },
tx_buffer = { start = 0x60200000, length = 2 << 20 },
input_metadata = { start = 0x60400000, length = 4096 },
voucher_hashes = { start = 0x60600000, length = 2 << 20 },
notice_hashes = { start = 0x60800000, length = 2 << 20 },
},
flash_drive = { {
start = 0x80000000000000,
Expand Down
157 changes: 52 additions & 105 deletions src/cartesi-machine.lua

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/clua-htif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ int clua_htif_export(lua_State *L, int ctxidx) {
named_constant{HTIF_YIELD_REASON_TX_NOTICE, "HTIF_YIELD_REASON_TX_NOTICE"},
named_constant{HTIF_YIELD_REASON_TX_REPORT, "HTIF_YIELD_REASON_TX_REPORT"},
named_constant{HTIF_YIELD_REASON_TX_EXCEPTION, "HTIF_YIELD_REASON_TX_EXCEPTION"},
named_constant{HTIF_YIELD_REASON_ADVANCE_STATE, "HTIF_YIELD_REASON_ADVANCE_STATE"},
named_constant{HTIF_YIELD_REASON_INSPECT_STATE, "HTIF_YIELD_REASON_INSPECT_STATE"},
named_constant{HTIF_CONSOLE_GETCHAR, "HTIF_CONSOLE_GETCHAR"},
named_constant{HTIF_CONSOLE_PUTCHAR, "HTIF_CONSOLE_PUTCHAR"},
};
Expand Down
15 changes: 0 additions & 15 deletions src/clua-machine-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,6 @@ static void push_cm_rollup_config(lua_State *L, const cm_rollup_config *r) {
lua_setfield(L, -2, "rx_buffer"); // rollup
push_cm_memory_range_config(L, &r->tx_buffer); // rollup tx_buffer
lua_setfield(L, -2, "tx_buffer"); // rollup
push_cm_memory_range_config(L, &r->input_metadata); // rollup input_metadata
lua_setfield(L, -2, "input_metadata"); // rollup
push_cm_memory_range_config(L, &r->voucher_hashes); // rollup voucher_hashes
lua_setfield(L, -2, "voucher_hashes"); // rollup
push_cm_memory_range_config(L, &r->notice_hashes); // rollup notice_hashes
lua_setfield(L, -2, "notice_hashes"); // rollup
}

/// \brief Pushes cm_flash_drive_configs to the Lua stack
Expand Down Expand Up @@ -1032,15 +1026,6 @@ static void check_cm_rollup_config(lua_State *L, int tabidx, cm_rollup_config *r
lua_pop(L, 1);
lua_getfield(L, -1, "tx_buffer");
clua_check_cm_memory_range_config(L, -1, "rollup rx buffer", &r->tx_buffer);
lua_pop(L, 1);
lua_getfield(L, -1, "input_metadata");
clua_check_cm_memory_range_config(L, -1, "rollup input metadata", &r->input_metadata);
lua_pop(L, 1);
lua_getfield(L, -1, "voucher_hashes");
clua_check_cm_memory_range_config(L, -1, "rollup voucher hashes", &r->voucher_hashes);
lua_pop(L, 1);
lua_getfield(L, -1, "notice_hashes");
clua_check_cm_memory_range_config(L, -1, "rollup notice hashes", &r->notice_hashes);
lua_pop(L, 2);
}

Expand Down
19 changes: 2 additions & 17 deletions src/dtb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le
// rollup
if (c.rollup.has_value()) {
const auto &r = c.rollup.value();
fdt.begin_node("rollup");
fdt.begin_node("cmio");
fdt.prop_u32("#address-cells", 2);
fdt.prop_u32("#size-cells", 2);
fdt.prop_string("compatible", "ctsi-rollup");
fdt.prop_string("compatible", "ctsi-cmio");
{ // rx_buffer
fdt.begin_node_num("rx_buffer", r.rx_buffer.start);
fdt.prop_u64_list<2>("reg", {r.rx_buffer.start, r.rx_buffer.length});
Expand All @@ -179,21 +179,6 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le
fdt.prop_u64_list<2>("reg", {r.tx_buffer.start, r.tx_buffer.length});
fdt.end_node();
}
{ // input_metadata
fdt.begin_node_num("input_metadata", r.input_metadata.start);
fdt.prop_u64_list<2>("reg", {r.input_metadata.start, r.input_metadata.length});
fdt.end_node();
}
{ // voucher_hashes
fdt.begin_node_num("voucher_hashes", r.voucher_hashes.start);
fdt.prop_u64_list<2>("reg", {r.voucher_hashes.start, r.voucher_hashes.length});
fdt.end_node();
}
{ // notice_hashes
fdt.begin_node_num("notice_hashes", r.notice_hashes.start);
fdt.prop_u64_list<2>("reg", {r.notice_hashes.start, r.notice_hashes.length});
fdt.end_node();
}
fdt.end_node();
}

Expand Down
2 changes: 2 additions & 0 deletions src/htif-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
#define HTIF_YIELD_REASON_TX_NOTICE_DEF 4
#define HTIF_YIELD_REASON_TX_REPORT_DEF 5
#define HTIF_YIELD_REASON_TX_EXCEPTION_DEF 6
#define HTIF_YIELD_REASON_ADVANCE_STATE_DEF 0
#define HTIF_YIELD_REASON_INSPECT_STATE_DEF 1

#endif /* end of include guard: HTIF_DEFINES_H */
2 changes: 2 additions & 0 deletions src/htif.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ enum HTIF_yield_reason : uint64_t {
HTIF_YIELD_REASON_TX_NOTICE = HTIF_YIELD_REASON_TX_NOTICE_DEF,
HTIF_YIELD_REASON_TX_REPORT = HTIF_YIELD_REASON_TX_REPORT_DEF,
HTIF_YIELD_REASON_TX_EXCEPTION = HTIF_YIELD_REASON_TX_EXCEPTION_DEF,
HTIF_YIELD_REASON_ADVANCE_STATE = HTIF_YIELD_REASON_ADVANCE_STATE_DEF,
HTIF_YIELD_REASON_INSPECT_STATE = HTIF_YIELD_REASON_INSPECT_STATE_DEF,
};
/// \brief Mapping between CSRs and their relative addresses in HTIF memory
enum class htif_csr {
Expand Down
9 changes: 0 additions & 9 deletions src/json-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,6 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, rollup_config &valu
const auto new_path = path + to_string(key) + "/";
ju_get_field(jconfig, "rx_buffer"s, value.rx_buffer, new_path);
ju_get_field(jconfig, "tx_buffer"s, value.tx_buffer, new_path);
ju_get_field(jconfig, "input_metadata"s, value.input_metadata, new_path);
ju_get_field(jconfig, "voucher_hashes"s, value.voucher_hashes, new_path);
ju_get_field(jconfig, "notice_hashes"s, value.notice_hashes, new_path);
}

template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key, rollup_config &value,
Expand All @@ -1002,9 +999,6 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, std::optional<rollu
auto &value = optional.value();
ju_get_field(jconfig, "rx_buffer"s, value.rx_buffer, new_path);
ju_get_field(jconfig, "tx_buffer"s, value.tx_buffer, new_path);
ju_get_field(jconfig, "input_metadata"s, value.input_metadata, new_path);
ju_get_field(jconfig, "voucher_hashes"s, value.voucher_hashes, new_path);
ju_get_field(jconfig, "notice_hashes"s, value.notice_hashes, new_path);
}

template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key,
Expand Down Expand Up @@ -1272,9 +1266,6 @@ void to_json(nlohmann::json &j, const rollup_config &config) {
j = nlohmann::json{
{"rx_buffer", config.rx_buffer},
{"tx_buffer", config.tx_buffer},
{"input_metadata", config.input_metadata},
{"voucher_hashes", config.voucher_hashes},
{"notice_hashes", config.notice_hashes},
};
}

Expand Down
9 changes: 0 additions & 9 deletions src/jsonrpc-discover.json
Original file line number Diff line number Diff line change
Expand Up @@ -1705,15 +1705,6 @@
},
"tx_buffer": {
"$ref": "#/components/schemas/MemoryRangeConfig"
},
"input_metadata": {
"$ref": "#/components/schemas/MemoryRangeConfig"
},
"voucher_hashes": {
"$ref": "#/components/schemas/MemoryRangeConfig"
},
"notice_hashes": {
"$ref": "#/components/schemas/MemoryRangeConfig"
}
}
},
Expand Down
13 changes: 4 additions & 9 deletions src/machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ static std::optional<cartesi::rollup_config> convert_from_c(const cm_rollup_conf
if (!c_config->has_value) {
return {};
}
cartesi::rollup_config new_cpp_rollup_config{convert_from_c(&c_config->rx_buffer),
convert_from_c(&c_config->tx_buffer), convert_from_c(&c_config->input_metadata),
convert_from_c(&c_config->voucher_hashes), convert_from_c(&c_config->notice_hashes)};
cartesi::rollup_config new_cpp_rollup_config{
convert_from_c(&c_config->rx_buffer),
convert_from_c(&c_config->tx_buffer)
};
return new_cpp_rollup_config;
}

Expand All @@ -297,9 +298,6 @@ static cm_rollup_config convert_to_c(const std::optional<cartesi::rollup_config>
}
new_c_rollup_config.rx_buffer = convert_to_c(cpp_config->rx_buffer);
new_c_rollup_config.tx_buffer = convert_to_c(cpp_config->tx_buffer);
new_c_rollup_config.input_metadata = convert_to_c(cpp_config->input_metadata);
new_c_rollup_config.voucher_hashes = convert_to_c(cpp_config->voucher_hashes);
new_c_rollup_config.notice_hashes = convert_to_c(cpp_config->notice_hashes);
return new_c_rollup_config;
}

Expand Down Expand Up @@ -753,9 +751,6 @@ void cm_delete_machine_config(const cm_machine_config *config) {
delete[] config->tlb.image_filename;
delete[] config->rollup.rx_buffer.image_filename;
delete[] config->rollup.tx_buffer.image_filename;
delete[] config->rollup.input_metadata.image_filename;
delete[] config->rollup.voucher_hashes.image_filename;
delete[] config->rollup.notice_hashes.image_filename;
delete[] config->uarch.ram.image_filename;

delete config;
Expand Down
3 changes: 0 additions & 3 deletions src/machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ typedef struct { // NOLINT(modernize-use-using)
bool has_value; ///< Represents whether the rest of the struct have been filled
cm_memory_range_config rx_buffer; ///< RX buffer memory range
cm_memory_range_config tx_buffer; ///< TX buffer memory range
cm_memory_range_config input_metadata; ///< Input metadata memory range
cm_memory_range_config voucher_hashes; ///< Voucher hashes memory range
cm_memory_range_config notice_hashes; ///< Notice hashes memory range
} cm_rollup_config;

/// \brief microarchitecture RAM configuration
Expand Down
3 changes: 0 additions & 3 deletions src/machine-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ static void adjust_image_filenames(machine_config &c, const std::string &dir) {
auto &r = c.rollup.value();
r.rx_buffer.image_filename = c.get_image_filename(dir, r.rx_buffer);
r.tx_buffer.image_filename = c.get_image_filename(dir, r.tx_buffer);
r.input_metadata.image_filename = c.get_image_filename(dir, r.input_metadata);
r.voucher_hashes.image_filename = c.get_image_filename(dir, r.voucher_hashes);
r.notice_hashes.image_filename = c.get_image_filename(dir, r.notice_hashes);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/machine-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ struct htif_config final {
struct rollup_config { // NOLINT(bugprone-exception-escape)
memory_range_config rx_buffer{0x60000000, 2 << 20}; ///< RX buffer
memory_range_config tx_buffer{0x60200000, 2 << 20}; ///< TX buffer
memory_range_config input_metadata{0x60400000, 4096}; ///< Buffer for input metadata
memory_range_config voucher_hashes{0x60600000, 2 << 20}; ///< Buffer for the voucher hash array
memory_range_config notice_hashes{0x60800000, 2 << 20}; ///< Buffer for the notice hash array
};

/// \brief Machine state configuration
Expand Down
61 changes: 1 addition & 60 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ const pma_entry::flags machine::m_rollup_tx_buffer_flags{
PMA_ISTART_DID::rollup_tx_buffer // DID
};

const pma_entry::flags machine::m_rollup_input_metadata_flags{
true, // R
false, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_input_metadata // DID
};

const pma_entry::flags machine::m_rollup_voucher_hashes_flags{
true, // R
true, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_voucher_hashes // DID
};

const pma_entry::flags machine::m_rollup_notice_hashes_flags{
true, // R
true, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_notice_hashes // DID
};

pma_entry machine::make_memory_range_pma_entry(const std::string &description, const memory_range_config &c) {
if (c.image_filename.empty()) {
return make_callocd_memory_pma_entry(description, c.start, c.length);
Expand All @@ -147,20 +120,6 @@ pma_entry machine::make_rollup_tx_buffer_pma_entry(const memory_range_config &c)
return make_memory_range_pma_entry("rollup tx buffer memory range"s, c).set_flags(m_rollup_tx_buffer_flags);
}

pma_entry machine::make_rollup_input_metadata_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup input metadata memory range"s, c)
.set_flags(m_rollup_input_metadata_flags);
}

pma_entry machine::make_rollup_voucher_hashes_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup voucher hashes memory range"s, c)
.set_flags(m_rollup_voucher_hashes_flags);
}

pma_entry machine::make_rollup_notice_hashes_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup notice hashes memory range"s, c).set_flags(m_rollup_notice_hashes_flags);
}

pma_entry &machine::register_pma_entry(pma_entry &&pma) {
if (m_s.pmas.capacity() <= m_s.pmas.size()) { // NOLINT(readability-static-accessed-through-instance)
throw std::runtime_error{"too many PMAs when adding "s + pma.get_description()};
Expand Down Expand Up @@ -206,12 +165,6 @@ static bool DID_is_protected(PMA_ISTART_DID DID) {
return false;
case PMA_ISTART_DID::rollup_tx_buffer:
return false;
case PMA_ISTART_DID::rollup_input_metadata:
return false;
case PMA_ISTART_DID::rollup_voucher_hashes:
return false;
case PMA_ISTART_DID::rollup_notice_hashes:
return false;
default:
return true;
}
Expand Down Expand Up @@ -388,17 +341,11 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) :
throw std::invalid_argument{"rollup device requires automatic and manual yield"};
}
if (m_c.rollup->rx_buffer.length == 0 || m_c.rollup->rx_buffer.start == 0 ||
m_c.rollup->tx_buffer.length == 0 || m_c.rollup->tx_buffer.start == 0 ||
m_c.rollup->input_metadata.length == 0 || m_c.rollup->input_metadata.start == 0 ||
m_c.rollup->voucher_hashes.length == 0 || m_c.rollup->voucher_hashes.start == 0 ||
m_c.rollup->notice_hashes.length == 0 || m_c.rollup->notice_hashes.start == 0) {
m_c.rollup->tx_buffer.length == 0 || m_c.rollup->tx_buffer.start == 0) {
throw std::invalid_argument{"incomplete rollup configuration"};
}
register_pma_entry(make_rollup_tx_buffer_pma_entry(m_c.rollup->tx_buffer));
register_pma_entry(make_rollup_rx_buffer_pma_entry(m_c.rollup->rx_buffer));
register_pma_entry(make_rollup_input_metadata_pma_entry(m_c.rollup->input_metadata));
register_pma_entry(make_rollup_voucher_hashes_pma_entry(m_c.rollup->voucher_hashes));
register_pma_entry(make_rollup_notice_hashes_pma_entry(m_c.rollup->notice_hashes));
}

// Register HTIF device
Expand Down Expand Up @@ -577,9 +524,6 @@ machine_config machine::get_serialization_config(void) const {
auto &r = c.rollup.value();
r.rx_buffer.image_filename.clear();
r.tx_buffer.image_filename.clear();
r.input_metadata.image_filename.clear();
r.voucher_hashes.image_filename.clear();
r.notice_hashes.image_filename.clear();
}
c.uarch.processor.cycle = read_uarch_cycle();
c.uarch.processor.halt_flag = read_uarch_halt_flag();
Expand Down Expand Up @@ -684,9 +628,6 @@ void machine::store_pmas(const machine_config &c, const std::string &dir) const
const auto &r = c.rollup.value();
store_memory_pma(find_pma_entry<uint64_t>(r.rx_buffer.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.tx_buffer.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.input_metadata.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.voucher_hashes.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.notice_hashes.start), dir);
}
if (!m_uarch.get_state().ram.get_istart_E()) {
store_memory_pma(m_uarch.get_state().ram, dir);
Expand Down
3 changes: 0 additions & 3 deletions src/pma-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ enum class PMA_ISTART_DID {
HTIF = PMA_HTIF_DID_DEF, ///< DID for HTIF device
rollup_rx_buffer = PMA_ROLLUP_RX_BUFFER_DID_DEF, ///< DID for rollup receive buffer
rollup_tx_buffer = PMA_ROLLUP_TX_BUFFER_DID_DEF, ///< DID for rollup transmit buffer
rollup_input_metadata = PMA_ROLLUP_INPUT_METADATA_DID_DEF, ///< DID for rollup input metadata memory range
rollup_voucher_hashes = PMA_ROLLUP_VOUCHER_HASHES_DID_DEF, ///< DID for rollup voucher hashes memory range
rollup_notice_hashes = PMA_ROLLUP_NOTICE_HASHES_DID_DEF, ///< DID for rollup notice hashes memory range
shadow_uarch = PMA_SHADOW_UARCH_STATE_DID_DEF, ///< DID for shadow uarch state device
};

Expand Down
12 changes: 0 additions & 12 deletions src/protobuf-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ void set_proto_memory_range(const memory_range_config &m, CartesiMachine::Memory
void set_proto_rollup(const rollup_config &r, CartesiMachine::RollupConfig *proto_r) {
set_proto_memory_range(r.rx_buffer, proto_r->mutable_rx_buffer());
set_proto_memory_range(r.tx_buffer, proto_r->mutable_tx_buffer());
set_proto_memory_range(r.input_metadata, proto_r->mutable_input_metadata());
set_proto_memory_range(r.voucher_hashes, proto_r->mutable_voucher_hashes());
set_proto_memory_range(r.notice_hashes, proto_r->mutable_notice_hashes());
}

void set_proto_machine_config(const machine_config &c, CartesiMachine::MachineConfig *proto_c) {
Expand Down Expand Up @@ -840,15 +837,6 @@ rollup_config get_proto_rollup_config(const CartesiMachine::RollupConfig &proto_
if (proto_r.has_tx_buffer()) {
r.tx_buffer = get_proto_memory_range_config(proto_r.tx_buffer());
}
if (proto_r.has_input_metadata()) {
r.input_metadata = get_proto_memory_range_config(proto_r.input_metadata());
}
if (proto_r.has_voucher_hashes()) {
r.voucher_hashes = get_proto_memory_range_config(proto_r.voucher_hashes());
}
if (proto_r.has_input_metadata()) {
r.notice_hashes = get_proto_memory_range_config(proto_r.notice_hashes());
}
return r;
}

Expand Down
Loading

0 comments on commit 9f3c65d

Please sign in to comment.