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)
Mon, Feb 24, 12:13 PM
Unknown Object (File)
Tue, Feb 18, 9:31 PM
Unknown Object (File)
Mon, Feb 17, 9:56 PM
Unknown Object (File)
Mon, Feb 17, 8:24 PM
Unknown Object (File)
Mon, Feb 17, 12:43 AM
Unknown Object (File)
Jan 27 2025, 6:21 PM
Unknown Object (File)
Jan 25 2025, 10:10 AM
Unknown Object (File)
Jan 20 2025, 9:15 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
48

why this header is needed?

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

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
78

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
48

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

78

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
102

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