Skip to content

lbc: phytium: Bugfix issue with computing device#1667

Open
mamingrui123 wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
mamingrui123:LBC-6.6.y
Open

lbc: phytium: Bugfix issue with computing device#1667
mamingrui123 wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
mamingrui123:LBC-6.6.y

Conversation

@mamingrui123
Copy link
Copy Markdown

@mamingrui123 mamingrui123 commented May 7, 2026

This patch fixes the issue of computing device capacity, and adds some debug printing code for debugging.

Summary by Sourcery

Fix Phytium local bus controller device capacity handling and improve diagnostics.

Bug Fixes:

  • Correct device size encoding logic in the Phytium LBC driver to handle only supported discrete capacities and report invalid sizes.
  • Use the probed resource start address as the device base address instead of a hard-coded constant.

Enhancements:

  • Clarify error messages for failed device-tree and ACPI probing in the Phytium LBC driver.
  • Log an explicit error when an unsupported or invalid device size is configured.

This patch fixes the issue of computing device capacity,
and adds some debug printing code for debugging.

Signed-off-by: Ma Mingrui <mamingrui1243@phytium.com.cn>
Signed-off-by: Wang Hanmo <wanghanmo2242@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's Guide

Fixes Phytium localbus controller device capacity computation and improves diagnostics, including changing the device base address handling and refining error messages for DT/ACPI probing.

Flow diagram for updated phytium_lbc_calc_device_size logic

flowchart TD
    A[phytium_lbc_calc_device_size device_size] --> B{device_size}

    B --> C[SZ_16K]
    B --> D[SZ_32K]
    B --> E[SZ_64K]
    B --> F[SZ_128K]
    B --> G[SZ_256K]
    B --> H[SZ_512K]
    B --> I[SZ_1M]
    B --> J[SZ_2M]
    B --> K[SZ_4M]
    B --> L[SZ_8M]
    B --> M[SZ_16M]
    B --> N[SZ_32M]
    B --> O[SZ_64M]
    B --> P[SZ_128M]
    B --> Q[SZ_256M]
    B --> R[Other]

    C --> C1[Set value = 0x0]
    D --> D1[Set value = 0x1]
    E --> E1[Set value = 0x2]
    F --> F1[Set value = 0x3]
    G --> G1[Set value = 0x4]
    H --> H1[Set value = 0x5]
    I --> I1[Set value = 0x6]
    J --> J1[Set value = 0x7]
    K --> K1[Set value = 0x8]
    L --> L1[Set value = 0x9]
    M --> M1[Set value = 0xa]
    N --> N1[Set value = 0xb]
    O --> O1[Set value = 0xc]
    P --> P1[Set value = 0xd]
    Q --> Q1[Set value = 0xe]

    R --> R1[Set value = -EINVAL]
    R1 --> R2[pr_err device size is invalid or not supported]

    C1 --> Z[return value]
    D1 --> Z
    E1 --> Z
    F1 --> Z
    G1 --> Z
    H1 --> Z
    I1 --> Z
    J1 --> Z
    K1 --> Z
    L1 --> Z
    M1 --> Z
    N1 --> Z
    O1 --> Z
    P1 --> Z
    Q1 --> Z
    R2 --> Z
Loading

File-Level Changes

Change Details Files
Correct device size encoding logic used when configuring the LBC-attached memory device.
  • Replace arithmetic-based device size calculation with an explicit switch over supported SZ_* constants (16K–256M) mapping to encoded size values 0x0–0xe.
  • Return -EINVAL and emit a pr_err message when an unsupported or invalid device size is provided instead of relying on modulo arithmetic.
  • Remove now-unnecessary temporary 'ret' variable and simplify return path of the size calculation helper.
drivers/mtd/maps/phytium_lbc.c
Make the localbus device base address configurable at runtime and initialize it from the platform resource.
  • Change LBC_DEVICE_ADDR from a fixed macro constant to a static uint64_t variable so that it can reflect the hardware resource address.
  • Set LBC_DEVICE_ADDR to res->start during phytium_lbc_probe() after successfully acquiring the memory resource, tying it to the actual mapped device address.
drivers/mtd/maps/phytium_lbc.c
Improve debugging and error reporting around device probing.
  • Clarify error messages for DT-based setup from generic 'probing failed' to 'device tree probing failed' to better indicate the failure source.
  • Clarify error messages for ACPI-based setup from generic 'probing failed' to 'acpi probing failed' to distinguish ACPI failures.
drivers/mtd/maps/phytium_lbc.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 deepin-ci-robot requested review from BLumia and Wenlp May 7, 2026 10:25
@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 avenger-285714 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

