Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / ppc / common_ppc.c
1 /*
2  * (C) Copyright IBM Corporation 2004
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * on the rights to use, copy, modify, merge, publish, distribute, sub
9  * license, and/or sell copies of the Software, and to permit persons to whom
10  * the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19  * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22  * USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /**
26  * \file common_ppc.c
27  * Check CPU capabilities & initialize optimized funtions for this particular
28  * processor.
29  *
30  * \author Ian Romanick <idr@us.ibm.com>
31  */
32
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36
37 #ifdef USE_PPC_ASM
38 #include <elf.h>
39 #endif
40
41 #include "common_ppc_features.h"
42
43
44 unsigned long _mesa_ppc_cpu_features = 0;
45
46 /**
47  * Detect CPU features and install optimized transform and lighting routines.
48  * Currently, CPU features are only detected.  The optimized routines have
49  * yet to be written.
50  * 
51  * \bug
52  * This routine is highly specific to Linux kernel 2.6.  I'm still waiting
53  * to hear back from the glibc folk on how to do this "right".
54  */
55
56 void _mesa_init_all_ppc_transform_asm( void )
57 {
58 #ifdef USE_PPC_ASM
59    const pid_t  my_pid = getpid();
60    char file_name[32];
61    FILE * f;
62 #ifdef __powerpc64__
63    Elf64_auxv_t  v;
64 #else
65    Elf32_auxv_t  v;
66 #endif
67
68    sprintf( file_name, "/proc/%u/auxv", (unsigned) my_pid );
69    f = fopen( file_name, "rb" );
70    if ( f != NULL ) {
71       while( 1 ) {
72          ssize_t elem = fread( & v, sizeof( v ), 1, f );
73
74          if ( elem < 1 ) {
75             break;
76          }
77
78          if ( v.a_type == AT_HWCAP ) {
79             _mesa_ppc_cpu_features = v.a_un.a_val;
80             break;
81          }
82       }
83
84       fclose( f );
85    }
86    
87 # ifndef USE_VMX_ASM
88    _mesa_ppc_cpu_features &= ~PPC_FEATURE_HAS_ALTIVEC;
89 # endif
90 #endif
91 }