OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [mpc8xx/] [v2_0/] [src/] [var_misc.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
// Copyright (C) 2002 Gary Thomas
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License along
24
// with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
//
27
// As a special exception, if other files instantiate templates or use macros
28
// or inline functions from this file, or you compile this file and link it
29
// with other works to produce a work based on this file, this file does not
30
// by itself cause the resulting work to be covered by the GNU General Public
31
// License. However the source code for this file must still be made available
32
// in accordance with section (3) of the GNU General Public License.
33
//
34
// This exception does not invalidate any other reasons why a work based on
35
// this file might be covered by the GNU General Public License.
36
//
37
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38
// at http://sources.redhat.com/ecos/ecos-license/
39
// -------------------------------------------
40
//####ECOSGPLCOPYRIGHTEND####
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    jskov
45
// Contributors: jskov, gthomas
46
// Date:         2000-02-04
47
// Purpose:      HAL miscellaneous functions
48
// Description:  This file contains miscellaneous functions provided by the
49
//               HAL.
50
//
51
//####DESCRIPTIONEND####
52
//
53
//==========================================================================
54
 
55
#include <pkgconf/hal.h>
56
 
57
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
58
#include <cyg/hal/ppc_regs.h>
59
#include <cyg/infra/cyg_type.h>         // types
60
#include <cyg/infra/diag.h>             // diag_printf
61
 
62
#include <cyg/hal/hal_mem.h>            // some of the functions defined here
63
 
64
//--------------------------------------------------------------------------
65
void
66
hal_variant_init(void)
67
{
68
    // Disable serialization
69
    {
70
        cyg_uint32 ictrl;
71
        CYGARC_MFSPR (ICTRL, ictrl);
72
        ictrl |= ICTRL_NOSERSHOW;
73
        CYGARC_MTSPR (ICTRL, ictrl);
74
    }
75
}
76
 
77
//--------------------------------------------------------------------------
78
// Variant specific idle thread action.
79
bool
80
hal_variant_idle_thread_action( cyg_uint32 count )
81
{
82
#if 0
83
    cyg_uint32 *psivec  = (cyg_uint32*)CYGARC_REG_IMM_SIVEC ;
84
    cyg_uint32 *psimask = (cyg_uint32*)CYGARC_REG_IMM_SIMASK;
85
    cyg_uint32 *psipend = (cyg_uint32*)CYGARC_REG_IMM_SIPEND;
86
    cyg_uint16 *ptbscr =  (cyg_uint16*)CYGARC_REG_IMM_TBSCR;
87
 
88
    diag_printf( "TBSCR %04x, vec %d: sivec %08x, simask %08x, sipend %08x\n",
89
                 (cyg_uint32)(*ptbscr), (*psivec)>>26, *psivec,
90
                 *psimask, *psipend );
91
#endif
92
 
93
    // Let architecture idle thread action run
94
    return true;
95
}
96
 
97
//---------------------------------------------------------------------------
98
// Use MMU resources to map memory regions.  
99
// Takes and returns an int used to ID the MMU resource to use. This ID
100
// is increased as resources are used and should be used for subsequent
101
// invocations.
102
//
103
// The MPC8xx CPUs do not have BATs. Fortunately we don't currently
104
// use the MMU, so we can simulate BATs by using the TLBs.
105
int
106
cyg_hal_map_memory (int id,CYG_ADDRESS virt, CYG_ADDRESS phys,
107
                    cyg_int32 size, cyg_uint8 flags)
108
{
109
    cyg_uint32 epn, rpn, twc, ctr = 0;
110
    int max_tlbs;
111
 
112
#if defined(CYGPKG_HAL_POWERPC_MPC860)
113
    // There are 32 TLBs.
114
    max_tlbs = 32;
115
#elif defined(CYGPKG_HAL_POWERPC_MPC823) || defined(CYGPKG_HAL_POWERPC_MPC850)
116
    // There are 8 TLBs.
117
    max_tlbs = 8;
118
#endif
119
 
120
    epn = (virt & MI_EPN_EPNMASK) | MI_EPN_EV;
121
    rpn = ((phys & MI_RPN_RPNMASK)
122
           | MI_RPN_PPRWRW | MI_RPN_LPS | MI_RPN_SH | MI_RPN_V);
123
    if (flags & CYGARC_MEMDESC_CI)
124
        rpn |= MI_RPN_CI;
125
 
126
    twc = MI_TWC_PS8MB | MI_TWC_V;
127
    if (flags & CYGARC_MEMDESC_GUARDED)
128
        twc |= MI_TWC_G;
129
 
130
    // Ignore attempts to use more than max_tlbs.
131
    while (id < max_tlbs && size > 0) {
132
        ctr = id << MI_CTR_INDX_SHIFT;
133
 
134
        // Instruction TLB.
135
        CYGARC_MTSPR (MI_TWC, twc);
136
        CYGARC_MTSPR (MI_CTR, ctr);
137
        CYGARC_MTSPR (MI_EPN, epn);
138
        CYGARC_MTSPR (MI_RPN, rpn);
139
 
140
        // Data TLB.
141
        {
142
            cyg_uint32 drpn;
143
 
144
            // Need to mark data page as changed or an exception
145
            // will be generated on first write to the page.
146
            drpn = rpn | MD_RPN_CHANGED;
147
 
148
            CYGARC_MTSPR (MD_TWC, twc);
149
            CYGARC_MTSPR (MD_CTR, ctr);
150
            CYGARC_MTSPR (MD_EPN, epn);
151
            CYGARC_MTSPR (MD_RPN, drpn);
152
        }
153
 
154
        // Move to next 8MB block.
155
        size -= 8*1024*1024;
156
        epn  += 8*1024*1024;
157
        rpn  += 8*1024*1024;
158
        id++;
159
    }
160
 
161
    // Make caches default disabled when MMU is disabled.
162
    CYGARC_MTSPR (MI_CTR, ctr | CYGARC_REG_MI_CTR_CIDEF);
163
    CYGARC_MTSPR (MD_CTR, ctr | CYGARC_REG_MD_CTR_CIDEF);
164
 
165
    return id;
166
}
167
 
168
 
169
// Initialize MMU to a sane (NOP) state.
170
//
171
// Initialize TLBs with 0, Valid bits unset.
172
void
173
cyg_hal_clear_MMU (void)
174
{
175
    cyg_uint32 ctr = 0;
176
    int id;
177
    int max_tlbs;
178
 
179
#if defined(CYGPKG_HAL_POWERPC_MPC860)
180
    // There are 32 TLBs.
181
    max_tlbs = 32;
182
#elif defined(CYGPKG_HAL_POWERPC_MPC823) || defined(CYGPKG_HAL_POWERPC_MPC850)
183
    // There are 8 TLBs.
184
    max_tlbs = 8;
185
#endif
186
 
187
    CYGARC_MTSPR (M_CASID, 0);
188
 
189
    for (id = 0; id < max_tlbs; id++) {
190
        ctr = id << MI_CTR_INDX_SHIFT;
191
 
192
        // Instruction TLBs.
193
        CYGARC_MTSPR (MI_TWC, 0);
194
        CYGARC_MTSPR (MI_CTR, ctr);
195
        CYGARC_MTSPR (MI_EPN, 0);
196
        CYGARC_MTSPR (MI_RPN, 0);
197
        // Data TLBs.
198
        CYGARC_MTSPR (MD_TWC, 0);
199
        CYGARC_MTSPR (MD_CTR, ctr);
200
        CYGARC_MTSPR (MD_EPN, 0);
201
        CYGARC_MTSPR (MD_RPN, 0);
202
    }
203
 
204
    // Make caches default disabled when MMU is disabled.
205
    CYGARC_MTSPR (MI_CTR, ctr | CYGARC_REG_MI_CTR_CIDEF);
206
    CYGARC_MTSPR (MD_CTR, ctr | CYGARC_REG_MD_CTR_CIDEF);
207
}
208
 
209
#ifdef CYGPKG_PROFILE_GPROF
210
//--------------------------------------------------------------------------
211
//
212
// Profiling support - uses a separate high-speed timer
213
//
214
 
215
#include <cyg/hal/hal_arch.h>
216
#include <cyg/hal/hal_intr.h>
217
#include <cyg/hal/quicc/ppc8xx.h>
218
#include <cyg/profile/profile.h>
219
 
220
// Can't rely on Cyg_Interrupt class being defined.
221
#define Cyg_InterruptHANDLED 1
222
 
223
#define PIT_IRQ_LEVEL 4
224
#define PIT_IRQ CYGNUM_HAL_INTERRUPT_SIU_LVL4
225
#define ID_PIT       34512
226
 
227
 
228
// Periodic timer ISR.
229
static cyg_uint32
230
isr_pit(CYG_ADDRWORD vector, CYG_ADDRWORD data, HAL_SavedRegisters *regs)
231
{
232
 
233
    HAL_INTERRUPT_ACKNOWLEDGE (CYGNUM_HAL_INTERRUPT_SIU_PIT);
234
    __profile_hit(regs->pc);
235
 
236
    return Cyg_InterruptHANDLED;
237
}
238
 
239
void
240
hal_enable_profile_timer(int resolution)
241
{
242
    // Run periodic timer interrupt for profile 
243
    cyg_uint16 piscr;
244
    int period = resolution / 100;
245
 
246
    // Attach pit arbiter.
247
    HAL_INTERRUPT_ATTACH (PIT_IRQ,
248
                          &hal_arbitration_isr_pit, ID_PIT, 0);
249
    HAL_INTERRUPT_UNMASK (PIT_IRQ);
250
 
251
    // Attach pit isr.
252
    HAL_INTERRUPT_ATTACH (CYGNUM_HAL_INTERRUPT_SIU_PIT, &isr_pit,
253
                          ID_PIT, 0);
254
    HAL_INTERRUPT_SET_LEVEL (CYGNUM_HAL_INTERRUPT_SIU_PIT, PIT_IRQ_LEVEL);
255
    HAL_INTERRUPT_UNMASK (CYGNUM_HAL_INTERRUPT_SIU_PIT);
256
 
257
 
258
    // Set period.
259
    HAL_WRITE_UINT32 (CYGARC_REG_IMM_PITC,
260
                      (2*period) << CYGARC_REG_IMM_PITC_COUNT_SHIFT);
261
 
262
    // Enable.
263
    HAL_READ_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
264
    piscr |= CYGARC_REG_IMM_PISCR_PTE;
265
    HAL_WRITE_UINT16 (CYGARC_REG_IMM_PISCR, piscr);
266
}
267
#endif
268
 
269
//--------------------------------------------------------------------------
270
// End of var_misc.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.