Skip to content

irq: phytium: update phytium irq controller driver support to 6.6.0.4#1683

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

irq: phytium: update phytium irq controller driver support to 6.6.0.4#1683
wangchenlu2236 wants to merge 3 commits into
deepin-community:linux-6.6.yfrom
wangchenlu2236:irq-6.6.y

Conversation

@wangchenlu2236
Copy link
Copy Markdown

@wangchenlu2236 wangchenlu2236 commented May 12, 2026

This patches updates the support for phytium irq controller driver.

1.iommu/arm-smmu: Add SMMU workaround for Phytium Ps17064
2.arm64: Phytium: Slove the error on aarch32 compiler
3.arm64: Phytium: Fix incorrect MSI compose logic on Phytium PS17064 SoCs

Summary by Sourcery

Update IOMMU and IRQ handling for Phytium PS17064 SoCs and add a platform-specific SMMU workaround.

Bug Fixes:

  • Force IOMMU default domain to identity on Phytium PS17064 to avoid issues introduced by the SMMU workaround.
  • Adjust SMMU device probing on Phytium PS17064 to correctly handle firmware-provided stream IDs.
  • Bypass generic MSI message composition on Phytium PS17064 to fix incorrect MSI programming for GICv3 ITS interrupts.

Enhancements:

  • Integrate Phytium PS17064-specific CPU model detection into IOMMU and SMMU paths under CONFIG_ARCH_PHYTIUM.

There are two hacks needed for IOMMU enablement on Phytium
Ps17064 SoC. One is the MSI hack, the other is the SMMU hack.

When using this enablement, we assumes that users would set
CONIFIG_IOMMU_DEFAULT_PASSTHROUGH=y or pass 'iommu.passthrough=on'
or 'iommu.pt' as the kernel command-line parameters. Therefore,
we also force default iommu domain type to IOMMU_DOMAIN_IDENTITY
on Ps17064 to avoid unnecessary troubles.

Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Chen Baozi <chenbaozi@phytium.com.cn>
Signed-off-by:Wang Chenlu <wangchenlu2236@phytium.com.cn>
When compiling with the aarch32 compiler, the arm64-specific macros were
not defined. Add restriction to bring these macros only into effect
on arm64 architecture.

Mainline: NA
Signed-off-by: Li Mingzhe <limingzhe1839@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by:Wang Chenlu <wangchenlu2236@phytium.com.cn>
Fix the logic in its_irq_compose_msi() where CONFIG_ARCH_PHYTIUM
filtering accidentally changed the original behavior.
Now iommu_dma_compose_msi_msg() is skipped only on PS17064 SoCs,
and executed on all other platforms as intended.

Mainline: NA
Signed-off-by: Li Mingzhe <limingzhe1839@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by:Wang Chenlu <wangchenlu2236@phytium.com.cn>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 12, 2026

Reviewer's Guide

Updates IOMMU and GICv3 ITS handling for Phytium PS17064 SoCs by adding an SMMU firmware-ID workaround, forcing identity IOMMU domains, and bypassing generic MSI message composition on that CPU model.

Sequence diagram for updated MSI composition on Phytium PS17064

sequenceDiagram
    actor Phytium_PS17064
    participant GICv3_ITS as its_irq_compose_msi_msg
    participant IOMMU_DMA as iommu_dma_compose_msi_msg

    Phytium_PS17064 ->> GICv3_ITS: its_irq_compose_msi_msg(irq_data, msg)
    GICv3_ITS ->> GICv3_ITS: its_get_event_id(irq_data)
    GICv3_ITS ->> GICv3_ITS: set msg.address_lo, msg.address_hi, msg.data
    alt [CPU is Phytium PS17064]
        GICv3_ITS -->> Phytium_PS17064: return
    else [other CPUs]
        GICv3_ITS ->> IOMMU_DMA: iommu_dma_compose_msi_msg(msi_desc, msg)
        IOMMU_DMA -->> GICv3_ITS: return
        GICv3_ITS -->> Phytium_PS17064: return
    end
Loading

File-Level Changes

Change Details Files
Force IOMMU default domain to identity on Phytium PS17064 SoCs and handle cmdline override consistently.
  • Include <asm/cputype.h> when building for CONFIG_ARCH_PHYTIUM to access MIDR-based CPU model detection.
  • In iommu_subsys_init, detect MIDR_PHYTIUM_PS17064 and force default IOMMU passthrough to true to select IOMMU_DOMAIN_IDENTITY.
  • In iommu_set_def_domain_type(), detect MIDR_PHYTIUM_PS17064 and override any user-specified default with IOMMU_DOMAIN_IDENTITY, also forcing default passthrough.
drivers/iommu/iommu.c
Add an SMMU ID remapping workaround for Phytium PS17064 in the ARM SMMU driver.
  • Include <asm/cputype.h> in the ARM SMMU header and define FWID_READ() under CONFIG_ARCH_PHYTIUM to translate SMMU IDs for this SoC.
  • In arm_smmu_probe_device(), when running on MIDR_PHYTIUM_PS17064, iterate firmware IDs in the IOMMU fwspec and re-add translated IDs using iommu_fwspec_add_ids().
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/arm/arm-smmu/arm-smmu.h
Adjust GICv3 ITS MSI message composition for Phytium PS17064 SoCs to avoid incorrect IOMMU DMA composition.
  • In its_irq_compose_msi_msg(), after programming the GICv3 ITS MSI address and data, early-return on MIDR_PHYTIUM_PS17064 instead of calling iommu_dma_compose_msi_msg().
