Skip to content

Commit

Permalink
Merge pull request #349 from sifive/l2pf-mc-maxout-fix
Browse files Browse the repository at this point in the history
Add check for a valid l2pf base address.
  • Loading branch information
bsousi5 committed Oct 5, 2020
2 parents 5d4f3e2 + dbcaa88 commit c740bd1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/drivers/sifive_l2pf0.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void sifive_l2pf0_enable(void) {
int hartid;
__asm__ volatile("csrr %0, mhartid" : "=r"(hartid));

if (hartid < l2pf_base_len) {
if ((hartid < l2pf_base_len) && (l2pf_base[hartid] != 0UL)) {
uint32_t val = REGW(METAL_SIFIVE_L2PF0_BASIC_CONTROL);

/* Enable L2 prefetch unit for current hart */
Expand All @@ -52,7 +52,7 @@ void sifive_l2pf0_disable(void) {
int hartid;
__asm__ volatile("csrr %0, mhartid" : "=r"(hartid));

if (hartid < l2pf_base_len) {
if ((hartid < l2pf_base_len) && (l2pf_base[hartid] != 0UL)) {
uint32_t val = REGW(METAL_SIFIVE_L2PF0_BASIC_CONTROL);

/* Disable L2 prefetch unit for current hart */
Expand All @@ -68,7 +68,7 @@ void sifive_l2pf0_get_config(sifive_l2pf0_config *config) {
uint32_t val;

/* Check for NULL, valid base address */
if ((config) && (hartid < l2pf_base_len)) {
if ((config) && (hartid < l2pf_base_len) && (l2pf_base[hartid] != 0UL)) {
/* Get currently active L2 prefetch configuration values */
val = REGW(METAL_SIFIVE_L2PF0_BASIC_CONTROL);

Expand Down Expand Up @@ -103,7 +103,7 @@ void sifive_l2pf0_set_config(sifive_l2pf0_config *config) {
uint32_t val;

/* Check for NULL, valid base address */
if ((config) && (hartid < l2pf_base_len)) {
if ((config) && (hartid < l2pf_base_len) && (l2pf_base[hartid] != 0UL)) {
/* Get values from configuration to write into register */
val = (uint32_t)(
(config->HwPrefetchEnable & REG_MASK_BITWIDTH1) |
Expand Down

0 comments on commit c740bd1

Please sign in to comment.