1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// var_misc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL implementation miscellaneous functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): jskov
|
44 |
|
|
// Contributors: jskov, gthomas
|
45 |
|
|
// Date: 2000-02-04
|
46 |
|
|
// Purpose: HAL miscellaneous functions
|
47 |
|
|
// Description: This file contains miscellaneous functions provided by the
|
48 |
|
|
// HAL.
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/hal.h>
|
55 |
|
|
|
56 |
|
|
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
|
57 |
|
|
#include <cyg/hal/ppc_regs.h>
|
58 |
|
|
#include <cyg/infra/cyg_type.h>
|
59 |
|
|
|
60 |
|
|
#include <cyg/hal/hal_mem.h>
|
61 |
|
|
|
62 |
|
|
void hal_ppc40x_clock_initialize(cyg_uint32 period);
|
63 |
|
|
|
64 |
|
|
//--------------------------------------------------------------------------
|
65 |
|
|
void hal_variant_init(void)
|
66 |
|
|
{
|
67 |
|
|
// Initialize real-time clock (for delays, etc, even if kernel doesn't use it)
|
68 |
|
|
hal_ppc40x_clock_initialize(CYGNUM_HAL_RTC_PERIOD);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
//--------------------------------------------------------------------------
|
73 |
|
|
// Variant specific idle thread action.
|
74 |
|
|
bool
|
75 |
|
|
hal_variant_idle_thread_action( cyg_uint32 count )
|
76 |
|
|
{
|
77 |
|
|
// Let architecture idle thread action run
|
78 |
|
|
return true;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
//---------------------------------------------------------------------------
|
82 |
|
|
// Use MMU resources to map memory regions.
|
83 |
|
|
// Takes and returns an int used to ID the MMU resource to use. This ID
|
84 |
|
|
// is increased as resources are used and should be used for subsequent
|
85 |
|
|
// invocations.
|
86 |
|
|
//
|
87 |
|
|
// The PPC4xx CPUs do not have BATs. Fortunately we don't currently
|
88 |
|
|
// use the MMU, so we can simulate BATs by using the TLBs.
|
89 |
|
|
int
|
90 |
|
|
cyg_hal_map_memory (int id, CYG_ADDRESS virt, CYG_ADDRESS phys,
|
91 |
|
|
cyg_int32 size, cyg_uint8 flags)
|
92 |
|
|
{
|
93 |
|
|
cyg_uint32 epn, rpn;
|
94 |
|
|
int sv, lv, max_tlbs;
|
95 |
|
|
|
96 |
|
|
// There are 64 TLBs.
|
97 |
|
|
max_tlbs = 64;
|
98 |
|
|
|
99 |
|
|
// Use the smallest "size" value which is big enough (round up)
|
100 |
|
|
for (sv = 0, lv = 0x400; sv < 8; sv++, lv <<= 2) {
|
101 |
|
|
if (lv >= size) break;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
// Note: the process ID comes from the PID register (always 0)
|
105 |
|
|
epn = (virt & M_EPN_EPNMASK) | M_EPN_EV | M_EPN_SIZE(sv);
|
106 |
|
|
rpn = (phys & M_RPN_RPNMASK) | M_RPN_EX | M_RPN_WR;
|
107 |
|
|
|
108 |
|
|
if (flags & CYGARC_MEMDESC_CI) {
|
109 |
|
|
rpn |= M_RPN_I;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
if (flags & CYGARC_MEMDESC_GUARDED)
|
113 |
|
|
rpn |= M_RPN_G;
|
114 |
|
|
|
115 |
|
|
CYGARC_TLBWE(id, epn, rpn);
|
116 |
|
|
id++;
|
117 |
|
|
|
118 |
|
|
// Make caches default disabled when MMU is disabled.
|
119 |
|
|
|
120 |
|
|
return id;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
// Initialize MMU to a sane (NOP) state.
|
125 |
|
|
//
|
126 |
|
|
// Initialize TLBs with 0, Valid bits unset.
|
127 |
|
|
void
|
128 |
|
|
cyg_hal_clear_MMU (void)
|
129 |
|
|
{
|
130 |
|
|
cyg_uint32 tlbhi = 0;
|
131 |
|
|
cyg_uint32 tlblo = 0;
|
132 |
|
|
int id, max_tlbs;
|
133 |
|
|
|
134 |
|
|
// There are 64 TLBs.
|
135 |
|
|
max_tlbs = 64;
|
136 |
|
|
|
137 |
|
|
CYGARC_MTSPR (SPR_PID, 0);
|
138 |
|
|
|
139 |
|
|
for (id = 0; id < max_tlbs; id++) {
|
140 |
|
|
CYGARC_TLBWE(id, tlbhi, tlblo);
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
//--------------------------------------------------------------------------
|
145 |
|
|
// Clock control - use the programmable (variable period) timer
|
146 |
|
|
|
147 |
|
|
static cyg_uint32 _period;
|
148 |
|
|
extern cyg_uint32 _hold_tcr; // Shadow of TCR register which can't be read
|
149 |
|
|
|
150 |
|
|
void
|
151 |
|
|
hal_ppc40x_clock_initialize(cyg_uint32 period)
|
152 |
|
|
{
|
153 |
|
|
cyg_uint32 tcr;
|
154 |
|
|
|
155 |
|
|
// Enable auto-reload
|
156 |
|
|
CYGARC_MFSPR(SPR_TCR, tcr);
|
157 |
|
|
tcr = _hold_tcr;
|
158 |
|
|
tcr |= TCR_ARE;
|
159 |
|
|
CYGARC_MTSPR(SPR_TCR, tcr);
|
160 |
|
|
_hold_tcr = tcr;
|
161 |
|
|
|
162 |
|
|
// Set up the counter register
|
163 |
|
|
_period = period;
|
164 |
|
|
CYGARC_MTSPR(SPR_PIT, period);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
// Returns the number of clocks since the last interrupt
|
168 |
|
|
externC void
|
169 |
|
|
hal_ppc40x_clock_read(cyg_uint32 *val)
|
170 |
|
|
{
|
171 |
|
|
cyg_uint32 cur_val;
|
172 |
|
|
|
173 |
|
|
CYGARC_MFSPR(SPR_PIT, cur_val);
|
174 |
|
|
*val = _period - cur_val;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
externC void
|
178 |
|
|
hal_ppc40x_clock_reset(cyg_uint32 vector, cyg_uint32 period)
|
179 |
|
|
{
|
180 |
|
|
hal_ppc40x_clock_initialize(period);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
//
|
184 |
|
|
// Delay for the specified number of microseconds.
|
185 |
|
|
// Assumption: _period has been set already and corresponds to the
|
186 |
|
|
// system clock frequency, normally 10ms.
|
187 |
|
|
//
|
188 |
|
|
|
189 |
|
|
externC void
|
190 |
|
|
hal_ppc40x_delay_us(int us)
|
191 |
|
|
{
|
192 |
|
|
cyg_uint32 delay_period, delay, diff;
|
193 |
|
|
cyg_uint32 pit_val1, pit_val2;
|
194 |
|
|
|
195 |
|
|
delay_period = (_period * us) / 10000;
|
196 |
|
|
delay = 0;
|
197 |
|
|
CYGARC_MFSPR(SPR_PIT, pit_val1);
|
198 |
|
|
while (delay < delay_period) {
|
199 |
|
|
// Wait for clock to "tick"
|
200 |
|
|
while (true) {
|
201 |
|
|
CYGARC_MFSPR(SPR_PIT, pit_val2);
|
202 |
|
|
if (pit_val2 != pit_val1) break;
|
203 |
|
|
}
|
204 |
|
|
if (pit_val2 > pit_val1) {
|
205 |
|
|
diff = pit_val2 - pit_val1;
|
206 |
|
|
} else {
|
207 |
|
|
diff = (pit_val2 + _period) - pit_val1;
|
208 |
|
|
}
|
209 |
|
|
delay += diff;
|
210 |
|
|
pit_val1 = pit_val2;
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
//--------------------------------------------------------------------------
|
215 |
|
|
// End of var_misc.c
|