Skip to contentSkip to conversation

CPU-i386-Geode: Chipset access macros do not work as expected

PATCH Mikael Pettersson 4 participants 6 messages Apr 30, 2007 – May 2, 2007

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · Juergen Beisert

Replace NSC/Cyrix specific chipset access macros by inlined functions. With the macros a line like this fails (and does nothing):

	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);

With inlined functions this line will work as expected.

Looks ok, but some cleanups are in order. See below.

Quoted 17 lines

+++ linux-2.6.21/include/asm-i386/processor-cyrix.h

(quoted diff) +15 -0
@@ -0,0 +1,35 @@
+/*
+ * NSC/Cyrix CPU configuration register indexes
+ */
+#define CX86_PCR0 0x20
+#define CX86_GCR  0xb8
+#define CX86_CCR0 0xc0
+#define CX86_CCR1 0xc1
+#define CX86_CCR2 0xc2
+#define CX86_CCR3 0xc3
+#define CX86_CCR4 0xe8
+#define CX86_CCR5 0xe9
+#define CX86_CCR6 0xea
+#define CX86_CCR7 0xeb
+#define CX86_PCR1 0xf0
+#define CX86_DIR0 0xfe

Review line 25

Quoted 10 lines
(quoted diff) +10 -0
+#define CX86_DIR1 0xff
+#define CX86_ARR_BASE 0xc4
+#define CX86_RCR_BASE 0xdc
+
+/*
+ * NSC/Cyrix CPU indexed register access
+ */
+static inline u8 getCx86(u8 reg)
+{
+	outb(reg,0x22);

----------------^ missing space after comma

Review line 31

Quoted 6 lines
(quoted diff) +6 -0
+	return inb(0x23);
+}
+
+static inline void setCx86(u8 reg, u8 data)
+{
+	outb(reg,0x22);

----------------^ missing space after comma

Review line 32

Quoted 1 line
(quoted diff) +1 -0
+	outb(data,0x23);

ditto

Review line 35

Quoted 3 lines
(quoted diff) +3 -0
+}
+
+/* end of file processor-cyrix.h */

Totally redundant comment. Drop it.

/Mikael

#1 lore raw

Re: [PATCH] [1/1] CPU-i386-Geode: Chipset access macros do not work as expected (2nd try)

From: Juergen Beisert <[email protected]>

Replace NSC/Cyrix specific chipset access macros by inlined functions. With the macros a line like this fails (and does nothing):

	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);

With inlined functions this line will work as expected.

Note about a side effect: Seems on Geode GX1 based systems the "suspend on halt power saving feature" was never enabled due to this wrong macro expansion. With inlined functions it will be enabled, but this will stop the TSC when the CPU runs into a HLT instruction. Kernel outputs something like this:

	Clocksource tsc unstable (delta = -472746897 ns)

Tested on a Geode GX1 system.

This is the second version with some modifications suggested by Mikael Pettersson

include/asm-i386/processor.h +0 -31
Index: linux-2.6.21/include/asm-i386/processor.h
===================================================================
@@ -202,37 +202,6 @@ static inline void clear_in_cr4 (unsigne
 	write_cr4(cr4);
 }
 
