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