]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyCmos.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyCmos.c
CommitLineData
bcecde14 1/** @file\r
2 This code fills in standard CMOS values and updates the standard CMOS\r
3 checksum. The Legacy16 code or LegacyBiosPlatform.c is responsible for\r
4 non-standard CMOS locations and non-standard checksums.\r
5\r
6Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
7\r
c0a00b14 8SPDX-License-Identifier: BSD-2-Clause-Patent\r
bcecde14 9\r
10**/\r
11\r
12#include "LegacyBiosInterface.h"\r
13\r
14/**\r
15 Read CMOS register through index/data port.\r
16\r
17 @param[in] Index The index of the CMOS register to read.\r
18\r
19 @return The data value from the CMOS register specified by Index.\r
20\r
21**/\r
22UINT8\r
23LegacyReadStandardCmos (\r
24 IN UINT8 Index\r
25 )\r
26{\r
27 IoWrite8 (PORT_70, Index);\r
28 return IoRead8 (PORT_71);\r
29}\r
30\r
31/**\r
32 Write CMOS register through index/data port.\r
33\r
34 @param[in] Index The index of the CMOS register to write.\r
35 @param[in] Value The value of CMOS register to write.\r
36\r
37 @return The value written to the CMOS register specified by Index.\r
38\r
39**/\r
40UINT8\r
41LegacyWriteStandardCmos (\r
42 IN UINT8 Index,\r
43 IN UINT8 Value\r
44 )\r
45{\r
46 IoWrite8 (PORT_70, Index);\r
47 return IoWrite8 (PORT_71, Value);\r
48}\r
49\r
50/**\r
51 Calculate the new standard CMOS checksum and write it.\r
52\r
53 @param Private Legacy BIOS Instance data\r
54\r
55 @retval EFI_SUCCESS Calculate 16-bit checksum successfully\r
56\r
57**/\r
58EFI_STATUS\r
59LegacyCalculateWriteStandardCmosChecksum (\r
60 VOID\r
61 )\r
62{\r
63 UINT8 Register;\r
64 UINT16 Checksum;\r
65\r
66 for (Checksum = 0, Register = 0x10; Register < 0x2e; Register++) {\r
67 Checksum = (UINT16)(Checksum + LegacyReadStandardCmos (Register));\r
68 }\r
69 LegacyWriteStandardCmos (CMOS_2E, (UINT8)(Checksum >> 8));\r
70 LegacyWriteStandardCmos (CMOS_2F, (UINT8)(Checksum & 0xff));\r
71 return EFI_SUCCESS;\r
72}\r
73\r
74\r
75/**\r
76 Fill in the standard CMOS stuff before Legacy16 load\r
77\r
78 @param Private Legacy BIOS Instance data\r
79\r
80 @retval EFI_SUCCESS It should always work.\r
81\r
82**/\r
83EFI_STATUS\r
84LegacyBiosInitCmos (\r
85 IN LEGACY_BIOS_INSTANCE *Private\r
86 )\r
87{\r
88 UINT32 Size;\r
89\r
90 //\r
91 // Clear all errors except RTC lost power\r
92 //\r
93 LegacyWriteStandardCmos (CMOS_0E, (UINT8)(LegacyReadStandardCmos (CMOS_0E) & BIT7));\r
94\r
95 //\r
96 // Update CMOS locations 15,16,17,18,30,31 and 32\r
97 // CMOS 16,15 = 640Kb = 0x280\r
98 // CMOS 18,17 = 31,30 = 15Mb max in 1Kb increments =0x3C00 max\r
99 // CMOS 32 = 0x20\r
100 //\r
101 LegacyWriteStandardCmos (CMOS_15, 0x80);\r
102 LegacyWriteStandardCmos (CMOS_16, 0x02);\r
103\r
104 Size = 15 * SIZE_1MB;\r
105 if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) {\r
106 Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10;\r
107 }\r
108\r
109 LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF));\r
110 LegacyWriteStandardCmos (CMOS_30, (UINT8)(Size & 0xFF));\r
111 LegacyWriteStandardCmos (CMOS_18, (UINT8)(Size >> 8));\r
112 LegacyWriteStandardCmos (CMOS_31, (UINT8)(Size >> 8));\r
113\r
114 LegacyCalculateWriteStandardCmosChecksum ();\r
115\r
116 return EFI_SUCCESS;\r
117}\r