Skip to content

Conversation

@AaronDot
Copy link
Contributor

@AaronDot AaronDot commented Feb 15, 2025

Introduction to the patch set:

  1. Some patches backported from upstream
  2. Added Loongson-3C600 multi-chip support
  3. Added support for LoongArch AVEC interrupt controller
  4. Added Loongson-3 CPU hwmon driver support
  5. Fixed Loongson-7A2000 related issues
  6. Fix i2c-hid touchpad anomaly
  7. Fix the latest version of AST driver anomaly

Summary by Sourcery

Add support for the LoongArch AVEC interrupt controller, Loongson-3C600 multi-chip, and Loongson-3 CPU hwmon driver. Backport patches from upstream. Fix issues related to Loongson-7A2000, i2c-hid touchpad, and AST driver.

New Features:

  • Added support for LoongArch AVEC interrupt controller

Bug Fixes:

  • Fixed Loongson-7A2000 related issues
  • Fixed i2c-hid touchpad anomaly
  • Fixed the latest version of AST driver anomaly

Enhancements:

  • Backported some patches from upstream
  • Added multi-chip support for Loongson-3C600
  • Added Loongson-3 CPU hwmon driver support

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 15, 2025

Reviewer's Guide by Sourcery

This pull request includes several backports from upstream, adds Loongson-3C600 multi-chip support, adds support for LoongArch AVEC interrupt controller, adds Loongson-3 CPU hwmon driver support, fixes Loongson-7A2000 related issues, fixes i2c-hid touchpad anomaly, and fixes the latest version of AST driver anomaly. The changes span across multiple files and include improvements to GPIO, memory management, interrupt handling, PCI quirks, and driver support.

Updated class diagram for irq-loongson-eiointc.c

classDiagram
  class eiointc_priv {
    +node: int
    +vec_count: int
    +node_map: nodemask_t
    +domain: irq_domain
  }
  class extioi_node_map {
    +bits: DECLARE_BITMAP
  }
  note for eiointc_priv "Added eio_node_map"
  note for extioi_node_map "Added extioi_node_maps"
Loading

Updated class diagram for pch_msi_data

classDiagram
  class pch_msi_data {
    +dev: device
    +msi_domain: irq_domain
    +pci_segment: int
    +irq: int
  }
  note for pch_msi_data "Added pch_msi_acpi_init_avec"
Loading

Updated class diagram for loongarch CPU features

classDiagram
  class cpuinfo_loongarch {
    +options: unsigned long
  }
  note for cpuinfo_loongarch "Added LOONGARCH_CPU_AVECINT"
  class loongarch_cpu_features {
    +CPU_FEATURE_AVECINT: int
  }
  note for loongarch_cpu_features "Added CPU_FEATURE_AVECINT"
Loading

File-Level Changes

Change Details Files
Refactor GPIO control mode and add interrupt enable functionality.
  • Added inten_offset to loongson_gpio_chip_data struct.
  • Added gsi_idx_map and mapsize to loongson_gpio_chip struct.
  • Added BIT_CTRL_MODE and BYTE_CTRL_MODE defines.
  • Modified loongson_commit_direction and loongson_commit_level to handle different control modes.
  • Modified loongson_gpio_get and loongson_gpio_get_direction to handle different control modes.
  • Added loongson_gpio_to_irq to support interrupt mapping.
  • Modified loongson_gpio_init to initialize the gpio_chip structure and handle gsi_idx_map.
  • Added several new loongson_gpio_chip_data definitions for different Loongson chipsets.
  • Added of_device_id and acpi_device_id entries for new chipsets.
drivers/gpio/gpio-loongson-64bit.c
Fixes and improvements to memory management.
  • Added ptep_get and pmdp_get macros.
  • Added set_p4d, set_pud, and set_pmd macros using WRITE_ONCE.
  • Added p4d_clear, pud_clear, and pmd_clear macros using the new set macros.
  • Modified set_pte to use WRITE_ONCE and conditionally flush TLB on SMP systems.
  • Modified pte_clear to preserve global status.