-/*
- *      NSC/Cyrix CPU configuration register indexes
- */
-
-#define CX86_PCR0 0x20
-#define CX86_GCR  0xb8
-#define CX86_CCR0 0xc0
-#define CX86_CCR1 0xc1
-#define CX86_CCR2 0xc2
-#define CX86_CCR3 0xc3
-#define CX86_CCR4 0xe8
-#define CX86_CCR5 0xe9
-#define CX86_CCR6 0xea
-#define CX86_CCR7 0xeb
-#define CX86_PCR1 0xf0
-#define CX86_DIR0 0xfe
-#define CX86_DIR1 0xff
-#define CX86_ARR_BASE 0xc4
-#define CX86_RCR_BASE 0xdc
-
-/*
- *      NSC/Cyrix CPU indexed register access macros
- */
-
-#define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
-
-#define setCx86(reg, data) do { \
-	outb((reg), 0x22); \
-	outb((data), 0x23); \
-} while (0)
-
 /* Stop speculative execution */
 static inline void sync_core(void)
 {
include/asm-i386/processor-cyrix.h new file +33 -0
Index: linux-2.6.21/include/asm-i386/processor-cyrix.h
===================================================================
@@ -0,0 +1,33 @@
+/*
+ * NSC/Cyrix CPU configuration register indexes
+ */
+#define CX86_PCR0 0x20
+#define CX86_GCR  0xb8
+#define CX86_CCR0 0xc0
+#define CX86_CCR1 0xc1
+#define CX86_CCR2 0xc2
+#define CX86_CCR3 0xc3
+#define CX86_CCR4 0xe8
+#define CX86_CCR5 0xe9
+#define CX86_CCR6 0xea
+#define CX86_CCR7 0xeb
+#define CX86_PCR1 0xf0
+#define CX86_DIR0 0xfe
+#define CX86_DIR1 0xff
+#define CX86_ARR_BASE 0xc4
+#define CX86_RCR_BASE 0xdc
+
+/*
+ * NSC/Cyrix CPU indexed register access
+ */
+static inline u8 getCx86(u8 reg)
+{
+	outb(reg, 0x22);
+	return inb(0x23);
+}
+
+static inline void setCx86(u8 reg, u8 data)
+{
+	outb(reg, 0x22);
+	outb(data, 0x23);
+}
arch/i386/kernel/cpu/cyrix.c +1 -1
Index: linux-2.6.21/arch/i386/kernel/cpu/cyrix.c
===================================================================
@@ -4,7 +4,7 @@
 #include <linux/pci.h>
 #include <asm/dma.h>
 #include <asm/io.h>
-#include <asm/processor.h>
+#include <asm/processor-cyrix.h>
 #include <asm/timer.h>
 #include <asm/pci-direct.h>
 
arch/i386/kernel/cpu/mtrr/cyrix.c +1 -0
Index: linux-2.6.21/arch/i386/kernel/cpu/mtrr/cyrix.c
===================================================================
@@ -3,6 +3,7 @@
 #include <asm/mtrr.h>
 #include <asm/msr.h>
 #include <asm/io.h>
+#include <asm/processor-cyrix.h>
 #include "mtrr.h"
 
 int arr3_protected;
#2 lore raw

Re: [PATCH] [1/1] CPU-i386-Geode: Chipset access macros do not work as expected (2nd try)

Quoted 37 lines · On Mon, 30 Apr 2007 17:33:41 +0200 Juergen Beisert <[email protected]>…

From: Juergen Beisert <[email protected]>

Replace NSC/Cyrix specific chipset access macros by inlined functions. With the macros a line like this fails (and does nothing):

	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);

With inlined functions this line will work as expected.

Note about a side effect: Seems on Geode GX1 based systems the "suspend on halt power saving feature" was never enabled due to this wrong macro expansion. With inlined functions it will be enabled, but this will stop the TSC when the CPU runs into a HLT instruction. Kernel outputs something like this:

	Clocksource tsc unstable (delta = -472746897 ns)

Tested on a Geode GX1 system.

This is the second version with some modifications suggested by Mikael Pettersson

Index: linux-2.6.21/include/asm-i386/processor.h
===================================================================

include/asm-i386/processor.h +0 -9
@@ -202,37 +202,6 @@ static inline void clear_in_cr4 (unsigne
 	write_cr4(cr4);
 }
 
-/*
- *      NSC/Cyrix CPU configuration register indexes
- */
-
-#define CX86_PCR0 0x20
-#define CX86_GCR  0xb8
-#define CX86_CCR0 0xc0
-#define CX86_CCR1 0xc1
-#define CX86_CCR2 0xc2

include/asm-i386/processor.h static inline void clear_in_cr4 (unsigne · line 223

Quoted 10 lines
include/asm-i386/processor.h +0 -10
-#define CX86_CCR3 0xc3
-#define CX86_CCR4 0xe8
-#define CX86_CCR5 0xe9
-#define CX86_CCR6 0xea
-#define CX86_CCR7 0xeb
-#define CX86_PCR1 0xf0
-#define CX86_DIR0 0xfe
-#define CX86_DIR1 0xff
-#define CX86_ARR_BASE 0xc4
-#define CX86_RCR_BASE 0xdc

This clashes with Andi's "msr-index" patch:

ftp://ftp.firstfloor.org/pub/ak/x86_64/quilt/patches/msr-index

Perhaps it'd be best to wait until msr-index goes upstream and to raise a patch then. Or to redo and retest against 2.6.21-rc7-mm2, which includes msr-index.

Also, include/asm-x86_64/processor.h has a getCx86(), too. Does it also need fixing?

#3 lore raw

Re: [PATCH] [1/1] CPU-i386-Geode: Chipset access macros do not work as expected (2nd try)

Hi Andrew,

Quoted 53 lines · Andrew Morton

On Mon, 30 Apr 2007 17:33:41 +0200

Quoted 37 lines · Juergen Beisert

From: Juergen Beisert <[email protected]>

Replace NSC/Cyrix specific chipset access macros by inlined functions. With the macros a line like this fails (and does nothing):

	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);

With inlined functions this line will work as expected.

Note about a side effect: Seems on Geode GX1 based systems the "suspend on halt power saving feature" was never enabled due to this wrong macro expansion. With inlined functions it will be enabled, but this will stop the TSC when the CPU runs into a HLT instruction. Kernel outputs something like this:

	Clocksource tsc unstable (delta = -472746897 ns)

Tested on a Geode GX1 system.

This is the second version with some modifications suggested by Mikael Pettersson

Index: linux-2.6.21/include/asm-i386/processor.h
===================================================================

include/asm-i386/processor.h +0 -9
@@ -202,37 +202,6 @@ static inline void clear_in_cr4 (unsigne
 	write_cr4(cr4);
 }
 
