Skip to content

Commit 9e112e4

Browse files
xuyanopsiff
authored andcommitted
dma: phytium: fix more bugs of pswiotlb
fix more bugs of pswiotlb in cloud kernel 6.6 including: Move pswiotlb dma functions behind dma_map_ops Optimized variable types and removed unused header files Move PCI-related changes to the PCI quirks. Move platform-identification to cpu errata Adjust the location of the platform-identification process Fix a issue of member variable force not being initialized Signed-off-by: xuyan <xuyan1481@phytium.com.cn>
1 parent 8200fe6 commit 9e112e4

18 files changed

Lines changed: 507 additions & 130 deletions

File tree

arch/arm64/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,16 @@ config SOCIONEXT_SYNQUACER_PREITS
13131313

13141314
If unsure, say Y.
13151315

1316+
config PHYTIUM_ERRATUM_FT3386
1317+
bool "FT3386: enable Phytium FT3386 pswiotlb can improve dma performance"
1318+
depends on PSWIOTLB
1319+
default y
1320+
help
1321+
Phytium FT3386 pswiotlb can improve D2H dma performance and
1322+
should be enabled by default.
1323+
1324+
If unsure, say Y.
1325+
13161326
endmenu # "ARM errata workarounds via the alternatives framework"
13171327

13181328
choice

arch/arm64/include/asm/cputype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#define APM_CPU_PART_XGENE 0x000
104104
#define APM_CPU_VAR_POTENZA 0x00
105105

106+
106107
#define CAVIUM_CPU_PART_THUNDERX 0x0A1
107108
#define CAVIUM_CPU_PART_THUNDERX_81XX 0x0A2
108109
#define CAVIUM_CPU_PART_THUNDERX_83XX 0x0A3
@@ -164,6 +165,7 @@
164165
#define PHYTIUM_CPU_PART_FTC862 0x862
165166
#define PHYTIUM_CPU_SOCID_PS24080 0x6
166167

168+
167169
#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
168170
#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
169171
#define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)

arch/arm64/kernel/cpu_errata.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,28 @@ static const struct midr_range erratum_ac03_cpu_38_list[] = {
495495
};
496496
#endif
497497

