diff mbox

[8/8] acpi: Use booleans when probing different _DSM types

Message ID 1432592573-13743-8-git-send-email-pierre.morrow@free.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Pierre Moreau May 25, 2015, 10:22 p.m. UTC
Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Pierre Moreau May 26, 2015, 12:46 p.m. UTC | #1
I'm thinking of re-writing this patch to just OR the different returned retval and test for individual bits directly in the final conditionals.
So this would give something like:


int retval = 0;

while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
	vga_count++;
	retval |= nouveau_dsm_pci_probe(pdev);
}
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
	vga_count++;
	retval |= nouveau_dsm_pci_probe(pdev);
}

if (retval & NOUVEAU_DSM_HAS_OPT) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.optimus_detected = true;
	ret = true;
} else if (vga_count == 2 && (retval & NOUVEAU_DSM_HAS_MUX) && guid_valid) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.mux_detected = true;
	ret = true;
} else if (retval & NOUVEAU_DSM_HAS_GMUX) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.gmux_detected = true;
	ret = true;
}


Any opinions on this?

Pierre

----- Mail original -----
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>  drm/nouveau/nouveau_acpi.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 3d6a1ea..5d63621 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
>  	char acpi_method_name[255] = { 0 };
>  	struct acpi_buffer buffer = {sizeof(acpi_method_name),
>  	acpi_method_name};
>  	struct pci_dev *pdev = NULL;
> -	int has_dsm = 0;
> -	int has_optimus = 0;
> +	bool has_mux = false;
> +	bool has_optimus = false;
>  	bool has_gmux = false;
>  	int vga_count = 0;
>  	bool guid_valid;
> @@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
>  
>  		retval = nouveau_dsm_pci_probe(pdev);
>  		if (retval & NOUVEAU_DSM_HAS_MUX)
> -			has_dsm |= 1;
> +			has_mux = true;
>  		if (retval & NOUVEAU_DSM_HAS_OPT)
> -			has_optimus = 1;
> +			has_optimus = true;
>  		if (retval & NOUVEAU_DSM_HAS_GMUX)
>  			has_gmux = true;
>  	}
> @@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
>  
>  		retval = nouveau_dsm_pci_probe(pdev);
>  		if (retval & NOUVEAU_DSM_HAS_MUX)
> -			has_dsm |= 1;
> +			has_mux = true;
>  		if (retval & NOUVEAU_DSM_HAS_OPT)
> -			has_optimus = 1;
> +			has_optimus = true;
>  		if (retval & NOUVEAU_DSM_HAS_GMUX)
>  			has_gmux = true;
>  	}
> @@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
>  			acpi_method_name);
>  		nouveau_dsm_priv.optimus_detected = true;
>  		ret = true;
> -	} else if (vga_count == 2 && has_dsm && guid_valid) {
> +	} else if (vga_count == 2 && has_mux && guid_valid) {
>  		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>  			&buffer);
>  		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching
>  		method %s handle\n",
> --
> 2.4.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
Samuel Pitoiset May 26, 2015, 8:42 p.m. UTC | #2
On 05/26/2015 02:46 PM, Pierre Moreau wrote:
> I'm thinking of re-writing this patch to just OR the different returned retval and test for individual bits directly in the final conditionals.
> So this would give something like:
>
>
> int retval = 0;
>
> while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
> 	vga_count++;
> 	retval |= nouveau_dsm_pci_probe(pdev);
> }
> while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
> 	vga_count++;
> 	retval |= nouveau_dsm_pci_probe(pdev);
> }
>
> if (retval & NOUVEAU_DSM_HAS_OPT) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.optimus_detected = true;
> 	ret = true;
> } else if (vga_count == 2 && (retval & NOUVEAU_DSM_HAS_MUX) && guid_valid) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.mux_detected = true;
> 	ret = true;
> } else if (retval & NOUVEAU_DSM_HAS_GMUX) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.gmux_detected = true;
> 	ret = true;
> }
>
>
> Any opinions on this?

