todpc_subr.c revision 8500cbf9b5297326cb6b4abec139e8784dcd5ee5
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
#include <sys/archsystm.h>
#include <sys/sysmacros.h>
#include <sys/lockstat.h>
static int todpc_rtcget(unsigned char *buf);
static void todpc_rtcput(unsigned char *buf);
/*
* The minimum sleep time till an alarm can be fired.
* there is a danger that it will be missed if it takes too long to
* get from the set point to sleep. Or that it can fire quickly, and
* generate a power spike on the hardware. And small values are
* probably only usefull for test setups.
*/
int clock_min_alarm = 4;
/*
* Machine-dependent clock routines.
*/
extern long gmt_lag;
struct rtc_offset {
};
static struct rtc_offset pc_rtc_offset = {0, 0, 0, 0};
/*
* Entry point for ACPI to pass RTC or other clock values that
* are useful to TOD.
*/
void
int ok = 0;
/*
* ASSERT is for debugging, but we don't want the machine
* falling over because for some reason we didn't get a valid
* pointer.
*/
return;
}
ok = 1;
}
if (fadt->MonthAlarm) {
ok = 1;
}
ok = 1;
}
}
/*
* Write the specified time into the clock chip.
* Must be called with tod_lock held.
*/
/*ARGSUSED*/
static void
{
if (todpc_rtcget((unsigned char *)&rtc))
return;
/*
* rtc bytes are in binary-coded decimal, so we have to convert.
* We assume that we wrap the rtc year back to zero at 2000.
*/
/* LINTED: YRBASE = 0 for x86 */
} else
/* dow < 10, so no conversion */
todpc_rtcput((unsigned char *)&rtc);
}
/*
* Read the current time from the clock chip and convert to UNIX form.
* Assumes that the year in the clock chip is valid.
* Must be called with tod_lock held.
*/
/*ARGSUSED*/
static timestruc_t
{
int compute_century;
static int range_warn = 1;
if (todpc_rtcget((unsigned char *)&rtc)) {
return (hrestime);
}
/* assume that we wrap the rtc year back to zero at 2000 */
"of range -- time needs to be reset");
range_warn = 0;
}
compute_century = 20;
} else {
/* LINTED: YRBASE = 0 for x86 */
compute_century = 19;
}
"The hardware real-time clock appears to have the "
"wrong century: %d.\nSolaris will still operate "
"not.\nUse date(1) to set the date to the current "
"time to correct the RTC.",
century_warn = 0;
}
/* read was successful so ensure failure flag is clear */
return (ts);
}
/*
* Write the specified wakeup alarm into the clock chip.
* Must be called with tod_lock held.
*/
void
/*ARGSUSED*/
{
/* A delay of zero is not allowed */
if (nsecs == 0)
return;
/* Make sure that we delay no less than the minimum time */
if (nsecs < clock_min_alarm)
if (todpc_rtcget((unsigned char *)&rtc))
return;
/*
* Compute alarm secs, mins and hrs, and where appropriate, dom
* and mon. rtc bytes are in binary-coded decimal, so we have
* to convert.
*/
prom_printf("No day alarm - set to end of today!\n");
asec = 59;
amin = 59;
ahr = 23;
} else {
static int dpm[] =
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (mon_alrm == 0) {
prom_printf("No mon alarm - "
"set to end of current month!\n");
asec = 59;
amin = 59;
ahr = 23;
}
} else {
}
if (amon > 12) {
prom_printf("Alarm too far in future - "
"set to end of current year!\n");
asec = 59;
amin = 59;
ahr = 23;
amon = 12;
}
}
}
todpc_rtcput((unsigned char *)&rtc);
}
/*
* Clear an alarm. This is effectively setting an alarm of 0.
*/
void
/*ARGSUSED*/
{
todpc_setalarm(top, 0);
}
/*
* Routine to read contents of real time clock to the specified buffer.
* Returns ENXIO if clock not valid, or EAGAIN if clock data cannot be read
* else 0.
* The routine will busy wait for the Update-In-Progress flag to clear.
* On completion of the reads the Seconds register is re-read and the
* UIP flag is rechecked to confirm that an clock update did not occur
* during the accesses. Routine will error exit after 256 attempts.
* (See bugid 1158298.)
* Routine returns RTC_NREG (which is 15) bytes of data, as given in the
* technical reference. This data includes both time and status registers.
*/
static int
todpc_rtcget(unsigned char *buf)
{
unsigned char reg;
int i;
int retries = 256;
unsigned char *rawp;
unsigned char century = RTC_CENTURY;
unsigned char day_alrm;
unsigned char mon_alrm;
if (pc_rtc_offset.century != 0) {
}
return (ENXIO);
if (retries-- < 0)
return (EAGAIN);
tenmicrosec();
goto checkuip;
}
}
if (day_alrm > 0) {
}
if (mon_alrm > 0) {
}
/* update occured during reads */
goto checkuip;
return (0);
}
/*
* This routine writes the contents of the given buffer to the real time
* clock. It is given RTC_NREGP bytes of data, which are the 10 bytes used
* to write the time and set the alarm. It should be called with the priority
* raised to 5.
*/
static void
todpc_rtcput(unsigned char *buf)
{
unsigned char reg;
int i;
unsigned char century = RTC_CENTURY;
unsigned char tmp;
if (pc_rtc_offset.century != 0) {
}
for (i = 0; i < RTC_NREGP; i++) { /* set the time */
}
if (day_alrm > 0) {
/* preserve RTC_VRT bit; some virt envs accept writes there */
}
if (mon_alrm > 0) {
}
}
NULL,
NULL,
};
/*
* Initialize for the default TOD ops vector for use on hardware.
*/