]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Drivers/PL390Gic/PL390GicSec.c
ArmPkg/Application/LinuxLoader: Create a Linux Loader EFI application
[mirror_edk2.git] / ArmPkg / Drivers / PL390Gic / PL390GicSec.c
CommitLineData
1bfda055 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4* \r
5* This program and the accompanying materials \r
6* are licensed and made available under the terms and conditions of the BSD License \r
7* which accompanies this distribution. The full text of the license may be found at \r
8* http://opensource.org/licenses/bsd-license.php \r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12*\r
13**/\r
14\r
9e2b420e 15#include <Uefi.h>\r
1bfda055 16#include <Library/IoLib.h>\r
17#include <Drivers/PL390Gic.h>\r
18\r
19/*\r
20 * This function configures the all interrupts to be Non-secure.\r
21 *\r
22 */\r
23VOID\r
24EFIAPI\r
25PL390GicSetupNonSecure (\r
26 IN INTN GicDistributorBase,\r
27 IN INTN GicInterruptInterfaceBase\r
28 )\r
29{\r
9e2b420e 30 UINTN CachedPriorityMask = MmioRead32(GicInterruptInterfaceBase + GIC_ICCPMR);\r
1bfda055 31\r
9e2b420e 32 // Set priority Mask so that no interrupts get through to CPU\r
33 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCPMR, 0);\r
1bfda055 34\r
9e2b420e 35 // Check if there are any pending interrupts\r
36 while(0 != (MmioRead32(GicDistributorBase + GIC_ICDICPR) & 0xF)) {\r
37 // Some of the SGI's are still pending, read Ack register and send End of Interrupt Signal\r
38 UINTN InterruptId = MmioRead32(GicInterruptInterfaceBase + GIC_ICCIAR);\r
1bfda055 39\r
9e2b420e 40 // Write to End of interrupt signal\r
41 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCEIOR, InterruptId);\r
42 }\r
1bfda055 43\r
44 // Ensure all GIC interrupts are Non-Secure\r
9e2b420e 45 MmioWrite32(GicDistributorBase + GIC_ICDISR, 0xffffffff); // IRQs 0-31 are Non-Secure : Private Peripheral Interrupt[31:16] & Software Generated Interrupt[15:0]\r
46 MmioWrite32(GicDistributorBase + GIC_ICDISR + 4, 0xffffffff); // IRQs 32-63 are Non-Secure : Shared Peripheral Interrupt\r
47 MmioWrite32(GicDistributorBase + GIC_ICDISR + 8, 0xffffffff); // And another 32 in case we're on the testchip : Shared Peripheral Interrupt (2)\r
1bfda055 48\r
49 // Ensure all interrupts can get through the priority mask\r
9e2b420e 50 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCPMR, CachedPriorityMask);\r
1bfda055 51}\r
52\r
53VOID\r
54EFIAPI\r
55PL390GicEnableInterruptInterface (\r
56 IN INTN GicInterruptInterfaceBase\r
57 )\r
58{\r
2ac288f9 59 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCPMR, 0x000000FF); /* Set Priority Mask to allow interrupts */\r
1bfda055 60\r
2ac288f9 61 /*\r
62 * Enable CPU interface in Secure world\r
1bfda055 63 * Enable CPU inteface in Non-secure World\r
2ac288f9 64 * Signal Secure Interrupts to CPU using FIQ line *\r
65 */\r
9e2b420e 66 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCICR,\r
67 GIC_ICCICR_ENABLE_SECURE(1) |\r
68 GIC_ICCICR_ENABLE_NS(1) |\r
69 GIC_ICCICR_ACK_CTL(0) |\r
70 GIC_ICCICR_SIGNAL_SECURE_TO_FIQ(1) |\r
71 GIC_ICCICR_USE_SBPR(0));\r
1bfda055 72}\r
73\r
74VOID\r
75EFIAPI\r
76PL390GicEnableDistributor (\r
77 IN INTN GicDistributorBase\r
78 )\r
79{\r
9e2b420e 80 MmioWrite32(GicDistributorBase + GIC_ICDDCR, 1); // turn on the GIC distributor\r
1bfda055 81}\r
82\r
83VOID\r
84EFIAPI\r
85PL390GicSendSgiTo (\r
86 IN INTN GicDistributorBase,\r
87 IN INTN TargetListFilter,\r
88 IN INTN CPUTargetList\r
89 )\r
90{\r
2ac288f9 91 MmioWrite32(GicDistributorBase + GIC_ICDSGIR, ((TargetListFilter & 0x3) << 24) | ((CPUTargetList & 0xFF) << 16));\r
1bfda055 92}\r
93\r
94UINT32\r
95EFIAPI\r
96PL390GicAcknowledgeSgiFrom (\r
97 IN INTN GicInterruptInterfaceBase,\r
98 IN INTN CoreId\r
99 )\r
100{\r
9e2b420e 101 INTN InterruptId;\r
1bfda055 102\r
9e2b420e 103 InterruptId = MmioRead32(GicInterruptInterfaceBase + GIC_ICCIAR);\r
1bfda055 104\r
9e2b420e 105 // Check if the Interrupt ID is valid, The read from Interrupt Ack register returns CPU ID and Interrupt ID\r
2ac288f9 106 if (((CoreId & 0x7) << 10) == (InterruptId & 0x1C00)) {\r
9e2b420e 107 // Got SGI number 0 hence signal End of Interrupt by writing to ICCEOIR\r
2ac288f9 108 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCEIOR, InterruptId);\r
9e2b420e 109 return 1;\r
110 } else {\r
111 return 0;\r
112 }\r
1bfda055 113}\r
114\r
115UINT32\r
116EFIAPI\r
117PL390GicAcknowledgeSgi2From (\r
118 IN INTN GicInterruptInterfaceBase,\r
119 IN INTN CoreId,\r
120 IN INTN SgiId\r
121 )\r
122{\r
9e2b420e 123 INTN InterruptId;\r
1bfda055 124\r
9e2b420e 125 InterruptId = MmioRead32(GicInterruptInterfaceBase + GIC_ICCIAR);\r
1bfda055 126\r
9e2b420e 127 // Check if the Interrupt ID is valid, The read from Interrupt Ack register returns CPU ID and Interrupt ID\r
2ac288f9 128 if((((CoreId & 0x7) << 10) | (SgiId & 0x3FF)) == (InterruptId & 0x1FFF)) {\r
9e2b420e 129 // Got SGI number 0 hence signal End of Interrupt by writing to ICCEOIR\r
2ac288f9 130 MmioWrite32(GicInterruptInterfaceBase + GIC_ICCEIOR, InterruptId);\r
9e2b420e 131 return 1;\r
132 } else {\r
133 return 0;\r
134 }\r
1bfda055 135}\r