source: mainline/kernel/arch/ia64/src/drivers/it.c

Last change on this file was 4760793, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 18 months ago

Add CPU_LOCAL alongside CPU and segregate fields that are only used locally

This makes it more clear which fields can be used without synchronization
and which need more care.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
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
29/** @addtogroup kernel_ia64
30 * @{
31 */
32/** @file
33 */
34
35/** Interval Timer driver. */
36
37#include <arch/drivers/it.h>
38#include <arch/interrupt.h>
39#include <arch/register.h>
40#include <arch/asm.h>
41#include <barrier.h>
42#include <time/clock.h>
43#include <ddi/irq.h>
44#include <arch.h>
45
46#define IT_SERVICE_CLOCKS 64
47
48#define FREQ_NUMERATOR_SHIFT 32
49#define FREQ_NUMERATOR_MASK 0xffffffff00000000ULL
50
51#define FREQ_DENOMINATOR_SHIFT 0
52#define FREQ_DENOMINATOR_MASK 0xffffffffULL
53
54uint64_t it_delta;
55
56static irq_t it_irq;
57
58static irq_ownership_t it_claim(irq_t *);
59static void it_interrupt(irq_t *);
60
61/** Initialize Interval Timer. */
62void it_init(void)
63{
64 if (config.cpu_active == 1) {
65 irq_initialize(&it_irq);
66 it_irq.inr = INTERRUPT_TIMER;
67 it_irq.claim = it_claim;
68 it_irq.handler = it_interrupt;
69 irq_register(&it_irq);
70
71 uint64_t base_freq;
72 base_freq = ((bootinfo->freq_scale) & FREQ_NUMERATOR_MASK) >>
73 FREQ_NUMERATOR_SHIFT;
74 base_freq *= bootinfo->sys_freq;
75 base_freq /= ((bootinfo->freq_scale) & FREQ_DENOMINATOR_MASK) >>
76 FREQ_DENOMINATOR_SHIFT;
77
78 it_delta = base_freq / HZ;
79 }
80
81 /* Initialize Interval Timer external interrupt vector */
82 cr_itv_t itv;
83
84 itv.value = itv_read();
85 itv.vector = INTERRUPT_TIMER;
86 itv.m = 0;
87 itv_write(itv.value);
88
89 /* Set Interval Timer Counter to zero */
90 itc_write(0);
91
92 /* Generate first Interval Timer interrupt in IT_DELTA ticks */
93 itm_write(IT_DELTA);
94
95 /* Propagate changes */
96 srlz_d();
97}
98
99/** Always claim ownership for this IRQ.
100 *
101 * Other devices are responsible to avoid using INR 0.
102 *
103 * @return Always IRQ_ACCEPT.
104 *
105 */
106irq_ownership_t it_claim(irq_t *irq)
107{
108 return IRQ_ACCEPT;
109}
110
111/** Process Interval Timer interrupt. */
112void it_interrupt(irq_t *irq)
113{
114 eoi_write(EOI);
115
116 int64_t itm = itm_read();
117
118 while (true) {
119 int64_t itc = itc_read();
120 itc += IT_SERVICE_CLOCKS;
121
122 itm += IT_DELTA;
123 if (itm - itc < 0)
124 CPU_LOCAL->missed_clock_ticks++;
125 else
126 break;
127 }
128
129 itm_write(itm);
130 srlz_d(); /* Propagate changes */
131
132 /*
133 * We are holding a lock which prevents preemption.
134 * Release the lock, call clock() and reacquire the lock again.
135 */
136 irq_spinlock_unlock(&irq->lock, false);
137 clock();
138 irq_spinlock_lock(&irq->lock, false);
139}
140
141/** @}
142 */
Note: See TracBrowser for help on using the repository browser.