From dbd155d4632244cbd3d478ffa7e90dc15a3fea13 Mon Sep 17 00:00:00 2001 From: Jiankang Chen Date: Mon, 28 Oct 2019 20:29:40 +0800 Subject: [PATCH] svm: add init svm device for dts ascend inclusion category: feature bugzilla: 16554 CVE: NA -------- To init svm device using dts, and init the hi1910 and hi1980 cores for ai; Signed-off-by: Jiankang Chen Signed-off-by: Lijun Fang Reviewed-by: Li Zefan Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- drivers/char/svm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/char/svm.c b/drivers/char/svm.c index b754eb8036e6..1a1a3be41a99 100644 --- a/drivers/char/svm.c +++ b/drivers/char/svm.c @@ -31,10 +31,16 @@ #include #include #include +#ifdef CONFIG_ACPI #include +#endif #define SVM_DEVICE_NAME "svm" +#ifndef CONFIG_ACPI +static int probe_index; +#endif + struct core_device { struct device dev; struct iommu_group *group; @@ -87,12 +93,19 @@ static int svm_open(struct inode *inode, struct file *file) return 0; } +#ifdef CONFIG_ACPI static int svm_init_core(struct svm_device *sdev) { /*TODO init hi1910 and hi1980 cores for ai*/ return 0; } - +#else +static int svm_init_core(struct svm_device *sdev, struct device_node *np) +{ + /*TODO*/ + return 0; +} +#endif /*svm ioctl will include some case for HI1980 and HI1910*/ static long svm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) @@ -112,6 +125,13 @@ static int svm_device_probe(struct platform_device *pdev) int err = -1; struct device *dev = &pdev->dev; struct svm_device *sdev = NULL; +#ifndef CONFIG_ACPI + struct device_node *np = dev->of_node; + int alias_id; + + if (np == NULL) + return -ENODEV; +#endif if (!dev->bus->iommu_ops) { dev_dbg(dev, "defer probe svm device\n"); @@ -122,11 +142,19 @@ static int svm_device_probe(struct platform_device *pdev) if (sdev == NULL) return -ENOMEM; +#ifdef CONFIG_ACPI err = device_property_read_u64(dev, "svmid", &sdev->id); if (err) { dev_err(dev, "failed to get this svm device id\n"); return err; } +#else + alias_id = of_alias_get_id(np, "svm"); + if (alias_id < 0) + sdev->id = probe_index; + else + sdev->id = alias_id; +#endif sdev->dev = dev; sdev->miscdev.minor = MISC_DYNAMIC_MINOR; @@ -142,13 +170,21 @@ static int svm_device_probe(struct platform_device *pdev) dev_err(dev, "Unable to register misc device\n"); return err; } - +#ifdef CONFIG_ACPI err = svm_init_core(sdev); +#else + err = svm_init_core(sdev, np); +#endif + if (err) { dev_err(dev, "failed to init cores\n"); goto err_unregister_misc; } +#ifndef CONFIG_ACPI + probe_index++; +#endif + return err; err_unregister_misc: @@ -167,18 +203,31 @@ static int svm_device_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_ACPI static const struct acpi_device_id svm_acpi_match[] = { { "HSVM1980", 0}, { } }; MODULE_DEVICE_TABLE(acpi, svm_acpi_match); +#else +static const struct of_device_id svm_of_match[] = { + { .compatible = "hisilicon,svm" }, + { } +}; +MODULE_DEVICE_TABLE(of, svm_of_match); +#endif + /*svm acpi probe and remove*/ static struct platform_driver svm_driver = { .probe = svm_device_probe, .remove = svm_device_remove, .driver = { .name = SVM_DEVICE_NAME, +#ifdef CONFIG_ACPI .acpi_match_table = ACPI_PTR(svm_acpi_match), +#else + .of_match_table = svm_of_match, +#endif }, }; -- GitLab