arch/loongarch/include/asm/pgtable.h
Enhancements and fixes for the EIO interrupt controller.
  • Added irq-loongson.h include.
  • Added extioi_node_map structure and extioi_node_maps variable.
  • Modified eiointc_set_irq_route to use cpu_logical_map and iterate over online CPUs.
  • Modified eiointc_set_irq_affinity to use cpu_logical_map and iterate over online CPUs.
  • Modified eiointc_router_init to use cpu_logical_map and set bits in extioi_node_maps.
  • Added eiointc_resume to reset extioi_node_maps.
  • Added CPUHP_AP_IRQ_EIOINTC_STARTING cpuhp state.
  • Added cpu_has_avecint check to skip acpi_table_parse_madt if AVEC is enabled.
drivers/irqchip/irq-loongson-eiointc.c
Added support for AVEC interrupt controller and fixes for PCH MSI.
  • Added irq-loongson.h include.
  • Modified get_pch_msi_handle to return pch_msi_handle[0] if cpu_has_avecint is true.
  • Added pch_msi_acpi_init_avec to initialize PCH MSI with AVEC.
  • Added pch_msi_irq_chip_avec and pch_msi_domain_info_avec structures.
drivers/irqchip/irq-loongson-pch-msi.c
Added PCI quirks for Loongson PCIe MSI and D3/Link.
  • Added loongson_pcie_msi_quirk to enable MSI flags for Loongson PCIe devices.
  • Added loongson_d3_and_link_quirk to disable D3 and link speed changes for specific Loongson devices.
drivers/pci/quirks.c
Fixed spurious fault handling in memory management.
  • Added spurious_fault function to check for valid PTE entries before handling faults.
  • Called spurious_fault in no_context to prevent handling valid PTE entries as faults.
arch/loongarch/mm/fault.c
Improved MMU context switching and TLB management.
  • Modified get_new_mmu_context to accept a bool pointer and set it to true if a TLB flush is needed.
  • Added atomic_update_pgd_asid to atomically update ASID and PGDL CSRs.
  • Modified switch_mm_irqs_off to use atomic_update_pgd_asid and conditionally flush TLB.
  • Modified drop_mmu_context to conditionally flush TLB.
arch/loongarch/include/asm/mmu_context.h
Added AVEC interrupt support and increased vector count.
  • Added INT_AVEC define.
  • Increased EXCCODE_INT_NUM.
  • Added NR_VECTORS, NR_LEGACY_VECTORS, and IRQ_MATRIX_BITS defines.
  • Modified arch_probe_nr_irqs to account for AVEC and IO pics.
arch/loongarch/include/asm/irq.h
Added direct map window setup macro and stack fill option.
  • Added SETUP_DMWINS macro to set up direct map windows.
  • Added CSR_STFILL option for stack fill.
arch/loongarch/include/asm/stackframe.h
arch/loongarch/kernel/head.S
arch/loongarch/kernel/smp.c
Initialized kernel PTEs and improved PTE clearing.
  • Added kernel_pte_init to initialize kernel PTEs with _PAGE_GLOBAL.
  • Modified pte_clear to preserve global status.
arch/loongarch/mm/pgtable.c
arch/loongarch/include/asm/pgalloc.h
mm/kasan/init.c
mm/sparse-vmemmap.c
Added node ID offset for DMA.
  • Added node_id_offset variable.
  • Modified phys_to_dma and dma_to_phys to include node ID in DMA addresses.
arch/loongarch/kernel/dma.c
arch/loongarch/include/asm/dma-direct.h
Added clear vector IPI and complete IRQ moving function.
  • Added IPI_CLEAR_VECTOR define.
  • Added SMP_CLEAR_VECTOR define.
  • Modified loongson_ipi_interrupt to handle SMP_CLEAR_VECTOR.
  • Added complete_irq_moving function to complete IRQ moving process.
arch/loongarch/kernel/smp.c
arch/loongarch/include/asm/smp.h
arch/loongarch/include/asm/hardirq.h
Added support for more than 4 packages.
  • Added __max_packages variable.
  • Modified topology_max_packages to use __max_packages.
  • Increment __max_packages in parse_cpu_table.
