Skip to content

Commit

Permalink
Add Astral option to N-EUREKA's BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoConti committed Mar 26, 2024
1 parent 99cc182 commit 37a8013
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 1 deletion.
101 changes: 101 additions & 0 deletions neureka/bsp/astral/neureka_astral_bsp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Luka Macan <luka.macan@unibo.it>
*
* Copyright 2023 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "neureka_astral_bsp.h"
#include <pmsis.h>

#define NEUREKA_ASTRAL_CLUSTER_CTRL_BASE_ADDR (0x50200000)
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_OFFS 0x18
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR \
(NEUREKA_ASTRAL_CLUSTER_CTRL_BASE_ADDR + \
NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_OFFS)
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_CG_EN 0x800
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_NEUREKA_SEL 0x2000
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO 0x100
#define NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL 0xff
#define NEUREKA_ASTRAL_MAX_STALL (8)
#define NEUREKA_ASTRAL_EVENT (1 << 12)
#define NEUREKA_ASTRAL_BASE_ADDR (0x50201000)

void neureka_astral_cg_enable() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR |=
NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_CG_EN;
}

void neureka_astral_cg_disable() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR &=
~NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_CG_EN;
}

void neureka_astral_neureka_select() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR |=
NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_NEUREKA_SEL;
}

void neureka_astral_neureka_unselect() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR &=
~NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_NEUREKA_SEL;
}

void neureka_astral_hci_setpriority_neureka() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR |=
NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO;
}

void neureka_astral_hci_setpriority_core() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR &=
~NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO;
}

void neureka_astral_hci_reset_max_stall() {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR &=
~NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL;
}

void neureka_astral_hci_set_max_stall(uint32_t max_stall) {
*(volatile uint32_t *)NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_ADDR |=
max_stall & NEUREKA_ASTRAL_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL;
}

void neureka_astral_open(neureka_astral_conf_t *conf) {
neureka_astral_cg_enable();
neureka_astral_neureka_select();
neureka_astral_hci_setpriority_neureka();
neureka_astral_hci_set_max_stall(conf->max_stall);
}

void neureka_astral_close() {
neureka_astral_cg_disable();
neureka_astral_neureka_unselect();
neureka_astral_hci_reset_max_stall();
neureka_astral_hci_setpriority_core();
}

void neureka_astral_event_wait_and_clear() {
eu_evt_maskWaitAndClr(NEUREKA_ASTRAL_EVENT);
}

static const neureka_dev_t neureka_astral_dev = {
.hwpe_dev = (struct hwpe_dev_t){
.base_addr = (volatile uint32_t *)NEUREKA_ASTRAL_BASE_ADDR}};

const neureka_dev_t *neureka_astral_get_dev() {
return &neureka_astral_dev;
}
67 changes: 67 additions & 0 deletions neureka/bsp/astral/neureka_astral_bsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Luka Macan <luka.macan@unibo.it>
*
* Copyright 2023 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __NEUREKA_ASTRAL_BSP_H__
#define __NEUREKA_ASTRAL_BSP_H__

#include "neureka.h"
#include <stdint.h>

/**
* neureka_astral_setpriority_neureka
*
* Set HCI interconnect bus priority to prioritize neureka.
*/
void neureka_astral_hci_setpriority_neureka();

/**
* neureka_astral_setpriority_core
*
* Set HCI bus priority to prioritize cores.
*/
void neureka_astral_hci_setpriority_core();

/**
* neureka_astral_hci_reset_maxstall
*
* Reset the HCI bus maxstall parameter.
* TODO: Check if it disables it also or just resets?
*/
void neureka_astral_hci_reset_max_stall();

/**
* neureka_astral_hci_set_maxstall
*
* Set the HCI bus maxstall. Maxstall defines how many cycles
* will the HCI bus stall the lower priority master, i.e. neureka or core,
* before letting it do a transaction.
*/
void neureka_astral_hci_set_max_stall(uint32_t max_stall);

typedef struct neureka_astral_conf_t {
int max_stall;
} neureka_astral_conf_t;

void neureka_astral_open(neureka_astral_conf_t *conf);
void neureka_astral_close();
void neureka_astral_event_wait_and_clear();
const neureka_dev_t *neureka_astral_get_dev();

#endif // !__NEUREKA_ASTRAL_BSP_H__
8 changes: 7 additions & 1 deletion neureka/bsp/neureka_bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
#define neureka_bsp_open neureka_testbench_open
#define neureka_bsp_close neureka_testbench_close
#define neureka_bsp_event_wait_and_clear neureka_testbench_event_wait_and_clear
#elif NNX_NEUREKA_ASTRAL
#include "neureka_astral_bsp.h"
#define neureka_bsp_conf_t neureka_astral_conf_t
#define neureka_bsp_open neureka_astral_open
#define neureka_bsp_close neureka_astral_close
#define neureka_bsp_event_wait_and_clear neureka_astral_event_wait_and_clear
#else
#include "neureka_siracusa_bsp.h"
#define neureka_bsp_conf_t neureka_siracusa_conf_t
#define neureka_bsp_open neureka_siracusa_open
#define neureka_bsp_close neureka_siracusa_close
#define neureka_bsp_event_wait_and_clear neureka_siracusa_event_wait_and_clear
#endif
#endif

0 comments on commit 37a8013

Please sign in to comment.