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