arch/loongarch/kernel/smp.c
arch/loongarch/include/asm/topology.h
arch/loongarch/kernel/setup.c
Fixed Kasan initialization and PTE population.
  • Modified kasan_pte_offset, kasan_pmd_offset, and kasan_pud_offset to use pmdp_get, pudp_get, and p4dp_get.
  • Modified kasan_pte_populate, kasan_pmd_populate, and kasan_pud_populate to use ptep_get and pmdp_get.
arch/loongarch/mm/kasan_init.c
Added support for more ECAM entries.
  • Added more LOONGSON_ECAM_MCFG entries.
drivers/acpi/pci_mcfg.c
Fixed I2C frequency setting.
  • Replaced I2C_LS2X_PRER with I2C_LS2X_PRER_LO and I2C_LS2X_PRER_HI.
  • Modified ls2x_i2c_adjust_bus_speed to write to I2C_LS2X_PRER_LO and I2C_LS2X_PRER_HI.
drivers/i2c/busses/i2c-ls2x.c
Added write combine base address.
  • Added WRITECOMBINE_BASE define.
arch/loongarch/include/asm/addrspace.h
Fixed huge PTE access flags.
  • Modified huge_ptep_get_and_clear and huge_ptep_set_access_flags to use ptep_get.
arch/loongarch/include/asm/hugetlb.h
Added atomic operations.
  • Added __AMOR define.
arch/loongarch/include/asm/atomic.h
Added CPU feature flag for AVEC interrupt.
  • Added CPU_FEATURE_AVECINT define.
  • Added LOONGARCH_CPU_AVECINT define.
  • Added cpu_has_avecint macro.
  • Added IOCSRF_AVEC define.
  • Added LOONGARCH_IOCSR_MISC_FUNC_AVEC_EN define.
  • Added LOONGARCH_CPU_AVECINT option.
arch/loongarch/include/asm/cpu.h
arch/loongarch/kernel/cpu-probe.c
Fixed DWMAC reset timeout.
  • Added loongson_dwmac_fix_reset function.
  • Added fix_soc_reset to plat_stmmacenet_data.
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
Added CPU temperature monitoring driver.
  • Added cpu_hwmon.c file.
  • Added CONFIG_CPU_HWMON option.
drivers/platform/loongarch/Makefile
drivers/platform/loongarch/cpu_hwmon.c
drivers/platform/loongarch/Kconfig
Added DRM driver for AST.
  • Added ast_old directory.
  • Added CONFIG_DRM_AST_LOONGSON option.
drivers/gpu/drm/Makefile
drivers/gpu/drm/loongson/Kconfig
drivers/gpu/drm/loongson/ast_old/ast_post.c
drivers/gpu/drm/loongson/ast_old/ast_mode.c
drivers/gpu/drm/loongson/ast_old/ast_drv.h
drivers/gpu/drm/loongson/ast_old/ast_main.c
drivers/gpu/drm/loongson/ast_old/ast_tables.h
drivers/gpu/drm/loongson/ast_old/ast_dp.c
drivers/gpu/drm/loongson/ast_old/ast_i2c.c
drivers/gpu/drm/loongson/ast_old/ast_mm.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Hi @AaronDot. Thanks for your PR. 😃

@deepin-ci-robot
Copy link

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

@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 @AaronDot - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The commit message is very detailed and helpful, but consider summarizing the changes in a more concise way in the title.
  • This pull request introduces a lot of new features and bug fixes, so it would be helpful to have a high-level overview of the changes in the commit message.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues found
  • 🟢 Documentation: all looks good

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 332 to 341
/* wait ready */
do {
j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
} while ((j & 0x40) == 0);
}

