~ubuntu-branches/ubuntu/trusty/linuxlogo/trusty

« back to all changes in this revision

Viewing changes to libsysinfo-0.1.0/Linux/cpuinfo_arm.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-06-20 09:19:00 UTC
  • mfrom: (4.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080620091900-4xzuv7c7ntxvs7wt
Tags: 5.03-4
* Adding patch to fix FTBFS on s390x.
* Updating to standards 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Re-written from scratch 3 March 2001      */
2
 
/* Handles arm chips on Linux architecture   */
3
 
/* by Vince Weaver <vince@deater.net>        */
4
 
 
5
 
#include <stdio.h>
6
 
#include <string.h>
7
 
#include <stdlib.h>  /* atof */
8
 
 
9
 
#include "../sysinfo.h"
10
 
#include "../include/generic.h"
11
 
 
12
 
int get_cpu_info(cpu_info_t *cpu_info) {
13
 
 
14
 
    FILE *fff;
15
 
    char temp_string[256]; 
16
 
    char vendor_string[256],model_string[256],hardware_string[256];
17
 
    int cpu_count=0;
18
 
    float bogomips=0.0;
19
 
   
20
 
    vendor_string[0]=model_string[0]=hardware_string[0]=0;
21
 
 
22
 
       /* We get all of our info here from /proc/cpuinfo */
23
 
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
24
 
       
25
 
       while ( (fgets(temp_string,255,fff)!=NULL) ) {
26
 
        
27
 
          if ( !(strncmp(temp_string,"Processor",9))) {
28
 
             strncpy(vendor_string,parse_line(temp_string),256);
29
 
             clip_lf(vendor_string,255);
30
 
          }       
31
 
          if ( !(strncmp(temp_string,"Processor",9))) {
32
 
             strncpy(model_string,parse_line(temp_string),256);
33
 
             clip_lf(model_string,255);
34
 
          }       
35
 
          
36
 
          if ( !(strncmp(temp_string,"cpu",3))) {
37
 
             strncpy(model_string,parse_line(temp_string),256);
38
 
             clip_lf(model_string,255);
39
 
          }
40
 
          
41
 
             /* Huge big ugly hack */
42
 
          if (strstr(model_string,"sa11")!=NULL) {
43
 
             strncpy(model_string,"StrongARM",16);
44
 
          } else
45
 
          if (strstr(model_string,"StrongARM")!=NULL) {
46
 
             strncpy(model_string,"StrongARM",14);
47
 
          } else
48
 
          if (strstr(model_string,"XScale")!=NULL) {
49
 
             strncpy(model_string,"XScale",14);
50
 
          } else            
51
 
          if (strstr(model_string,"710")!=NULL) {
52
 
             strncpy(model_string,"710",4);
53
 
          } else
54
 
          if (strstr(model_string,"940")!=NULL) {
55
 
             strncpy(model_string,"940",4);
56
 
          } 
57
 
            
58
 
          
59
 
          
60
 
             /* Ugh why must people play with capitalization */
61
 
          if ( !(strncmp(temp_string,"bogomips",8)) ||
62
 
               !(strncmp(temp_string,"BogoMips",8)) ||
63
 
               !(strncmp(temp_string,"BogoMIPS",8))) {
64
 
             bogomips+=atof(parse_line(temp_string));
65
 
             cpu_count++;  /* Cheating way to detect number of intel CPU's */
66
 
          }
67
 
       }
68
 
    }
69
 
 
70
 
    strncpy(cpu_info->chip_vendor,vendor_string,32);
71
 
    strncpy(cpu_info->chip_type,model_string,63);
72
 
   
73
 
       /* This done off of only 2 cpuinfos, so probably not the best */
74
 
    if (!strncmp(vendor_string,"ARM",3)) {
75
 
       strncpy(cpu_info->chip_vendor,"ARM",4);
76
 
//       sscanf(vendor_string,"%s %s %s",throw_away,throw_away,cpu_info->chip_type);
77
 
    }
78
 
    else
79
 
    if (!strncmp(vendor_string,"Intel",5)){
80
 
       strncpy(cpu_info->chip_vendor,"Intel",6);
81
 
    }
82
 
    else strncpy(cpu_info->chip_vendor,"ARM",4);
83
 
 
84
 
    cpu_info->num_cpus=cpu_count;
85
 
    cpu_info->megahertz=0.0;
86
 
    cpu_info->bogomips=bogomips;
87
 
 
88
 
    return 0;
89
 
   
90
 
}
91
 
 
92
 
int get_hardware(char hardware_string[65]) {
93
 
    
94
 
    char temp_string[256];
95
 
    FILE *fff;
96
 
   
97
 
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
98
 
       
99
 
       while ( (fgets(temp_string,255,fff)!=NULL) ) {
100
 
                  
101
 
          if (!(strncmp(temp_string,"Hardware",8))) {
102
 
             strncpy(hardware_string,parse_line(temp_string),64);
103
 
          }
104
 
 
105
 
       }
106
 
    }
107
 
    return 1;
108
 
}
109
 
 
110
 
    /* Some architectures might have better ways of detecting RAM size */
111
 
long int get_arch_specific_mem_size(void) {
112
 
       /* We have no special way of detecting RAM */
113
 
       return -1;
114
 
}