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

4.115
Last change on this file since 71d97c9 was 71d97c9, checked in by Gedare Bloom <gedare@…>, on 12/08/14 at 18:16:37

sparc64: put each copyright on one line

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