Skip to content

Commit

Permalink
sw: Correct uintptr_t - void* castings
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilKoe committed Jan 29, 2025
1 parent 7908f99 commit 84f14c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 52 deletions.
16 changes: 8 additions & 8 deletions sw/include/car_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#pragma once

#ifndef LINUX_APP // Hardcoded const pointers
const void* car_soc_ctrl = 0x20010000;
const void* car_safety_island = 0x60000000;
const void* car_integer_cluster = 0x50000000;
const void* car_spatz_cluster = 0x51000000;
const void* car_l2_intl_0 = 0x78000000;
const void* car_l2_cont_0 = 0x78100000;
const void* car_l2_intl_1 = 0x78200000;
const void* car_l2_cont_1 = 0x78300000;
const void* car_soc_ctrl = (void*) 0x20010000;
const void* car_safety_island = (void*) 0x60000000;
const void* car_integer_cluster = (void*) 0x50000000;
const void* car_spatz_cluster = (void*) 0x51000000;
const void* car_l2_intl_0 = (void*) 0x78000000;
const void* car_l2_cont_0 = (void*) 0x78100000;
const void* car_l2_intl_1 = (void*) 0x78200000;
const void* car_l2_cont_1 = (void*) 0x78300000;

#else // Pointers to be mapped by the driver
void* car_soc_ctrl;
Expand Down
35 changes: 18 additions & 17 deletions sw/include/car_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,38 +143,39 @@ static inline enum car_clk car_clkd_from_rstd(enum car_rst rst)
case CAR_L2_RST:
return CAR_L2_CLK;
}
return -1;
}

