Skip to content

Commit c23be91

Browse files
Merge patch series "Add non-coherent DMA support for AX45MP"
Prabhakar <prabhakar.csengg@gmail.com> says: From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> non-coherent DMA support for AX45MP ==================================== On the Andes AX45MP core, cache coherency is a specification option so it may not be supported. In this case DMA will fail. To get around with this issue this patch series does the below: 1] Andes alternative ports is implemented as errata which checks if the IOCP is missing and only then applies to CMO errata. One vendor specific SBI EXT (ANDES_SBI_EXT_IOCP_SW_WORKAROUND) is implemented as part of errata. Below are the configs which Andes port provides (and are selected by RZ/Five): - ERRATA_ANDES - ERRATA_ANDES_CMO OpenSBI patch supporting ANDES_SBI_EXT_IOCP_SW_WORKAROUND SBI is now part v1.3 release. 2] Andes AX45MP core has a Programmable Physical Memory Attributes (PMA) block that allows dynamic adjustment of memory attributes in the runtime. It contains a configurable amount of PMA entries implemented as CSR registers to control the attributes of memory locations in interest. OpenSBI configures the PMA regions as required and creates a reserve memory node and propagates it to the higher boot stack. Currently OpenSBI (upstream) configures the required PMA region and passes this a shared DMA pool to Linux. reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges; pma_resv0@58000000 { compatible = "shared-dma-pool"; reg = <0x0 0x58000000 0x0 0x08000000>; no-map; linux,dma-default; }; }; The above shared DMA pool gets appended to Linux DTB so the DMA memory requests go through this region. 3] We provide callbacks to synchronize specific content between memory and cache. 4] RZ/Five SoC selects the below configs - AX45MP_L2_CACHE - DMA_GLOBAL_POOL - ERRATA_ANDES - ERRATA_ANDES_CMO ----------x---------------------x--------------------x---------------x---- * b4-shazam-merge: soc: renesas: Kconfig: Select the required configs for RZ/Five SoC cache: Add L2 cache management for Andes AX45MP RISC-V core dt-bindings: cache: andestech,ax45mp-cache: Add DT binding documentation for L2 cache controller riscv: mm: dma-noncoherent: nonstandard cache operations support riscv: errata: Add Andes alternative ports riscv: asm: vendorid_list: Add Andes Technology to the vendors list Link: https://lore.kernel.org/r/20230818135723.80612-1-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents 7f215d0 + 484861e commit c23be91

File tree

20 files changed

+516
-0
lines changed

20 files changed

+516
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
# Copyright (C) 2023 Renesas Electronics Corp.
3+
%YAML 1.2
4+
---
5+
$id: http://devicetree.org/schemas/cache/andestech,ax45mp-cache.yaml#
6+
$schema: http://devicetree.org/meta-schemas/core.yaml#
7+
8+
title: Andestech AX45MP L2 Cache Controller
9+
10+
maintainers:
11+
- Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
12+
13+
description:
14+
A level-2 cache (L2C) is used to improve the system performance by providing
15+
a large amount of cache line entries and reasonable access delays. The L2C
16+
is shared between cores, and a non-inclusive non-exclusive policy is used.
17+
18+
select:
19+
properties:
20+
compatible:
21+
contains:
22+
enum:
23+
- andestech,ax45mp-cache
24+
25+
required:
26+
- compatible
27+
28+
properties:
29+
compatible:
30+
items:
31+
- const: andestech,ax45mp-cache
32+
- const: cache
33+
34+
reg:
35+
maxItems: 1
36+
37+
interrupts:
38+
maxItems: 1
39+
40+
cache-line-size:
41+
const: 64
42+
43+
cache-level:
44+
const: 2
45+
46+
cache-sets:
47+
const: 1024
48+
49+
cache-size:
50+
enum: [131072, 262144, 524288, 1048576, 2097152]
51+
52+
cache-unified: true
53+
54+
next-level-cache: true
55+
56+
additionalProperties: false
57+
58+
required:
59+
- compatible
60+
- reg
61+
- interrupts
62+
- cache-line-size
63+
- cache-level
64+
- cache-sets
65+
- cache-size
66+
- cache-unified
67+
68+
examples:
69+
- |
70+
#include <dt-bindings/interrupt-controller/irq.h>
71+
72+
cache-controller@2010000 {
73+
compatible = "andestech,ax45mp-cache", "cache";
74+
reg = <0x13400000 0x100000>;
75+
interrupts = <508 IRQ_TYPE_LEVEL_HIGH>;
76+
cache-line-size = <64>;
77+
cache-level = <2>;
78+
cache-sets = <1024>;
79+
cache-size = <262144>;
80+
cache-unified;
81+
};

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20340,6 +20340,13 @@ S: Supported
2034020340
T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
2034120341
F: drivers/staging/
2034220342

