Initial support for PowerPC specific code in Mesa and DRI drivers. DRI
[mesa.git] / src / mesa / drivers / dri / common / utils.c
index e6823cfaee03be13335315fa2565d25a45a51348..0e8e54a2028fde1a5f847d9fed5b3e1c27e897ae 100644 (file)
  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file utils.c
+ * Utility functions for DRI drivers.
  *
- * Authors:
- *    Ian Romanick <idr@us.ibm.com>
+ * \author Ian Romanick <idr@us.ibm.com>
  */
-/* $XFree86:$ */
 
 #include <string.h>
 #include <stdlib.h>
@@ -32,7 +35,7 @@
 #include "extensions.h"
 #include "utils.h"
 
-#if !defined( DRI_NEW_INTERFACE_ONLY ) && !defined( _SOLO )
+#if !defined( DRI_NEW_INTERFACE_ONLY )
 #include "xf86dri.h"        /* For XF86DRIQueryVersion prototype. */
 #endif
 
 #include "x86/common_x86_asm.h"
 #endif
 
+#if defined(USE_PPC_ASM)
+#include "ppc/common_ppc_features.h"
+#endif
+
 unsigned
 driParseDebugString( const char * debug, 
                     const struct dri_debug_control * control  )
@@ -64,17 +71,33 @@ driParseDebugString( const char * debug,
 
 
 
-
+/**
+ * Create the \c GL_RENDERER string for DRI drivers.
+ * 
+ * Almost all DRI drivers use a \c GL_RENDERER string of the form:
+ *
+ *    "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
+ *
+ * Using the supplied chip name, driver data, and AGP speed, this function
+ * creates the string.
+ * 
+ * \param buffer         Buffer to hold the \c GL_RENDERER string.
+ * \param hardware_name  Name of the hardware.
+ * \param driver_date    Driver date.
+ * \param agp_mode       AGP mode (speed).
+ * 
+ * \returns
+ * The length of the string stored in \c buffer.  This does \b not include
+ * the terminating \c NUL character.
+ */
 unsigned
 driGetRendererString( char * buffer, const char * hardware_name,
                      const char * driver_date, GLuint agp_mode )
 {
-#ifdef USE_X86_ASM
-   char * x86_str = "";
-   char * mmx_str = "";
-   char * tdnow_str = "";
-   char * sse_str = "";
-#endif
+#define MAX_INFO   4
+   const char * cpu[MAX_INFO];
+   unsigned   next = 0;
+   unsigned   i;
    unsigned   offset;
 
 
@@ -98,33 +121,59 @@ driGetRendererString( char * buffer, const char * hardware_name,
     */
 #ifdef USE_X86_ASM
    if ( _mesa_x86_cpu_features ) {
-      x86_str = " x86";
+      cpu[next] = " x86";
+      next++;
    }
 # ifdef USE_MMX_ASM
    if ( cpu_has_mmx ) {
-      mmx_str = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
+      cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
+      next++;
    }
 # endif
 # ifdef USE_3DNOW_ASM
    if ( cpu_has_3dnow ) {
-      tdnow_str = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
+      cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
+      next++;
    }
 # endif
 # ifdef USE_SSE_ASM
    if ( cpu_has_xmm ) {
-      sse_str = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
+      cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
+      next++;
    }
 # endif
 
-   offset += sprintf( & buffer[ offset ], "%s%s%s%s", 
-                     x86_str, mmx_str, tdnow_str, sse_str );
-
 #elif defined(USE_SPARC_ASM)
 
-   offset += sprintf( & buffer[ offset ], " Sparc" );
+   cpu[0] = " SPARC";
+   next = 1;
+
+#elif defined(USE_PPC_ASM)
+   if ( _mesa_ppc_cpu_features ) {
+      cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC";
+      next++;
+   }
+
+# ifdef USE_VMX_ASM
+   if ( cpu_has_vmx ) {
+      cpu[next] = "/Altivec";
+      next++;
+   }
+# endif
 
+   if ( ! cpu_has_fpu ) {
+      cpu[next] = "/No FPU";
+      next++;
+   }
 #endif
 
+   for ( i = 0 ; i < next ; i++ ) {
+      const size_t len = strlen( cpu[i] );
+
+      strncpy( & buffer[ offset ], cpu[i], len );
+      offset += len;
+   }
+
    return offset;
 }
 
@@ -171,7 +220,6 @@ driCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv,
        "but got version %d.%d.%d";
    int major, minor, patch;
 
-#ifndef _SOLO
    /* Check the DRI version */
    if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) {
       if (major != dri_major || minor < dri_minor) {
@@ -187,9 +235,6 @@ driCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv,
                       sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch);
       return GL_FALSE;
    }
-#else
-   (void)major;(void)minor;(void)patch;
-#endif
    
    /* Check that the DRM driver version is compatible */
    if (sPriv->drmMajor != drm_major || sPriv->drmMinor < drm_minor) {
@@ -390,7 +435,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
-      { 0x000000F8, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
+      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
       { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8     */
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -401,7 +446,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
-      { 0x000000F8, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
+      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
       { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8     */
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -413,7 +458,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
-      { 0x000000F8, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
+      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
       { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8     */
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
@@ -424,7 +469,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
-      { 0x000000F8, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
+      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
       { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8     */
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */