-/** @file\r
-\r
- Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
- \r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-/** @file\r
- DXE Cpu Driver.\r
- \r
- May need some porting work for platform specifics.\r
-\r
- Copyright (c) 2008, Apple Inc \r
- All rights reserved. This program and the accompanying materials \r
- are licensed and made available under the terms and conditions of the BSD License \r
- which accompanies this distribution. The full text of the license may be found at \r
- http://opensource.org/licenses/bsd-license.php \r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-**/\r
-\r
-#include "CpuDxe.h"\r
-\r
-EFI_PERIODIC_CALLBACK gPeriodicCallBack = (EFI_PERIODIC_CALLBACK)NULL;\r
-\r
-EFI_DEBUG_SUPPORT_PERIODIC_CALLBACK_PROTOCOL *gDebugSupportCallback = NULL;\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportGetMaximumProcessorIndex (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- OUT UINTN *MaxProcessorIndex\r
- )\r
-/*++\r
-\r
-Routine Description: This is a DebugSupport protocol member function.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- MaxProcessorIndex - The maximuim supported processor index\r
-\r
-Returns:\r
- Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
-\r
---*/\r
-{\r
- *MaxProcessorIndex = 0;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportRegisterPeriodicCallback (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN EFI_PERIODIC_CALLBACK PeriodicCallback\r
- )\r
-/*++\r
-\r
-Routine Description: This is a DebugSupport protocol member function.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- PeriodicCallback - Callback function\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS\r
- EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
- no handler registered for it\r
- EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.\r
-\r
- Other possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if ((gPeriodicCallBack != (EFI_PERIODIC_CALLBACK)NULL) && (PeriodicCallback != (EFI_PERIODIC_CALLBACK)NULL)) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
- \r
- gPeriodicCallBack = PeriodicCallback;\r
- \r
- if (gDebugSupportCallback != NULL) {\r
- //\r
- // We can only update this protocol if the Register Protocol Notify has fired. If it fires \r
- // after this call it will update with gPeriodicCallBack value.\r
- //\r
- gDebugSupportCallback->PeriodicCallback = gPeriodicCallBack;\r
- }\r
- \r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportRegisterExceptionCallback (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN EFI_EXCEPTION_CALLBACK NewCallback,\r
- IN EFI_EXCEPTION_TYPE ExceptionType\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is a DebugSupport protocol member function.\r
-\r
- This code executes in boot services context.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- NewCallback - Callback function\r
- ExceptionType - Which exception to hook\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS\r
- EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
- no handler registered for it\r
- EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.\r
-\r
- Other possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return RegisterDebuggerInterruptHandler (ExceptionType, NewCallback);\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportInvalidateInstructionCache (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN VOID *Start,\r
- IN UINT64 Length\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is a DebugSupport protocol member function.\r
- Calls assembly routine to flush cache.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- Start - Physical base of the memory range to be invalidated\r
- Length - mininum number of bytes in instruction cache to invalidate\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - always return success\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- InvalidateInstructionCache();\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-//\r
-// This is a global that is the actual interface\r
-//\r
-EFI_DEBUG_SUPPORT_PROTOCOL gDebugSupportProtocolInterface = {\r
- IsaArm, // Fixme to be more generic\r
- DebugSupportGetMaximumProcessorIndex,\r
- DebugSupportRegisterPeriodicCallback,\r
- DebugSupportRegisterExceptionCallback,\r
- DebugSupportInvalidateInstructionCache\r
-};\r
-\r
-\r
-VOID\r
-EFIAPI\r
-DebugSupportPeriodicCallbackEventProtocolNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- EFI_STATUS Status;\r
- \r
- Status = gBS->LocateProtocol (&gEfiDebugSupportPeriodicCallbackProtocolGuid, NULL, (VOID **)&gDebugSupportCallback);\r
- if (!EFI_ERROR (Status)) {\r
- gDebugSupportCallback->PeriodicCallback = gPeriodicCallBack;\r
- }\r
-}\r
-\r
-VOID *gRegistration = NULL;\r
-\r
-\r
-EFI_DEBUG_SUPPORT_PROTOCOL *\r
-InitilaizeDebugSupport (\r
- VOID\r
- )\r
-{\r
- // RPN gEfiDebugSupportPeriodicCallbackProtocolGuid\r
- EFI_STATUS Status;\r
- EFI_EVENT Event;\r
-\r
- if (!FeaturePcdGet (PcdCpuDxeProduceDebugSupport)) {\r
- // Don't include this code unless Feature Flag is set\r
- return NULL;\r
- }\r
- \r
-\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL, \r
- TPL_CALLBACK, \r
- DebugSupportPeriodicCallbackEventProtocolNotify, \r
- NULL, \r
- &Event\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = gBS->RegisterProtocolNotify (&gEfiDebugSupportPeriodicCallbackProtocolGuid, Event, &gRegistration);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // We assume the Timer must depend on our driver to register interrupts so we don't need to do\r
- // a gBS->SignalEvent (Event) here to check to see if the protocol allready exists\r
- //\r
-\r
- return &gDebugSupportProtocolInterface;\r
-}\r