/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Glue for the Peripheral Channel Controller timers and the
* Mostek clock chip found on the MVME-147.
*/
/*
* There's no way to latch the counter and overflow registers
* without pausing the clock, so compensate for the possible
* race by checking for counter wrap-around and re-reading the
* overflow counter if necessary.
*
* Note: This only works because we're at splhigh().
*/
tc1 = pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT);
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
tc2 = pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT);
if (tc1 > tc2) {
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
tc1 = tc2;
}
cnt = clock_pcc_count;
splx(s);
/* XXX assume HZ == 100 */
cnt += (tc1 - clock_pcc_reload) +
(PCC_TIMERFREQ / 100) * (cr >> PCC_TIMEROVFLSHIFT);
return cnt;
}
int
clock_pcc_profintr(void *frame)
{
uint8_t cr;
uint16_t tc;
int s;