Skip to content

Commit 7b4a200

Browse files
authored
Merge pull request #74 from pulp-platform/bluewww/soc-reg-tests
Improve SW helper functions and mixed fixes
2 parents 342ace2 + f4c5219 commit 7b4a200

File tree

10 files changed

+530
-56
lines changed

10 files changed

+530
-56
lines changed

carfield.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ hw/regs/carfield_regs.hjson: hw/regs/carfield_regs.csv | venv
9999
hw/regs/carfield_reg_pkg.sv hw/regs/carfield_reg_top.sv: hw/regs/carfield_regs.hjson | venv
100100
$(VENV)/python utils/reggen/regtool.py -r $< --outdir $(dir $@)
101101

102+
.PHONY: sw/include/regs/soc_ctrl.h
103+
sw/include/regs/soc_ctrl.h: hw/regs/carfield_regs.hjson | venv
104+
$(VENV)/python utils/reggen/regtool.py -D $< > $@
105+
102106
## @section Carfield SoC HW Generation
103107
.PHONY: regenerate_soc_regs
104108
## Regenerate the toplevel SoC Control Register file from the CSV description of all registers in

hw/carfield.sv

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ module carfield
6363
output logic jtag_safety_island_tdo_o,
6464
// Secure Subsystem BOOT pins
6565
input logic [1:0] bootmode_ot_i,
66-
// unused by safety island -- tdo pad always out mode
67-
output logic jtag_safe_isln_tdo_oe_o,
6866
// Safety Island BOOT pins
6967
input logic [1:0] bootmode_safe_isln_i,
7068
// Host UART Interface
@@ -1548,7 +1546,7 @@ secure_subsystem_synth_wrap #(
15481546
.jtag_trst_n_i ( jtag_ot_trst_ni ),
15491547
.jtag_tdi_i ( jtag_ot_tdi_i ),
15501548
.jtag_tdo_o ( jtag_ot_tdo_o ),
1551-
.jtag_tdo_oe_o ( ),
1549+
.jtag_tdo_oe_o ( jtag_ot_tdo_oe_o),
15521550
// Asynch axi port
15531551
.async_axi_out_aw_data_o ( axi_mst_ext_aw_data [SecurityIslandMstIdx] ),
15541552
.async_axi_out_aw_wptr_o ( axi_mst_ext_aw_wptr [SecurityIslandMstIdx] ),

sw/include/car_memory_map.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
// Nicole Narr <[email protected]>
66
// Christopher Reinwardt <[email protected]>
77
// Paul Scheffler <[email protected]>
8+
// Robert Balas <[email protected]>
9+
// Alessandro Ottaviano <[email protected]>
810
//
911
// This header provides information defined by hardware parameters, such as
1012
// the address map. In the future, it should be generated automatically as
1113
// part of the SoC generation process.
1214

13-
#pragma once
15+
#ifndef __CAR_MEMORY_MAP_H
16+
#define __CAR_MEMORY_MAP_H
1417

1518
// Base addresses provided at link time
1619
extern void *__base_l2;
@@ -46,20 +49,26 @@ extern void *__base_l2;
4649
#define CAR_HYPERRAM_END_ADDR 0x80800000
4750

4851
// Peripheral devices
49-
#define CAR_ETHERNET_BASE_ADDR 0x20000000
50-
#define CAR_PERIPHS_BASE_ADDR 0x20001000
52+
#define CAR_PERIPHS_BASE_ADDR 0x20000000
5153

52-
#define CAR_CAN_OFFSET 0x0000
53-
#define CAR_SYSTEM_TIMER_OFFSET 0x3000
54-
#define CAR_ADVANCED_TIMER_OFFSET 0x4000
55-
#define CAR_WATCHDOG_TIMER_OFFSET 0x6000
56-
#define CAR_HYPERBUS_CFG_OFFSET 0x8000
54+
#define CAR_ETHERNET_OFFSET 0x0000
55+
#define CAR_CAN_OFFSET 0x1000
56+
#define CAR_SYSTEM_TIMER_OFFSET 0x4000
57+
#define CAR_ADVANCED_TIMER_OFFSET 0x5000
58+
#define CAR_WATCHDOG_TIMER_OFFSET 0x7000
59+
#define CAR_HYPERBUS_CFG_OFFSET 0x9000
60+
#define CAR_PAD_CFG_OFFSET 0xa000
61+
#define CAR_SOC_CTRL_OFFSET 0x10000
5762

5863
#define CAR_ETHERNET_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_ETHERNET_OFFSET)
5964
#define CAR_CAN_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_CAN_OFFSET)
6065
#define CAR_SYSTEM_TIMER_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_SYSTEM_TIMER_OFFSET)
6166
#define CAR_ADVANCED_TIMER_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_ADVANCED_TIMER_OFFSET)
6267
#define CAR_WATCHDOG_TIMER_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_WATCHDOG_TIMER_OFFSET)
6368
#define CAR_HYPERBUS_CFG_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_HYPERBUS_CFG_OFFSET)
69+
#define CAR_PAD_CFG_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_PAD_CFG_OFFSET)
70+
#define CAR_SOC_CTRL_BASE_ADDR (CAR_PERIPHS_BASE_ADDR + CAR_SOC_CTRL_OFFSET)
6471

6572
#define CAR_MBOX_BASE_ADDR 0x40000000
73+
74+
#endif /* __CAR_MEMORY_MAP_H */

