Subject: mfdcr/mtdcr
To: None <port-powerpc@netbsd.org>
From: Jachym Holecek <freza@dspfpga.com>
List: port-powerpc
Date: 05/10/2006 03:25:14
Hello,

I'd like to move mfdcr()/mtdcr() macro definitions into a separate file.
Motivation:

  * Currently, they're defined multiple times in include/ibm4xx/dcr40*.h

  * For evbppc/virtex, I'd like to be able to access DCR without
    also pulling in irrelevant address definitions (DCR address
    layout is completely up to the HDL designer)

The diff below (relative to arch/powerpc/include/ibm4xx) creates dcr.h
and makes dcr40*.h use it. Other option would be to move the macros to
ibm4xx/cpu.h (the m{f,t}dcr instructions are 4xx specific).

Does it sound OK? If so, anyone wants to commit? ;-)

	-- Jachym

--- /dev/null	2006-05-10 03:03:43.000000000 +0200
+++ dcr.h	2006-05-10 03:11:37.000000000 +0200
@@ -0,0 +1,20 @@
+/* 	$NetBSD$ */
+
+#ifndef _IBM4XX_DCR_H_
+#define _IBM4XX_DCR_H_
+
+#ifndef _LOCORE
+
+#define	mtdcr(reg, val)						\
+	__asm volatile("mtdcr %0,%1" : : "K"(reg), "r"(val))
+
+#define	mfdcr(reg)						\
+({ 								\
+	u_int32_t __val;					\
+								\
+	__asm volatile("mfdcr %0,%1" : "=r"(__val) : "K"(reg)); \
+	__val; 							\
+})
+
+#endif /* _LOCORE */
+#endif /* _IBM4XX_DCR_H_ */
Index: dcr403cgx.h
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/include/ibm4xx/dcr403cgx.h,v
retrieving revision 1.2
diff -u -r1.2 dcr403cgx.h
--- dcr403cgx.h	24 Dec 2005 22:45:36 -0000	1.2
+++ dcr403cgx.h	9 May 2006 23:18:51 -0000
@@ -36,17 +36,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <powerpc/ibm4xx/dcr.h>
+
 #ifndef _DCR403GCXP_H_
 #define	_DCR403GCXP_H_
-
-#ifndef _LOCORE
-#define	mtdcr(reg, val)						\
-	__asm volatile("mtdcr %0,%1" : : "K"(reg), "r"(val))
-#define	mfdcr(reg)						\
-	( { u_int32_t val;					\
-	  __asm volatile("mfdcr %0,%1" : "=r"(val) : "K"(reg));	\
-	  val; } )
-#endif /* _LOCORE */
 
 /* Device Control Register declarations */
 
Index: dcr405gp.h
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/include/ibm4xx/dcr405gp.h,v
retrieving revision 1.4
diff -u -r1.4 dcr405gp.h
--- dcr405gp.h	24 Dec 2005 22:45:36 -0000	1.4
+++ dcr405gp.h	9 May 2006 23:18:52 -0000
@@ -35,17 +35,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <powerpc/ibm4xx/dcr.h>
+
 #ifndef _DCR405GP_H_
 #define	_DCR405GP_H_
-
-#ifndef _LOCORE
-#define	mtdcr(reg, val)						\
-	__asm volatile("mtdcr %0,%1" : : "K"(reg), "r"(val))
-#define	mfdcr(reg)						\
-	( { u_int32_t val;					\
-	  __asm volatile("mfdcr %0,%1" : "=r"(val) : "K"(reg));	\
-	  val; } )
-#endif /* _LOCORE */
 
 /* Device Control Register declarations */
 
Index: dcr405xx.h
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/include/ibm4xx/dcr405xx.h,v
retrieving revision 1.4
diff -u -r1.4 dcr405xx.h
--- dcr405xx.h	24 Dec 2005 22:45:36 -0000	1.4
+++ dcr405xx.h	9 May 2006 23:18:55 -0000
@@ -30,6 +30,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <powerpc/ibm4xx/dcr.h>
+
 #ifndef _IBM4XX_DCR405XX_H_
 #define	_IBM4XX_DCR405XX_H_
 
@@ -38,16 +40,6 @@
  *   for AMCC(IBM) PowerPC 405 series
  * 	405CR/NPe405L/NPe405H/405EP/405GP/405GPr
  */
-
-#ifndef _LOCORE
-#define	mtdcr(reg, val)						\
-	__asm volatile("mtdcr %0,%1" : : "K"(reg), "r"(val))
-#define	mfdcr(reg)						\
-	( { u_int32_t val;					\
-	  __asm volatile("mfdcr %0,%1" : "=r"(val) : "K"(reg));	\
-	  val; } )
-#endif /* _LOCORE */
-
 
 /*****************************************************************************/
 /*