Skip to content

Commit

Permalink
device_t: Add device_factory_t
Browse files Browse the repository at this point in the history
This class should implement conditional fdt-based device instantiation,
as well as adding device nodes to the dts
  • Loading branch information
jerryz123 committed Jun 20, 2023
1 parent b2ab751 commit 0beed2c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions riscv/abstract_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "common.h"
#include <cstdint>
#include <cstddef>
#include <string>

class sim_t;

class abstract_device_t {
public:
Expand All @@ -14,4 +17,20 @@ class abstract_device_t {
virtual void tick(reg_t UNUSED rtc_ticks) {}
};

// factory for devices which should show up in the DTS, and can be
// parameterized by parsing the DTS
class device_factory_t {
public:
virtual abstract_device_t* parse_from_fdt(const void* fdt, const sim_t* sim, reg_t* base) = 0;
virtual std::string generate_dts(const sim_t* sim) = 0;
virtual ~device_factory_t() {}
};

#define REGISTER_DEVICE(name, parse, generate) \
class name##_factory_t : public device_factory_t { \
public: \
name##_t* parse_from_fdt(const void* fdt, const sim_t* sim, reg_t* base) override { return parse(fdt, sim, base); } \
std::string generate_dts(const sim_t* sim) override { return generate(sim); } \
}; device_factory_t *name##_factory = new name##_factory_t();

#endif

0 comments on commit 0beed2c

Please sign in to comment.