1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[mirror_edk2.git] / MdeModulePkg / Universal / PcatRealTimeClockRuntimeDxe / PcRtc.h
CommitLineData
8cd4d17c 1/*++\r
2\r
3cfb790c 3Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
8cd4d17c 11\r
12\r
13Module Name:\r
14 \r
15 PcRtc.h\r
16\r
17Abstract:\r
18\r
19 Include for real time clock driver\r
20\r
21Revision History\r
22\r
23\r
24--*/\r
25\r
26#ifndef _RTC_H_\r
27#define _RTC_H_\r
28\r
ed7748fe 29\r
8cd4d17c 30#include <PiDxe.h>\r
ed7748fe 31\r
8cd4d17c 32#include <Protocol/RealTimeClock.h>\r
ed7748fe 33\r
8cd4d17c 34#include <Library/BaseLib.h>\r
35#include <Library/DebugLib.h>\r
36#include <Library/UefiLib.h>\r
37#include <Library/BaseMemoryLib.h>\r
38#include <Library/IoLib.h>\r
39#include <Library/TimerLib.h>\r
40#include <Library/UefiDriverEntryPoint.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42#include <Library/UefiRuntimeLib.h>\r
43#include <Library/UefiRuntimeServicesTableLib.h>\r
44\r
45\r
46typedef struct {\r
47 EFI_LOCK RtcLock;\r
48 UINT16 SavedTimeZone;\r
49 UINT8 Daylight;\r
50} PC_RTC_MODULE_GLOBALS;\r
51\r
52#define PCAT_RTC_ADDRESS_REGISTER 0x70\r
53#define PCAT_RTC_DATA_REGISTER 0x71\r
54\r
55//\r
56// Dallas DS12C887 Real Time Clock\r
57//\r
58#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59\r
59#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59\r
60#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59\r
61#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59\r
62#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
63#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
64#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7\r
65#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31\r
66#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12\r
67#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99\r
68#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]\r
69#define RTC_ADDRESS_REGISTER_B 11 // R/W\r
70#define RTC_ADDRESS_REGISTER_C 12 // RO\r
71#define RTC_ADDRESS_REGISTER_D 13 // RO\r
72#define RTC_ADDRESS_CENTURY 50 // R/W Range 19..20 Bit 8 is R/W\r
73//\r
74// Date and time initial values.\r
75// They are used if the RTC values are invalid during driver initialization\r
76//\r
77#define RTC_INIT_SECOND 0\r
78#define RTC_INIT_MINUTE 0\r
79#define RTC_INIT_HOUR 0\r
80#define RTC_INIT_DAY 1\r
81#define RTC_INIT_MONTH 1\r
82#define RTC_INIT_YEAR 2001\r
83\r
84//\r
85// Register initial values\r
86//\r
87#define RTC_INIT_REGISTER_A 0x26\r
88#define RTC_INIT_REGISTER_B 0x02\r
89#define RTC_INIT_REGISTER_D 0x0\r
90\r
91#pragma pack(1)\r
92//\r
93// Register A\r
94//\r
95typedef struct {\r
96 UINT8 RS : 4; // Rate Selection Bits\r
97 UINT8 DV : 3; // Divisor\r
98 UINT8 UIP : 1; // Update in progress\r
99} RTC_REGISTER_A_BITS;\r
100\r
101typedef union {\r
102 RTC_REGISTER_A_BITS Bits;\r
103 UINT8 Data;\r
104} RTC_REGISTER_A;\r
105\r
106//\r
107// Register B\r
108//\r
109typedef struct {\r
110 UINT8 DSE : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled\r
111 UINT8 MIL : 1; // 0 - 12 hour mode 1 - 24 hour mode\r
112 UINT8 DM : 1; // 0 - BCD Format 1 - Binary Format\r
113 UINT8 SQWE : 1; // 0 - Disable SQWE output 1 - Enable SQWE output\r
114 UINT8 UIE : 1; // 0 - Update INT disabled 1 - Update INT enabled\r
115 UINT8 AIE : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled\r
116 UINT8 PIE : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled\r
117 UINT8 SET : 1; // 0 - Normal operation. 1 - Updates inhibited\r
118} RTC_REGISTER_B_BITS;\r
119\r
120typedef union {\r
121 RTC_REGISTER_B_BITS Bits;\r
122 UINT8 Data;\r
123} RTC_REGISTER_B;\r
124\r
125//\r
126// Register C\r
127//\r
128typedef struct {\r
129 UINT8 Reserved : 4; // Read as zero. Can not be written.\r
130 UINT8 UF : 1; // Update End Interrupt Flag\r
131 UINT8 AF : 1; // Alarm Interrupt Flag\r
132 UINT8 PF : 1; // Periodic Interrupt Flag\r
133 UINT8 IRQF : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE\r
134} RTC_REGISTER_C_BITS;\r
135\r
136typedef union {\r
137 RTC_REGISTER_C_BITS Bits;\r
138 UINT8 Data;\r
139} RTC_REGISTER_C;\r
140\r
141//\r
142// Register D\r
143//\r
144typedef struct {\r
145 UINT8 Reserved : 7; // Read as zero. Can not be written.\r
146 UINT8 VRT : 1; // Valid RAM and Time\r
147} RTC_REGISTER_D_BITS;\r
148\r
149typedef union {\r
150 RTC_REGISTER_D_BITS Bits;\r
151 UINT8 Data;\r
152} RTC_REGISTER_D;\r
153\r
154#pragma pack()\r
155\r
156EFI_STATUS\r
157PcRtcInit (\r
158 IN PC_RTC_MODULE_GLOBALS *Global\r
159 )\r
160/*++\r
161\r
162Routine Description:\r
163\r
164 GC_TODO: Add function description\r
165\r
166Arguments:\r
167\r
168 Global - GC_TODO: add argument description\r
169\r
170Returns:\r
171\r
172 GC_TODO: add return values\r
173\r
174--*/\r
175;\r
176\r
177EFI_STATUS\r
178PcRtcSetTime (\r
179 IN EFI_TIME *Time,\r
180 IN PC_RTC_MODULE_GLOBALS *Global\r
181 )\r
182/*++\r
183\r
184Routine Description:\r
185\r
186 GC_TODO: Add function description\r
187\r
188Arguments:\r
189\r
190 Time - GC_TODO: add argument description\r
191 Global - GC_TODO: add argument description\r
192\r
193Returns:\r
194\r
195 GC_TODO: add return values\r
196\r
197--*/\r
198;\r
199\r
200EFI_STATUS\r
201PcRtcGetTime (\r
202 OUT EFI_TIME *Time,\r
203 IN EFI_TIME_CAPABILITIES *Capabilities,\r
204 IN PC_RTC_MODULE_GLOBALS *Global\r
205 )\r
206/*++\r
207\r
208Routine Description:\r
209\r
210 GC_TODO: Add function description\r
211\r
212Arguments:\r
213\r
214 Time - GC_TODO: add argument description\r
215 Capabilities - GC_TODO: add argument description\r
216 Global - GC_TODO: add argument description\r
217\r
218Returns:\r
219\r
220 GC_TODO: add return values\r
221\r
222--*/\r
223;\r
224\r
225EFI_STATUS\r
226PcRtcSetWakeupTime (\r
227 IN BOOLEAN Enable,\r
228 OUT EFI_TIME *Time,\r
229 IN PC_RTC_MODULE_GLOBALS *Global\r
230 )\r
231/*++\r
232\r
233Routine Description:\r
234\r
235 GC_TODO: Add function description\r
236\r
237Arguments:\r
238\r
239 Enable - GC_TODO: add argument description\r
240 Time - GC_TODO: add argument description\r
241 Global - GC_TODO: add argument description\r
242\r
243Returns:\r
244\r
245 GC_TODO: add return values\r
246\r
247--*/\r
248;\r
249\r
250EFI_STATUS\r
251PcRtcGetWakeupTime (\r
252 OUT BOOLEAN *Enabled,\r
253 OUT BOOLEAN *Pending,\r
254 OUT EFI_TIME *Time,\r
255 IN PC_RTC_MODULE_GLOBALS *Global\r
256 )\r
257/*++\r
258\r
259Routine Description:\r
260\r
261 GC_TODO: Add function description\r
262\r
263Arguments:\r
264\r
265 Enabled - GC_TODO: add argument description\r
266 Pending - GC_TODO: add argument description\r
267 Time - GC_TODO: add argument description\r
268 Global - GC_TODO: add argument description\r
269\r
270Returns:\r
271\r
272 GC_TODO: add return values\r
273\r
274--*/\r
275;\r
276\r
277EFI_STATUS\r
278EFIAPI\r
279InitializePcRtc (\r
280 IN EFI_HANDLE ImageHandle,\r
281 IN EFI_SYSTEM_TABLE *SystemTable\r
282 )\r
283/*++\r
284\r
285Routine Description:\r
286\r
287 GC_TODO: Add function description\r
288\r
289Arguments:\r
290\r
291 ImageHandle - GC_TODO: add argument description\r
292 SystemTable - GC_TODO: add argument description\r
293\r
294Returns:\r
295\r
296 GC_TODO: add return values\r
297\r
298--*/\r
299;\r
300\r
301UINT8\r
302BcdToDecimal (\r
303 IN UINT8 BcdValue\r
304 )\r
305/*++\r
306\r
307Routine Description:\r
308\r
309 GC_TODO: Add function description\r
310\r
311Arguments:\r
312\r
313 BcdValue - GC_TODO: add argument description\r
314\r
315Returns:\r
316\r
317 GC_TODO: add return values\r
318\r
319--*/\r
320;\r
321\r
322EFI_STATUS\r
323RtcTimeFieldsValid (\r
324 IN EFI_TIME *Time\r
325 )\r
326/*++\r
327\r
328Routine Description:\r
329\r
330 GC_TODO: Add function description\r
331\r
332Arguments:\r
333\r
334 Time - GC_TODO: add argument description\r
335\r
336Returns:\r
337\r
338 GC_TODO: add return values\r
339\r
340--*/\r
341;\r
342\r
343UINT8\r
344DecimaltoBcd (\r
345 IN UINT8 DecValue\r
346 )\r
347/*++\r
348\r
349Routine Description:\r
350\r
351 GC_TODO: Add function description\r
352\r
353Arguments:\r
354\r
355 DecValue - GC_TODO: add argument description\r
356\r
357Returns:\r
358\r
359 GC_TODO: add return values\r
360\r
361--*/\r
362;\r
363\r
364VOID\r
365ConvertEfiTimeToRtcTime (\r
366 IN EFI_TIME *Time,\r
367 IN RTC_REGISTER_B RegisterB,\r
368 IN UINT8 *Century\r
369 )\r
370/*++\r
371\r
372Routine Description:\r
373\r
374 GC_TODO: Add function description\r
375\r
376Arguments:\r
377\r
378 Time - GC_TODO: add argument description\r
379 RegisterB - GC_TODO: add argument description\r
380 Century - GC_TODO: add argument description\r
381\r
382Returns:\r
383\r
384 GC_TODO: add return values\r
385\r
386--*/\r
387;\r
388\r
389EFI_STATUS\r
390RtcTestCenturyRegister (\r
391 VOID\r
392 )\r
393/*++\r
394\r
395Routine Description:\r
396\r
397 GC_TODO: Add function description\r
398\r
399Arguments:\r
400\r
401 None\r
402\r
403Returns:\r
404\r
405 GC_TODO: add return values\r
406\r
407--*/\r
408;\r
409\r
410VOID\r
411ConvertRtcTimeToEfiTime (\r
412 IN EFI_TIME *Time,\r
413 IN RTC_REGISTER_B RegisterB\r
414 )\r
415/*++\r
416\r
417Routine Description:\r
418\r
419 GC_TODO: Add function description\r
420\r
421Arguments:\r
422\r
423 Time - GC_TODO: add argument description\r
424 RegisterB - GC_TODO: add argument description\r
425\r
426Returns:\r
427\r
428 GC_TODO: add return values\r
429\r
430--*/\r
431;\r
432\r
433EFI_STATUS\r
434RtcWaitToUpdate (\r
435 UINTN Timeout\r
436 )\r
437/*++\r
438\r
439Routine Description:\r
440\r
441 GC_TODO: Add function description\r
442\r
443Arguments:\r
444\r
445 Timeout - GC_TODO: add argument description\r
446\r
447Returns:\r
448\r
449 GC_TODO: add return values\r
450\r
451--*/\r
452;\r
453\r
454UINT8\r
455RtcSaveContext (\r
456 IN PC_RTC_MODULE_GLOBALS *Global\r
457 )\r
458/*++\r
459\r
460Routine Description:\r
461\r
462 GC_TODO: Add function description\r
463\r
464Arguments:\r
465\r
466 Global - GC_TODO: add argument description\r
467\r
468Returns:\r
469\r
470 GC_TODO: add return values\r
471\r
472--*/\r
473;\r
474\r
475VOID\r
476RtcRestoreContext (\r
477 IN UINT8 SavedAddressRegister,\r
478 IN PC_RTC_MODULE_GLOBALS *Global\r
479 )\r
480/*++\r
481\r
482Routine Description:\r
483\r
484 GC_TODO: Add function description\r
485\r
486Arguments:\r
487\r
488 SavedAddressRegister - GC_TODO: add argument description\r
489 Global - GC_TODO: add argument description\r
490\r
491Returns:\r
492\r
493 GC_TODO: add return values\r
494\r
495--*/\r
496;\r
497\r
498BOOLEAN\r
499DayValid (\r
500 IN EFI_TIME *Time\r
501 );\r
502\r
503BOOLEAN\r
504IsLeapYear (\r
505 IN EFI_TIME *Time\r
506 );\r
507\r
508#endif\r