20343+
STANDALONE CACHE CONTROLLER DRIVERS
20344+
M: Conor Dooley <conor@kernel.org>
20345+
L: linux-riscv@lists.infradead.org
20346+
S: Maintained
20347+
T: git https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/
20348+
F: drivers/cache
20349+
2034320350
STARFIRE/DURALAN NETWORK DRIVER
2034420351
M: Ion Badulescu <ionut@badula.org>
2034520352
S: Odd Fixes

arch/riscv/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ config RISCV_DMA_NONCOHERENT
275275
select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
276276
select DMA_DIRECT_REMAP
277277

278+
config RISCV_NONSTANDARD_CACHE_OPS
279+
bool
280+
depends on RISCV_DMA_NONCOHERENT
281+
help
282+
This enables function pointer support for non-standard noncoherent
283+
systems to handle cache management.
284+
278285
config AS_HAS_INSN
279286
def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(comma) t0$(comma) zero)
280287

arch/riscv/Kconfig.errata

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
menu "CPU errata selection"
22

3+
config ERRATA_ANDES
4+
bool "Andes AX45MP errata"
5+
depends on RISCV_ALTERNATIVE
6+
help
7+
All Andes errata Kconfig depend on this Kconfig. Disabling
8+
this Kconfig will disable all Andes errata. Please say "Y"
9+
here if your platform uses Andes CPU cores.
10+
11+
Otherwise, please say "N" here to avoid unnecessary overhead.
12+
13+
config ERRATA_ANDES_CMO
14+
bool "Apply Andes cache management errata"
15+
depends on ERRATA_ANDES && MMU && ARCH_R9A07G043
16+
select RISCV_DMA_NONCOHERENT
17+
default y
18+
help
19+
This will apply the cache management errata to handle the
20+
non-standard handling on non-coherent operations on Andes cores.
21+
22+
If you don't know what to do here, say "Y".
23+
324
config ERRATA_SIFIVE
425
bool "SiFive errata"
526
depends on RISCV_ALTERNATIVE

arch/riscv/errata/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ ifdef CONFIG_RELOCATABLE
22
KBUILD_CFLAGS += -fno-pie
33
endif
44

5+
obj-$(CONFIG_ERRATA_ANDES) += andes/
56
obj-$(CONFIG_ERRATA_SIFIVE) += sifive/
67
obj-$(CONFIG_ERRATA_THEAD) += thead/

arch/riscv/errata/andes/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
obj-y += errata.o

