devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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@microsoft.com
Subject: [PATCH v2 6/6] Driver: VMBus: Add device tree support
Date: Tue, 31 Jan 2023 10:10:09 -0800	[thread overview]
Message-ID: <1675188609-20913-7-git-send-email-ssengar@linux.microsoft.com> (raw)
In-Reply-To: <1675188609-20913-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.

Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
 drivers/hv/vmbus_drv.c | 75 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 49030e756b9f..1741f1348f9f 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -2152,7 +2152,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 +2262,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 +2283,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 +2443,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;
@@ -2496,10 +2498,68 @@ static int vmbus_acpi_add(struct platform_device *pdev)
 		vmbus_mmio_remove();
 	return ret_val;
 }
+#else
+
+static int vmbus_device_add(struct platform_device *pdev)
+{
+	struct resource **cur_res = &hyperv_mmio;
+	struct device_node *np;
+	u32 *ranges, len;
+	u64 start;
+	int nr_ranges, child_cells = 2, cur_cell = 0, ret = 0;
+
+	hv_dev = pdev;
+	np = pdev->dev.of_node;
+
+	nr_ranges = device_property_count_u32(&pdev->dev, "ranges");
+	if (nr_ranges < 0)
+		return nr_ranges;
+	ranges = kcalloc(nr_ranges, sizeof(u32), GFP_KERNEL);
+	if (!ranges)
+		return -ENOMEM;
+
+	if (device_property_read_u32_array(&pdev->dev, "ranges", ranges, nr_ranges)) {
+		ret =  -EINVAL;
+		goto free_ranges;
+	}
+
+	while (cur_cell < nr_ranges) {
+		struct resource *res;
+
+		/* The first u64 in the ranges description isn't used currently. */
+		cur_cell = cur_cell + child_cells;
+		start = ranges[cur_cell++];
+		start = (start << 32) | ranges[cur_cell++];
+		len = ranges[cur_cell++];
+
+		res = kzalloc(sizeof(*res), GFP_ATOMIC);
+		if (!res) {
+			ret = -ENOMEM;
+			goto free_ranges;
+		}
+
+		res->name = "hyperv mmio";
+		res->flags = IORESOURCE_MEM | IORESOURCE_MEM_64;
+		res->start = start;
+		res->end = start + len;
+
+		*cur_res = res;
+		cur_res = &res->sibling;
+	}
+
+free_ranges:
+	kfree(ranges);
+	return ret;
+}
+#endif
 
 static int vmbus_platform_driver_probe(struct platform_device *pdev)
 {
+#ifdef CONFIG_ACPI
 	return vmbus_acpi_add(pdev);
+#else
+	return vmbus_device_add(pdev);
+#endif
 }
 
 static int vmbus_platform_driver_remove(struct platform_device *pdev)
@@ -2645,6 +2705,16 @@ static int vmbus_bus_resume(struct device *dev)
 #define vmbus_bus_resume NULL
 #endif /* CONFIG_PM_SLEEP */
 
+static const struct of_device_id vmbus_of_match[] = {
+	{
+		.compatible = "msft,vmbus",
+	},
+	{
+		/* sentinel */
+	},
+};
+MODULE_DEVICE_TABLE(of, vmbus_of_match);
+
 static const struct acpi_device_id vmbus_acpi_device_ids[] = {
 	{"VMBUS", 0},
 	{"VMBus", 0},
@@ -2679,6 +2749,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.25.1


  parent reply	other threads:[~2023-01-31 18:10 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31 18:10 [PATCH v2 0/6] Device tree support for Hyper-V VMBus driver Saurabh Sengar
2023-01-31 18:10 ` [PATCH v2 1/6] drivers/clocksource/hyper-v: non ACPI support in hyperv clock Saurabh Sengar
2023-01-31 18:10 ` [PATCH v2 2/6] Drivers: hv: allow non ACPI compilation for hv_is_hibernation_supported Saurabh Sengar
2023-02-01 17:47   ` Michael Kelley (LINUX)
2023-02-02 14:48     ` Saurabh Singh Sengar
2023-02-02 15:33       ` Michael Kelley (LINUX)
2023-01-31 18:10 ` [PATCH v2 3/6] Drivers: hv: vmbus: Convert acpi_device to platform_device Saurabh Sengar
2023-02-01 18:32   ` Michael Kelley (LINUX)
2023-02-02 15:27     ` Saurabh Singh Sengar
2023-02-03  5:32     ` Saurabh Singh Sengar
2023-01-31 18:10 ` [PATCH v2 4/6] dt-bindings: hypervisor: Rename virtio to hypervisor Saurabh Sengar
2023-01-31 19:57   ` Rob Herring
2023-02-01  5:36     ` Saurabh Singh Sengar
2023-01-31 18:10 ` [PATCH v2 5/6] dt-bindings: hypervisor: Add dt-bindings for VMBus Saurabh Sengar
2023-01-31 18:51   ` Krzysztof Kozlowski
2023-02-01  1:39     ` Saurabh Singh Sengar
2023-01-31 18:54   ` Krzysztof Kozlowski
2023-02-01  1:57     ` Saurabh Singh Sengar
2023-02-01  7:23       ` Krzysztof Kozlowski
2023-02-01  8:05         ` Saurabh Singh Sengar
2023-01-31 18:10 ` Saurabh Sengar [this message]
2023-01-31 20:12   ` [PATCH v2 6/6] Driver: VMBus: Add device tree support Rob Herring
2023-02-01 16:51     ` Saurabh Singh Sengar
2023-02-01 17:46       ` Rob Herring
2023-02-01 18:31         ` Saurabh Singh Sengar
2023-02-03 17:36         ` Saurabh Singh Sengar
2023-02-07 17:38           ` Rob Herring
2023-02-08  2:30             ` Saurabh Singh Sengar
2023-01-31 20:27 ` [PATCH v2 0/6] Device tree support for Hyper-V VMBus driver Rob Herring
2023-02-01  2:04   ` Saurabh Singh Sengar
2023-02-01 14:51     ` Rob Herring
2023-02-01 16:34       ` Saurabh Singh Sengar
2023-02-01 17:15         ` Krzysztof Kozlowski
2023-02-06 17:40           ` Saurabh Singh Sengar
2023-02-07 17:53         ` Rob Herring
2023-02-08  2:44           ` Saurabh Singh Sengar
2023-02-07 18:37     ` Sudeep Holla

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=1675188609-20913-7-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=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=ssengar@microsoft.com \
    --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).