[v4,6/6] Driver: VMBus: Add device tree support

Message ID 1675756199-5917-7-git-send-email-ssengar@linux.microsoft.com
State New
Headers
Series Device tree support for Hyper-V VMBus driver |

Commit Message

Saurabh Singh Sengar Feb. 7, 2023, 7:49 a.m. UTC
  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>
---
[V4]
- used __maybe_unused for 'vmbus_of_match' and safeguard vmbus_acpi_device_ids
  under #ifdef

 drivers/hv/Kconfig     |  4 ++--
 drivers/hv/vmbus_drv.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 4 deletions(-)
  

Comments

kernel test robot Feb. 8, 2023, 8:22 a.m. UTC | #1
Hi Saurabh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20230207]
[cannot apply to robh/for-next tip/timers/core brgl/gpio/for-next wsa/i2c/for-next linus/master v6.2-rc7 v6.2-rc6 v6.2-rc5 v6.2-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Saurabh-Sengar/drivers-clocksource-hyper-v-non-ACPI-support-in-hyperv-clock/20230207-155113
patch link:    https://lore.kernel.org/r/1675756199-5917-7-git-send-email-ssengar%40linux.microsoft.com
patch subject: [PATCH v4 6/6] Driver: VMBus: Add device tree support
config: i386-randconfig-a015 (https://download.01.org/0day-ci/archive/20230208/202302081621.odizDzHG-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/b3cd029f78e9c1f5cd1633e1ffc7c5a09deae98f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Saurabh-Sengar/drivers-clocksource-hyper-v-non-ACPI-support-in-hyperv-clock/20230207-155113
        git checkout b3cd029f78e9c1f5cd1633e1ffc7c5a09deae98f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/hv/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/hv/vmbus_drv.c:2691:21: warning: attribute declaration must precede definition [-Wignored-attributes]
   static const struct __maybe_unused of_device_id vmbus_of_match[] = {
                       ^
   include/linux/compiler_attributes.h:355:56: note: expanded from macro '__maybe_unused'
   #define __maybe_unused                  __attribute__((__unused__))
                                                          ^
   include/linux/mod_devicetable.h:268:8: note: previous definition is here
   struct of_device_id {
          ^
   1 warning generated.


vim +2691 drivers/hv/vmbus_drv.c

  2690	
> 2691	static const struct __maybe_unused of_device_id vmbus_of_match[] = {
  2692		{
  2693			.compatible = "microsoft,vmbus",
  2694		},
  2695		{
  2696			/* sentinel */
  2697		},
  2698	};
  2699	MODULE_DEVICE_TABLE(of, vmbus_of_match);
  2700
  
Krzysztof Kozlowski Feb. 8, 2023, 10:25 a.m. UTC | #2
On 08/02/2023 09:22, kernel test robot wrote:
> Hi Saurabh,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on next-20230207]
> [cannot apply to robh/for-next tip/timers/core brgl/gpio/for-next wsa/i2c/for-next linus/master v6.2-rc7 v6.2-rc6 v6.2-rc5 v6.2-rc7]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 

All of your recent patches have build errors. Can you at least build
test them before sending? It's a unnecessary noise in our mailboxes to
get non-buildable patches, just to trigger compilation which you can
easily do by your own. GCC is a free software...

Best regards,
Krzysztof
  
Nathan Chancellor Feb. 8, 2023, 2:39 p.m. UTC | #3
On Wed, Feb 08, 2023 at 11:25:57AM +0100, Krzysztof Kozlowski wrote:
> On 08/02/2023 09:22, kernel test robot wrote:
> > Hi Saurabh,
> > 
> > Thank you for the patch! Perhaps something to improve:
> > 
> > [auto build test WARNING on next-20230207]
> > [cannot apply to robh/for-next tip/timers/core brgl/gpio/for-next wsa/i2c/for-next linus/master v6.2-rc7 v6.2-rc6 v6.2-rc5 v6.2-rc7]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> > 
> 
> All of your recent patches have build errors. Can you at least build
> test them before sending? It's a unnecessary noise in our mailboxes to
> get non-buildable patches, just to trigger compilation which you can
> easily do by your own. GCC is a free software...

For what it's worth, GCC does not have a warning like this, it just
accepts the incorrect location of the attribute, which has gotten others
in trouble before:

https://lore.kernel.org/CAHk-=wgf+kHeSZbpkZumWcTXUD7ordqTMvPRNL6aQVG1DSBDnQ@mail.gmail.com/

So the patch probably did build clean with GCC but that is one of the
reasons that there is no longer a compiler monopoly for the kernel ;)

Cheers,
Nathan
  
Krzysztof Kozlowski Feb. 8, 2023, 3:36 p.m. UTC | #4
On 08/02/2023 15:39, Nathan Chancellor wrote:
> On Wed, Feb 08, 2023 at 11:25:57AM +0100, Krzysztof Kozlowski wrote:
>> On 08/02/2023 09:22, kernel test robot wrote:
>>> Hi Saurabh,
>>>
>>> Thank you for the patch! Perhaps something to improve:
>>>
>>> [auto build test WARNING on next-20230207]
>>> [cannot apply to robh/for-next tip/timers/core brgl/gpio/for-next wsa/i2c/for-next linus/master v6.2-rc7 v6.2-rc6 v6.2-rc5 v6.2-rc7]
>>> [If your patch is applied to the wrong git tree, kindly drop us a note.
>>> And when submitting patch, we suggest to use '--base' as documented in
>>> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>>>
>>
>> All of your recent patches have build errors. Can you at least build
>> test them before sending? It's a unnecessary noise in our mailboxes to
>> get non-buildable patches, just to trigger compilation which you can
>> easily do by your own. GCC is a free software...
> 
> For what it's worth, GCC does not have a warning like this, it just
> accepts the incorrect location of the attribute, which has gotten others
> in trouble before:
> 
> https://lore.kernel.org/CAHk-=wgf+kHeSZbpkZumWcTXUD7ordqTMvPRNL6aQVG1DSBDnQ@mail.gmail.com/
> 
> So the patch probably did build clean with GCC but that is one of the
> reasons that there is no longer a compiler monopoly for the kernel ;)

OK then the patchset is reasonable/built enough.

Best regards,
Krzysztof
  

Patch

diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 0747a8f..7e44d42 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -4,8 +4,8 @@  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
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 7349715..1774cae 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,52 @@  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 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;
+}
+#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)
@@ -2643,12 +2688,24 @@  static int vmbus_bus_resume(struct device *dev)
 #define vmbus_bus_resume NULL
 #endif /* CONFIG_PM_SLEEP */
 
+static const struct __maybe_unused 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 +2734,7 @@  static int vmbus_bus_resume(struct device *dev)
 	.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,
 	}