forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: add memory-type errata for T-Head
Some current cpus based on T-Head cores implement memory-types way different than described in the svpbmt spec even going so far as using PTE bits marked as reserved. Add the T-Head vendor-id and necessary errata code to replace the affected instructions. Signed-off-by: Heiko Stuebner <[email protected]> Tested-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
- Loading branch information
1 parent
1745cfa
commit a35707c
Showing
15 changed files
with
260 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
obj-$(CONFIG_ERRATA_SIFIVE) += sifive/ | ||
obj-$(CONFIG_ERRATA_THEAD) += thead/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ifdef CONFIG_RISCV_ALTERNATIVE_EARLY | ||
CFLAGS_errata.o := -mcmodel=medany | ||
ifdef CONFIG_FTRACE | ||
CFLAGS_REMOVE_errata.o = $(CC_FLAGS_FTRACE) | ||
endif | ||
ifdef CONFIG_KASAN | ||
KASAN_SANITIZE_errata.o := n | ||
endif | ||
endif | ||
|
||
obj-y += errata.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (C) 2021 Heiko Stuebner <[email protected]> | ||
*/ | ||
|
||
#include <linux/bug.h> | ||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/string.h> | ||
#include <linux/uaccess.h> | ||
#include <asm/alternative.h> | ||
#include <asm/cacheflush.h> | ||
#include <asm/errata_list.h> | ||
#include <asm/patch.h> | ||
#include <asm/vendorid_list.h> | ||
|
||
struct errata_info { | ||
char name[ERRATA_STRING_LENGTH_MAX]; | ||
bool (*check_func)(unsigned long arch_id, unsigned long impid); | ||
unsigned int stage; | ||
}; | ||
|
||
static bool errata_mt_check_func(unsigned long arch_id, unsigned long impid) | ||
{ | ||
if (arch_id != 0 || impid != 0) | ||
return false; | ||
return true; | ||
} | ||
|
||
static const struct errata_info errata_list[ERRATA_THEAD_NUMBER] = { | ||
{ | ||
.name = "memory-types", | ||
.stage = RISCV_ALTERNATIVES_EARLY_BOOT, | ||
.check_func = errata_mt_check_func | ||
}, | ||
}; | ||
|
||
static u32 thead_errata_probe(unsigned int stage, unsigned long archid, unsigned long impid) | ||
{ | ||
const struct errata_info *info; | ||
u32 cpu_req_errata = 0; | ||
int idx; | ||
|
||
for (idx = 0; idx < ERRATA_THEAD_NUMBER; idx++) { | ||
info = &errata_list[idx]; | ||
|
||
if ((stage == RISCV_ALTERNATIVES_MODULE || | ||
info->stage == stage) && info->check_func(archid, impid)) | ||
cpu_req_errata |= (1U << idx); | ||
} | ||
|
||
return cpu_req_errata; | ||
} | ||
|
||
void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end, | ||
unsigned long archid, unsigned long impid, | ||
unsigned int stage) | ||
{ | ||
struct alt_entry *alt; | ||
u32 cpu_req_errata = thead_errata_probe(stage, archid, impid); | ||
u32 tmp; | ||
|
||
for (alt = begin; alt < end; alt++) { | ||
if (alt->vendor_id != THEAD_VENDOR_ID) | ||
continue; | ||
if (alt->errata_id >= ERRATA_THEAD_NUMBER) | ||
continue; | ||
|
||
tmp = (1U << alt->errata_id); | ||
if (cpu_req_errata & tmp) { | ||
/* On vm-alternatives, the mmu isn't running yet */ | ||
if (stage == RISCV_ALTERNATIVES_EARLY_BOOT) | ||
memcpy((void *)__pa_symbol(alt->old_ptr), | ||
(void *)__pa_symbol(alt->alt_ptr), alt->alt_len); | ||
else | ||
patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len); | ||
} | ||
} | ||
|
||
if (stage == RISCV_ALTERNATIVES_EARLY_BOOT) | ||
local_flush_icache_all(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
#define ASM_VENDOR_LIST_H | ||
|
||
#define SIFIVE_VENDOR_ID 0x489 | ||
#define THEAD_VENDOR_ID 0x5b7 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.