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

« back to all changes in this revision

Viewing changes to libsysinfo-0.1.0/Linux/cpuinfo_ppc.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 ppc 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],throw_away[256];
16
 
    char vendor_string[256],model_string[256],hardware_string[256];
17
 
    int cpu_count=0;
18
 
    float megahertz=0.0,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,"cpu",3))) {
28
 
             strncpy(model_string,parse_line(temp_string),256);
29
 
             clip_lf(model_string,255);
30
 
          }
31
 
          
32
 
          if (!(strncmp(temp_string,"clock",5))) {
33
 
             megahertz=atof(parse_line(temp_string));  
34
 
          }
35
 
          
36
 
             /* Ugh why must people play with capitalization */
37
 
          if ( !(strncmp(temp_string,"bogomips",8)) ||
38
 
               !(strncmp(temp_string,"BogoMips",8)) ||
39
 
               !(strncmp(temp_string,"BogoMIPS",8))) {
40
 
             bogomips+=atof(parse_line(temp_string));
41
 
             cpu_count++;  /* Cheating way to detect number of intel CPU's */
42
 
          }
43
 
       }
44
 
    }
45
 
  
46
 
    strncpy(cpu_info->chip_vendor,"PPC",4);
47
 
    strncpy(cpu_info->chip_type,model_string,63);
48
 
 
49
 
    if (strstr(model_string,"POWER3")!=NULL) {
50
 
       strncpy(cpu_info->chip_type,"POWER3",7);
51
 
    }
52
 
   
53
 
       /* I Have an iBook now ;) */
54
 
    if (strstr(model_string,"745/755")!=NULL) {
55
 
       strncpy(cpu_info->chip_type,"G3",3);
56
 
    }
57
 
       
58
 
       /* But that's not the only iBook around! ;) */
59
 
    if (strstr(model_string,"750CX")!=NULL) {
60
 
       strncpy(cpu_info->chip_type,"G3",3);         
61
 
    }
62
 
   
63
 
    if (strstr(model_string,"750FX")!=NULL) {
64
 
       strncpy(cpu_info->chip_type,"G3",3);         
65
 
    }
66
 
   
67
 
   
68
 
    if (strstr(model_string,"7400")!=NULL) {
69
 
       strncpy(cpu_info->chip_type,"7400",5);
70
 
    }
71
 
 
72
 
   
73
 
       /* There should be a way to figure out */
74
 
       /* G4/G3 more efficiently than this    */
75
 
    if (strstr(model_string,"7410,")!=NULL) {
76
 
       strncpy(cpu_info->chip_type,"G4",3);
77
 
    }
78
 
   
79
 
    if (strstr(model_string,"7455")!=NULL) {
80
 
       strncpy(cpu_info->chip_type,"G4",3);
81
 
    }
82
 
   
83
 
       /* I have a powerbook now too ;) */
84
 
    if (strstr(model_string,"7457")!=NULL) {
85
 
       strncpy(cpu_info->chip_type,"G4",3);
86
 
    }
87
 
   
88
 
        
89
 
    if (!strncmp(model_string,"PowerPC",7)) {
90
 
       sscanf(model_string,"%s %s",throw_away,cpu_info->chip_type);
91
 
    }
92
 
  
93
 
    cpu_info->num_cpus=cpu_count;
94
 
    cpu_info->megahertz=megahertz;
95
 
    cpu_info->bogomips=bogomips;
96
 
 
97
 
    return 0;
98
 
   
99
 
}
100
 
 
101
 
int get_hardware(char hardware_string[65]) {
102
 
    
103
 
    char temp_string[256];
104
 
    FILE *fff;
105
 
   
106
 
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
107
 
       
108
 
       while ( (fgets(temp_string,255,fff)!=NULL) ) {
109
 
                  
110
 
          if (!(strncmp(temp_string,"machine",7))) {
111
 
             strncpy(hardware_string,parse_line(temp_string),64);
112
 
          }
113
 
 
114
 
       }
115
 
    }
116
 
    return 1;
117
 
}
118
 
 
119
 
    /* Some architectures might have better ways of detecting RAM size */
120
 
long int get_arch_specific_mem_size(void) {
121
 
       /* We have no special way of detecting RAM */
122
 
       return -1;
123
 
}