Page MenuHomeFreeBSD

riscv: Add driver for the cvitek restart controller
AcceptedPublic

Authored by bnovkov on Jan 20 2025, 6:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 21, 9:49 AM
Unknown Object (File)
Fri, Jun 20, 10:55 PM
Unknown Object (File)
Thu, Jun 19, 4:57 AM
Unknown Object (File)
Tue, Jun 17, 1:15 AM
Unknown Object (File)
Mon, Jun 16, 11:07 PM
Unknown Object (File)
Sun, Jun 15, 9:24 AM
Unknown Object (File)
Sat, Jun 7, 2:06 AM
Unknown Object (File)
Jun 3 2025, 9:25 PM

Details

Reviewers
br
Summary

This patch adds support for the cvitek restart controller.
This controller is present on the Milk-V riscv SoCs.

Test Plan

Tested on a Milk-V Duo S board.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

jrtc27 added inline comments.
sys/riscv/cvitek/cvitek_restart.c
118

Don't need to check this

sys/riscv/cvitek/cvitek_restart.c
43

sys headers first, then vm headers (if any), then machine headers, then dev

155

this should fit into line, no wrapping needed

Address @br 's and @jrtc27 's comments:

  • remove redundant property checks
  • style fixes
sys/riscv/cvitek/cvitek_restart.c
47

why this header is needed?

mhorne added inline comments.
sys/riscv/cvitek/cvitek_restart.c
77

You can't use a switch statement here; howto is a bitmask not an enum. You'll need to check each flag in an if case.

Off the top of my head it is possible to have RB_HALT and RB_POWEROFF both set (and possibly other cases).

sys/riscv/cvitek/cvitek_restart.c
77

Yes. RB_POWEROFF and RB_POWERCYCLE will never be set at the same time.
I'm not sure what SHUTDOWN does: if it just stops the CPU, but leaves power applied, then it should be set when RB_HALT is set, but RB_POWERCYLE or RB_POWEROFF are not. If it does remove power, it should only be when RB_POWEROFF is set (no need to test for RB_HALT, that will also be set, but it will always be set).

Properly handle howto bitmask.

bnovkov added inline comments.
sys/riscv/cvitek/cvitek_restart.c
47

Thanks for catching this, I've removed the stray header.

77

You can't use a switch statement here; howto is a bitmask not an enum. You'll need to check each flag in an if case.

Off the top of my head it is possible to have RB_HALT and RB_POWEROFF both set (and possibly other cases).

Oh, was not aware of that, thanks!
It should be handled properly now.

Yes. RB_POWEROFF and RB_POWERCYCLE will never be set at the same time.
I'm not sure what SHUTDOWN does: if it just stops the CPU, but leaves power applied, then it should be set when RB_HALT is set, but RB_POWERCYLE or RB_POWEROFF are not. If it does remove power, it should only be when RB_POWEROFF is set (no need to test for RB_HALT, that will also be set, but it will always be set).

The manual is a bit vague and uses both terms interchangeably, but it appears that it does remove power.

br added inline comments.
sys/riscv/cvitek/cvitek_restart.c
103

although this is correct, but to match style of other drivers, could we return success at the end of function unless some issue arise, i.e.

cvitek_restart_probe(device_t dev)
{

        if (!ofw_bus_status_okay(dev))
                return (ENXIO);

        if (!ofw_bus_is_compatible(dev, "cvitek,restart"))
                return (ENXIO);

         device_set_desc(dev, "Cvitek restart controller");

         return (BUS_PROBE_DEFAULT);
This revision is now accepted and ready to land.Jan 30 2025, 8:34 AM