nvidia-oot: hypervisor driver as platform driver

Using this patch we are converting hypervisor driver
as platform driver since insertion of this module
is getting failed on native kernel due to
is_tegra_hypervisor_mode API failure since
hypervisor environment is missing, leading to
nvethernet module insertion causing the error
"Unknown Symbol tegra_hv_ivc_reserve".

Bug 3793131

Change-Id: I626c62aa0ada15c41283fb1875c351cada16ac51
Signed-off-by: Manish Bhardwaj <mbhardwaj@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2798141
Reviewed-by: Suresh Venkatachalam <skathirampat@nvidia.com>
Reviewed-by: Sandeep Trasi <strasi@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Manish Bhardwaj
2022-10-26 10:47:57 +00:00
committed by mobile promotions
parent 994623c5ea
commit 006187b889

View File

@@ -10,6 +10,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/of_platform.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
@@ -29,6 +30,7 @@
#define ERR(...) pr_err("tegra_hv: " __VA_ARGS__) #define ERR(...) pr_err("tegra_hv: " __VA_ARGS__)
#define INFO(...) pr_info("tegra_hv: " __VA_ARGS__) #define INFO(...) pr_info("tegra_hv: " __VA_ARGS__)
#define DRV_NAME "tegra_hv"
struct tegra_hv_data; struct tegra_hv_data;
@@ -607,52 +609,6 @@ static int __init tegra_hv_setup(struct tegra_hv_data *hvd)
return 0; return 0;
} }
static int __init tegra_hv_init(void)
{
struct tegra_hv_data *hvd;
int ret;
if (!is_tegra_hypervisor_mode())
return -ENODEV;
hvd = kzalloc(sizeof(*hvd), GFP_KERNEL);
if (!hvd) {
ERR("failed to allocate hvd\n");
return -ENOMEM;
}
ret = tegra_hv_setup(hvd);
if (ret != 0) {
tegra_hv_cleanup(hvd);
kfree(hvd);
return ret;
}
/*
* Ensure that all contents of hvd are visible before they are visible
* to other threads.
*/
smp_wmb();
BUG_ON(tegra_hv_data);
tegra_hv_data = hvd;
INFO("initialized\n");
return 0;
}
static void __exit tegra_hv_exit(void)
{
if (!is_tegra_hypervisor_mode())
return;
tegra_hv_cleanup(tegra_hv_data);
kfree(tegra_hv_data);
tegra_hv_data = NULL;
INFO("de-initialized\n");
}
static int ivc_dump(struct hv_ivc *ivc) static int ivc_dump(struct hv_ivc *ivc)
{ {
INFO("IVC#%d: IRQ=%d(%d) nframes=%d frame_size=%d offset=%d\n", INFO("IVC#%d: IRQ=%d(%d) nframes=%d frame_size=%d offset=%d\n",
@@ -968,6 +924,85 @@ void tegra_hv_ivc_channel_reset(struct tegra_hv_ivc_cookie *ivck)
} }
EXPORT_SYMBOL(tegra_hv_ivc_channel_reset); EXPORT_SYMBOL(tegra_hv_ivc_channel_reset);
static int tegra_hv_probe(struct platform_device *pdev)
{
struct tegra_hv_data *hvd;
int ret;
if (!is_tegra_hypervisor_mode())
return -ENODEV;
hvd = kzalloc(sizeof(*hvd), GFP_KERNEL);
if (!hvd) {
ERR("failed to allocate hvd\n");
return -ENOMEM;
}
ret = tegra_hv_setup(hvd);
if (ret != 0) {
tegra_hv_cleanup(hvd);
kfree(hvd);
return ret;
}
/*
* Ensure that all contents of hvd are visible before they are visible
* to other threads.
*/
smp_wmb();
BUG_ON(tegra_hv_data);
tegra_hv_data = hvd;
INFO("tegra_hv driver probed successfully\n");
return 0;
}
static int tegra_hv_remove(struct platform_device *pdev)
{
if (!is_tegra_hypervisor_mode())
return 0;
tegra_hv_cleanup(tegra_hv_data);
kfree(tegra_hv_data);
tegra_hv_data = NULL;
INFO("tegra_hv driver removed successfully\n");
return 0;
}
static const struct of_device_id tegra_hv_match[] = {
{ .compatible = "nvidia,tegra-hv", },
{},
};
static struct platform_driver tegra_hv_driver = {
.driver = {
.name = DRV_NAME,
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(tegra_hv_match),
},
.probe = tegra_hv_probe,
.remove = tegra_hv_remove,
};
static int __init tegra_hv_init(void)
{
int ret;
ret = platform_driver_register(&tegra_hv_driver);
if (ret)
pr_err("Error: tegra_hv driver registration failed\n");
return ret;
}
static void __exit tegra_hv_exit(void)
{
platform_driver_unregister(&tegra_hv_driver);
}
module_init(tegra_hv_init); module_init(tegra_hv_init);
module_exit(tegra_hv_exit); module_exit(tegra_hv_exit);