mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: dean@arctic.org, patches@x86-64.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [1/12] x86: Work around mmio config space quirk on AMD Fam10h
Date: Thu,  9 Aug 2007 14:41:28 +0200 (CEST)	[thread overview]
Message-ID: <20070809124128.886BE14F3B@wotan.suse.de> (raw)
In-Reply-To: <20070809241.425881000@suse.de>


From: dean gaudet <dean@arctic.org>

Some broken devices have been discovered to require %al/%ax/%eax registers 
for MMIO config space accesses.  Modify mmconfig.c to use these registers 
explicitly (rather than modify the global readb/writeb/etc inlines).

AK: also changed i386 to always use eax
AK: moved change to extended space probing to different patch
AK: reworked with inlines according to Linus' requirements.
AK: improve comments.

Signed-off-by: dean gaudet <dean@arctic.org>
Signed-off-by: Andi Kleen <ak@suse.de>


---
 arch/i386/pci/mmconfig.c   |   14 ++++++--------
 arch/i386/pci/pci.h        |   43 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86_64/pci/mmconfig.c |   12 ++++++------
 3 files changed, 55 insertions(+), 14 deletions(-)

Index: linux/arch/x86_64/pci/mmconfig.c
===================================================================
--- linux.orig/arch/x86_64/pci/mmconfig.c
+++ linux/arch/x86_64/pci/mmconfig.c
@@ -66,13 +66,13 @@ static int pci_mmcfg_read(unsigned int s
 
 	switch (len) {
 	case 1:
-		*value = readb(addr + reg);
+		*value = mmio_config_readb(addr + reg);
 		break;
 	case 2:
-		*value = readw(addr + reg);
+		*value = mmio_config_readw(addr + reg);
 		break;
 	case 4:
-		*value = readl(addr + reg);
+		*value = mmio_config_readl(addr + reg);
 		break;
 	}
 
@@ -94,13 +94,13 @@ static int pci_mmcfg_write(unsigned int 
 
 	switch (len) {
 	case 1:
-		writeb(value, addr + reg);
+		mmio_config_writeb(addr + reg, value);
 		break;
 	case 2:
-		writew(value, addr + reg);
+		mmio_config_writew(addr + reg, value);
 		break;
 	case 4:
-		writel(value, addr + reg);
+		mmio_config_writel(addr + reg, value);
 		break;
 	}
 
Index: linux/arch/i386/pci/mmconfig.c
===================================================================
--- linux.orig/arch/i386/pci/mmconfig.c
+++ linux/arch/i386/pci/mmconfig.c
@@ -82,16 +82,15 @@ static int pci_mmcfg_read(unsigned int s
 
 	switch (len) {
 	case 1:
-		*value = readb(mmcfg_virt_addr + reg);
+		*value = mmio_config_readb(mmcfg_virt_addr + reg);
 		break;
 	case 2:
-		*value = readw(mmcfg_virt_addr + reg);
+		*value = mmio_config_readw(mmcfg_virt_addr + reg);
 		break;
 	case 4:
-		*value = readl(mmcfg_virt_addr + reg);
+		*value = mmio_config_readl(mmcfg_virt_addr + reg);
 		break;
 	}
-
 	spin_unlock_irqrestore(&pci_config_lock, flags);
 
 	return 0;
@@ -116,16 +115,15 @@ static int pci_mmcfg_write(unsigned int 
 
 	switch (len) {
 	case 1:
-		writeb(value, mmcfg_virt_addr + reg);
+		mmio_config_writeb(mmcfg_virt_addr, value);
 		break;
 	case 2:
-		writew(value, mmcfg_virt_addr + reg);
+		mmio_config_writew(mmcfg_virt_addr, value);
 		break;
 	case 4:
-		writel(value, mmcfg_virt_addr + reg);
+		mmio_config_writel(mmcfg_virt_addr, value);
 		break;
 	}
-
 	spin_unlock_irqrestore(&pci_config_lock, flags);
 
 	return 0;
Index: linux/arch/i386/pci/pci.h
===================================================================
--- linux.orig/arch/i386/pci/pci.h
+++ linux/arch/i386/pci/pci.h
@@ -104,3 +104,46 @@ extern DECLARE_BITMAP(pci_mmcfg_fallback
 extern int __init pci_mmcfg_arch_reachable(unsigned int seg, unsigned int bus,
 					   unsigned int devfn);
 extern int __init pci_mmcfg_arch_init(void);
+
+/*
+ * AMD Fam10h CPUs are buggy, and cannot access MMIO config space
+ * on their northbrige except through the * %eax register. As such, you MUST
+ * NOT use normal IOMEM accesses, you need to only use the magic mmio-config
+ * accessor functions.
+ * In fact just use pci_config_*, nothing else please.
+ */
+static inline unsigned char mmio_config_readb(void __iomem *pos)
+{
+	u8 val;
+	asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos));
+	return val;
+}
+
+static inline unsigned short mmio_config_readw(void __iomem *pos)
+{
+	u16 val;
+	asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos));
+	return val;
+}
+
+static inline unsigned int mmio_config_readl(void __iomem *pos)
+{
+	u32 val;
+	asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos));
+	return val;
+}
+
+static inline void mmio_config_writeb(void __iomem *pos, u8 val)
+{
+	asm volatile("movb %%al,(%1)" :: "a" (val), "r" (pos) : "memory");
+}
+
+static inline void mmio_config_writew(void __iomem *pos, u16 val)
+{
+	asm volatile("movw %%ax,(%1)" :: "a" (val), "r" (pos) : "memory");
+}
+
+static inline void mmio_config_writel(void __iomem *pos, u32 val)
+{
+	asm volatile("movl %%eax,(%1)" :: "a" (val), "r" (pos) : "memory");
+}

  reply	other threads:[~2007-08-09 12:42 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-09 12:41 [PATCH] [0/12] x86 Late merge bug fixes for 2.6.23 Andi Kleen
2007-08-09 12:41 ` Andi Kleen [this message]
2007-08-10 10:19   ` [patches] [PATCH] [1/12] x86: Work around mmio config space quirk on AMD Fam10h Joachim Deguara
2007-08-12  9:25   ` Linus Torvalds
2007-08-12 10:03     ` Andi Kleen
2007-08-12 19:15       ` Linus Torvalds
2007-08-13  3:06         ` Dave Jones
2007-08-13  3:26           ` Linus Torvalds
2007-08-13  3:38             ` dean gaudet
2007-08-09 12:41 ` [PATCH] [2/12] x86_64: Calgary - Fix mis-handled PCI topology Andi Kleen
2007-08-09 12:41 ` [PATCH] [3/12] x86_64: Don't mark __exitcall as __cold Andi Kleen
2007-08-09 12:41 ` [PATCH] [4/12] x86_64: Disable CLFLUSH support again Andi Kleen
2007-08-09 12:54   ` [patches] " Jan Beulich
2007-08-09 13:11   ` Muli Ben-Yehuda
2007-08-09 13:12     ` Andi Kleen
2007-08-09 13:29     ` [patches] " Jan Beulich
2007-08-09 16:24       ` Muli Ben-Yehuda
2007-08-09 12:41 ` [PATCH] [5/12] x86_64: Make patching more robust, fix paravirt issue Andi Kleen
2007-08-18  0:05   ` Jeremy Fitzhardinge
2007-08-18  0:11     ` Chris Wright
2007-08-18  9:49     ` Andi Kleen
2007-08-18 20:32       ` Chris Wright
2007-08-18 20:55         ` Linus Torvalds
2007-08-18 21:31           ` Chris Wright
2007-08-18 22:28             ` [PATCH] x86: skip paravirt patching when appropriate Chris Wright
2007-08-19  3:08               ` Zachary Amsden
2007-08-19  5:55               ` Zachary Amsden
2007-08-18 21:58       ` [PATCH] [5/12] x86_64: Make patching more robust, fix paravirt issue Jeremy Fitzhardinge
2007-08-20  1:50     ` Rusty Russell
2007-08-20  2:07       ` Chris Wright
2007-08-20  6:15         ` Jeremy Fitzhardinge
2007-08-21  7:30           ` Glauber de Oliveira Costa
2007-08-21 11:23             ` Andi Kleen
2007-08-21 12:26               ` Glauber de Oliveira Costa
2007-08-09 12:41 ` [PATCH] [6/12] x86_64: Early segment setup for VT Andi Kleen
2007-10-11 21:30   ` H. Peter Anvin
2007-08-09 12:41 ` [PATCH] [7/12] x86_64: really stop MCEs during code patching Andi Kleen
2007-08-09 12:41 ` [PATCH] [8/12] x86_64: Use global flag to disable broken local apic timer on AMD CPUs Andi Kleen
2007-08-09 16:46   ` Cal Peake
2007-08-09 16:50     ` Andi Kleen
2007-08-09 12:41 ` [PATCH] [9/12] x86_64: Avoid NMI Watchdog and/or long wait in setup_APIC_timer Andi Kleen
2007-08-09 12:41 ` [PATCH] [10/12] x86_64: Add warning in Documentation that zero-page is not a stable ABI Andi Kleen
2007-08-09 12:41 ` [PATCH] [11/12] x86_64: vdso.lds in arch/x86_64/vdso/.gitignore Andi Kleen
2007-08-09 12:41 ` [PATCH] [12/12] x86_64: Fix start_kernel warning Andi Kleen
2007-08-09 13:06 ` [PATCH] [0/12] x86 Late merge bug fixes for 2.6.23 Muli Ben-Yehuda
2007-08-09 13:12   ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070809124128.886BE14F3B@wotan.suse.de \
    --to=ak@suse.de \
    --cc=dean@arctic.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@x86-64.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®