void ast_post_gpu(struct drm_device *dev)
{
struct ast_private *ast = to_ast_private(dev);
struct pci_dev *pdev = to_pci_dev(dev->dev);
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Add timeout protection to the busy‐wait loop in ast_post_chip_2300.

Without a timeout, misbehaving hardware could cause an infinite loop. Adding a counter or timeout mechanism would improve robustness.

Suggested implementation:

#include <drm/drm_print.h>
#include "ast_dram_tables.h"
#include "ast_drv.h"
#include <linux/jiffies.h>
	/* wait ready with timeout */
	{
		unsigned long timeout = jiffies + msecs_to_jiffies(1000); /* 1000ms timeout */
		do {
			reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
			if (time_after_eq(jiffies, timeout)) {
				DRM_ERROR("ast_post_chip_2300: timed out waiting for hardware ready\n");
				break;
			}
		} while ((reg & 0x40) == 0);
	}

This change adds a 1000ms timeout period. Depending on your hardware expectations and performance requirements, you may adjust the timeout value (e.g. msecs_to_jiffies(500) for 500ms). Also ensure that including <linux/jiffies.h> is acceptable within your code base.

ast_write32(ast, 0xf004, r & 0xffff0000);
ast_write32(ast, 0xf000, 0x1);

do {
Copy link

Choose a reason for hiding this comment

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

suggestion: Implement timeout handling for the MCLK2X lock loop.

The current busy‐wait loop relies solely on hardware signaling. A timeout or error detection here could prevent a hang if the expected flag is never set.

Suggested implementation:

	/* Wait MCLK2X lock to MCLK with timeout handling */
	{
		unsigned long timeout = jiffies + msecs_to_jiffies(1000); /* 1s timeout */
		do {
			data = ast_mindwm(ast, 0x1E6E001C);
			if (time_after(jiffies, timeout)) {
				DRM_ERROR("MCLK2X lock timeout\n");
				break;
			}
		} while (!(data & 0x08000000));
	}

Ensure the necessary headers are included at the top of the file if they are not present:
#include <linux/jiffies.h>
#include <linux/delay.h>
#include <drm/drm_print.h>
These headers provide the jiffies API, timeout conversion macros, and DRM error logging.

^ ^ ^
| | |
+---------+ +----------+ +---------+ +-------+
| EIOINTC | | AVECINTC | | LIOINTC | <-- | UARTs |
Copy link

Choose a reason for hiding this comment

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

issue (typo): Typo: "UARTS" should be "UART"

Suggested change
| EIOINTC | | AVECINTC | | LIOINTC | <-- | UARTs |
| EIOINTC | | AVECINTC | | LIOINTC | <-- | UART |

return sprintf(buf, "%d\n", value);
}

static SENSOR_DEVICE_ATTR(temp1_input, 0444, get_cpu_temp, NULL, 1);
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider using macros to define sensor attributes and build the attribute array to reduce code repetition.

You can reduce the repetitive definitions by using helper macros to both generate the sensor attributes and build the attributes array. For example, you might do:

// Macro to declare sensor attributes for a given index 'n'
#define SENSOR_ATTR_ENTRY(n) \
    static SENSOR_DEVICE_ATTR(temp##n##_input, 0444, get_cpu_temp, NULL, n); \
    static SENSOR_DEVICE_ATTR(temp##n##_label, 0444, cpu_temp_label, NULL, n)

// Generate the sensor attributes (for indices 1..16)
SENSOR_ATTR_ENTRY(1);
SENSOR_ATTR_ENTRY(2);
SENSOR_ATTR_ENTRY(3);
SENSOR_ATTR_ENTRY(4);
SENSOR_ATTR_ENTRY(5);
SENSOR_ATTR_ENTRY(6);
SENSOR_ATTR_ENTRY(7);
SENSOR_ATTR_ENTRY(8);
SENSOR_ATTR_ENTRY(9);
SENSOR_ATTR_ENTRY(10);
SENSOR_ATTR_ENTRY(11);
SENSOR_ATTR_ENTRY(12);
SENSOR_ATTR_ENTRY(13);
SENSOR_ATTR_ENTRY(14);
SENSOR_ATTR_ENTRY(15);
SENSOR_ATTR_ENTRY(16);

// Macro to add sensor attribute pointers into the array
#define SENSOR_ATTR_ITEMS(n) \
    &sensor_dev_attr_temp##n##_input.dev_attr.attr, \
    &sensor_dev_attr_temp##n##_label.dev_attr.attr

// Build the attribute array using the macro
static struct attribute *cpu_hwmon_attributes[] = {
    SENSOR_ATTR_ITEMS(1),
    SENSOR_ATTR_ITEMS(2),
    SENSOR_ATTR_ITEMS(3),
    SENSOR_ATTR_ITEMS(4),
    SENSOR_ATTR_ITEMS(5),
    SENSOR_ATTR_ITEMS(6),
    SENSOR_ATTR_ITEMS(7),
    SENSOR_ATTR_ITEMS(8),
    SENSOR_ATTR_ITEMS(9),
    SENSOR_ATTR_ITEMS(10),
    SENSOR_ATTR_ITEMS(11),
    SENSOR_ATTR_ITEMS(12),
    SENSOR_ATTR_ITEMS(13),
    SENSOR_ATTR_ITEMS(14),
    SENSOR_ATTR_ITEMS(15),
    SENSOR_ATTR_ITEMS(16),
    NULL
};

This approach keeps functionality intact and improves readability and maintainability by removing repetitive code blocks.

#include <drm/drm_print.h>
#include "ast_drv.h"

int ast_astdp_read_edid(struct drm_device *dev, u8 *ediddata)
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extracting the EDID ready check and the wait loop into helper functions to improve readability and maintainability.

Consider extracting repeated register condition checks and retry loops into helper functions. For example, you can factor out the EDID-ready check and the wait‐loop into separate routines to reduce nesting and duplication. For instance:

static bool edid_ready(struct ast_private *ast)
{
    return ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xD1, ASTDP_MCU_FW_EXECUTING) &&
           ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xDC, ASTDP_LINK_SUCCESS) &&
           ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xDF, ASTDP_HPD) &&
           ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xE5, ASTDP_HOST_EDID_READ_DONE_MASK);
}

