]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyCmos.c
IntelFrameworkModulePkg: Add Compatibility Support Module (CSM) drivers
[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
8This program and the accompanying materials\r
9are licensed and made available under the terms and conditions\r
10of the BSD License which accompanies this distribution. The\r
11full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#include "LegacyBiosInterface.h"\r
20\r
21/**\r
22 Read CMOS register through index/data port.\r
23\r
24 @param[in] Index The index of the CMOS register to read.\r
25\r
26 @return The data value from the CMOS register specified by Index.\r
27\r
28**/\r
29UINT8\r
30LegacyReadStandardCmos (\r
31 IN UINT8 Index\r
32 )\r
33{\r
34 IoWrite8 (PORT_70, Index);\r
35 return IoRead8 (PORT_71);\r
36}\r
37\r
38/**\r
39 Write CMOS register through index/data port.\r
40\r
41 @param[in] Index The index of the CMOS register to write.\r
42 @param[in] Value The value of CMOS register to write.\r
43\r
44 @return The value written to the CMOS register specified by Index.\r
45\r
46**/\r
47UINT8\r
48LegacyWriteStandardCmos (\r
49 IN UINT8 Index,\r
50 IN UINT8 Value\r
51 )\r
52{\r
53 IoWrite8 (PORT_70, Index);\r
54 return IoWrite8 (PORT_71, Value);\r
55}\r
56\r
57/**\r
58 Calculate the new standard CMOS checksum and write it.\r
59\r
60 @param Private Legacy BIOS Instance data\r
61\r
62 @retval EFI_SUCCESS Calculate 16-bit checksum successfully\r
63\r
64**/\r
65EFI_STATUS\r
66LegacyCalculateWriteStandardCmosChecksum (\r
67 VOID\r
68 )\r
69{\r
70 UINT8 Register;\r
71 UINT16 Checksum;\r
72\r
73 for (Checksum = 0, Register = 0x10; Register < 0x2e; Register++) {\r
74 Checksum = (UINT16)(Checksum + LegacyReadStandardCmos (Register));\r
75 }\r
76 LegacyWriteStandardCmos (CMOS_2E, (UINT8)(Checksum >> 8));\r
77 LegacyWriteStandardCmos (CMOS_2F, (UINT8)(Checksum & 0xff));\r
78 return EFI_SUCCESS;\r
79}\r
80\r
81\r
82/**\r
83 Fill in the standard CMOS stuff before Legacy16 load\r
84\r
85 @param Private Legacy BIOS Instance data\r
86\r
87 @retval EFI_SUCCESS It should always work.\r
88\r
89**/\r
90EFI_STATUS\r
91LegacyBiosInitCmos (\r
92 IN LEGACY_BIOS_INSTANCE *Private\r
93 )\r
94{\r
95 UINT32 Size;\r
96\r
97 //\r
98 // Clear all errors except RTC lost power\r
99 //\r
100 LegacyWriteStandardCmos (CMOS_0E, (UINT8)(LegacyReadStandardCmos (CMOS_0E) & BIT7));\r
101\r
102 //\r
103 // Update CMOS locations 15,16,17,18,30,31 and 32\r
104 // CMOS 16,15 = 640Kb = 0x280\r
105 // CMOS 18,17 = 31,30 = 15Mb max in 1Kb increments =0x3C00 max\r
106 // CMOS 32 = 0x20\r
107 //\r
108 LegacyWriteStandardCmos (CMOS_15, 0x80);\r
109 LegacyWriteStandardCmos (CMOS_16, 0x02);\r
110\r
111 Size = 15 * SIZE_1MB;\r
112 if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) {\r
113 Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10;\r
114 }\r
115\r
116 LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF));\r
117 LegacyWriteStandardCmos (CMOS_30, (UINT8)(Size & 0xFF));\r
118 LegacyWriteStandardCmos (CMOS_18, (UINT8)(Size >> 8));\r
119 LegacyWriteStandardCmos (CMOS_31, (UINT8)(Size >> 8));\r
120\r
121 LegacyCalculateWriteStandardCmosChecksum ();\r
122\r
123 return EFI_SUCCESS;\r
124}\r