source: mainline/kernel/arch/sparc64/src/drivers/tick.c@ 63e27ef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 63e27ef was 63e27ef, checked in by Jiri Svoboda <jiri@…>, 8 years ago

ASSERT → assert

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[39494010]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Jermar
[39494010]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[d46f5cc]29/** @addtogroup sparc64
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[39494010]35#include <arch/drivers/tick.h>
36#include <arch/interrupt.h>
[ec443d5]37#include <arch/trap/interrupt.h>
[b3f8fb7]38#include <arch/sparc64.h>
[39494010]39#include <arch/asm.h>
40#include <arch/register.h>
[9a5b556]41#include <arch/cpu.h>
42#include <arch/boot/boot.h>
43#include <time/clock.h>
44#include <arch.h>
[63e27ef]45#include <assert.h>
[9a5b556]46
[965dc18]47/** Initialize tick and stick interrupt. */
[39494010]48void tick_init(void)
49{
[965dc18]50 /* initialize TICK interrupt */
[39494010]51 tick_compare_reg_t compare;
[adfdbd5]52 softint_reg_t clear;
[965dc18]53
[39494010]54 compare.int_dis = false;
[b4655da]55 compare.tick_cmpr = tick_counter_read() +
56 CPU->arch.clock_frequency / HZ;
[2a0cda72]57 CPU->arch.next_tick_cmpr = compare.tick_cmpr;
[39494010]58 tick_compare_write(compare.value);
[965dc18]59
[adfdbd5]60 clear.value = 0;
61 clear.tick_int = 1;
62 clear_softint_write(clear.value);
63
[b4655da]64#if defined (US3) || defined (SUN4V)
[965dc18]65 /* disable STICK interrupts and clear any pending ones */
66 tick_compare_reg_t stick_compare;
67
68 stick_compare.value = stick_compare_read();
69 stick_compare.int_dis = true;
70 stick_compare.tick_cmpr = 0;
71 stick_compare_write(stick_compare.value);
72
73 clear.value = 0;
74 clear.stick_int = 1;
75 clear_softint_write(clear.value);
76#endif
[39494010]77}
78
[1120276]79/** Process tick interrupt.
80 *
[ec443d5]81 * @param n Trap type (0x4e, can be ignored)
[25d7709]82 * @param istate Interrupted state.
[d46f5cc]83 *
[1120276]84 */
[d46f5cc]85void tick_interrupt(unsigned int n, istate_t *istate)
[39494010]86{
[1120276]87 softint_reg_t softint, clear;
[2a0cda72]88 uint64_t drift;
[965dc18]89
[1120276]90 softint.value = softint_read();
91
92 /*
93 * Make sure we are servicing interrupt_level_14
94 */
[63e27ef]95 assert(n == TT_INTERRUPT_LEVEL_14);
[1120276]96
97 /*
98 * Make sure we are servicing TICK_INT.
99 */
[63e27ef]100 assert(softint.tick_int);
[1120276]101
102 /*
103 * Clear tick interrupt.
104 */
105 clear.value = 0;
106 clear.tick_int = 1;
107 clear_softint_write(clear.value);
108
109 /*
[2a0cda72]110 * Reprogram the compare register.
111 * For now, we can ignore the potential of the registers to overflow.
112 * On a 360MHz Ultra 60, the 63-bit compare counter will overflow in
113 * about 812 years. If there was a 2GHz UltraSPARC computer, it would
114 * overflow only in 146 years.
[1120276]115 */
[b4655da]116 drift = tick_counter_read() - CPU->arch.next_tick_cmpr;
[2a0cda72]117 while (drift > CPU->arch.clock_frequency / HZ) {
118 drift -= CPU->arch.clock_frequency / HZ;
[9a5b556]119 CPU->missed_clock_ticks++;
120 }
[b4655da]121 CPU->arch.next_tick_cmpr = tick_counter_read() +
[f619ec11]122 (CPU->arch.clock_frequency / HZ) - drift;
[2a0cda72]123 tick_compare_write(CPU->arch.next_tick_cmpr);
[1120276]124 clock();
[39494010]125}
[b45c443]126
[f9a56c0]127/** @}
[b45c443]128 */
Note: See TracBrowser for help on using the repository browser.