]>
Commit | Line | Data |
---|---|---|
86d96aef AB |
1 | /** @file\r |
2 | \r | |
72e514c9 | 3 | Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.<BR>\r |
86d96aef AB |
4 | \r |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
72e514c9 AB |
15 | #include <Library/BaseLib.h>\r |
16 | #include <Library/DebugLib.h>\r | |
86d96aef | 17 | #include <Library/NorFlashPlatformLib.h>\r |
72e514c9 AB |
18 | #include <Library/UefiBootServicesTableLib.h>\r |
19 | \r | |
20 | #include <Protocol/FdtClient.h>\r | |
86d96aef | 21 | \r |
f311e5d8 | 22 | #define QEMU_NOR_BLOCK_SIZE SIZE_256KB\r |
72e514c9 AB |
23 | \r |
24 | #define MAX_FLASH_BANKS 4\r | |
f311e5d8 | 25 | \r |
86d96aef AB |
26 | EFI_STATUS\r |
27 | NorFlashPlatformInitialization (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | return EFI_SUCCESS;\r | |
32 | }\r | |
33 | \r | |
72e514c9 | 34 | NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS];\r |
86d96aef AB |
35 | \r |
36 | EFI_STATUS\r | |
37 | NorFlashPlatformGetDevices (\r | |
38 | OUT NOR_FLASH_DESCRIPTION **NorFlashDescriptions,\r | |
39 | OUT UINT32 *Count\r | |
40 | )\r | |
41 | {\r | |
72e514c9 AB |
42 | FDT_CLIENT_PROTOCOL *FdtClient;\r |
43 | INT32 Node;\r | |
44 | EFI_STATUS Status;\r | |
45 | EFI_STATUS FindNodeStatus;\r | |
46 | CONST UINT32 *Reg;\r | |
47 | UINT32 PropSize;\r | |
48 | UINT32 Num;\r | |
49 | UINT64 Base;\r | |
50 | UINT64 Size;\r | |
51 | \r | |
52 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
53 | (VOID **)&FdtClient);\r | |
54 | ASSERT_EFI_ERROR (Status);\r | |
55 | \r | |
56 | Num = 0;\r | |
57 | for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient,\r | |
58 | "cfi-flash", &Node);\r | |
59 | !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS;\r | |
60 | FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient,\r | |
61 | "cfi-flash", Node, &Node)) {\r | |
62 | \r | |
63 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r | |
64 | (CONST VOID **)&Reg, &PropSize);\r | |
65 | if (EFI_ERROR (Status)) {\r | |
66 | DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n",\r | |
67 | __FUNCTION__, Status));\r | |
68 | continue;\r | |
69 | }\r | |
70 | \r | |
71 | ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0);\r | |
72 | \r | |
73 | while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) {\r | |
74 | Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));\r | |
75 | Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));\r | |
76 | Reg += 4;\r | |
77 | \r | |
5e27deed AB |
78 | PropSize -= 4 * sizeof (UINT32);\r |
79 | \r | |
80 | //\r | |
81 | // Disregard any flash devices that overlap with the primary FV.\r | |
82 | // The firmware is not updatable from inside the guest anyway.\r | |
83 | //\r | |
84 | if ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) > Base) &&\r | |
85 | (Base + Size) > PcdGet64 (PcdFvBaseAddress)) {\r | |
86 | continue;\r | |
87 | }\r | |
88 | \r | |
72e514c9 AB |
89 | mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base;\r |
90 | mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base;\r | |
91 | mNorFlashDevices[Num].Size = (UINTN)Size;\r | |
92 | mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE;\r | |
93 | Num++;\r | |
72e514c9 AB |
94 | }\r |
95 | }\r | |
96 | \r | |
86d96aef | 97 | *NorFlashDescriptions = mNorFlashDevices;\r |
72e514c9 AB |
98 | *Count = Num;\r |
99 | \r | |
86d96aef AB |
100 | return EFI_SUCCESS;\r |
101 | }\r |