Skip to contentSkip to conversation

hyperv-fb: add support for generation 2 virtual machines

PATCH In review Gerd Hoffmann 3 participants 8 messages Feb 26, 2014 – Feb 28, 2014 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

v5 cover hyperv-fb: add support for generation 2 virtual machines

Hi,

This patch series adds support for uefi-based gen2 virtual machines to the hyperv-fb driver. It depends on a few vmbus changes which are staged in Greg's char-misc tree (and linux-next).

Patch #1 implements gen2 vm support for hyperv-fb.

Patch #2 unregisters efifb early to make sure the framebuffer isn't used any more while hyperv-fb initialization is in progress.

v5 changes:
- call remove_conflicting_framebuffers() only on gen2 virtual machines.

v4 changes:
- use KBUILD_MODNAME everywhere for consistent naming.
- drop the two patches which Greg has staged in char-misc.

please apply,
Gerd

Gerd Hoffmann (2):
hyperv-fb: add support for generation 2 virtual machines.
hyperv-fb: kick off efifb early

 drivers/video/hyperv_fb.c | 88 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 62 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v5 1/2 hyperv-fb: add support for generation 2 virtual machines.

UEFI-based generation 2 virtual machines support vmbus devices only. There is no pci bus. Thus they use a different mechanism for the graphics framebuffer: Instead of using the vga pci bar a chunk of memory muct be allocated from the hyperv mmio region declared using APCI. This patch implements support for it.

Based on a patch by Haiyang Zhang <[email protected]>

---
 drivers/video/hyperv_fb.c | 86 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 60 insertions(+), 26 deletions(-)
drivers/video/hyperv_fb.c +60 -26
index 130708f..b7b3dd0 100644
@@ -42,6 +42,7 @@
 #include <linux/completion.h>
 #include <linux/fb.h>
 #include <linux/pci.h>
+#include <linux/efi.h>
 
 #include <linux/hyperv.h>
 
@@ -212,6 +213,7 @@ struct synthvid_msg {
 
 struct hvfb_par {
 	struct fb_info *info;
+	struct resource mem;
 	bool fb_ready; /* fb device is ready */
 	struct completion wait;
 	u32 synthvid_version;
@@ -460,13 +462,13 @@ static int synthvid_connect_vsp(struct hv_device *hdev)
 		goto error;
 	}
 
-	if (par->synthvid_version = SYNTHVID_VERSION_WIN7) {
+	if (par->synthvid_version = SYNTHVID_VERSION_WIN7)
 		screen_depth = SYNTHVID_DEPTH_WIN7;
-		screen_fb_size = SYNTHVID_FB_SIZE_WIN7;
-	} else {
+	else
 		screen_depth = SYNTHVID_DEPTH_WIN8;
-		screen_fb_size = SYNTHVID_FB_SIZE_WIN8;
-	}
+
+	screen_fb_size = hdev->channel->offermsg.offer.
+				mmio_megabytes * 1024 * 1024;
 
 	return 0;
 
@@ -627,26 +629,46 @@ static void hvfb_get_option(struct fb_info *info)
 /* Get framebuffer memory from Hyper-V video pci space */
 static int hvfb_getmem(struct fb_info *info)
 {
-	struct pci_dev *pdev;
-	ulong fb_phys;
+	struct hvfb_par *par = info->par;
+	struct pci_dev *pdev  = NULL;
 	void __iomem *fb_virt;
+	int gen2vm = efi_enabled(EFI_BOOT);
+	int ret;
 
-	pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
+	par->mem.name = KBUILD_MODNAME;
+	par->mem.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	if (gen2vm) {
+		ret = allocate_resource(&hyperv_mmio, &par->mem,
+					screen_fb_size,
+					0, -1,
+					screen_fb_size,
+					NULL, NULL);
+		if (ret != 0) {
+			pr_err("Unable to allocate framebuffer memory\n");
+			return -ENODEV;
+		}
+	} else {
+		pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
 			      PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
-	if (!pdev) {
-		pr_err("Unable to find PCI Hyper-V video\n");
-		return -ENODEV;
-	}
+		if (!pdev) {
+			pr_err("Unable to find PCI Hyper-V video\n");
+			return -ENODEV;
+		}
 
-	if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
-	    pci_resource_len(pdev, 0) < screen_fb_size)
-		goto err1;
+		if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
+		    pci_resource_len(pdev, 0) < screen_fb_size)
+			goto err1;
 
-	fb_phys = pci_resource_end(pdev, 0) - screen_fb_size + 1;
-	if (!request_mem_region(fb_phys, screen_fb_size, KBUILD_MODNAME))
-		goto err1;
+		par->mem.end = pci_resource_end(pdev, 0);
+		par->mem.start = par->mem.end - screen_fb_size + 1;
+		ret = request_resource(&pdev->resource[0], &par->mem);
+		if (ret != 0) {
+			pr_err("Unable to request framebuffer memory\n");
+			goto err1;
+		}
+	}
 
