Skip to content

Commit

Permalink
sw: Adjust *_decls headers for usability in downstream projects (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
zero9178 authored Apr 23, 2024
1 parent 13d1e6b commit e02cc9e
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 5 deletions.
5 changes: 5 additions & 0 deletions sw/snRuntime/api/alloc_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stddef.h>
#include <stdint.h>

typedef struct {
// Base address from where allocation starts
uint32_t base;
Expand Down
6 changes: 6 additions & 0 deletions sw/snRuntime/api/cls_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

#include "alloc_decls.h"

typedef struct {
uint32_t hw_barrier;
snrt_allocator_t l1_allocator;
Expand Down
4 changes: 4 additions & 0 deletions sw/snRuntime/api/cluster_interrupt_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

inline void snrt_int_cluster_set(uint32_t mask);

inline void snrt_int_cluster_clr(uint32_t mask);
Expand Down
4 changes: 4 additions & 0 deletions sw/snRuntime/api/global_interrupt_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

inline void snrt_int_sw_clear(uint32_t hartid);

inline void snrt_int_sw_set(uint32_t hartid);
Expand Down
4 changes: 4 additions & 0 deletions sw/snRuntime/api/memory_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

inline uint32_t __attribute__((const)) snrt_l1_start_addr();

inline uint32_t __attribute__((const)) snrt_l1_end_addr();
Expand Down
4 changes: 4 additions & 0 deletions sw/snRuntime/api/omp/eu_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

typedef struct {
uint32_t workers_in_loop;
uint32_t exit_flag;
Expand Down
4 changes: 3 additions & 1 deletion sw/snRuntime/api/riscv_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "../../deps/riscv-opcodes/encoding.h"
#pragma once

#include <stdint.h>

static inline void snrt_wfi();

Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/api/start_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

static inline void snrt_exit(int exit_code);
4 changes: 4 additions & 0 deletions sw/snRuntime/api/sync_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

typedef struct {
uint32_t volatile cnt;
uint32_t volatile iteration;
Expand Down
6 changes: 5 additions & 1 deletion sw/snRuntime/api/team_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <stdint.h>

inline uint32_t __attribute__((const)) snrt_hartid();
inline uint32_t __attribute__((const)) snrt_cluster_num();
inline uint32_t __attribute__((const)) snrt_cluster_core_num();
Expand All @@ -13,4 +17,4 @@ inline uint32_t __attribute__((const)) snrt_cluster_core_idx();
inline uint32_t __attribute__((const)) snrt_cluster_dm_core_num();
inline uint32_t __attribute__((const)) snrt_cluster_compute_core_num();
inline int __attribute__((const)) snrt_is_compute_core();
inline int __attribute__((const)) snrt_is_dm_core();
inline int __attribute__((const)) snrt_is_dm_core();
2 changes: 2 additions & 0 deletions sw/snRuntime/src/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#define ALIGN_UP(addr, size) (((addr) + (size)-1) & ~((size)-1))
#define ALIGN_DOWN(addr, size) ((addr) & ~((size)-1))

Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/cls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

extern __thread cls_t* _cls_ptr;

inline cls_t* cls() { return _cls_ptr; }
2 changes: 2 additions & 0 deletions sw/snRuntime/src/cluster_interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../../deps/riscv-opcodes/encoding.h"

/**
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

/// A DMA transfer identifier.
typedef uint32_t snrt_dma_txid_t;

Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// will print the given value via the 8th register. Alternatively, the
// `write_csr(reg, val)` macro can be used directly.

#pragma once

#define NAMED_DUMP(type, name, reg) \
static __attribute__((always_inline)) inline void dump_##name(type val) { \
asm volatile("csrw " #reg ", %0" ::"rK"(val)); \
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/global_interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

/**
* @brief Clear SW interrupt in CLINT
* @details
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/perf_cnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

/// Different perf counters
// Must match with `snitch_cluster_peripheral`
enum snrt_perf_cnt {
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

// Use snrt_putchar for printf
#define _putchar snrt_putchar

Expand Down
21 changes: 21 additions & 0 deletions sw/snRuntime/src/riscv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "riscv_decls.h"

#include "riscv.h"

extern void snrt_wfi();

extern void snrt_nop();

extern uint32_t snrt_mcycle();

extern void snrt_interrupt_enable(uint32_t irq);

extern void snrt_interrupt_disable(uint32_t irq);

extern void snrt_interrupt_global_enable(void);

extern void snrt_interrupt_global_disable(void);
10 changes: 7 additions & 3 deletions sw/snRuntime/src/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

#include "riscv_decls.h"

#pragma once

#include "../../deps/riscv-opcodes/encoding.h"

/**
* @brief Put the hart into wait for interrupt state
*
*/
static inline void snrt_wfi() { asm volatile("wfi"); }
inline void snrt_wfi() { asm volatile("wfi"); }

static inline void snrt_nop() { asm volatile("nop" : : :); }
inline void snrt_nop() { asm volatile("nop" : : :); }

static inline uint32_t snrt_mcycle() {
inline uint32_t snrt_mcycle() {
uint32_t register r;
asm volatile("csrr %0, mcycle" : "=r"(r) : : "memory");
return r;
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/ssr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

/// Synchronize the integer and float pipelines.
inline void snrt_fpu_fence() {
unsigned tmp;
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Luca Colagrande <colluca@iis.ee.ethz.ch>
// Viviane Potocnik <vivianep@iis.ee.ethz.ch>

#pragma once

#include <math.h>

//================================================================================
Expand Down
2 changes: 2 additions & 0 deletions sw/snRuntime/src/team.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#pragma once

inline uint32_t __attribute__((const)) snrt_hartid() {
uint32_t hartid;
asm("csrr %0, mhartid" : "=r"(hartid));
Expand Down
1 change: 1 addition & 0 deletions target/snitch_cluster/sw/runtime/banshee/src/snrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "omp.c"
#include "printf.c"
#include "putchar.c"
#include "riscv.c"
#include "snitch_cluster_start.c"
#include "sync.c"
#include "team.c"
1 change: 1 addition & 0 deletions target/snitch_cluster/sw/runtime/rtl/src/snrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "omp.c"
#include "printf.c"
#include "putchar.c"
#include "riscv.c"
#include "snitch_cluster_start.c"
#include "sync.c"
#include "team.c"

0 comments on commit e02cc9e

Please sign in to comment.