diff mbox

[5/6] powerpc/boot: Add mfdcrx

Message ID 1322630640-13708-6-git-send-email-tony@bakeyournoodle.com (mailing list archive)
State Superseded
Delegated to: Josh Boyer
Headers show

Commit Message

Tony Breeds Nov. 30, 2011, 5:23 a.m. UTC
Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
---
 arch/powerpc/boot/dcr.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Comments

Segher Boessenkool Nov. 30, 2011, 1:09 p.m. UTC | #1
> +#define mfdcrx(rn) \
> +	({	\
> +		unsigned long rval; \
> +		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "g"(rn)); \
> +		rval; \
> +	})

"g" is never correct on PowerPC, you want "r" here.  You can write
this as a static inline btw, you only need the #define stuff when
there is an "i" constraint involved.


Segher
David Laight Nov. 30, 2011, 6:10 p.m. UTC | #2
> > +#define mfdcrx(rn) \
> > +	({	\
> > +		unsigned long rval; \
> > +		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "g"(rn)); \
> > +		rval; \
> > +	})
> 
> "g" is never correct on PowerPC, you want "r" here.  You can write
> this as a static inline btw, you only need the #define stuff when
> there is an "i" constraint involved.

I think you can still use static inlines even when a
constraint is one that requires a compile time constant.
eg (not ppc, but the "n" become part of the instruction
word):

static __inline__ uint32_t
custom_inic(const uint32_t op, uint32_t a, const uint32_t b)
{
    uint32_t result;

    __asm__ ( "custom\t%1, %0, %2, c%3"
        : "=r" (result) : "n" (op), "r" (a), "n" (b));
    return result;
}

	David
Tony Breeds Nov. 30, 2011, 11:30 p.m. UTC | #3
On Wed, Nov 30, 2011 at 02:09:20PM +0100, Segher Boessenkool wrote:
> >+#define mfdcrx(rn) \
> >+	({	\
> >+		unsigned long rval; \
> >+		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "g"(rn)); \
> >+		rval; \
> >+	})
> 
> "g" is never correct on PowerPC, you want "r" here.  You can write
> this as a static inline btw, you only need the #define stuff when
> there is an "i" constraint involved.

Okay I'll change it to "i", mostly I used a #define to match the style
of m[tf]dcr.  To be honnest I didn't know about the issue with "i"
constraints and static inlines.

Yours Tony
Tony Breeds Nov. 30, 2011, 11:35 p.m. UTC | #4
On Thu, Dec 01, 2011 at 10:30:27AM +1100, Tony Breeds wrote:

> Okay I'll change it to "i", mostly I used a #define to match the style

Of course I menat "r" here.

Yours Tony
Segher Boessenkool Dec. 1, 2011, 10:55 p.m. UTC | #5
>>> +#define mfdcrx(rn) \
>>> +	({	\
>>> +		unsigned long rval; \
>>> +		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "g"(rn)); \
>>> +		rval; \
>>> +	})
>>
>> "g" is never correct on PowerPC, you want "r" here.  You can write
>> this as a static inline btw, you only need the #define stuff when
>> there is an "i" constraint involved.
>
> I think you can still use static inlines even when a
> constraint is one that requires a compile time constant.

Marking a function inline does not guarantee the compiler will
perform inline substitution on it, which you need here.  I don't
think it's a problem with recent GCC in the context of the Linux
kernel though, if you use __always_inline that is.


Segher
diff mbox

Patch

diff --git a/arch/powerpc/boot/dcr.h b/arch/powerpc/boot/dcr.h
index 645a7c9..51b5893 100644
--- a/arch/powerpc/boot/dcr.h
+++ b/arch/powerpc/boot/dcr.h
@@ -9,6 +9,12 @@ 
 	})
 #define mtdcr(rn, val) \
 	asm volatile("mtdcr %0,%1" : : "i"(rn), "r"(val))
+#define mfdcrx(rn) \
+	({	\
+		unsigned long rval; \
+		asm volatile("mfdcrx %0,%1" : "=r"(rval) : "g"(rn)); \
+		rval; \
+	})
 
 /* 440GP/440GX SDRAM controller DCRs */
 #define DCRN_SDRAM0_CFGADDR				0x010