-	fb_virt = ioremap(fb_phys, screen_fb_size);
+	fb_virt = ioremap(par->mem.start, screen_fb_size);
 	if (!fb_virt)
 		goto err2;
 
@@ -654,30 +676,42 @@ static int hvfb_getmem(struct fb_info *info)
 	if (!info->apertures)
 		goto err3;
 
-	info->apertures->ranges[0].base = pci_resource_start(pdev, 0);
-	info->apertures->ranges[0].size = pci_resource_len(pdev, 0);
-	info->fix.smem_start = fb_phys;
+	if (gen2vm) {
+		info->apertures->ranges[0].base = screen_info.lfb_base;
+		info->apertures->ranges[0].size = screen_info.lfb_size;
+	} else {
+		info->apertures->ranges[0].base = pci_resource_start(pdev, 0);
+		info->apertures->ranges[0].size = pci_resource_len(pdev, 0);
+	}
+
+	info->fix.smem_start = par->mem.start;
 	info->fix.smem_len = screen_fb_size;
 	info->screen_base = fb_virt;
 	info->screen_size = screen_fb_size;
 
-	pci_dev_put(pdev);
+	if (!gen2vm)
+		pci_dev_put(pdev);
+
 	return 0;
 
 err3:
 	iounmap(fb_virt);
 err2:
-	release_mem_region(fb_phys, screen_fb_size);
+	release_resource(&par->mem);
 err1:
-	pci_dev_put(pdev);
+	if (!gen2vm)
+		pci_dev_put(pdev);
+
 	return -ENOMEM;
 }
 
 /* Release the framebuffer */
 static void hvfb_putmem(struct fb_info *info)
 {
+	struct hvfb_par *par = info->par;
+
 	iounmap(info->screen_base);
-	release_mem_region(info->fix.smem_start, screen_fb_size);
+	release_resource(&par->mem);
 }
 
 
Signature · 1 line
1.8.3.1
#2 lore raw

RE: [PATCH v5 1/2] hyperv-fb: add support for generation 2 virtual machines.

Quoted 20 lines

-----Original Message-----
From: [email protected] [mailto:linux-fbdev- [email protected]] On Behalf Of Gerd Hoffmann
Sent: Wednesday, February 26, 2014 5:51 AM
To: [email protected]
Cc: [email protected]; [email protected]; KY Srinivasan; Abhishek Gupta (LIS); Haiyang Zhang; [email protected]; [email protected]; [email protected]; Gerd Hoffmann; Jean- Christophe Plagniol-Villard
Subject: [PATCH v5 1/2] hyperv-fb: add support for generation 2 virtual machines.

UEFI-based generation 2 virtual machines support vmbus devices only. There is no pci bus. Thus they use a different mechanism for the graphics framebuffer: Instead of using the vga pci bar a chunk of memory muct be allocated from the hyperv mmio region declared using APCI. This patch implements support for it.

