From 8f29578be61750d83b8effb090c25e07432dcb75 Mon Sep 17 00:00:00 2001 From: Jiankang Chen Date: Mon, 28 Oct 2019 20:29:37 +0800 Subject: [PATCH] svm: add svm drv framework for hi1910 and hi1980 ascend inclusion category: feature bugzilla: 16554 CVE: NA -------- add svm driver framework for hi1910 and hi1980, fistly we add the acpi driver for hi1980;However, we design the structure for svm; Signed-off-by: Jiankang Chen Signed-off-by: Lijun Fang Reviewed-by: Li Zefan Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/include/asm/mmu_context.h | 3 + arch/arm64/mm/context.c | 4 + drivers/char/Kconfig | 10 +++ drivers/char/Makefile | 1 + drivers/char/svm.c | 128 +++++++++++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 drivers/char/svm.c diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index 5ba0dbab9f5e..3e02efc9cdd0 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -29,6 +29,7 @@ typedef struct { atomic64_t id; unsigned long pinned; void *vdso; + unsigned long refcount; unsigned long flags; } mm_context_t; diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 0eb3f8cc3c9b..93d6a3c093db 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -244,6 +244,9 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next, #define deactivate_mm(tsk,mm) do { } while (0) #define activate_mm(prev,next) switch_mm(prev, next, current) +unsigned long mm_context_get(struct mm_struct *mm); +void mm_context_put(struct mm_struct *mm); + void verify_cpu_asid_bits(void); void post_ttbr_update_workaround(void); diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index 59d8173a685e..2b80ceff5d6c 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -158,6 +158,10 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu) if (asid != 0) { u64 newasid = generation | (asid & ~ASID_MASK); + /* That ASID is pinned for us, we're good to go. */ + if (mm->context.refcount) + return newasid; + /* * If our current ASID was active during a rollover, we * can continue to use it and this was just a false alarm. diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 1df9cb8e659e..0c25d37ca1be 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -552,6 +552,16 @@ config ADI and SSM (Silicon Secured Memory). Intended consumers of this driver include crash and makedumpfile. +config HISI_SVM + bool "Hisilicon svm driver" + depends on ARM64 && ARM_SMMU_V3 && MMU_NOTIFIER + default y + help + This driver provides character-level access to Hisilicon + SVM chipset. Typically, you can bind a task to the + svm and share the virtual memory with hisilicon svm device. + When in doubt, say "N". + endmenu config RANDOM_TRUST_CPU diff --git a/drivers/char/Makefile b/drivers/char/Makefile index b8d42b4e979b..3adc5ced7bc5 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -58,3 +58,4 @@ js-rtc-y = rtc.o obj-$(CONFIG_XILLYBUS) += xillybus/ obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o obj-$(CONFIG_ADI) += adi.o +obj-$(CONFIG_HISI_SVM) += svm.o diff --git a/drivers/char/svm.c b/drivers/char/svm.c new file mode 100644 index 000000000000..db3191c9c3ba --- /dev/null +++ b/drivers/char/svm.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2017-2018 Hisilicon Limited. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SVM_DEVICE_NAME "svm" + +struct core_device { + struct device dev; + struct iommu_group *group; + struct iommu_domain *domain; + bool smmu_bypass; +}; + +struct svm_device { + unsigned long long id; + struct miscdevice miscdev; + struct device *dev; + phys_addr_t l2buff; + unsigned long l2size; +}; + +struct svm_bind_process { + pid_t vpid; + u64 ttbr; + u64 tcr; + int pasid; + u32 flags; +#define SVM_BIND_PID (1 << 0) +}; + +struct svm_process { + struct pid *pid; + struct mm_struct *mm; + unsigned long asid; + struct kref kref; + struct rb_node rb_node; + struct mmu_notifier notifier; + /* For postponed release */ + struct rcu_head rcu; + struct list_head contexts; + int pasid; + struct mutex mutex; + struct rb_root sdma_list; +}; + +/* keep the relationship of svm_process and svm_device */ +struct svm_context { + struct svm_process *process; + struct svm_device *sdev; + struct list_head process_head; + atomic_t ref; +}; +/*svm ioctl will include some case for HI1980 and HI1910*/ +static long svm_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + /*TODO add svm ioctl*/ + return 0; +} + +static const struct file_operations svm_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = svm_ioctl, +}; +/*svm device probe this is init the svm device*/ +static int svm_device_probe(struct platform_device *pdev) +{ + /*TODO svm device init*/ + return 0; +} +/*svm device remove this is device remove*/ +static int svm_device_remove(struct platform_device *pdev) +{ + /*TODO svm device remove*/ + return 0; +} + +static const struct acpi_device_id svm_acpi_match[] = { + { "HSVM1980", 0}, + { } +}; +MODULE_DEVICE_TABLE(acpi, svm_acpi_match); +/*svm acpi probe and remove*/ +static struct platform_driver svm_driver = { + .probe = svm_device_probe, + .remove = svm_device_remove, + .driver = { + .name = SVM_DEVICE_NAME, + .acpi_match_table = ACPI_PTR(svm_acpi_match), + }, +}; + +module_platform_driver(svm_driver); + +MODULE_DESCRIPTION("Hisilicon SVM driver"); +MODULE_AUTHOR("JianKang Chen "); +MODULE_LICENSE("GPL v2"); -- GitLab