X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmVirtPkg%2FFdtClientDxe%2FFdtClientDxe.c;h=547a29fce62c9fc06cc525776daf5ba983af708f;hp=c336e2410033e2832db06fa98d2517a4948edc10;hb=eec1ba7dab8bfc774cab63523c999e5264a7b848;hpb=1e7143d81a08c18d0b684853a756362ad7f693f3 diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c index c336e24100..547a29fce6 100644 --- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c +++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c @@ -29,6 +29,7 @@ STATIC VOID *mDeviceTreeBase; STATIC EFI_STATUS +EFIAPI GetNodeProperty ( IN FDT_CLIENT_PROTOCOL *This, IN INT32 Node, @@ -55,6 +56,7 @@ GetNodeProperty ( STATIC EFI_STATUS +EFIAPI SetNodeProperty ( IN FDT_CLIENT_PROTOCOL *This, IN INT32 Node, @@ -159,7 +161,8 @@ FindCompatibleNodeReg ( IN FDT_CLIENT_PROTOCOL *This, IN CONST CHAR8 *CompatibleString, OUT CONST VOID **Reg, - OUT UINT32 *RegElemSize, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, OUT UINT32 *RegSize ) { @@ -178,20 +181,95 @@ FindCompatibleNodeReg ( return Status; } - if ((*RegSize % 8) != 0) { + if ((*RegSize % 16) != 0) { DEBUG ((EFI_D_ERROR, "%a: '%a' compatible node has invalid 'reg' property (size == 0x%x)\n", __FUNCTION__, CompatibleString, *RegSize)); return EFI_NOT_FOUND; } - *RegElemSize = 8; + *AddressCells = 2; + *SizeCells = 2; return EFI_SUCCESS; } STATIC EFI_STATUS +EFIAPI +FindNextMemoryNodeReg ( + IN FDT_CLIENT_PROTOCOL *This, + IN INT32 PrevNode, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ) +{ + INT32 Prev, Next; + CONST CHAR8 *DeviceType; + INT32 Len; + EFI_STATUS Status; + + ASSERT (mDeviceTreeBase != NULL); + ASSERT (Node != NULL); + + for (Prev = PrevNode;; Prev = Next) { + Next = fdt_next_node (mDeviceTreeBase, Prev, NULL); + if (Next < 0) { + break; + } + + DeviceType = fdt_getprop (mDeviceTreeBase, Next, "device_type", &Len); + if (DeviceType != NULL && AsciiStrCmp (DeviceType, "memory") == 0) { + // + // Get the 'reg' property of this memory node. For now, we will assume + // 8 byte quantities for base and size, respectively. + // TODO use #cells root properties instead + // + Status = GetNodeProperty (This, Next, "reg", Reg, RegSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_WARN, + "%a: ignoring memory node with no 'reg' property\n", + __FUNCTION__)); + continue; + } + if ((*RegSize % 16) != 0) { + DEBUG ((EFI_D_WARN, + "%a: ignoring memory node with invalid 'reg' property (size == 0x%x)\n", + __FUNCTION__, *RegSize)); + continue; + } + + *Node = Next; + *AddressCells = 2; + *SizeCells = 2; + return EFI_SUCCESS; + } + } + return EFI_NOT_FOUND; +} + +STATIC +EFI_STATUS +EFIAPI +FindMemoryNodeReg ( + IN FDT_CLIENT_PROTOCOL *This, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ) +{ + return FindNextMemoryNodeReg (This, 0, Node, Reg, AddressCells, SizeCells, + RegSize); +} + +STATIC +EFI_STATUS +EFIAPI GetOrInsertChosenNode ( IN FDT_CLIENT_PROTOCOL *This, OUT INT32 *Node @@ -223,6 +301,8 @@ STATIC FDT_CLIENT_PROTOCOL mFdtClientProtocol = { FindNextCompatibleNode, FindCompatibleNodeProperty, FindCompatibleNodeReg, + FindMemoryNodeReg, + FindNextMemoryNodeReg, GetOrInsertChosenNode, };