Lines Matching full:rtc
45 #include <isa/rtc.h>
53 /* Register layout of the RTC */
80 u_int addr; /* RTC register to read or write */
91 * RTC time is considered "broken" if:
92 * - RTC updates are halted by the guest
93 * - RTC date/time fields have invalid values
108 static MALLOC_DEFINE(M_VRTC, "vrtc", "bhyve virtual rtc");
116 &rtc_flag_broken_time, 0, "Stop guest when invalid RTC time is detected");
122 * The RTC is counting only when dividers are not held in reset.
131 * RTC date/time can be updated only if:
171 rtcset(struct rtcdev *rtc, int val)
177 return ((rtc->reg_b & RTCSB_BIN) ? val : bin2bcd_data[val]);
185 struct rtcdev *rtc;
197 * If the RTC is halted then the guest has "ownership" of the
198 * date/time fields. Don't update the RTC date/time fields in
223 rtc = &vrtc->rtcdev;
224 rtc->sec = rtcset(rtc, ct.sec);
225 rtc->min = rtcset(rtc, ct.min);
227 if (rtc->reg_b & RTCSB_24HR) {
249 rtc->hour = rtcset(rtc, hour);
251 if ((rtc->reg_b & RTCSB_24HR) == 0 && ct.hour >= 12)
252 rtc->hour |= 0x80; /* set MSB to indicate PM */
254 rtc->day_of_week = rtcset(rtc, ct.dow + 1);
255 rtc->day_of_month = rtcset(rtc, ct.day);
256 rtc->month = rtcset(rtc, ct.mon);
257 rtc->year = rtcset(rtc, ct.year % 100);
258 rtc->century = rtcset(rtc, ct.year / 100);
262 rtcget(struct rtcdev *rtc, int val, int *retval)
266 if (rtc->reg_b & RTCSB_BIN) {
286 struct rtcdev *rtc;
294 rtc = &vrtc->rtcdev;
298 error = rtcget(rtc, rtc->sec, &ct.sec);
300 VM_CTR2(vm, "Invalid RTC sec %#x/%d", rtc->sec, ct.sec);
304 error = rtcget(rtc, rtc->min, &ct.min);
306 VM_CTR2(vm, "Invalid RTC min %#x/%d", rtc->min, ct.min);
311 hour = rtc->hour;
312 if ((rtc->reg_b & RTCSB_24HR) == 0) {
318 error = rtcget(rtc, hour, &ct.hour);
319 if ((rtc->reg_b & RTCSB_24HR) == 0) {
336 VM_CTR2(vm, "Invalid RTC 12-hour format %#x/%d",
337 rtc->hour, ct.hour);
343 VM_CTR2(vm, "Invalid RTC hour %#x/%d", rtc->hour, ct.hour);
348 * Ignore 'rtc->dow' because some guests like Linux don't bother
355 error = rtcget(rtc, rtc->day_of_month, &ct.day);
357 VM_CTR2(vm, "Invalid RTC mday %#x/%d", rtc->day_of_month,
362 error = rtcget(rtc, rtc->month, &ct.mon);
364 VM_CTR2(vm, "Invalid RTC month %#x/%d", rtc->month, ct.mon);
368 error = rtcget(rtc, rtc->year, &year);
370 VM_CTR2(vm, "Invalid RTC year %#x/%d", rtc->year, year);
374 error = rtcget(rtc, rtc->century, ¢ury);
377 VM_CTR2(vm, "Invalid RTC century %#x/%d", rtc->century,
384 VM_CTR3(vm, "Invalid RTC clocktime.date %04d-%02d-%02d",
386 VM_CTR3(vm, "Invalid RTC clocktime.time %02d:%02d:%02d",
393 * Stop updating the RTC if the date/time fields programmed by
396 VM_CTR0(vrtc->vm, "Invalid RTC date/time programming detected");
403 struct rtcdev *rtc;
409 rtc = &vrtc->rtcdev;
410 alarm_sec = rtc->alarm_sec;
411 alarm_min = rtc->alarm_min;
412 alarm_hour = rtc->alarm_hour;
415 VM_CTR2(vrtc->vm, "Updating RTC secs from %#lx to %#lx",
418 VM_CTR2(vrtc->vm, "Updating RTC base uptime from %#lx to %#lx",
426 * If 'newtime' indicates that RTC updates are disabled then just
436 * Return an error if RTC updates are halted by the guest.
439 VM_CTR0(vrtc->vm, "RTC update halted by guest");
449 * Otherwise move the RTC time forward directly to 'newtime'.
458 * Update the RTC date/time fields before checking
463 if ((alarm_sec >= 0xC0 || alarm_sec == rtc->sec) &&
464 (alarm_min >= 0xC0 || alarm_min == rtc->min) &&
465 (alarm_hour >= 0xC0 || alarm_hour == rtc->hour)) {
466 vrtc_set_reg_c(vrtc, rtc->reg_c | RTCIR_ALARM);
472 vrtc_set_reg_c(vrtc, rtc->reg_c | RTCIR_UPDATE);
530 VM_CTR0(vrtc->vm, "RTC callout stopped");
535 VM_CTR1(vrtc->vm, "RTC callout frequency %d hz", SBT_1S / freqsbt);
593 struct rtcdev *rtc;
599 rtc = &vrtc->rtcdev;
602 oldirqf = rtc->reg_c & RTCIR_INT;
611 oldval = rtc->reg_c;
612 rtc->reg_c = newirqf | newval;
613 changed = oldval ^ rtc->reg_c;
615 VM_CTR2(vrtc->vm, "RTC reg_c changed from %#x to %#x",
616 oldval, rtc->reg_c);
620 VM_CTR1(vrtc->vm, "RTC irq %d asserted", RTC_IRQ);
624 VM_CTR1(vrtc->vm, "RTC irq %d deasserted", RTC_IRQ);
631 struct rtcdev *rtc;
639 rtc = &vrtc->rtcdev;
640 oldval = rtc->reg_b;
643 rtc->reg_b = newval;
646 VM_CTR2(vrtc->vm, "RTC reg_b changed from %#x to %#x",
665 * Force a refresh of the RTC date/time fields so
673 * that the RTC date/time is in flux.
676 rtc->reg_b &= ~RTCSB_UINTR;
698 * The side effect of bits that control the RTC date/time format
717 VM_CTR2(vrtc->vm, "RTC divider held in reset at %#lx/%#lx",
723 * maintain the illusion that the RTC date/time was frozen
727 VM_CTR2(vrtc->vm, "RTC divider out of reset at %#lx/%#lx",
736 VM_CTR2(vrtc->vm, "RTC reg_a changed from %#x to %#x",
762 VM_CTR2(vrtc->vm, "Error %d setting RTC time to %#lx", error,
765 VM_CTR1(vrtc->vm, "RTC time set to %#lx", secs);
795 * Don't allow writes to RTC control registers or the date/time fields.
799 VM_CTR1(vrtc->vm, "RTC nvram write to invalid offset %d",
807 VM_CTR2(vrtc->vm, "RTC nvram write %#x to offset %#x", value, offset);
822 * Allow all offsets in the RTC to be read.
831 * Update RTC date/time fields if necessary.
871 struct rtcdev *rtc;
877 rtc = &vrtc->rtcdev;
894 * Update RTC date/time fields if necessary.
896 * This is not just for reads of the RTC. The side-effect of writing
897 * the century byte requires other RTC date/time fields (e.g. sec)
913 *val = *((uint8_t *)rtc + offset);
915 VM_CTR2(vm, "Read value %#x from RTC offset %#x",
920 VM_CTR1(vm, "RTC reg_a set to %#x", *val);
924 VM_CTR1(vm, "RTC reg_b set to %#x", *val);
928 VM_CTR1(vm, "RTC reg_c set to %#x (ignored)",
932 VM_CTR1(vm, "RTC reg_d set to %#x (ignored)",
942 VM_CTR2(vm, "RTC offset %#x set to %#x",
944 *((uint8_t *)rtc + offset) = *val;
950 * outside of RTCSB_HALT so re-calculate the RTC date/time.
967 struct rtcdev *rtc;
971 rtc = &vrtc->rtcdev;
972 vrtc_set_reg_b(vrtc, rtc->reg_b & ~(RTCSB_ALL_INTRS | RTCSB_SQWE));
974 KASSERT(!callout_active(&vrtc->callout), ("rtc callout still active"));
983 struct rtcdev *rtc;
992 rtc = &vrtc->rtcdev;
993 rtc->reg_a = 0x20;
994 rtc->reg_b = RTCSB_24HR;
995 rtc->reg_c = 0;
996 rtc->reg_d = RTCSD_PWR;
1002 * Initialize RTC time to 00:00:00 Jan 1, 1970.