3 Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/NorFlashPlatformLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
20 #include <Protocol/FdtClient.h>
22 #define QEMU_NOR_BLOCK_SIZE SIZE_256KB
24 #define MAX_FLASH_BANKS 4
27 NorFlashPlatformInitialization (
34 NOR_FLASH_DESCRIPTION mNorFlashDevices
[MAX_FLASH_BANKS
];
37 NorFlashPlatformGetDevices (
38 OUT NOR_FLASH_DESCRIPTION
**NorFlashDescriptions
,
42 FDT_CLIENT_PROTOCOL
*FdtClient
;
45 EFI_STATUS FindNodeStatus
;
52 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
54 ASSERT_EFI_ERROR (Status
);
57 for (FindNodeStatus
= FdtClient
->FindCompatibleNode (FdtClient
,
59 !EFI_ERROR (FindNodeStatus
) && Num
< MAX_FLASH_BANKS
;
60 FindNodeStatus
= FdtClient
->FindNextCompatibleNode (FdtClient
,
61 "cfi-flash", Node
, &Node
)) {
63 Status
= FdtClient
->GetNodeProperty (FdtClient
, Node
, "reg",
64 (CONST VOID
**)&Reg
, &PropSize
);
65 if (EFI_ERROR (Status
)) {
66 DEBUG ((DEBUG_ERROR
, "%a: GetNodeProperty () failed (Status == %r)\n",
67 __FUNCTION__
, Status
));
71 ASSERT ((PropSize
% (4 * sizeof (UINT32
))) == 0);
73 while (PropSize
>= (4 * sizeof (UINT32
)) && Num
< MAX_FLASH_BANKS
) {
74 Base
= SwapBytes64 (ReadUnaligned64 ((VOID
*)&Reg
[0]));
75 Size
= SwapBytes64 (ReadUnaligned64 ((VOID
*)&Reg
[2]));
78 mNorFlashDevices
[Num
].DeviceBaseAddress
= (UINTN
)Base
;
79 mNorFlashDevices
[Num
].RegionBaseAddress
= (UINTN
)Base
;
80 mNorFlashDevices
[Num
].Size
= (UINTN
)Size
;
81 mNorFlashDevices
[Num
].BlockSize
= QEMU_NOR_BLOCK_SIZE
;
84 PropSize
-= 4 * sizeof (UINT32
);
88 *NorFlashDescriptions
= mNorFlashDevices
;