Fixed ZDE build - missing header file
[ZeXOS.git] / kernel / core / smp.c
blob3a6a2b34efca0a42964cee7b4528be6d2b8545ba
1 /*
2 * ZeX/OS
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/>.
20 #include <system.h>
21 #include <string.h>
22 #include <config.h>
23 #include <smp.h>
24 #include <vfs.h>
26 smp_cpu_t smp_cpu_list;
28 smp_cpu_t *smp_cpu_getnextcpu (smp_cpu_t *cpu)
30 if (!cpu)
31 return smp_cpu_list.next;
33 smp_cpu_t *nextcpu = cpu->next;
35 if (cpu == &smp_cpu_list)
36 return 0;
38 return nextcpu;
41 void smp_cpu_check ()
43 unsigned cpu_cnt = 1;
45 /*char *str = (char *) kmalloc (sizeof (char) * (cpu_cnt * 256));
47 if (!str)
48 return;
50 str[0] = '\0';*/
52 /*char strcpu[80];
54 char cpuarch[16];
56 smp_cpu_t *cpu;
57 for (cpu = smp_cpu_list.next; cpu != &smp_cpu_list; cpu = cpu->next) {*/
58 /*if (cpu->arch == SMP_ARCH_x86)
59 strcpy (cpuarch, "x86");
60 else if (cpu->arch == SMP_ARCH_ARM)
61 strcpy (cpuarch, "ARM");
62 else if (cpu->arch != SMP_ARCH_x86)
63 strcpy (cpuarch, "unknown");
65 sprintf (strcpu, "CPU %d (%s)\n\tarch: %s\n\tstate: %s\n\tfeatures: ", cpu_cnt, (cpu->flags == SMP_FLAGS_CPU_BS ) ? "BS" : "AP",
66 cpuarch, (cpu->state == SMP_STATE_CPU_UP ) ? "running" : "down");
68 strcpy (str, strcpu);
70 smp_arch_x86 *arch_spec = cpu->arch_spec;
72 if (!arch_spec) {
73 strcat (str, "N/A");
74 goto r;
77 if (arch_spec->features & SMP_ARCH_x86_FEATURE_FPU)
78 strcat (str, "fpu ");
79 if (arch_spec->features & SMP_ARCH_x86_FEATURE_VME)
80 strcat (str, "vme ");
81 if (arch_spec->features & SMP_ARCH_x86_FEATURE_DE)
82 strcat (str, "de ");
83 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PSE)
84 strcat (str, "pse ");
85 if (arch_spec->features & SMP_ARCH_x86_FEATURE_TSC)
86 strcat (str, "tsc ");
87 if (arch_spec->features & SMP_ARCH_x86_FEATURE_MSR)
88 strcat (str, "msr ");
89 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PAE)
90 strcat (str, "pae ");
91 if (arch_spec->features & SMP_ARCH_x86_FEATURE_MCE)
92 strcat (str, "mce ");
93 if (arch_spec->features & SMP_ARCH_x86_FEATURE_CX8)
94 strcat (str, "cx8 ");
95 if (arch_spec->features & SMP_ARCH_x86_FEATURE_APIC)
96 strcat (str, "apic ");
97 if (arch_spec->features & SMP_ARCH_x86_FEATURE_SEP)
98 strcat (str, "sep ");
99 if (arch_spec->features & SMP_ARCH_x86_FEATURE_MTRR)
100 strcat (str, "mttr ");
101 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PGE)
102 strcat (str, "pge ");
103 if (arch_spec->features & SMP_ARCH_x86_FEATURE_MCA)
104 strcat (str, "mca ");
105 if (arch_spec->features & SMP_ARCH_x86_FEATURE_CMOV)
106 strcat (str, "cmov ");
107 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PAT)
108 strcat (str, "pat ");
109 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PSE36)
110 strcat (str, "pse36 ");
111 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PSN)
112 strcat (str, "psn ");
113 if (arch_spec->features & SMP_ARCH_x86_FEATURE_CLFSH)
114 strcat (str, "clfsh ");
115 if (arch_spec->features & SMP_ARCH_x86_FEATURE_DS)
116 strcat (str, "ds ");
117 if (arch_spec->features & SMP_ARCH_x86_FEATURE_ACPI)
118 strcat (str, "acpi ");
119 if (arch_spec->features & SMP_ARCH_x86_FEATURE_MMX)
120 strcat (str, "mmx ");
121 if (arch_spec->features & SMP_ARCH_x86_FEATURE_FXSR)
122 strcat (str, "fxsr ");
123 if (arch_spec->features & SMP_ARCH_x86_FEATURE_SSE)
124 strcat (str, "sse ");
125 if (arch_spec->features & SMP_ARCH_x86_FEATURE_SSE2)
126 strcat (str, "sse2 ");
127 if (arch_spec->features & SMP_ARCH_x86_FEATURE_SS)
128 strcat (str, "ss ");
129 if (arch_spec->features & SMP_ARCH_x86_FEATURE_HTT)
130 strcat (str, "htt ");
131 if (arch_spec->features & SMP_ARCH_x86_FEATURE_TM)
132 strcat (str, "tm ");
133 if (arch_spec->features & SMP_ARCH_x86_FEATURE_PBE)
134 strcat (str, "pbe ");
136 strcat (str, "\n");
138 cpu_cnt ++;*/
141 //vfs_list_add ("cpuinfo", VFS_FILEATTR_FILE | VFS_FILEATTR_READ | VFS_FILEATTR_SYSTEM, "/proc/");
143 /*vfs_content_t content;
144 content.ptr = "prd";
145 content.len = 3;*/
147 //vfs_mmap ("/proc/cpuinfo", 13, &content);
150 /* mostly x86 stuff */
151 unsigned smp_cpu_register (unsigned char arch, unsigned char state, unsigned char flags, void *arch_spec)
153 smp_cpu_t *cpu;
155 /* alloc and init context */
156 cpu = (smp_cpu_t *) kmalloc (sizeof (smp_cpu_t));
158 if (!cpu)
159 return 0;
161 cpu->arch = arch;
162 cpu->arch_spec = arch_spec;
163 cpu->flags = flags;
164 cpu->state = state;
166 /* add into list */
167 cpu->next = &smp_cpu_list;
168 cpu->prev = smp_cpu_list.prev;
169 cpu->prev->next = cpu;
170 cpu->next->prev = cpu;
172 return 1;
175 unsigned int init_smp ()
177 smp_cpu_list.next = &smp_cpu_list;
178 smp_cpu_list.prev = &smp_cpu_list;
180 return arch_smp_init ();