Skip to content

CPU type: phytium: update phytium CPU type support#1948

Open
wangchenlu2236 wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
wangchenlu2236:chip-6.6.y
Open

CPU type: phytium: update phytium CPU type support#1948
wangchenlu2236 wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
wangchenlu2236:chip-6.6.y

Conversation

@wangchenlu2236

@wangchenlu2236 wangchenlu2236 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

These patches updates the support for phytium CPU type.

1.arm64: phytium: Add support of reading cpu type for Phytium Socs
2.arm64: phytium: Update the method to obtain CPU type for Phytium SoCs

Summary by Sourcery

Add centralized detection and initialization of Phytium SoC CPU types on arm64 at boot.

New Features:

  • Introduce a Phytium-specific CPU/SoC type enumeration and detection helpers for arm64.
  • Expose a global Phytium SoC type variable for use by other subsystems.
  • Initialize Phytium SoC type early in arm64 boot when building for CONFIG_ARCH_PHYTIUM.

This patch provides three methods for reading cpu type for
Phytium Socs, with priority from high to low as follows:
- read socid by arm-smccc
- read system register of SYS_AIDR_EL1
- read system register of MPIDR_EL1

Mainline: NA
Signed-off-by: Feng Jun <fengjun@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Chenlu <wangchenlu2236@phytium.com.cn>
This patch adjusts the machanism of obtaining the CPU type for
Phytium Socs. It can directly return current CPU type when
external interface calls the function.

Mainline: Open-Source
Signed-off-by: Feng Jun <fengjun@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Chenlu <wangchenlu2236@phytium.com.cn>
@deepin-ci-robot deepin-ci-robot requested a review from winnscode July 3, 2026 16:10
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign opsiff for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a Phytium SoC type detection/initialization framework on arm64 and wires it into early boot so other code can query a global Phytium SoC type symbol.

Sequence diagram for Phytium SoC type initialization during arm64 boot

sequenceDiagram
    participant Kernel as setup_arch
    participant Phytium as phyt_soc_type_init
    participant Detector as phyt_read_soc_type
    participant SMCCC as arm_smccc_smc

    Kernel->>Phytium: phyt_soc_type_init()
    Phytium->>Detector: phyt_read_soc_type()
    Detector->>Detector: is_phytium_soc()
    alt [is_phytium_soc]
        Detector->>SMCCC: arm_smccc_smc(FUNC_ID_GET_CPU_VERSION,...)
        alt [res.a0 == SMCCC_SUCCESS]
            Detector->>Detector: do_smccc_res(res)
        else [res.a0 == SMCCC_FAILURE]
            Detector->>Detector: do_read_sysreg()
        else [other]
            Detector->>Detector: do_read_mpidr()
        end
    else [not Phytium]
        Detector-->>Detector: return UNKNOWN_SOC
    end
    Detector-->>Phytium: enum phyt_soc_type
    Phytium->>Phytium: set phyt_soc_type_t
    Phytium-->>Kernel: return
Loading

Flow diagram for Phytium SoC type detection strategy

flowchart TD
    A[Start phyt_read_soc_type] --> B[is_phytium_soc]
    B -->|false| Z[UNKNOWN_SOC]
    B -->|true| C["arm_smccc_smc(FUNC_ID_GET_CPU_VERSION,...)"]
    C --> D[Check res.a0]
    D -->|SMCCC_SUCCESS| E[do_smccc_res]
    E --> F{ctype != UNKNOWN_SOC}
    F -->|true| Y[Detected SoC]
    F -->|false| G[do_read_sysreg]
    D -->|SMCCC_FAILURE| G
    G --> H{ctype != UNKNOWN_SOC}
    H -->|true| Y
    H -->|false| I[do_read_mpidr]
    D -->|other| I
    I --> Y
    Y --> Z[Return enum phyt_soc_type]
Loading

File-Level Changes

Change Details Files
Introduce a Phytium SoC type detection helper API and global state for arm64 Phytium platforms.
  • Add new asm header defining enum of Phytium SoC types and public phyt_soc_type_t variable
  • Implement layered SoC detection using SMCCC call, system register read, and CPU part number fallback
  • Provide inline helpers to initialize and query specific Phytium SoC types
arch/arm64/include/asm/phytium_cputype.h
Integrate Phytium SoC type initialization into the arm64 boot sequence and export global SoC type.
  • Conditionally include new Phytium CPU type header when CONFIG_ARCH_PHYTIUM is enabled
  • Define and export global phyt_soc_type_t variable for use by other subsystems
  • Invoke Phytium SoC type initialization during setup_arch for Phytium builds
arch/arm64/kernel/setup.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

Hi @wangchenlu2236. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In phyt_soc_type_init(), the large switch just reassigns the same enum value and can be simplified to a single phyt_soc_type_t = ctype;, which reduces boilerplate and makes future enum additions simpler.
  • The multiple is_* helpers (e.g. is_pd2408, is_ps23064, etc.) all duplicate the same pattern of equality checks; consider either a single helper that compares against an argument or using direct comparisons at call sites to avoid proliferating near-identical functions.
  • SMCCC_FAILURE is defined as -1 while arm_smccc_res fields are unsigned long, so relying on equality against -1 may be brittle; using explicit SMCCC return codes or checking ranges/bit patterns instead would make the error handling more robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In phyt_soc_type_init(), the large switch just reassigns the same enum value and can be simplified to a single `phyt_soc_type_t = ctype;`, which reduces boilerplate and makes future enum additions simpler.
- The multiple `is_*` helpers (e.g. is_pd2408, is_ps23064, etc.) all duplicate the same pattern of equality checks; consider either a single helper that compares against an argument or using direct comparisons at call sites to avoid proliferating near-identical functions.
- SMCCC_FAILURE is defined as -1 while arm_smccc_res fields are unsigned long, so relying on equality against -1 may be brittle; using explicit SMCCC return codes or checking ranges/bit patterns instead would make the error handling more robust.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants