mbox series

[v5,00/16] firmware: scmi: add SCMI base protocol support

Message ID 20230926065750.734440-1-takahiro.akashi@linaro.org
Headers show
Series firmware: scmi: add SCMI base protocol support | expand

Message

AKASHI Takahiro Sept. 26, 2023, 6:57 a.m. UTC
This patch series allows users to access SCMI base protocol provided by
SCMI server (platform). It will also be utilized in separate patches
in the future to add sanity/validity checks for other protocols.
See SCMI specification document v3.2 beta[1] for more details about SCMI
base protocol.

What is currently not implemented is
- SCMI_BASE_NOTIFY_ERRORS command and notification callback mechanism

This feature won't be very useful in the current U-Boot environment.

[1] https://developer.arm.com/documentation/den0056/e/?lang=en


Test
====
The patch series was tested on the following platforms:
* sandbox
* qemu-arm64 with OPTEE as SCMI server


Prerequisite:
=============
* This patch series is based on v2023.10-rc4.


Patches:
========
Patch#1-#4: refactoring & bug fix
Patch#5-#7,#10-#11: Add SCMI base protocol driver
Patch#8-#9,#12-#13: Add SCMI base protocol device unit test
Patch#14-#16: Add scmi command


Change history:
===============
v5 (sep 26, 2023)
* fix a per_child_auto size (patch#1)
* fix an existing bug (not using a protocol's channel) (patch#2-#4)

v4 (Sep 12, 2023)
* shuffle the patch order (patch#5,6 prior to patch#7)
* several improvements/cleanup thanks to Etienne
  (Each commit message has more details.)

v3 (Sep 8, 2023)
* import patch#6 (protocol availability check) from my followup patch
* fix an issue on ST board (reported by Etienne) (patch#1)
* minor code improvements
* fix various typos pointed out by Etienne
* revise function descriptions/comments 
  (Each commit message has more details.)

v2 (Jul, 26, 2023)
* refactor devm_scmi_of_get_channel()/process_msg(), removing uses of ops
  (patch#1)
* use helper functions, removing uses of ops (patch#2,#9,#10)
* add more descriptions in scmi command doc (patch#11)
* remove 'scmi base' sub-command (patch#10,#12)

v1 (Jun, 28, 2023)
* initial release

AKASHI Takahiro (16):
  scmi: refactor the code to hide a channel from devices
  firmware: scmi: use a protocol's own channel if assigned
  firmware: scmi: support dummy channels for sandbox agent
  test: dm: add protocol-specific channel test
  firmware: scmi: implement SCMI base protocol
  firmware: scmi: move scmi_bind_protocols() backward
  firmware: scmi: framework for installing additional protocols
  firmware: scmi: fake base protocol commands on sandbox
  test: dm: simplify SCMI unit test on sandbox
  firmware: scmi: install base protocol to SCMI agent
  firmware: scmi: add a check against availability of protocols
  sandbox: remove SCMI base node definition from test.dts
  test: dm: add SCMI base protocol test
  cmd: add scmi command for SCMI firmware
  doc: cmd: add documentation for scmi
  test: dm: add scmi command test

 arch/sandbox/dts/test.dts                  |   5 +-
 arch/sandbox/include/asm/scmi_test.h       |  19 +-
 cmd/Kconfig                                |   9 +
 cmd/Makefile                               |   1 +
 cmd/scmi.c                                 | 337 +++++++++++
 configs/sandbox_defconfig                  |   1 +
 doc/usage/cmd/scmi.rst                     | 126 ++++
 drivers/clk/clk_scmi.c                     |  27 +-
 drivers/firmware/scmi/Makefile             |   1 +
 drivers/firmware/scmi/base.c               | 657 +++++++++++++++++++++
 drivers/firmware/scmi/mailbox_agent.c      |   5 +-
 drivers/firmware/scmi/optee_agent.c        |   5 +-
 drivers/firmware/scmi/sandbox-scmi_agent.c | 469 ++++++++++++++-
 drivers/firmware/scmi/scmi_agent-uclass.c  | 412 +++++++++++--
 drivers/firmware/scmi/smccc_agent.c        |   5 +-
 drivers/power/regulator/scmi_regulator.c   |  26 +-
 drivers/reset/reset-scmi.c                 |  19 +-
 include/dm/uclass-id.h                     |   1 +
 include/scmi_agent-uclass.h                |  89 ++-
 include/scmi_agent.h                       |  29 +-
 include/scmi_protocols.h                   | 351 +++++++++++
 test/dm/scmi.c                             | 248 ++++++--
 22 files changed, 2638 insertions(+), 204 deletions(-)
 create mode 100644 cmd/scmi.c
 create mode 100644 doc/usage/cmd/scmi.rst
 create mode 100644 drivers/firmware/scmi/base.c

Comments

Tom Rini Oct. 10, 2023, 2:19 p.m. UTC | #1
On Tue, Sep 26, 2023 at 03:57:34PM +0900, AKASHI Takahiro wrote:

> This patch series allows users to access SCMI base protocol provided by
> SCMI server (platform). It will also be utilized in separate patches
> in the future to add sanity/validity checks for other protocols.
> See SCMI specification document v3.2 beta[1] for more details about SCMI
> base protocol.
> 
> What is currently not implemented is
> - SCMI_BASE_NOTIFY_ERRORS command and notification callback mechanism
> 
> This feature won't be very useful in the current U-Boot environment.
> 
> [1] https://developer.arm.com/documentation/den0056/e/?lang=en
> 
> 
> Test
> ====
> The patch series was tested on the following platforms:
> * sandbox
> * qemu-arm64 with OPTEE as SCMI server

I have two problems.  The first is that for sandbox, this series is not
bisectable as a commits fail to build due to needing a definition in the
test before it's added:
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c: In function 'dm_test_scmi_clocks':
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c:117:21: warning: implicit declaration of function 'scmi_get_protocol' [-Wimplicit-function-declaration]
  117 |         clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
      |                     ^~~~~~~~~~~~~~~~~
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c:117:50: error: 'SCMI_PROTOCOL_ID_CLOCK' undeclared (first use in this function)
  117 |         clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
      |                                                  ^~~~~~~~~~~~~~~~~~~~~~
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c:117:50: note: each undeclared identifier is reported only once for each function it appears in
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c: In function 'dm_test_scmi_resets':
/home/uboot/work/u-boot/u-boot/test/dm/scmi.c:182:50: error: 'SCMI_PROTOCOL_ID_RESET_DOMAIN' undeclared (first use in this function)
  182 |         reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN);
      |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[4]: *** [/home/uboot/work/u-boot/u-boot/scripts/Makefile.build:256: test/dm/scmi.o] Error 1

Second, the series causes this failure:
========================================== FAILURES ===========================================
_______________________________ test_ut[ut_dm_dm_test_scmi_cmd] _______________________________
test/py/u_boot_spawn.py:195: in expect
    c = os.read(self.fd, 1024).decode(errors='replace')
E   OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:
test/py/tests/test_ut.py:497: in test_ut
    output = u_boot_console.run_command('ut ' + ut_subtest)
test/py/u_boot_console_base.py:266: in run_command
    m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
test/py/u_boot_spawn.py:204: in expect
    raise ValueError('U-Boot exited with %s' % info)
E   ValueError: U-Boot exited with signal 11 (SIGSEGV)
------------------------------------ Captured stdout call -------------------------------------
=> ut dm dm_test_scmi_cmd
Test: dm_test_scmi_cmd: scmi.c
SCMI device: scmi
  protocol version: 0x20000
  # of agents: 2
      0: platform
    > 1: OSPM
  # of protocols: 3
      Clock management
      Reset domain management
      Voltage domain management
  vendor: U-Boot
  sub vendor: Sandbox
  impl version: 0x1
Denying access to device:0 failed (-13)
Denying access to protocol:0x14 on device:0 failed (-13)
Reset failed (-13)
Test: dm_test_scmi_cmd: scmi.c (flat tree)
SCMI device: ?n
=================================== short test summary info ===================================
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_scmi_cmd] - ValueError: U-Boot exited...

Which I believe CI will also produce, once the issue with htmldocs is
fixed.  I can't bisect it exactly as the failure shows up once the new
test is added.
AKASHI Takahiro Oct. 11, 2023, 1:36 a.m. UTC | #2
Hi Tom,

On Tue, Oct 10, 2023 at 10:19:09AM -0400, Tom Rini wrote:
> On Tue, Sep 26, 2023 at 03:57:34PM +0900, AKASHI Takahiro wrote:
> 
> > This patch series allows users to access SCMI base protocol provided by
> > SCMI server (platform). It will also be utilized in separate patches
> > in the future to add sanity/validity checks for other protocols.
> > See SCMI specification document v3.2 beta[1] for more details about SCMI
> > base protocol.
> > 
> > What is currently not implemented is
> > - SCMI_BASE_NOTIFY_ERRORS command and notification callback mechanism
> > 
> > This feature won't be very useful in the current U-Boot environment.
> > 
> > [1] https://developer.arm.com/documentation/den0056/e/?lang=en
> > 
> > 
> > Test
> > ====
> > The patch series was tested on the following platforms:
> > * sandbox
> > * qemu-arm64 with OPTEE as SCMI server
> 
> I have two problems.  The first is that for sandbox, this series is not
> bisectable as a commits fail to build due to needing a definition in the
> test before it's added:
> /home/uboot/work/u-boot/u-boot/test/dm/scmi.c: In function 'dm_test_scmi_clocks':
> /home/uboot/work/u-boot/u-boot/test/dm/scmi.c:117:21: warning: implicit declaration of function 'scmi_get_protocol' [-Wimplicit-function-declaration]
>   117 |         clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
>       |                     ^~~~~~~~~~~~~~~~~

[snip]

Ah, I didn't notice this dependency.
I will fix it by re-ordering the commits.

> Second, the series causes this failure:
> ========================================== FAILURES ===========================================
> _______________________________ test_ut[ut_dm_dm_test_scmi_cmd] _______________________________
> test/py/u_boot_spawn.py:195: in expect
>     c = os.read(self.fd, 1024).decode(errors='replace')
> E   OSError: [Errno 5] Input/output error
> 
> During handling of the above exception, another exception occurred:
> test/py/tests/test_ut.py:497: in test_ut
>     output = u_boot_console.run_command('ut ' + ut_subtest)
> test/py/u_boot_console_base.py:266: in run_command
>     m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
> test/py/u_boot_spawn.py:204: in expect
>     raise ValueError('U-Boot exited with %s' % info)
> E   ValueError: U-Boot exited with signal 11 (SIGSEGV)
> ------------------------------------ Captured stdout call -------------------------------------
> => ut dm dm_test_scmi_cmd
> Test: dm_test_scmi_cmd: scmi.c
> SCMI device: scmi
>   protocol version: 0x20000
>   # of agents: 2
>       0: platform
>     > 1: OSPM
>   # of protocols: 3
>       Clock management
>       Reset domain management
>       Voltage domain management
>   vendor: U-Boot
>   sub vendor: Sandbox
>   impl version: 0x1
> Denying access to device:0 failed (-13)
> Denying access to protocol:0x14 on device:0 failed (-13)
> Reset failed (-13)
> Test: dm_test_scmi_cmd: scmi.c (flat tree)
> SCMI device: ?n
> =================================== short test summary info ===================================
> FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_scmi_cmd] - ValueError: U-Boot exited...

This seems to happen in the case of "flat tree", but
I cannot reproduce it in my local environment with
  $ pytest test/py/tests/test_ut.py -bd sandbox -k scmi_cmd ...

> Which I believe CI will also produce, once the issue with htmldocs is
> fixed.  I can't bisect it exactly as the failure shows up once the new
> test is added.

Anyhow, "scmi" command is more or less a debug tool for my development.
All the functionality provided by this patch set is tested at "function"
level with "ut dm scmi_base" and the command is *not* needed.
To avoid increasing the maintenance cost, I will drop the command
(patch #14-#16) in the next version.

Thanks,
-Takahiro Akashi


> 
> -- 
> Tom
Tom Rini Oct. 11, 2023, 2:11 a.m. UTC | #3
On Wed, Oct 11, 2023 at 10:36:11AM +0900, AKASHI Takahiro wrote:
> Hi Tom,
> 
> On Tue, Oct 10, 2023 at 10:19:09AM -0400, Tom Rini wrote:
> > On Tue, Sep 26, 2023 at 03:57:34PM +0900, AKASHI Takahiro wrote:
> > 
> > > This patch series allows users to access SCMI base protocol provided by
> > > SCMI server (platform). It will also be utilized in separate patches
> > > in the future to add sanity/validity checks for other protocols.
> > > See SCMI specification document v3.2 beta[1] for more details about SCMI
> > > base protocol.
> > > 
> > > What is currently not implemented is
> > > - SCMI_BASE_NOTIFY_ERRORS command and notification callback mechanism
> > > 
> > > This feature won't be very useful in the current U-Boot environment.
> > > 
> > > [1] https://developer.arm.com/documentation/den0056/e/?lang=en
> > > 
> > > 
> > > Test
> > > ====
> > > The patch series was tested on the following platforms:
> > > * sandbox
> > > * qemu-arm64 with OPTEE as SCMI server
> > 
> > I have two problems.  The first is that for sandbox, this series is not
> > bisectable as a commits fail to build due to needing a definition in the
> > test before it's added:
> > /home/uboot/work/u-boot/u-boot/test/dm/scmi.c: In function 'dm_test_scmi_clocks':
> > /home/uboot/work/u-boot/u-boot/test/dm/scmi.c:117:21: warning: implicit declaration of function 'scmi_get_protocol' [-Wimplicit-function-declaration]
> >   117 |         clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
> >       |                     ^~~~~~~~~~~~~~~~~
> 
> [snip]
> 
> Ah, I didn't notice this dependency.
> I will fix it by re-ordering the commits.
> 
> > Second, the series causes this failure:
> > ========================================== FAILURES ===========================================
> > _______________________________ test_ut[ut_dm_dm_test_scmi_cmd] _______________________________
> > test/py/u_boot_spawn.py:195: in expect
> >     c = os.read(self.fd, 1024).decode(errors='replace')
> > E   OSError: [Errno 5] Input/output error
> > 
> > During handling of the above exception, another exception occurred:
> > test/py/tests/test_ut.py:497: in test_ut
> >     output = u_boot_console.run_command('ut ' + ut_subtest)
> > test/py/u_boot_console_base.py:266: in run_command
> >     m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
> > test/py/u_boot_spawn.py:204: in expect
> >     raise ValueError('U-Boot exited with %s' % info)
> > E   ValueError: U-Boot exited with signal 11 (SIGSEGV)
> > ------------------------------------ Captured stdout call -------------------------------------
> > => ut dm dm_test_scmi_cmd
> > Test: dm_test_scmi_cmd: scmi.c
> > SCMI device: scmi
> >   protocol version: 0x20000
> >   # of agents: 2
> >       0: platform
> >     > 1: OSPM
> >   # of protocols: 3
> >       Clock management
> >       Reset domain management
> >       Voltage domain management
> >   vendor: U-Boot
> >   sub vendor: Sandbox
> >   impl version: 0x1
> > Denying access to device:0 failed (-13)
> > Denying access to protocol:0x14 on device:0 failed (-13)
> > Reset failed (-13)
> > Test: dm_test_scmi_cmd: scmi.c (flat tree)
> > SCMI device: ?n
> > =================================== short test summary info ===================================
> > FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_scmi_cmd] - ValueError: U-Boot exited...
> 
> This seems to happen in the case of "flat tree", but
> I cannot reproduce it in my local environment with
>   $ pytest test/py/tests/test_ut.py -bd sandbox -k scmi_cmd ...

How about if you run all of the tests?  That's how I usually do it, and
CI as well.

> > Which I believe CI will also produce, once the issue with htmldocs is
> > fixed.  I can't bisect it exactly as the failure shows up once the new
> > test is added.
> 
> Anyhow, "scmi" command is more or less a debug tool for my development.
> All the functionality provided by this patch set is tested at "function"
> level with "ut dm scmi_base" and the command is *not* needed.
> To avoid increasing the maintenance cost, I will drop the command
> (patch #14-#16) in the next version.

OK.  Please make sure CI runs and passes as well, thanks.