Skip to content

lbc: phytium: Bugfix issue with computing device capacity - #2243

Open
wangchenlu2236 wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
wangchenlu2236:lbc-6.6.y
Open

wangchenlu2236 wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
wangchenlu2236:lbc-6.6.y

Conversation

@wangchenlu2236

@wangchenlu2236 wangchenlu2236 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

Mainline: NA

Summary by Sourcery

Fix Phytium local bus device capacity detection and improve probe diagnostics.

Bug Fixes:

  • Correct device capacity calculation by supporting the full set of valid local bus device sizes and deriving the device address from the platform resource.

Enhancements:

  • Improve probing error messages to identify whether device tree or ACPI setup failed.
  • Add diagnostic reporting for unsupported device sizes.

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

Mainline: NA
Signed-off-by: Wang Hanmo <wanghanmo2242@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Chenlu <wangchenlu2236@phytium.com.cn>
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Fixes Phytium local-bus device-capacity encoding by using explicit controller size codes and initializes the device base address from the platform resource; also adds clearer probe diagnostics.

Flow diagram for Phytium local-bus device setup

flowchart TD
    A[Platform resource discovered] --> B[LBC_DEVICE_ADDR = res.start]
    B --> C[phytium_lbc_probe]
    C --> D[phytium_lbc_calc_device_size]
    D --> E{Supported device size?}
    E -->|16K to 256M| F[Return controller size code 0x0 to 0xe]
    E -->|Unsupported| G[Return -EINVAL and log error]
    F --> H[Configure local-bus device capacity]
Loading

File-Level Changes

Change Details Files
Correct device-size encoding to accept only hardware-supported capacities and derive the local-bus address from the platform resource.
  • Map each supported size from 16 KiB through 256 MiB to the controller’s explicit encoding values.
  • Reject unsupported sizes with -EINVAL and log an error.
  • Store the mapped resource start address during probe instead of using a fixed address.
drivers/mtd/maps/phytium_lbc.c
Improve probe failure diagnostics by identifying the firmware description source.
  • Differentiate device-tree probing failures from ACPI probing failures in error messages.
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

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

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="drivers/mtd/maps/phytium_lbc.c" line_range="44" />
<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>
**Flash maps use wrong base**

When two controllers with different resource bases probe concurrently and one overwrites the global before the other's setup, `phytium_lbc_of_setup()` and `phytium_lbc_acpi_setup()` copy the wrong `LBC_DEVICE_ADDR` into `map->phys` and program the wrong CSAR, so the first MTD device maps the other flash; users of that device can read or modify the other flash.

Store each resource base in its controller's `lbc` instance and have both setup paths use that per-controller value.

Also at `drivers/mtd/maps/phytium_lbc.c:504`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

#define LBC_FTIM2_CS_GPCM(n) (0x1a4+0xc*n)

#define LBC_DEVICE_ADDR 0x10000000
static uint64_t LBC_DEVICE_ADDR;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Flash maps use wrong base

When two controllers with different resource bases probe concurrently and one overwrites the global before the other's setup, phytium_lbc_of_setup() and phytium_lbc_acpi_setup() copy the wrong LBC_DEVICE_ADDR into map->phys and program the wrong CSAR, so the first MTD device maps the other flash; users of that device can read or modify the other flash.

Store each resource base in its controller's lbc instance and have both setup paths use that per-controller value.

Also at drivers/mtd/maps/phytium_lbc.c:504.

Prompt for AI agents
In `drivers/mtd/maps/phytium_lbc.c` at line 44:

**Flash maps use wrong base**

When two controllers with different resource bases probe concurrently and one overwrites the global before the other's setup, `phytium_lbc_of_setup()` and `phytium_lbc_acpi_setup()` copy the wrong `LBC_DEVICE_ADDR` into `map->phys` and program the wrong CSAR, so the first MTD device maps the other flash; users of that device can read or modify the other flash.

Store each resource base in its controller's `lbc` instance and have both setup paths use that per-controller value.

Also at `drivers/mtd/maps/phytium_lbc.c:504`.

Copilot AI 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.

🟡 Changes recommended

The shared LBC_DEVICE_ADDR can be overwritten by concurrent controller probes, causing an instance to program the wrong physical base and break device access; both setup paths need a per-instance base.

1 open issue
What changed in this PR

This PR corrects device-capacity encoding in the Phytium local bus MTD driver and improves probe diagnostics.

Changes:

  • Map supported power-of-two sizes from 16 KiB through 256 MiB to hardware encodings.
  • Derive the device base address from the platform memory resource.
  • Distinguish device-tree and ACPI probe failures and report unsupported sizes.
File Description
drivers/​mtd/​maps/​phytium_lbc.c Updates capacity encoding, resource-based addressing, and probe error messages.

Review effort: Balanced

return -ENODEV;
}

LBC_DEVICE_ADDR = res->start;
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