From: Saurabh Sengar <ssengar@linux.microsoft.com>
To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, daniel.lezcano@linaro.org,
tglx@linutronix.de, virtualization@lists.linux-foundation.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org, mikelley@microsoft.com,
ssengar@linux.microsoft.com, dphadke@linux.microsoft.com
Subject: [PATCH v5 5/5] Driver: VMBus: Add device tree support
Date: Thu, 9 Feb 2023 04:15:39 -0800 [thread overview]
Message-ID: <1675944939-22631-6-git-send-email-ssengar@linux.microsoft.com> (raw)
In-Reply-To: <1675944939-22631-1-git-send-email-ssengar@linux.microsoft.com>
Update the driver to support device tree boot as well along with ACPI.
At present the device tree parsing only provides the mmio region info
and is not the exact copy of ACPI parsing. This is sufficient to cater
all the current device tree usecases for VMBus.
Currently device tree is supported only for x86 systems.
Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
- Removed #else for device tree parsing code. This should help better
test coverage.
- Fix macro '__maybe_unused' warning
- Added below options in Kconfig to enable device tree options for HYPERV
select OF if !ACPI
select OF_EARLY_FLATTREE if !ACPI
drivers/hv/Kconfig | 6 +++--
drivers/hv/vmbus_drv.c | 60 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 0747a8f1fcee..1a55bf32d195 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -4,11 +4,13 @@ menu "Microsoft Hyper-V guest support"
config HYPERV
tristate "Microsoft Hyper-V client drivers"
- depends on ACPI && ((X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \
- || (ARM64 && !CPU_BIG_ENDIAN))
+ depends on (X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \
+ || (ACPI && ARM64 && !CPU_BIG_ENDIAN)
select PARAVIRT
select X86_HV_CALLBACK_VECTOR if X86
select VMAP_PFN
+ select OF if !ACPI
+ select OF_EARLY_FLATTREE if !ACPI
help
Select this option to run Linux as a Hyper-V client operating
system.
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 73497157a23a..02f6bab61c37 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -20,6 +20,7 @@
#include <linux/completion.h>
#include <linux/hyperv.h>
#include <linux/kernel_stat.h>
+#include <linux/of_address.h>
#include <linux/clockchips.h>
#include <linux/cpu.h>
#include <linux/sched/isolation.h>
@@ -2152,7 +2153,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
device_unregister(&device_obj->device);
}
-
+#ifdef CONFIG_ACPI
/*
* VMBUS is an acpi enumerated device. Get the information we
* need from DSDT.
@@ -2262,6 +2263,7 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
return AE_OK;
}
+#endif
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;
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);
+#ifdef CONFIG_ACPI
static int vmbus_acpi_add(struct platform_device *pdev)
{
acpi_status result;
@@ -2494,10 +2497,50 @@ static int vmbus_acpi_add(struct platform_device *pdev)
vmbus_mmio_remove();
return ret_val;
}
+#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;
+ int ret = 0;
+
+ hv_dev = &pdev->dev;
+ np = pdev->dev.of_node;
+
+ ret = of_range_parser_init(&parser, np);
+ if (ret) {
+ dev_err(hv_dev, "Failed to parse resources.\n");
+ return ret;
+ }
+
+ for_each_of_range(&parser, &range) {
+ struct resource *res;
+
+ res = kzalloc(sizeof(*res), GFP_ATOMIC);
+ if (!res)
+ return -ENOMEM;
+
+ res->name = "hyperv mmio";
+ res->flags = IORESOURCE_MEM | IORESOURCE_MEM_64;
+ res->start = range.pci_addr;
+ res->end = range.pci_addr + range.size;
+
+ *cur_res = res;
+ cur_res = &res->sibling;
+ }
+
+ return ret;
+}
static int vmbus_platform_driver_probe(struct platform_device *pdev)
{
+#ifdef CONFIG_ACPI
return vmbus_acpi_add(pdev);
+#endif
+ return vmbus_device_add(pdev);
}
static int vmbus_platform_driver_remove(struct platform_device *pdev)
@@ -2643,12 +2686,24 @@ static int vmbus_bus_resume(struct device *dev)
#define vmbus_bus_resume NULL
#endif /* CONFIG_PM_SLEEP */
+static const __maybe_unused struct of_device_id vmbus_of_match[] = {
+ {
+ .compatible = "microsoft,vmbus",
+ },
+ {
+ /* sentinel */
+ },
+};
+MODULE_DEVICE_TABLE(of, vmbus_of_match);
+
+#ifdef CONFIG_ACPI
static const struct acpi_device_id vmbus_acpi_device_ids[] = {
{"VMBUS", 0},
{"VMBus", 0},
{"", 0},
};
MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids);
+#endif
/*
* Note: we must use the "no_irq" ops, otherwise hibernation can not work with
@@ -2677,6 +2732,7 @@ static struct platform_driver vmbus_platform_driver = {
.driver = {
.name = "vmbus",
.acpi_match_table = ACPI_PTR(vmbus_acpi_device_ids),
+ .of_match_table = of_match_ptr(vmbus_of_match),
.pm = &vmbus_bus_pm,
.probe_type = PROBE_FORCE_SYNCHRONOUS,
}
--
2.34.1
next prev parent reply other threads:[~2023-02-09 12:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 12:15 [PATCH v5 0/5] Device tree support for Hyper-V VMBus driver Saurabh Sengar
2023-02-09 12:15 ` [PATCH v5 1/5] drivers/clocksource/hyper-v: non ACPI support in hyperv clock Saurabh Sengar
2023-02-09 12:15 ` [PATCH v5 2/5] Drivers: hv: allow non ACPI compilation for hv_is_hibernation_supported Saurabh Sengar
2023-02-09 15:17 ` Rob Herring
2023-02-09 17:29 ` Saurabh Singh Sengar
2023-02-09 12:15 ` [PATCH v5 3/5] Drivers: hv: vmbus: Convert acpi_device to more generic platform_device Saurabh Sengar
2023-02-09 12:15 ` [PATCH v5 4/5] dt-bindings: hypervisor: VMBus Saurabh Sengar
2023-02-09 12:15 ` Saurabh Sengar [this message]
2023-02-09 15:50 ` [PATCH v5 5/5] Driver: VMBus: Add device tree support Rob Herring
2023-02-09 17:46 ` Saurabh Singh Sengar
2023-02-10 22:37 ` Rob Herring
2023-02-13 11:24 ` Saurabh Singh Sengar
2023-02-17 13:27 ` Saurabh Singh Sengar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1675944939-22631-6-git-send-email-ssengar@linux.microsoft.com \
--to=ssengar@linux.microsoft.com \
--cc=daniel.lezcano@linaro.org \
--cc=decui@microsoft.com \
--cc=devicetree@vger.kernel.org \
--cc=dphadke@linux.microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=robh+dt@kernel.org \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).