Unverified Commit d68dc6ee authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!13999 add iommu support for loongarch

parents d3f9c037 72fe4978
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2200,3 +2200,7 @@ CONFIG_FUNCTION_TRACER=y
# CONFIG_STRICT_DEVMEM is not set
CONFIG_UNWINDER_ORC=y
# CONFIG_RUNTIME_TESTING_MENU is not set
CONFIG_LOONGARCH_IOMMU=m
CONFIG_IOMMU_DEFAULT_PASSTHROUGH=y
CONFIG_CMDLINE_EXTEND=y
CONFIG_CMDLINE="vfio_iommu_type1.allow_unsafe_interrupts=1 nokaslr"
+36 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Arch specific extensions to struct device
 *
 * This file is released under the GPLv2
 * Copyright (C) 2020 Loongson Technology Corporation Limited
 */
#ifndef _ASM_LOONGARCH_DEVICE_H
#define _ASM_LOONGARCH_DEVICE_H

struct dev_archdata {
	/* hook for IOMMU specific extension */
	void *iommu;
	struct bus_dma_region *dma_range_map;
	/*
	 * On some old 7A chipset, dma address is different from physical
	 * address, the main difference is that node id. For dma address
	 * node id starts from bit 36, physical node id starts from
	 * bit 44. The remaining address below node id is the same.
	 */
	unsigned long   dma_node_mask;
	unsigned int	dma_node_off;
};

struct pdev_archdata {
};

struct dma_domain {
	struct list_head node;
	const struct dma_map_ops *dma_ops;
	int domain_nr;
};
void add_dma_domain(struct dma_domain *domain);
void del_dma_domain(struct dma_domain *domain);

#endif /* _ASM_LOONGARCH_DEVICE_H*/
+3 −0
Original line number Diff line number Diff line
@@ -102,4 +102,7 @@ static inline void __cpu_die(unsigned int cpu)
}
#endif

int topo_add_cpu(int physid);
int topo_get_cpu(int physid);

#endif /* __ASM_SMP_H */
+16 −8
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ int set_processor_mask(u32 id, u32 flags)
		return -ENODEV;

	}
	if (cpuid == loongson_sysconf.boot_cpu_id)
		cpu = 0;
	else
		cpu = cpumask_next_zero(-1, cpu_present_mask);

	cpu = topo_add_cpu(cpuid);
	if (cpu < 0)
		return -EEXIST;

	if (flags & ACPI_MADT_ENABLED) {
		num_processors++;
@@ -197,8 +197,6 @@ void __init acpi_boot_table_init(void)
		goto fdt_earlycon;
	}

	loongson_sysconf.boot_cpu_id = read_csr_cpuid();

	/*
	 * Process the Multiple APIC Description Table (MADT), if present
	 */
@@ -248,7 +246,7 @@ void __init numa_set_distance(int from, int to, int distance)
void __init
acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
{
	int pxm, node;
	int pxm, node, cpu;

	if (srat_disabled())
		return;
@@ -277,6 +275,11 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
		return;
	}

	cpu = topo_get_cpu(pa->apic_id);
	/* Check whether apic_id exists in MADT table */
	if (cpu < 0)
		return;

	early_numa_add_cpu(pa->apic_id, node);

	set_cpuid_to_node(pa->apic_id, node);
@@ -315,12 +318,17 @@ int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, int *pcpu
{
	int cpu;

	cpu = set_processor_mask(physid, ACPI_MADT_ENABLED);
	cpu = topo_get_cpu(physid);
	/* Check whether apic_id exists in MADT table */
	if (cpu < 0) {
		pr_info(PREFIX "Unable to map lapic to logical cpu number\n");
		return cpu;
	}

	num_processors++;
	set_cpu_present(cpu, true);
	__cpu_number_map[physid] = cpu;
	__cpu_logical_map[cpu] = physid;
	acpi_map_cpu2node(handle, cpu, physid);

	*pcpu = cpu;
+47 −0
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ EXPORT_SYMBOL(cpu_data);

struct loongson_board_info b_info;
static const char dmi_empty_string[] = "        ";
static int possible_cpus;
static bool bsp_added;

/*
 * Setup information
@@ -373,10 +375,55 @@ static void __init bootcmdline_init(char **cmdline_p)
	*cmdline_p = boot_command_line;
}

int topo_get_cpu(int physid)
{
	int i;

	for (i = 0; i < possible_cpus; i++)
		if (cpu_logical_map(i) == physid)
			break;

	if (i == possible_cpus)
		return -ENOENT;

	return i;
}

int topo_add_cpu(int physid)
{
	int cpu;

	if (!bsp_added && (physid == loongson_sysconf.boot_cpu_id)) {
		bsp_added = true;
		return 0;
	}

	cpu = topo_get_cpu(physid);
	if (cpu >= 0) {
		pr_warn("Adding duplicated physical cpuid 0x%x\n", physid);
		return -EEXIST;
	}

	if (possible_cpus >= nr_cpu_ids)
		return -ERANGE;

	__cpu_logical_map[possible_cpus] = physid;
	cpu = possible_cpus++;
	return cpu;
}

static void __init topo_init(void)
{
	loongson_sysconf.boot_cpu_id = read_csr_cpuid();
	__cpu_logical_map[0] = loongson_sysconf.boot_cpu_id;
	possible_cpus++;
}

void __init platform_init(void)
{
	arch_reserve_vmcore();
	arch_parse_crashkernel();
	topo_init();

#ifdef CONFIG_ACPI_TABLE_UPGRADE
	acpi_table_upgrade();
Loading