sw/include/car_util.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

sw/include/csr.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2023 ETH Zurich and University of Bologna.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Robert Balas <[email protected]>
6+
//
7+
8+
/* Description: CSR access macros
9+
* Authors: Robert Balas ([email protected])
10+
*/
11+
12+
#ifndef __CSR_H
13+
#define __CSR_H
14+
15+
/* TODO: complete this */
16+
#define CSR_MSTATUS 0x300
17+
#define CSR_MISA 0x301
18+
#define CSR_MIE 0x304
19+
#define CSR_MTVEC 0x305
20+
#define CSR_MSCRATCH 0x340
21+
#define CSR_MEPC 0x341
22+
#define CSR_MCAUSE 0x342
23+
#define CSR_MTVAL 0x343
24+
#define CSR_MIP 0x344
25+
#define CSR_MNXTI 0x345
26+
#define CSR_PMPCFG0 0x3a0
27+
#define CSR_PMPADDR0 0x3b0
28+
#define CSR_MHARTID 0xf14
29+
#define CSR_MINTSTATUS 0x346
30+
#define CSR_MINTTHRESH 0x347
31+
#define CSR_MCLICBASE 0x350
32+
#define MIE 8
33+
34+
#define __CSR_EXPAND(x) #x
35+
36+
#define csr_read(csr) \
37+
({ \
38+
register unsigned long __val; \
39+
asm volatile("csrr %0, " __CSR_EXPAND(csr) \
40+
: "=r"(__val) \
41+
: \
42+
: "memory"); \
43+
__val; \
44+
})
45+
46+
#define csr_write(csr, val) \
47+
({ \
48+
unsigned long __val = (unsigned long)(val); \
49+
asm volatile("csrw " __CSR_EXPAND(csr) ", %0" \
50+
: \
51+
: "rK"(__val) \
52+
: "memory"); \
53+
})
54+
55+
/* I hope this properly does a memory barrier with the "memory" hint */
56+
#define csr_read_clear(csr, val) \
57+
({ \
58+
unsigned long __val = (unsigned long)(val); \
59+
asm volatile("csrrc %0, " __CSR_EXPAND(csr) ", %1" \
60+
: "=r"(__val) \
61+
: "rK"(__val) \
62+
: "memory"); \
63+
__val; \
64+
})
65+
66+
#define csr_read_set(csr, val) \
67+
({ \
68+
unsigned long __val = (unsigned long)(val); \
69+
asm volatile("csrrs %0, " __CSR_EXPAND(csr) ", %1" \
70+
: "=r"(__val) \
71+
: "rK"(__val) \
72+
: "memory"); \
73+
__val; \
74+
})
75+
76+
#endif

sw/include/io.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2023 ETH Zurich and University of Bologna.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Robert Balas <[email protected]>
6+
//
7+
8+
/* Description: Memory mapped register I/O access
9+
*/
10+
11+
#ifndef __IO_H
12+
#define __IO_H
13+
14+
#include <stdint.h>
15+
16+
17+
/* generic I/O write */
18+
static inline void writeb(uint8_t val, uintptr_t addr)
19+
{
20+
asm volatile("sb %0, 0(%1)"
21+
:
22+
: "r"(val), "r"((volatile uint8_t *)addr)
23+
: "memory");
24+
}
25+
26+
static inline void writeh(uint16_t val, uintptr_t addr)
27+
{
28+
asm volatile("sh %0, 0(%1)"
29+
:
30+
: "r"(val), "r"((volatile uint16_t *)addr)
31+
: "memory");
32+
}
33+
34+
static inline void writew(uint32_t val, uintptr_t addr)
35+
{
36+
asm volatile("sw %0, 0(%1)"
37+
:
38+
: "r"(val), "r"((volatile uint32_t *)addr)
39+
: "memory");
40+
}
41+
42+
static inline void writed(uint64_t val, uintptr_t addr)
43+
{
44+
asm volatile("sd %0, 0(%1)"
45+
:
46+
: "r"(val), "r"((volatile uint64_t *)addr)
47+
: "memory");
48+
}
49+
50+
/* generic I/O read */
51+
static inline uint8_t readb(const uintptr_t addr)
52+
{
53+
uint8_t val;
54+
55+
asm volatile("lb %0, 0(%1)"
56+
: "=r"(val)
57+
: "r"((const volatile uint8_t *)addr)
58+
: "memory");
59+
return val;
60+
}
61+
62+
static inline uint16_t readh(const uintptr_t addr)
63+
{
64+
uint16_t val;
65+
66+
asm volatile("lh %0, 0(%1)"
67+
: "=r"(val)
68+
: "r"((const volatile uint16_t *)addr)
69+
: "memory");
70+
return val;
71+
}
72+
73+
static inline uint32_t readw(const uintptr_t addr)
74+
{
75+
uint32_t val;
76+
77+
asm volatile("lw %0, 0(%1)"
78+
: "=r"(val)
79+
: "r"((const volatile uint32_t *)addr)
80+
: "memory");
81+
return val;
82+
}
83+
84+
static inline uint64_t readd(const uintptr_t addr)
85+
{
86+
uint64_t val;
87+
88+
asm volatile("ld %0, 0(%1)"
89+
: "=r"(val)
90+
: "r"((const volatile uint64_t *)addr)
91+
: "memory");
92+
return val;
93+
}
94+
#endif

0 commit comments

Comments
 (0)