Driver: VMBus: Add Devicetree support

Update the driver to support Devicetree boot as well along with ACPI.
At present the Devicetree parsing only provides the mmio region info
and is not the exact copy of ACPI parsing. This is sufficient to cater
all the current Devicetree usecases for VMBus.

Currently Devicetree is supported only for x86 systems.

Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/1679298460-11855-6-git-send-email-ssengar@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
This commit is contained in:
Saurabh Sengar 2023-03-20 00:47:40 -07:00 committed by Wei Liu
parent 61f7a32592
commit f83705a512
2 changed files with 65 additions and 6 deletions

View File

@ -4,11 +4,12 @@ menu "Microsoft Hyper-V guest support"
config HYPERV config HYPERV
tristate "Microsoft Hyper-V client drivers" tristate "Microsoft Hyper-V client drivers"
depends on ACPI && ((X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \ depends on (X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \
|| (ARM64 && !CPU_BIG_ENDIAN)) || (ACPI && ARM64 && !CPU_BIG_ENDIAN)
select PARAVIRT select PARAVIRT
select X86_HV_CALLBACK_VECTOR if X86 select X86_HV_CALLBACK_VECTOR if X86
select VMAP_PFN select VMAP_PFN
select OF_EARLY_FLATTREE if OF
help help
Select this option to run Linux as a Hyper-V client operating Select this option to run Linux as a Hyper-V client operating
system. system.

View File

@ -20,6 +20,7 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/hyperv.h> #include <linux/hyperv.h>
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/of_address.h>
#include <linux/clockchips.h> #include <linux/clockchips.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/sched/isolation.h> #include <linux/sched/isolation.h>
@ -2152,7 +2153,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
device_unregister(&device_obj->device); device_unregister(&device_obj->device);
} }
#ifdef CONFIG_ACPI
/* /*
* VMBUS is an acpi enumerated device. Get the information we * VMBUS is an acpi enumerated device. Get the information we
* need from DSDT. * need from DSDT.
@ -2262,6 +2263,7 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
return AE_OK; return AE_OK;
} }
#endif
static void vmbus_mmio_remove(void) static void vmbus_mmio_remove(void)
{ {
@ -2282,7 +2284,7 @@ static void vmbus_mmio_remove(void)
} }
} }
static void vmbus_reserve_fb(void) static void __maybe_unused vmbus_reserve_fb(void)
{ {
resource_size_t start = 0, size; resource_size_t start = 0, size;
struct pci_dev *pdev; struct pci_dev *pdev;
@ -2442,6 +2444,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size)
} }
EXPORT_SYMBOL_GPL(vmbus_free_mmio); EXPORT_SYMBOL_GPL(vmbus_free_mmio);
#ifdef CONFIG_ACPI
static int vmbus_acpi_add(struct platform_device *pdev) static int vmbus_acpi_add(struct platform_device *pdev)
{ {
acpi_status result; acpi_status result;
@ -2494,10 +2497,54 @@ acpi_walk_err:
vmbus_mmio_remove(); vmbus_mmio_remove();
return ret_val; return ret_val;
} }
#else
static int vmbus_acpi_add(struct platform_device *pdev)
{
return 0;
}
#endif
static int vmbus_device_add(struct platform_device *pdev)
{
struct resource **cur_res = &hyperv_mmio;
struct of_range range;
struct of_range_parser parser;
struct device_node *np = pdev->dev.of_node;
int ret;
hv_dev = &pdev->dev;
ret = of_range_parser_init(&parser, np);
if (ret)
return ret;
for_each_of_range(&parser, &range) {
struct resource *res;
res = kzalloc(sizeof(*res), GFP_KERNEL);
if (!res) {
vmbus_mmio_remove();
return -ENOMEM;
}
res->name = "hyperv mmio";
res->flags = range.flags;
res->start = range.cpu_addr;
res->end = range.cpu_addr + range.size;
*cur_res = res;
cur_res = &res->sibling;
}
return ret;
}
static int vmbus_platform_driver_probe(struct platform_device *pdev) static int vmbus_platform_driver_probe(struct platform_device *pdev)
{ {
return vmbus_acpi_add(pdev); if (acpi_disabled)
return vmbus_device_add(pdev);
else
return vmbus_acpi_add(pdev);
} }
static int vmbus_platform_driver_remove(struct platform_device *pdev) static int vmbus_platform_driver_remove(struct platform_device *pdev)
@ -2643,7 +2690,17 @@ static int vmbus_bus_resume(struct device *dev)
#define vmbus_bus_resume NULL #define vmbus_bus_resume NULL
#endif /* CONFIG_PM_SLEEP */ #endif /* CONFIG_PM_SLEEP */
static const struct acpi_device_id vmbus_acpi_device_ids[] = { static const __maybe_unused struct of_device_id vmbus_of_match[] = {
{
.compatible = "microsoft,vmbus",
},
{
/* sentinel */
},
};
MODULE_DEVICE_TABLE(of, vmbus_of_match);
static const __maybe_unused struct acpi_device_id vmbus_acpi_device_ids[] = {
{"VMBUS", 0}, {"VMBUS", 0},
{"VMBus", 0}, {"VMBus", 0},
{"", 0}, {"", 0},
@ -2677,6 +2734,7 @@ static struct platform_driver vmbus_platform_driver = {
.driver = { .driver = {
.name = "vmbus", .name = "vmbus",
.acpi_match_table = ACPI_PTR(vmbus_acpi_device_ids), .acpi_match_table = ACPI_PTR(vmbus_acpi_device_ids),
.of_match_table = of_match_ptr(vmbus_of_match),
.pm = &vmbus_bus_pm, .pm = &vmbus_bus_pm,
.probe_type = PROBE_FORCE_SYNCHRONOUS, .probe_type = PROBE_FORCE_SYNCHRONOUS,
} }