Quoted 3 lines

Based on a patch by Haiyang Zhang <[email protected]>

Thank you!

#3 lore raw

PATCH v5 2/2 hyperv-fb: kick off efifb early

In reply to Gerd Hoffmann

Remove firmware framebuffer before initializing hyperv-fb. Needed
on gen2 virtual machines. Letting register_framebuffer handle the
switchover results in efifb still being active while hyperv graphics are initialized, which in turn can make the linux kernel hang.

---
 drivers/video/hyperv_fb.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/video/hyperv_fb.c +2 -0
index b7b3dd0..e23392e 100644
@@ -679,6 +679,8 @@ static int hvfb_getmem(struct fb_info *info)
 	if (gen2vm) {
 		info->apertures->ranges[0].base = screen_info.lfb_base;
 		info->apertures->ranges[0].size = screen_info.lfb_size;
+		remove_conflicting_framebuffers(info->apertures,
+						KBUILD_MODNAME, false);
 	} else {
 		info->apertures->ranges[0].base = pci_resource_start(pdev, 0);
 		info->apertures->ranges[0].size = pci_resource_len(pdev, 0);
Signature · 1 line
1.8.3.1
#4 lore raw

RE: [PATCH v5 2/2] hyperv-fb: kick off efifb early

Quoted 12 lines

-----Original Message-----
From: Gerd Hoffmann [mailto:[email protected]]
Sent: Wednesday, February 26, 2014 5:51 AM
To: [email protected]
Cc: [email protected]; [email protected]; KY Srinivasan; Abhishek Gupta (LIS); Haiyang Zhang; [email protected]; [email protected]; [email protected]; Gerd Hoffmann; Jean- Christophe Plagniol-Villard
Subject: [PATCH v5 2/2] hyperv-fb: kick off efifb early

Quoted 6 lines

Remove firmware framebuffer before initializing hyperv-fb. Needed
on gen2 virtual machines. Letting register_framebuffer handle the
switchover results in efifb still being active while hyperv graphics are initialized, which in turn can make the linux kernel hang.

Thank you!

#5 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann

Hi,

This patch series adds support for uefi-based gen2 virtual machines to the hyperv-fb driver. It depends on a few vmbus changes which are staged in Greg's char-misc tree (and linux-next).

Depends how? Patches that depend on other patches should be merged via the same tree to avoid compile or functional breaks.

Tomi

#6 lore raw
Quoted 8 lines · Tomi Valkeinen
Quoted 5 lines · Gerd Hoffmann

Hi,

This patch series adds support for uefi-based gen2 virtual machines to the hyperv-fb driver. It depends on a few vmbus changes which are staged in Greg's char-misc tree (and linux-next).

Depends how?

Will fail to build without the vmbus patches.

Quoted 2 lines

Patches that depend on other patches should be merged via the same tree to avoid compile or functional breaks.

I think Greg will happily merge them through char-misc if he gets your fbdev maintainer ACK for the patches.

cheers,
Gerd

#7 lore raw
Quoted 10 lines · Gerd Hoffmann
Quoted 8 lines · Tomi Valkeinen
Quoted 5 lines · Gerd Hoffmann

Hi,

This patch series adds support for uefi-based gen2 virtual machines to the hyperv-fb driver. It depends on a few vmbus changes which are staged in Greg's char-misc tree (and linux-next).

Depends how?

Quoted 7 lines

Will fail to build without the vmbus patches.

Quoted 2 lines

Patches that depend on other patches should be merged via the same tree to avoid compile or functional breaks.

I think Greg will happily merge them through char-misc if he gets your fbdev maintainer ACK for the patches.

Ok. It's usually good to mention if only an ack is needed (and from whom). You did send this to fbdev, and said "please apply". So I already applied it, until I realized you said there are dependencies.

So:

Tomi