source: rtems/c/src/lib/libbsp/sparc64/shared/clock/ckinit.c @ 436008c

5
Last change on this file since 436008c was 436008c, checked in by Joel Sherrill <joel@…>, on 04/24/17 at 01:34:42

sparc64/shared/clock/ckinit.c: Include <rtems/bspIo.h>

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*  ckinit.c
2 *
3 *  This file provides a template for the clock device driver initialization.
4 *
5 *  Modified for sun4v - niagara
6 */
7
8/*
9 *  Copyright (c) 2010 Gedare Bloom.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#include <stdlib.h>
17
18#include <rtems.h>
19#include <bsp.h>
20#include <bspopts.h>
21#include <boot/ofw.h>
22#include <rtems/bspIo.h>
23
24/* This is default frequency for simics simulator of niagara. Use the
25 * get_Frequency function to determine the CPU clock frequency at runtime.
26 */
27#define CPU_FREQ (5000000)
28
29uint64_t sparc64_cycles_per_tick;
30
31/* TICK_CMPR and STICK_CMPR trigger soft interrupt 14 */
32#define CLOCK_VECTOR SPARC_SYNCHRONOUS_TRAP(0x4E)
33
34static unsigned int get_Frequency(void)
35{
36  phandle root = ofw_find_device("/");
37  unsigned int freq;
38
39  if (ofw_get_property(root, "clock-frequency", &freq, sizeof(freq)) <= 0) {
40    printk("Unable to determine frequency, default: 0x%x\n",CPU_FREQ);
41    return CPU_FREQ;
42  }
43
44  return freq;
45}
46
47#define Clock_driver_support_at_tick() \
48  Clock_driver_support_at_tick_helper()
49
50static void Clock_driver_support_at_tick_helper(void)
51{
52  uint64_t tick_reg;
53  int bit_mask;
54  uint64_t pil_reg;
55
56  bit_mask = SPARC_SOFTINT_TM_MASK | SPARC_SOFTINT_SM_MASK | (1<<14);
57  sparc64_clear_interrupt_bits(bit_mask);
58
59  sparc64_get_pil(pil_reg);
60  if(pil_reg == 0xe) { /* 0xe is the tick compare interrupt (softint(14)) */
61    pil_reg--;
62    sparc64_set_pil(pil_reg); /* enable the next timer interrupt */
63  }
64  /* Note: sun4v uses stick_cmpr for clock driver for M5 simulator, which
65   * does not currently have tick_cmpr implemented */
66  /* TODO: this could be more efficiently implemented as a single assembly
67   * inline */
68#if defined (SUN4U)
69  sparc64_read_tick(tick_reg);
70#elif defined (SUN4V)
71  sparc64_read_stick(tick_reg);
72#endif
73  tick_reg &= ~(1UL<<63); /* mask out NPT bit, prevents int_dis from being set */
74
75  tick_reg += sparc64_cycles_per_tick;
76
77#if defined (SUN4U)
78  sparc64_write_tick_cmpr(tick_reg);
79#elif defined (SUN4V)
80  sparc64_write_stick_cmpr(tick_reg);
81#endif
82}
83
84#define Clock_driver_support_install_isr(_new, _old) \
85  do { \
86    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
87  } while ( 0 )
88
89static void Clock_driver_support_initialize_hardware(void)
90{
91  uint64_t tick_reg;
92  int bit_mask;
93
94  bit_mask = SPARC_SOFTINT_TM_MASK | SPARC_SOFTINT_SM_MASK | (1<<14);
95  sparc64_clear_interrupt_bits(bit_mask);
96
97  sparc64_cycles_per_tick =
98    rtems_configuration_get_microseconds_per_tick()*(get_Frequency()/1000000);
99
100#if defined (SUN4U)
101  sparc64_read_tick(tick_reg);
102#elif defined (SUN4V)
103  sparc64_read_stick(tick_reg);
104#endif
105
106  tick_reg &= ~(1UL<<63); /* mask out NPT bit, prevents int_dis from being set */
107  tick_reg += sparc64_cycles_per_tick;
108
109#if defined (SUN4U)
110  sparc64_write_tick_cmpr(tick_reg);
111#elif defined (SUN4V)
112  sparc64_write_stick_cmpr(tick_reg);
113#endif
114}
115
116#define Clock_driver_support_shutdown_hardware( ) \
117  do { \
118    \
119  } while ( 0 )
120
121#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
122
123#include "../../../shared/clockdrv_shell.h"
124
Note: See TracBrowser for help on using the repository browser.