static int wait_for_edid_valid(struct ast_private *ast, u8 pointer)
{
    int retry = 0;
    /* Wait until EDID valid flag and read pointer match expectation */
    while ((ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xD7, ASTDP_EDID_VALID_FLAG_MASK) != 0x01) ||
           (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xD6, ASTDP_EDID_READ_POINTER_MASK) != pointer)) {
        if (!edid_ready(ast))
            return -EINVAL;  // or appropriate error code

        mdelay(retry + 1);
        if (++retry > 200)
            return -ETIMEDOUT;
    }
    return 0;
}

Then in your ast_astdp_read_edid function, you can greatly simplify the logic:

if (!edid_ready(ast))
    goto err_astdp_edid_not_ready;

ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xE5, (u8)~ASTDP_HOST_EDID_READ_DONE_MASK, 0x00);

for (i = 0; i < 32; i++) {
    ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xE4, ASTDP_AND_CLEAR_MASK, (u8)i);
    if (wait_for_edid_valid(ast, i))
        goto err_astdp_jump_out_loop_of_edid;

    /* read the 4 EDID bytes */
    *(ediddata)     = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xD8, ASTDP_EDID_READ_DATA_MASK);
    *(ediddata + 1) = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xD9, ASTDP_EDID_READ_DATA_MASK);
    *(ediddata + 2) = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xDA, ASTDP_EDID_READ_DATA_MASK);
    *(ediddata + 3) = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xDB, ASTDP_EDID_READ_DATA_MASK);

    if (i == 31) {
        *(ediddata + 3) += *(ediddata + 2);
        *(ediddata + 2) = 0;
    }

    ediddata += 4;
}

This approach keeps the functionality intact while reducing nesting and duplication, making the code easier to read and maintain.

@opsiff
Copy link
Member

opsiff commented Feb 16, 2025

/lgtm

opsiff
opsiff previously requested changes Feb 16, 2025
CONFIG_DRM_QXL=m
CONFIG_DRM_VIRTIO_GPU=m
CONFIG_DRM_LOONGSON=y
CONFIG_DRM_LOONGSON=m
Copy link
Member

Choose a reason for hiding this comment

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

需要一并在deepin_loongarch_desktop_defconfig 中也修改

@opsiff opsiff dismissed their stale review February 16, 2025 08:34

not a problem

@opsiff
Copy link
Member

opsiff commented Feb 16, 2025

建议upstream的commit一并标明upstream的commit sha256号

@AaronDot
Copy link
Contributor Author

