[PATCH 0/5] Per-hart feature-configuration CSR support

Leo Yu-Chi Liang leo.liang at sifive.com
Tue Sep 29 22:42:05 PDT 2026


Some RISC-V implementations expose per-hart machine-mode CSRs that
select microarchitectural behaviour, such as branch prediction policy
or hardware prefetcher configuration. These CSRs must be set on every
hart, and on hart resume too, since a non-retentive suspend can reset
them to their power-on values.

This series adds a generic feature-configuration framework:

- Patch 1 adds a per-hart cache of pending CSR writes and the
  feature_config_init platform operation. A platform's hook caches
  writes instead of issuing them immediately, so a later override
  can replace an earlier value before anything is actually written.
  sbi_hart_feature_config_init() calls the hook once per hart on
  cold/warm boot, then (re)writes every cached CSR; on hart resume
  it skips the hook and just rewrites the already-cached values
  directly. A failure anywhere in this path is treated as fatal and
  hangs the hart, since an unconfigured hart may run with unsafe
  microarchitectural defaults.

- Patch 2 adds the vendor feature-configuration driver interface,
  which matches a hart's mvendorid against a registered driver and
  hands off to its init() callback. All vendor-specific policy lives
  in the driver, keeping libsbi.a self-contained.

- Patch 3 adds the SiFive vendor driver, which further matches a
  hart's marchid/mimpid against a per-core table of CSR values.
  Harts whose identity isn't in the table are left untouched.

- Patch 4 wires the generic feature-configuration probe up as
  the platform's default feature_config_init operation, gated by
  Kconfig, so any platform enabling the SiFive driver gets it for
  free.

- Patch 5 shows a platform override: the Eswin EIC7700 needs a
  different L1 hardware-prefetcher value than the vendor default, so
  it delegates to the generic probe first, then overrides the cached
  CSR with its own value before anything is written.

Leo Yu-Chi Liang (5):
  lib: sbi: Add per-hart feature-configuration platform operation
  lib: utils: Add vendor feature-configuration driver support
  lib: utils: Add SiFive feature-configuration driver
  platform: generic: Enable feature-configuration support
  platform: generic: eswin: Add feature_config_init op for L1_HWPF
    override

 include/sbi/sbi_hart_feature_config.h         |  16 ++
 include/sbi/sbi_platform.h                    |   7 +
 include/sbi_utils/feature/feature_config.h    |  71 ++++++++
 .../sbi_utils/feature/sifive_feature_config.h |  32 ++++
 lib/sbi/Kconfig                               |  23 +++
 lib/sbi/objects.mk                            |   1 +
 lib/sbi/sbi_hart_feature_config.c             | 169 ++++++++++++++++++
 lib/sbi/sbi_init.c                            |  21 +++
 lib/utils/Kconfig                             |   2 +
 lib/utils/feature/Kconfig                     |  22 +++
 lib/utils/feature/feature_config.c            |  36 ++++
 .../feature/feature_config_drivers.carray     |   3 +
 lib/utils/feature/objects.mk                  |  11 ++
 lib/utils/feature/sifive_feature_config.c     | 101 +++++++++++
 platform/generic/configs/defconfig            |   2 +
 platform/generic/eswin/eic770x.c              |  36 ++--
 platform/generic/include/eswin/eic770x.h      |   7 -
 platform/generic/include/platform_override.h  |   1 +
 platform/generic/platform.c                   |   7 +
 19 files changed, 547 insertions(+), 21 deletions(-)
 create mode 100644 include/sbi/sbi_hart_feature_config.h
 create mode 100644 include/sbi_utils/feature/feature_config.h
 create mode 100644 include/sbi_utils/feature/sifive_feature_config.h
 create mode 100644 lib/sbi/sbi_hart_feature_config.c
 create mode 100644 lib/utils/feature/Kconfig
 create mode 100644 lib/utils/feature/feature_config.c
 create mode 100644 lib/utils/feature/feature_config_drivers.carray
 create mode 100644 lib/utils/feature/objects.mk
 create mode 100644 lib/utils/feature/sifive_feature_config.c

-- 
2.43.7




More information about the opensbi mailing list