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