3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 smp_cpu_t smp_cpu_list
;
28 smp_cpu_t
*smp_cpu_getnextcpu (smp_cpu_t
*cpu
)
31 return smp_cpu_list
.next
;
33 smp_cpu_t
*nextcpu
= cpu
->next
;
35 if (cpu
== &smp_cpu_list
)
45 char *str
= (char *) kmalloc (sizeof (char) * (cpu_cnt
* 256));
55 for (cpu
= smp_cpu_list
.next
; cpu
!= &smp_cpu_list
; cpu
= cpu
->next
) {
56 if (cpu
->arch
== SMP_ARCH_x86
)
57 strcpy (cpuarch
, "x86");
58 else if (cpu
->arch
== SMP_ARCH_ARM
)
59 strcpy (cpuarch
, "ARM");
60 else if (cpu
->arch
!= SMP_ARCH_x86
)
61 strcpy (cpuarch
, "unknown");
63 sprintf (strcpu
, "CPU %d (%s)\n\tarch: %s\n\tstate: %s\n\tfeatures: ", cpu_cnt
, (cpu
->flags
== SMP_FLAGS_CPU_BS
) ? "BS" : "AP",
64 cpuarch
, (cpu
->state
== SMP_STATE_CPU_UP
) ? "running" : "down");
68 smp_arch_x86
*arch_spec
= cpu
->arch_spec
;
75 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_FPU
)
77 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_VME
)
79 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_DE
)
81 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PSE
)
83 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_TSC
)
85 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_MSR
)
87 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PAE
)
89 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_MCE
)
91 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_CX8
)
93 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_APIC
)
94 strcat (str
, "apic ");
95 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_SEP
)
97 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_MTRR
)
98 strcat (str
, "mttr ");
99 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PGE
)
100 strcat (str
, "pge ");
101 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_MCA
)
102 strcat (str
, "mca ");
103 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_CMOV
)
104 strcat (str
, "cmov ");
105 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PAT
)
106 strcat (str
, "pat ");
107 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PSE36
)
108 strcat (str
, "pse36 ");
109 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PSN
)
110 strcat (str
, "psn ");
111 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_CLFSH
)
112 strcat (str
, "clfsh ");
113 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_DS
)
115 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_ACPI
)
116 strcat (str
, "acpi ");
117 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_MMX
)
118 strcat (str
, "mmx ");
119 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_FXSR
)
120 strcat (str
, "fxsr ");
121 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_SSE
)
122 strcat (str
, "sse ");
123 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_SSE2
)
124 strcat (str
, "sse2 ");
125 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_SS
)
127 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_HTT
)
128 strcat (str
, "htt ");
129 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_TM
)
131 if (arch_spec
->features
& SMP_ARCH_x86_FEATURE_PBE
)
132 strcat (str
, "pbe ");
139 vfs_list_add ("cpuinfo", VFS_FILEATTR_FILE
| VFS_FILEATTR_READ
| VFS_FILEATTR_SYSTEM
, "/proc/");
141 vfs_content_t content
;
143 content
.len
= strlen (str
);
145 vfs_mmap ("/proc/cpuinfo", 13, &content
);
148 /* mostly x86 stuff */
149 unsigned smp_cpu_register (unsigned char arch
, unsigned char state
, unsigned char flags
, void *arch_spec
)
153 /* alloc and init context */
154 cpu
= (smp_cpu_t
*) kmalloc (sizeof (smp_cpu_t
));
160 cpu
->arch_spec
= arch_spec
;
165 cpu
->next
= &smp_cpu_list
;
166 cpu
->prev
= smp_cpu_list
.prev
;
167 cpu
->prev
->next
= cpu
;
168 cpu
->next
->prev
= cpu
;
173 unsigned int init_smp ()
175 smp_cpu_list
.next
= &smp_cpu_list
;
176 smp_cpu_list
.prev
= &smp_cpu_list
;
178 return arch_smp_init ();