@deepin-ci-robot
Copy link
Copy Markdown

Hi @mamingrui123. Thanks for your PR. 😃

@deepin-ci-robot
Copy link
Copy Markdown

Hi @mamingrui123. 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.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In phytium_lbc_calc_device_size(), assigning -EINVAL to a u32 and returning it through an int will result in a large positive value rather than a proper error code; consider returning -EINVAL directly from the default case and keeping the encoded size in a separate signed/unsigned variable to avoid this mismatch.
  • Changing LBC_DEVICE_ADDR from a fixed macro to a static global set from res->start may cause issues if multiple controllers are present; it would be safer to store the base address in the phytium_lbc instance (or another per-device structure) instead of a single global.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `phytium_lbc_calc_device_size()`, assigning `-EINVAL` to a `u32` and returning it through an `int` will result in a large positive value rather than a proper error code; consider returning `-EINVAL` directly from the default case and keeping the encoded size in a separate signed/unsigned variable to avoid this mismatch.
- Changing `LBC_DEVICE_ADDR` from a fixed macro to a static global set from `res->start` may cause issues if multiple controllers are present; it would be safer to store the base address in the `phytium_lbc` instance (or another per-device structure) instead of a single global.

## Individual Comments

### Comment 1
<location path="drivers/mtd/maps/phytium_lbc.c" line_range="44-47" />
<code_context>
 #define LBC_FTIM2_CS_GPCM(n)		(0x1a4+0xc*n)

-#define LBC_DEVICE_ADDR			0x10000000
+static uint64_t LBC_DEVICE_ADDR;
 #define PHYTIUM_MAX_SRAM_BLOCK		8

</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid using a single global LBC_DEVICE_ADDR for what may be per-device state.

This makes the base address effectively shared by all driver instances: any later probe will overwrite the value for earlier ones, and multi-controller or multi-platform-device setups will misbehave. Please store this per-instance (e.g. in `struct phytium_lbc` or by using `map->phys` / the resource) instead of a file-scope static.
</issue_to_address>

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.

Comment on lines +44 to 47
static uint64_t LBC_DEVICE_ADDR;
#define PHYTIUM_MAX_SRAM_BLOCK 8

#define PHYTIUM_LOCALBUS_DRIVER_VERSION "1.0.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Avoid using a single global LBC_DEVICE_ADDR for what may be per-device state.

This makes the base address effectively shared by all driver instances: any later probe will overwrite the value for earlier ones, and multi-controller or multi-platform-device setups will misbehave. Please store this per-instance (e.g. in struct phytium_lbc or by using map->phys / the resource) instead of a file-scope static.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Phytium Localbus Controller (LBC) MTD mapping issues by tightening device-size encoding and using the probed MMIO resource base for device addressing, with improved probe diagnostics.

Changes:

  • Replace linear “multiple of 16K” size encoding with a discrete supported-size mapping and emit an error for unsupported sizes.
  • Improve probe failure messages to distinguish device-tree vs ACPI probing failures.
  • Use the probed memory resource start address as the device base address (instead of a hard-coded constant).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 107 to 163
static int phytium_lbc_calc_device_size(int device_size)
{
int ret = 0;
u32 value;

if (device_size%SZ_16K == 0) {
value = device_size/SZ_16K - 1;
} else {
ret = -EINVAL;
return ret;
switch (device_size) {
case SZ_16K:
value = 0x0;
break;
case SZ_32K:
value = 0x1;
break;
case SZ_64K:
value = 0x2;
break;
case SZ_128K:
value = 0x3;
break;
case SZ_256K:
value = 0x4;
break;
case SZ_512K:
value = 0x5;
break;
case SZ_1M:
value = 0x6;
break;
case SZ_2M:
value = 0x7;
break;
case SZ_4M:
value = 0x8;
break;
case SZ_8M:
value = 0x9;
break;
case SZ_16M:
value = 0xa;
break;
case SZ_32M:
value = 0xb;
break;
case SZ_64M:
value = 0xc;
break;
case SZ_128M:
value = 0xd;
break;
case SZ_256M:
value = 0xe;
break;
default:
value = -EINVAL;
pr_err("lbc: device size is invalid or not supported.\n");
break;
}

return value;
Comment on lines 41 to 46
#define LBC_FTIM1_CS_GPCM(n) (0x1a0+0xc*n)
#define LBC_FTIM2_CS_GPCM(n) (0x1a4+0xc*n)

#define LBC_DEVICE_ADDR 0x10000000
static uint64_t LBC_DEVICE_ADDR;
#define PHYTIUM_MAX_SRAM_BLOCK 8

Comment on lines 501 to 502
}
}
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.

3 participants