33 OUT UINT32 *PropSize OPTIONAL
38 ASSERT (mDeviceTreeBase !=
NULL);
39 ASSERT (Prop !=
NULL);
41 *Prop =
FdtGetProp (mDeviceTreeBase, Node, PropertyName, &Len);
46 if (PropSize !=
NULL) {
66 ASSERT (mDeviceTreeBase !=
NULL);
68 Ret =
FdtSetProp (mDeviceTreeBase, Node, PropertyName, Prop, PropSize);
70 return EFI_DEVICE_ERROR;
82 CONST CHAR8 *NodeStatus;
90 NodeStatus =
FdtGetProp (mDeviceTreeBase, Node,
"status", &Len);
91 if (NodeStatus ==
NULL) {
95 if ((Len >= 5) && (
AsciiStrCmp (NodeStatus,
"okay") == 0)) {
99 if ((Len >= 3) && (
AsciiStrCmp (NodeStatus,
"ok") == 0)) {
109FindNextCompatibleNode (
111 IN CONST CHAR8 *CompatibleString,
117 CONST CHAR8 *Type, *Compatible;
120 ASSERT (mDeviceTreeBase !=
NULL);
121 ASSERT (Node !=
NULL);
123 for (Prev = PrevNode; ; Prev = Next) {
129 if (!IsNodeEnabled (Next)) {
133 Type =
FdtGetProp (mDeviceTreeBase, Next,
"compatible", &Len);
142 for (Compatible = Type; Compatible < Type + Len && *Compatible;
145 if (
AsciiStrCmp (CompatibleString, Compatible) == 0) {
152 return EFI_NOT_FOUND;
160 IN CONST CHAR8 *CompatibleString,
164 return FindNextCompatibleNode (This, CompatibleString, 0, Node);
170FindCompatibleNodeProperty (
172 IN CONST CHAR8 *CompatibleString,
175 OUT UINT32 *PropSize OPTIONAL
181 Status = FindCompatibleNode (This, CompatibleString, &Node);
182 if (EFI_ERROR (Status)) {
186 return GetNodeProperty (This, Node, PropertyName, Prop, PropSize);
192FindCompatibleNodeReg (
194 IN CONST CHAR8 *CompatibleString,
203 ASSERT (RegSize !=
NULL);
210 Status = FindCompatibleNodeProperty (
217 if (EFI_ERROR (Status)) {
221 if ((*RegSize % 16) != 0) {
224 "%a: '%a' compatible node has invalid 'reg' property (size == 0x%x)\n",
229 return EFI_NOT_FOUND;
241FindNextMemoryNodeReg (
252 CONST CHAR8 *DeviceType;
256 ASSERT (mDeviceTreeBase !=
NULL);
257 ASSERT (Node !=
NULL);
259 for (Prev = PrevNode; ; Prev = Next) {
265 DeviceType =
FdtGetProp (mDeviceTreeBase, Next,
"device_type", &Len);
266 if ((DeviceType ==
NULL) || (
AsciiStrCmp (DeviceType,
"memory") != 0)) {
270 if (!IsNodeEnabled (Next)) {
271 DEBUG ((DEBUG_WARN,
"%a: ignoring disabled memory node\n", __func__));
280 Status = GetNodeProperty (This, Next,
"reg", Reg, RegSize);
281 if (EFI_ERROR (Status)) {
284 "%a: ignoring memory node with no 'reg' property\n",
290 if ((*RegSize % 16) != 0) {
293 "%a: ignoring memory node with invalid 'reg' property (size == 0x%x)\n",
306 return EFI_NOT_FOUND;
321 return FindNextMemoryNodeReg (
335GetOrInsertChosenNode (
342 ASSERT (mDeviceTreeBase !=
NULL);
343 ASSERT (Node !=
NULL);
351 return EFI_OUT_OF_RESOURCES;
363 FindNextCompatibleNode,
364 FindCompatibleNodeProperty,
365 FindCompatibleNodeReg,
367 FindNextMemoryNodeReg,
368 GetOrInsertChosenNode,
374OnPlatformHasDeviceTree (
381 VOID *DeviceTreeBase;
383 Status =
gBS->LocateProtocol (
384 &gEdkiiPlatformHasDeviceTreeGuid,
388 if (EFI_ERROR (Status)) {
392 DeviceTreeBase = Context;
395 "%a: exposing DTB @ 0x%p to OS\n",
399 Status =
gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase);
402 gBS->CloseEvent (Event);
407InitializeFdtClientDxe (
413 VOID *DeviceTreeBase;
419 if ((Hob ==
NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) !=
sizeof (UINT64))) {
420 return EFI_NOT_FOUND;
423 DeviceTreeBase = (
VOID *)(
UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);
428 "%a: No DTB found @ 0x%p\n",
432 return EFI_NOT_FOUND;
435 mDeviceTreeBase = DeviceTreeBase;
437 DEBUG ((DEBUG_INFO,
"%a: DTB @ 0x%p\n", __func__, mDeviceTreeBase));
443 Status =
gBS->CreateEvent (
446 OnPlatformHasDeviceTree,
448 &PlatformHasDeviceTreeEvent
450 if (EFI_ERROR (Status)) {
451 DEBUG ((DEBUG_ERROR,
"%a: CreateEvent(): %r\n", __func__, Status));
455 Status =
gBS->RegisterProtocolNotify (
456 &gEdkiiPlatformHasDeviceTreeGuid,
457 PlatformHasDeviceTreeEvent,
460 if (EFI_ERROR (Status)) {
463 "%a: RegisterProtocolNotify(): %r\n",
473 Status =
gBS->SignalEvent (PlatformHasDeviceTreeEvent);
474 if (EFI_ERROR (Status)) {
475 DEBUG ((DEBUG_ERROR,
"%a: SignalEvent(): %r\n", __func__, Status));
479 Status =
gBS->InstallProtocolInterface (
481 &gFdtClientProtocolGuid,
485 if (EFI_ERROR (Status)) {
488 "%a: InstallProtocolInterface(): %r\n",
498 gBS->CloseEvent (PlatformHasDeviceTreeEvent);
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
INT32 EFIAPI FdtSetProp(IN VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN CONST VOID *Value, IN UINT32 Length)
INT32 EFIAPI FdtAddSubnode(IN VOID *Fdt, IN INT32 ParentOffset, IN CONST CHAR8 *Name)
INT32 EFIAPI FdtNextNode(IN CONST VOID *Fdt, IN INT32 Offset, IN INT32 *Depth)
INT32 EFIAPI FdtCheckHeader(IN CONST VOID *Fdt)
INT32 EFIAPI FdtPathOffset(IN CONST VOID *Fdt, IN CONST CHAR8 *Path)
CONST VOID *EFIAPI FdtGetProp(IN CONST VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN INT32 *Length)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)