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