drivers/irqchip/irq-gic-v3-its.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.

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 left some high level feedback:

  • The Phytium PS17064 MIDR check is open‑coded in multiple places; consider introducing a small helper (e.g. cpu_is_ps17064()) to centralize the model detection logic and reduce duplication.
  • In arm_smmu_probe_device(), you append additional FWIDs to fwspec while later iterating over fwspec->num_ids; double‑check whether this can cause the ID list to grow unexpectedly or be processed twice and, if so, consider using a separate buffer or normalizing the IDs before probing.
  • The new drivers/irqchip/irq-gic-v3-its.c.orig file appears to be an editor backup and should be removed from the commit.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Phytium PS17064 MIDR check is open‑coded in multiple places; consider introducing a small helper (e.g. `cpu_is_ps17064()`) to centralize the model detection logic and reduce duplication.
- In `arm_smmu_probe_device()`, you append additional FWIDs to `fwspec` while later iterating over `fwspec->num_ids`; double‑check whether this can cause the ID list to grow unexpectedly or be processed twice and, if so, consider using a separate buffer or normalizing the IDs before probing.
- The new `drivers/irqchip/irq-gic-v3-its.c.orig` file appears to be an editor backup and should be removed from the commit.

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.

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

This PR updates kernel IRQ/MSI and IOMMU/SMMU handling for Phytium PS17064 SoCs, aiming to apply platform-specific workarounds and avoid incorrect MSI programming and IOMMU issues on that platform.

Changes:

  • Bypass iommu_dma_compose_msi_msg() on PS17064 in the GICv3 ITS MSI compose path.
  • Force the IOMMU default domain to identity/passthrough on PS17064 (including the iommu.passthrough= early param path).
  • Add a PS17064-specific SMMU probing workaround that rewrites/derives firmware IDs for stream IDs.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
drivers/irqchip/irq-gic-v3-its.c.orig Adds a full duplicate copy of the ITS driver as a .orig file.
drivers/irqchip/irq-gic-v3-its.c Skips iommu_dma_compose_msi_msg() on PS17064 when composing MSI messages.
drivers/iommu/iommu.c Forces default IOMMU domain to identity/passthrough on PS17064.
drivers/iommu/arm/arm-smmu/arm-smmu.h Adds Phytium-specific helper macro and includes for CPU model detection.
drivers/iommu/arm/arm-smmu/arm-smmu.c Adds PS17064 workaround in SMMU device probing by adding derived firmware IDs.

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

Comment on lines +1382 to +1386
for (i = 0; i < num; i++) {
u32 fwid = FWID_READ(fwspec->ids[i]);

iommu_fwspec_add_ids(dev, &fwid, 1);
}
Comment on lines +1 to +155
* be 64kB aligned (one bit per LPI, plus 8192 bits for SPI/PPI/SGI).
*/
#define LPI_NRBITS lpi_id_bits
#define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K)
#define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K)

#define LPI_PROP_DEFAULT_PRIO GICD_INT_DEF_PRI

/*
* Collection structure - just an ID, and a redistributor address to
* ping. We use one per CPU as a bag of interrupts assigned to this
* CPU.
*/
struct its_collection {
u64 target_address;
u16 col_id;
};

/*
* The ITS_BASER structure - contains memory information, cached
* value of BASER register configuration and ITS page size.
*/
struct its_baser {
void *base;
u64 val;
u32 order;
u32 psz;
};

struct its_device;

/*
* The ITS structure - contains most of the infrastructure, with the
* top-level MSI domain, the command queue, the collections, and the
* list of devices writing to it.
*
* dev_alloc_lock has to be taken for device allocations, while the
* spinlock must be taken to parse data structures such as the device
* list.
*/
struct its_node {
raw_spinlock_t lock;
struct mutex dev_alloc_lock;
struct list_head entry;
void __iomem *base;
void __iomem *sgir_base;
phys_addr_t phys_base;
struct its_cmd_block *cmd_base;
struct its_cmd_block *cmd_write;
struct its_baser tables[GITS_BASER_NR_REGS];
struct its_collection *collections;
struct fwnode_handle *fwnode_handle;
u64 (*get_msi_base)(struct its_device *its_dev);
u64 typer;
u64 cbaser_save;
u32 ctlr_save;
u32 mpidr;
struct list_head its_device_list;
u64 flags;
unsigned long list_nr;
int numa_node;
unsigned int msi_domain_flags;
u32 pre_its_base; /* for Socionext Synquacer */
int vlpi_redist_offset;
};

#define is_v4(its) (!!((its)->typer & GITS_TYPER_VLPIS))
#define is_v4_1(its) (!!((its)->typer & GITS_TYPER_VMAPP))
#define device_ids(its) (FIELD_GET(GITS_TYPER_DEVBITS, (its)->typer) + 1)

#define ITS_ITT_ALIGN SZ_256

/* The maximum number of VPEID bits supported by VLPI commands */
#define ITS_MAX_VPEID_BITS \
({ \
int nvpeid = 16; \
if (gic_rdists->has_rvpeid && \
gic_rdists->gicd_typer2 & GICD_TYPER2_VIL) \
nvpeid = 1 + (gic_rdists->gicd_typer2 & \
GICD_TYPER2_VID); \
\
nvpeid; \
})
#define ITS_MAX_VPEID (1 << (ITS_MAX_VPEID_BITS))

/* Convert page order to size in bytes */
#define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o))

struct event_lpi_map {
unsigned long *lpi_map;
u16 *col_map;
irq_hw_number_t lpi_base;
int nr_lpis;
raw_spinlock_t vlpi_lock;
struct its_vm *vm;
struct its_vlpi_map *vlpi_maps;
int nr_vlpis;
};

/*
Comment thread drivers/iommu/iommu.c
* introduced by the SMMU workaround.
*/
if ((read_cpuid_id() & MIDR_CPU_MODEL_MASK) == MIDR_PHYTIUM_PS17064)
iommu_set_default_passthrough(true);
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