arch/riscv/errata/andes/errata.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Erratas to be applied for Andes CPU cores
4+
*
5+
* Copyright (C) 2023 Renesas Electronics Corporation.
6+
*
7+
* Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
8+
*/
9+
10+
#include <linux/memory.h>
11+
#include <linux/module.h>
12+
13+
#include <asm/alternative.h>
14+
#include <asm/cacheflush.h>
15+
#include <asm/errata_list.h>
16+
#include <asm/patch.h>
17+
#include <asm/processor.h>
18+
#include <asm/sbi.h>
19+
#include <asm/vendorid_list.h>
20+
21+
#define ANDESTECH_AX45MP_MARCHID 0x8000000000008a45UL
22+
#define ANDESTECH_AX45MP_MIMPID 0x500UL
23+
#define ANDESTECH_SBI_EXT_ANDES 0x0900031E
24+
25+
#define ANDES_SBI_EXT_IOCP_SW_WORKAROUND 1
26+
27+
static long ax45mp_iocp_sw_workaround(void)
28+
{
29+
struct sbiret ret;
30+
31+
/*
32+
* ANDES_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP is missing and
33+
* cache is controllable only then CMO will be applied to the platform.
34+
*/
35+
ret = sbi_ecall(ANDESTECH_SBI_EXT_ANDES, ANDES_SBI_EXT_IOCP_SW_WORKAROUND,
36+
0, 0, 0, 0, 0, 0);
37+
38+
return ret.error ? 0 : ret.value;
39+
}
40+
41+
static bool errata_probe_iocp(unsigned int stage, unsigned long arch_id, unsigned long impid)
42+
{
43+
if (!IS_ENABLED(CONFIG_ERRATA_ANDES_CMO))
44+
return false;
45+
46+
if (arch_id != ANDESTECH_AX45MP_MARCHID || impid != ANDESTECH_AX45MP_MIMPID)
47+
return false;
48+
49+
if (!ax45mp_iocp_sw_workaround())
50+
return false;
51+
52+
/* Set this just to make core cbo code happy */
53+
riscv_cbom_block_size = 1;
54+
riscv_noncoherent_supported();
55+
56+
return true;
57+
}
58+
59+
void __init_or_module andes_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
60+
unsigned long archid, unsigned long impid,
61+
unsigned int stage)
62+
{
63+
errata_probe_iocp(stage, archid, impid);
64+
65+
/* we have nothing to patch here ATM so just return back */
66+
}

arch/riscv/include/asm/alternative.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct alt_entry {
4545
u32 patch_id; /* The patch ID (erratum ID or cpufeature ID) */
4646
};
4747

48+
void andes_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
49+
unsigned long archid, unsigned long impid,
50+
unsigned int stage);
4851
void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
4952
unsigned long archid, unsigned long impid,
5053
unsigned int stage);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2023 Renesas Electronics Corp.
4+
*/
5+
6+
#ifndef __ASM_DMA_NONCOHERENT_H
7+
#define __ASM_DMA_NONCOHERENT_H
8+
9+
#include <linux/dma-direct.h>
10+
11+
/*
12+
* struct riscv_nonstd_cache_ops - Structure for non-standard CMO function pointers
13+
*
14+
* @wback: Function pointer for cache writeback
15+
* @inv: Function pointer for invalidating cache
16+
* @wback_inv: Function pointer for flushing the cache (writeback + invalidating)
17+
*/
18+
struct riscv_nonstd_cache_ops {
19+
void (*wback)(phys_addr_t paddr, size_t size);
20+
void (*inv)(phys_addr_t paddr, size_t size);
21+
void (*wback_inv)(phys_addr_t paddr, size_t size);
22+
};
23+
24+
extern struct riscv_nonstd_cache_ops noncoherent_cache_ops;
25+
26+
void riscv_noncoherent_register_cache_ops(const struct riscv_nonstd_cache_ops *ops);
27+
28+
#endif /* __ASM_DMA_NONCOHERENT_H */

arch/riscv/include/asm/errata_list.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include <asm/hwcap.h>
1212
#include <asm/vendorid_list.h>
1313

14+
#ifdef CONFIG_ERRATA_ANDES
15+
#define ERRATA_ANDESTECH_NO_IOCP 0
16+
#define ERRATA_ANDESTECH_NUMBER 1
17+
#endif
18+
1419
#ifdef CONFIG_ERRATA_SIFIVE
1520
#define ERRATA_SIFIVE_CIP_453 0
1621
#define ERRATA_SIFIVE_CIP_1200 1

0 commit comments

Comments
 (0)