]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/CpuRuntimeDxe/Cpu.c
Add comments for IntelFrameworkModulePkg Header file.
[mirror_edk2.git] / Nt32Pkg / CpuRuntimeDxe / Cpu.c
CommitLineData
6ae81428 1/**@file\r
770bcbb6 2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 Cpu.c\r
15\r
16Abstract:\r
17\r
18 NT Emulation Architectural Protocol Driver as defined in Tiano.\r
19 This CPU module abstracts the interrupt subsystem of a platform and\r
20 the CPU-specific setjump/long pair. Other services are not implemented\r
21 in this driver.\r
22\r
6ae81428 23**/\r
770bcbb6 24\r
770bcbb6 25\r
26#include "CpuDriver.h"\r
27\r
b397fbbb
A
28\r
29CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
30 CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
31 NULL,\r
32 {\r
33 WinNtFlushCpuDataCache,\r
34 WinNtEnableInterrupt,\r
35 WinNtDisableInterrupt,\r
36 WinNtGetInterruptState,\r
37 WinNtInit,\r
38 WinNtRegisterInterruptHandler,\r
39 WinNtGetTimerValue,\r
40 WinNtSetMemoryAttributes,\r
41 0,\r
42 4\r
43 },\r
44 {\r
45 CpuMemoryServiceRead,\r
46 CpuMemoryServiceWrite,\r
47 CpuIoServiceRead,\r
48 CpuIoServiceWrite\r
49 },\r
50 0,\r
51 TRUE\r
52};\r
53\r
770bcbb6 54#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
55\r
770bcbb6 56\r
770bcbb6 57\r
58typedef union {\r
59 EFI_CPU_DATA_RECORD *DataRecord;\r
60 UINT8 *Raw;\r
61} EFI_CPU_DATA_RECORD_BUFFER;\r
62\r
63EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {\r
64 EFI_PROCESSOR_SUBCLASS_VERSION, // Version\r
65 sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size\r
66 0, // Instance, Initialize later\r
67 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance\r
68 0 // RecordType, Initialize later\r
69};\r
70\r
71//\r
72// Service routines for the driver\r
73//\r
770bcbb6 74EFI_STATUS\r
75EFIAPI\r
76WinNtFlushCpuDataCache (\r
77 IN EFI_CPU_ARCH_PROTOCOL *This,\r
78 IN EFI_PHYSICAL_ADDRESS Start,\r
79 IN UINT64 Length,\r
80 IN EFI_CPU_FLUSH_TYPE FlushType\r
81 )\r
82/*++\r
83\r
84Routine Description:\r
85\r
86 This routine would provide support for flushing the CPU data cache.\r
87 In the case of NT emulation environment, this flushing is not necessary and\r
88 is thus not implemented.\r
89\r
90Arguments:\r
91\r
92 Pointer to CPU Architectural Protocol interface\r
93 Start adddress in memory to flush\r
94 Length of memory to flush\r
95 Flush type\r
96\r
97Returns:\r
98\r
99 Status\r
100 EFI_SUCCESS\r
101\r
102--*/\r
103// TODO: This - add argument and description to function comment\r
104// TODO: FlushType - add argument and description to function comment\r
105// TODO: EFI_UNSUPPORTED - add return value to function comment\r
106{\r
107 if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
108 //\r
109 // Only WB flush is supported. We actually need do nothing on NT emulator\r
110 // environment. Classify this to follow EFI spec\r
111 //\r
112 return EFI_SUCCESS;\r
113 }\r
114 //\r
115 // Other flush types are not supported by NT emulator\r
116 //\r
117 return EFI_UNSUPPORTED;\r
118}\r
119\r
b397fbbb 120\r
770bcbb6 121EFI_STATUS\r
122EFIAPI\r
123WinNtEnableInterrupt (\r
124 IN EFI_CPU_ARCH_PROTOCOL *This\r
125 )\r
126/*++\r
127\r
128Routine Description:\r
129\r
130 This routine provides support for emulation of the interrupt enable of the\r
131 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
132 Architectural Protocol observes in order to defer behaviour while in its\r
133 emulated interrupt, or timer tick.\r
134\r
135Arguments:\r
136\r
137 Pointer to CPU Architectural Protocol interface\r
138\r
139Returns:\r
140\r
141 Status\r
142 EFI_SUCCESS\r
143\r
144--*/\r
145// TODO: This - add argument and description to function comment\r
146{\r
147 CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
148\r
149 Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
150 Private->InterruptState = TRUE;\r
151 return EFI_SUCCESS;\r
152}\r
153\r
b397fbbb 154\r
770bcbb6 155EFI_STATUS\r
156EFIAPI\r
157WinNtDisableInterrupt (\r
158 IN EFI_CPU_ARCH_PROTOCOL *This\r
159 )\r
160/*++\r
161\r
162Routine Description:\r
163\r
164 This routine provides support for emulation of the interrupt disable of the\r
165 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
166 Architectural Protocol observes in order to defer behaviour while in its\r
167 emulated interrupt, or timer tick.\r
168\r
169Arguments:\r
170\r
171 Pointer to CPU Architectural Protocol interface\r
172\r
173Returns:\r
174\r
175 Status\r
176 EFI_SUCCESS\r
177\r
178--*/\r
179// TODO: This - add argument and description to function comment\r
180{\r
181 CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
182\r
183 Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
184 Private->InterruptState = FALSE;\r
185 return EFI_SUCCESS;\r
186}\r
187\r
b397fbbb 188\r
770bcbb6 189EFI_STATUS\r
190EFIAPI\r
191WinNtGetInterruptState (\r
192 IN EFI_CPU_ARCH_PROTOCOL *This,\r
193 OUT BOOLEAN *State\r
194 )\r
195/*++\r
196\r
197Routine Description:\r
198\r
199 This routine provides support for emulation of the interrupt disable of the\r
200 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
201 Architectural Protocol observes in order to defer behaviour while in its\r
202 emulated interrupt, or timer tick.\r
203\r
204Arguments:\r
205\r
206 Pointer to CPU Architectural Protocol interface\r
207\r
208Returns:\r
209\r
210 Status\r
211 EFI_SUCCESS\r
212\r
213--*/\r
214// TODO: This - add argument and description to function comment\r
215// TODO: State - add argument and description to function comment\r
216// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
217{\r
218 CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
219\r
220 if (State == NULL) {\r
221 return EFI_INVALID_PARAMETER;\r
222 }\r
223\r
224 Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
225 *State = Private->InterruptState;\r
226 return EFI_SUCCESS;\r
227}\r
228\r
b397fbbb 229\r
770bcbb6 230EFI_STATUS\r
231EFIAPI\r
232WinNtInit (\r
233 IN EFI_CPU_ARCH_PROTOCOL *This,\r
234 IN EFI_CPU_INIT_TYPE InitType\r
235 )\r
236/*++\r
237\r
238Routine Description:\r
239\r
240 This routine would support generation of a CPU INIT. At\r
241 present, this code does not provide emulation.\r
242\r
243Arguments:\r
244\r
245 Pointer to CPU Architectural Protocol interface\r
246 INIT Type\r
247\r
248Returns:\r
249\r
250 Status\r
251 EFI_UNSUPPORTED - not yet implemented\r
252\r
253--*/\r
254// TODO: This - add argument and description to function comment\r
255// TODO: InitType - add argument and description to function comment\r
256{\r
770bcbb6 257 return EFI_UNSUPPORTED;\r
258}\r
259\r
b397fbbb 260\r
770bcbb6 261EFI_STATUS\r
262EFIAPI\r
263WinNtRegisterInterruptHandler (\r
264 IN EFI_CPU_ARCH_PROTOCOL *This,\r
265 IN EFI_EXCEPTION_TYPE InterruptType,\r
266 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
267 )\r
268/*++\r
269\r
270Routine Description:\r
271\r
272 This routine would support registration of an interrupt handler. At\r
273 present, this code does not provide emulation.\r
274\r
275Arguments:\r
276\r
277 Pointer to CPU Architectural Protocol interface\r
278 Pointer to interrupt handlers\r
279 Interrupt type\r
280\r
281Returns:\r
282\r
283 Status\r
284 EFI_UNSUPPORTED - not yet implemented\r
285\r
286--*/\r
287// TODO: This - add argument and description to function comment\r
288// TODO: InterruptType - add argument and description to function comment\r
289// TODO: InterruptHandler - add argument and description to function comment\r
290{\r
770bcbb6 291\r
292 //\r
293 // Do parameter checking for EFI spec conformance\r
294 //\r
295 if (InterruptType < 0 || InterruptType > 0xff) {\r
296 return EFI_UNSUPPORTED;\r
297 }\r
298 //\r
299 // Do nothing for Nt32 emulation\r
300 //\r
770bcbb6 301 return EFI_UNSUPPORTED;\r
302}\r
303\r
b397fbbb 304\r
770bcbb6 305EFI_STATUS\r
306EFIAPI\r
307WinNtGetTimerValue (\r
308 IN EFI_CPU_ARCH_PROTOCOL *This,\r
309 IN UINT32 TimerIndex,\r
310 OUT UINT64 *TimerValue,\r
311 OUT UINT64 *TimerPeriod OPTIONAL\r
312 )\r
313/*++\r
314\r
315Routine Description:\r
316\r
317 This routine would support querying of an on-CPU timer. At present,\r
318 this code does not provide timer emulation.\r
319\r
320Arguments:\r
321\r
322 This - Pointer to CPU Architectural Protocol interface\r
323 TimerIndex - Index of given CPU timer\r
324 TimerValue - Output of the timer\r
325 TimerPeriod - Output of the timer period\r
326\r
327Returns:\r
328\r
329 EFI_UNSUPPORTED - not yet implemented\r
330 EFI_INVALID_PARAMETER - TimeValue is NULL\r
331\r
332--*/\r
333{\r
334 if (TimerValue == NULL) {\r
335 return EFI_INVALID_PARAMETER;\r
336 }\r
337\r
338 //\r
339 // No timer supported\r
340 //\r
341 return EFI_UNSUPPORTED;\r
342}\r
343\r
b397fbbb 344\r
770bcbb6 345EFI_STATUS\r
346EFIAPI\r
347WinNtSetMemoryAttributes (\r
348 IN EFI_CPU_ARCH_PROTOCOL *This,\r
349 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
350 IN UINT64 Length,\r
351 IN UINT64 Attributes\r
352 )\r
353/*++\r
354\r
355Routine Description:\r
356\r
357 This routine would support querying of an on-CPU timer. At present,\r
358 this code does not provide timer emulation.\r
359\r
360Arguments:\r
361\r
362 Pointer to CPU Architectural Protocol interface\r
363 Start address of memory region\r
364 The size in bytes of the memory region\r
365 The bit mask of attributes to set for the memory region\r
366\r
367Returns:\r
368\r
369 Status\r
370 EFI_UNSUPPORTED - not yet implemented\r
371\r
372--*/\r
373// TODO: This - add argument and description to function comment\r
374// TODO: BaseAddress - add argument and description to function comment\r
375// TODO: Length - add argument and description to function comment\r
376// TODO: Attributes - add argument and description to function comment\r
377// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
378{\r
770bcbb6 379 //\r
380 // Check for invalid parameter for Spec conformance\r
381 //\r
382 if (Length == 0) {\r
383 return EFI_INVALID_PARAMETER;\r
384 }\r
385\r
386 //\r
387 // Do nothing for Nt32 emulation\r
388 //\r
770bcbb6 389 return EFI_UNSUPPORTED;\r
390}\r
391\r
392\r
770bcbb6 393VOID\r
b397fbbb
A
394CpuUpdateDataHub (\r
395 VOID\r
770bcbb6 396 )\r
397/*++\r
398\r
399Routine Description:\r
400 This function will log processor version and frequency data to data hub.\r
401\r
402Arguments:\r
403 Event - Event whose notification function is being invoked.\r
404 Context - Pointer to the notification function's context.\r
405\r
406Returns:\r
407 None.\r
408\r
409--*/\r
410{\r
411 EFI_STATUS Status;\r
412 EFI_CPU_DATA_RECORD_BUFFER RecordBuffer;\r
770bcbb6 413 UINT32 HeaderSize;\r
414 UINT32 TotalSize;\r
770bcbb6 415 EFI_DATA_HUB_PROTOCOL *DataHub;\r
5fd5fcd3 416 EFI_HII_HANDLE HiiHandle;\r
770bcbb6 417\r
418 //\r
b397fbbb 419 // Locate DataHub protocol.\r
770bcbb6 420 //\r
0b94e319 421 Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);\r
770bcbb6 422 if (EFI_ERROR (Status)) {\r
b397fbbb 423 return;\r
770bcbb6 424 }\r
b397fbbb 425\r
770bcbb6 426 //\r
427 // Initialize data record header\r
428 //\r
429 mCpuDataRecordHeader.Instance = 1;\r
430 HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
431\r
432 RecordBuffer.Raw = AllocatePool (HeaderSize + EFI_CPU_DATA_MAXIMUM_LENGTH);\r
433 if (RecordBuffer.Raw == NULL) {\r
434 return ;\r
435 }\r
436\r
b397fbbb
A
437 //\r
438 // Initialize strings to HII database\r
439 //\r
cb7d01c0 440 HiiHandle = HiiAddPackages (\r
441 &gEfiProcessorProducerGuid,\r
442 NULL,\r
443 CpuStrings,\r
444 NULL\r
445 );\r
446 ASSERT (HiiHandle != NULL);\r
b397fbbb 447\r
770bcbb6 448 CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize);\r
449\r
b397fbbb
A
450\r
451 RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorVersionRecordType;\r
e0f06862 452 RecordBuffer.DataRecord->VariableRecord.ProcessorVersion = STRING_TOKEN (STR_PROCESSOR_VERSION);\r
b397fbbb
A
453 TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_VERSION_DATA);\r
454\r
455 Status = DataHub->LogData (\r
456 DataHub,\r
457 &gEfiProcessorSubClassGuid,\r
458 &gEfiProcessorProducerGuid,\r
459 EFI_DATA_RECORD_CLASS_DATA,\r
460 RecordBuffer.Raw,\r
461 TotalSize\r
462 );\r
463\r
464 //\r
e0f06862 465 // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
b397fbbb
A
466 //\r
467 RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorCoreFrequencyRecordType;\r
e0f06862 468 RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Value = 1234;\r
b397fbbb
A
469 RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Exponent = 6;\r
470 TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA);\r
471\r
472 Status = DataHub->LogData (\r
473 DataHub,\r
474 &gEfiProcessorSubClassGuid,\r
475 &gEfiProcessorProducerGuid,\r
476 EFI_DATA_RECORD_CLASS_DATA,\r
477 RecordBuffer.Raw,\r
478 TotalSize\r
479 );\r
480\r
481 FreePool (RecordBuffer.Raw);\r
482}\r
483\r
484\r
485\r
486EFI_STATUS\r
487EFIAPI\r
488InitializeCpu (\r
489 IN EFI_HANDLE ImageHandle,\r
490 IN EFI_SYSTEM_TABLE *SystemTable\r
491 )\r
492/*++\r
493\r
494Routine Description:\r
495\r
496 Initialize the state information for the CPU Architectural Protocol\r
497\r
498Arguments:\r
499\r
500 ImageHandle of the loaded driver\r
501 Pointer to the System Table\r
502\r
503Returns:\r
504\r
505 Status\r
506\r
507 EFI_SUCCESS - protocol instance can be published\r
508 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure\r
509 EFI_DEVICE_ERROR - cannot create the thread\r
510\r
511--*/\r
512{\r
513 EFI_STATUS Status;\r
514\r
515 CpuUpdateDataHub ();\r
516\r
517 Status = gBS->InstallMultipleProtocolInterfaces (\r
518 &mCpuTemplate.Handle,\r
519 &gEfiCpuArchProtocolGuid, &mCpuTemplate.Cpu,\r
520 &gEfiCpuIoProtocolGuid, &mCpuTemplate.CpuIo,\r
521 NULL\r
522 );\r
523 ASSERT_EFI_ERROR (Status);\r
524\r
525 return Status;\r
770bcbb6 526}\r
b397fbbb
A
527\r
528\r