void car_set_isolate(enum car_rst rst, enum car_isolation_status status)
{
writew(status, CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_ISOLATE_offset(rst));
writew(status, (uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_ISOLATE_offset(rst)));
fence();
while (readw(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_ISOLATE_STATUS_offset(rst)) !=
while (readw((uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_ISOLATE_STATUS_offset(rst))) !=
status)
;
}

void car_enable_clk(enum car_clk clk)
{
writew(1, CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_EN_offset(clk));
writew(1, (uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_EN_offset(clk)));
fence();
}

void car_disable_clk(enum car_clk clk)
{
writew(0, CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_EN_offset(clk));
writew(0, (uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_EN_offset(clk)));
fence();
}

void car_select_clk(enum car_src_clk clk_src, enum car_clk clk)
{
writew(clk_src, CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_SEL_offset(clk));
writew(clk_src, (uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_CLK_SEL_offset(clk)));
fence();
}

void car_set_rst(enum car_rst rst, enum car_rst_status status)
{
writew(status, CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_RST_offset(rst));
writew(status, (uintptr_t)(CAR_SOC_CTRL_BASE_ADDR(car_soc_ctrl) + car_get_RST_offset(rst)));
fence();
}

Expand Down Expand Up @@ -295,23 +296,23 @@ int car_irq_router_range_disable(int lower, int upper, enum car_irq_router_targe
void prepare_safed_boot () {

// Select bootmode
volatile uintptr_t *bootmode_addr = (uintptr_t*)CAR_SAFETY_ISLAND_BOOTMODE_ADDR(car_safety_island);
volatile uintptr_t bootmode_addr = (uintptr_t)CAR_SAFETY_ISLAND_BOOTMODE_ADDR(car_safety_island);
writew(1, bootmode_addr);

// Write entry point into boot address
volatile uintptr_t *bootaddr_addr = (uintptr_t*)CAR_SAFETY_ISLAND_BOOTADDR_ADDR(car_safety_island);
writew(CAR_SAFETY_ISLAND_ENTRY_POINT(car_safety_island), bootaddr_addr);
volatile uintptr_t bootaddr_addr = (uintptr_t)CAR_SAFETY_ISLAND_BOOTADDR_ADDR(car_safety_island);
writew((uintptr_t)CAR_SAFETY_ISLAND_ENTRY_POINT(car_safety_island), bootaddr_addr);

// Assert fetch enable
volatile uintptr_t *fetchen_addr = (uintptr_t*)CAR_SAFETY_ISLAND_FETCHEN_ADDR(car_safety_island);
volatile uintptr_t fetchen_addr = (uintptr_t)CAR_SAFETY_ISLAND_FETCHEN_ADDR(car_safety_island);
writew(1, fetchen_addr);

}

uint32_t poll_safed_corestatus () {

volatile uint32_t corestatus;
volatile uintptr_t *corestatus_addr = (uintptr_t*)CAR_SAFETY_ISLAND_CORESTATUS_ADDR(car_safety_island);
volatile uintptr_t corestatus_addr = (uintptr_t)CAR_SAFETY_ISLAND_CORESTATUS_ADDR(car_safety_island);
// TODO: Add a timeut to not poll indefinitely
while (((uint32_t)readw(corestatus_addr) & 0x80000000) == 0)
;
Expand Down Expand Up @@ -346,34 +347,34 @@ uint32_t safed_offloader_blocking () {

void pulp_cluster_set_bootaddress(uint32_t pulp_boot_addr) {

volatile uint32_t cluster_boot_reg_addr = CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster);
volatile void *cluster_boot_reg_addr = (void *)CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster);

for (int i = 0; i < IntClustNumCores; i++) {
writew(pulp_boot_addr, (uint32_t*)(cluster_boot_reg_addr));
writew(pulp_boot_addr, (uintptr_t)(cluster_boot_reg_addr));
cluster_boot_reg_addr += 0x4;
}
}

void pulp_cluster_start() {

volatile uint32_t *booten_addr = (uint32_t*)(CAR_INT_CLUSTER_BOOTEN_ADDR(car_soc_ctrl));
volatile uintptr_t booten_addr = (uintptr_t)(CAR_INT_CLUSTER_BOOTEN_ADDR(car_soc_ctrl));
writew(1, booten_addr);

volatile uint32_t *fetchen_addr = (uint32_t*)(CAR_INT_CLUSTER_FETCHEN_ADDR(car_soc_ctrl));
volatile uintptr_t fetchen_addr = (uintptr_t)(CAR_INT_CLUSTER_FETCHEN_ADDR(car_soc_ctrl));
writew(1, fetchen_addr);
}

void pulp_cluster_wait_eoc() {

volatile uint32_t *pulp_eoc_addr = (uint32_t*)(CAR_INT_CLUSTER_EOC_ADDR(car_soc_ctrl));
volatile uintptr_t pulp_eoc_addr = (uintptr_t)(CAR_INT_CLUSTER_EOC_ADDR(car_soc_ctrl));

while(!readw(pulp_eoc_addr))
;

}

uint32_t pulp_cluster_get_return(){
volatile uint32_t *pulp_return_addr = (uint32_t*)(CAR_INT_CLUSTER_RETURN_ADDR(car_integer_cluster));
volatile uintptr_t pulp_return_addr = (uintptr_t)(CAR_INT_CLUSTER_RETURN_ADDR(car_integer_cluster));
return readw(pulp_return_addr);
}

Expand Down
36 changes: 18 additions & 18 deletions sw/tests/bare-metal/hostd/addressability_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,42 @@ int main(void) {
// (wrwr)

// L2 shared memory
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_L2_SPM_PORT1_INTERLEAVED_BASE_ADDR(car_l2_intl_1),
(uint64_t *)CAR_L2_SPM_PORT1_INTERLEAVED_END_ADDR(car_l2_intl_1), N_SAMPLES);
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_L2_SPM_PORT1_INTERLEAVED_BASE_ADDR(car_l2_intl_1),
(uintptr_t)CAR_L2_SPM_PORT1_INTERLEAVED_END_ADDR(car_l2_intl_1), N_SAMPLES);
if (errors) {
char str[] = "1\n";
diyprintf(str, sizeof(str));
}

errors += probe_range_lfsr_wrwr((uint64_t *)CAR_L2_SPM_PORT1_CONTIGUOUS_BASE_ADDR(car_l2_cont_1),
(uint64_t *)CAR_L2_SPM_PORT1_CONTIGUOUS_END_ADDR(car_l2_cont_1), N_SAMPLES);
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_L2_SPM_PORT1_CONTIGUOUS_BASE_ADDR(car_l2_cont_1),
(uintptr_t)CAR_L2_SPM_PORT1_CONTIGUOUS_END_ADDR(car_l2_cont_1), N_SAMPLES);
if (errors) {
char str[] = "2\n";
diyprintf(str, sizeof(str));
}

