VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1/** @file
2 NULL library class implementation to discover the GIC for DT based virt platforms
3
4 Copyright (c) 2015 - 2016, Linaro Ltd. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <Base.h>
11#include <Uefi.h>
12
13#include <Library/ArmGicLib.h>
14#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
16#include <Library/PcdLib.h>
17#include <Library/UefiBootServicesTableLib.h>
18
19#include <Protocol/FdtClient.h>
20
21RETURN_STATUS
22EFIAPI
23ArmVirtGicArchLibConstructor (
24 VOID
25 )
26{
27 FDT_CLIENT_PROTOCOL *FdtClient;
28 CONST UINT64 *Reg;
29 UINT32 RegSize;
30 UINTN AddressCells, SizeCells;
31 UINTN GicRevision;
32 EFI_STATUS Status;
33 UINT64 DistBase, CpuBase, RedistBase;
34 RETURN_STATUS PcdStatus;
35
36 Status = gBS->LocateProtocol (
37 &gFdtClientProtocolGuid,
38 NULL,
39 (VOID **)&FdtClient
40 );
41 ASSERT_EFI_ERROR (Status);
42
43 GicRevision = 2;
44 Status = FdtClient->FindCompatibleNodeReg (
45 FdtClient,
46 "arm,cortex-a15-gic",
47 (CONST VOID **)&Reg,
48 &AddressCells,
49 &SizeCells,
50 &RegSize
51 );
52 if (Status == EFI_NOT_FOUND) {
53 GicRevision = 3;
54 Status = FdtClient->FindCompatibleNodeReg (
55 FdtClient,
56 "arm,gic-v3",
57 (CONST VOID **)&Reg,
58 &AddressCells,
59 &SizeCells,
60 &RegSize
61 );
62 }
63
64 if (EFI_ERROR (Status)) {
65 return Status;
66 }
67
68 switch (GicRevision) {
69 case 3:
70 //
71 // The GIC v3 DT binding describes a series of at least 3 physical (base
72 // addresses, size) pairs: the distributor interface (GICD), at least one
73 // redistributor region (GICR) containing dedicated redistributor
74 // interfaces for all individual CPUs, and the CPU interface (GICC).
75 // Under virtualization, we assume that the first redistributor region
76 // listed covers the boot CPU. Also, our GICv3 driver only supports the
77 // system register CPU interface, so we can safely ignore the MMIO version
78 // which is listed after the sequence of redistributor interfaces.
79 // This means we are only interested in the first two memory regions
80 // supplied, and ignore everything else.
81 //
82 ASSERT (RegSize >= 32);
83
84 // RegProp[0..1] == { GICD base, GICD size }
85 DistBase = SwapBytes64 (Reg[0]);
86 ASSERT (DistBase < MAX_UINTN);
87
88 // RegProp[2..3] == { GICR base, GICR size }
89 RedistBase = SwapBytes64 (Reg[2]);
90 ASSERT (RedistBase < MAX_UINTN);
91
92 PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);
93 ASSERT_RETURN_ERROR (PcdStatus);
94 PcdStatus = PcdSet64S (PcdGicRedistributorsBase, RedistBase);
95 ASSERT_RETURN_ERROR (PcdStatus);
96
97 DEBUG ((
98 DEBUG_INFO,
99 "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n",
100 DistBase,
101 RedistBase
102 ));
103
104 break;
105
106 case 2:
107 //
108 // When the GICv2 is emulated with virtualization=on, it adds a virtual
109 // set of control registers. This means the register property can be
110 // either 32 or 64 bytes in size.
111 //
112 ASSERT ((RegSize == 32) || (RegSize == 64));
113
114 DistBase = SwapBytes64 (Reg[0]);
115 CpuBase = SwapBytes64 (Reg[2]);
116 ASSERT (DistBase < MAX_UINTN);
117 ASSERT (CpuBase < MAX_UINTN);
118
119 PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);
120 ASSERT_RETURN_ERROR (PcdStatus);
121 PcdStatus = PcdSet64S (PcdGicInterruptInterfaceBase, CpuBase);
122 ASSERT_RETURN_ERROR (PcdStatus);
123
124 DEBUG ((DEBUG_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));
125
126 break;
127
128 default:
129 DEBUG ((DEBUG_ERROR, "%a: No GIC revision specified!\n", __func__));
130 return RETURN_NOT_FOUND;
131 }
132
133 return RETURN_SUCCESS;
134}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette