Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added trace encoder controller #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/trace_encoder_ctrl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "trace_encoder_ctrl.h"

trace_encoder_ctrl_t::trace_encoder_ctrl_t(trace_encoder_l* encoder) {
this->encoder = encoder;
}

bool trace_encoder_ctrl_t::load(reg_t addr, size_t len, uint8_t* bytes) {
switch (addr) {
case TR_TE_CTRL:
bytes[0] = this->encoder->get_enable() << 1;
return true;
default:
return false;
}
}

bool trace_encoder_ctrl_t::store(reg_t addr, size_t len, const uint8_t* bytes) {
printf("[TRACE_ENCODER_CTRL]: Storing %d bytes with value %lx to 0x%lx\n", len, bytes[0], addr);
switch (addr) {
case TR_TE_CTRL:
printf("[TRACE_ENCODER_CTRL]: Setting enable to %d\n", (bytes[0] >> 1) & 0x1);
this->encoder->set_enable((bytes[0] >> 1) & 0x1); // Set enable to the second bit
return true;
default:
return false;
}
}

int trace_encoder_ctrl_parseFDT(const void *fdt, reg_t *address,
const char *compatible) {
int nodeoffset, len, rc;
const fdt32_t *reg_p;

nodeoffset = fdt_node_offset_by_compatible(fdt, -1, compatible);
if (nodeoffset < 0)
return nodeoffset;

rc = fdt_get_node_addr_size(fdt, nodeoffset, address, NULL, "reg");
if (rc < 0 || !address)
return -ENODEV;

return 0;
}

// This function parses an instance of this device from the FDT
// An FDT node for a device should encode, at minimum, the base address for the device
trace_encoder_ctrl_t* trace_encoder_ctrl_parseFromFDT(const void* fdt, const sim_t* sim, reg_t* base, std::vector<std::string> sargs) {
if (trace_encoder_ctrl_parseFDT(fdt, base, "ucbbar,trace_encoder_ctrl") == 0) {
printf("Found trace_encoder_ctrl at 0x%lx\n", *base);
return new trace_encoder_ctrl_t(&(const_cast<sim_t*>(sim)->get_core(0)->trace_encoder));
} else {
return nullptr;
}
}

std::string trace_encoder_ctrl_generateDTS(const sim_t* sim, const std::vector<std::string>& args) {
std::stringstream s;
s << std::hex
<< " trace_encoder_ctrl: trace_encoder_ctrl@" << TRACE_ENCODER_CTRL_BASE << " {\n"
" compatible = \"ucbbar,trace_encoder_ctrl\";\n"
" interrupt-parent = <&PLIC>;\n"
" interrupts = <" << std::dec << 2;
reg_t blkdevbs = TRACE_ENCODER_CTRL_BASE;
reg_t blkdevsz = TRACE_ENCODER_CTRL_SIZE;
s << std::hex << ">;\n"
" reg = <0x" << (blkdevbs >> 32) << " 0x" << (blkdevbs & (uint32_t)-1) <<
" 0x" << (blkdevsz >> 32) << " 0x" << (blkdevsz & (uint32_t)-1) << ">;\n"
" };\n";
return s.str();
}

REGISTER_DEVICE(trace_encoder_ctrl, trace_encoder_ctrl_parseFromFDT, trace_encoder_ctrl_generateDTS);
25 changes: 25 additions & 0 deletions src/trace_encoder_ctrl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _TRACE_ENCODER_CTRL_H
#define _TRACE_ENCODER_CTRL_H

#include <riscv/abstract_device.h>
#include <riscv/trace_encoder_l.h>
#include <riscv/dts.h>
#include <riscv/sim.h>
#include <fdt/libfdt.h>

#define TRACE_ENCODER_CTRL_BASE 0x3000000
#define TRACE_ENCODER_CTRL_SIZE 0x1000

#define TR_TE_CTRL 0x000
#define TR_TE_IMPL 0x004

class trace_encoder_ctrl_t : public abstract_device_t {
public:
trace_encoder_ctrl_t(trace_encoder_l* encoder);
bool load(reg_t addr, size_t len, uint8_t* bytes) override;
bool store(reg_t addr, size_t len, const uint8_t* bytes) override;
private:
trace_encoder_l* encoder;
};

#endif