-/*
- *      NSC/Cyrix CPU configuration register indexes
- */
-
-#define CX86_PCR0 0x20
-#define CX86_GCR  0xb8
-#define CX86_CCR0 0xc0
-#define CX86_CCR1 0xc1
-#define CX86_CCR2 0xc2

include/asm-i386/processor.h static inline void clear_in_cr4 (unsigne · line 223

Quoted 10 lines
include/asm-i386/processor.h +0 -10
-#define CX86_CCR3 0xc3
-#define CX86_CCR4 0xe8
-#define CX86_CCR5 0xe9
-#define CX86_CCR6 0xea
-#define CX86_CCR7 0xeb
-#define CX86_PCR1 0xf0
-#define CX86_DIR0 0xfe
-#define CX86_DIR1 0xff
-#define CX86_ARR_BASE 0xc4
-#define CX86_RCR_BASE 0xdc

This clashes with Andi's "msr-index" patch:

Quoted 1 line

ftp://ftp.firstfloor.org/pub/ak/x86_64/quilt/patches/msr-index

I see. He also moves these defines to another file. Not problem where they are. But it isn't possible to replace the macros by the inlined functions in processor.h. The used outb/inb macros fail for various other files.

Quoted 3 lines

Perhaps it'd be best to wait until msr-index goes upstream and to raise a patch then. Or to redo and retest against 2.6.21-rc7-mm2, which includes msr-index.

All right. To wait is no problem for me (my system works with my patch.... ;-) )

Quoted 2 lines

Also, include/asm-x86_64/processor.h has a getCx86(), too. Does it also need fixing?

As I can see the macros are used in:
- i386/kernel/cpu/cpufreq/gx-suspmod.c (ups, its not in my patch, so it is currently no complete)
- i386/kernel/cpu/mtrr/state.c (also not part of my patch yet)
- i386/kernel/cpu/cyrix.c
- i386/kernel/cpu/mtrr/cyrix.c

Most comments states Cyrix CPUs when they are using the macros. Is anything with Cyrix 64 bit relevant? Maybe "include/asm-x86_64/processor.h" is a simple copy of "include/asm-i386/processor.h" and nobody delete the unused macros?

Please keep me informed and I will resend the patch.

Juergen

#4 lore raw

Re: [PATCH] [1/1] CPU-i386-Geode: Chipset access macros do not work as expected (2nd try)

Quoted 8 lines · On Wed, 2 May 2007 09:16:59 +0200 Juergen Beisert <[email protected]>…
Quoted 4 lines

This clashes with Andi's "msr-index" patch:

ftp://ftp.firstfloor.org/pub/ak/x86_64/quilt/patches/msr-index

I see. He also moves these defines to another file. Not problem where they are. But it isn't possible to replace the macros by the inlined functions in processor.h. The used outb/inb macros fail for various other files.

Oh well. Please work out what you think needs to be done.

Quoted 17 lines
Quoted 3 lines

Perhaps it'd be best to wait until msr-index goes upstream and to raise a patch then. Or to redo and retest against 2.6.21-rc7-mm2, which includes msr-index.

All right. To wait is no problem for me (my system works with my patch.... ;-) )

Quoted 2 lines

Also, include/asm-x86_64/processor.h has a getCx86(), too. Does it also need fixing?

As I can see the macros are used in:
- i386/kernel/cpu/cpufreq/gx-suspmod.c (ups, its not in my patch, so it is currently no complete)
- i386/kernel/cpu/mtrr/state.c (also not part of my patch yet)
- i386/kernel/cpu/cyrix.c
- i386/kernel/cpu/mtrr/cyrix.c

Quoted 4 lines

Most comments states Cyrix CPUs when they are using the macros. Is anything with Cyrix 64 bit relevant? Maybe "include/asm-x86_64/processor.h" is a simple copy of "include/asm-i386/processor.h" and nobody delete the unused macros?

I don't think Cyrix make 64-bit stuff, surely. Andi?

Quoted 2 lines

Please keep me informed and I will resend the patch.

Thanks. I think Andi was after a better explanation of what was going wrong with the macros, too. Please include that in the changelog.

#5 lore raw

Re: [PATCH] [1/1] CPU-i386-Geode: Chipset access macros do not work as expected (2nd try)

In reply to Juergen Beisert
Quoted 5 lines

Most comments states Cyrix CPUs when they are using the macros. Is anything with Cyrix 64 bit relevant? Maybe "include/asm-x86_64/processor.h" is a simple copy of "include/asm-i386/processor.h" and nobody delete the unused macros?

It was originally deleted but later readded when the MTRR code was merged together. That's because of i386/kernel/cpu/mtrr/state.c which is compiled on x86-64 too. If you can move that code into cyrix.c it can be removed. Might be a good opportunity to clean this up.

Quoted 1 line

Please keep me informed and I will resend the patch.

I would need an patch against the current ff tree that doesn't break x86-64.

-Andi