建议upstream的commit一并标明upstream的commit sha256号

好的,等该系列补丁疑问都解决后, 我会加上 upstream commit!

@AaronDot
Copy link
Contributor Author

Update:

To be compatible with OLD firmware which has no _DMA method,
we should use arch specific phys_to_dma.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit d23b779 upstream.

LoongArch has hardware page coloring for L1 Cache, so we don't have
cache aliases. But SFB (Store Fill Buffer) still has aliases. So we
define SHMLBA to SZ_64K previously. But there are losts of applications
use PAGE_SIZE rather than SHMLBA to mmap() file pages and shared pages.
Of course we can fix them one by one, but not easy.

On the other hand, we can simply disable SFB for 4KB page size to fix
cache alias (there will be performance decrease, but acceptable), and
in future we will fix SFB in hardware. So we can safely define SHMLBA to
PAGE_SIZE (use the generic shmparam.h) to make life easier.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit 8e02c3b upstream.

Currently, only TLB-based ioremap() support writecombine, so add the
counterpart for DMW-based ioremap() with help of DMW2. The base address
(WRITECOMBINE_BASE) is configured as 0xa000000000000000.

DMW3 is unused by kernel now, however firmware may leave garbage in them
and interfere kernel's address mapping. So clear it as necessary.

BTW, centralize the DMW configuration to macro SETUP_DMWINS.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit 82bf60a upstream.

LoongArch doesn't have cache aliases, so flush_dcache_page() is a no-op.
There is a generic implementation for this case in include/asm-generic/
cacheflush.h. So remove the superfluous flush_dcache_page() definition,
which also silences such build warnings:

   In file included from crypto/scompress.c:12:
   include/crypto/scatterwalk.h: In function 'scatterwalk_pagedone':
   include/crypto/scatterwalk.h:76:30: warning: variable 'page' set but not used [-Wunused-but-set-variable]
      76 |                 struct page *page;
         |                              ^~~~
   crypto/scompress.c: In function 'scomp_acomp_comp_decomp':
>> crypto/scompress.c:174:38: warning: unused variable 'dst_page' [-Wunused-variable]
     174 |                         struct page *dst_page = sg_page(req->dst);
         |

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202403091614.NeUw5zcv-lkp@intel.com/
Suggested-by: Barry Song <baohua@kernel.org>
Acked-by: Barry Song <baohua@kernel.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
…ference

commit 4574815 upstream.

As very well explained in commit 20a004e ("arm64: mm: Use
READ_ONCE/WRITE_ONCE when accessing page tables"), an architecture whose
page table walker can modify the PTE in parallel must use READ_ONCE()/
WRITE_ONCE() macro to avoid any compiler transformation.

So apply that to LoongArch which is such an architecture, in order to
avoid potential problems.

Similar to commit edf9556 ("riscv: Use accessors to page table
entries instead of direct dereference").

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit f93f67d upstream.

LoongArch has similar problems explained in commit 7f0b1bf
("arm64: Fix barriers used for page table modifications"), when hardware
page table walker (PTW) enabled, speculative accesses may cause spurious
page fault in kernel space. Theoretically, in order to completely avoid
spurious page fault we need a "dbar + ibar" pair between the page table
modifications and the subsequent memory accesses using the corresponding
virtual address. But "ibar" is too heavy for performace, so we only use
a "dbar 0b11000" in set_pte(). And let spurious_fault() filter the rest
rare spurious page faults which should be avoided by "ibar".

Besides, we replace the llsc loop with amo in set_pte() which has better
performace, and refactor mmu_context.h to 1) avoid any load/store/branch
instructions between the writing of CSR.ASID & CSR.PGDL, 2) ensure flush
tlb operation is after updating ASID.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit d2f8671 upstream.

There are two pages in one TLB entry on LoongArch system. For kernel
space, it requires both two pte entries (buddies) with PAGE_GLOBAL bit
set, otherwise HW treats it as non-global tlb, there will be potential
problems if tlb entry for kernel space is not global. Such as fail to
flush kernel tlb with the function local_flush_tlb_kernel_range() which
supposed only flush tlb with global bit.

