linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/PCI: simplify pci_bios_{read,write}
@ 2015-12-07 13:42 Geliang Tang
  2015-12-08 12:16 ` Thomas Gleixner
  2015-12-09 16:50 ` Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: Geliang Tang @ 2015-12-07 13:42 UTC (permalink / raw)
  To: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
  Cc: Geliang Tang, x86, linux-pci, linux-kernel

There are some repetitive code in the switch/case statement in
pci_bios_read() and pci_bios_write(). I drop it to simplify the
code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 arch/x86/pci/pcbios.c | 108 ++++++++++++++++++--------------------------------
 1 file changed, 38 insertions(+), 70 deletions(-)

diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
index 9b83b90..9770e55 100644
--- a/arch/x86/pci/pcbios.c
+++ b/arch/x86/pci/pcbios.c
@@ -180,6 +180,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
 	unsigned long result = 0;
 	unsigned long flags;
 	unsigned long bx = (bus << 8) | devfn;
+	u16 number = 0, mask = 0;
 
 	WARN_ON(seg);
 	if (!value || (bus > 255) || (devfn > 255) || (reg > 255))
@@ -189,53 +190,35 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
 
 	switch (len) {
 	case 1:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=c" (*value),
-			  "=a" (result)
-			: "1" (PCIBIOS_READ_CONFIG_BYTE),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
-		/*
-		 * Zero-extend the result beyond 8 bits, do not trust the
-		 * BIOS having done it:
-		 */
-		*value &= 0xff;
+		number = PCIBIOS_READ_CONFIG_BYTE;
+		mask = 0xff;
 		break;
 	case 2:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=c" (*value),
-			  "=a" (result)
-			: "1" (PCIBIOS_READ_CONFIG_WORD),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
-		/*
-		 * Zero-extend the result beyond 16 bits, do not trust the
-		 * BIOS having done it:
-		 */
-		*value &= 0xffff;
+		number = PCIBIOS_READ_CONFIG_WORD;
+		mask = 0xffff;
 		break;
 	case 4:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=c" (*value),
-			  "=a" (result)
-			: "1" (PCIBIOS_READ_CONFIG_DWORD),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
+		number = PCIBIOS_READ_CONFIG_DWORD;
 		break;
 	}
 
+	__asm__("lcall *(%%esi); cld\n\t"
+		"jc 1f\n\t"
+		"xor %%ah, %%ah\n"
+		"1:"
+		: "=c" (*value),
+		  "=a" (result)
+		: "1" (number),
+		  "b" (bx),
+		  "D" ((long)reg),
+		  "S" (&pci_indirect));
+	/*
+	 * Zero-extend the result beyond 8 or 16 bits, do not trust the
+	 * BIOS having done it:
+	 */
+	if (mask)
+		*value &= mask;
+
 	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
 
 	return (int)((result & 0xff00) >> 8);
@@ -247,6 +230,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
 	unsigned long result = 0;
 	unsigned long flags;
 	unsigned long bx = (bus << 8) | devfn;
+	u16 number = 0;
 
 	WARN_ON(seg);
 	if ((bus > 255) || (devfn > 255) || (reg > 255)) 
@@ -256,43 +240,27 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
 
 	switch (len) {
 	case 1:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=a" (result)
-			: "0" (PCIBIOS_WRITE_CONFIG_BYTE),
-			  "c" (value),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
+		number = PCIBIOS_WRITE_CONFIG_BYTE;
 		break;
 	case 2:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=a" (result)
-			: "0" (PCIBIOS_WRITE_CONFIG_WORD),
-			  "c" (value),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
+		number = PCIBIOS_WRITE_CONFIG_WORD;
 		break;
 	case 4:
-		__asm__("lcall *(%%esi); cld\n\t"
-			"jc 1f\n\t"
-			"xor %%ah, %%ah\n"
-			"1:"
-			: "=a" (result)
-			: "0" (PCIBIOS_WRITE_CONFIG_DWORD),
-			  "c" (value),
-			  "b" (bx),
-			  "D" ((long)reg),
-			  "S" (&pci_indirect));
+		number = PCIBIOS_WRITE_CONFIG_DWORD;
 		break;
 	}
 
+	__asm__("lcall *(%%esi); cld\n\t"
+		"jc 1f\n\t"
+		"xor %%ah, %%ah\n"
+		"1:"
+		: "=a" (result)
+		: "0" (number),
+		  "c" (value),
+		  "b" (bx),
+		  "D" ((long)reg),
+		  "S" (&pci_indirect));
+
 	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
 
 	return (int)((result & 0xff00) >> 8);
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/PCI: simplify pci_bios_{read,write}
  2015-12-07 13:42 [PATCH] x86/PCI: simplify pci_bios_{read,write} Geliang Tang
@ 2015-12-08 12:16 ` Thomas Gleixner
  2015-12-09 16:50 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2015-12-08 12:16 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Bjorn Helgaas, Ingo Molnar, H. Peter Anvin, x86, linux-pci, linux-kernel

On Mon, 7 Dec 2015, Geliang Tang wrote:

> There are some repetitive code in the switch/case statement in
> pci_bios_read() and pci_bios_write(). I drop it to simplify the
> code.
> 
> Signed-off-by: Geliang Tang <geliangtang@163.com>

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/PCI: simplify pci_bios_{read,write}
  2015-12-07 13:42 [PATCH] x86/PCI: simplify pci_bios_{read,write} Geliang Tang
  2015-12-08 12:16 ` Thomas Gleixner
