Skip to content

Commit

Permalink
Merge pull request #50 from sifive/htif
Browse files Browse the repository at this point in the history
Add support for HTIF
  • Loading branch information
nategraff-sifive committed Oct 7, 2019
2 parents e41e646 + f351ce8 commit 790c47d
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ freedom_metal_header_generator_SOURCES = \
metal_header/stdout_path.c++ \
metal_header/stdout_path.h \
metal_header/template_device.c++ \
metal_header/template_device.h
metal_header/template_device.h \
metal_header/ucb_htif0.c++ \
metal_header/ucb_htif0.h

freedom_bare_header_generator_CPPFLAGS = -I$(srcdir) -I$(srcdir)/bare_header

Expand Down Expand Up @@ -187,6 +189,7 @@ freedom_bare_header_generator_SOURCES = \
bare_header/sifive_trace.h \
bare_header/sifive_uart0.h \
bare_header/sifive_wdog0.h \
bare_header/ucb_htif0.h \
ranges.c++ \
ranges.h

Expand Down
26 changes: 24 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ am_freedom_metal_header_generator_OBJECTS = \
metal_header/freedom_metal_header_generator-sifive_uart0.$(OBJEXT) \
metal_header/freedom_metal_header_generator-sifive_wdog0.$(OBJEXT) \
metal_header/freedom_metal_header_generator-stdout_path.$(OBJEXT) \
metal_header/freedom_metal_header_generator-template_device.$(OBJEXT)
metal_header/freedom_metal_header_generator-template_device.$(OBJEXT) \
metal_header/freedom_metal_header_generator-ucb_htif0.$(OBJEXT)
freedom_metal_header_generator_OBJECTS = \
$(am_freedom_metal_header_generator_OBJECTS)
freedom_metal_header_generator_LDADD = $(LDADD)
Expand Down Expand Up @@ -745,7 +746,9 @@ freedom_metal_header_generator_SOURCES = \
metal_header/stdout_path.c++ \
metal_header/stdout_path.h \
metal_header/template_device.c++ \
metal_header/template_device.h
metal_header/template_device.h \
metal_header/ucb_htif0.c++ \
metal_header/ucb_htif0.h

freedom_bare_header_generator_CPPFLAGS = -I$(srcdir) -I$(srcdir)/bare_header
freedom_bare_header_generator_SOURCES = \
Expand Down Expand Up @@ -781,6 +784,7 @@ freedom_bare_header_generator_SOURCES = \
bare_header/sifive_trace.h \
bare_header/sifive_uart0.h \
bare_header/sifive_wdog0.h \
bare_header/ucb_htif0.h \
ranges.c++ \
ranges.h

Expand Down Expand Up @@ -1147,6 +1151,9 @@ metal_header/freedom_metal_header_generator-stdout_path.$(OBJEXT): \
metal_header/freedom_metal_header_generator-template_device.$(OBJEXT): \
metal_header/$(am__dirstamp) \
metal_header/$(DEPDIR)/$(am__dirstamp)
metal_header/freedom_metal_header_generator-ucb_htif0.$(OBJEXT): \
metal_header/$(am__dirstamp) \
metal_header/$(DEPDIR)/$(am__dirstamp)

freedom-metal_header-generator$(EXEEXT): $(freedom_metal_header_generator_OBJECTS) $(freedom_metal_header_generator_DEPENDENCIES) $(EXTRA_freedom_metal_header_generator_DEPENDENCIES)
@rm -f freedom-metal_header-generator$(EXEEXT)
Expand Down Expand Up @@ -1244,6 +1251,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@metal_header/$(DEPDIR)/freedom_metal_header_generator-sifive_wdog0.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@metal_header/$(DEPDIR)/freedom_metal_header_generator-stdout_path.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@metal_header/$(DEPDIR)/freedom_metal_header_generator-template_device.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Po@am__quote@