// Safety Island
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_SAFETY_ISLAND_SPM_BASE_ADDR(car_safety_island),
(uint64_t *)CAR_SAFETY_ISLAND_SPM_END_ADDR(car_safety_island), N_SAMPLES);
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_SAFETY_ISLAND_SPM_BASE_ADDR(car_safety_island),
(uintptr_t)CAR_SAFETY_ISLAND_SPM_END_ADDR(car_safety_island), N_SAMPLES);
if (errors) {
char str[] = "3\n";
diyprintf(str, sizeof(str));
}
// Integer Cluster
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_INT_CLUSTER_SPM_BASE_ADDR(car_integer_cluster), (uint64_t *)CAR_INT_CLUSTER_SPM_END_ADDR(car_integer_cluster),
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_INT_CLUSTER_SPM_BASE_ADDR(car_integer_cluster), (uintptr_t)CAR_INT_CLUSTER_SPM_END_ADDR(car_integer_cluster),
N_SAMPLES);
if (errors) {
char str[] = "4\n";
diyprintf(str, sizeof(str));
}
// HyperRAM
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_HYPERRAM_BASE_ADDR, (uint64_t *)CAR_HYPERRAM_END_ADDR, N_SAMPLES);
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_HYPERRAM_BASE_ADDR, (uintptr_t)CAR_HYPERRAM_END_ADDR, N_SAMPLES);
if (errors) {
char str[] = "5\n";
diyprintf(str, sizeof(str));
}
// FP Cluster
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_FP_CLUSTER_SPM_BASE_ADDR(car_spatz_cluster), (uint64_t *)CAR_FP_CLUSTER_SPM_END_ADDR(car_spatz_cluster),
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_FP_CLUSTER_SPM_BASE_ADDR(car_spatz_cluster), (uintptr_t)CAR_FP_CLUSTER_SPM_END_ADDR(car_spatz_cluster),
N_SAMPLES);
if (errors) {
char str[] = "6\n";
Expand All @@ -202,41 +202,41 @@ int main(void) {
// writing (wwrr)

// L2 shared memory
errors += probe_range_lfsr_wwrr((uint64_t *)CAR_L2_SPM_PORT1_INTERLEAVED_BASE_ADDR(car_l2_intl_1),
(uint64_t *)CAR_L2_SPM_PORT1_INTERLEAVED_END_ADDR(car_l2_intl_1), N_SAMPLES);
errors += probe_range_lfsr_wwrr((uintptr_t)CAR_L2_SPM_PORT1_INTERLEAVED_BASE_ADDR(car_l2_intl_1),
(uintptr_t)CAR_L2_SPM_PORT1_INTERLEAVED_END_ADDR(car_l2_intl_1), N_SAMPLES);
if (errors) {
char str[] = "7\n";
diyprintf(str, sizeof(str));
}
errors += probe_range_lfsr_wwrr((uint64_t *)CAR_L2_SPM_PORT1_CONTIGUOUS_BASE_ADDR(car_l2_cont_1),
(uint64_t *)CAR_L2_SPM_PORT1_CONTIGUOUS_END_ADDR(car_l2_cont_1), N_SAMPLES);
errors += probe_range_lfsr_wwrr((uintptr_t)CAR_L2_SPM_PORT1_CONTIGUOUS_BASE_ADDR(car_l2_cont_1),
(uintptr_t)CAR_L2_SPM_PORT1_CONTIGUOUS_END_ADDR(car_l2_cont_1), N_SAMPLES);
if (errors) {
char str[] = "8\n";
diyprintf(str, sizeof(str));
}

// Safety Island
errors += probe_range_lfsr_wwrr((uint64_t *)CAR_SAFETY_ISLAND_SPM_BASE_ADDR(car_safety_island),
(uint64_t *)CAR_SAFETY_ISLAND_SPM_END_ADDR(car_safety_island), N_SAMPLES);
errors += probe_range_lfsr_wwrr((uintptr_t)CAR_SAFETY_ISLAND_SPM_BASE_ADDR(car_safety_island),
(uintptr_t)CAR_SAFETY_ISLAND_SPM_END_ADDR(car_safety_island), N_SAMPLES);
if (errors) {
char str[] = "9\n";
diyprintf(str, sizeof(str));
}
// Integer Cluster
errors += probe_range_lfsr_wwrr((uint64_t *)CAR_INT_CLUSTER_SPM_BASE_ADDR(car_integer_cluster), (uint64_t *)CAR_INT_CLUSTER_SPM_END_ADDR(car_integer_cluster),
errors += probe_range_lfsr_wwrr((uintptr_t)CAR_INT_CLUSTER_SPM_BASE_ADDR(car_integer_cluster), (uintptr_t)CAR_INT_CLUSTER_SPM_END_ADDR(car_integer_cluster),
N_SAMPLES);
if (errors) {
char str[] = "a\n";
diyprintf(str, sizeof(str));
}
// HyperRAM
errors += probe_range_lfsr_wwrr((uint64_t *)CAR_HYPERRAM_BASE_ADDR, (uint64_t *)CAR_HYPERRAM_END_ADDR, N_SAMPLES);
errors += probe_range_lfsr_wwrr((uintptr_t)CAR_HYPERRAM_BASE_ADDR, (uintptr_t)CAR_HYPERRAM_END_ADDR, N_SAMPLES);
if (errors) {
char str[] = "b\n";
diyprintf(str, sizeof(str));
}
// FP Cluster
errors += probe_range_lfsr_wrwr((uint64_t *)CAR_FP_CLUSTER_SPM_BASE_ADDR(car_spatz_cluster), (uint64_t *)CAR_FP_CLUSTER_SPM_END_ADDR(car_spatz_cluster),
errors += probe_range_lfsr_wrwr((uintptr_t)CAR_FP_CLUSTER_SPM_BASE_ADDR(car_spatz_cluster), (uintptr_t)CAR_FP_CLUSTER_SPM_END_ADDR(car_spatz_cluster),
N_SAMPLES);
if (errors) {
char str[] = "c\n";
Expand Down
18 changes: 9 additions & 9 deletions sw/tests/bare-metal/hostd/sw_rst_seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,44 @@ int main(void)
uint64_t magic = 0xcafebeef;

// Write a pattern to safety island boot addr
writew(magic, CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
writew(magic, (uintptr_t)CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
SAFETY_SOC_CTRL_BOOTADDR_REG_OFFSET);

// Double check
if (readw(CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
if (readw((uintptr_t)CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
SAFETY_SOC_CTRL_BOOTADDR_REG_OFFSET) != magic)
return ESAFEDNOACCES;

// engage reset sequence for safety island
car_reset_domain(CAR_SAFETY_RST);

// After the reset we should only see zeros
if (readw(CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
if (readw((uintptr_t)CAR_SAFETY_ISLAND_PERIPHS_BASE_ADDR(car_safety_island) +
SAFETY_SOC_CTRL_BOOTADDR_REG_OFFSET) !=
SAFETY_ISLAND_BOOT_ADDR_RSVAL)
return ESAFEDNOACCES;

// Spatz
writew(magic, CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
writew(magic, (uintptr_t)CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
SPATZ_CLUSTER_PERIPHERAL_CLUSTER_BOOT_CONTROL_REG_OFFSET);
if (readw(CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
if (readw((uintptr_t)CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
SPATZ_CLUSTER_PERIPHERAL_CLUSTER_BOOT_CONTROL_REG_OFFSET) !=
magic)
return EFPCLNOACCES;

car_reset_domain(CAR_SPATZ_RST);
if (readw(CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
if (readw((uintptr_t)CAR_FP_CLUSTER_PERIPHS_BASE_ADDR(car_spatz_cluster) +
SPATZ_CLUSTER_PERIPHERAL_CLUSTER_BOOT_CONTROL_REG_OFFSET) != 0)
return EFPCLNOACCES;

// PULP Reset
writew(magic, CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster));
if (readw(CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster)) != magic)
writew(magic, (uintptr_t)CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster));
if (readw((uintptr_t)CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster)) != magic)
return EINTCLNOACCES;

volatile uint32_t pulp_boot_addr_rst_value = 0x78008080;
car_reset_domain(CAR_PULP_RST);
if (readw(CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster)) != pulp_boot_addr_rst_value)
if (readw((uintptr_t)CAR_INT_CLUSTER_BOOT_ADDR_REG(car_integer_cluster)) != pulp_boot_addr_rst_value)
return EINTCLNOACCES;

// L2 Reset
Expand Down

0 comments on commit 84f14c0

Please sign in to comment.