diff mbox series

[1/1] vgaarb: Use ACPI HID name to find integrated GPU

Message ID 20210521130718.1030487-2-kai.heng.feng@canonical.com
State New
Headers show
Series Select correct boot VGA when BIOS doesn't do it properly | expand

Commit Message

Kai-Heng Feng May 21, 2021, 1:07 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/1929217

Commit 3d42f1ddc47a ("vgaarb: Keep adding VGA device in queue") assumes
the first device is an integrated GPU. However, on AMD platforms an
integrated GPU can have higher PCI device number than a discrete GPU.

Integrated GPU on ACPI platform generally has _DOD and _DOS method, so
use that as predicate to find integrated GPU. If the new strategy
doesn't work, fallback to use the first device as boot VGA.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210519135723.525997-1-kai.heng.feng@canonical.com
(cherry picked from commit 808a4ae5fa7dfba286a274e729e40522500c57fe linux-next)
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/gpu/vga/vgaarb.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

Comments

Krzysztof Kozlowski May 21, 2021, 2:35 p.m. UTC | #1
On 21/05/2021 09:07, Kai-Heng Feng wrote:
> BugLink: https://bugs.launchpad.net/bugs/1929217
> 
> Commit 3d42f1ddc47a ("vgaarb: Keep adding VGA device in queue") assumes
> the first device is an integrated GPU. However, on AMD platforms an
> integrated GPU can have higher PCI device number than a discrete GPU.
> 
> Integrated GPU on ACPI platform generally has _DOD and _DOS method, so
> use that as predicate to find integrated GPU. If the new strategy
> doesn't work, fallback to use the first device as boot VGA.
> 
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> Link: https://patchwork.freedesktop.org/patch/msgid/20210519135723.525997-1-kai.heng.feng@canonical.com
> (cherry picked from commit 808a4ae5fa7dfba286a274e729e40522500c57fe linux-next)
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  drivers/gpu/vga/vgaarb.c | 31 ++++++++++++++++++++++++++-----
>  1 file changed, 26 insertions(+), 5 deletions(-)
> 


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

Best regards,
Krzysztof
Kleber Sacilotto de Souza May 27, 2021, 12:19 p.m. UTC | #2
On 21.05.21 15:07, Kai-Heng Feng wrote:
> BugLink: https://bugs.launchpad.net/bugs/1929217
> 
> Commit 3d42f1ddc47a ("vgaarb: Keep adding VGA device in queue") assumes
> the first device is an integrated GPU. However, on AMD platforms an
> integrated GPU can have higher PCI device number than a discrete GPU.
> 
> Integrated GPU on ACPI platform generally has _DOD and _DOS method, so
> use that as predicate to find integrated GPU. If the new strategy
> doesn't work, fallback to use the first device as boot VGA.
> 
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> Link: https://patchwork.freedesktop.org/patch/msgid/20210519135723.525997-1-kai.heng.feng@canonical.com
> (cherry picked from commit 808a4ae5fa7dfba286a274e729e40522500c57fe linux-next)
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

Thanks

> ---
>   drivers/gpu/vga/vgaarb.c | 31 ++++++++++++++++++++++++++-----
>   1 file changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 5180c5687ee5..949fde433ea2 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -50,6 +50,7 @@
>   #include <linux/screen_info.h>
>   #include <linux/vt.h>
>   #include <linux/console.h>
> +#include <linux/acpi.h>
>   
>   #include <linux/uaccess.h>
>   
> @@ -1450,9 +1451,23 @@ static struct miscdevice vga_arb_device = {
>   	MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops
>   };
>   
> +#if defined(CONFIG_ACPI)
> +static bool vga_arb_integrated_gpu(struct device *dev)
> +{
> +	struct acpi_device *adev = ACPI_COMPANION(dev);
> +
> +	return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID);
> +}
> +#else
> +static bool vga_arb_integrated_gpu(struct device *dev)
> +{
> +	return false;
> +}
> +#endif
> +
>   static void __init vga_arb_select_default_device(void)
>   {
> -	struct pci_dev *pdev;
> +	struct pci_dev *pdev, *found = NULL;
>   	struct vga_device *vgadev;
>   
>   #if defined(CONFIG_X86) || defined(CONFIG_IA64)
> @@ -1505,20 +1520,26 @@ static void __init vga_arb_select_default_device(void)
>   #endif
>   
>   	if (!vga_default_device()) {
> -		list_for_each_entry(vgadev, &vga_list, list) {
> +		list_for_each_entry_reverse(vgadev, &vga_list, list) {
>   			struct device *dev = &vgadev->pdev->dev;
>   			u16 cmd;
>   
>   			pdev = vgadev->pdev;
>   			pci_read_config_word(pdev, PCI_COMMAND, &cmd);
>   			if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
> -				vgaarb_info(dev, "setting as boot device (VGA legacy resources not available)\n");
> -				vga_set_default_device(pdev);
> -				break;
> +				found = pdev;
> +				if (vga_arb_integrated_gpu(dev))
> +					break;
>   			}
>   		}
>   	}
>   
> +	if (found) {
> +		vgaarb_info(&found->dev, "setting as boot device (VGA legacy resources not available)\n");
> +		vga_set_default_device(found);
> +		return;
> +	}
> +
>   	if (!vga_default_device()) {
>   		vgadev = list_first_entry_or_null(&vga_list,
>   						  struct vga_device, list);
>
diff mbox series

Patch

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 5180c5687ee5..949fde433ea2 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -50,6 +50,7 @@ 
 #include <linux/screen_info.h>
 #include <linux/vt.h>
 #include <linux/console.h>
+#include <linux/acpi.h>
 
 #include <linux/uaccess.h>
 
@@ -1450,9 +1451,23 @@  static struct miscdevice vga_arb_device = {
 	MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops
 };
 
+#if defined(CONFIG_ACPI)
+static bool vga_arb_integrated_gpu(struct device *dev)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+
+	return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID);
+}
+#else
+static bool vga_arb_integrated_gpu(struct device *dev)
+{
+	return false;
+}
+#endif
+
 static void __init vga_arb_select_default_device(void)
 {
-	struct pci_dev *pdev;
+	struct pci_dev *pdev, *found = NULL;
 	struct vga_device *vgadev;
 
 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
@@ -1505,20 +1520,26 @@  static void __init vga_arb_select_default_device(void)
 #endif
 
 	if (!vga_default_device()) {
-		list_for_each_entry(vgadev, &vga_list, list) {
+		list_for_each_entry_reverse(vgadev, &vga_list, list) {
 			struct device *dev = &vgadev->pdev->dev;
 			u16 cmd;
 
 			pdev = vgadev->pdev;
 			pci_read_config_word(pdev, PCI_COMMAND, &cmd);
 			if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
-				vgaarb_info(dev, "setting as boot device (VGA legacy resources not available)\n");
-				vga_set_default_device(pdev);
-				break;
+				found = pdev;
+				if (vga_arb_integrated_gpu(dev))
+					break;
 			}
 		}
 	}
 
+	if (found) {
+		vgaarb_info(&found->dev, "setting as boot device (VGA legacy resources not available)\n");
+		vga_set_default_device(found);
+		return;
+	}
+
 	if (!vga_default_device()) {
 		vgadev = list_first_entry_or_null(&vga_list,
 						  struct vga_device, list);