Kernel address space areas include percpu, vmalloc, vmemmap, fixmap and
kasan areas. For these areas both two consecutive page table entries
should be enabled with PAGE_GLOBAL bit. So with function set_pte() and
pte_clear(), pte buddy entry is checked and set besides its own pte
entry. However it is not atomic operation to set both two pte entries,
there is problem with test_vmalloc test case.

So function kernel_pte_init() is added to init a pte table when it is
created for kernel address space, and the default initial pte value is
PAGE_GLOBAL rather than zero at beginning. Then only its own pte entry
need update with function set_pte() and pte_clear(), nothing to do with
the pte buddy entry.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit ae16f05 upstream.

Introduce the advanced extended interrupt controllers (AVECINTC). This
feature will allow each core to have 256 independent interrupt vectors
and MSI interrupts can be independently routed to any vector on any CPU.

Co-developed-by: Jianmin Lv <lvjianmin@loongson.cn>
Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
Co-developed-by: Liupu Wang <wangliupu@loongson.cn>
Signed-off-by: Liupu Wang <wangliupu@loongson.cn>
Co-developed-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Tianyang Zhang <zhangtianyang@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
This add CPU HWMon (temperature sensor) platform driver for Loongson-3.

Tested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Kexy Biscuit <kexybiscuit@aosc.io>
Signed-off-by: gaojuxin <gaojuxin@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: wanghongliang <wanghongliang@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: wanghongliang <wanghongliang@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit 2af2573 upstream.

avecintc_init() enables the Advanced Interrupt Controller (AVEC) of
the boot CPU node, but nothing enables the AVEC on secondary nodes.

Move the enablement to the CPU hotplug callback so that secondary
nodes get the AVEC enabled too. In theory enabling it once per node
would be sufficient, but redundant enabling does no hard, so keep the
code simple and do it unconditionally.

Signed-off-by: Tianyang Zhang <zhangtianyang@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: wanghongliang <wanghongliang@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
This is similar to commit 62b6dee ("PCI/portdrv: Prevent
LS7A Bus Master clearing on shutdown"), which prevents LS7A Bus Master
clearing on kexec.

Only skip Bus Master clearing on bridges because endpoint devices still
need it.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
The CPU may not be able to access the PCI header of the device if
it is in low-power mode.

Signed-off-by: Zhao Qunqin <zhaoqunqin@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
commit 1f35a0c upstream.

Beginning with Loongson-3C6000, there can be up to 8 PCI hosts for
multi-chip machines. To support these machines, increase the number of
entries in mcfg_quirks to 8.

Link: https://lore.kernel.org/r/20240726092911.2042656-1-chenhuacai@loongson.cn
Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Loongson drm driver will not be used in the future, use loongson drm
dkms package instead.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
The policy->cur was not being initialized properly during CPU
initialization, leading to it always reporting 0. This commit addresses
this issue by setting the initial frequency to the normal maximum
frequency.

This ensures that the current frequency reflects the actual CPU
operating frequency.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Loongson's DWMAC device may take nearly two seconds to complete DMA reset,
however, the default waiting time for reset is 200 milliseconds.

Fixes: 803fc61 ("net: stmmac: dwmac-loongson: Add Loongson Multi-channels GMAC support")
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
@AaronDot
Copy link
Contributor Author

更新:

  1. 对upstream backport 补丁加上 upstream commit;
  2. 去掉“pci/quirks: Enable LS7A2000 MSI“ 补丁: 该补丁在deepin内核里已经有了,只是函数位置不一样drivers/pci/controller/pci-loongson.c
  3. 去掉 “drm/loongson: Use old version of ast driver for LoongArch platform”补丁:后续会有新的方案,这一版暂时先去掉

@AaronDot AaronDot reopened this Feb 17, 2025
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sourcery-ai[bot]
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

1 similar comment
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sourcery-ai[bot]
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

@Avenger-285714 Avenger-285714 merged commit b1c3e27 into deepin-community:linux-6.6.y Feb 18, 2025
6 of 8 checks passed
@AaronDot AaronDot deleted the dev-6.6 branch February 18, 2025 05:27
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.

4 participants