Adding support for BeagleBoard.
[mirror_edk2.git] / EmbeddedPkg / DebugSupportDxe / DebugSupport.c
1 /** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Uefi.h>
16
17 #include <Library/CacheMaintenanceLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20
21 #include <Protocol/Cpu.h>
22 #include <Protocol/DebugSupport.h>
23 #include <Protocol/TimerDebugSupport.h>
24
25 EFI_STATUS
26 EFIAPI
27 DebugSupportGetMaximumProcessorIndex (
28 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
29 OUT UINTN *MaxProcessorIndex
30 )
31 {
32 if (MaxProcessorIndex == NULL) {
33 return EFI_INVALID_PARAMETER;
34 }
35
36 *MaxProcessorIndex = 0;
37
38 return EFI_SUCCESS;
39 }
40
41 EFI_STATUS
42 EFIAPI
43 DebugSupportRegisterPeriodicCallback (
44 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
45 IN UINTN ProcessorIndex,
46 IN EFI_PERIODIC_CALLBACK PeriodicCallback
47 )
48 {
49 TIMER_DEBUG_SUPPORT_PROTOCOL *Timer;
50 EFI_STATUS Status;
51
52 Status = gBS->LocateProtocol(&gTimerDebugSupportProtocolGuid, NULL, (VOID **)&Timer);
53 if (EFI_ERROR(Status)) {
54 return Status;
55 }
56
57 Status = Timer->RegisterPeriodicCallback(Timer, PeriodicCallback);
58
59 return Status;
60 }
61
62 EFI_STATUS
63 EFIAPI
64 DebugSupportRegisterExceptionCallback (
65 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
66 IN UINTN ProcessorIndex,
67 IN EFI_EXCEPTION_CALLBACK ExceptionCallback,
68 IN EFI_EXCEPTION_TYPE ExceptionType
69 )
70 {
71 EFI_CPU_ARCH_PROTOCOL *Cpu;
72 EFI_STATUS Status;
73
74 Status = gBS->LocateProtocol(&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);
75 if (EFI_ERROR(Status)) {
76 return Status;
77 }
78
79 Status = Cpu->RegisterInterruptHandler(Cpu, ExceptionType, (EFI_CPU_INTERRUPT_HANDLER)ExceptionCallback);
80
81 return Status;
82 }
83
84 EFI_STATUS
85 EFIAPI
86 DebugSupportInvalidateInstructionCache (
87 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
88 IN UINTN ProcessorIndex,
89 IN VOID *Start,
90 IN UINT64 Length
91 )
92 {
93 InvalidateInstructionCacheRange(Start, Length);
94 return EFI_SUCCESS;
95 }
96
97 EFI_DEBUG_SUPPORT_PROTOCOL mDebugSupport = {
98 IsaArm,
99 DebugSupportGetMaximumProcessorIndex,
100 DebugSupportRegisterPeriodicCallback,
101 DebugSupportRegisterExceptionCallback,
102 DebugSupportInvalidateInstructionCache
103 };
104
105 EFI_STATUS
106 DebugSupportDxeInitialize (
107 IN EFI_HANDLE ImageHandle,
108 IN EFI_SYSTEM_TABLE *SystemTable
109 )
110 {
111 EFI_STATUS Status;
112 EFI_HANDLE Handle = NULL;
113
114 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiDebugSupportProtocolGuid);
115 Status = gBS->InstallMultipleProtocolInterfaces(&Handle, &gEfiDebugSupportProtocolGuid, &mDebugSupport, NULL);
116
117 return Status;
118 }
119