.c++.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
Expand Down Expand Up @@ -2213,6 +2221,20 @@ metal_header/freedom_metal_header_generator-template_device.obj: metal_header/te
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(freedom_metal_header_generator_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o metal_header/freedom_metal_header_generator-template_device.obj `if test -f 'metal_header/template_device.c++'; then $(CYGPATH_W) 'metal_header/template_device.c++'; else $(CYGPATH_W) '$(srcdir)/metal_header/template_device.c++'; fi`

metal_header/freedom_metal_header_generator-ucb_htif0.o: metal_header/ucb_htif0.c++
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(freedom_metal_header_generator_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT metal_header/freedom_metal_header_generator-ucb_htif0.o -MD -MP -MF metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Tpo -c -o metal_header/freedom_metal_header_generator-ucb_htif0.o `test -f 'metal_header/ucb_htif0.c++' || echo '$(srcdir)/'`metal_header/ucb_htif0.c++
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Tpo metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='metal_header/ucb_htif0.c++' object='metal_header/freedom_metal_header_generator-ucb_htif0.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(freedom_metal_header_generator_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o metal_header/freedom_metal_header_generator-ucb_htif0.o `test -f 'metal_header/ucb_htif0.c++' || echo '$(srcdir)/'`metal_header/ucb_htif0.c++

metal_header/freedom_metal_header_generator-ucb_htif0.obj: metal_header/ucb_htif0.c++
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(freedom_metal_header_generator_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT metal_header/freedom_metal_header_generator-ucb_htif0.obj -MD -MP -MF metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Tpo -c -o metal_header/freedom_metal_header_generator-ucb_htif0.obj `if test -f 'metal_header/ucb_htif0.c++'; then $(CYGPATH_W) 'metal_header/ucb_htif0.c++'; else $(CYGPATH_W) '$(srcdir)/metal_header/ucb_htif0.c++'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Tpo metal_header/$(DEPDIR)/freedom_metal_header_generator-ucb_htif0.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='metal_header/ucb_htif0.c++' object='metal_header/freedom_metal_header_generator-ucb_htif0.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(freedom_metal_header_generator_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o metal_header/freedom_metal_header_generator-ucb_htif0.obj `if test -f 'metal_header/ucb_htif0.c++'; then $(CYGPATH_W) 'metal_header/ucb_htif0.c++'; else $(CYGPATH_W) '$(srcdir)/metal_header/ucb_htif0.c++'; fi`

ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
Expand Down
2 changes: 2 additions & 0 deletions bare_header/freedom-bare_header-generator.c++
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "bare_header/sifive_trace.h"
#include "bare_header/sifive_uart0.h"
#include "bare_header/sifive_wdog0.h"
#include "bare_header/ucb_htif0.h"

using std::cerr;
using std::endl;
Expand Down Expand Up @@ -166,6 +167,7 @@ static void write_config_file(const fdt &dtb, fstream &os, std::string cfg_file,
devices.push_back(new sifive_trace(os, dtb));
devices.push_back(new sifive_uart0(os, dtb));
devices.push_back(new sifive_wdog0(os, dtb));
devices.push_back(new ucb_htif0(os, dtb));

for (auto it = devices.begin(); it != devices.end(); it++) {
(*it)->emit_defines();
Expand Down
32 changes: 32 additions & 0 deletions bare_header/ucb_htif0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef __BARE_HEADER_UCB_HTIF0__H
#define __BARE_HEADER_UCB_HTIF0__H

#include "bare_header/device.h"

#include <regex>

class ucb_htif0 : public Device {
public:
ucb_htif0(std::ostream &os, const fdt &dtb) : Device(os, dtb, "ucb,htif0") {}

void emit_defines() {
dtb.match(std::regex(compat_string), [&](node n) {
emit_comment(n);

os << std::endl;
});
}

void emit_offsets() {
if (dtb.match(std::regex(compat_string), [](const node n) {}) != 0) {
emit_compat();

os << std::endl;
}
}
};

#endif
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for freedom-devicetree-tools v201905-109-g1b5e465.
# Generated by GNU Autoconf 2.69 for freedom-devicetree-tools v201905-115-g7c4a007.
#
# Report bugs to <bsou@sifive.com>.
#
Expand Down Expand Up @@ -580,8 +580,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='freedom-devicetree-tools'
PACKAGE_TARNAME='freedom-devicetree-tools'
PACKAGE_VERSION='v201905-109-g1b5e465'
PACKAGE_STRING='freedom-devicetree-tools v201905-109-g1b5e465'
PACKAGE_VERSION='v201905-115-g7c4a007'
PACKAGE_STRING='freedom-devicetree-tools v201905-115-g7c4a007'
PACKAGE_BUGREPORT='bsou@sifive.com'
PACKAGE_URL=''

Expand Down Expand Up @@ -1291,7 +1291,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures freedom-devicetree-tools v201905-109-g1b5e465 to adapt to many kinds of systems.
\`configure' configures freedom-devicetree-tools v201905-115-g7c4a007 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1359,7 +1359,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of freedom-devicetree-tools v201905-109-g1b5e465:";;
short | recursive ) echo "Configuration of freedom-devicetree-tools v201905-115-g7c4a007:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1455,7 +1455,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
freedom-devicetree-tools configure v201905-109-g1b5e465
freedom-devicetree-tools configure v201905-115-g7c4a007
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1795,7 +1795,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by freedom-devicetree-tools $as_me v201905-109-g1b5e465, which was
It was created by freedom-devicetree-tools $as_me v201905-115-g7c4a007, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2662,7 +2662,7 @@ fi
# Define the identity of the package.
PACKAGE='freedom-devicetree-tools'
VERSION='v201905-109-g1b5e465'
VERSION='v201905-115-g7c4a007'
cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -5768,7 +5768,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by freedom-devicetree-tools $as_me v201905-109-g1b5e465, which was
This file was extended by freedom-devicetree-tools $as_me v201905-115-g7c4a007, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -5825,7 +5825,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
freedom-devicetree-tools config.status v201905-109-g1b5e465
freedom-devicetree-tools config.status v201905-115-g7c4a007
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Expand Down
5 changes: 5 additions & 0 deletions freedom-makeattributes-generator.c++
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ static void write_config_file(fstream &os, std::string board,
os << "TARGET_TAGS=qemu" << std::endl;
os << "TARGET_DHRY_ITERS=20000000" << std::endl;
os << "TARGET_CORE_ITERS=5000" << std::endl;
} else if (board.find("spike") != std::string::npos) {
os << "TARGET_TAGS=spike" << std::endl;
os << "TARGET_DHRY_ITERS=20000000" << std::endl;
os << "TARGET_CORE_ITERS=5000" << std::endl;
} else if (board.find("arty") != std::string::npos) {
os << "TARGET_TAGS=fpga openocd" << std::endl;
os << "TARGET_DHRY_ITERS=20000000" << std::endl;
Expand Down Expand Up @@ -561,6 +565,7 @@ int main(int argc, char *argv[]) {
board = argv[++i];
if ((board.find("rtl") != std::string::npos) ||
(board.find("arty") != std::string::npos) ||
(board.find("spike") != std::string::npos) ||
(board.find("hifive") != std::string::npos)) {
std::cout << "Board type given is " << board << std::endl;
} else {
Expand Down
21 changes: 21 additions & 0 deletions metal_header/device.c++
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ void Device::emit_def_handle(std::string handle, const node &n,
<< field << ")\n\n";
}

void Device::emit_def_handle(std::string handle, std::string suffix,
const node &n, std::string field) {
emit_comment(n);
os << "#define " << handle << " (&__metal_dt_" << n.handle() << "_" << suffix
<< field << ")\n\n";
}

void Device::emit_def(std::string handle, std::string field) {
os << "#define " << handle << " " << field << "\n\n";
}
Expand Down Expand Up @@ -244,12 +251,26 @@ void Device::emit_struct_decl(std::string type, const node &n) {
<< ";\n\n";
}

void Device::emit_struct_decl(std::string type, std::string suffix,
const node &n) {
emit_comment(n);
os << "struct __metal_driver_" << type << "_" << suffix << " __metal_dt_"
<< n.handle() << "_" << suffix << ";\n\n";
}

void Device::emit_struct_begin(std::string type, const node &n) {
emit_comment(n);
os << "struct __metal_driver_" << type << " __metal_dt_" << n.handle()
<< " = {\n";
}

void Device::emit_struct_begin(std::string type, std::string suffix,
const node &n) {
emit_comment(n);
os << "struct __metal_driver_" << type << "_" << suffix << " __metal_dt_"
<< n.handle() << "_" << suffix << " = {\n";
}

void Device::emit_struct_field(std::string field, std::string value) {
os << " ." << field << " = " << value << ",\n";
}
Expand Down
4 changes: 4 additions & 0 deletions metal_header/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Device {
void emit_handle(std::string d, const node &n, std::string v);

void emit_def_handle(std::string handle, const node &n, std::string field);
void emit_def_handle(std::string handle, std::string suffix, const node &n,
std::string field);

void emit_def(std::string handle, std::string field);

Expand Down Expand Up @@ -74,8 +76,10 @@ class Device {
void emit_struct_pointer_end(std::string empty);

void emit_struct_decl(std::string type, const node &n);
void emit_struct_decl(std::string type, std::string suffix, const node &n);

void emit_struct_begin(std::string type, const node &n);
void emit_struct_begin(std::string type, std::string suffix, const node &n);

void emit_struct_field(std::string field, std::string value);
void emit_struct_field_null(std::string field);
Expand Down
2 changes: 2 additions & 0 deletions metal_header/freedom-metal_header-generator.c++
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <sifive_trace.h>
#include <sifive_uart0.h>
#include <sifive_wdog0.h>
#include <ucb_htif0.h>

/* FE310-G000 Devices */
#include <sifive_fe310_g000_hfrosc.h>
Expand Down Expand Up @@ -159,6 +160,7 @@ static void prepare_devices(const fdt &dtb, fstream &os,
devices.push_back(new sifive_trace(os, dtb));
devices.push_back(new sifive_uart0(os, dtb));
devices.push_back(new sifive_wdog0(os, dtb));
devices.push_back(new ucb_htif0(os, dtb));

/* FE310-G000 Devices */
devices.push_back(new sifive_fe310_g000_hfrosc(os, dtb));
Expand Down
48 changes: 35 additions & 13 deletions metal_header/stdout_path.c++
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,48 @@

#include <stdout_path.h>

#include <iostream>
#include <regex>
#include <string>

using std::string;

stdout_path::stdout_path(std::ostream &os, const fdt &dtb)
: Device(os, dtb, "") {}

void stdout_path::create_handles() {
dtb.chosen("stdout-path", tuple_t<std::string>(), [&](std::string info) {
if (info.find(":") != decltype(info)::npos) {
auto path = info.substr(0, info.find(":"));
auto target = dtb.node_by_path(path);
auto baud = info.substr(info.find(":") + 1);

emit_def_handle("__METAL_DT_STDOUT_UART_HANDLE", target, ".uart");
emit_def("__METAL_DT_STDOUT_UART_BAUD", baud);
} else {
auto target = dtb.node_by_path(info);

emit_def_handle("__METAL_DT_STDOUT_UART_HANDLE", target, ".uart");
/* If no baud rate is specified, default to 115200 */
emit_def("__METAL_DT_STDOUT_UART_BAUD", "115200");
/* If no baud rate is specified, default to 115200 */
string baud = "115200";

auto get_target_node = [&]() -> const node {
if (info.find(":") != decltype(info)::npos) {
auto path = info.substr(0, info.find(":"));
auto target = dtb.node_by_path(path);
baud = info.substr(info.find(":") + 1);

return target;
} else {
auto target = dtb.node_by_path(info);

return target;
}
};

auto target = get_target_node();

/* Device-specific stdout-path behavior */
auto compat_strings = target.get_fields<string>("compatible");
for (auto it = compat_strings.begin(); it != compat_strings.end(); it++) {
if (it->find("ucb,htif0") != string::npos) {
emit_def_handle("__METAL_DT_STDOUT_UART_HANDLE", "uart", target,
".uart");
emit_def("__METAL_DT_STDOUT_UART_BAUD", baud);
return;
}
}

emit_def_handle("__METAL_DT_STDOUT_UART_HANDLE", target, ".uart");
emit_def("__METAL_DT_STDOUT_UART_BAUD", baud);
});
}

0 comments on commit 790c47d

Please sign in to comment.