├── Application ├── DtInfo │ ├── DtInfo.c │ └── DtInfo.inf ├── DtProp │ ├── DtProp.c │ └── DtProp.inf ├── DtReg │ ├── DtReg.c │ └── DtReg.inf └── PciInfo │ ├── PciInfo.c │ └── PciInfo.inf ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Docs ├── Developers.md ├── DeviceDrivers.md ├── DtBindings.md ├── DtInterruptProtocol.md ├── DtIoProtocol.md ├── FdtBusDxe.md ├── StyleAndTerms.md ├── Uefi2023 │ └── slides.pdf ├── edk2-patches │ ├── 0001-EDK2-BaseTools-Scripts-SetupGit.py-make-aware-of-Fdt.patch │ ├── 0002-EDK2-UefiDevicePathLib-support-DT-.-device-path-node.patch │ ├── 0003-EDK2-PciBusDxe-support-UEFI-DM-based-root-complex-ho.patch │ ├── 0004-EDK2-PciBus-PciIoGetBarAttributes-correct-reporting-.patch │ └── 0005-EDK2-ShellPkg-Mm.patch └── ovmf-patches │ ├── 0001-OvmfPkg-RiscVVirt-change-for-testing-HighMemDxe.patch │ ├── 0002-RiscVVirt-add-FdtBusDxe.patch │ ├── 0003-RiscVVirt-enable-PciSioSerialDxe.patch │ ├── 0004-RiscVVirt-enable-VirtioFdtDxe.patch │ ├── 0005-RiscVVirt-enable-VirtNorFlashDxe.patch │ ├── 0006-RiscVVirt-enable-HighMemDxe.patch │ ├── 0007-RiscVVirt-enable-FBP-enabled-legacy-PCI-stack.patch │ ├── 0008-RiscVVirt-enable-native-DT-based-PCI-stack.patch │ └── 0009-UiApp-FBP-enable-FrontPage.patch ├── Drivers ├── FdtBusDxe │ ├── ComponentName.c │ ├── DriverBinding.c │ ├── DtDevice.c │ ├── DtIo.c │ ├── DtIoDma.c │ ├── DtIoProp.c │ ├── DtIoPropParse.c │ ├── DtProp.c │ ├── Entry.c │ ├── Fdt.c │ ├── FdtBusDxe.h │ ├── FdtBusDxe.inf │ ├── TestDt.dtbi │ ├── TestDt.dts │ ├── TestDt.sh │ ├── Tests.c │ └── Utils.c ├── HighMemDxe │ ├── ComponentName.c │ ├── DriverBinding.c │ ├── HighMemDxe.c │ ├── HighMemDxe.h │ ├── HighMemDxe.inf │ └── HighMemDxeNoBinding.inf ├── PciHostBridgeFdtDxe │ ├── ComponentName.c │ ├── Driver.c │ ├── Driver.h │ ├── Driver.inf │ ├── DriverBinding.c │ ├── HostBridge.c │ └── RootBridge.c ├── PciSioSerialDxe │ ├── ComponentName.c │ ├── PciSioSerialDxe.inf │ ├── PciSioSerialDxe.uni │ ├── PciSioSerialDxeExtra.uni │ ├── Serial.c │ ├── Serial.h │ └── SerialIo.c ├── SampleBusDxe │ ├── ComponentName.c │ ├── Driver.c │ ├── Driver.h │ ├── Driver.inf │ └── DriverBinding.c ├── SampleDeviceDxe │ ├── ComponentName.c │ ├── Driver.c │ ├── Driver.h │ ├── Driver.inf │ └── DriverBinding.c ├── VirtNorFlashDxe │ ├── ComponentName.c │ ├── DriverBinding.c │ ├── VirtNorFlash.c │ ├── VirtNorFlash.h │ ├── VirtNorFlashDxe.c │ ├── VirtNorFlashDxe.inf │ └── VirtNorFlashFvb.c └── VirtioFdtDxe │ ├── ComponentName.c │ ├── DriverBinding.c │ ├── VirtioFdtDxe.c │ ├── VirtioFdtDxe.h │ └── VirtioFdtDxe.inf ├── FdtBusPkg.dec ├── FdtBusPkg.dsc ├── FdtBusPkgApps.dsc ├── Include ├── Library │ ├── FbpAppUtilsLib.h │ ├── FbpInterruptUtilsLib.h │ ├── FbpPciUtilsLib.h │ ├── FbpPlatformDtLib.h │ └── FbpUtilsLib.h └── Protocol │ ├── DtInterrupt.h │ └── DtIo.h ├── LICENSE ├── Library ├── FbpAppUtilsLib │ ├── FbpAppUtilsLib.inf │ └── Utils.c ├── FbpInterruptUtilsLib │ ├── FbpInterruptUtilsLib.inf │ └── Utils.c ├── FbpPciUtilsLib │ ├── FbpPciUtilsLib.inf │ └── Utils.c ├── FbpPlatformDtLib │ ├── FbpPlatformDtLib.c │ └── FbpPlatformDtLib.inf ├── FbpUtilsLib │ ├── FbpUtilsLib.inf │ └── Utils.c ├── FdtPciPcdProducerLib │ ├── FdtPciPcdProducerLib.c │ └── FdtPciPcdProducerLib.inf └── PciHostBridgeLibEcam │ ├── PciHostBridgeLibEcam.c │ └── PciHostBridgeLibEcam.inf └── README.md /Application/DtInfo/DtInfo.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | Copyright (C) 2016 Andrei Evgenievich Warkentin 5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | STATIC 18 | EFI_STATUS 19 | Usage ( 20 | IN CHAR16 *Name 21 | ) 22 | { 23 | Print (L"Usage: %s controller\n", Name); 24 | return EFI_INVALID_PARAMETER; 25 | } 26 | 27 | STATIC 28 | CONST CHAR8 * 29 | DtStatusString ( 30 | IN EFI_DT_STATUS DtStatus 31 | ) 32 | { 33 | switch (DtStatus) { 34 | case EFI_DT_STATUS_BROKEN: 35 | return "BROKEN"; 36 | case EFI_DT_STATUS_OKAY: 37 | return "OKAY"; 38 | case EFI_DT_STATUS_DISABLED: 39 | return "DISABLED"; 40 | case EFI_DT_STATUS_RESERVED: 41 | return "RESERVED"; 42 | case EFI_DT_STATUS_FAIL: 43 | return "FAIL"; 44 | case EFI_DT_STATUS_FAIL_WITH_CONDITION: 45 | return "FAIL_WITH_CONDITION"; 46 | default: 47 | break; 48 | } 49 | 50 | return ""; 51 | } 52 | 53 | STATIC 54 | EFI_STATUS 55 | DtInfo ( 56 | IN EFI_DT_IO_PROTOCOL *DtIo 57 | ) 58 | { 59 | UINTN Index; 60 | EFI_STATUS Status; 61 | CONST CHAR8 *AsciiValue; 62 | STATIC CONST CHAR8 *ErrorValue = "[ERROR]"; 63 | STATIC CONST CHAR8 *NoneValue = "[NONE]"; 64 | 65 | #define PP(x) Print (L"%18a: ", (x)) 66 | #define P(x, ty, y) PP(x); Print (L"'%" #ty "'\n", (y)) 67 | 68 | P ("ComponentName", s, DtIo->ComponentName); 69 | P ("Name", a, DtIo->Name); 70 | P ( 71 | "DeviceType", 72 | a, 73 | AsciiStrLen (DtIo->DeviceType) == 0 ? 74 | NoneValue : DtIo->DeviceType 75 | ); 76 | P ("DeviceStatus", a, DtStatusString (DtIo->DeviceStatus)); 77 | P ("AddressCells", u, DtIo->AddressCells); 78 | P ("SizeCells", u, DtIo->SizeCells); 79 | P ("ChildAddressCells", u, DtIo->ChildAddressCells); 80 | P ("ChildSizeCells", u, DtIo->ChildSizeCells); 81 | P ("IsDmaCoherent", a, DtIo->IsDmaCoherent ? "yes" : "no"); 82 | if (DtIo->ParentDevice == NULL) { 83 | P ("ParentDevice", a, NoneValue); 84 | } else { 85 | P ("ParentDevice", lx, DtIo->ParentDevice); 86 | } 87 | 88 | Index = 0; 89 | do { 90 | Status = DtIo->GetString ( 91 | DtIo, 92 | "compatible", 93 | Index, 94 | &AsciiValue 95 | ); 96 | if (EFI_ERROR (Status)) { 97 | if (Status == EFI_NOT_FOUND) { 98 | if (Index != 0) { 99 | break; 100 | } 101 | 102 | AsciiValue = NoneValue; 103 | } else { 104 | AsciiValue = ErrorValue; 105 | } 106 | } 107 | 108 | P ("Compatible", a, AsciiValue); 109 | 110 | Index++; 111 | } while (!EFI_ERROR (Status)); 112 | 113 | Index = 0; 114 | do { 115 | CONST CHAR8 *Name; 116 | EFI_DT_REG Reg; 117 | 118 | Name = NULL; 119 | DtIo->GetString (DtIo, "reg-names", Index, &Name); 120 | 121 | Status = DtIo->GetReg (DtIo, Index, &Reg); 122 | if (EFI_ERROR (Status)) { 123 | if (Status == EFI_NOT_FOUND) { 124 | if (Index != 0) { 125 | break; 126 | } 127 | 128 | AsciiValue = NoneValue; 129 | } else { 130 | AsciiValue = ErrorValue; 131 | } 132 | 133 | P ("Reg", a, AsciiValue); 134 | } else { 135 | PP ("Reg"); 136 | if (Name != NULL) { 137 | Print (L"%a ", Name); 138 | } else { 139 | Print (L"#%u ", Index); 140 | } 141 | 142 | PrintDtReg (&Reg, TRUE); 143 | } 144 | 145 | Index++; 146 | } while (!EFI_ERROR (Status)); 147 | 148 | #undef P 149 | 150 | return EFI_SUCCESS; 151 | } 152 | 153 | EFI_STATUS 154 | EFIAPI 155 | EntryPoint ( 156 | IN EFI_HANDLE ImageHandle, 157 | IN EFI_SYSTEM_TABLE *SystemTable 158 | ) 159 | { 160 | UINTN Argc; 161 | CHAR16 **Argv; 162 | EFI_STATUS Status; 163 | GET_OPT_CONTEXT GetOptContext; 164 | EFI_DT_IO_PROTOCOL *DtIo; 165 | 166 | Status = GetShellArgcArgv (ImageHandle, &Argc, &Argv); 167 | if (EFI_ERROR (Status)) { 168 | // 169 | // Already logged error. 170 | // 171 | return Status; 172 | } 173 | 174 | INIT_GET_OPT_CONTEXT (&GetOptContext); 175 | while ((Status = GetOpt ( 176 | Argc, 177 | Argv, 178 | L"", 179 | &GetOptContext 180 | )) == EFI_SUCCESS) 181 | { 182 | switch (GetOptContext.Opt) { 183 | default: 184 | Print (L"Unknown option '%c'\n", GetOptContext.Opt); 185 | return Usage (Argv[0]); 186 | } 187 | } 188 | 189 | if (Argc - GetOptContext.OptIndex < 1) { 190 | return Usage (Argv[0]); 191 | } 192 | 193 | Status = FbpAppLookup ( 194 | Argv[GetOptContext.OptIndex], 195 | &DtIo, 196 | NULL 197 | ); 198 | if (EFI_ERROR (Status)) { 199 | // 200 | // Already logged the error in FbpAppLookup. 201 | // 202 | return Status; 203 | } 204 | 205 | Status = DtInfo (DtIo); 206 | if (EFI_ERROR (Status)) { 207 | Print ( 208 | L"Can't dump info on '%s': %r\n", 209 | Argv[GetOptContext.OptIndex], 210 | Status 211 | ); 212 | } 213 | 214 | return Status; 215 | } 216 | -------------------------------------------------------------------------------- /Application/DtInfo/DtInfo.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010019 11 | BASE_NAME = DtInfo 12 | FILE_GUID = E6727A5E-CBCD-4418-B17F-781C310C14D8 13 | MODULE_TYPE = UEFI_APPLICATION 14 | VERSION_STRING = 1.0 15 | ENTRY_POINT = EntryPoint 16 | 17 | # 18 | # VALID_ARCHITECTURES = X64 AARCH64 RISCV64 19 | # 20 | 21 | [Sources] 22 | DtInfo.c 23 | 24 | [Packages] 25 | MdePkg/MdePkg.dec 26 | MdeModulePkg/MdeModulePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | ShellPkg/ShellPkg.dec 29 | 30 | [LibraryClasses] 31 | UefiLib 32 | FbpAppUtilsLib 33 | UefiApplicationEntryPoint 34 | DebugLib 35 | 36 | [Guids] 37 | 38 | [Protocols] 39 | gEfiDtIoProtocolGuid 40 | 41 | [Depex] 42 | 43 | [BuildOptions] 44 | -------------------------------------------------------------------------------- /Application/DtProp/DtProp.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | Copyright (C) 2016 Andrei Evgenievich Warkentin 5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | STATIC 19 | VOID 20 | DumpHex ( 21 | IN UINTN Indent, 22 | IN UINTN Offset, 23 | IN UINTN DataSize, 24 | IN CONST VOID *UserData 25 | ) 26 | { 27 | CONST UINT8 *Data; 28 | CHAR8 Val[50]; 29 | CHAR8 Str[20]; 30 | UINT8 TempByte; 31 | UINTN Size; 32 | UINTN Index; 33 | 34 | STATIC CONST CHAR8 Hex[] = { 35 | '0', '1', '2', '3', 36 | '4', '5', '6', '7', 37 | '8', '9', 'A', 'B', 38 | 'C', 'D', 'E', 'F' 39 | }; 40 | 41 | Data = UserData; 42 | while (DataSize != 0) { 43 | Size = 16; 44 | if (Size > DataSize) { 45 | Size = DataSize; 46 | } 47 | 48 | for (Index = 0; Index < Size; Index += 1) { 49 | TempByte = Data[Index]; 50 | Val[Index * 3 + 0] = Hex[TempByte >> 4]; 51 | Val[Index * 3 + 1] = Hex[TempByte & 0xF]; 52 | Val[Index * 3 + 2] = (CHAR8)((Index == 7) ? '-' : ' '); 53 | Str[Index] = (CHAR8)((TempByte < ' ' || TempByte > '~') ? '.' : TempByte); 54 | } 55 | 56 | Val[Index * 3] = 0; 57 | Str[Index] = 0; 58 | Print (L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str); 59 | 60 | Data += Size; 61 | Offset += Size; 62 | DataSize -= Size; 63 | } 64 | } 65 | 66 | STATIC 67 | EFI_STATUS 68 | Usage ( 69 | IN CHAR16 *Name 70 | ) 71 | { 72 | Print (L"Usage: %s controller property [parse string]\n", Name); 73 | return EFI_INVALID_PARAMETER; 74 | } 75 | 76 | EFI_STATUS 77 | EFIAPI 78 | EntryPoint ( 79 | IN EFI_HANDLE ImageHandle, 80 | IN EFI_SYSTEM_TABLE *SystemTable 81 | ) 82 | { 83 | UINTN Argc; 84 | CHAR16 **Argv; 85 | EFI_STATUS Status; 86 | GET_OPT_CONTEXT GetOptContext; 87 | EFI_DT_IO_PROTOCOL *DtIo; 88 | CHAR8 *PropName; 89 | EFI_DT_PROPERTY Prop; 90 | 91 | Status = GetShellArgcArgv (ImageHandle, &Argc, &Argv); 92 | if (EFI_ERROR (Status)) { 93 | // 94 | // Already logged error. 95 | // 96 | return Status; 97 | } 98 | 99 | INIT_GET_OPT_CONTEXT (&GetOptContext); 100 | while ((Status = GetOpt ( 101 | Argc, 102 | Argv, 103 | L"", 104 | &GetOptContext 105 | )) == EFI_SUCCESS) 106 | { 107 | switch (GetOptContext.Opt) { 108 | default: 109 | Print (L"Unknown option '%c'\n", GetOptContext.Opt); 110 | return Usage (Argv[0]); 111 | } 112 | } 113 | 114 | if (Argc - GetOptContext.OptIndex < 2) { 115 | return Usage (Argv[0]); 116 | } 117 | 118 | Status = FbpAppLookup ( 119 | Argv[GetOptContext.OptIndex], 120 | &DtIo, 121 | NULL 122 | ); 123 | if (EFI_ERROR (Status)) { 124 | // 125 | // Already logged the error in FbpAppLookup. 126 | // 127 | return Status; 128 | } 129 | 130 | PropName = UnicodeStrDupToAsciiStr (Argv[GetOptContext.OptIndex + 1]); 131 | if (PropName == NULL) { 132 | Print ( 133 | L"Couldn't convert '%s' to ASCII\n", 134 | Argv[GetOptContext.OptIndex + 1] 135 | ); 136 | return EFI_OUT_OF_RESOURCES; 137 | } 138 | 139 | Status = DtIo->GetProp (DtIo, PropName, &Prop); 140 | if (EFI_ERROR (Status)) { 141 | Print (L"Couldn't get property '%a': %r\n", PropName, Status); 142 | goto out; 143 | } 144 | 145 | if (Argc - GetOptContext.OptIndex < 3) { 146 | if ((Prop.End - Prop.Begin) == 0) { 147 | Print (L"Property '%a' exists but is EMPTY\n"); 148 | } else { 149 | Print (L"Dumping %u bytes of '%a':\n", Prop.End - Prop.Begin, PropName); 150 | DumpHex (0, 0, Prop.End - Prop.Begin, Prop.Begin); 151 | } 152 | } else { 153 | UINTN Index; 154 | 155 | Print ( 156 | L"Parsing '%a' with command string '%s':\n", 157 | PropName, 158 | Argv[GetOptContext.OptIndex + 2] 159 | ); 160 | for (Index = 0; Argv[GetOptContext.OptIndex + 2][Index] != L'\0'; Index++) { 161 | CHAR16 Command; 162 | EFI_DT_VALUE_TYPE Type; 163 | CONST CHAR8 *Desc; 164 | union { 165 | UINT32 U32; 166 | UINT64 U64; 167 | EFI_DT_U128 U128; 168 | EFI_DT_BUS_ADDRESS Address; 169 | EFI_DT_SIZE Size; 170 | EFI_DT_REG Reg; 171 | EFI_DT_RANGE Range; 172 | EFI_HANDLE Handle; 173 | CHAR8 *String; 174 | } Value; 175 | 176 | #define P(x) Type = x; Desc = #x; 177 | 178 | Print (L"%08x: ", Prop.Iter - Prop.Begin); 179 | Command = Argv[GetOptContext.OptIndex + 2][Index]; 180 | switch (Command) { 181 | case L'1': 182 | P (EFI_DT_VALUE_U32); 183 | break; 184 | case L'2': 185 | P (EFI_DT_VALUE_U64); 186 | break; 187 | case L'4': 188 | P (EFI_DT_VALUE_U128); 189 | break; 190 | case L'b': 191 | P (EFI_DT_VALUE_BUS_ADDRESS); 192 | break; 193 | case L'B': 194 | P (EFI_DT_VALUE_CHILD_BUS_ADDRESS); 195 | break; 196 | case L'z': 197 | P (EFI_DT_VALUE_SIZE); 198 | break; 199 | case L'Z': 200 | P (EFI_DT_VALUE_CHILD_SIZE); 201 | break; 202 | case L'r': 203 | P (EFI_DT_VALUE_REG); 204 | break; 205 | case L'R': 206 | P (EFI_DT_VALUE_RANGE); 207 | break; 208 | case L's': 209 | P (EFI_DT_VALUE_STRING); 210 | break; 211 | case L'd': 212 | P (EFI_DT_VALUE_DEVICE); 213 | break; 214 | default: 215 | Print (L"Unknown parsing commmand '%c'\n", Command); 216 | goto out; 217 | } 218 | 219 | #undef P 220 | 221 | Status = DtIo->ParseProp (DtIo, &Prop, Type, 0, &Value); 222 | if (EFI_ERROR (Status)) { 223 | Print ( 224 | L"\nError parsing %a at offset 0x%x: %r\n", 225 | Desc, 226 | Prop.Iter - Prop.Begin, 227 | Status 228 | ); 229 | goto out; 230 | } 231 | 232 | switch (Command) { 233 | case L'1': 234 | Print (L"0x%x\n", Value.U32); 235 | break; 236 | case L'2': 237 | Print (L"0x%lx\n", Value.U64); 238 | break; 239 | case L'4': 240 | PrintDtU128 (Value.U128, TRUE); 241 | break; 242 | case L'b': 243 | case L'B': 244 | PrintDtU128 (Value.Address, TRUE); 245 | break; 246 | case L'z': 247 | case L'Z': 248 | PrintDtU128 (Value.Size, TRUE); 249 | break; 250 | case L'r': 251 | PrintDtReg (&Value.Reg, TRUE); 252 | break; 253 | case L'R': 254 | PrintDtRange (&Value.Range, TRUE); 255 | break; 256 | case L's': 257 | Print (L"%a\n", Value.String); 258 | break; 259 | case L'd': 260 | { 261 | EFI_DT_IO_PROTOCOL *NewDtIo; 262 | 263 | Status = gBS->HandleProtocol (Value.Handle, &gEfiDtIoProtocolGuid, (VOID **)&NewDtIo); 264 | if (EFI_ERROR (Status)) { 265 | // 266 | // Weird (how did ParseProp succeed?), but let's not crash. 267 | // 268 | Print (L"%lx (no DtIo?)\n", Value.Handle); 269 | } else { 270 | Print (L"%s\n", NewDtIo->ComponentName); 271 | } 272 | 273 | break; 274 | } 275 | default: 276 | ASSERT (0); 277 | } 278 | } 279 | } 280 | 281 | out: 282 | FreePool (PropName); 283 | return Status; 284 | } 285 | -------------------------------------------------------------------------------- /Application/DtProp/DtProp.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010019 11 | BASE_NAME = DtProp 12 | FILE_GUID = E6727A5E-CAAD-4418-B17F-781C310C14DA 13 | MODULE_TYPE = UEFI_APPLICATION 14 | VERSION_STRING = 1.0 15 | ENTRY_POINT = EntryPoint 16 | 17 | # 18 | # VALID_ARCHITECTURES = X64 AARCH64 RISCV64 19 | # 20 | 21 | [Sources] 22 | DtProp.c 23 | 24 | [Packages] 25 | MdePkg/MdePkg.dec 26 | MdeModulePkg/MdeModulePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | ShellPkg/ShellPkg.dec 29 | 30 | [LibraryClasses] 31 | UefiLib 32 | FbpAppUtilsLib 33 | UefiApplicationEntryPoint 34 | MemoryAllocationLib 35 | DebugLib 36 | 37 | [Guids] 38 | 39 | [Protocols] 40 | gEfiDtIoProtocolGuid 41 | 42 | [Depex] 43 | 44 | [BuildOptions] 45 | -------------------------------------------------------------------------------- /Application/DtReg/DtReg.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | Copyright (C) 2016 Andrei Evgenievich Warkentin 5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | STATIC 19 | EFI_STATUS 20 | Usage ( 21 | IN CHAR16 *Name 22 | ) 23 | { 24 | Print (L"Usage: %s [-i reg index|name] [-n count] [-w access width] controller offset [set value]\n", Name); 25 | return EFI_INVALID_PARAMETER; 26 | } 27 | 28 | EFI_STATUS 29 | EFIAPI 30 | EntryPoint ( 31 | IN EFI_HANDLE ImageHandle, 32 | IN EFI_SYSTEM_TABLE *SystemTable 33 | ) 34 | { 35 | UINTN Argc; 36 | CHAR16 **Argv; 37 | EFI_STATUS Status; 38 | GET_OPT_CONTEXT GetOptContext; 39 | EFI_DT_IO_PROTOCOL *DtIo; 40 | UINTN RegIndex; 41 | CHAR8 *RegName; 42 | UINTN AccessWidth; 43 | EFI_DT_IO_PROTOCOL_WIDTH IoWidth; 44 | UINTN Count; 45 | EFI_DT_REG Reg; 46 | UINTN Offset; 47 | BOOLEAN Set; 48 | UINTN SetValue; 49 | 50 | Status = GetShellArgcArgv (ImageHandle, &Argc, &Argv); 51 | if (EFI_ERROR (Status)) { 52 | // 53 | // Already logged error. 54 | // 55 | return Status; 56 | } 57 | 58 | Count = 1; 59 | AccessWidth = 1; 60 | RegIndex = 0; 61 | RegName = NULL; 62 | Set = FALSE; 63 | INIT_GET_OPT_CONTEXT (&GetOptContext); 64 | while ((Status = GetOpt ( 65 | Argc, 66 | Argv, 67 | L"inw", 68 | &GetOptContext 69 | )) == EFI_SUCCESS) 70 | { 71 | switch (GetOptContext.Opt) { 72 | case L'i': 73 | if (GetOptContext.OptArg == NULL) { 74 | return Usage (Argv[0]); 75 | } 76 | 77 | RegIndex = StrHexOrDecToUintn (GetOptContext.OptArg); 78 | RegName = UnicodeStrDupToAsciiStr (GetOptContext.OptArg); 79 | break; 80 | case L'n': 81 | if (GetOptContext.OptArg == NULL) { 82 | return Usage (Argv[0]); 83 | } 84 | 85 | Count = StrHexOrDecToUintn (GetOptContext.OptArg); 86 | break; 87 | case L'w': 88 | if (GetOptContext.OptArg == NULL) { 89 | return Usage (Argv[0]); 90 | } 91 | 92 | AccessWidth = StrHexOrDecToUintn (GetOptContext.OptArg); 93 | break; 94 | default: 95 | Print (L"Unknown option '%c'\n", GetOptContext.Opt); 96 | return Usage (Argv[0]); 97 | } 98 | } 99 | 100 | if (AccessWidth == 1) { 101 | IoWidth = EfiDtIoWidthUint8; 102 | } else if (AccessWidth == 2) { 103 | IoWidth = EfiDtIoWidthUint16; 104 | } else if (AccessWidth == 4) { 105 | IoWidth = EfiDtIoWidthUint32; 106 | } else if (AccessWidth == 8) { 107 | IoWidth = EfiDtIoWidthUint64; 108 | } else { 109 | Print (L"Bad access width parameter %u\n", AccessWidth); 110 | return EFI_INVALID_PARAMETER; 111 | } 112 | 113 | if (Argc - GetOptContext.OptIndex < 2) { 114 | return Usage (Argv[0]); 115 | } 116 | 117 | if (Argc - GetOptContext.OptIndex == 3) { 118 | Set = TRUE; 119 | SetValue = StrHexOrDecToUintn (Argv[GetOptContext.OptIndex + 2]); 120 | } 121 | 122 | Offset = StrHexOrDecToUintn (Argv[GetOptContext.OptIndex + 1]); 123 | Status = FbpAppLookup ( 124 | Argv[GetOptContext.OptIndex], 125 | &DtIo, 126 | NULL 127 | ); 128 | if (EFI_ERROR (Status)) { 129 | // 130 | // Already logged the error in FbpAppLookup. 131 | // 132 | return Status; 133 | } 134 | 135 | Status = EFI_NOT_FOUND; 136 | if (RegName != NULL) { 137 | Status = DtIo->GetRegByName (DtIo, RegName, &Reg); 138 | } 139 | 140 | if (EFI_ERROR (Status)) { 141 | Status = DtIo->GetReg (DtIo, RegIndex, &Reg); 142 | } 143 | 144 | if (EFI_ERROR (Status)) { 145 | if (RegName != NULL) { 146 | Print ( 147 | L"Cannot get region by name '%a' or index %u: %r\n", 148 | RegName, 149 | RegIndex, 150 | Status 151 | ); 152 | } else { 153 | Print (L"Cannot get region by index %u: %r\n", RegIndex, Status); 154 | } 155 | 156 | return Usage (Argv[0]); 157 | } 158 | 159 | if (RegName != NULL) { 160 | FreePool (RegName); 161 | } 162 | 163 | if (!Set) { 164 | Print ( 165 | L"Dumping %lu bytes at offset 0x%lx of reg ", 166 | AccessWidth * Count, 167 | Offset 168 | ); 169 | PrintDtReg (&Reg, FALSE); 170 | Print (L":\n"); 171 | } 172 | 173 | while (Count--) { 174 | if (Set) { 175 | Status = DtIo->WriteReg (DtIo, IoWidth, &Reg, Offset, 1, &SetValue); 176 | if (EFI_ERROR (Status)) { 177 | Print (L"WriteReg at offset 0x%lx failed: %r\n", Offset, Status); 178 | break; 179 | } 180 | } else { 181 | UINT64 Value; 182 | 183 | Value = 0; 184 | Status = DtIo->ReadReg (DtIo, IoWidth, &Reg, Offset, 1, &Value); 185 | if (EFI_ERROR (Status)) { 186 | Print (L"ReadReg at offset 0x%lx failed: %r\n", Offset, Status); 187 | break; 188 | } 189 | 190 | Print (L"%08x: %0*lx\n", Offset, AccessWidth * 2, Value); 191 | } 192 | 193 | Offset += AccessWidth; 194 | } 195 | 196 | return Status; 197 | } 198 | -------------------------------------------------------------------------------- /Application/DtReg/DtReg.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010019 11 | BASE_NAME = DtReg 12 | FILE_GUID = E6717A5E-CBCD-4418-B17F-781C310D4321 13 | MODULE_TYPE = UEFI_APPLICATION 14 | VERSION_STRING = 1.0 15 | ENTRY_POINT = EntryPoint 16 | 17 | # 18 | # VALID_ARCHITECTURES = X64 AARCH64 RISCV64 19 | # 20 | 21 | [Sources] 22 | DtReg.c 23 | 24 | [Packages] 25 | MdePkg/MdePkg.dec 26 | MdeModulePkg/MdeModulePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | ShellPkg/ShellPkg.dec 29 | 30 | [LibraryClasses] 31 | UefiLib 32 | FbpAppUtilsLib 33 | UefiApplicationEntryPoint 34 | MemoryAllocationLib 35 | DebugLib 36 | 37 | [Guids] 38 | 39 | [Protocols] 40 | gEfiDtIoProtocolGuid 41 | 42 | [Depex] 43 | 44 | [BuildOptions] 45 | -------------------------------------------------------------------------------- /Application/PciInfo/PciInfo.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010019 11 | BASE_NAME = PciInfo 12 | FILE_GUID = A57F1751-649A-4581-B2A0-56D17E1B148C 13 | MODULE_TYPE = UEFI_APPLICATION 14 | VERSION_STRING = 1.0 15 | ENTRY_POINT = EntryPoint 16 | 17 | [Sources] 18 | PciInfo.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | MdeModulePkg/MdeModulePkg.dec 23 | FdtBusPkg/FdtBusPkg.dec 24 | ShellPkg/ShellPkg.dec 25 | 26 | [LibraryClasses] 27 | UefiLib 28 | FbpAppUtilsLib 29 | UefiApplicationEntryPoint 30 | UefiBootServicesTableLib 31 | HandleParsingLib 32 | 33 | [Protocols] 34 | gEfiPciIoProtocolGuid 35 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | CommunityCodeOfConduct AT intel DOT com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series of 86 | actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or permanent 93 | ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within the 113 | community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.1, available at 119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 123 | 124 | For answers to common questions about this code of conduct, see the FAQ at 125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 126 | [https://www.contributor-covenant.org/translations][translations]. 127 | 128 | [homepage]: https://www.contributor-covenant.org 129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 130 | [Mozilla CoC]: https://github.com/mozilla/diversity 131 | [FAQ]: https://www.contributor-covenant.org/faq 132 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ### License 4 | 5 | is licensed under the terms in [LICENSE]. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. 6 | 7 | ### Sign your work 8 | 9 | Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify 10 | the below (from [developercertificate.org](http://developercertificate.org/)): 11 | 12 | ``` 13 | Developer Certificate of Origin 14 | Version 1.1 15 | 16 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 17 | 660 York Street, Suite 102, 18 | San Francisco, CA 94110 USA 19 | 20 | Everyone is permitted to copy and distribute verbatim copies of this 21 | license document, but changing it is not allowed. 22 | 23 | Developer's Certificate of Origin 1.1 24 | 25 | By making a contribution to this project, I certify that: 26 | 27 | (a) The contribution was created in whole or in part by me and I 28 | have the right to submit it under the open source license 29 | indicated in the file; or 30 | 31 | (b) The contribution is based upon previous work that, to the best 32 | of my knowledge, is covered under an appropriate open source 33 | license and I have the right under that license to submit that 34 | work with modifications, whether created in whole or in part 35 | by me, under the same open source license (unless I am 36 | permitted to submit under a different license), as indicated 37 | in the file; or 38 | 39 | (c) The contribution was provided directly to me by some other 40 | person who certified (a), (b) or (c) and I have not modified 41 | it. 42 | 43 | (d) I understand and agree that this project and the contribution 44 | are public and that a record of the contribution (including all 45 | personal information I submit with it, including my sign-off) is 46 | maintained indefinitely and may be redistributed consistent with 47 | this project or the open source license(s) involved. 48 | ``` 49 | 50 | Then you just add a line to every git commit message: 51 | 52 | Signed-off-by: Joe Smith 53 | 54 | Use your real name (sorry, no pseudonyms or anonymous contributions.) 55 | 56 | If you set your `user.name` and `user.email` git configs, you can sign your 57 | commit automatically with `git commit -s`. 58 | -------------------------------------------------------------------------------- /Docs/DtBindings.md: -------------------------------------------------------------------------------- 1 | # FdtBusPkg-Specific Devicetree Bindings 2 | 3 | > [!NOTE] 4 | > See [FdtBusPkg Documentation Style and Terms Definitions](StyleAndTerms.md) first. 5 | 6 | These apply on top of [Devicetree Specification, Chapter 4](https://devicetree-specification.readthedocs.io/en/stable/device-bindings.html) and use terms and definitions from that spec. 7 | 8 | ## PCIe Root Complex and PCI Host Bridge Properties 9 | 10 | ### _fdtbuspkg,pci-keep-config_ 11 | 12 | | Property | Value Type | Description | 13 | | -------- | :--------: | ----------- | 14 | | _fdtbuspkg,pci-keep-config_ | | Keep existing PCI(e) BAR configuration. | 15 | 16 | When set, UEFI PCI bus driver will perform a lightweight enumeration, that skips 17 | resource (re)assignment. This requires the resource assignment to be performed 18 | elsewhere (e.g. before UEFI). 19 | 20 | ## Miscellaneous Properties 21 | 22 | ### _fdtbuspkg,critical_ 23 | 24 | | Property | Value Type | Description | 25 | | -------- | :--------: | ----------- | 26 | | _fdtbuspkg,critical_ | | Marks a DT controller as critical. | 27 | 28 | A critical controller is always connected at End-of-DXE event (`gEfiEndOfDxeEventGroupGuid`). This facility allows device to be always initialized, even under rapid boot conditions. 29 | 30 | > [!NOTE] 31 | > This property is parsed by FdtBusDxe during processing of child DT 32 | > controllers. Thus, a DT device with _fdtbuspkg,critical_ must be a child 33 | > of a controller supported by an existing driver, and this controller 34 | > needs to have a _fdtbuspkg,critical_ property as well. 35 | 36 | > [!NOTE] 37 | > Devices of type _memory_ are implicitly treated as having _fdtbuspkg,critical_. 38 | 39 | ### _fdtbuspkg,unit-test-device_ 40 | 41 | | Property | Value Type | Description | 42 | | -------- | :--------: | ----------- | 43 | | _fdtbuspkg,unit-test-device_ | | Marks a DT controller as being used by internal unit tests. 44 | 45 | > [!NOTE] 46 | > Only supported in the special testing Devicetree with a DEBUG build of FdtBusDxe. Don't use it. 47 | 48 | ### _fdtbuspkg,reg-attrs_ and _fdtbuspkg,range-attrs_ 49 | 50 | Provides optional `EFI_DT_IO_REG_TYPE` and mapping attribute information for 51 | CPU-accessible regions. When not provided, `reg` and `ranges` memory regions returned from 52 | DtIo default to memory type `EfiDtIoRegTypeMemoryMappedIo` and and attributes `EFI_MEMORY_UC`. 53 | 54 | The `EFI_DT_IO_REG_TYPE` is encoded as a ``. The EFI memory attributes are encoded as a ``. 55 | 56 | | Property | Value Type | Description | 57 | | -------- | :--------: | ----------- | 58 | | _fdtbuspkg,reg-attrs_ | `` | Consist of a number of (_EFI_DT_IO_REG_TYPE_, _EFI_MEMORY_* attributes_) pairs, matching the number of entries in a _reg_ property. | 59 | | _fdtbuspkg,ranges-attrs_ | `` | Consist of a number of (_EFI_DT_IO_REG_TYPE_, _EFI_MEMORY_* attributes_) pairs, matching the number of entries in a _ranges_ property. | 60 | 61 | > [!NOTE] 62 | > The attributes are not inherited and do not stack. _reg_ does not inherit the parent's _ranges_ type and attribute information. 63 | -------------------------------------------------------------------------------- /Docs/DtInterruptProtocol.md: -------------------------------------------------------------------------------- 1 | # EFI Devicetree Interrupt Protocol 2 | 3 | > [!NOTE] 4 | > See [FdtBusPkg Documentation Style and Terms Definitions](StyleAndTerms.md) first. 5 | 6 | This section provides a detailed description of the `EFI_DT_INTERRUPT_PROTOCOL`. 7 | This protocol is used by DT controller drivers for interrupt controllers. 8 | 9 | The interfaces provided in the `EFI_DT_INTERRUPT_PROTOCOL` are for registering 10 | an interrupt handler and enabling and disabling the registered interrupt source. The 11 | protocol is specifically tailored to an environment, which relies on describing 12 | the platform devices using a Devicetree, including the timer hardware exposed to UEFI via 13 | the architectural timer protocol. 14 | 15 | ## EFI_DT_INTERRUPT_PROTOCOL 16 | 17 | ### Summary 18 | 19 | Provides an interface for registering an interrupt handler and manipulating the 20 | registered interrupt source. The inteface is meant to be used by a DT controller 21 | driver (in practice, a timer source driver implementing the `EFI_TIMER_ARCH_PROTOCOL`). 22 | 23 | ### GUID 24 | 25 | ``` 26 | #define EFI_DT_INTERRUPT_PROTOCOL_GUID \ 27 | { \ 28 | 0x5ce5a2b0, 0x2838, 0x3c35, {0x1e, 0xe3, 0x42, 0x5e, 0x36, 0x50, 0xa3, 0x9c } \ 29 | } 30 | ``` 31 | 32 | ### Protocol Interface Structure 33 | 34 | ``` 35 | typedef struct _EFI_DT_INTERRUPT_PROTOCOL { 36 | EFI_DT_INTERRUPT_REGISTER RegisterInterrupt; 37 | EFI_DT_INTERRUPT_UNREGISTER UnregisterInterrupt; 38 | EFI_DT_INTERRUPT_ENABLE EnableInterrupt; 39 | EFI_DT_INTERRUPT_DISABLE DisableInterrupt; 40 | } EFI_DT_INTERRUPT_PROTOCOL; 41 | ``` 42 | 43 | ### Members 44 | 45 | | Name | Description | 46 | | ---- | ----------- | 47 | | [`RegisterInterrupt`](#efi_dt_interrupt_protocolregisterinterrupt) | Register an interrupt handler. | 48 | | [`UnregisterInterrupt`](#efi_dt_interrupt_protocolunregisterinterrupt) | Unregisters an interrupt handler. | 49 | | [`EnableInterrupt`](#efi_dt_interrupt_protocolenableinterrupt) | Unmask the interrupt with a registered interrupt handler. | 50 | | [`DisableInterrupt`](#efi_dt_interrupt_protocoldisableinterrupt) | Mask the interrupt with a registered interrupt handler. | 51 | 52 | ### Related Definitions 53 | 54 | ``` 55 | typedef VOID *EFI_DT_INTERRUPT_COOKIE; 56 | 57 | typedef 58 | VOID 59 | (EFIAPI *EFI_DT_INTERRUPT_HANDLER)( 60 | IN EFI_DT_INTERRUPT_COOKIE Cookie, 61 | IN VOID *CookieContext, 62 | IN EFI_SYSTEM_CONTEXT SystemContext 63 | ); 64 | ``` 65 | 66 | ### Description 67 | 68 | The `EFI_DT_INTERRUPT_PROTOCOL` abstracts registered handlers with a `EFI_DT_INTERRUPT_COOKIE`. The cookie 69 | uniquely identifies the registered interrupt and is used with further API calls to unregister, enable 70 | and disable the interrupt. The actual interrupt configuration is entirely opaque, being specific 71 | to the interrupt controller implementation itself, and is passed via a DT property blob. 72 | 73 | ### Interrupt Handler 74 | 75 | Interrupt completion (aka EOI, end-of-interrupt) is done automatically after the handler completes. 76 | 77 | ### `EFI_DT_INTERRUPT_PROTOCOL.RegisterInterrupt()` 78 | 79 | #### Description 80 | 81 | Registers an interrupt handler for an interrupt source. On success, populates 82 | `*Cookie` with a value uniquely identifying the interrupt source. 83 | 84 | An `EFI_DT_INTERRUPT_PROTOCOL` implementation is only required to support one outstanding registered interrupt. 85 | 86 | The `InterruptData` parameter is an `EFI_DT_PROPERTY` encoding an interrupt 87 | specifier valid in the context of the interrupt controller driver. Such 88 | an interrupt specifier could come from the _interrupts_ property for a DT 89 | controller, or from the _interrupt-map_ of an interrupt nexus Devicetree node. 90 | 91 | `InterruptData->Iter` is only updated on success. 92 | 93 | #### Prototype 94 | 95 | ``` 96 | typedef 97 | EFI_STATUS 98 | (EFIAPI *EFI_DT_INTERRUPT_REGISTER)( 99 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 100 | IN EFI_DT_PROPERTY *InterruptData, 101 | IN EFI_DT_INTERRUPT_HANDLER Handler, 102 | IN VOID *CookieContext, 103 | OUT EFI_DT_INTERRUPT_COOKIE *Cookie 104 | ); 105 | ``` 106 | 107 | #### Parameters 108 | 109 | | Parameter | Description | 110 | | --------- | ----------- | 111 | | `This` | Instance pointer for this protocol. | 112 | | `InterruptData` | Interrupt specifier. | 113 | | `Handler` | Callback for interrupt. | 114 | | `CookieContext` | Additional context to pass to `Handler`. | 115 | | `Cookie` | A unique value used for further operations on a registered interrupt. | 116 | 117 | #### Status Codes Returned 118 | 119 | | Status Code | Description | 120 | | ----------- | ----------- | 121 | | `EFI_SUCCESS` | Interrupt handler registered, `*Cookie` set, `InterruptData->Iter` updated. | 122 | | `EFI_UNSUPPORTED` | Configuration not supported. | 123 | | `EFI_INVALID_PARAMETER` | Bad parameter. | 124 | | `EFI_DEVICE_ERROR` | Hardware could not be programmed. | 125 | 126 | ### `EFI_DT_INTERRUPT_PROTOCOL.UnregisterInterrupt()` 127 | 128 | #### Description 129 | 130 | Unregister handler for an interrupt. 131 | 132 | #### Prototype 133 | 134 | ``` 135 | typedef 136 | EFI_STATUS 137 | (EFIAPI *EFI_DT_INTERRUPT_UNREGISTER)( 138 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 139 | IN EFI_DT_INTERRUPT_COOKIE Cookie 140 | ); 141 | ``` 142 | 143 | #### Parameters 144 | 145 | | Parameter | Description | 146 | | --------- | ----------- | 147 | | `This` | Instance pointer for this protocol. | 148 | | `Cookie` | As provided by [`RegisterInterrupt`](#efi_dt_interrupt_protocolregisterinterrupt). | 149 | 150 | #### Status Codes Returned 151 | 152 | | Status Code | Description | 153 | | ----------- | ----------- | 154 | | `EFI_SUCCESS` | Interrupt unregistered. | 155 | | `EFI_INVALID_PARAMETER` | Bad parameter. | 156 | | `EFI_DEVICE_ERROR` | Hardware could not be programmed. | 157 | 158 | ### `EFI_DT_INTERRUPT_PROTOCOL.EnableInterrupt()` 159 | 160 | #### Description 161 | 162 | #### Prototype 163 | 164 | ``` 165 | typedef 166 | EFI_STATUS 167 | (EFIAPI *EFI_DT_INTERRUPT_ENABLE)( 168 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 169 | IN EFI_DT_INTERRUPT_COOKIE Cookie 170 | ); 171 | ``` 172 | 173 | #### Parameters 174 | 175 | | Parameter | Description | 176 | | --------- | ----------- | 177 | | `This` | Instance pointer for this protocol. | 178 | | `Cookie` | As provided by [`RegisterInterrupt`](#efi_dt_interrupt_protocolregisterinterrupt). | 179 | 180 | #### Status Codes Returned 181 | 182 | | Status Code | Description | 183 | | ----------- | ----------- | 184 | | `EFI_SUCCESS` | Interrupt enabled. | 185 | | `EFI_INVALID_PARAMETER` | Bad parameter. | 186 | | `EFI_DEVICE_ERROR` | Hardware could not be programmed. | 187 | 188 | ### `EFI_DT_INTERRUPT_PROTOCOL.DisableInterrupt()` 189 | 190 | #### Description 191 | 192 | #### Prototype 193 | 194 | ``` 195 | typedef 196 | EFI_STATUS 197 | (EFIAPI *EFI_DT_INTERRUPT_DISABLE)( 198 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 199 | IN EFI_DT_INTERRUPT_COOKIE Cookie 200 | ); 201 | ``` 202 | 203 | #### Parameters 204 | 205 | | Parameter | Description | 206 | | --------- | ----------- | 207 | | `This` | Instance pointer for this protocol. | 208 | | `Cookie` | As provided by [`RegisterInterrupt`](#efi_dt_interrupt_protocolregisterinterrupt). | 209 | 210 | #### Status Codes Returned 211 | 212 | | Status Code | Description | 213 | | ----------- | ----------- | 214 | | `EFI_SUCCESS` | Interrupt disabled. | 215 | | `EFI_INVALID_PARAMETER` | Bad parameter. | 216 | | `EFI_DEVICE_ERROR` | Hardware could not be programmed. | 217 | -------------------------------------------------------------------------------- /Docs/FdtBusDxe.md: -------------------------------------------------------------------------------- 1 | # FdtBusDxe Overview 2 | 3 | > [!NOTE] 4 | > See [FdtBusPkg Documentation Style and Terms Definitions](StyleAndTerms.md) first. 5 | 6 | [FdtBusDxe](../Drivers/FdtBusDxe) is responsible for enumerating 7 | DT controllers based on Devicetree nodes, and implementing 8 | `EFI_DT_IO_PROTOCOL` for basic operations on such controllers, such as 9 | device property access, register I/O, DMA buffer handling and child 10 | device enumeration. It is overall meant as the logical successor for 11 | the existing Tiano FdtClientDxe component. 12 | 13 | ## Entry 14 | 15 | On loading, `EntryPoint()`: 16 | 17 | - Uses FbpPlatformGetDt to get the platform Devicetree. The [default implementation](../Library/FbpPlatformDtLib) looks 18 | for the Devicetree HOB (`gFdtHobGuid`). 19 | - On debug builds, check that the Devicetree is allocated in the UEFI memory map, i.e. not part of free memory. 20 | - Bails if neither a platform Devicetree is available, nor regression tests are available (i.e. non-debug builds). 21 | - Locates `EFI_CPU_IO2_PROTOCOL` (`gEfiCpuIo2ProtocolGuid` is in the `[Depex]` list) 22 | - If a platform Devicetree is available, registers a notification callback on 23 | `gEdkiiPlatformHasDeviceTreeGuid`, which is the "UEFI will expose 24 | Devicetree to the OS" signal. The callback installs the managed 25 | Devicetree in the EFI Configuration Table, which matches FdtClientDxe behavior. 26 | - Registers an End-of-DXE notification callback. The callback ensures 27 | that controllers [marked as critical](DtBindings.md#fdtbuspkgcritical) 28 | are connected to their drivers and initialized when End-of-DXE is signaled 29 | during the BDS phase. 30 | - Registers as a bus driver, by: 31 | - Creating the device handle for the Devicetree root, if a platform Devicetree is found. 32 | - On debug builds, creating the device handle for the test Devicetree root (used for regression testing). 33 | - Registering the Driver Binding and Component Name protocols. 34 | 35 | Unloading is not supported. 36 | 37 | ## Driver Binding 38 | 39 | Every Devicetree node can be ultimately exposed as an `EFI_HANDLE` with the 40 | `EFI_DT_IO_PROTOCOL` installed. Initially (ignoring the support for 41 | regression testing), there's only the root Devicetree node. Its direct 42 | children are enumerated by FdtBusDxe as part of the `Start()` Driver 43 | Binding Protocol function being invoked. 44 | 45 | FdtBusDxe manages the following Devicetree nodes: 46 | 47 | - Devicetree root. 48 | - _simple-bus_ (a simple container for devices). 49 | - Regression (unit) testing nodes. 50 | 51 | Every enumerated node is tracked via a `DT_DEVICE` structure. 52 | 53 | Stopping is supported. 54 | 55 | ## Structure 56 | 57 | | File | Description | 58 | | ---- | ----------- | 59 | | ComponentName.c | `EFI_COMPONENT_NAME_PROTOCOL` and `EFI_COMPONENT_NAME2_PROTOCOL`. | 60 | | DriverBinding.c | `EFI_DRIVER_BINDING_PROTOCOL`. | 61 | | DtDevice.c | `DT_DEVICE` object management. | 62 | | DtIoProp.c | Simple `EFI_DT_IO_PROTOCOL` property API wrappers. | 63 | | DtIoPropParse.c | Bulk of `EFI_DT_PROPERTY` management, property parsing and `EFI_DT_IO_PROTOCOL` property API. | 64 | | DtIo.c | `EFI_DT_IO_PROTOCOL`. | 65 | | Entry.c | Driver entrypoint and related. | 66 | | Fdt.c | Simple wrappres around libfdt functionality. | 67 | | Utils.c | Various. | 68 | | Tests.c | Regression tests. | 69 | 70 | ## Testing 71 | 72 | Debug builds come with automatic regression testing. This uses an 73 | [entirely separate Devicetree](../Drivers/FdtBusDxe/TestDt.dts), and 74 | is managed separately - there is a separate test Devicetree root, and 75 | FdtBusDxe can easy differentiate a testing `DT_DEVICE` from a regular 76 | one. 77 | 78 | The test Devicetree [is built](../Drivers/FdtBusDxe/TestDt.sh) as part 79 | of building `FdtBusPkg.dsc`. Both the source and the resulting TestDt.dtbi 80 | file should be checked in, as the regular use of FdtBusPkg shouldn't 81 | involve adding new regression tests. The test Devicetree is embedded 82 | into the FdtBusDxe driver. 83 | 84 | The nodes under `/unit-test-devices` are used for unit tests. 85 | Others (like `/sample-device`) are for playing around with [sample 86 | driver code](../Drivers/SampleDeviceDxe). 87 | 88 | The regression test for each unit test device is invoked from 89 | `DriverStart()`. The tests are contained in 90 | [Tests.c](../Drivers/FdtBusDxe/Tests.c). Every unit test node 91 | added to TestDt.dts must be declared in the `TestDescs[]` array. -------------------------------------------------------------------------------- /Docs/StyleAndTerms.md: -------------------------------------------------------------------------------- 1 | # FdtBusPkg Documentation Style and Terms Definitions 2 | 3 | ## Style 4 | 5 | | Format | Meaning | 6 | | ------ | ------- | 7 | | `Fixed width quoted` | Code identifiers, including types, structure and function names. | 8 | | _italicized_ | Devicetree property names or values. | 9 | 10 | ## Terms 11 | 12 | | Term | Description | 13 | | ---- | ----------- | 14 | | Devicetree | See [Devicetree Specification](https://www.devicetree.org/). | 15 | | DT | Shorthand for Devicetree. | 16 | | DT controller | A DT controller directly corresponds to a Devicetree node, which is a software abstraction over a platform device. | 17 | | DtIo | Shorthand for `EFI_DT_IO_PROTOCOL`. | 18 | | DtInterrupt | Shorthand for `EFI_DT_INTERRUPT_PROTOCOL`. | 19 | | Platform devices | Non-discoverable devices in a computer system, referring to a lack of standardized hardware or software mechanism for renumeration and configuration of such device, unlike say PCIe or USB. | 20 | -------------------------------------------------------------------------------- /Docs/Uefi2023/slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/FdtBusPkg/9afa9ee56098aeaaeda6756821cee1b002324b28/Docs/Uefi2023/slides.pdf -------------------------------------------------------------------------------- /Docs/edk2-patches/0001-EDK2-BaseTools-Scripts-SetupGit.py-make-aware-of-Fdt.patch: -------------------------------------------------------------------------------- 1 | From 03f9a1f4c9ed6d77fa72e88f94459d9e02d6cfbe Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 15:27:30 -0600 4 | Subject: [PATCH 1/5] EDK2: BaseTools/Scripts/SetupGit.py: make aware of 5 | FdtBusPkg 6 | 7 | Signed-off-by: Andrei Warkentin 8 | --- 9 | BaseTools/Scripts/SetupGit.py | 3 +++ 10 | 1 file changed, 3 insertions(+) 11 | 12 | diff --git a/BaseTools/Scripts/SetupGit.py b/BaseTools/Scripts/SetupGit.py 13 | index 5f93124967bf..0e3a0f353f12 100644 14 | --- a/BaseTools/Scripts/SetupGit.py 15 | +++ b/BaseTools/Scripts/SetupGit.py 16 | @@ -38,6 +38,9 @@ CONFDIR = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__ 17 | 'Conf') 18 | 19 | UPSTREAMS = [ 20 | + {'name': 'FdtBusPkg', 21 | + 'repo': 'https://github.com/intel/FdtBusPkg.git', 22 | + 'list': 'andrei.warkentin@intel.com', 'prefix': 'FdtBusPkg'}, 23 | {'name': 'edk2', 24 | 'repo': 'https://github.com/tianocore/edk2.git', 25 | 'list': 'devel@edk2.groups.io'}, 26 | -- 27 | 2.34.1 28 | 29 | -------------------------------------------------------------------------------- /Docs/edk2-patches/0002-EDK2-UefiDevicePathLib-support-DT-.-device-path-node.patch: -------------------------------------------------------------------------------- 1 | From bc2f352c07a7461cdfb62daae99f83167b05bf1d Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Tue, 13 Feb 2024 14:36:42 -0600 4 | Subject: [PATCH 2/5] EDK2: UefiDevicePathLib: support DT(...) device path 5 | nodes 6 | 7 | This patch is entirely optional, it just gives a nicer experience 8 | within UEFI Shell and setup, e.g.: 9 | 10 | Shell> map -r 11 | Mapping table 12 | FS0: Alias(s):HD0b:;BLK1: 13 | DT(DtRoot)/DT(soc)/DT(virtio_mmio@10008000)/VenHw(837DCA9E-E874-4D82-B 14 | 29A-23FE0E23D1E2,0080001000000000)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1) 15 | 16 | Note: Ignores AllowShortcuts for converting to text. It is IMHO 17 | never useful to know that a DT(..) DP node is a VenHw, and long 18 | term (e.g. when upstreamed to Tiano and spec) - DT would be its own 19 | type like ACPI_DEVICE_PATH. 20 | 21 | Signed-off-by: Andrei Warkentin 22 | --- 23 | .../UefiDevicePathLib/UefiDevicePathLib.inf | 4 ++- 24 | .../UefiDevicePathLibBase.inf | 3 ++ 25 | ...evicePathLibOptionalDevicePathProtocol.inf | 4 ++- 26 | .../UefiDevicePathLibStandaloneMm.inf | 3 ++ 27 | .../UefiDevicePathLib/UefiDevicePathLib.h | 1 + 28 | .../UefiDevicePathLib/DevicePathFromText.c | 33 +++++++++++++++++++ 29 | .../UefiDevicePathLib/DevicePathToText.c | 12 +++++++ 30 | 7 files changed, 58 insertions(+), 2 deletions(-) 31 | 32 | diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 33 | index eb85a54a74c3..5022a91933df 100644 34 | --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 35 | +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 36 | @@ -34,7 +34,7 @@ [Sources] 37 | 38 | [Packages] 39 | MdePkg/MdePkg.dec 40 | - 41 | + FdtBusPkg/FdtBusPkg.dec 42 | 43 | [LibraryClasses] 44 | BaseLib 45 | @@ -65,6 +65,8 @@ [Guids] 46 | gEfiPersistentVirtualDiskGuid 47 | ## SOMETIMES_CONSUMES ## GUID 48 | gEfiPersistentVirtualCdGuid 49 | + ## SOMETIMES_CONSUMES ## GUID 50 | + gEfiDtDevicePathGuid 51 | 52 | [Protocols] 53 | gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES 54 | diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf 55 | index 323043033f1a..ff0541e52f66 100644 56 | --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf 57 | +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf 58 | @@ -36,6 +36,7 @@ [Sources] 59 | 60 | [Packages] 61 | MdePkg/MdePkg.dec 62 | + FdtBusPkg/FdtBusPkg.dec 63 | 64 | [LibraryClasses] 65 | BaseLib 66 | @@ -66,6 +67,8 @@ [Guids] 67 | gEfiPersistentVirtualDiskGuid 68 | ## SOMETIMES_CONSUMES ## GUID 69 | gEfiPersistentVirtualCdGuid 70 | + ## SOMETIMES_CONSUMES ## GUID 71 | + gEfiDtDevicePathGuid 72 | 73 | [Protocols] 74 | gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES 75 | diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf 76 | index 81323bc70061..693d90fa344a 100644 77 | --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf 78 | +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf 79 | @@ -37,7 +37,7 @@ [Sources] 80 | 81 | [Packages] 82 | MdePkg/MdePkg.dec 83 | - 84 | + FdtBusPkg/FdtBusPkg.dec 85 | 86 | [LibraryClasses] 87 | BaseLib 88 | @@ -69,6 +69,8 @@ [Guids] 89 | gEfiPersistentVirtualDiskGuid 90 | ## SOMETIMES_CONSUMES ## GUID 91 | gEfiPersistentVirtualCdGuid 92 | + ## SOMETIMES_CONSUMES ## GUID 93 | + gEfiDtDevicePathGuid 94 | 95 | [Protocols] 96 | gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES 97 | diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf 98 | index 97db485e23f8..10bd85c28884 100644 99 | --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf 100 | +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf 101 | @@ -39,6 +39,7 @@ [Sources] 102 | 103 | [Packages] 104 | MdePkg/MdePkg.dec 105 | + FdtBusPkg/FdtBusPkg.dec 106 | 107 | [LibraryClasses] 108 | BaseLib 109 | @@ -69,6 +70,8 @@ [Guids] 110 | gEfiPersistentVirtualDiskGuid 111 | ## SOMETIMES_CONSUMES ## GUID 112 | gEfiPersistentVirtualCdGuid 113 | + ## SOMETIMES_CONSUMES ## GUID 114 | + gEfiDtDevicePathGuid 115 | 116 | [Protocols] 117 | gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES 118 | diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h 119 | index 8f759f18facb..3fc1114cf10f 100644 120 | --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h 121 | +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h 122 | @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent 123 | #include 124 | #include 125 | #include 126 | +#include 127 | #include 128 | #include 129 | #include 130 | diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 131 | index 1aaa968d6fb5..ec84bbdad572 100644 132 | --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 133 | +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 134 | @@ -1311,6 +1311,38 @@ DevPathFromTextVenMsg ( 135 | ); 136 | } 137 | 138 | +/** 139 | + Converts a text device path node to Vendor defined Decicetree device path structure. 140 | + 141 | + @param TextDeviceNode The input Text device path node. 142 | + 143 | + @return A pointer to the newly-created Vendor defined Devicetree device path structure. 144 | + 145 | +**/ 146 | +EFI_DEVICE_PATH_PROTOCOL * 147 | +DevPathFromTextVenDT ( 148 | + IN CHAR16 *TextDeviceNode 149 | + ) 150 | +{ 151 | + CHAR16 *Name; 152 | + UINTN NameLen; 153 | + EFI_DT_DEVICE_PATH_NODE *Node; 154 | + EFI_STATUS Status; 155 | + 156 | + Name = GetNextParamStr (&TextDeviceNode); 157 | + NameLen = StrLen (Name) + 1; 158 | + Node = (EFI_DT_DEVICE_PATH_NODE *)CreateDeviceNode ( 159 | + HARDWARE_DEVICE_PATH, 160 | + HW_VENDOR_DP, 161 | + (UINT16)sizeof (EFI_DT_DEVICE_PATH_NODE) + NameLen 162 | + ); 163 | + CopyGuid (&Node->VendorDevicePath.Guid, &gEfiDtDevicePathGuid); 164 | + Status = UnicodeStrToAsciiStrS (Name, Node->Name, NameLen); 165 | + ASSERT_EFI_ERROR (Status); 166 | + 167 | + return (EFI_DEVICE_PATH_PROTOCOL *)Node; 168 | +} 169 | + 170 | /** 171 | Converts a text device path node to Vendor defined PC-ANSI device path structure. 172 | 173 | @@ -3503,6 +3535,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDev 174 | { L"USB", DevPathFromTextUsb }, 175 | { L"I2O", DevPathFromTextI2O }, 176 | { L"Infiniband", DevPathFromTextInfiniband }, 177 | + { L"DT", DevPathFromTextVenDT }, 178 | { L"VenMsg", DevPathFromTextVenMsg }, 179 | { L"VenPcAnsi", DevPathFromTextVenPcAnsi }, 180 | { L"VenVt100", DevPathFromTextVenVt100 }, 181 | diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c 182 | index 468baa5a7626..f06786d5d7f4 100644 183 | --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c 184 | +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c 185 | @@ -175,6 +175,18 @@ DevPathToTextVendor ( 186 | switch (DevicePathType (&Vendor->Header)) { 187 | case HARDWARE_DEVICE_PATH: 188 | Type = L"Hw"; 189 | + if (CompareGuid (&Vendor->Guid, &gEfiDtDevicePathGuid)) { 190 | + // 191 | + // Ignore AllowShortcuts here. It is never useful to know 192 | + // that a DT(..) DP node is a VenHw, and long term (e.g. when 193 | + // upstreamed to Tiano and spec) - it would be its own 194 | + // type like ACPI_DEVICE_PATH. 195 | + // 196 | + CHAR8 *Name = ((EFI_DT_DEVICE_PATH_NODE *)Vendor)->Name; 197 | + UefiDevicePathLibCatPrint (Str, L"DT(%a)", Name); 198 | + return; 199 | + } 200 | + 201 | break; 202 | 203 | case MESSAGING_DEVICE_PATH: 204 | -- 205 | 2.34.1 206 | 207 | -------------------------------------------------------------------------------- /Docs/edk2-patches/0003-EDK2-PciBusDxe-support-UEFI-DM-based-root-complex-ho.patch: -------------------------------------------------------------------------------- 1 | From 6eaed8438905306130d6bbf73406460a8edfcdf9 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Wed, 28 Feb 2024 10:37:52 -0600 4 | Subject: [PATCH 3/5] EDK2: PciBusDxe: support UEFI DM-based root complex/host 5 | bridge drivers. 6 | 7 | Fixes issue with connecting PciBusDxe after disconnecting PciBusDxe, 8 | caused by stale host bridge handle within gPciHostBridgeHandles. Now, 9 | host bridge handle is cleaned up when the last root bridge associated 10 | with the host bridge goes away. 11 | 12 | Signed-off-by: Andrei Warkentin 13 | --- 14 | MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 7 ++- 15 | .../Bus/Pci/PciBusDxe/PciEnumerator.h | 22 ++++++++ 16 | MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c | 24 ++++++-- 17 | .../Bus/Pci/PciBusDxe/PciEnumerator.c | 55 +++++++++++++++++-- 18 | 4 files changed, 98 insertions(+), 10 deletions(-) 19 | 20 | diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h 21 | index ca5c06204dec..32c19fc4832a 100644 22 | --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h 23 | +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h 24 | @@ -284,6 +284,11 @@ struct _PCI_IO_DEVICE { 25 | UINT32 ResizableBarNumber; 26 | }; 27 | 28 | +typedef struct _PCI_HOST_BRIDGE_HANDLE { 29 | + EFI_HANDLE Handle; 30 | + UINTN RootBridgeCount; 31 | +} PCI_HOST_BRIDGE_HANDLE; 32 | + 33 | #define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \ 34 | CR (a, PCI_IO_DEVICE, PciIo, PCI_IO_DEVICE_SIGNATURE) 35 | 36 | @@ -305,7 +310,7 @@ extern EFI_COMPONENT_NAME_PROTOCOL gPciBusComponentName; 37 | extern EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2; 38 | extern BOOLEAN gFullEnumeration; 39 | extern UINTN gPciHostBridgeNumber; 40 | -extern EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM]; 41 | +extern PCI_HOST_BRIDGE_HANDLE gPciHostBridgeHandles[PCI_MAX_HOST_BRIDGE_NUM]; 42 | extern UINT64 gAllOne; 43 | extern UINT64 gAllZero; 44 | extern EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol; 45 | diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.h 46 | index 2c81def04c9a..77a59b4fe863 100644 47 | --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.h 48 | +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.h 49 | @@ -500,6 +500,8 @@ SearchHostBridgeHandle ( 50 | /** 51 | Add host bridge handle to global variable for enumerating. 52 | 53 | + Called once for every root bridge added. 54 | + 55 | @param HostBridgeHandle Host bridge handle. 56 | 57 | @retval EFI_SUCCESS Successfully added host bridge. 58 | @@ -512,4 +514,24 @@ AddHostBridgeEnumerator ( 59 | IN EFI_HANDLE HostBridgeHandle 60 | ); 61 | 62 | +/** 63 | + Delete host bridge handle to global variable for enumerating. 64 | + 65 | + Called once for every root bridge removed (stopped). When the 66 | + number of calls to DeleteHostBridgeEnumerator matches the number 67 | + of calls to AddHostBridgeEnumerator, the handle is removed 68 | + from the global host bridge handle tracker. 69 | + 70 | + @param HostBridgeHandle Host bridge handle. 71 | + 72 | + @retval EFI_SUCCESS Successfully added host bridge. 73 | + @retval EFI_ABORTED Host bridge is NULL, or given host bridge 74 | + has been in host bridge list. 75 | + 76 | +**/ 77 | +EFI_STATUS 78 | +DeleteHostBridgeEnumeratorIfPossible ( 79 | + IN EFI_HANDLE HostBridgeHandle 80 | + ); 81 | + 82 | #endif 83 | diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c 84 | index 337b2090d98e..7593a816ab5a 100644 85 | --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c 86 | +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c 87 | @@ -27,7 +27,7 @@ EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = { 88 | NULL 89 | }; 90 | 91 | -EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM]; 92 | +PCI_HOST_BRIDGE_HANDLE gPciHostBridgeHandles[PCI_MAX_HOST_BRIDGE_NUM]; 93 | EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gIncompatiblePciDeviceSupport = NULL; 94 | UINTN gPciHostBridgeNumber = 0; 95 | BOOLEAN gFullEnumeration = TRUE; 96 | @@ -406,9 +406,23 @@ PciBusDriverBindingStop ( 97 | IN EFI_HANDLE *ChildHandleBuffer 98 | ) 99 | { 100 | - EFI_STATUS Status; 101 | - UINTN Index; 102 | - BOOLEAN AllChildrenStopped; 103 | + EFI_STATUS Status; 104 | + UINTN Index; 105 | + BOOLEAN AllChildrenStopped; 106 | + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; 107 | + EFI_HANDLE ParentHandle; 108 | + 109 | + PciRootBridgeIo = NULL; 110 | + Status = gBS->OpenProtocol ( 111 | + Controller, 112 | + &gEfiPciRootBridgeIoProtocolGuid, 113 | + (VOID **)&PciRootBridgeIo, 114 | + gPciBusDriverBinding.DriverBindingHandle, 115 | + Controller, 116 | + EFI_OPEN_PROTOCOL_GET_PROTOCOL 117 | + ); 118 | + ASSERT_EFI_ERROR (Status); 119 | + ParentHandle = PciRootBridgeIo->ParentHandle; 120 | 121 | if (NumberOfChildren == 0) { 122 | // 123 | @@ -431,6 +445,8 @@ PciBusDriverBindingStop ( 124 | Controller 125 | ); 126 | 127 | + DeleteHostBridgeEnumeratorIfPossible (ParentHandle); 128 | + 129 | return EFI_SUCCESS; 130 | } 131 | 132 | diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 133 | index 3f8c6e6da7dc..364c72ca4bf8 100644 134 | --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 135 | +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 136 | @@ -1887,7 +1887,7 @@ PreprocessController ( 137 | } 138 | 139 | // 140 | - // Get Root Brige Handle 141 | + // Get Root Brigde Handle 142 | // 143 | while (Bridge->Parent != NULL) { 144 | Bridge = Bridge->Parent; 145 | @@ -2149,7 +2149,7 @@ SearchHostBridgeHandle ( 146 | 147 | HostBridgeHandle = PciRootBridgeIo->ParentHandle; 148 | for (Index = 0; Index < gPciHostBridgeNumber; Index++) { 149 | - if (HostBridgeHandle == gPciHostBrigeHandles[Index]) { 150 | + if (HostBridgeHandle == gPciHostBridgeHandles[Index].Handle) { 151 | return TRUE; 152 | } 153 | } 154 | @@ -2160,6 +2160,8 @@ SearchHostBridgeHandle ( 155 | /** 156 | Add host bridge handle to global variable for enumerating. 157 | 158 | + Called once for every root bridge added. 159 | + 160 | @param HostBridgeHandle Host bridge handle. 161 | 162 | @retval EFI_SUCCESS Successfully added host bridge. 163 | @@ -2179,15 +2181,58 @@ AddHostBridgeEnumerator ( 164 | } 165 | 166 | for (Index = 0; Index < gPciHostBridgeNumber; Index++) { 167 | - if (HostBridgeHandle == gPciHostBrigeHandles[Index]) { 168 | - return EFI_ABORTED; 169 | + if (HostBridgeHandle == gPciHostBridgeHandles[Index].Handle) { 170 | + gPciHostBridgeHandles[Index].RootBridgeCount++; 171 | + return EFI_SUCCESS; 172 | } 173 | } 174 | 175 | if (Index < PCI_MAX_HOST_BRIDGE_NUM) { 176 | - gPciHostBrigeHandles[Index] = HostBridgeHandle; 177 | + gPciHostBridgeHandles[Index].Handle = HostBridgeHandle; 178 | + gPciHostBridgeHandles[Index].RootBridgeCount = 1; 179 | gPciHostBridgeNumber++; 180 | } 181 | 182 | return EFI_SUCCESS; 183 | } 184 | + 185 | +/** 186 | + Delete host bridge handle to global variable for enumerating. 187 | + 188 | + Called once for every root bridge removed (stopped). When the 189 | + number of calls to DeleteHostBridgeEnumerator matches the number 190 | + of calls to AddHostBridgeEnumerator, the handle is removed 191 | + from the global host bridge handle tracker. 192 | + 193 | + @param HostBridgeHandle Host bridge handle. 194 | + 195 | + @retval EFI_SUCCESS Successfully added host bridge. 196 | + @retval EFI_ABORTED Host bridge is NULL, or given host bridge 197 | + has been in host bridge list. 198 | + 199 | +**/ 200 | +EFI_STATUS 201 | +DeleteHostBridgeEnumeratorIfPossible ( 202 | + IN EFI_HANDLE HostBridgeHandle 203 | + ) 204 | +{ 205 | + UINTN Index; 206 | + 207 | + if (HostBridgeHandle == NULL) { 208 | + return EFI_ABORTED; 209 | + } 210 | + 211 | + for (Index = 0; Index < gPciHostBridgeNumber; Index++) { 212 | + if (HostBridgeHandle == gPciHostBridgeHandles[Index].Handle) { 213 | + gPciHostBridgeHandles[Index].RootBridgeCount--; 214 | + if (gPciHostBridgeHandles[Index].RootBridgeCount == 0) { 215 | + gPciHostBridgeHandles[Index].Handle = NULL; 216 | + gPciHostBridgeNumber--; 217 | + } 218 | + 219 | + return EFI_SUCCESS; 220 | + } 221 | + } 222 | + 223 | + return EFI_NOT_FOUND; 224 | +} 225 | -- 226 | 2.34.1 227 | 228 | -------------------------------------------------------------------------------- /Docs/edk2-patches/0004-EDK2-PciBus-PciIoGetBarAttributes-correct-reporting-.patch: -------------------------------------------------------------------------------- 1 | From 4b5797f655b854016a1da52692b4d93c75038e8c Mon Sep 17 00:00:00 2001 2 | From: "andrei.warkentin@intel.com" 3 | Date: Wed, 4 Sep 2024 08:18:23 +0300 4 | Subject: [PATCH 4/5] EDK2: PciBus: PciIoGetBarAttributes correct reporting 5 | address translation for PCI IO BAR 6 | 7 | AddrTranslationOffset was not being reported. 8 | 9 | Signed-off-by: Andrei Warkentin 10 | --- 11 | MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 64 ++++++++++++++++++++++++++ 12 | 1 file changed, 64 insertions(+) 13 | 14 | diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c 15 | index 14bed5472958..1103f3f7ab44 100644 16 | --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c 17 | +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c 18 | @@ -1835,6 +1835,59 @@ GetMmioAddressTranslationOffset ( 19 | return (UINT64)-1; 20 | } 21 | 22 | +/** 23 | + Retrieve the AddrTranslationOffset from RootBridgeIo for the 24 | + specified PCI I/O range. 25 | + 26 | + @param RootBridgeIo Root Bridge IO instance. 27 | + @param AddrRangeMin The base address of the PCI IO. 28 | + @param AddrLen The length of the PCI IO. 29 | + 30 | + @retval The AddrTranslationOffset from RootBridgeIo for the 31 | + specified range, or (UINT64) -1 if the range is not 32 | + found in RootBridgeIo. 33 | +**/ 34 | +UINT64 35 | +GetIoAddressTranslationOffset ( 36 | + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo, 37 | + UINT64 AddrRangeMin, 38 | + UINT64 AddrLen 39 | + ) 40 | +{ 41 | + EFI_STATUS Status; 42 | + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration; 43 | + 44 | + Status = RootBridgeIo->Configuration ( 45 | + RootBridgeIo, 46 | + (VOID **)&Configuration 47 | + ); 48 | + if (EFI_ERROR (Status)) { 49 | + return (UINT64)-1; 50 | + } 51 | + 52 | + // According to UEFI 2.7, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL::Configuration() 53 | + // returns host address instead of device address, while AddrTranslationOffset 54 | + // is not zero, and device address = host address + AddrTranslationOffset, so 55 | + // we convert host address to device address for range compare. 56 | + while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) { 57 | + if ((Configuration->ResType == ACPI_ADDRESS_SPACE_TYPE_IO) && 58 | + (Configuration->AddrRangeMin + Configuration->AddrTranslationOffset <= AddrRangeMin) && 59 | + (Configuration->AddrRangeMin + Configuration->AddrLen + Configuration->AddrTranslationOffset >= AddrRangeMin + AddrLen) 60 | + ) 61 | + { 62 | + return Configuration->AddrTranslationOffset; 63 | + } 64 | + 65 | + Configuration++; 66 | + } 67 | + 68 | + // 69 | + // The resource occupied by BAR should be in the range reported by RootBridge. 70 | + // 71 | + ASSERT (FALSE); 72 | + return (UINT64)-1; 73 | +} 74 | + 75 | /** 76 | Gets the attributes that this PCI controller supports setting on a BAR using 77 | SetBarAttributes(), and retrieves the list of resource descriptors for a BAR. 78 | @@ -1973,6 +2026,17 @@ PciIoGetBarAttributes ( 79 | FreePool (Descriptor); 80 | return EFI_UNSUPPORTED; 81 | } 82 | + } else { 83 | + ASSERT (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_IO); 84 | + Descriptor->AddrTranslationOffset = GetIoAddressTranslationOffset ( 85 | + PciIoDevice->PciRootBridgeIo, 86 | + Descriptor->AddrRangeMin, 87 | + Descriptor->AddrLen 88 | + ); 89 | + if (Descriptor->AddrTranslationOffset == (UINT64)-1) { 90 | + FreePool (Descriptor); 91 | + return EFI_UNSUPPORTED; 92 | + } 93 | } 94 | 95 | // According to UEFI spec 2.7, we need return host address for 96 | -- 97 | 2.34.1 98 | 99 | -------------------------------------------------------------------------------- /Docs/edk2-patches/0005-EDK2-ShellPkg-Mm.patch: -------------------------------------------------------------------------------- 1 | From c22a8c0ee584d90c3694ebb5a18d38bc1b7e0efd Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Wed, 4 Sep 2024 08:38:40 +0300 4 | Subject: [PATCH 5/5] EDK2: ShellPkg: Mm 5 | 6 | Make aware of AddrTranslationOffset for root bridge resources. 7 | 8 | Signed-off-by: Andrei Warkentin 9 | --- 10 | ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c | 2 +- 11 | 1 file changed, 1 insertion(+), 1 deletion(-) 12 | 13 | diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c 14 | index b75e2f477080..11ddfe91aa16 100644 15 | --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c 16 | +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c 17 | @@ -386,7 +386,7 @@ ShellMmLocateIoProtocol ( 18 | // 19 | } else if ((((Descriptors->ResType == ACPI_ADDRESS_SPACE_TYPE_IO) && (AccessType == ShellMmIo)) || 20 | ((Descriptors->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) && (AccessType == ShellMmMemoryMappedIo)) 21 | - ) && ((Address >= Descriptors->AddrRangeMin) && (Address <= Descriptors->AddrRangeMax)) 22 | + ) && ((Address >= Descriptors->AddrRangeMin + Descriptors->AddrTranslationOffset) && (Address <= Descriptors->AddrRangeMax + Descriptors->AddrTranslationOffset)) 23 | ) 24 | { 25 | *PciRootBridgeIo = Io; 26 | -- 27 | 2.34.1 28 | 29 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0001-OvmfPkg-RiscVVirt-change-for-testing-HighMemDxe.patch: -------------------------------------------------------------------------------- 1 | From 4b8e9bc65e18f08c347f7af89b1b58bbb1e4b961 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Thu, 15 Feb 2024 23:25:47 -0600 4 | Subject: [PATCH 1/9] OvmfPkg/RiscVVirt: change for testing HighMemDxe 5 | 6 | Since MemoryPeimInitialization loops over all "memory" 7 | devices, HighMemDxe does nothing. Stop after the first 8 | entry to give HighMemDxe a chance. 9 | 10 | To test, run Qemu with NUMA, e.g: 11 | ... -m 8192 -numa node,mem=4G -numa node,mem=4G ... 12 | 13 | Signed-off-by: Andrei Warkentin 14 | --- 15 | OvmfPkg/RiscVVirt/Sec/Memory.c | 26 +++++++++++++++----------- 16 | 1 file changed, 15 insertions(+), 11 deletions(-) 17 | 18 | diff --git a/OvmfPkg/RiscVVirt/Sec/Memory.c b/OvmfPkg/RiscVVirt/Sec/Memory.c 19 | index 7c6d920bd2a6..4bd4f88e15b8 100644 20 | --- a/OvmfPkg/RiscVVirt/Sec/Memory.c 21 | +++ b/OvmfPkg/RiscVVirt/Sec/Memory.c 22 | @@ -253,6 +253,7 @@ MemoryPeimInitialization ( 23 | INT32 Node, Prev; 24 | INT32 Len; 25 | VOID *FdtPointer; 26 | + BOOLEAN Once = TRUE; 27 | 28 | FirmwareContext = NULL; 29 | GetFirmwareContextPointer (&FirmwareContext); 30 | @@ -285,18 +286,21 @@ MemoryPeimInitialization ( 31 | CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp)); 32 | CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); 33 | 34 | - DEBUG (( 35 | - DEBUG_INFO, 36 | - "%a: System RAM @ 0x%lx - 0x%lx\n", 37 | - __func__, 38 | - CurBase, 39 | - CurBase + CurSize - 1 40 | - )); 41 | + if (Once) { 42 | + DEBUG (( 43 | + DEBUG_INFO, 44 | + "%a: System RAM @ 0x%lx - 0x%lx\n", 45 | + __func__, 46 | + CurBase, 47 | + CurBase + CurSize - 1 48 | + )); 49 | 50 | - InitializeRamRegions ( 51 | - CurBase, 52 | - CurSize 53 | - ); 54 | + InitializeRamRegions ( 55 | + CurBase, 56 | + CurSize 57 | + ); 58 | + Once = FALSE; 59 | + } 60 | } else { 61 | DEBUG (( 62 | DEBUG_ERROR, 63 | -- 64 | 2.34.1 65 | 66 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0002-RiscVVirt-add-FdtBusDxe.patch: -------------------------------------------------------------------------------- 1 | From b1818d4cd4089de02c964757fff987b35985e59c Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 17:01:39 -0600 4 | Subject: [PATCH 2/9] RiscVVirt: add FdtBusDxe 5 | 6 | Not used by anything. 7 | 8 | Signed-off-by: Andrei Warkentin 9 | --- 10 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 6 ++++++ 11 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 1 + 12 | 2 files changed, 7 insertions(+) 13 | 14 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 15 | index 024badebf250..2d9dc2fbdc5a 100644 16 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 17 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 18 | @@ -160,6 +160,8 @@ [LibraryClasses.common] 19 | PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf 20 | PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf 21 | ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf 22 | + FbpUtilsLib|FdtBusPkg/Library/FbpUtilsLib/FbpUtilsLib.inf 23 | + FbpInterruptUtilsLib|FdtBusPkg/Library/FbpInterruptUtilsLib/FbpInterruptUtilsLib.inf 24 | 25 | !if $(TPM2_ENABLE) == TRUE 26 | Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf 27 | @@ -421,6 +423,10 @@ [Components] 28 | OvmfPkg/VirtioScsiDxe/VirtioScsi.inf 29 | OvmfPkg/VirtioNetDxe/VirtioNet.inf 30 | OvmfPkg/VirtioRngDxe/VirtioRng.inf 31 | + FdtBusPkg/Drivers/FdtBusDxe/FdtBusDxe.inf { 32 | + 33 | + FbpPlatformDtLib|FdtBusPkg/Library/FbpPlatformDtLib/FbpPlatformDtLib.inf 34 | + } 35 | 36 | # 37 | # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs 38 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 39 | index 3a542a5cb13f..2ed85c52830c 100644 40 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 41 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 42 | @@ -128,6 +128,7 @@ [FV.DXEFV] 43 | INF OvmfPkg/VirtioNetDxe/VirtioNet.inf 44 | INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf 45 | INF OvmfPkg/VirtioRngDxe/VirtioRng.inf 46 | +INF FdtBusPkg/Drivers/FdtBusDxe/FdtBusDxe.inf 47 | 48 | INF ShellPkg/Application/Shell/Shell.inf 49 | INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf 50 | -- 51 | 2.34.1 52 | 53 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0003-RiscVVirt-enable-PciSioSerialDxe.patch: -------------------------------------------------------------------------------- 1 | From 982f26163abede6d6ce0b2c9e42c7591665c4a38 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 17:20:41 -0600 4 | Subject: [PATCH 3/9] RiscVVirt: enable PciSioSerialDxe 5 | 6 | Build with FBP_SERIAL_DXE=TRUE (default) to use DT-based 7 | console driver. Build with FALSE for old behavior. 8 | 9 | Signed-off-by: Andrei Warkentin 10 | --- 11 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 12 ++++ 12 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 6 +- 13 | .../PlatformBootManagerLib.inf | 2 + 14 | .../PlatformBootManagerLib/PlatformBm.c | 65 +++++++++++++++++-- 15 | 4 files changed, 80 insertions(+), 5 deletions(-) 16 | 17 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 18 | index 2d9dc2fbdc5a..14661698c82e 100644 19 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 20 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 21 | @@ -24,6 +24,11 @@ [Defines] 22 | SKUID_IDENTIFIER = DEFAULT 23 | FLASH_DEFINITION = OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 24 | 25 | + # 26 | + # FdtBusDxe-based build options. 27 | + # 28 | + FBP_SERIAL_DXE = TRUE 29 | + 30 | # 31 | # Enable below options may cause build error or may not work on 32 | # the initial version of RISC-V package 33 | @@ -113,6 +118,9 @@ [Defines] 34 | 35 | [BuildOptions] 36 | GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG 37 | +!if $(FBP_SERIAL_DXE) == TRUE 38 | + GCC:*_*_*_CC_FLAGS = -DFBP_SERIAL_DXE 39 | +!endif 40 | !ifdef $(SOURCE_DEBUG_ENABLE) 41 | GCC:*_*_RISCV64_GENFW_FLAGS = --keepexceptiontable 42 | !endif 43 | @@ -394,7 +402,11 @@ [Components] 44 | MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf 45 | MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf 46 | MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf 47 | +!if $(FBP_SERIAL_DXE) == TRUE 48 | + FdtBusPkg/Drivers/PciSioSerialDxe/PciSioSerialDxe.inf 49 | +!else 50 | MdeModulePkg/Universal/SerialDxe/SerialDxe.inf 51 | +!endif 52 | 53 | MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf 54 | 55 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 56 | index 2ed85c52830c..6ebd986c6698 100644 57 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 58 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 59 | @@ -98,7 +98,11 @@ [FV.DXEFV] 60 | INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf 61 | INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf 62 | INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf 63 | -INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf 64 | +!if $(FBP_SERIAL_DXE) == TRUE 65 | + INF FdtBusPkg/Drivers/PciSioSerialDxe/PciSioSerialDxe.inf 66 | +!else 67 | + INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf 68 | +!endif 69 | 70 | # RISC-V Core Drivers 71 | INF UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf 72 | diff --git a/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 73 | index 9d66c8110c53..8dedff8cb268 100644 74 | --- a/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 75 | +++ b/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 76 | @@ -32,6 +32,7 @@ [Packages] 77 | OvmfPkg/OvmfPkg.dec 78 | SecurityPkg/SecurityPkg.dec 79 | ShellPkg/ShellPkg.dec 80 | + FdtBusPkg/FdtBusPkg.dec 81 | 82 | [LibraryClasses] 83 | BaseLib 84 | @@ -50,6 +51,7 @@ [LibraryClasses] 85 | UefiBootServicesTableLib 86 | UefiLib 87 | UefiRuntimeServicesTableLib 88 | + FbpUtilsLib 89 | 90 | [FixedPcd] 91 | gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate 92 | diff --git a/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBm.c b/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBm.c 93 | index 44fd21f74fcf..354efccd36a6 100644 94 | --- a/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBm.c 95 | +++ b/OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBm.c 96 | @@ -31,6 +31,12 @@ 97 | #include 98 | #include 99 | 100 | +#ifdef FBP_SERIAL_DXE 101 | +#include 102 | +#include 103 | +#include 104 | +#endif /* FBP_SERIAL_DXE */ 105 | + 106 | #include "PlatformBm.h" 107 | 108 | #define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } 109 | @@ -39,13 +45,18 @@ 110 | 111 | #pragma pack (1) 112 | typedef struct { 113 | +#ifndef FBP_SERIAL_DXE 114 | VENDOR_DEVICE_PATH SerialDxe; 115 | +#endif /* FBP_SERIAL_DXE */ 116 | UART_DEVICE_PATH Uart; 117 | VENDOR_DEFINED_DEVICE_PATH TermType; 118 | EFI_DEVICE_PATH_PROTOCOL End; 119 | } PLATFORM_SERIAL_CONSOLE; 120 | #pragma pack () 121 | 122 | +#ifdef FBP_SERIAL_DXE 123 | +STATIC PLATFORM_SERIAL_CONSOLE mSerialConsoleSuffix = { 124 | +#else 125 | STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { 126 | // 127 | // VENDOR_DEVICE_PATH SerialDxe 128 | @@ -54,7 +65,7 @@ STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { 129 | { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) }, 130 | EDKII_SERIAL_PORT_LIB_VENDOR_GUID 131 | }, 132 | - 133 | +#endif /* FBP_SERIAL_DXE */ 134 | // 135 | // UART_DEVICE_PATH Uart 136 | // 137 | @@ -784,9 +795,16 @@ PlatformBootManagerBeforeConsole ( 138 | VOID 139 | ) 140 | { 141 | - UINT16 FrontPageTimeout; 142 | - RETURN_STATUS PcdStatus; 143 | - EFI_STATUS Status; 144 | + UINT16 FrontPageTimeout; 145 | + RETURN_STATUS PcdStatus; 146 | + EFI_STATUS Status; 147 | +#ifdef FBP_SERIAL_DXE 148 | + EFI_HANDLE Handle; 149 | + EFI_DT_IO_PROTOCOL *DtIo; 150 | + EFI_DEVICE_PATH_PROTOCOL *DtDp; 151 | + EFI_DEVICE_PATH_PROTOCOL *NewDp; 152 | + CONST CHAR8 *DtStdOutPath; 153 | +#endif /* FBP_SERIAL_DXE */ 154 | 155 | // 156 | // Signal EndOfDxe PI Event 157 | @@ -837,6 +855,44 @@ PlatformBootManagerBeforeConsole ( 158 | NULL 159 | ); 160 | 161 | +#ifdef FBP_SERIAL_DXE 162 | + CopyGuid (&mSerialConsoleSuffix.TermType.Guid, &gEfiTtyTermGuid); 163 | + 164 | + DtIo = FbpGetDtRoot (); 165 | + ASSERT (DtIo != NULL); 166 | + 167 | + Status = DtIo->Lookup (DtIo, "/chosen", TRUE, &Handle); 168 | + ASSERT_EFI_ERROR (Status); 169 | + 170 | + Status = gBS->HandleProtocol ( 171 | + Handle, 172 | + &gEfiDtIoProtocolGuid, 173 | + (VOID **)&DtIo 174 | + ); 175 | + ASSERT_EFI_ERROR (Status); 176 | + 177 | + DtStdOutPath = NULL; 178 | + Status = DtIo->GetString (DtIo, "stdout-path", 0, &DtStdOutPath); 179 | + ASSERT_EFI_ERROR (Status); 180 | + ASSERT (DtStdOutPath != NULL); 181 | + 182 | + Status = DtIo->Lookup (DtIo, DtStdOutPath, TRUE, &Handle); 183 | + ASSERT_EFI_ERROR (Status); 184 | + 185 | + Status = gBS->HandleProtocol ( 186 | + Handle, 187 | + &gEfiDevicePathProtocolGuid, 188 | + (VOID **)&DtDp 189 | + ); 190 | + ASSERT_EFI_ERROR (Status); 191 | + 192 | + NewDp = AppendDevicePath (DtDp, (VOID *)&mSerialConsoleSuffix); 193 | + 194 | + EfiBootManagerUpdateConsoleVariable (ConIn, NewDp, NULL); 195 | + EfiBootManagerUpdateConsoleVariable (ConOut, NewDp, NULL); 196 | + EfiBootManagerUpdateConsoleVariable (ErrOut, NewDp, NULL); 197 | + FreePool (NewDp); 198 | +#else 199 | // 200 | // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut. 201 | // 202 | @@ -857,6 +913,7 @@ PlatformBootManagerBeforeConsole ( 203 | (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, 204 | NULL 205 | ); 206 | +#endif /* FBP_SERIAL_DXE */ 207 | 208 | // 209 | // Set the front page timeout from the QEMU configuration. 210 | -- 211 | 2.34.1 212 | 213 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0004-RiscVVirt-enable-VirtioFdtDxe.patch: -------------------------------------------------------------------------------- 1 | From 403acb4ac87113e40ea4391bba37831f52521b40 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 17:27:05 -0600 4 | Subject: [PATCH 4/9] RiscVVirt: enable VirtioFdtDxe 5 | 6 | Build with FBP_VIRTIO_DXE=TRUE (default) to use DT-based 7 | virtio driver. Build with FALSE for old behavior. 8 | 9 | Signed-off-by: Andrei Warkentin 10 | --- 11 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 8 ++++++++ 12 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 6 +++++- 13 | OvmfPkg/RiscVVirt/Sec/Platform.c | 2 ++ 14 | 3 files changed, 15 insertions(+), 1 deletion(-) 15 | 16 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 17 | index 14661698c82e..6beac1671b4e 100644 18 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 19 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 20 | @@ -28,6 +28,7 @@ [Defines] 21 | # FdtBusDxe-based build options. 22 | # 23 | FBP_SERIAL_DXE = TRUE 24 | + FBP_VIRTIO_DXE = TRUE 25 | 26 | # 27 | # Enable below options may cause build error or may not work on 28 | @@ -121,6 +122,9 @@ [BuildOptions] 29 | !if $(FBP_SERIAL_DXE) == TRUE 30 | GCC:*_*_*_CC_FLAGS = -DFBP_SERIAL_DXE 31 | !endif 32 | +!if $(FBP_VIRTIO_DXE) == TRUE 33 | + GCC:*_*_*_CC_FLAGS = -DFBP_VIRTIO_DXE 34 | +!endif 35 | !ifdef $(SOURCE_DEBUG_ENABLE) 36 | GCC:*_*_RISCV64_GENFW_FLAGS = --keepexceptiontable 37 | !endif 38 | @@ -423,7 +427,11 @@ [Components] 39 | # 40 | # Platform Driver 41 | # 42 | +!if $(FBP_VIRTIO_DXE) == TRUE 43 | + FdtBusPkg/Drivers/VirtioFdtDxe/VirtioFdtDxe.inf 44 | +!else 45 | OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf 46 | +!endif 47 | EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf { 48 | 49 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 50 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 51 | index 6ebd986c6698..aff49852a45a 100644 52 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 53 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 54 | @@ -69,7 +69,11 @@ [FV.DXEFV] 55 | INF MdeModulePkg/Core/Dxe/DxeMain.inf 56 | INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf 57 | INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf 58 | -INF OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf 59 | +!if $(FBP_VIRTIO_DXE) == TRUE 60 | + INF FdtBusPkg/Drivers/VirtioFdtDxe/VirtioFdtDxe.inf 61 | +!else 62 | + INF OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf 63 | +!endif 64 | INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf 65 | INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf 66 | 67 | diff --git a/OvmfPkg/RiscVVirt/Sec/Platform.c b/OvmfPkg/RiscVVirt/Sec/Platform.c 68 | index c66432473067..78e659d99c85 100644 69 | --- a/OvmfPkg/RiscVVirt/Sec/Platform.c 70 | +++ b/OvmfPkg/RiscVVirt/Sec/Platform.c 71 | @@ -140,7 +140,9 @@ PlatformPeimInitialization ( 72 | 73 | PopulateIoResources (Base, "ns16550a"); 74 | PopulateIoResources (Base, "qemu,fw-cfg-mmio"); 75 | +#ifndef FBP_VIRTIO_DXE 76 | PopulateIoResources (Base, "virtio,mmio"); 77 | +#endif /* FBP_VIRTIO_DXE */ 78 | 79 | return EFI_SUCCESS; 80 | } 81 | -- 82 | 2.34.1 83 | 84 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0005-RiscVVirt-enable-VirtNorFlashDxe.patch: -------------------------------------------------------------------------------- 1 | From 0f0249835d949ec082a4b6d42294b1e3f3c819f6 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 17:43:10 -0600 4 | Subject: [PATCH 5/9] RiscVVirt: enable VirtNorFlashDxe 5 | 6 | Build with FBP_NORFLASH_DXE=TRUE (default) to use DT-based 7 | flash driver. Build with FALSE for old behavior. 8 | 9 | Signed-off-by: Andrei Warkentin 10 | --- 11 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 7 +++++++ 12 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 12 +++++++++++- 13 | 2 files changed, 18 insertions(+), 1 deletion(-) 14 | 15 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 16 | index 6beac1671b4e..b0ef45b5c22b 100644 17 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 18 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 19 | @@ -29,6 +29,7 @@ [Defines] 20 | # 21 | FBP_SERIAL_DXE = TRUE 22 | FBP_VIRTIO_DXE = TRUE 23 | + FBP_NORFLASH_DXE = TRUE 24 | 25 | # 26 | # Enable below options may cause build error or may not work on 27 | @@ -155,7 +156,9 @@ [LibraryClasses.common] 28 | QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf 29 | 30 | TimerLib|UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf 31 | +!if $(FBP_NORFLASH_DXE) == FALSE 32 | VirtNorFlashPlatformLib|OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf 33 | +!endif 34 | 35 | CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf 36 | BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf 37 | @@ -415,7 +418,11 @@ [Components] 38 | MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf 39 | 40 | UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf 41 | +!if $(FBP_NORFLASH_DXE) == TRUE 42 | + FdtBusPkg/Drivers/VirtNorFlashDxe/VirtNorFlashDxe.inf 43 | +!else 44 | OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf 45 | +!endif 46 | MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf 47 | 48 | # 49 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 50 | index aff49852a45a..70624c1afb68 100644 51 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 52 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 53 | @@ -60,7 +60,13 @@ [FV.DXEFV] 54 | INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf 55 | INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf 56 | INF UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf 57 | +!if $(FBP_NORFLASH_DXE) == TRUE 58 | + INF OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf 59 | + INF FdtBusPkg/Drivers/VirtNorFlashDxe/VirtNorFlashDxe.inf 60 | + INF FdtBusPkg/Drivers/FdtBusDxe/FdtBusDxe.inf 61 | +!else 62 | INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf 63 | +!endif 64 | } 65 | 66 | # 67 | @@ -110,7 +116,11 @@ [FV.DXEFV] 68 | 69 | # RISC-V Core Drivers 70 | INF UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf 71 | -INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf 72 | +!if $(FBP_NORFLASH_DXE) == TRUE 73 | + INF FdtBusPkg/Drivers/VirtNorFlashDxe/VirtNorFlashDxe.inf 74 | +!else 75 | + INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf 76 | +!endif 77 | INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf 78 | 79 | # 80 | -- 81 | 2.34.1 82 | 83 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0006-RiscVVirt-enable-HighMemDxe.patch: -------------------------------------------------------------------------------- 1 | From 712f90e370f68765465dc386302a5230bf68e1fa Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 18:01:14 -0600 4 | Subject: [PATCH 6/9] RiscVVirt: enable HighMemDxe 5 | 6 | Build with FBP_HIGHMEMDXE_DXE=TRUE (default) to use DT-based 7 | HighMemDxe driver. Build with FALSE for old behavior. 8 | 9 | When building with FBP_HIGHMEM_BINDING=TRUE (default) the 10 | UEFI Driver Model-based driver is used. Otherwise, a legacy-style 11 | driver is used. 12 | 13 | Signed-off-by: Andrei Warkentin 14 | --- 15 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 11 +++++++++++ 16 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 10 +++++++++- 17 | 2 files changed, 20 insertions(+), 1 deletion(-) 18 | 19 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 20 | index b0ef45b5c22b..a1a333acd8f2 100644 21 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 22 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 23 | @@ -30,6 +30,8 @@ [Defines] 24 | FBP_SERIAL_DXE = TRUE 25 | FBP_VIRTIO_DXE = TRUE 26 | FBP_NORFLASH_DXE = TRUE 27 | + FBP_HIGHMEM_DXE = TRUE 28 | + FBP_HIGHMEM_BINDING = TRUE 29 | 30 | # 31 | # Enable below options may cause build error or may not work on 32 | @@ -445,7 +447,16 @@ [Components] 33 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 34 | DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf 35 | } 36 | +!if $(FBP_HIGHMEM_DXE) == TRUE 37 | + !if $(FBP_HIGHMEM_BINDING) == TRUE 38 | + FdtBusPkg/Drivers/HighMemDxe/HighMemDxe.inf 39 | + !else 40 | + FdtBusPkg/Drivers/HighMemDxe/HighMemDxeNoBinding.inf 41 | + !endif 42 | +!else 43 | OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf 44 | +!endif 45 | + 46 | OvmfPkg/VirtioBlkDxe/VirtioBlk.inf 47 | OvmfPkg/VirtioScsiDxe/VirtioScsi.inf 48 | OvmfPkg/VirtioNetDxe/VirtioNet.inf 49 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 50 | index 70624c1afb68..793f69ba5d22 100644 51 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 52 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 53 | @@ -81,7 +81,15 @@ [FV.DXEFV] 54 | INF OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf 55 | !endif 56 | INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf 57 | -INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf 58 | +!if $(FBP_HIGHMEM_DXE) == TRUE 59 | + !if $(FBP_HIGHMEM_BINDING) == TRUE 60 | + INF FdtBusPkg/Drivers/HighMemDxe/HighMemDxe.inf 61 | + !else 62 | + INF FdtBusPkg/Drivers/HighMemDxe/HighMemDxeNoBinding.inf 63 | + !endif 64 | +!else 65 | + INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf 66 | +!endif 67 | 68 | # 69 | # PI DXE Drivers producing Architectural Protocols (EFI Services) 70 | -- 71 | 2.34.1 72 | 73 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0007-RiscVVirt-enable-FBP-enabled-legacy-PCI-stack.patch: -------------------------------------------------------------------------------- 1 | From 650604b055bcc5d8c0c037df275050badae4d4e5 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Mon, 26 Feb 2024 18:16:36 -0600 4 | Subject: [PATCH 7/9] RiscVVirt: enable FBP-enabled legacy PCI stack 5 | 6 | Build with FBP_PCI_LEGACY=TRUE (default) to use FBP-based 7 | PCI support libraries Build with FALSE for old behavior 8 | (which use FdtClientDxe). 9 | 10 | Signed-off-by: Andrei Warkentin 11 | --- 12 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 27 +++++++++++++++++++++++---- 13 | 1 file changed, 23 insertions(+), 4 deletions(-) 14 | 15 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 16 | index a1a333acd8f2..c2d0cf1af7c8 100644 17 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 18 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 19 | @@ -32,6 +32,7 @@ [Defines] 20 | FBP_NORFLASH_DXE = TRUE 21 | FBP_HIGHMEM_DXE = TRUE 22 | FBP_HIGHMEM_BINDING = TRUE 23 | + FBP_PCI_LEGACY = TRUE 24 | 25 | # 26 | # Enable below options may cause build error or may not work on 27 | @@ -170,15 +171,21 @@ [LibraryClasses.common] 28 | FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf 29 | QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf 30 | FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf 31 | +!if $(FBP_PCI_LEGACY) == TRUE 32 | + PciPcdProducerLib|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 33 | + PciHostBridgeLib|FdtBusPkg/Library/PciHostBridgeLibEcam/PciHostBridgeLibEcam.inf 34 | +!else 35 | PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 36 | - PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf 37 | PciHostBridgeLib|OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf 38 | +!endif 39 | + PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf 40 | PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf 41 | PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf 42 | PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf 43 | ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf 44 | FbpUtilsLib|FdtBusPkg/Library/FbpUtilsLib/FbpUtilsLib.inf 45 | FbpInterruptUtilsLib|FdtBusPkg/Library/FbpInterruptUtilsLib/FbpInterruptUtilsLib.inf 46 | + FbpPciUtilsLib|FdtBusPkg/Library/FbpPciUtilsLib/FbpPciUtilsLib.inf 47 | 48 | !if $(TPM2_ENABLE) == TRUE 49 | Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf 50 | @@ -550,12 +557,20 @@ [Components] 51 | # 52 | OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf { 53 | 54 | - NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 55 | + !if $(FBP_PCI_LEGACY) == TRUE 56 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 57 | + !else 58 | + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 59 | + !endif 60 | } 61 | MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 62 | MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { 63 | 64 | - NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 65 | + !if $(FBP_PCI_LEGACY) == TRUE 66 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 67 | + !else 68 | + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 69 | + !endif 70 | } 71 | OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf 72 | OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf 73 | @@ -605,5 +620,9 @@ [Components] 74 | MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf 75 | OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { 76 | 77 | - NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 78 | + !if $(FBP_PCI_LEGACY) == TRUE 79 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 80 | + !else 81 | + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 82 | + !endif 83 | } 84 | -- 85 | 2.34.1 86 | 87 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0008-RiscVVirt-enable-native-DT-based-PCI-stack.patch: -------------------------------------------------------------------------------- 1 | From ad502e71292f5c71c6f9678fa0e38128281e5231 Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Wed, 28 Feb 2024 00:39:31 -0600 4 | Subject: [PATCH 8/9] RiscVVirt: enable native DT-based PCI stack 5 | 6 | Build with FBP_PCI=TRUE and FBP_PCI_LEGACY=FALSE (default) to 7 | use the new PciHostBridgeFdtDxe root complex driver. Build with 8 | FBP_PCI_LEGACY=TRUE to use the legacy PCI stack with the FBP-enabled 9 | PCI support libraries. Build with FBP_PCI=FALSE for the 10 | legacy PCI stack without the FBP-enabled PCI support libraries 11 | (using FdtClientDxe instead). 12 | 13 | The difference are: 14 | - PCI children are children of the DT controller 15 | - More than one ECAM-compatible DT controller (more than one segment) 16 | is supported. 17 | - Simpler handling of PCIe -> CPU aperture translations. 18 | - Simpler code (as I/O and eventually DMA is handled by DT I/O Protocol) 19 | 20 | Signed-off-by: Andrei Warkentin 21 | --- 22 | OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 55 +++++++++++++++++++++++------ 23 | OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 10 +++++- 24 | 2 files changed, 53 insertions(+), 12 deletions(-) 25 | 26 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 27 | index c2d0cf1af7c8..39476e0be971 100644 28 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 29 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc 30 | @@ -32,7 +32,8 @@ [Defines] 31 | FBP_NORFLASH_DXE = TRUE 32 | FBP_HIGHMEM_DXE = TRUE 33 | FBP_HIGHMEM_BINDING = TRUE 34 | - FBP_PCI_LEGACY = TRUE 35 | + FBP_PCI = TRUE 36 | + FBP_PCI_LEGACY = FALSE 37 | 38 | # 39 | # Enable below options may cause build error or may not work on 40 | @@ -171,15 +172,21 @@ [LibraryClasses.common] 41 | FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf 42 | QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf 43 | FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf 44 | -!if $(FBP_PCI_LEGACY) == TRUE 45 | - PciPcdProducerLib|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 46 | - PciHostBridgeLib|FdtBusPkg/Library/PciHostBridgeLibEcam/PciHostBridgeLibEcam.inf 47 | +!if $(FBP_PCI) == TRUE 48 | + !if $(FBP_PCI_LEGACY) == TRUE 49 | + PciPcdProducerLib|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 50 | + PciHostBridgeLib|FdtBusPkg/Library/PciHostBridgeLibEcam/PciHostBridgeLibEcam.inf 51 | + PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf 52 | + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf 53 | + !else 54 | + PciSegmentLib|MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/UefiPciSegmentLibPciRootBridgeIo.inf 55 | + !endif 56 | !else 57 | PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 58 | PciHostBridgeLib|OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf 59 | -!endif 60 | PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf 61 | PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf 62 | +!endif 63 | PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf 64 | PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf 65 | ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf 66 | @@ -200,7 +207,13 @@ [LibraryClasses.common] 67 | [LibraryClasses.common.DXE_DRIVER] 68 | AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf 69 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 70 | +!if $(FBP_PCI) == TRUE 71 | + !if $(FBP_PCI_LEGACY) == TRUE 72 | + PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf 73 | + !endif 74 | +!else 75 | PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf 76 | +!endif 77 | 78 | !if $(TPM2_ENABLE) == TRUE 79 | Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf 80 | @@ -208,7 +221,13 @@ [LibraryClasses.common.DXE_DRIVER] 81 | 82 | [LibraryClasses.common.UEFI_DRIVER] 83 | UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf 84 | +!if $(FBP_PCI) == TRUE 85 | + !if $(FBP_PCI_LEGACY) == TRUE 86 | + PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf 87 | + !endif 88 | +!else 89 | PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf 90 | +!endif 91 | 92 | #!include NetworkPkg/NetworkBuildOptions.dsc.inc 93 | 94 | @@ -557,17 +576,29 @@ [Components] 95 | # 96 | OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf { 97 | 98 | - !if $(FBP_PCI_LEGACY) == TRUE 99 | - NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 100 | + !if $(FBP_PCI) == TRUE 101 | + !if $(FBP_PCI_LEGACY) == TRUE 102 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 103 | + !endif 104 | !else 105 | NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 106 | !endif 107 | } 108 | +!if $(FBP_PCI) == TRUE 109 | + !if $(FBP_PCI_LEGACY) == TRUE 110 | + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 111 | + !else 112 | + FdtBusPkg/Drivers/PciHostBridgeFdtDxe/Driver.inf 113 | + !endif 114 | +!else 115 | MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 116 | +!endif 117 | MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { 118 | 119 | - !if $(FBP_PCI_LEGACY) == TRUE 120 | - NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 121 | + !if $(FBP_PCI) == TRUE 122 | + !if $(FBP_PCI_LEGACY) == TRUE 123 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 124 | + !endif 125 | !else 126 | NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 127 | !endif 128 | @@ -620,8 +651,10 @@ [Components] 129 | MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf 130 | OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { 131 | 132 | - !if $(FBP_PCI_LEGACY) == TRUE 133 | - NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 134 | + !if $(FBP_PCI) == TRUE 135 | + !if $(FBP_PCI_LEGACY) == TRUE 136 | + NULL|FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 137 | + !endif 138 | !else 139 | NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 140 | !endif 141 | diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 142 | index 793f69ba5d22..df9b4af3bf45 100644 143 | --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 144 | +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf 145 | @@ -212,7 +212,15 @@ [FV.DXEFV] 146 | # PCI support 147 | # 148 | INF OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf 149 | -INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 150 | +!if $(FBP_PCI) == TRUE 151 | + !if $(FBP_PCI_LEGACY) == TRUE 152 | + INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 153 | + !else 154 | + INF FdtBusPkg/Drivers/PciHostBridgeFdtDxe/Driver.inf 155 | + !endif 156 | +!else 157 | + INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf 158 | +!endif 159 | INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf 160 | INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf 161 | INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf 162 | -- 163 | 2.34.1 164 | 165 | -------------------------------------------------------------------------------- /Docs/ovmf-patches/0009-UiApp-FBP-enable-FrontPage.patch: -------------------------------------------------------------------------------- 1 | From f4991709aa357ae64c46a0ab9f620c3283b7c8cc Mon Sep 17 00:00:00 2001 2 | From: Andrei Warkentin 3 | Date: Wed, 28 Feb 2024 09:10:53 -0600 4 | Subject: [PATCH 9/9] UiApp: FBP-enable FrontPage 5 | 6 | Get the memory and board/cpu strings from FBP device properties. 7 | 8 | Just meant as an example - e.g. should be rewritten to be a fallback for 9 | situations where SMBIOS provides no strings. 10 | 11 | Signed-off-by: Andrei Warkentin 12 | --- 13 | MdeModulePkg/Application/UiApp/UiApp.inf | 2 + 14 | MdeModulePkg/Application/UiApp/FrontPage.c | 109 +++++++++++++++++++++ 15 | 2 files changed, 111 insertions(+) 16 | 17 | diff --git a/MdeModulePkg/Application/UiApp/UiApp.inf b/MdeModulePkg/Application/UiApp/UiApp.inf 18 | index 3b9e048851fe..89eabe97e1be 100644 19 | --- a/MdeModulePkg/Application/UiApp/UiApp.inf 20 | +++ b/MdeModulePkg/Application/UiApp/UiApp.inf 21 | @@ -37,6 +37,7 @@ [Sources] 22 | [Packages] 23 | MdePkg/MdePkg.dec 24 | MdeModulePkg/MdeModulePkg.dec 25 | + FdtBusPkg/FdtBusPkg.dec 26 | 27 | [LibraryClasses] 28 | DevicePathLib 29 | @@ -54,6 +55,7 @@ [LibraryClasses] 30 | PcdLib 31 | UefiHiiServicesLib 32 | UefiBootManagerLib 33 | + FbpUtilsLib 34 | 35 | [Guids] 36 | gEfiIfrTianoGuid ## CONSUMES ## GUID (Extended IFR Guid Opcode) 37 | diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c 38 | index 0e784fb327f5..c66adfdfca94 100644 39 | --- a/MdeModulePkg/Application/UiApp/FrontPage.c 40 | +++ b/MdeModulePkg/Application/UiApp/FrontPage.c 41 | @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent 42 | 43 | #include "FrontPage.h" 44 | #include "FrontPageCustomizedUi.h" 45 | +#include 46 | 47 | #define MAX_STRING_LEN 200 48 | 49 | @@ -496,6 +497,107 @@ GetOptionalStringByIndex ( 50 | return EFI_SUCCESS; 51 | } 52 | 53 | +/** 54 | + 55 | + Update the banner information for the Front Page based on DT information. 56 | + 57 | +**/ 58 | +EFI_STATUS 59 | +UpdateFrontPageBannerStringsFbp ( 60 | + VOID 61 | + ) 62 | +{ 63 | + EFI_DT_IO_PROTOCOL *DtIo; 64 | + CONST CHAR8 *Model; 65 | + EFI_STATUS Status; 66 | + CHAR16 *String; 67 | + UINTN Size; 68 | + EFI_HANDLE Handle; 69 | + UINTN HandleCount; 70 | + EFI_HANDLE *HandleBuffer; 71 | + UINTN Index; 72 | + EFI_DT_SIZE MemorySize; 73 | + 74 | + DtIo = FbpGetDtRoot (); 75 | + if (DtIo == NULL) { 76 | + return EFI_UNSUPPORTED; 77 | + } 78 | + 79 | + Status = DtIo->GetString (DtIo, "model", 0, &Model); 80 | + ASSERT_EFI_ERROR (Status); 81 | + 82 | + Size = AsciiStrSize (Model); 83 | + String = AllocatePool (Size * sizeof (CHAR16)); 84 | + AsciiStrToUnicodeStrS (Model, String, Size); 85 | + UiCustomizeFrontPageBanner (1, TRUE, &String); 86 | + HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL), String, NULL); 87 | + FreePool (String); 88 | + 89 | + Status = DtIo->Lookup (DtIo, "/cpus/cpu@0", FALSE, &Handle); 90 | + ASSERT_EFI_ERROR (Status); 91 | + Status = gBS->HandleProtocol ( 92 | + Handle, 93 | + &gEfiDtIoProtocolGuid, 94 | + (VOID **)&DtIo 95 | + ); 96 | + ASSERT_EFI_ERROR (Status); 97 | + 98 | + Status = DtIo->GetString (DtIo, "riscv,isa", 0, &Model); 99 | + ASSERT_EFI_ERROR (Status); 100 | + 101 | + Size = AsciiStrSize (Model); 102 | + String = AllocatePool (Size * sizeof (CHAR16)); 103 | + AsciiStrToUnicodeStrS (Model, String, Size); 104 | + UiCustomizeFrontPageBanner (2, TRUE, &String); 105 | + HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL), String, NULL); 106 | + FreePool (String); 107 | + 108 | + Status = gBS->LocateHandleBuffer ( 109 | + ByProtocol, 110 | + &gEfiDtIoProtocolGuid, 111 | + NULL, 112 | + &HandleCount, 113 | + &HandleBuffer 114 | + ); 115 | + ASSERT_EFI_ERROR (Status); 116 | + 117 | + MemorySize = 0; 118 | + for (Index = 0; Index < HandleCount; Index++) { 119 | + EFI_DT_REG Reg; 120 | + UINTN Index2; 121 | + 122 | + Status = gBS->HandleProtocol ( 123 | + HandleBuffer[Index], 124 | + &gEfiDtIoProtocolGuid, 125 | + (VOID **)&DtIo 126 | + ); 127 | + ASSERT_EFI_ERROR (Status); 128 | + 129 | + if (AsciiStrCmp (DtIo->DeviceType, "memory") != 0) { 130 | + continue; 131 | + } 132 | + 133 | + Index2 = 0; 134 | + do { 135 | + Status = DtIo->GetReg (DtIo, Index2++, &Reg); 136 | + if (EFI_ERROR (Status)) { 137 | + break; 138 | + } 139 | + 140 | + MemorySize += Reg.Length; 141 | + } while (1); 142 | + } 143 | + 144 | + FreePool (HandleBuffer); 145 | + 146 | + ConvertMemorySizeToString (MemorySize >> 20, &String); 147 | + UiCustomizeFrontPageBanner (3, FALSE, &String); 148 | + HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE), String, NULL); 149 | + FreePool (String); 150 | + 151 | + return EFI_SUCCESS; 152 | +} 153 | + 154 | /** 155 | 156 | Update the banner information for the Front Page based on Smbios information. 157 | @@ -546,6 +648,13 @@ UpdateFrontPageBannerStrings ( 158 | HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT), NewString, NULL); 159 | FreePool (NewString); 160 | 161 | + // 162 | + // Use FBP if available. 163 | + // 164 | + if (!EFI_ERROR (UpdateFrontPageBannerStringsFbp ())) { 165 | + return; 166 | + } 167 | + 168 | // 169 | // Update Front Page banner strings base on SmBios Table. 170 | // 171 | -- 172 | 2.34.1 173 | 174 | -------------------------------------------------------------------------------- /Drivers/FdtBusDxe/DtProp.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #include "FdtBusDxe.h" 10 | 11 | /** 12 | Parses out a fdtbuspkg,reg-attrs/fdtbuspkg,range-attrs property value, 13 | advancing Prop->Iter on success. 14 | 15 | @param This A pointer to the EFI_DT_IO_PROTOCOL instance. 16 | @param Prop EFI_DT_PROPERTY describing the property buffer and 17 | @param Index Index of the field to return, starting from the 18 | current buffer position within the EFI_DT_PROPERTY. 19 | @param GcdType Pointer to EFI_GCD_MEMORY_TYPE to populate. 20 | @param EfiMemoryAttributes Pointer to UINT64 to populate. 21 | current position. 22 | 23 | @retval EFI_SUCCESS Parsing successful. 24 | @retval EFI_NOT_FOUND Not enough remaining property buffer to contain 25 | the field of specified type. 26 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 27 | 28 | **/ 29 | STATIC 30 | EFI_STATUS 31 | DtPropParseEfiTypeAndAttrs ( 32 | IN DT_DEVICE *DtDevice, 33 | IN OUT EFI_DT_PROPERTY *Prop, 34 | IN UINTN Index, 35 | OUT EFI_GCD_MEMORY_TYPE *GcdType, 36 | OUT UINT64 *EfiMemoryAttributes 37 | ) 38 | { 39 | UINTN Cells; 40 | UINTN ElemCells; 41 | CONST VOID *OriginalIter; 42 | EFI_DT_IO_REG_TYPE DtType; 43 | EFI_GCD_MEMORY_TYPE Type; 44 | EFI_STATUS Status; 45 | UINT64 Attributes; 46 | 47 | // 48 | // 1 cell for EFI_DT_IO_REG_TYPE. 49 | // 2 cells for EfiMemoryAttributes. 50 | // 51 | ElemCells = 1 + 2; 52 | Cells = (Prop->End - Prop->Iter) / sizeof (EFI_DT_CELL); 53 | OriginalIter = Prop->Iter; 54 | 55 | if ((Cells / ElemCells) <= Index) { 56 | return EFI_NOT_FOUND; 57 | } 58 | 59 | Prop->Iter = (EFI_DT_CELL *)Prop->Iter + ElemCells * Index; 60 | Status = DtIoParseProp (&DtDevice->DtIo, Prop, EFI_DT_VALUE_U32, 0, &DtType); 61 | if (EFI_ERROR (Status)) { 62 | goto Out; 63 | } 64 | 65 | Status = DtIoParseProp (&DtDevice->DtIo, Prop, EFI_DT_VALUE_U64, 0, &Attributes); 66 | if (EFI_ERROR (Status)) { 67 | goto Out; 68 | } 69 | 70 | switch (DtType) { 71 | case EfiDtIoRegTypeReserved: 72 | Type = EfiGcdMemoryTypeReserved; 73 | break; 74 | case EfiDtIoRegTypeSystemMemory: 75 | Type = EfiGcdMemoryTypeSystemMemory; 76 | break; 77 | case EfiDtIoRegTypeMemoryMappedIo: 78 | Type = EfiGcdMemoryTypeMemoryMappedIo; 79 | break; 80 | case EfiDtIoRegTypePersistent: 81 | Type = EfiGcdMemoryTypePersistent; 82 | break; 83 | case EfiDtIoRegTypeMoreReliable: 84 | Type = EfiGcdMemoryTypeMoreReliable; 85 | break; 86 | default: 87 | Status = EFI_INVALID_PARAMETER; 88 | goto Out; 89 | } 90 | 91 | Out: 92 | if (EFI_ERROR (Status)) { 93 | Prop->Iter = OriginalIter; 94 | } else { 95 | *GcdType = Type; 96 | *EfiMemoryAttributes = Attributes; 97 | } 98 | 99 | return Status; 100 | } 101 | 102 | /** 103 | Return the attributes for a reg or ranges property field. 104 | 105 | This looks at optional fdtbuspkg,reg-attrs/fdtbuspkg,range-attrs 106 | properties. If these are absent, EfiGcdMemoryTypeMemoryMappedIo 107 | and EFI_MEMORY_UC are reported. 108 | 109 | Corrupt properties are treated as errors. 110 | 111 | @param[in] DtDevice DtDevice for property lookup. 112 | @param[in] IsReg TRUE if reg, FALSE if ranges. 113 | @param[in] Index Index of the reg/range field to look up for. 114 | @param[out] GcdType Pointer to EFI_GCD_MEMORY_TYPE to populate. 115 | @param[out] EfiMemoryAttributes Pointer to UINT64 to populate. 116 | 117 | @retval EFI_SUCCESS Success. 118 | @retval Other Errors. 119 | 120 | **/ 121 | EFI_STATUS 122 | DtPropGetRegOrRangeEfiTypeAndAttrs ( 123 | IN DT_DEVICE *DtDevice, 124 | IN BOOLEAN IsReg, 125 | IN UINTN Index, 126 | OUT EFI_GCD_MEMORY_TYPE *GcdType, 127 | OUT UINT64 *EfiMemoryAttributes 128 | ) 129 | { 130 | EFI_STATUS Status; 131 | EFI_DT_PROPERTY Property; 132 | CONST CHAR8 *PropertyName; 133 | 134 | ASSERT (DtDevice != NULL); 135 | ASSERT (GcdType != NULL); 136 | ASSERT (EfiMemoryAttributes != NULL); 137 | 138 | if (IsReg) { 139 | PropertyName = "fdtbuspkg,reg-attrs"; 140 | } else { 141 | PropertyName = "fdtbuspkg,range-attrs"; 142 | } 143 | 144 | Status = DtIoGetProp (&DtDevice->DtIo, PropertyName, &Property); 145 | if (Status == EFI_NOT_FOUND) { 146 | *GcdType = EfiGcdMemoryTypeMemoryMappedIo; 147 | *EfiMemoryAttributes = EFI_MEMORY_UC; 148 | return EFI_SUCCESS; 149 | } else if (EFI_ERROR (Status)) { 150 | DEBUG (( 151 | DEBUG_ERROR, 152 | "%a: DtIoGetProp(%a): %r\n", 153 | __func__, 154 | PropertyName, 155 | Status 156 | )); 157 | return Status; 158 | } 159 | 160 | Status = DtPropParseEfiTypeAndAttrs ( 161 | DtDevice, 162 | &Property, 163 | Index, 164 | GcdType, 165 | EfiMemoryAttributes 166 | ); 167 | if (EFI_ERROR (Status)) { 168 | DEBUG (( 169 | DEBUG_ERROR, 170 | "%a: DtPropParseEfiTypeAndAttrs(%a, %lu): %r\n", 171 | __func__, 172 | PropertyName, 173 | Index, 174 | Status 175 | )); 176 | return Status; 177 | } 178 | 179 | return EFI_SUCCESS; 180 | } 181 | -------------------------------------------------------------------------------- /Drivers/FdtBusDxe/Fdt.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #include "FdtBusDxe.h" 10 | 11 | /** 12 | Given an FdtNode, return the device_type property or the empty string. 13 | 14 | @param[in] TreeBase Devicetree blob base 15 | @param[in] FdtNode INTN 16 | 17 | @retval CHAR8 * Device type or empty string. 18 | 19 | **/ 20 | CONST CHAR8 * 21 | FdtGetDeviceType ( 22 | IN VOID *TreeBase, 23 | IN INTN FdtNode 24 | ) 25 | { 26 | CONST CHAR8 *Buf; 27 | 28 | Buf = fdt_getprop (TreeBase, FdtNode, "device_type", NULL); 29 | if (Buf == NULL) { 30 | return ""; 31 | } 32 | 33 | return Buf; 34 | } 35 | 36 | /** 37 | Given an FdtNode, return the device status. 38 | 39 | @param[in] TreeBase Devicetree blob base 40 | @param[in] FdtNode INTN 41 | 42 | @retval EFI_DT_STATUS Enum. 43 | 44 | **/ 45 | EFI_DT_STATUS 46 | FdtGetStatus ( 47 | IN VOID *TreeBase, 48 | IN INTN FdtNode 49 | ) 50 | { 51 | CONST CHAR8 *Buf; 52 | 53 | Buf = fdt_getprop (TreeBase, FdtNode, "status", NULL); 54 | if (Buf == NULL) { 55 | return EFI_DT_STATUS_OKAY; 56 | } 57 | 58 | if (AsciiStrCmp (Buf, "okay") == 0) { 59 | return EFI_DT_STATUS_OKAY; 60 | } else if (AsciiStrCmp (Buf, "disabled") == 0) { 61 | return EFI_DT_STATUS_DISABLED; 62 | } else if (AsciiStrCmp (Buf, "reserved") == 0) { 63 | return EFI_DT_STATUS_RESERVED; 64 | } else if (AsciiStrCmp (Buf, "fail") == 0) { 65 | return EFI_DT_STATUS_FAIL; 66 | } else if (AsciiStrnCmp (Buf, "fail-", 5) == 0) { 67 | return EFI_DT_STATUS_FAIL_WITH_CONDITION; 68 | } 69 | 70 | return EFI_DT_STATUS_BROKEN; 71 | } 72 | 73 | /** 74 | Given an FdtNode, return the size cells in *Cells. 75 | 76 | @param[in] TreeBase Devicetree blob base 77 | @param[in] FdtNode INTN 78 | @param[out] Cells UINTN 79 | 80 | @retval EFI_SUCCESS *Out is populated. 81 | @retval Others Errors. 82 | 83 | **/ 84 | EFI_STATUS 85 | FdtGetSizeCells ( 86 | IN VOID *TreeBase, 87 | IN INTN FdtNode, 88 | OUT UINT8 *Cells 89 | ) 90 | { 91 | INT32 Len; 92 | UINT8 Value; 93 | CONST EFI_DT_CELL *Buf; 94 | 95 | Buf = fdt_getprop (TreeBase, FdtNode, "#size-cells", &Len); 96 | if (!Buf) { 97 | // 98 | // Default value in 2.3.5 #address-cells and #size-cells. 99 | // 100 | *Cells = 1; 101 | return EFI_SUCCESS; 102 | } 103 | 104 | if (Len != sizeof (EFI_DT_CELL)) { 105 | return EFI_DEVICE_ERROR; 106 | } 107 | 108 | Value = fdt32_to_cpu (*Buf); 109 | if (Value > FDT_MAX_NCELLS) { 110 | return EFI_DEVICE_ERROR; 111 | } 112 | 113 | *Cells = Value; 114 | return EFI_SUCCESS; 115 | } 116 | 117 | /** 118 | Given an FdtNode, return the address cells in *Cells. 119 | 120 | @param[in] TreeBase Devicetree blob base 121 | @param[in] FdtNode INTN 122 | @param[out] Cells UINTN 123 | 124 | @retval EFI_SUCCESS *Out is populated. 125 | @retval Others Errors. 126 | 127 | **/ 128 | EFI_STATUS 129 | FdtGetAddressCells ( 130 | IN VOID *TreeBase, 131 | IN INTN FdtNode, 132 | OUT UINT8 *Cells 133 | ) 134 | { 135 | INT32 Len; 136 | UINT8 Value; 137 | CONST EFI_DT_CELL *Buf; 138 | 139 | Buf = fdt_getprop (TreeBase, FdtNode, "#address-cells", &Len); 140 | if (!Buf) { 141 | // 142 | // Default value in 2.3.5 #address-cells and #size-cells. 143 | // 144 | *Cells = 2; 145 | return EFI_SUCCESS; 146 | } 147 | 148 | if (Len != sizeof (EFI_DT_CELL)) { 149 | return EFI_DEVICE_ERROR; 150 | } 151 | 152 | Value = fdt32_to_cpu (*Buf); 153 | if (Value > FDT_MAX_NCELLS) { 154 | return EFI_DEVICE_ERROR; 155 | } 156 | 157 | *Cells = Value; 158 | return EFI_SUCCESS; 159 | } 160 | 161 | /** 162 | Given an FdtNode, return whether this device is critical to platform 163 | operation (e.g. it must be connected before or during EndOfDxe event). 164 | 165 | @param[in] TreeBase Devicetree blob base 166 | @param[in] FdtNode INTN 167 | 168 | @retval TRUE Device is critical. 169 | @retval FALSE Device is not critical. 170 | 171 | **/ 172 | BOOLEAN 173 | FdtIsDeviceCritical ( 174 | IN VOID *TreeBase, 175 | IN INTN FdtNode 176 | ) 177 | { 178 | return fdt_getprop (TreeBase, FdtNode, "fdtbuspkg,critical", NULL) != NULL; 179 | } 180 | 181 | #ifndef MDEPKG_NDEBUG 182 | 183 | /** 184 | Given an FdtNode, return whether this device is a unit test device. 185 | 186 | @param[in] TreeBase Devicetree blob base 187 | @param[in] FdtNode INTN 188 | 189 | @retval TRUE Device is critical. 190 | @retval FALSE Device is not critical. 191 | 192 | **/ 193 | BOOLEAN 194 | FdtIsUnitTestDevice ( 195 | IN VOID *TreeBase, 196 | IN INTN FdtNode 197 | ) 198 | { 199 | return fdt_getprop (TreeBase, FdtNode, "fdtbuspkg,unit-test-device", NULL) != NULL; 200 | } 201 | 202 | #endif /* MDEPKG_NDEBUG */ 203 | -------------------------------------------------------------------------------- /Drivers/FdtBusDxe/FdtBusDxe.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010019 11 | BASE_NAME = FdtBusDxe 12 | FILE_GUID = E6727A5E-CBCD-44C8-B37F-78BC3A0C1234 13 | MODULE_TYPE = DXE_DRIVER 14 | VERSION_STRING = 1.0 15 | ENTRY_POINT = EntryPoint 16 | 17 | # 18 | # VALID_ARCHITECTURES = AARCH64 RISCV64 19 | # 20 | 21 | [Sources] 22 | ComponentName.c 23 | DriverBinding.c 24 | DtDevice.c 25 | DtIoProp.c 26 | DtIoPropParse.c 27 | DtProp.c 28 | DtIo.c 29 | DtIoDma.c 30 | Entry.c 31 | Fdt.c 32 | Utils.c 33 | Tests.c 34 | 35 | [Packages] 36 | MdeModulePkg/MdeModulePkg.dec 37 | FdtBusPkg/FdtBusPkg.dec 38 | EmbeddedPkg/EmbeddedPkg.dec 39 | MdePkg/MdePkg.dec 40 | 41 | [LibraryClasses] 42 | BaseLib 43 | BaseMemoryLib 44 | DebugLib 45 | UefiBootServicesTableLib 46 | DxeServicesTableLib 47 | UefiDriverEntryPoint 48 | FdtLib 49 | DevicePathLib 50 | TimerLib 51 | FbpUtilsLib 52 | FbpPlatformDtLib 53 | FbpInterruptUtilsLib 54 | 55 | [Protocols] 56 | gEfiDtIoProtocolGuid 57 | gEfiDevicePathProtocolGuid 58 | gEfiCpuIo2ProtocolGuid 59 | 60 | [Guids] 61 | gFdtTableGuid 62 | gEdkiiPlatformHasDeviceTreeGuid 63 | gEfiEndOfDxeEventGroupGuid 64 | 65 | [Depex] 66 | gEfiCpuIo2ProtocolGuid 67 | 68 | [BuildOptions] 69 | -------------------------------------------------------------------------------- /Drivers/FdtBusDxe/TestDt.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | aliases { 5 | alias-G2P0 = &l1; 6 | }; 7 | 8 | sample-bus { 9 | compatible = "fdtbuspkg,sample-bus"; 10 | #address-cells = <1>; 11 | #size-cells = <1>; 12 | 13 | sample-device@1337 { 14 | compatible = "fdtbuspkg,sample-device"; 15 | 16 | reg = < 0x1337 0x100 >; 17 | }; 18 | }; 19 | 20 | unit-test-devices { 21 | compatible = "simple-bus"; 22 | fdtbuspkg,unit-test-device; 23 | 24 | G0 { 25 | compatible = "test1_compatible"; 26 | }; 27 | G1 { 28 | device_type = "bar"; 29 | }; 30 | G2 { 31 | #address-cells = <4>; 32 | #size-cells = <3>; 33 | l1: G2P0 { 34 | reg = < 0x1 0x2 0x3 0x4 0x5 0x6 0x7 35 | 0x1 0xa 0x3 0xb 0x5 0xc 0x7 >; 36 | G2P0C1 { 37 | reg = < 0 0 0x4 >; 38 | }; 39 | }; 40 | G2P1 { 41 | #address-cells = <5>; 42 | #size-cells = <2>; 43 | }; 44 | G2p2 { 45 | #address-cells = <2>; 46 | #size-cells = <5>; 47 | }; 48 | }; 49 | G3 { 50 | G3P0 { 51 | status = "disabled"; 52 | }; 53 | G3P1 { 54 | status = "reserved"; 55 | }; 56 | G3P2 { 57 | status = "fail"; 58 | }; 59 | G3P3 { 60 | status = "fail-foo"; 61 | }; 62 | G3P4 { 63 | status = "okay"; 64 | }; 65 | G3P5 { 66 | status = "lkalksjdlkajsd"; 67 | }; 68 | }; 69 | G4 { 70 | #address-cells = <3>; 71 | #size-cells = <2>; 72 | ranges = < 0x1 0x2 0x3 0x5 0x6 0x7 0x8 73 | 0xa 0xb 0xc 0xd 0xe 0xf 0x1 >; 74 | }; 75 | G5 { 76 | #address-cells = <3>; 77 | #size-cells = <2>; 78 | G5P0 { 79 | }; 80 | G5P1 { 81 | }; 82 | G5P2 { 83 | }; 84 | G5P3 { 85 | }; 86 | }; 87 | G6 { 88 | string = "a string"; 89 | svals1 = "string1", "string2"; 90 | empty; 91 | svals2 = "", "", "1", ""; 92 | }; 93 | G7 { 94 | #address-cells = <2>; 95 | #size-cells = <2>; 96 | G7P0 { 97 | reg = < 0x1 0x00000002 0x3 0x00000004 >, 98 | < 0x5 0x00000006 0x7 0x00000008 >, 99 | < 0x9 0x0000000A 0xB 0x0000000C >, 100 | < 0xD 0x0000000E 0xF 0x00000011 >, 101 | < 0x12 0x00000013 0x14 0x00000015 >; 102 | reg-names = "apple", "banana", "orange", "grape", "peach"; 103 | }; 104 | }; 105 | Dma0 { 106 | Dma1 { 107 | dma-coherent; 108 | Dma2 { 109 | dma-ranges; 110 | }; 111 | Dma3 { 112 | dma-ranges = < 0x1 0x2 0x3 0x4 0x5 >; 113 | Dma4 { 114 | }; 115 | }; 116 | }; 117 | }; 118 | NodeToLookup: NodeToLookup { 119 | test = "NodeToLookup"; 120 | }; 121 | LookupTest { 122 | ref = < &NodeToLookup >; 123 | }; 124 | TestPic: TestPic { 125 | interrupt-controller; 126 | #address-cells = <0>; 127 | #interrupt-cells = <2>; 128 | test = "TestPic"; 129 | }; 130 | DevWithInterrupt { 131 | interrupt-parent = < &TestPic >; 132 | interrupts = < 2 8 >; 133 | }; 134 | InterruptNexus { 135 | #address-cells = <2>; 136 | #size-cells = <2>; 137 | #interrupt-cells = <1>; 138 | interrupt-map-mask = < 0 0 0xffffffff >; 139 | interrupt-map = < 140 | 0 0 0xf &TestPic 0xff 4 141 | 0 0 0x2 &TestPic 0x22 8 142 | 0 0 0xe &TestPic 0xee 2 143 | 2 144 | >; 145 | DevWithInterruptUnderNexus { 146 | reg = < 0xaaaabbbb 0xccccdddd 0 0 >; 147 | interrupts = < 2 0xe 0xf 0xd >; 148 | }; 149 | }; 150 | }; 151 | }; 152 | -------------------------------------------------------------------------------- /Drivers/FdtBusDxe/TestDt.sh: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Build the DTB for FdtBusDxe unit tests, and process it into a form 3 | # that can be consumed by the C compiler. 4 | # 5 | # Copyright (C) 2023, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX -License-Identifier: BSD-2-Clause-Patent 8 | # 9 | ## 10 | 11 | set -e 12 | 13 | basedir=$(dirname -- "$0") 14 | 15 | cleanup () { 16 | rm -f *.dtb 17 | } 18 | 19 | trap cleanup EXIT 20 | 21 | ( 22 | cd ${basedir} 23 | dtc -I dts -O dtb -o TestDt.dtb TestDt.dts 24 | xxd -i TestDt.dtb TestDt.dtbi 25 | rm TestDt.dtb 26 | unix2dos TestDt.dts 27 | unix2dos TestDt.dtbi 28 | ) 29 | -------------------------------------------------------------------------------- /Drivers/HighMemDxe/ComponentName.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | High memory node enumeration DXE driver for ARM and RISC-V. 3 | 4 | Copyright (c) 2023, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "HighMemDxe.h" 11 | 12 | STATIC 13 | EFI_STATUS 14 | EFIAPI 15 | ComponentNameGetDriverName ( 16 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 17 | IN CHAR8 *Language, 18 | OUT CHAR16 **DriverName 19 | ); 20 | 21 | STATIC 22 | EFI_STATUS 23 | EFIAPI 24 | ComponentNameGetControllerName ( 25 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 26 | IN EFI_HANDLE ControllerHandle, 27 | IN EFI_HANDLE ChildHandle, 28 | IN CHAR8 *Language, 29 | OUT CHAR16 **ControllerName 30 | ); 31 | 32 | // 33 | // EFI Component Name Protocol 34 | // 35 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gComponentName = { 36 | ComponentNameGetDriverName, 37 | ComponentNameGetControllerName, 38 | "eng" 39 | }; 40 | 41 | // 42 | // EFI Component Name 2 Protocol 43 | // 44 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = { 45 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)ComponentNameGetDriverName, 46 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)ComponentNameGetControllerName, 47 | "en" 48 | }; 49 | 50 | STATIC EFI_UNICODE_STRING_TABLE mDriverName[] = { 51 | { 52 | "eng;en", 53 | (CHAR16 *)L"High Memory Enumeration Driver" 54 | }, 55 | { 56 | NULL, 57 | NULL 58 | } 59 | }; 60 | 61 | STATIC EFI_UNICODE_STRING_TABLE mDeviceName[] = { 62 | { 63 | "eng;en", 64 | (CHAR16 *)L"Memory Device" 65 | }, 66 | { 67 | NULL, 68 | NULL 69 | } 70 | }; 71 | 72 | /** 73 | Retrieves a Unicode string that is the user readable name of the driver. 74 | 75 | This function retrieves the user readable name of a driver in the form of a 76 | Unicode string. If the driver specified by This has a user readable name in 77 | the language specified by Language, then a pointer to the driver name is 78 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 79 | by This does not support the language specified by Language, 80 | then EFI_UNSUPPORTED is returned. 81 | 82 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 83 | EFI_COMPONENT_NAME_PROTOCOL instance. 84 | 85 | @param Language[in] A pointer to a Null-terminated ASCII string 86 | array indicating the language. This is the 87 | language of the driver name that the caller is 88 | requesting, and it must match one of the 89 | languages specified in SupportedLanguages. The 90 | number of languages supported by a driver is up 91 | to the driver writer. Language is specified 92 | in RFC 4646 or ISO 639-2 language code format. 93 | 94 | @param DriverName[out] A pointer to the Unicode string to return. 95 | This Unicode string is the name of the 96 | driver specified by This in the language 97 | specified by Language. 98 | 99 | @retval EFI_SUCCESS The Unicode string for the Driver specified by 100 | This and the language specified by Language was 101 | returned in DriverName. 102 | 103 | @retval EFI_INVALID_PARAMETER Language is NULL. 104 | 105 | @retval EFI_INVALID_PARAMETER DriverName is NULL. 106 | 107 | @retval EFI_UNSUPPORTED The driver specified by This does not support 108 | the language specified by Language. 109 | 110 | **/ 111 | STATIC 112 | EFI_STATUS 113 | EFIAPI 114 | ComponentNameGetDriverName ( 115 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 116 | IN CHAR8 *Language, 117 | OUT CHAR16 **DriverName 118 | ) 119 | { 120 | return LookupUnicodeString2 ( 121 | Language, 122 | This->SupportedLanguages, 123 | mDriverName, 124 | DriverName, 125 | (BOOLEAN)(This == &gComponentName) 126 | ); 127 | } 128 | 129 | /** 130 | Retrieves a Unicode string that is the user readable name of the controller 131 | that is being managed by a driver. 132 | 133 | This function retrieves the user readable name of the controller specified by 134 | ControllerHandle and ChildHandle in the form of a Unicode string. If the 135 | driver specified by This has a user readable name in the language specified by 136 | Language, then a pointer to the controller name is returned in ControllerName, 137 | and EFI_SUCCESS is returned. If the driver specified by This is not currently 138 | managing the controller specified by ControllerHandle and ChildHandle, 139 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not 140 | support the language specified by Language, then EFI_UNSUPPORTED is returned. 141 | 142 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 143 | EFI_COMPONENT_NAME_PROTOCOL instance. 144 | 145 | @param ControllerHandle[in] The handle of a controller that the driver 146 | specified by This is managing. This handle 147 | specifies the controller whose name is to be 148 | returned. 149 | 150 | @param ChildHandle[in] The handle of the child controller to retrieve 151 | the name of. This is an optional parameter that 152 | may be NULL. It will be NULL for device 153 | drivers. It will also be NULL for a bus drivers 154 | that wish to retrieve the name of the bus 155 | controller. It will not be NULL for a bus 156 | driver that wishes to retrieve the name of a 157 | child controller. 158 | 159 | @param Language[in] A pointer to a Null-terminated ASCII string 160 | array indicating the language. This is the 161 | language of the driver name that the caller is 162 | requesting, and it must match one of the 163 | languages specified in SupportedLanguages. The 164 | number of languages supported by a driver is up 165 | to the driver writer. Language is specified in 166 | RFC 4646 or ISO 639-2 language code format. 167 | 168 | @param ControllerName[out] A pointer to the Unicode string to return. 169 | This Unicode string is the name of the 170 | controller specified by ControllerHandle and 171 | ChildHandle in the language specified by 172 | Language from the point of view of the driver 173 | specified by This. 174 | 175 | @retval EFI_SUCCESS The Unicode string for the user readable name in 176 | the language specified by Language for the 177 | driver specified by This was returned in 178 | DriverName. 179 | 180 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 181 | 182 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 183 | EFI_HANDLE. 184 | 185 | @retval EFI_INVALID_PARAMETER Language is NULL. 186 | 187 | @retval EFI_INVALID_PARAMETER ControllerName is NULL. 188 | 189 | @retval EFI_UNSUPPORTED The driver specified by This is not currently 190 | managing the controller specified by 191 | ControllerHandle and ChildHandle. 192 | 193 | @retval EFI_UNSUPPORTED The driver specified by This does not support 194 | the language specified by Language. 195 | 196 | **/ 197 | STATIC 198 | EFI_STATUS 199 | EFIAPI 200 | ComponentNameGetControllerName ( 201 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 202 | IN EFI_HANDLE ControllerHandle, 203 | IN EFI_HANDLE ChildHandle, 204 | IN CHAR8 *Language, 205 | OUT CHAR16 **ControllerName 206 | ) 207 | { 208 | EFI_STATUS Status; 209 | 210 | // 211 | // Make sure this driver is currently managing ControllerHandle 212 | // 213 | Status = EfiTestManagedDevice ( 214 | ControllerHandle, 215 | gDriverBinding.DriverBindingHandle, 216 | &gEfiDtIoProtocolGuid 217 | ); 218 | if (EFI_ERROR (Status)) { 219 | return Status; 220 | } 221 | 222 | if (ChildHandle != NULL) { 223 | return EFI_UNSUPPORTED; 224 | } 225 | 226 | return LookupUnicodeString2 ( 227 | Language, 228 | This->SupportedLanguages, 229 | mDeviceName, 230 | ControllerName, 231 | (BOOLEAN)(This == &gComponentName) 232 | ); 233 | } 234 | -------------------------------------------------------------------------------- /Drivers/HighMemDxe/HighMemDxe.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | High memory node enumeration DXE driver for ARM and RISC-V. 3 | 4 | Copyright (c) 2015-2016, Linaro Ltd. All rights reserved. 5 | Copyright (c) 2023, Intel Corporation. All rights reserved.
6 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent 8 | 9 | **/ 10 | 11 | #ifndef __HIGH_MEM_DXE_H__ 12 | #define __HIGH_MEM_DXE_H__ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | extern EFI_COMPONENT_NAME_PROTOCOL gComponentName; 27 | extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2; 28 | extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding; 29 | 30 | EFI_STATUS 31 | DeviceIsSupported ( 32 | IN EFI_DT_IO_PROTOCOL *DtIo 33 | ); 34 | 35 | EFI_STATUS 36 | ProcessMemoryRanges ( 37 | IN EFI_DT_IO_PROTOCOL *DtIo 38 | ); 39 | 40 | #endif /* __HIGH_MEM_DXE_H__ */ 41 | -------------------------------------------------------------------------------- /Drivers/HighMemDxe/HighMemDxe.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # High memory node enumeration DXE driver for ARM and RISC-V. 3 | # 4 | # Copyright (c) 2015-2016, Linaro Ltd. All rights reserved. 5 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent 8 | # 9 | ## 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010005 13 | BASE_NAME = HighMemDxe 14 | FILE_GUID = 63EA1463-FBFA-428A-B97F-E222755852D7 15 | MODULE_TYPE = DXE_DRIVER 16 | VERSION_STRING = 1.0 17 | 18 | ENTRY_POINT = InitializeHighMemDxe 19 | 20 | [Sources] 21 | HighMemDxe.c 22 | ComponentName.c 23 | DriverBinding.c 24 | 25 | [Packages] 26 | EmbeddedPkg/EmbeddedPkg.dec 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | FdtBusPkg/FdtBusPkg.dec 30 | 31 | [LibraryClasses] 32 | UefiLib 33 | DebugLib 34 | PcdLib 35 | UefiBootServicesTableLib 36 | UefiDriverEntryPoint 37 | FbpUtilsLib 38 | 39 | [Protocols] 40 | gEfiCpuArchProtocolGuid ## CONSUMES 41 | gEfiDtIoProtocolGuid ## CONSUMES 42 | 43 | [Pcd] 44 | gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy 45 | 46 | [Depex] 47 | gEfiCpuArchProtocolGuid 48 | -------------------------------------------------------------------------------- /Drivers/HighMemDxe/HighMemDxeNoBinding.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # High memory node enumeration DXE driver for ARM and RISC-V. 3 | # 4 | # Copyright (c) 2015-2016, Linaro Ltd. All rights reserved. 5 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent 8 | # 9 | ## 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010005 13 | BASE_NAME = HighMemDxeNoBinding 14 | FILE_GUID = 2E6D0598-1085-4F74-BC4D-23D2C6600C26 15 | MODULE_TYPE = DXE_DRIVER 16 | VERSION_STRING = 1.0 17 | 18 | ENTRY_POINT = InitializeHighMemDxe 19 | 20 | [Sources] 21 | HighMemDxe.c 22 | 23 | [Packages] 24 | MdePkg/MdePkg.dec 25 | MdeModulePkg/MdeModulePkg.dec 26 | FdtBusPkg/FdtBusPkg.dec 27 | 28 | [LibraryClasses] 29 | BaseLib 30 | DebugLib 31 | DxeServicesTableLib 32 | PcdLib 33 | UefiBootServicesTableLib 34 | UefiDriverEntryPoint 35 | 36 | [Protocols] 37 | gEfiCpuArchProtocolGuid ## CONSUMES 38 | gEfiDtIoProtocolGuid ## CONSUMES 39 | 40 | [Pcd] 41 | gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy 42 | 43 | [Depex] 44 | gEfiCpuArchProtocolGuid AND gEfiDtIoProtocolGuid 45 | 46 | [BuildOptions] 47 | MSFT:*_*_*_CC_FLAGS = /DDT_NON_DRIVER_BINDING 48 | GCC:*_*_*_CC_FLAGS = -DDT_NON_DRIVER_BINDING 49 | 50 | -------------------------------------------------------------------------------- /Drivers/PciHostBridgeFdtDxe/Driver.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | DT-based PCI(e) host bridge driver. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "Driver.h" 11 | 12 | /** 13 | The entry point for the driver. 14 | 15 | @param[in] ImageHandle The firmware allocated handle for the EFI image. 16 | @param[in] SystemTable A pointer to the EFI System Table. 17 | 18 | @retval EFI_SUCCESS The entry point is executed successfully. 19 | @retval other Some error occurs when executing this entry point. 20 | 21 | **/ 22 | EFI_STATUS 23 | EFIAPI 24 | EntryPoint ( 25 | IN EFI_HANDLE ImageHandle, 26 | IN EFI_SYSTEM_TABLE *SystemTable 27 | ) 28 | { 29 | EFI_STATUS Status; 30 | 31 | Status = EfiLibInstallDriverBindingComponentName2 ( 32 | ImageHandle, 33 | SystemTable, 34 | &gDriverBinding, 35 | ImageHandle, 36 | &gComponentName, 37 | &gComponentName2 38 | ); 39 | if (EFI_ERROR (Status)) { 40 | DEBUG ((DEBUG_ERROR, "%a: EfiLibInstallDriverBindingComponentName2: %r\n", __func__, Status)); 41 | return Status; 42 | } 43 | 44 | return EFI_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /Drivers/PciHostBridgeFdtDxe/Driver.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | DT-based PCI(e) host bridge driver. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #ifndef __DRIVER_H__ 11 | #define __DRIVER_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | extern EFI_COMPONENT_NAME_PROTOCOL gComponentName; 34 | extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2; 35 | extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding; 36 | 37 | // 38 | // Macros to translate device address to host address and vice versa. According 39 | // to UEFI 2.7, device address = host address + translation offset. 40 | // 41 | #define TO_HOST_ADDRESS(DeviceAddress, TranslationOffset) ((DeviceAddress) - (TranslationOffset)) 42 | #define TO_DEVICE_ADDRESS(HostAddress, TranslationOffset) ((HostAddress) + (TranslationOffset)) 43 | 44 | // 45 | // According to UEFI 2.7, Device Address = Host Address + Translation, 46 | // so Translation = Device Address - Host Address. 47 | // On platforms where Translation is not zero, the subtraction is probably to 48 | // be performed with UINT64 wrap-around semantics, for we may translate an 49 | // above-4G host address into a below-4G device address for legacy PCIe device 50 | // compatibility. 51 | // 52 | // NOTE: The alignment of Translation is required to be larger than any BAR 53 | // alignment in the same root bridge, so that the same alignment can be 54 | // applied to both device address and host address, which simplifies the 55 | // situation and makes the current resource allocation code in generic PCI 56 | // host bridge driver still work. 57 | // 58 | #define RT(Range) ((UINT64)((Range).ChildBase - (Range).TranslatedParentBase)) 59 | #define RB(Range) ((UINT64)((Range).ChildBase)) 60 | #define RS(Range) ((UINT64)((Range).Length)) 61 | #define RL(Range) ((UINT64)((Range).ChildBase + (Range).Length - 1)) 62 | #define RANGE_VALID(Range) ((Range).Length != 0) 63 | 64 | #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('d', 't', 'r', 'b') 65 | 66 | #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE) 67 | 68 | #define PCI_RESOURCE_LESS 0xFFFFFFFFFFFFFFFEULL 69 | 70 | typedef enum { 71 | TypeIo = 0, 72 | TypeMem32, 73 | TypePMem32, 74 | TypeMem64, 75 | TypePMem64, 76 | TypeBus, 77 | TypeMax 78 | } PCI_RESOURCE_TYPE; 79 | 80 | typedef enum { 81 | ResNone, 82 | ResSubmitted, 83 | ResAllocated, 84 | ResStatusMax 85 | } RES_STATUS; 86 | 87 | typedef struct { 88 | EFI_PHYSICAL_ADDRESS Base; 89 | UINT64 Length; 90 | UINT64 Alignment; 91 | RES_STATUS Status; 92 | BOOLEAN ResTracked; 93 | } PCI_RES_NODE; 94 | 95 | typedef struct _PCI_ROOT_BRIDGE_INSTANCE PCI_ROOT_BRIDGE_INSTANCE; 96 | 97 | struct _PCI_ROOT_BRIDGE_INSTANCE { 98 | UINT32 Signature; 99 | EFI_HANDLE Controller; 100 | EFI_DT_IO_PROTOCOL *DtIo; 101 | CHAR16 *DevicePathStr; 102 | VOID *ConfigBuffer; 103 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo; 104 | 105 | UINT32 Segment; 106 | EFI_DT_REG ConfigReg; 107 | UINT64 Attributes; 108 | UINT64 Supports; 109 | PCI_RES_NODE ResAllocNode[TypeMax]; 110 | EFI_DT_RANGE BusRange; 111 | EFI_DT_RANGE IoRange; 112 | EFI_DT_RANGE MemRange; 113 | EFI_DT_RANGE PMemRange; 114 | EFI_DT_RANGE MemAbove4GRange; 115 | EFI_DT_RANGE PMemAbove4GRange; 116 | EFI_DT_RANGE VgaMemRange; 117 | EFI_DT_RANGE VgaIo1Range; 118 | EFI_DT_RANGE VgaIo2Range; 119 | BOOLEAN DmaAbove4G; 120 | BOOLEAN NoExtendedConfigSpace; 121 | BOOLEAN KeepExistingConfig; 122 | // 123 | // Manipulated by HostBridge.c. 124 | // 125 | BOOLEAN ResourceSubmitted; 126 | BOOLEAN CanRestart; 127 | UINT64 AllocationAttributes; 128 | EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL ResAlloc; 129 | }; 130 | 131 | #define PCI_ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE) 132 | 133 | #define PCI_ROOT_BRIDGE_FROM_RES_ALLOC(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, ResAlloc, PCI_ROOT_BRIDGE_SIGNATURE) 134 | 135 | VOID 136 | HostBridgeInit ( 137 | IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge 138 | ); 139 | 140 | EFI_STATUS 141 | HostBridgeKeepExistingConfig ( 142 | IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge 143 | ); 144 | 145 | EFI_STATUS 146 | HostBridgeFreeExistingConfig ( 147 | IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge 148 | ); 149 | 150 | EFI_STATUS 151 | RootBridgeCreate ( 152 | IN EFI_DT_IO_PROTOCOL *DtIo, 153 | IN EFI_HANDLE Controller, 154 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 155 | OUT PCI_ROOT_BRIDGE_INSTANCE **RootBridge 156 | ); 157 | 158 | VOID 159 | RootBridgeFree ( 160 | IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge 161 | ); 162 | 163 | UINT64 164 | GetTranslationByResourceType ( 165 | IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge, 166 | IN PCI_RESOURCE_TYPE ResourceType 167 | ); 168 | 169 | #endif /* __DRIVER_H__ */ 170 | -------------------------------------------------------------------------------- /Drivers/PciHostBridgeFdtDxe/Driver.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # DT-based PCI(e) host bridge driver. 3 | # 4 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | # 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent 7 | # 8 | ## 9 | 10 | [Defines] 11 | INF_VERSION = 0x00010005 12 | BASE_NAME = PciHostBridgeFdtDxe 13 | FILE_GUID = 63EA1463-FBFA-428A-B97F-E262744651C2 14 | MODULE_TYPE = UEFI_DRIVER 15 | VERSION_STRING = 1.0 16 | 17 | ENTRY_POINT = EntryPoint 18 | 19 | [Sources] 20 | Driver.c 21 | ComponentName.c 22 | DriverBinding.c 23 | HostBridge.c 24 | RootBridge.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | FdtBusPkg/FdtBusPkg.dec 30 | 31 | [LibraryClasses] 32 | DebugLib 33 | MemoryAllocationLib 34 | UefiBootServicesTableLib 35 | DxeServicesTableLib 36 | UefiDriverEntryPoint 37 | DevicePathLib 38 | BaseMemoryLib 39 | FbpUtilsLib 40 | FbpPciUtilsLib 41 | UefiLib 42 | PcdLib 43 | 44 | [Guids] 45 | gEfiDtDevicePathGuid 46 | 47 | [Protocols] 48 | gEfiDtIoProtocolGuid ## CONSUMES 49 | gEfiPciHostBridgeResourceAllocationProtocolGuid ## PRODUCES 50 | gEfiPciRootBridgeIoProtocolGuid ## PRODUCES 51 | gEfiPciEnumerationCompleteProtocolGuid ## CONSUMES 52 | 53 | [Pcd] 54 | gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation ## PRODUCES 55 | gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## PRODUCES 56 | gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## PRODUCES 57 | 58 | [Depex] 59 | -------------------------------------------------------------------------------- /Drivers/PciSioSerialDxe/PciSioSerialDxe.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # SIO/PCI/FDT 16550 UART driver. 3 | # 4 | # Copyright (c) 2007 - 2024, Intel Corporation. All rights reserved.
5 | # 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent 7 | # 8 | ## 9 | 10 | [Defines] 11 | INF_VERSION = 0x00010005 12 | BASE_NAME = PciSioSerialDxe 13 | MODULE_UNI_FILE = PciSioSerialDxe.uni 14 | FILE_GUID = E2775B47-D453-4EE3-ADA7-391A1B05AC17 15 | MODULE_TYPE = UEFI_DRIVER 16 | VERSION_STRING = 1.0 17 | ENTRY_POINT = InitializePciSioSerial 18 | 19 | # 20 | # The following information is for reference only and not required by the build tools. 21 | # 22 | # VALID_ARCHITECTURES = IA32 X64 EBC 23 | # 24 | # DRIVER_BINDING = gSerialControllerDriver 25 | # COMPONENT_NAME = gPciSioSerialComponentName 26 | # COMPONENT_NAME2 = gPciSioSerialComponentName2 27 | # 28 | 29 | [Sources] 30 | ComponentName.c 31 | SerialIo.c 32 | Serial.h 33 | Serial.c 34 | 35 | [Packages] 36 | MdePkg/MdePkg.dec 37 | MdeModulePkg/MdeModulePkg.dec 38 | FdtBusPkg/FdtBusPkg.dec 39 | 40 | [LibraryClasses] 41 | PcdLib 42 | ReportStatusCodeLib 43 | UefiBootServicesTableLib 44 | MemoryAllocationLib 45 | BaseMemoryLib 46 | DevicePathLib 47 | UefiLib 48 | UefiDriverEntryPoint 49 | DebugLib 50 | IoLib 51 | 52 | [Guids] 53 | gEfiUartDevicePathGuid ## SOMETIMES_CONSUMES ## GUID 54 | 55 | [Protocols] 56 | gEfiSioProtocolGuid ## TO_START 57 | gEfiDevicePathProtocolGuid ## TO_START 58 | gEfiPciIoProtocolGuid ## TO_START 59 | gEfiSerialIoProtocolGuid ## BY_START 60 | gEfiDevicePathProtocolGuid ## BY_START 61 | gEfiDtIoProtocolGuid ## TO_START 62 | 63 | [FeaturePcd] 64 | gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHalfHandshake|FALSE ## CONSUMES 65 | 66 | [Pcd] 67 | gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 ## CONSUMES 68 | gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits|8 ## CONSUMES 69 | gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity|1 ## CONSUMES 70 | gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits|1 ## CONSUMES 71 | gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1843200 ## CONSUMES 72 | gEfiMdeModulePkgTokenSpaceGuid.PcdPciSerialParameters ## CONSUMES 73 | 74 | [UserExtensions.TianoCore."ExtraFiles"] 75 | PciSioSerialDxeExtra.uni 76 | -------------------------------------------------------------------------------- /Drivers/PciSioSerialDxe/PciSioSerialDxe.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // SIO/PCI/FDT 16550 UART driver. 3 | // 4 | // Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
5 | // 6 | // SPDX-License-Identifier: BSD-2-Clause-Patent 7 | // 8 | // **/ 9 | 10 | #string STR_MODULE_ABSTRACT #language en-US "SIO/PCI/FDT 16550 UART Driver" 11 | 12 | #string STR_MODULE_DESCRIPTION #language en-US "SIO/PCI/FDT 16550 UART Driver" 13 | -------------------------------------------------------------------------------- /Drivers/PciSioSerialDxe/PciSioSerialDxeExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // SIO/PCI/FDT 16550 UART driver. 3 | // 4 | // Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
5 | // 6 | // SPDX-License-Identifier: BSD-2-Clause-Patent 7 | // 8 | // **/ 9 | 10 | #string STR_PROPERTIES_MODULE_NAME 11 | #language en-US 12 | "SIO/PCI/FDT 16550 UART Driver" 13 | -------------------------------------------------------------------------------- /Drivers/SampleBusDxe/Driver.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Sample DT controller device driver code. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "Driver.h" 11 | 12 | /** 13 | The entry point for the driver. 14 | 15 | @param[in] ImageHandle The firmware allocated handle for the EFI image. 16 | @param[in] SystemTable A pointer to the EFI System Table. 17 | 18 | @retval EFI_SUCCESS The entry point is executed successfully. 19 | @retval other Some error occurs when executing this entry point. 20 | 21 | **/ 22 | EFI_STATUS 23 | EFIAPI 24 | EntryPoint ( 25 | IN EFI_HANDLE ImageHandle, 26 | IN EFI_SYSTEM_TABLE *SystemTable 27 | ) 28 | { 29 | EFI_STATUS Status; 30 | 31 | Status = EfiLibInstallDriverBindingComponentName2 ( 32 | ImageHandle, 33 | SystemTable, 34 | &gDriverBinding, 35 | ImageHandle, 36 | &gComponentName, 37 | &gComponentName2 38 | ); 39 | if (EFI_ERROR (Status)) { 40 | DEBUG ((DEBUG_ERROR, "%a: EfiLibInstallDriverBindingComponentName2: %r\n", __func__, Status)); 41 | return Status; 42 | } 43 | 44 | return EFI_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /Drivers/SampleBusDxe/Driver.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | Sample DT controller device driver code. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #ifndef __DRIVER_H__ 11 | #define __DRIVER_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | extern EFI_COMPONENT_NAME_PROTOCOL gComponentName; 24 | extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2; 25 | extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding; 26 | 27 | #endif /* __DRIVER_H__ */ 28 | -------------------------------------------------------------------------------- /Drivers/SampleBusDxe/Driver.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Sample DT controller device driver code. 3 | # 4 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | # 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent 7 | # 8 | ## 9 | 10 | [Defines] 11 | INF_VERSION = 0x00010005 12 | BASE_NAME = SampleBusDxe 13 | FILE_GUID = 63EA1463-FBFA-428A-B97F-E262755651C6 14 | MODULE_TYPE = UEFI_DRIVER 15 | VERSION_STRING = 1.0 16 | 17 | ENTRY_POINT = EntryPoint 18 | 19 | [Sources] 20 | Driver.c 21 | ComponentName.c 22 | DriverBinding.c 23 | 24 | [Packages] 25 | MdePkg/MdePkg.dec 26 | MdeModulePkg/MdeModulePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | 29 | [LibraryClasses] 30 | DebugLib 31 | UefiBootServicesTableLib 32 | UefiDriverEntryPoint 33 | DevicePathLib 34 | BaseMemoryLib 35 | FbpUtilsLib 36 | UefiLib 37 | 38 | [Guids] 39 | gEfiDtDevicePathGuid 40 | 41 | [Protocols] 42 | gEfiDtIoProtocolGuid ## CONSUMES 43 | 44 | [Pcd] 45 | 46 | [Depex] 47 | -------------------------------------------------------------------------------- /Drivers/SampleDeviceDxe/ComponentName.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Sample DT controller device driver code. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "Driver.h" 11 | 12 | STATIC 13 | EFI_STATUS 14 | EFIAPI 15 | ComponentNameGetDriverName ( 16 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 17 | IN CHAR8 *Language, 18 | OUT CHAR16 **DriverName 19 | ); 20 | 21 | STATIC 22 | EFI_STATUS 23 | EFIAPI 24 | ComponentNameGetControllerName ( 25 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 26 | IN EFI_HANDLE ControllerHandle, 27 | IN EFI_HANDLE ChildHandle, 28 | IN CHAR8 *Language, 29 | OUT CHAR16 **ControllerName 30 | ); 31 | 32 | // 33 | // EFI Component Name Protocol 34 | // 35 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gComponentName = { 36 | ComponentNameGetDriverName, 37 | ComponentNameGetControllerName, 38 | "eng" 39 | }; 40 | 41 | // 42 | // EFI Component Name 2 Protocol 43 | // 44 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = { 45 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)ComponentNameGetDriverName, 46 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)ComponentNameGetControllerName, 47 | "en" 48 | }; 49 | 50 | STATIC EFI_UNICODE_STRING_TABLE mDriverName[] = { 51 | { 52 | "eng;en", 53 | (CHAR16 *)L"Sample Device Driver" 54 | }, 55 | { 56 | NULL, 57 | NULL 58 | } 59 | }; 60 | 61 | STATIC EFI_UNICODE_STRING_TABLE mDeviceName[] = { 62 | { 63 | "eng;en", 64 | (CHAR16 *)L"Sample Device" 65 | }, 66 | { 67 | NULL, 68 | NULL 69 | } 70 | }; 71 | 72 | /** 73 | Retrieves a Unicode string that is the user readable name of the driver. 74 | 75 | This function retrieves the user readable name of a driver in the form of a 76 | Unicode string. If the driver specified by This has a user readable name in 77 | the language specified by Language, then a pointer to the driver name is 78 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 79 | by This does not support the language specified by Language, 80 | then EFI_UNSUPPORTED is returned. 81 | 82 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 83 | EFI_COMPONENT_NAME_PROTOCOL instance. 84 | 85 | @param Language[in] A pointer to a Null-terminated ASCII string 86 | array indicating the language. This is the 87 | language of the driver name that the caller is 88 | requesting, and it must match one of the 89 | languages specified in SupportedLanguages. The 90 | number of languages supported by a driver is up 91 | to the driver writer. Language is specified 92 | in RFC 4646 or ISO 639-2 language code format. 93 | 94 | @param DriverName[out] A pointer to the Unicode string to return. 95 | This Unicode string is the name of the 96 | driver specified by This in the language 97 | specified by Language. 98 | 99 | @retval EFI_SUCCESS The Unicode string for the Driver specified by 100 | This and the language specified by Language was 101 | returned in DriverName. 102 | 103 | @retval EFI_INVALID_PARAMETER Language is NULL. 104 | 105 | @retval EFI_INVALID_PARAMETER DriverName is NULL. 106 | 107 | @retval EFI_UNSUPPORTED The driver specified by This does not support 108 | the language specified by Language. 109 | 110 | **/ 111 | STATIC 112 | EFI_STATUS 113 | EFIAPI 114 | ComponentNameGetDriverName ( 115 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 116 | IN CHAR8 *Language, 117 | OUT CHAR16 **DriverName 118 | ) 119 | { 120 | return LookupUnicodeString2 ( 121 | Language, 122 | This->SupportedLanguages, 123 | mDriverName, 124 | DriverName, 125 | (BOOLEAN)(This == &gComponentName) 126 | ); 127 | } 128 | 129 | /** 130 | Retrieves a Unicode string that is the user readable name of the controller 131 | that is being managed by a driver. 132 | 133 | This function retrieves the user readable name of the controller specified by 134 | ControllerHandle and ChildHandle in the form of a Unicode string. If the 135 | driver specified by This has a user readable name in the language specified by 136 | Language, then a pointer to the controller name is returned in ControllerName, 137 | and EFI_SUCCESS is returned. If the driver specified by This is not currently 138 | managing the controller specified by ControllerHandle and ChildHandle, 139 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not 140 | support the language specified by Language, then EFI_UNSUPPORTED is returned. 141 | 142 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 143 | EFI_COMPONENT_NAME_PROTOCOL instance. 144 | 145 | @param ControllerHandle[in] The handle of a controller that the driver 146 | specified by This is managing. This handle 147 | specifies the controller whose name is to be 148 | returned. 149 | 150 | @param ChildHandle[in] The handle of the child controller to retrieve 151 | the name of. This is an optional parameter that 152 | may be NULL. It will be NULL for device 153 | drivers. It will also be NULL for a bus drivers 154 | that wish to retrieve the name of the bus 155 | controller. It will not be NULL for a bus 156 | driver that wishes to retrieve the name of a 157 | child controller. 158 | 159 | @param Language[in] A pointer to a Null-terminated ASCII string 160 | array indicating the language. This is the 161 | language of the driver name that the caller is 162 | requesting, and it must match one of the 163 | languages specified in SupportedLanguages. The 164 | number of languages supported by a driver is up 165 | to the driver writer. Language is specified in 166 | RFC 4646 or ISO 639-2 language code format. 167 | 168 | @param ControllerName[out] A pointer to the Unicode string to return. 169 | This Unicode string is the name of the 170 | controller specified by ControllerHandle and 171 | ChildHandle in the language specified by 172 | Language from the point of view of the driver 173 | specified by This. 174 | 175 | @retval EFI_SUCCESS The Unicode string for the user readable name in 176 | the language specified by Language for the 177 | driver specified by This was returned in 178 | DriverName. 179 | 180 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 181 | 182 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 183 | EFI_HANDLE. 184 | 185 | @retval EFI_INVALID_PARAMETER Language is NULL. 186 | 187 | @retval EFI_INVALID_PARAMETER ControllerName is NULL. 188 | 189 | @retval EFI_UNSUPPORTED The driver specified by This is not currently 190 | managing the controller specified by 191 | ControllerHandle and ChildHandle. 192 | 193 | @retval EFI_UNSUPPORTED The driver specified by This does not support 194 | the language specified by Language. 195 | 196 | **/ 197 | STATIC 198 | EFI_STATUS 199 | EFIAPI 200 | ComponentNameGetControllerName ( 201 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 202 | IN EFI_HANDLE ControllerHandle, 203 | IN EFI_HANDLE ChildHandle, 204 | IN CHAR8 *Language, 205 | OUT CHAR16 **ControllerName 206 | ) 207 | { 208 | EFI_STATUS Status; 209 | 210 | // 211 | // Make sure this driver is currently managing ControllerHandle 212 | // 213 | Status = EfiTestManagedDevice ( 214 | ControllerHandle, 215 | gDriverBinding.DriverBindingHandle, 216 | &gEfiDtIoProtocolGuid 217 | ); 218 | if (EFI_ERROR (Status)) { 219 | return Status; 220 | } 221 | 222 | if (ChildHandle != NULL) { 223 | return EFI_UNSUPPORTED; 224 | } 225 | 226 | return LookupUnicodeString2 ( 227 | Language, 228 | This->SupportedLanguages, 229 | mDeviceName, 230 | ControllerName, 231 | (BOOLEAN)(This == &gComponentName) 232 | ); 233 | } 234 | -------------------------------------------------------------------------------- /Drivers/SampleDeviceDxe/Driver.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Sample DT controller device driver code. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "Driver.h" 11 | 12 | /** 13 | The entry point for the driver. 14 | 15 | @param[in] ImageHandle The firmware allocated handle for the EFI image. 16 | @param[in] SystemTable A pointer to the EFI System Table. 17 | 18 | @retval EFI_SUCCESS The entry point is executed successfully. 19 | @retval other Some error occurs when executing this entry point. 20 | 21 | **/ 22 | EFI_STATUS 23 | EFIAPI 24 | EntryPoint ( 25 | IN EFI_HANDLE ImageHandle, 26 | IN EFI_SYSTEM_TABLE *SystemTable 27 | ) 28 | { 29 | EFI_STATUS Status; 30 | 31 | Status = EfiLibInstallDriverBindingComponentName2 ( 32 | ImageHandle, 33 | SystemTable, 34 | &gDriverBinding, 35 | ImageHandle, 36 | &gComponentName, 37 | &gComponentName2 38 | ); 39 | if (EFI_ERROR (Status)) { 40 | DEBUG ((DEBUG_ERROR, "%a: EfiLibInstallDriverBindingComponentName2: %r\n", __func__, Status)); 41 | return Status; 42 | } 43 | 44 | return EFI_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /Drivers/SampleDeviceDxe/Driver.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | Sample DT controller device driver code. 3 | 4 | Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #ifndef __DRIVER_H__ 11 | #define __DRIVER_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | extern EFI_COMPONENT_NAME_PROTOCOL gComponentName; 21 | extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2; 22 | extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding; 23 | 24 | #endif /* __DRIVER_H__ */ 25 | -------------------------------------------------------------------------------- /Drivers/SampleDeviceDxe/Driver.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Sample DT controller device driver code. 3 | # 4 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
5 | # 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent 7 | # 8 | ## 9 | 10 | [Defines] 11 | INF_VERSION = 0x00010005 12 | BASE_NAME = SampleDeviceDxe 13 | FILE_GUID = 63EA1463-FBFA-428A-B97F-E222755851C5 14 | MODULE_TYPE = UEFI_DRIVER 15 | VERSION_STRING = 1.0 16 | 17 | ENTRY_POINT = EntryPoint 18 | 19 | [Sources] 20 | Driver.c 21 | ComponentName.c 22 | DriverBinding.c 23 | 24 | [Packages] 25 | MdePkg/MdePkg.dec 26 | MdeModulePkg/MdeModulePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | 29 | [LibraryClasses] 30 | DebugLib 31 | UefiBootServicesTableLib 32 | UefiDriverEntryPoint 33 | UefiLib 34 | 35 | [Protocols] 36 | gEfiDtIoProtocolGuid ## CONSUMES 37 | 38 | [Pcd] 39 | 40 | [Depex] 41 | -------------------------------------------------------------------------------- /Drivers/VirtNorFlashDxe/VirtNorFlashDxe.inf: -------------------------------------------------------------------------------- 1 | #/** @file 2 | # NOR Flash Driver for the cfi-flash DT node. 3 | # 4 | # Copyright (c) 2011 - 2021, ARM Ltd. All rights reserved.
5 | # Copyright (c) 2020, Linaro, Ltd. All rights reserved.
6 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
7 | # 8 | # SPDX-License-Identifier: BSD-2-Clause-Patent 9 | # 10 | #**/ 11 | 12 | [Defines] 13 | INF_VERSION = 1.29 14 | BASE_NAME = VirtNorFlashDxe 15 | FILE_GUID = e452cabd-5fe1-4d97-8161-e80ed6a409a8 16 | MODULE_TYPE = DXE_RUNTIME_DRIVER 17 | VERSION_STRING = 1.0 18 | ENTRY_POINT = NorFlashInitialise 19 | 20 | [Sources.common] 21 | ComponentName.c 22 | DriverBinding.c 23 | VirtNorFlash.c 24 | VirtNorFlash.h 25 | VirtNorFlashDxe.c 26 | VirtNorFlashFvb.c 27 | 28 | [Packages] 29 | EmbeddedPkg/EmbeddedPkg.dec 30 | MdePkg/MdePkg.dec 31 | MdeModulePkg/MdeModulePkg.dec 32 | OvmfPkg/OvmfPkg.dec 33 | FdtBusPkg/FdtBusPkg.dec 34 | 35 | [LibraryClasses] 36 | IoLib 37 | HobLib 38 | BaseLib 39 | UefiLib 40 | DebugLib 41 | FbpUtilsLib 42 | BaseMemoryLib 43 | UefiRuntimeLib 44 | MemoryAllocationLib 45 | DxeServicesTableLib 46 | UefiDriverEntryPoint 47 | UefiBootServicesTableLib 48 | 49 | [Guids] 50 | gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL 51 | gEfiAuthenticatedVariableGuid 52 | gEfiEventVirtualAddressChangeGuid 53 | gEfiSystemNvDataFvGuid 54 | gEfiVariableGuid 55 | 56 | [Protocols] 57 | gEfiBlockIoProtocolGuid 58 | gEfiDevicePathProtocolGuid 59 | gEfiDiskIoProtocolGuid 60 | gEfiFirmwareVolumeBlockProtocolGuid 61 | 62 | [Pcd.common] 63 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 64 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase 65 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize 66 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 67 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase 68 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize 69 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 70 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase 71 | gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize 72 | 73 | [Depex] 74 | gEfiCpuArchProtocolGuid 75 | 76 | [Pcd] 77 | gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress 78 | gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize 79 | -------------------------------------------------------------------------------- /Drivers/VirtioFdtDxe/VirtioFdtDxe.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Virtio FDT client protocol driver for virtio,mmio DT node. 3 | 4 | Copyright (c) 2023, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #include "VirtioFdtDxe.h" 11 | 12 | /** 13 | The Entry Point for VirtioFdtDxe driver. 14 | 15 | @param[in] ImageHandle The firmware allocated handle for the EFI image. 16 | @param[in] SystemTable A pointer to the EFI System Table. 17 | 18 | @retval EFI_SUCCESS The entry point is executed successfully. 19 | @retval other Some error occurs when executing this entry point. 20 | 21 | **/ 22 | EFI_STATUS 23 | EFIAPI 24 | InitializeVirtioFdtDxe ( 25 | IN EFI_HANDLE ImageHandle, 26 | IN EFI_SYSTEM_TABLE *SystemTable 27 | ) 28 | { 29 | return EfiLibInstallDriverBindingComponentName2 ( 30 | ImageHandle, 31 | SystemTable, 32 | &gDriverBinding, 33 | ImageHandle, 34 | &gComponentName, 35 | &gComponentName2 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /Drivers/VirtioFdtDxe/VirtioFdtDxe.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | Virtio FDT client protocol driver for virtio,mmio DT node. 3 | 4 | Copyright (c) 2023, Intel Corporation. All rights reserved.
5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #ifndef __VIRTIO_FDT_DXE_H__ 11 | #define __VIRTIO_FDT_DXE_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | extern EFI_COMPONENT_NAME_PROTOCOL gComponentName; 28 | extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2; 29 | extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding; 30 | 31 | #pragma pack (1) 32 | typedef struct { 33 | VENDOR_DEVICE_PATH Vendor; 34 | UINT64 PhysBase; 35 | } VIRTIO_TRANSPORT_DEVICE_PATH_NODE; 36 | #pragma pack () 37 | 38 | #endif /* __VIRTIO_FDT_DXE_H__ */ 39 | -------------------------------------------------------------------------------- /Drivers/VirtioFdtDxe/VirtioFdtDxe.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Virtio FDT client protocol driver for virtio,mmio DT node. 3 | # 4 | # Copyright (c) 2014 - 2016, Linaro Ltd. All rights reserved.
5 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent 8 | # 9 | ## 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010005 13 | BASE_NAME = VirtioFdtDxe 14 | FILE_GUID = 0049858F-8CA7-4CCD-918B-D952CBF32975 15 | MODULE_TYPE = DXE_DRIVER 16 | VERSION_STRING = 1.0 17 | 18 | ENTRY_POINT = InitializeVirtioFdtDxe 19 | 20 | [Sources] 21 | ComponentName.c 22 | DriverBinding.c 23 | VirtioFdtDxe.c 24 | 25 | [Packages] 26 | EmbeddedPkg/EmbeddedPkg.dec 27 | MdePkg/MdePkg.dec 28 | OvmfPkg/OvmfPkg.dec 29 | FdtBusPkg/FdtBusPkg.dec 30 | 31 | [LibraryClasses] 32 | BaseLib 33 | BaseMemoryLib 34 | DebugLib 35 | UefiLib 36 | DevicePathLib 37 | MemoryAllocationLib 38 | UefiBootServicesTableLib 39 | UefiDriverEntryPoint 40 | VirtioMmioDeviceLib 41 | FbpUtilsLib 42 | 43 | [Guids] 44 | gVirtioMmioTransportGuid 45 | 46 | [Protocols] 47 | gEfiDevicePathProtocolGuid ## PRODUCES 48 | gEfiDtIoProtocolGuid ## CONSUMES 49 | 50 | [Depex] 51 | TRUE 52 | 53 | -------------------------------------------------------------------------------- /FdtBusPkg.dec: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023-2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | DEC_SPECIFICATION = 0x00010005 11 | PACKAGE_NAME = FdtBusPkg 12 | PACKAGE_GUID = 1E73767F-8F52-4603-AEB4-F29B510B9999 13 | PACKAGE_VERSION = 1.00 14 | 15 | [Includes] 16 | Include 17 | 18 | [Protocols] 19 | ## Include/Protocol/DtIo.h 20 | gEfiDtIoProtocolGuid = { 0x5ce5a2b0, 0x2838, 0x3c35, {0x1e, 0xe3, 0x42, 0x5e, 0x36, 0x50, 0xa2, 0x9b }} 21 | ## Include/Protoco/DtInterrupt.h 22 | gEfiDtInterruptProtocolGuid = { 0x5ce5a2b0, 0x2838, 0x3c35, {0x1e, 0xe3, 0x42, 0x5e, 0x36, 0x50, 0xa3, 0x9c }} 23 | 24 | [Guids] 25 | gEfiDtDevicePathGuid = { 0x5ce5a2b0, 0x2838, 0x3c35, {0x1e, 0xe3, 0x42, 0x5e, 0x36, 0x50, 0xa2, 0x9c }} 26 | 27 | [PcdsFixedAtBuild, PcdsPatchableInModule] 28 | 29 | -------------------------------------------------------------------------------- /FdtBusPkg.dsc: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | PLATFORM_NAME = FdtBusPkg 11 | PLATFORM_GUID = 62ad1d2c-3333-4021-b32d-268d0e71c032 12 | PLATFORM_VERSION = 0.98 13 | DSC_SPECIFICATION = 0x00010005 14 | OUTPUT_DIRECTORY = Build/FdtBusPkg 15 | SUPPORTED_ARCHITECTURES = AARCH64|RISCV64 16 | BUILD_TARGETS = DEBUG|RELEASE|NOOPT 17 | SKUID_IDENTIFIER = DEFAULT 18 | PREBUILD = sh FdtBusPkg/Drivers/FdtBusDxe/TestDt.sh 19 | 20 | !include MdePkg/MdeLibs.dsc.inc 21 | 22 | [PcdsFixedAtBuild.common] 23 | # DEBUG_ASSERT_ENABLED 0x01 24 | # DEBUG_PRINT_ENABLED 0x02 25 | # DEBUG_CODE_ENABLED 0x04 26 | # CLEAR_MEMORY_ENABLED 0x08 27 | # ASSERT_BREAKPOINT_ENABLED 0x10 28 | # ASSERT_DEADLOOP_ENABLED 0x20 29 | !if $(TARGET) == RELEASE 30 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x23 31 | !else 32 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f 33 | !endif 34 | 35 | # DEBUG_INIT 0x00000001 // Initialization 36 | # DEBUG_WARN 0x00000002 // Warnings 37 | # DEBUG_LOAD 0x00000004 // Load events 38 | # DEBUG_FS 0x00000008 // EFI File system 39 | # DEBUG_POOL 0x00000010 // Alloc & Free (pool) 40 | # DEBUG_PAGE 0x00000020 // Alloc & Free (page) 41 | # DEBUG_INFO 0x00000040 // Informational debug messages 42 | # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers 43 | # DEBUG_VARIABLE 0x00000100 // Variable 44 | # DEBUG_BM 0x00000400 // Boot Manager 45 | # DEBUG_BLKIO 0x00001000 // BlkIo Driver 46 | # DEBUG_NET 0x00004000 // SNP Driver 47 | # DEBUG_UNDI 0x00010000 // UNDI Driver 48 | # DEBUG_LOADFILE 0x00020000 // LoadFile 49 | # DEBUG_EVENT 0x00080000 // Event messages 50 | # DEBUG_GCD 0x00100000 // Global Coherency Database changes 51 | # DEBUG_CACHE 0x00200000 // Memory range cachability changes 52 | # DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may 53 | # // significantly impact boot performance 54 | # DEBUG_ERROR 0x80000000 // Error 55 | !if $(TARGET) == RELEASE 56 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000 57 | !else 58 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F 59 | !endif 60 | 61 | [PcdsDynamicDefault] 62 | # 63 | # These 3 are here only to compile FdtPciPcdProducerLib. 64 | # 65 | gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xffffffffffffffff 66 | gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE 67 | gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation|0x0 68 | 69 | [LibraryClasses.common] 70 | DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf 71 | # DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf 72 | # DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf 73 | # SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf 74 | 75 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 76 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 77 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 78 | BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 79 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 80 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 81 | UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 82 | NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf 83 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 84 | FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf 85 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 86 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 87 | DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf 88 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 89 | FbpUtilsLib|FdtBusPkg/Library/FbpUtilsLib/FbpUtilsLib.inf 90 | FbpPciUtilsLib|FdtBusPkg/Library/FbpPciUtilsLib/FbpPciUtilsLib.inf 91 | FbpInterruptUtilsLib|FdtBusPkg/Library/FbpInterruptUtilsLib/FbpInterruptUtilsLib.inf 92 | DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf 93 | 94 | [LibraryClasses.AARCH64] 95 | NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf 96 | TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf 97 | ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf 98 | ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf 99 | 100 | [LibraryClasses.RISCV64] 101 | TimerLib|UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf 102 | 103 | [Components] 104 | FdtBusPkg/Library/PciHostBridgeLibEcam/PciHostBridgeLibEcam.inf 105 | FdtBusPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf 106 | 107 | FdtBusPkg/Drivers/SampleDeviceDxe/Driver.inf 108 | FdtBusPkg/Drivers/SampleBusDxe/Driver.inf 109 | FdtBusPkg/Drivers/PciHostBridgeFdtDxe/Driver.inf 110 | FdtBusPkg/Drivers/FdtBusDxe/FdtBusDxe.inf { 111 | 112 | FbpPlatformDtLib|FdtBusPkg/Library/FbpPlatformDtLib/FbpPlatformDtLib.inf 113 | } 114 | FdtBusPkg/Drivers/VirtioFdtDxe/VirtioFdtDxe.inf { 115 | 116 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 117 | VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf 118 | VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf 119 | } 120 | FdtBusPkg/Drivers/HighMemDxe/HighMemDxe.inf { 121 | 122 | DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf 123 | } 124 | FdtBusPkg/Drivers/HighMemDxe/HighMemDxeNoBinding.inf { 125 | 126 | DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf 127 | } 128 | FdtBusPkg/Drivers/PciSioSerialDxe/PciSioSerialDxe.inf { 129 | 130 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 131 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 132 | } 133 | -------------------------------------------------------------------------------- /FdtBusPkgApps.dsc: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023-2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | PLATFORM_NAME = FdtBusPkgApps 11 | PLATFORM_GUID = 62ad1d2c-3333-4021-b32d-268d0e71c032 12 | PLATFORM_VERSION = 0.98 13 | DSC_SPECIFICATION = 0x00010005 14 | OUTPUT_DIRECTORY = Build/FdtBusPkg 15 | SUPPORTED_ARCHITECTURES = AARCH64|RISCV64 16 | BUILD_TARGETS = DEBUG|RELEASE|NOOPT 17 | SKUID_IDENTIFIER = DEFAULT 18 | 19 | !include MdePkg/MdeLibs.dsc.inc 20 | 21 | [PcdsFixedAtBuild.common] 22 | # DEBUG_ASSERT_ENABLED 0x01 23 | # DEBUG_PRINT_ENABLED 0x02 24 | # DEBUG_CODE_ENABLED 0x04 25 | # CLEAR_MEMORY_ENABLED 0x08 26 | # ASSERT_BREAKPOINT_ENABLED 0x10 27 | # ASSERT_DEADLOOP_ENABLED 0x20 28 | !if $(TARGET) == RELEASE 29 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x23 30 | !else 31 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f 32 | !endif 33 | 34 | # DEBUG_INIT 0x00000001 // Initialization 35 | # DEBUG_WARN 0x00000002 // Warnings 36 | # DEBUG_LOAD 0x00000004 // Load events 37 | # DEBUG_FS 0x00000008 // EFI File system 38 | # DEBUG_POOL 0x00000010 // Alloc & Free (pool) 39 | # DEBUG_PAGE 0x00000020 // Alloc & Free (page) 40 | # DEBUG_INFO 0x00000040 // Informational debug messages 41 | # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers 42 | # DEBUG_VARIABLE 0x00000100 // Variable 43 | # DEBUG_BM 0x00000400 // Boot Manager 44 | # DEBUG_BLKIO 0x00001000 // BlkIo Driver 45 | # DEBUG_NET 0x00004000 // SNP Driver 46 | # DEBUG_UNDI 0x00010000 // UNDI Driver 47 | # DEBUG_LOADFILE 0x00020000 // LoadFile 48 | # DEBUG_EVENT 0x00080000 // Event messages 49 | # DEBUG_GCD 0x00100000 // Global Coherency Database changes 50 | # DEBUG_CACHE 0x00200000 // Memory range cachability changes 51 | # DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may 52 | # // significantly impact boot performance 53 | # DEBUG_ERROR 0x80000000 // Error 54 | !if $(TARGET) == RELEASE 55 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000 56 | !else 57 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F 58 | !endif 59 | 60 | [LibraryClasses.common] 61 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 62 | BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 63 | NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf 64 | # 65 | # Even on RELEASE. You want to see the logging. 66 | # 67 | DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf 68 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 69 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 70 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 71 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 72 | UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf 73 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 74 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 75 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 76 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 77 | FbpUtilsLib|FdtBusPkg/Library/FbpUtilsLib/FbpUtilsLib.inf 78 | FbpAppUtilsLib|FdtBusPkg/Library/FbpAppUtilsLib/FbpAppUtilsLib.inf 79 | HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf 80 | FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf 81 | HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf 82 | SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf 83 | PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf 84 | UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf 85 | DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf 86 | 87 | [LibraryClasses.AARCH64] 88 | NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf 89 | 90 | [BuildOptions] 91 | 92 | [Components] 93 | FdtBusPkg/Application/DtInfo/DtInfo.inf 94 | FdtBusPkg/Application/DtProp/DtProp.inf 95 | FdtBusPkg/Application/DtReg/DtReg.inf 96 | FdtBusPkg/Application/PciInfo/PciInfo.inf 97 | -------------------------------------------------------------------------------- /Include/Library/FbpAppUtilsLib.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | Copyright (C) 2017 Andrei Evgenievich Warkentin 5 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent 7 | 8 | **/ 9 | 10 | #ifndef __FBP_APP_UTILS_LIB_H__ 11 | #define __FBP_APP_UTILS_LIB_H__ 12 | 13 | #include 14 | #include 15 | 16 | typedef struct GET_OPT_CONTEXT { 17 | CHAR16 Opt; 18 | CHAR16 *OptArg; 19 | UINTN OptIndex; 20 | } GET_OPT_CONTEXT; 21 | 22 | #define INIT_GET_OPT_CONTEXT(ContextPointer) do {\ 23 | (ContextPointer)->Opt = L'\0'; \ 24 | (ContextPointer)->OptArg = NULL; \ 25 | (ContextPointer)->OptIndex = 1; \ 26 | } while (0) 27 | 28 | EFI_STATUS 29 | GetOpt ( 30 | IN UINTN Argc, 31 | IN CHAR16 **Argv, 32 | IN CHAR16 *OptionsWithArgs, 33 | IN OUT GET_OPT_CONTEXT *Context 34 | ); 35 | 36 | EFI_STATUS 37 | GetShellArgcArgv ( 38 | IN EFI_HANDLE ImageHandle, 39 | OUT UINTN *Argcp, 40 | OUT CHAR16 ***Argvp 41 | ); 42 | 43 | CHAR8 * 44 | UnicodeStrDupToAsciiStr ( 45 | CONST CHAR16 *String 46 | ); 47 | 48 | EFI_STATUS 49 | FbpAppLookup ( 50 | IN CONST CHAR16 *String, 51 | OUT EFI_DT_IO_PROTOCOL **OutDtIo, 52 | OUT EFI_HANDLE *OutHandle OPTIONAL 53 | ); 54 | 55 | VOID 56 | PrintDtU128 ( 57 | IN EFI_DT_U128 Value, 58 | IN BOOLEAN NewLine 59 | ); 60 | 61 | VOID 62 | PrintDtReg ( 63 | IN EFI_DT_REG *Reg, 64 | IN BOOLEAN NewLine 65 | ); 66 | 67 | VOID 68 | PrintDtRange ( 69 | IN EFI_DT_RANGE *Range, 70 | IN BOOLEAN NewLine 71 | ); 72 | 73 | UINTN 74 | StrHexOrDecToUintn ( 75 | IN CONST CHAR16 *String 76 | ); 77 | 78 | #endif /* __FBP_APP_UTILS_LIB_H__ */ 79 | -------------------------------------------------------------------------------- /Include/Library/FbpInterruptUtilsLib.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #ifndef __FBP_INTERRUPT_UTILS_LIB_H__ 10 | #define __FBP_INTERRUPT_UTILS_LIB_H__ 11 | 12 | #include 13 | #include 14 | 15 | // 16 | // See Power ISA Open PIC Interrupt Controller in the Devicetree Specification. 17 | // 18 | #define EFI_DT_INTERRUPT_EDGE_HIGH 0 19 | #define EFI_DT_INTERRUPT_LEVEL_LOW 1 20 | #define EFI_DT_INTERRUPT_LEVEL_HIGH 2 21 | #define EFI_DT_INTERRUPT_EDGE_LOW 3 22 | 23 | EFI_STATUS 24 | FbpInterruptGet ( 25 | IN EFI_DT_IO_PROTOCOL *This, 26 | IN UINTN Index, 27 | OUT EFI_HANDLE *InterruptParent, 28 | OUT EFI_DT_PROPERTY *Interrupt 29 | ); 30 | 31 | #endif /* __FBP_INTERRUPT_UTILS_LIB_H__ */ 32 | -------------------------------------------------------------------------------- /Include/Library/FbpPciUtilsLib.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #ifndef __FBP_PCI_UTILS_LIB_H__ 10 | #define __FBP_PCI_UTILS_LIB_H__ 11 | 12 | #include 13 | #include 14 | 15 | // 16 | // See 2.2.1. Physical Address Formats in 17 | // IEEE Std 1275-1994. 18 | // 19 | #define EFI_DT_PCI_HOST_RANGE_RELOCATABLE BIT31 20 | #define EFI_DT_PCI_HOST_RANGE_PREFETCHABLE BIT30 21 | #define EFI_DT_PCI_HOST_RANGE_ALIASED BIT29 22 | #define EFI_DT_PCI_HOST_RANGE_SS_MASK (BIT24|BIT25) 23 | #define EFI_DT_PCI_HOST_RANGE_MMIO64 (BIT24|BIT25) 24 | #define EFI_DT_PCI_HOST_RANGE_MMIO32 BIT25 25 | #define EFI_DT_PCI_HOST_RANGE_IO BIT24 26 | 27 | EFI_DT_CELL 28 | FbpPciGetRangeAttribute ( 29 | IN EFI_DT_IO_PROTOCOL *This, 30 | IN EFI_DT_BUS_ADDRESS ChildBase 31 | ); 32 | 33 | #endif /* __FBP_PCI_UTILS_LIB_H__ */ 34 | -------------------------------------------------------------------------------- /Include/Library/FbpPlatformDtLib.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #ifndef __FBP_PLATFORM_DT_LIB_H__ 10 | #define __FBP_PLATFORM_DT_LIB_H__ 11 | 12 | VOID * 13 | FbpPlatformGetDt ( 14 | VOID 15 | ); 16 | 17 | #endif /* __FBP_PLATFORM_DT_LIB_H__ */ 18 | -------------------------------------------------------------------------------- /Include/Library/FbpUtilsLib.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #ifndef __FBP_UTILS_LIB_H__ 10 | #define __FBP_UTILS_LIB_H__ 11 | 12 | #include 13 | #include 14 | 15 | // 16 | // The name associated with the root DT controller, which 17 | // corresponds to '/' in the Devicetree. Because a DEBUG 18 | // build has a second tree used for unit testing, there 19 | // are real names assigned for these. 20 | // 21 | #define FBP_DT_ROOT_NAME "DtRoot" 22 | #define FBP_DT_TEST_ROOT_NAME "DtTestRoot" 23 | 24 | EFI_DT_IO_PROTOCOL * 25 | FbpGetDtRoot ( 26 | VOID 27 | ); 28 | 29 | EFI_DT_IO_PROTOCOL * 30 | FbpGetDtTestRoot ( 31 | VOID 32 | ); 33 | 34 | EFI_DT_DEVICE_PATH_NODE * 35 | FbpPathNodeCreate ( 36 | IN CONST CHAR8 *Name 37 | ); 38 | 39 | /** 40 | Convert an EFI_DT_RANGE to an EFI_DT_REG. 41 | 42 | If the EFI_DT_REG is going to be use with 43 | ChildBase address offsets, pass the appropriate 44 | ChildSideOffset to be subtracted. Note - this 45 | function *cannot* just blindly subtract 46 | ChildBase, as it could be more than an offset 47 | (e.g. for PCI it encodes type info as well). 48 | 49 | Useful in a bus driver to do I/O on behalf of a child. 50 | 51 | @param[in] Range EFI_DT_RANGE *. 52 | @param[in] ChildSideOFfset EFI_DT_SIZE. 53 | @param[out] Reg EFI_DT_REG *. 54 | 55 | **/ 56 | STATIC 57 | inline 58 | VOID 59 | FbpRangeToReg ( 60 | IN CONST EFI_DT_RANGE *Range, 61 | IN EFI_DT_SIZE ChildSideOffset, 62 | OUT EFI_DT_REG *Reg 63 | ) 64 | { 65 | Reg->BusBase = Range->ParentBase - ChildSideOffset; 66 | Reg->TranslatedBase = Range->TranslatedParentBase - ChildSideOffset; 67 | Reg->Length = Range->Length + ChildSideOffset; 68 | Reg->BusDtIo = Range->BusDtIo; 69 | } 70 | 71 | /** 72 | Return the EFI_PHYSICAL_ADDRESS corresponding to an EFI_DT_REG, 73 | if one exists. 74 | 75 | @param[in] Reg EFI_DT_REG *. 76 | @param[out] Address EFI_PHYSICAL_ADDRESS *. 77 | 78 | @retval EFI_STATUS EFI_SUCCESS or error. 79 | 80 | **/ 81 | STATIC 82 | inline 83 | EFI_STATUS 84 | FbpRegToPhysicalAddress ( 85 | IN CONST EFI_DT_REG *Reg, 86 | OUT EFI_PHYSICAL_ADDRESS *Address OPTIONAL 87 | ) 88 | { 89 | if (Reg->BusDtIo != NULL) { 90 | return EFI_UNSUPPORTED; 91 | } 92 | 93 | if (Address != NULL) { 94 | *Address = Reg->TranslatedBase; 95 | } 96 | 97 | return EFI_SUCCESS; 98 | } 99 | 100 | /** 101 | Return the EFI_PHYSICAL_ADDRESS corresponding to an EFI_DT_RANGE, 102 | if one exists. 103 | 104 | @param[in] Range EFI_DuT_RANGE *. 105 | @param[out] Address EFI_PHYSICAL_ADDRESS *. 106 | 107 | @retval EFI_STATUS EFI_SUCCESS or error. 108 | 109 | **/ 110 | STATIC 111 | inline 112 | EFI_STATUS 113 | FbpRangeToPhysicalAddress ( 114 | IN CONST EFI_DT_RANGE *Range, 115 | OUT EFI_PHYSICAL_ADDRESS *Address OPTIONAL 116 | ) 117 | { 118 | if (Range->BusDtIo != NULL) { 119 | return EFI_UNSUPPORTED; 120 | } 121 | 122 | if (Address != NULL) { 123 | *Address = Range->TranslatedParentBase; 124 | } 125 | 126 | return EFI_SUCCESS; 127 | } 128 | 129 | BOOLEAN 130 | FbpHandleHasBoundDriver ( 131 | IN EFI_HANDLE Handle, 132 | IN UINT32 ExtraAttributeChecks, 133 | OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *MatchingEntry OPTIONAL 134 | ); 135 | 136 | EFI_STATUS 137 | FbpBusComponentName ( 138 | IN EFI_HANDLE ControllerHandle, 139 | IN EFI_HANDLE ChildHandle, 140 | IN CHAR8 *Language, 141 | OUT CHAR16 **ControllerName 142 | ); 143 | 144 | BOOLEAN 145 | FbpPropertyCompare ( 146 | IN EFI_DT_PROPERTY *What, 147 | IN EFI_DT_PROPERTY *Against, 148 | IN UINTN Cells, 149 | IN EFI_DT_PROPERTY *Mask 150 | ); 151 | 152 | VOID 153 | FbpPropertyFreeDeepCopy ( 154 | IN EFI_DT_PROPERTY *Property 155 | ); 156 | 157 | EFI_STATUS 158 | FbpPropertyDeepCopy ( 159 | IN EFI_DT_PROPERTY *PropertyToCopy, 160 | OUT EFI_DT_PROPERTY *New 161 | ); 162 | 163 | #endif /* __FBP_UTILS_LIB_H__ */ 164 | -------------------------------------------------------------------------------- /Include/Protocol/DtInterrupt.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | EFI Devicetree Interrupt Protocol provides a mechanism to register 3 | interrupt handlers, and is implemented by interrupt controller 4 | drivers. 5 | 6 | Copyright (c) 2024, Intel Corporation. All rights reserved.
7 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent 9 | 10 | **/ 11 | 12 | #ifndef __DT_INTERRUPT_H__ 13 | #define __DT_INTERRUPT_H__ 14 | 15 | #include 16 | #include 17 | 18 | #define EFI_DT_INTERRUPT_PROTOCOL_GUID \ 19 | { \ 20 | 0x5ce5a2b0, 0x2838, 0x3c35, {0x1e, 0xe3, 0x42, 0x5e, 0x36, 0x50, 0xa3, 0x9c } \ 21 | } 22 | 23 | typedef struct _EFI_DT_INTERRUPT_PROTOCOL EFI_DT_INTERRUPT_PROTOCOL; 24 | typedef VOID *EFI_DT_INTERRUPT_COOKIE; 25 | 26 | /** 27 | C Interrupt Handler called in the interrupt context when Cookie interrupt is active. 28 | 29 | @param Cookie Identifies the interrupt registered. 30 | @param CookieContext Additional context passed during registration. 31 | @param SystemContext Pointer to system register context. Mostly used by debuggers and will 32 | update the system context after the return from the interrupt if 33 | modified. Don't change these values unless you know what you are doing. 34 | 35 | **/ 36 | typedef 37 | VOID 38 | (EFIAPI *EFI_DT_INTERRUPT_HANDLER)( 39 | IN EFI_DT_INTERRUPT_COOKIE Cookie, 40 | IN VOID *CookieContext, 41 | IN EFI_SYSTEM_CONTEXT SystemContext 42 | ); 43 | 44 | /** 45 | Register Handler for the specified interrupt source. 46 | 47 | InterruptData->Iter is only modified on success. 48 | 49 | @param This Instance pointer for this protocol. 50 | @param InterruptData Interrupt specifier. 51 | @param Handler Callback for interrupt. 52 | @param CookieContext Additional context to pass to Handler. 53 | @param Cookie A unique value used for further operations on a registered interrupt. 54 | 55 | @retval EFI_SUCCESS Interrupt handler registered, *Cookie set, InterruptData->Iter updated. 56 | @retval EFI_UNSUPPORTED Configuration not supported. 57 | @retval EFI_INVALID_PARAMETER Bad parameter. 58 | @retval EFI_DEVICE_ERROR Hardware could not be programmed. 59 | 60 | **/ 61 | typedef 62 | EFI_STATUS 63 | (EFIAPI *EFI_DT_INTERRUPT_REGISTER)( 64 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 65 | IN EFI_DT_PROPERTY *InterruptData, 66 | IN EFI_DT_INTERRUPT_HANDLER Handler, 67 | IN VOID *CookieContext, 68 | OUT EFI_DT_INTERRUPT_COOKIE *Cookie 69 | ); 70 | 71 | /** 72 | Unregister handler for an interrupt. 73 | 74 | @param This Instance pointer for this protocol. 75 | @param Cookie As provided by EFI_DT_INTERRUPT_REGISTER callback. 76 | 77 | @retval EFI_SUCCESS Interrupt unregistered. 78 | @retval EFI_INVALID_PARAMETER Bad parameter. 79 | @retval EFI_DEVICE_ERROR Hardware could not be programmed. 80 | 81 | **/ 82 | typedef 83 | EFI_STATUS 84 | (EFIAPI *EFI_DT_INTERRUPT_UNREGISTER)( 85 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 86 | IN EFI_DT_INTERRUPT_COOKIE Cookie 87 | ); 88 | 89 | /** 90 | Enable interrupt. 91 | 92 | @param This Instance pointer for this protocol. 93 | @param Cookie As provided by EFI_DT_INTERRUPT_REGISTER callback. 94 | 95 | @retval EFI_SUCCESS Interrupt enabled. 96 | @retval EFI_UNSUPPORTED Configuration not supported. 97 | @retval EFI_INVALID_PARAMETER Bad parameter. 98 | @retval EFI_DEVICE_ERROR Hardware could not be programmed. 99 | 100 | **/ 101 | typedef 102 | EFI_STATUS 103 | (EFIAPI *EFI_DT_INTERRUPT_ENABLE)( 104 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 105 | IN EFI_DT_INTERRUPT_COOKIE Cookie 106 | ); 107 | 108 | /** 109 | Disable interrupt. 110 | 111 | @param This Instance pointer for this protocol 112 | @param Cookie As provided by EFI_DT_INTERRUPT_REGISTER callback. 113 | 114 | @retval EFI_SUCCESS Interrupt disabled. 115 | @retval EFI_UNSUPPORTED Configuration not supported. 116 | @retval EFI_INVALID_PARAMETER Bad parameter. 117 | @retval EFI_DEVICE_ERROR Hardware could not be programmed. 118 | 119 | **/ 120 | typedef 121 | EFI_STATUS 122 | (EFIAPI *EFI_DT_INTERRUPT_DISABLE)( 123 | IN EFI_DT_INTERRUPT_PROTOCOL *This, 124 | IN EFI_DT_INTERRUPT_COOKIE Cookie 125 | ); 126 | 127 | struct _EFI_DT_INTERRUPT_PROTOCOL { 128 | EFI_DT_INTERRUPT_REGISTER RegisterInterrupt; 129 | EFI_DT_INTERRUPT_UNREGISTER UnregisterInterrupt; 130 | EFI_DT_INTERRUPT_ENABLE EnableInterrupt; 131 | EFI_DT_INTERRUPT_DISABLE DisableInterrupt; 132 | }; 133 | 134 | extern EFI_GUID gEfiDtInterruptProtocolGuid; 135 | 136 | #endif /* __DT_INTERRUPT_H__ */ 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023-2024, Intel Corporation and contributors. All rights reserved. 2 | 3 | SPDX-License-Identifier: BSD-2-Clause-Patent 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | Subject to the terms and conditions of this license, each copyright holder 16 | and contributor hereby grants to those receiving rights under this license 17 | a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable 18 | (except for failure to satisfy the conditions of this license) patent 19 | license to make, have made, use, offer to sell, sell, import, and otherwise 20 | transfer this software, where such license applies only to those patent 21 | claims, already acquired or hereafter acquired, licensable by such copyright 22 | holder or contributor that are necessarily infringed by: 23 | 24 | (a) their Contribution(s) (the licensed copyrights of copyright holders and 25 | non-copyrightable additions of contributors, in source or binary form) 26 | alone; or 27 | 28 | (b) combination of their Contribution(s) with the work of authorship to 29 | which such Contribution(s) was added by such copyright holder or 30 | contributor, if, at the time the Contribution is added, such addition 31 | causes such combination to be necessarily infringed. The patent license 32 | shall not apply to any other combinations which include the 33 | Contribution. 34 | 35 | Except as expressly stated above, no rights or licenses from any copyright 36 | holder or contributor is granted under this license, whether expressly, by 37 | implication, estoppel or otherwise. 38 | 39 | DISCLAIMER 40 | 41 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 42 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 45 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 46 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 47 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 51 | POSSIBILITY OF SUCH DAMAGE. 52 | -------------------------------------------------------------------------------- /Library/FbpAppUtilsLib/FbpAppUtilsLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010005 11 | BASE_NAME = FbpAppUtilsLib 12 | FILE_GUID = ccbbbbb1-bb25-11df-8e4e-abc2d5d5dabc 13 | MODULE_TYPE = BASE 14 | VERSION_STRING = 1.0 15 | LIBRARY_CLASS = FbpAppUtilsLib 16 | 17 | [Sources] 18 | Utils.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | ShellPkg/ShellPkg.dec 23 | MdeModulePkg/MdeModulePkg.dec 24 | FdtBusPkg/FdtBusPkg.dec 25 | 26 | [LibraryClasses] 27 | UefiLib 28 | BaseMemoryLib 29 | MemoryAllocationLib 30 | UefiBootServicesTableLib 31 | HandleParsingLib 32 | FbpUtilsLib 33 | DxeServicesTableLib 34 | 35 | [Guids] 36 | 37 | [Protocols] 38 | gEfiShellInterfaceGuid 39 | gEfiShellParametersProtocolGuid 40 | -------------------------------------------------------------------------------- /Library/FbpInterruptUtilsLib/FbpInterruptUtilsLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010005 11 | BASE_NAME = FbpInterruptUtilsLib 12 | FILE_GUID = 6c09c086-4b9d-448c-aadb-1925a703d735 13 | MODULE_TYPE = BASE 14 | VERSION_STRING = 1.0 15 | LIBRARY_CLASS = FbpInterruptUtilsLib 16 | 17 | [Sources] 18 | Utils.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | ShellPkg/ShellPkg.dec 23 | MdeModulePkg/MdeModulePkg.dec 24 | FdtBusPkg/FdtBusPkg.dec 25 | 26 | [LibraryClasses] 27 | UefiLib 28 | DebugLib 29 | UefiBootServicesTableLib 30 | FbpUtilsLib 31 | 32 | [Protocols] 33 | gEfiDtIoProtocolGuid ## CONSUMES 34 | gEfiDtInterruptProtocolGuid ## CONSUMES 35 | -------------------------------------------------------------------------------- /Library/FbpPciUtilsLib/FbpPciUtilsLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010005 11 | BASE_NAME = FbpPciUtilsLib 12 | FILE_GUID = ccbaabb1-bb25-11df-8e4e-abc2d5a5aaaa 13 | MODULE_TYPE = BASE 14 | VERSION_STRING = 1.0 15 | LIBRARY_CLASS = FbpPciUtilsLib 16 | 17 | [Sources] 18 | Utils.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | ShellPkg/ShellPkg.dec 23 | MdeModulePkg/MdeModulePkg.dec 24 | FdtBusPkg/FdtBusPkg.dec 25 | 26 | [LibraryClasses] 27 | UefiLib 28 | DebugLib 29 | 30 | [Guids] 31 | 32 | [Protocols] 33 | 34 | -------------------------------------------------------------------------------- /Library/FbpPciUtilsLib/Utils.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #include 10 | 11 | /** 12 | Get the range attribute portion of the child base address. 13 | 14 | @param This A pointer to the EFI_DT_IO_PROTOCOL instance. 15 | @param ChildBase The ChildBase portion of 'ranges' element. 16 | 17 | @return EFI_DT_CELL phys.hi from 2.2.1 IEEE Std 1275-1994. 18 | **/ 19 | EFI_DT_CELL 20 | FbpPciGetRangeAttribute ( 21 | IN EFI_DT_IO_PROTOCOL *This, 22 | IN EFI_DT_BUS_ADDRESS ChildBase 23 | ) 24 | { 25 | if (This->ChildAddressCells < 2) { 26 | return 0; 27 | } 28 | 29 | return (EFI_DT_CELL)(ChildBase >> ((This->ChildAddressCells - 1) * sizeof (EFI_DT_CELL) * 8)); 30 | } 31 | -------------------------------------------------------------------------------- /Library/FbpPlatformDtLib/FbpPlatformDtLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent 6 | 7 | **/ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | Return the platform-specific device tree pointer, to be used for 15 | FdtBusDxe initialization. 16 | 17 | @retval NULL Not found. 18 | @retval Other Pointer to dtb/fdb blob. 19 | 20 | **/ 21 | VOID * 22 | FbpPlatformGetDt ( 23 | VOID 24 | ) 25 | { 26 | VOID *Hob; 27 | 28 | Hob = GetFirstGuidHob (&gFdtHobGuid); 29 | if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64))) { 30 | return NULL; 31 | } 32 | 33 | return (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob); 34 | } 35 | -------------------------------------------------------------------------------- /Library/FbpPlatformDtLib/FbpPlatformDtLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010005 11 | BASE_NAME = FbpPlatformDtLib 12 | FILE_GUID = 676a3958-7d91-4897-adc1-4ef22544b7a1 13 | MODULE_TYPE = BASE 14 | VERSION_STRING = 1.0 15 | LIBRARY_CLASS = FbpPlatformDtLib 16 | 17 | [Sources] 18 | FbpPlatformDtLib.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | ShellPkg/ShellPkg.dec 23 | MdeModulePkg/MdeModulePkg.dec 24 | FdtBusPkg/FdtBusPkg.dec 25 | EmbeddedPkg/EmbeddedPkg.dec 26 | 27 | [LibraryClasses] 28 | UefiLib 29 | HobLib 30 | 31 | [Guids] 32 | gFdtHobGuid 33 | -------------------------------------------------------------------------------- /Library/FbpUtilsLib/FbpUtilsLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent 6 | # 7 | ## 8 | 9 | [Defines] 10 | INF_VERSION = 0x00010005 11 | BASE_NAME = FbpUtilsLib 12 | FILE_GUID = ccbbbbb1-bb25-11df-8e4e-abc2d5d5dabd 13 | MODULE_TYPE = BASE 14 | VERSION_STRING = 1.0 15 | LIBRARY_CLASS = FbpUtilsLib 16 | 17 | [Sources] 18 | Utils.c 19 | 20 | [Packages] 21 | MdePkg/MdePkg.dec 22 | ShellPkg/ShellPkg.dec 23 | MdeModulePkg/MdeModulePkg.dec 24 | FdtBusPkg/FdtBusPkg.dec 25 | 26 | [LibraryClasses] 27 | UefiLib 28 | BaseMemoryLib 29 | MemoryAllocationLib 30 | UefiBootServicesTableLib 31 | DebugLib 32 | DevicePathLib 33 | 34 | [Guids] 35 | gEfiDtDevicePathGuid 36 | 37 | [Protocols] 38 | gEfiDtIoProtocolGuid 39 | -------------------------------------------------------------------------------- /Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf: -------------------------------------------------------------------------------- 1 | #/** @file 2 | # DT I/O-based library for consumers of PCI related dynamic PCDs. 3 | # 4 | # Copyright (c) 2016, Linaro Ltd. All rights reserved. 5 | # Copyright (c) 2024, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent 8 | # 9 | #**/ 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010005 13 | BASE_NAME = FdtPciPcdProducerLib 14 | FILE_GUID = D584275B-BF1E-4DF8-A53D-980F5645C5E7 15 | MODULE_TYPE = BASE 16 | VERSION_STRING = 1.0 17 | LIBRARY_CLASS = PciPcdProducerLib|DXE_DRIVER UEFI_DRIVER 18 | CONSTRUCTOR = FdtPciPcdProducerLibConstructor 19 | DESTRUCTOR = FdtPciPcdProducerLibDestructor 20 | 21 | [Sources] 22 | FdtPciPcdProducerLib.c 23 | 24 | [Packages] 25 | MdeModulePkg/MdeModulePkg.dec 26 | MdePkg/MdePkg.dec 27 | FdtBusPkg/FdtBusPkg.dec 28 | 29 | [LibraryClasses] 30 | BaseLib 31 | DebugLib 32 | PcdLib 33 | UefiBootServicesTableLib 34 | FbpUtilsLib 35 | FbpPciUtilsLib 36 | 37 | [Protocols] 38 | gEfiDtIoProtocolGuid ## CONSUMES 39 | 40 | [Pcd] 41 | gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation ## PRODUCES 42 | gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## PRODUCES 43 | gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## PRODUCES 44 | 45 | -------------------------------------------------------------------------------- /Library/PciHostBridgeLibEcam/PciHostBridgeLibEcam.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # PCI Host Bridge Library instance for pci-host-ecam-generic 3 | # compatible RC implementations. 4 | # 5 | # Copyright (c) 2023, Intel Corporation. All rights reserved.
6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent 8 | # 9 | ## 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010019 13 | BASE_NAME = PciHostBridgeLibEcam 14 | FILE_GUID = 5E1895A8-A246-4B15-BC4B-0D373CDFBBBB 15 | MODULE_TYPE = BASE 16 | VERSION_STRING = 1.0 17 | LIBRARY_CLASS = PciHostBridgeLib|DXE_DRIVER UEFI_DRIVER 18 | 19 | # 20 | # The following information is for reference only and not required by the build 21 | # tools. 22 | # 23 | # VALID_ARCHITECTURES = ARM AARCH64 RISCV64 24 | # 25 | 26 | [Sources] 27 | PciHostBridgeLibEcam.c 28 | 29 | [Packages] 30 | MdePkg/MdePkg.dec 31 | MdeModulePkg/MdeModulePkg.dec 32 | FdtBusPkg/FdtBusPkg.dec 33 | 34 | [LibraryClasses] 35 | DebugLib 36 | DevicePathLib 37 | MemoryAllocationLib 38 | PcdLib 39 | UefiBootServicesTableLib 40 | FbpUtilsLib 41 | FbpPciUtilsLib 42 | 43 | [Pcd] 44 | 45 | [Protocols] 46 | gEfiDtIoProtocolGuid ## CONSUMES 47 | 48 | [Depex] 49 | gEfiDtIoProtocolGuid 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FdtBusPkg - Devicetree-based Platform Device Driver Development for Tiano UEFI. 2 | 3 | This repo implements support for developing Tiano platform device drivers 4 | compliant to the UEFI Driver Model, by performing driver binding and 5 | configuration using a Devicetree. Such a Devicetree is typically 6 | either passed to UEFI by higher-privileged firmware. 7 | 8 | > [!NOTE] 9 | > This is a staging branch created as part of the ongoing 10 | > [RISE](https://riseproject.dev/) collaboration. The net goal is to 11 | > upstream to TianoCore edk2 and the UEFI Specification. 12 | 13 | Advantages: 14 | - Allows UEFI developers to fully embrace modularity and code reuse. 15 | - Facilitates development of complex (graphics, NIC, etc) drivers. 16 | - Enables a single firmware binary to work across SoC revisions and 17 | board designs. 18 | 19 | FdtBusPkg consists of FdtBusDxe, a bus driver, and a number 20 | of examples drivers and libraries for demoing with the RISC-V 21 | OVMF firmware. FdtBusDxe is responsible for enumerating 22 | DT controllers based on Devicetree nodes, and implementing 23 | `EFI_DT_IO_PROTOCOL` for basic operations on such controllers, such as 24 | device property access, register I/O, DMA buffer handling and child 25 | device enumeration. 26 | 27 | See further documentation: 28 | - [FdtBusPkg Documentation Style and Terms Definitions](Docs/StyleAndTerms.md) 29 | - [Devicetree Device Drivers](Docs/DeviceDrivers.md) 30 | - [EFI Devicetree I/O Protocol](Docs/DtIoProtocol.md) 31 | - [EFI Devicetree Interrupt Protocol](Docs/DtInterruptProtocol.md) 32 | - [FdtBusPkg-Specific Devicetree Bindings](Docs/DtBindings.md) 33 | - [FdtBusDxe Overview](Docs/FdtBusDxe.md) 34 | - [Another README for Developers](Docs/Developers.md) 35 | 36 | FdtBusPkg components can be used on any architecture, but have been 37 | developed and tested with RISC-V. They should be reusable out of the box 38 | on AArch64 platforms as well, barring any missing dependencies. 39 | 40 | Note: this is Devicetree being used internally by UEFI. There is no 41 | relation to using Devicetree as possible mechanism of describing 42 | hardware configuration to an OS. 43 | 44 | See the [presentation video](https://www.youtube.com/watch?v=2w9iQE8jA1w) and [slides](Docs/Uefi2023/slides.pdf) from the UEFI Fall 2023 Developers Conference and Plugfest. Also see the [short demo video published February, 2024](https://youtu.be/9RqKq4wGYZI). 45 | 46 | ## Updates 47 | 48 | | When | What | 49 | | :-: | ------------ | 50 | | October 2024 | Support indirect access to preconfigured BARs. | 51 | | September 2024 | Range translation, DMA range narrowing, reg-attrs, range-attrs, improved address-cells and size-cells handling, PciHostBridgeFdtDxe support for indirect configuration space access, legacy VGA ranges, preconfigured BARs. PciInfo tool. | 52 | | August 2024 | Various fixes, DtInterrupt protocol. | 53 | | February 2024 | Docs complete. DtInfo, DtProp and DtReg tools added. VirtNorFlashDxe, PciSioSerialDxe, PciHostBridgeFdtDxe drivers ported. Demo video at https://youtu.be/9RqKq4wGYZI. | 54 | | January 2024 | Open sourced. Work on documentation. | 55 | | October 2023 | Presented at the UEFI Fall 2023 Developers Conference and Plugfest. See the [presentation slides](Docs/Uefi2023/slides.pdf). | 56 | | 2023 | Reported to RISE as a 2024 priority. | 57 | 58 | ## Quick Start 59 | 60 | To build RISC-V OVMF firmware enabled with FdtBusPkg components: 61 | 62 | $ git clone https://github.com/tianocore/edk2.git 63 | $ cd edk2 64 | $ git submodule add https://github.com/intel/FdtBusPkg 65 | $ git submodule update --init --recursive 66 | $ . edksetup.sh 67 | $ git am FdtBusPkg/Docs/edk2-patches/* 68 | $ git am FdtBusPkg/Docs/ovmf-patches/* 69 | $ export GCC_RISCV64_PREFIX=... (if you are on a non-RISCV64 system) 70 | $ build -a RISCV64 -p OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc -t GCC -b DEBUG 71 | 72 | 73 | See [the README for Developers](Docs/Developers.md) for more directions. 74 | 75 | ## License 76 | 77 | FdtBusPkg is licensed under the BSD-2-Clause-Patent license (just like Tiano). 78 | 79 | ## Security Policy 80 | 81 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 82 | 83 | ### Reporting a Vulnerability 84 | 85 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 86 | 87 | ## Contribute 88 | 89 | This is a [RISE Project](https://riseproject.dev) under the Firmware WG. See the [project wiki page](https://wiki.riseproject.dev/display/HOME/EDK2_00_03+-+FdtBusDxe+support). 90 | 91 | Contributions are welcome. Please raise issues and pull requests. 92 | 93 | Please see the [policy on contributions](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md). 94 | --------------------------------------------------------------------------------