"Fossies" - the Fresh Open Source Software Archive

Member "linux_logo-6.0/libsysinfo-0.3.0/Linux/cpuinfo_ppc.c" (9 May 2020, 4098 Bytes) of package /linux/misc/linux_logo-6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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(struct cpu_info_type *cpu_info) {
   13 
   14     FILE *fff;
   15     char temp_string[BUFSIZ],temp[BUFSIZ];
   16     char vendor_string[BUFSIZ],model_string[BUFSIZ];
   17     int cpu_count=0,processor_count=0,bogomips_count=0;
   18     float megahertz=0.0,bogomips=0.0;
   19 
   20     vendor_string[0]=model_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,BUFSIZ,fff)!=NULL) ) {
   26 
   27             if ( !(strncmp(temp_string,"cpu",3))) {
   28                 strncpy(model_string,parse_line(temp_string),BUFSIZ);
   29                 clip_lf(model_string,BUFSIZ);
   30             }
   31 
   32             if (!(strncmp(temp_string,"clock",5))) {
   33                 megahertz=atof(parse_line(temp_string));
   34             }
   35 
   36             if ( !(strncmp(temp_string,"processor",9))) {
   37                 processor_count++;
   38             }
   39 
   40             /* Ugh why must people play with capitalization */
   41             if ( !(strncmp(temp_string,"bogomips",8)) ||
   42                 !(strncmp(temp_string,"BogoMips",8)) ||
   43                 !(strncmp(temp_string,"BogoMIPS",8))) {
   44 
   45                 /* old way of determining processor count? */
   46                 bogomips+=atof(parse_line(temp_string));
   47                 bogomips_count++;
   48             }
   49         }
   50     }
   51 
   52     /* on cell (and most modern cpus) , there is no bogomips count! */
   53     if (bogomips_count==0) {
   54         cpu_count=processor_count;
   55     }
   56     else {
   57         cpu_count=bogomips_count;
   58     }
   59 
   60     strncpy(cpu_info->chip_vendor,"PPC",4);
   61     strncpy(cpu_info->chip_type,model_string,SYSINFO_CHIP_TYPE_SIZE);
   62 
   63     if (strstr(model_string,"POWER3")!=NULL) {
   64         strncpy(cpu_info->chip_type,"POWER3",7);
   65     }
   66 
   67     if (strstr(model_string,"POWER4")!=NULL) {
   68         strncpy(cpu_info->chip_type,"POWER4",7);
   69     }
   70 
   71     if (strstr(model_string,"POWER5")!=NULL) {
   72         strncpy(cpu_info->chip_type,"POWER5",7);
   73     }
   74 
   75     if (strstr(model_string,"POWER6")!=NULL) {
   76         strncpy(cpu_info->chip_type,"POWER6",7);
   77     }
   78 
   79     if (strstr(model_string,"POWER7")!=NULL) {
   80         strncpy(cpu_info->chip_type,"POWER7",7);
   81     }
   82 
   83     if (strstr(model_string,"POWER8")!=NULL) {
   84         strncpy(cpu_info->chip_type,"POWER8",7);
   85     }
   86 
   87     if (strstr(model_string,"POWER9")!=NULL) {
   88         strncpy(cpu_info->chip_type,"POWER9",7);
   89     }
   90 
   91     /* I Have an iBook now ;) */
   92     if (strstr(model_string,"745/755")!=NULL) {
   93         strncpy(cpu_info->chip_type,"G3",3);
   94     }
   95 
   96     /* But that's not the only iBook around! ;) */
   97     if (strstr(model_string,"750CX")!=NULL) {
   98         strncpy(cpu_info->chip_type,"G3",3);
   99     }
  100 
  101     if (strstr(model_string,"750FX")!=NULL) {
  102         strncpy(cpu_info->chip_type,"G3",3);
  103     }
  104 
  105     if (strstr(model_string,"7400")!=NULL) {
  106         strncpy(cpu_info->chip_type,"7400",5);
  107     }
  108 
  109     /* There should be a way to figure out */
  110     /* G4/G3 more efficiently than this    */
  111     if (strstr(model_string,"7410,")!=NULL) {
  112         strncpy(cpu_info->chip_type,"G4",3);
  113     }
  114 
  115     if (strstr(model_string,"7455")!=NULL) {
  116         strncpy(cpu_info->chip_type,"G4",3);
  117     }
  118 
  119     /* I have a powerbook now too ;) */
  120     if (strstr(model_string,"7457")!=NULL) {
  121         strncpy(cpu_info->chip_type,"G4",3);
  122     }
  123 
  124     if (strstr(model_string,"Cell")!=NULL) {
  125         strncpy(cpu_info->chip_type,"Cell",5);
  126     }
  127 
  128     if (!strncmp(model_string,"PowerPC",7)) {
  129         sscanf(model_string,"%*s %s",temp);
  130         strncpy(cpu_info->chip_type,temp,SYSINFO_CHIP_TYPE_SIZE);
  131     }
  132 
  133     cpu_info->num_cpus=cpu_count;
  134     cpu_info->megahertz=megahertz;
  135     cpu_info->bogomips=bogomips;
  136 
  137     return 0;
  138 }
  139 
  140 int get_hardware(char *hardware_string) {
  141 
  142     char temp_string[BUFSIZ];
  143     FILE *fff;
  144 
  145     if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
  146 
  147         while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) {
  148 
  149             if (!(strncmp(temp_string,"machine",7))) {
  150                 strncpy(hardware_string,parse_line(temp_string),
  151                     SYSINFO_HARDWARE_STRING_SIZE);
  152             }
  153 
  154         }
  155     }
  156     return 1;
  157 }
  158 
  159     /* Some architectures might have better ways of detecting RAM size */
  160 long long get_arch_specific_mem_size(void) {
  161     /* We have no special way of detecting RAM */
  162 
  163     /* sysinfo is the only way that works on cell? */
  164     /* can we detect that somehow and force it? */
  165 
  166     /* For mac the meminfo way is definitely better */
  167     return MEM_USE_MEMINFO;
  168 }