@ 2015-12-09 16:50 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2015-12-09 16:50 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	linux-pci, linux-kernel

On Mon, Dec 07, 2015 at 10:24:24PM +0800, Geliang Tang wrote:
> There are some repetitive code in the switch/case statement in
> pci_bios_read() and pci_bios_write(). I drop it to simplify the
> code.
> 
> Signed-off-by: Geliang Tang <geliangtang@163.com>

Applied to pci/misc for v4.5 with Thomas' Reviewed-by, thanks!

> ---
>  arch/x86/pci/pcbios.c | 108 ++++++++++++++++++--------------------------------
>  1 file changed, 38 insertions(+), 70 deletions(-)
> 
> diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
> index 9b83b90..9770e55 100644
> --- a/arch/x86/pci/pcbios.c
> +++ b/arch/x86/pci/pcbios.c
> @@ -180,6 +180,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
>  	unsigned long result = 0;
>  	unsigned long flags;
>  	unsigned long bx = (bus << 8) | devfn;
> +	u16 number = 0, mask = 0;
>  
>  	WARN_ON(seg);
>  	if (!value || (bus > 255) || (devfn > 255) || (reg > 255))
> @@ -189,53 +190,35 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
>  
>  	switch (len) {
>  	case 1:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=c" (*value),
> -			  "=a" (result)
> -			: "1" (PCIBIOS_READ_CONFIG_BYTE),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> -		/*
> -		 * Zero-extend the result beyond 8 bits, do not trust the
> -		 * BIOS having done it:
> -		 */
> -		*value &= 0xff;
> +		number = PCIBIOS_READ_CONFIG_BYTE;
> +		mask = 0xff;
>  		break;
>  	case 2:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=c" (*value),
> -			  "=a" (result)
> -			: "1" (PCIBIOS_READ_CONFIG_WORD),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> -		/*
> -		 * Zero-extend the result beyond 16 bits, do not trust the
> -		 * BIOS having done it:
> -		 */
> -		*value &= 0xffff;
> +		number = PCIBIOS_READ_CONFIG_WORD;
> +		mask = 0xffff;
>  		break;
>  	case 4:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=c" (*value),
> -			  "=a" (result)
> -			: "1" (PCIBIOS_READ_CONFIG_DWORD),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> +		number = PCIBIOS_READ_CONFIG_DWORD;
>  		break;
>  	}
>  
> +	__asm__("lcall *(%%esi); cld\n\t"
> +		"jc 1f\n\t"
> +		"xor %%ah, %%ah\n"
> +		"1:"
> +		: "=c" (*value),
> +		  "=a" (result)
> +		: "1" (number),
> +		  "b" (bx),
> +		  "D" ((long)reg),
> +		  "S" (&pci_indirect));
> +	/*
> +	 * Zero-extend the result beyond 8 or 16 bits, do not trust the
> +	 * BIOS having done it:
> +	 */
> +	if (mask)
> +		*value &= mask;
> +
>  	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
>  
>  	return (int)((result & 0xff00) >> 8);
> @@ -247,6 +230,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
>  	unsigned long result = 0;
>  	unsigned long flags;
>  	unsigned long bx = (bus << 8) | devfn;
> +	u16 number = 0;
>  
>  	WARN_ON(seg);
>  	if ((bus > 255) || (devfn > 255) || (reg > 255)) 
> @@ -256,43 +240,27 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
>  
>  	switch (len) {
>  	case 1:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=a" (result)
> -			: "0" (PCIBIOS_WRITE_CONFIG_BYTE),
> -			  "c" (value),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> +		number = PCIBIOS_WRITE_CONFIG_BYTE;
>  		break;
>  	case 2:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=a" (result)
> -			: "0" (PCIBIOS_WRITE_CONFIG_WORD),
> -			  "c" (value),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> +		number = PCIBIOS_WRITE_CONFIG_WORD;
>  		break;
>  	case 4:
> -		__asm__("lcall *(%%esi); cld\n\t"
> -			"jc 1f\n\t"
> -			"xor %%ah, %%ah\n"
> -			"1:"
> -			: "=a" (result)
> -			: "0" (PCIBIOS_WRITE_CONFIG_DWORD),
> -			  "c" (value),
> -			  "b" (bx),
> -			  "D" ((long)reg),
> -			  "S" (&pci_indirect));
> +		number = PCIBIOS_WRITE_CONFIG_DWORD;
>  		break;
>  	}
>  
> +	__asm__("lcall *(%%esi); cld\n\t"
> +		"jc 1f\n\t"
> +		"xor %%ah, %%ah\n"
> +		"1:"
> +		: "=a" (result)
> +		: "0" (number),
> +		  "c" (value),
> +		  "b" (bx),
> +		  "D" ((long)reg),
> +		  "S" (&pci_indirect));
> +
>  	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
>  
>  	return (int)((result & 0xff00) >> 8);
> -- 
> 2.5.0
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-09 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-07 13:42 [PATCH] x86/PCI: simplify pci_bios_{read,write} Geliang Tang
2015-12-08 12:16 ` Thomas Gleixner
2015-12-09 16:50 ` Bjorn Helgaas

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).