498+
#ifdef CONFIG_PHYTIUM_ERRATUM_FT3386
499+
#define SOC_ID_PS23064 0x8
500+
#define SOC_ID_PS24080 0x6
501+
#define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7)
502+
bool __read_mostly is_ps_socs;
503+
static bool
504+
should_enable_phytium_ft3386_pswiotlb(const struct arm64_cpu_capabilities *entry, int unused)
505+
{
506+
u32 model;
507+
u32 soc_id;
508+
509+
soc_id = read_sysreg_s(SYS_AIDR_EL1);
510+
model = read_cpuid_id();
511+
if ((soc_id == SOC_ID_PS23064 || soc_id == SOC_ID_PS24080)
512+
&& model == entry->midr_range.model) {
513+
is_ps_socs = true;
514+
return true;
515+
} else
516+
return false;
517+
}
518+
#endif
519+
498520
const struct arm64_cpu_capabilities arm64_errata[] = {
499521
#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
500522
{
@@ -808,6 +830,14 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
808830
ERRATA_MIDR_RANGE_LIST(erratum_spec_unpriv_load_list),
809831
},
810832
#endif
833+
#ifdef CONFIG_PHYTIUM_ERRATUM_FT3386
834+
{
835+
.desc = "Phytium erratum FT3386",
836+
.capability = ARM64_WORKAROUND_PHYTIUM_FT3386,
837+
ERRATA_MIDR_ALL_VERSIONS(MIDR_FT_FTC862),
838+
.matches = should_enable_phytium_ft3386_pswiotlb,
839+
},
840+
#endif
811841
#ifdef CONFIG_AMPERE_ERRATUM_AC03_CPU_38
812842
{
813843
.desc = "AmpereOne erratum AC03_CPU_38",

arch/arm64/mm/dma-mapping.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <asm/cacheflush.h>
1414
#include <asm/xen/xen-ops.h>
1515

16+
#ifdef CONFIG_PSWIOTLB
17+
#include <linux/pswiotlb.h>
18+
#endif
19+
1620
void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
1721
enum dma_data_direction dir)
1822
{
@@ -61,5 +65,9 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
6165
if (iommu)
6266
iommu_setup_dma_ops(dev, dma_base, dma_base + size - 1);
6367

68+
#ifdef CONFIG_PSWIOTLB
69+
pswiotlb_setup_dma_ops(dev);
70+
#endif
71+
6472
xen_setup_dma_ops(dev);
6573
}

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,4 @@ WORKAROUND_SPECULATIVE_SSBS
106106
WORKAROUND_SPECULATIVE_UNPRIV_LOAD
107107
HAS_LS64
108108
HAS_LS64_V
109+
WORKAROUND_PHYTIUM_FT3386

drivers/pci/pci.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
#include <linux/suspend.h>
3737
#endif
3838
#include "pci.h"
39-
#ifdef CONFIG_PSWIOTLB
40-
#include <linux/pswiotlb.h>
41-
#endif
4239

4340
DEFINE_MUTEX(pci_slot_mutex);
4441

@@ -4553,15 +4550,6 @@ void __weak pcibios_set_master(struct pci_dev *dev)
45534550
*/
45544551
void pci_set_master(struct pci_dev *dev)
45554552
{
4556-
#ifdef CONFIG_PSWIOTLB
4557-
if ((pswiotlb_force_disable != true) &&
4558-
is_phytium_ps_socs()) {
4559-
dev->dev.can_use_pswiotlb = pswiotlb_is_dev_in_passthroughlist(dev);
4560-
dev_info(&dev->dev, "The device %s use pswiotlb because vendor 0x%04x %s in pswiotlb passthroughlist\n",
4561-
dev->dev.can_use_pswiotlb ? "would" : "would NOT",
4562-
dev->vendor, dev->dev.can_use_pswiotlb ? "is NOT" : "is");
4563-
}
4564-
#endif
45654553
__pci_set_master(dev, true);
45664554
pcibios_set_master(dev);
45674555
}

drivers/pci/probe.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include <linux/pm_runtime.h>
2121
#include <linux/bitfield.h>
2222
#include "pci.h"
23-
#ifdef CONFIG_PSWIOTLB
24-
#include <linux/pswiotlb.h>
25-
#endif
2623

2724
#define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */
2825
#define CARDBUS_RESERVE_BUSNR 3
@@ -2628,13 +2625,8 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
26282625

26292626
dma_set_max_seg_size(&dev->dev, 65536);
26302627
dma_set_seg_boundary(&dev->dev, 0xffffffff);
2631-
#ifdef CONFIG_PSWIOTLB
2632-
if ((pswiotlb_force_disable != true) &&
2633-
is_phytium_ps_socs()) {
2634-
pswiotlb_store_local_node(dev, bus);
2635-
dma_set_seg_boundary(&dev->dev, 0xffffffffffff);
2636-
}
2637-
#endif
2628+
2629+
pci_configure_pswiotlb(dev, bus);
26382630

26392631
pcie_failed_link_retrain(dev);
26402632

drivers/pci/quirks.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include <linux/suspend.h>
3333
#include <linux/switchtec.h>
3434
#include "pci.h"
35+
#ifdef CONFIG_PSWIOTLB
36+
#include <linux/pswiotlb.h>
37+
#endif
3538

3639
/*
3740
* Retrain the link of a downstream PCIe port by hand if necessary.
@@ -6501,6 +6504,17 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node);
65016504
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node);
65026505
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node);
65036506

6507+
void pci_configure_pswiotlb(struct pci_dev *dev, struct pci_bus *bus)
6508+
{
6509+
#ifdef CONFIG_PSWIOTLB
6510+
if ((pswiotlb_force_disable != true) &&
6511+
is_phytium_ps_socs()) {
6512+
pswiotlb_store_local_node(dev, bus);
6513+
dma_set_seg_boundary(&dev->dev, 0xffffffffffff);
6514+
}
6515+
#endif
6516+
}
6517+
65046518
/*
65056519
* Devices known to require a longer delay before first config space access
65066520
* after reset recovery or resume from D3cold:

include/linux/device.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ struct device_physical_location {
658658
* @dma_io_tlb_lock: Protects changes to the list of active pools.
659659
* @dma_uses_io_tlb: %true if device has used the software IO TLB.
660660
* @dma_p_io_tlb_mem: Phytium Software IO TLB allocator. Not for driver use.
661+
* @orig_dma_ops: Original DMA mapping operations for this device.
662+
* @local_node: NUMA node this device is really belong to.
661663
* @dma_uses_p_io_tlb: %true if device has used the Phytium software IO TLB.
664+
* @can_use_pswiotlb: %true if device can use the Phytium software IO TLB.
662665
* @archdata: For arch-specific additions.
663666
* @of_node: Associated device tree node.
664667
* @fwnode: Associated device node supplied by platform firmware.
@@ -767,8 +770,16 @@ struct device {
767770
#endif
768771
#ifdef CONFIG_PSWIOTLB
769772
struct p_io_tlb_mem *dma_p_io_tlb_mem;
770-
bool dma_uses_p_io_tlb;
771-
bool can_use_pswiotlb;
773+
#ifdef CONFIG_DMA_OPS
774+
const struct dma_map_ops *orig_dma_ops;
775+
#endif
776+
struct {
777+
#ifdef CONFIG_NUMA
778+
int local_node;
779+
#endif
780+
bool dma_uses_p_io_tlb;
781+
bool can_use_pswiotlb;
782+
};
772783
#endif
773784
#ifdef CONFIG_SWIOTLB_DYNAMIC
774785
struct list_head dma_io_tlb_pools;
@@ -783,9 +794,6 @@ struct device {
783794

784795
#ifdef CONFIG_NUMA
785796
int numa_node; /* NUMA node this device is close to */
786-
#ifdef CONFIG_PSWIOTLB
787-
int local_node; /* NUMA node this device is really belong to */
788-
#endif
789797
#endif
790798
dev_t devt; /* dev_t, creates the sysfs "dev" */
791799
u32 id; /* device instance */

include/linux/pci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,9 +2314,12 @@ enum pci_fixup_pass {
23142314

23152315
#ifdef CONFIG_PCI_QUIRKS
23162316
void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
2317+
void pci_configure_pswiotlb(struct pci_dev *dev, struct pci_bus *bus);
23172318
#else
23182319
static inline void pci_fixup_device(enum pci_fixup_pass pass,
23192320
struct pci_dev *dev) { }
2321+
static inline void pci_configure_pswiotlb(struct pci_dev *dev,
2322+
struct pci_bus *bus) { }
23202323
#endif
23212324

23222325
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);

0 commit comments

Comments
 (0)