xref: /minix/minix/fs/procfs/cpuinfo.c (revision 9f988b79)
1 /* ProcFS - cpuinfo.c - generator for the cpuinfo file */
2 
3 #include "inc.h"
4 
5 #if defined(__i386__)
6 #include "../../kernel/arch/i386/include/archconst.h"
7 #endif
8 
9 #ifndef CONFIG_MAX_CPUS
10 #define CONFIG_MAX_CPUS	1
11 #endif
12 
13 #if defined(__i386__)
14 static const char * x86_flag[] = {
15 	"fpu",
16 	"vme",
17 	"de",
18 	"pse",
19 	"tsc",
20 	"msr",
21 	"pae",
22 	"mce",
23 	"cx8",
24 	"apic",
25 	"",
26 	"sep",
27 	"mtrr",
28 	"pge",
29 	"mca",
30 	"cmov",
31 	"pat",
32 	"pse36",
33 	"psn",
34 	"clfsh",
35 	"",
36 	"dts",
37 	"acpi",
38 	"mmx",
39 	"fxsr",
40 	"sse",
41 	"sse2",
42 	"ss",
43 	"ht",
44 	"tm",
45 	"",
46 	"pbe",
47 	"pni",
48 	"",
49 	"",
50 	"monitor",
51 	"ds_cpl",
52 	"vmx",
53 	"smx",
54 	"est",
55 	"tm2",
56 	"ssse3",
57 	"cid",
58 	"",
59 	"",
60 	"cx16",
61 	"xtpr",
62 	"pdcm",
63 	"",
64 	"",
65 	"dca",
66 	"sse4_1",
67 	"sse4_2",
68 	"x2apic",
69 	"movbe",
70 	"popcnt",
71 	"",
72 	"",
73 	"xsave",
74 	"osxsave",
75 	"",
76 	"",
77 	"",
78 	"",
79 };
80 
81 /*
82  * Output a space-separated list of supported CPU flags.  x86 only.
83  */
84 static void
85 print_x86_cpu_flags(u32_t * flags)
86 {
87 	int i, j;
88 
89 	for (i = 0; i < 2; i++) {
90 		for (j = 0; j < 32; j++) {
91 			if (flags[i] & (1 << j) && x86_flag[i * 32 + j][0])
92 				buf_printf("%s ", x86_flag[i * 32 + j]);
93 		}
94 	}
95 	buf_printf("\n");
96 }
97 #endif
98 
99 /*
100  * Print information for a single CPU.
101  */
102 static void
103 print_cpu(struct cpu_info * cpu_info, unsigned id)
104 {
105 
106 	buf_printf("%-16s: %d\n", "processor", id);
107 
108 #if defined(__i386__)
109 	switch (cpu_info->vendor) {
110 	case CPU_VENDOR_INTEL:
111 		buf_printf("%-16s: %s\n", "vendor_id", "GenuineIntel");
112 		buf_printf("%-16s: %s\n", "model name", "Intel");
113 		break;
114 	case CPU_VENDOR_AMD:
115 		buf_printf("%-16s: %s\n", "vendor_id", "AuthenticAMD");
116 		buf_printf("%-16s: %s\n", "model name", "AMD");
117 		break;
118 	default:
119 		buf_printf("%-16s: %s\n", "vendor_id", "unknown");
120 	}
121 
122 	buf_printf("%-16s: %d\n", "cpu family", cpu_info->family);
123 	buf_printf("%-16s: %d\n", "model", cpu_info->model);
124 	buf_printf("%-16s: %d\n", "stepping", cpu_info->stepping);
125 	buf_printf("%-16s: %d\n", "cpu MHz", cpu_info->freq);
126 	buf_printf("%-16s: ", "flags");
127 	print_x86_cpu_flags(cpu_info->flags);
128 	buf_printf("\n");
129 #endif
130 }
131 
132 /*
133  * Generate the contents of /proc/cpuinfo.
134  */
135 void
136 root_cpuinfo(void)
137 {
138 	struct cpu_info cpu_info[CONFIG_MAX_CPUS];
139 	struct machine machine;
140 	unsigned int c;
141 
142 	if (sys_getmachine(&machine)) {
143 		printf("PROCFS: cannot get machine\n");
144 		return;
145 	}
146 	if (sys_getcpuinfo(&cpu_info)) {
147 		printf("PROCFS: cannot get CPU info\n");
148 		return;
149 	}
150 
151 	for (c = 0; c < machine.processors_count; c++)
152 		print_cpu(&cpu_info[c], c);
153 }
154