If this improves readability of the code, go ahead.

>
> Pierre
>
> ----- Mail original -----
>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>> ---
>>   drm/nouveau/nouveau_acpi.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>> index 3d6a1ea..5d63621 100644
>> --- a/drm/nouveau/nouveau_acpi.c
>> +++ b/drm/nouveau/nouveau_acpi.c
>> @@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
>>   	char acpi_method_name[255] = { 0 };
>>   	struct acpi_buffer buffer = {sizeof(acpi_method_name),
>>   	acpi_method_name};
>>   	struct pci_dev *pdev = NULL;
>> -	int has_dsm = 0;
>> -	int has_optimus = 0;
>> +	bool has_mux = false;
>> +	bool has_optimus = false;
>>   	bool has_gmux = false;
>>   	int vga_count = 0;
>>   	bool guid_valid;
>> @@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
>>   
>>   		retval = nouveau_dsm_pci_probe(pdev);
>>   		if (retval & NOUVEAU_DSM_HAS_MUX)
>> -			has_dsm |= 1;
>> +			has_mux = true;
>>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>> -			has_optimus = 1;
>> +			has_optimus = true;
>>   		if (retval & NOUVEAU_DSM_HAS_GMUX)
>>   			has_gmux = true;
>>   	}
>> @@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
>>   
>>   		retval = nouveau_dsm_pci_probe(pdev);
>>   		if (retval & NOUVEAU_DSM_HAS_MUX)
>> -			has_dsm |= 1;
>> +			has_mux = true;
>>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>> -			has_optimus = 1;
>> +			has_optimus = true;
>>   		if (retval & NOUVEAU_DSM_HAS_GMUX)
>>   			has_gmux = true;
>>   	}
>> @@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
>>   			acpi_method_name);
>>   		nouveau_dsm_priv.optimus_detected = true;
>>   		ret = true;
>> -	} else if (vga_count == 2 && has_dsm && guid_valid) {
>> +	} else if (vga_count == 2 && has_mux && guid_valid) {
>>   		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>>   			&buffer);
>>   		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching
>>   		method %s handle\n",
>> --
>> 2.4.1
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>>
> _______________________________________________
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nouveau
diff mbox

Patch

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 3d6a1ea..5d63621 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -297,8 +297,8 @@  static bool nouveau_dsm_detect(void)
 	char acpi_method_name[255] = { 0 };
 	struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
 	struct pci_dev *pdev = NULL;
-	int has_dsm = 0;
-	int has_optimus = 0;
+	bool has_mux = false;
+	bool has_optimus = false;
 	bool has_gmux = false;
 	int vga_count = 0;
 	bool guid_valid;
@@ -317,9 +317,9 @@  static bool nouveau_dsm_detect(void)
 
 		retval = nouveau_dsm_pci_probe(pdev);
 		if (retval & NOUVEAU_DSM_HAS_MUX)
-			has_dsm |= 1;
+			has_mux = true;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
-			has_optimus = 1;
+			has_optimus = true;
 		if (retval & NOUVEAU_DSM_HAS_GMUX)
 			has_gmux = true;
 	}
@@ -329,9 +329,9 @@  static bool nouveau_dsm_detect(void)
 
 		retval = nouveau_dsm_pci_probe(pdev);
 		if (retval & NOUVEAU_DSM_HAS_MUX)
-			has_dsm |= 1;
+			has_mux = true;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
-			has_optimus = 1;
+			has_optimus = true;
 		if (retval & NOUVEAU_DSM_HAS_GMUX)
 			has_gmux = true;
 	}
@@ -344,7 +344,7 @@  static bool nouveau_dsm_detect(void)
 			acpi_method_name);
 		nouveau_dsm_priv.optimus_detected = true;
 		ret = true;
-	} else if (vga_count == 2 && has_dsm && guid_valid) {
+	} else if (vga_count == 2 && has_mux && guid_valid) {
 		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
 			&buffer);
 		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",