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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [hal/] [mips/] [mips32/] [v2_0/] [src/] [var_misc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//==========================================================================
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):    nickg
44
// Contributors: nickg, jlarmour, dmoseley
45
// Date:         2000-07-14
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
#include <cyg/infra/cyg_type.h>         // Base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
 
60
#include <cyg/hal/hal_intr.h>
61
 
62
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
63
#include <cyg/hal/hal_arch.h>
64
#include <cyg/hal/var_arch.h>
65
#include <cyg/hal/plf_io.h>
66
#include <cyg/hal/hal_cache.h>
67
 
68
/*------------------------------------------------------------------------*/
69
// Array which stores the configured priority levels for the configured
70
// interrupts.
71
 
72
volatile CYG_BYTE hal_interrupt_level[CYGNUM_HAL_ISR_COUNT];
73
 
74
/*------------------------------------------------------------------------*/
75
 
76
void hal_variant_init(void)
77
{
78
}
79
 
80
/*
81
 * Uncomment the following to allow for dynamic cache sizing.
82
 * Currently we are going to assume the exact part specified in the ecosconfig stuff.
83
 * Perhaps in the near future this can all be done dynamically.
84
 */
85
/* define DYNAMIC_CACHE_SIZING */
86
 
87
#if 0
88
#ifndef DYNAMIC_CACHE_SIZING
89
#warning "                                                                           \n\
90
STILL NEED TO IMPLEMENT DYNAMIC_CACHE_SIZING.                                        \n\
91
ALSO, the HAL_PLATFORM_CPU/etc defines need to be dynamic.                           \n\
92
ALSO, need to do big endian stuff as well.                                           \n\
93
Determine if network debug is necessary.                                             \n\
94
Remove MIPS memc_init code"
95
#endif
96
#endif
97
 
98
/*------------------------------------------------------------------------*/
99
// Initialize the caches
100
 
101
int hal_init_icache(unsigned long config1_val)
102
{
103
#ifdef DYNAMIC_CACHE_SIZING
104
  int icache_linesize, icache_assoc, icache_sets, icache_lines, icache_size;
105
  unsigned long cache_addr;
106
 
107
  switch (config1_val & CONFIG1_IL)
108
    {
109
    case CONFIG1_ICACHE_LINE_SIZE_16_BYTES: icache_linesize = 16;      break;
110
    case CONFIG1_ICACHE_NOT_PRESET:         return -1;                 break;
111
    default:      /* Error */               return -1;                 break;
112
    }
113
 
114
  switch (config1_val & CONFIG1_IA)
115
    {
116
    case CONFIG1_ICACHE_DIRECT_MAPPED:      icache_assoc = 1;          break;
117
    case CONFIG1_ICACHE_2_WAY:              icache_assoc = 2;          break;
118
    case CONFIG1_ICACHE_3_WAY:              icache_assoc = 3;          break;
119
    case CONFIG1_ICACHE_4_WAY:              icache_assoc = 4;          break;
120
    default:      /* Error */               return -1;                 break;
121
    }
122
 
123
  switch (config1_val & CONFIG1_IS)
124
    {
125
    case CONFIG1_ICACHE_64_SETS_PER_WAY:    icache_sets = 64;          break;
126
    case CONFIG1_ICACHE_128_SETS_PER_WAY:   icache_sets = 128;         break;
127
    case CONFIG1_ICACHE_256_SETS_PER_WAY:   icache_sets = 256;         break;
128
    default:      /* Error */               return -1;                 break;
129
    }
130
 
131
  icache_lines = icache_sets * icache_assoc;
132
  icache_size = icache_lines * icache_linesize;
133
#endif /* DYNAMIC_CACHE_SIZING */
134
 
135
  /*
136
   * Reset does not invalidate the cache so let's do so now.
137
   */
138
  HAL_ICACHE_INVALIDATE_ALL();
139
 
140
#ifdef DYNAMIC_CACHE_SIZING
141
  return icache_size;
142
#else
143
  return HAL_ICACHE_SIZE;
144
#endif
145
}
146
 
147
int hal_init_dcache(unsigned long config1_val)
148
{
149
#ifdef DYNAMIC_CACHE_SIZING
150
  int dcache_linesize, dcache_assoc, dcache_sets, dcache_lines, dcache_size;
151
 
152
  switch (config1_val & CONFIG1_DL)
153
    {
154
    case CONFIG1_DCACHE_LINE_SIZE_16_BYTES: dcache_linesize = 16;      break;
155
    case CONFIG1_DCACHE_NOT_PRESET:         return -1;                 break;
156
    default:      /* Error */               return -1;                 break;
157
    }
158
 
159
  switch (config1_val & CONFIG1_DA)
160
    {
161
    case CONFIG1_DCACHE_DIRECT_MAPPED:      dcache_assoc = 1;          break;
162
    case CONFIG1_DCACHE_2_WAY:              dcache_assoc = 2;          break;
163
    case CONFIG1_DCACHE_3_WAY:              dcache_assoc = 3;          break;
164
    case CONFIG1_DCACHE_4_WAY:              dcache_assoc = 4;          break;
165
    default:      /* Error */               return -1;                 break;
166
    }
167
 
168
  switch (config1_val & CONFIG1_DS)
169
    {
170
    case CONFIG1_DCACHE_64_SETS_PER_WAY:    dcache_sets = 64;          break;
171
    case CONFIG1_DCACHE_128_SETS_PER_WAY:   dcache_sets = 128;         break;
172
    case CONFIG1_DCACHE_256_SETS_PER_WAY:   dcache_sets = 256;         break;
173
    default:      /* Error */               return -1;                 break;
174
    }
175
 
176
  dcache_lines = dcache_sets * dcache_assoc;
177
  dcache_size = dcache_lines * dcache_linesize;
178
#endif /* DYNAMIC_CACHE_SIZING */
179
 
180
  /*
181
   * Reset does not invalidate the cache so let's do so now.
182
   */
183
  HAL_DCACHE_INVALIDATE_ALL();
184
 
185
#ifdef DYNAMIC_CACHE_SIZING
186
  return dcache_size;
187
#else
188
  return HAL_DCACHE_SIZE;
189
#endif
190
}
191
 
192
void hal_c_cache_init(unsigned long config1_val)
193
{
194
  volatile unsigned val;
195
 
196
  if (hal_init_icache(config1_val) == -1)
197
    {
198
        /* Error */
199
        ;
200
    }
201
 
202
  if (hal_init_dcache(config1_val) == -1)
203
    {
204
        /* Error */
205
        ;
206
    }
207
 
208
  // enable cached KSEG0
209
  asm volatile("mfc0 %0,$16;" : "=r"(val));
210
  val &= ~3;
211
  asm volatile("mtc0 %0,$16;" : : "r"(val));
212
}
213
 
214
void hal_icache_sync(void)
215
{
216
    HAL_ICACHE_INVALIDATE_ALL();
217
}
218
 
219
void hal_dcache_sync(void)
220
{
221
    HAL_DCACHE_INVALIDATE_ALL();
222
}
223
 
224
/*------------------------------------------------------------------------*/
225
/* 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.