source: svn/trunk/newcon3bcm2_21bu/dta/src/cache_util.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1/***************************************************************
2**
3** Broadcom Corp. Confidential
4** Copyright 1998-2000 Broadcom Corp. All Rights Reserved.
5**
6** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED
7** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM.
8** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT
9** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10**
11** File:                cache_util.c
12** Description:         cache handling utilities.
13**
14** Created: 06/07/04 by Jeff Fisher
15**
16**
17**
18****************************************************************/
19#include "cache_util.h"
20#include "ministd.h"
21#include "bcm_mips_defs.h"
22
23#define CU_DBG(x)       printf x
24#define RAC_CONFIGURATION_REGISTER      0xFF400000
25#define RAC_ADDRESS_RANGE_REGISTER      0xFF400004
26
27#if (BCHP_CHIP==7550) || (BCHP_CHIP==7552)
28unsigned int dcache_size;
29unsigned int dcache_linesize;
30unsigned int icache_size;
31unsigned int icache_linesize;
32#endif
33
34/* cache instructions invalidate RAC */
35#define invalidate_rac_all() ((void)0)
36
37static void rac_init(void)
38{
39        unsigned int flags;
40        unsigned int tmp;
41       
42        invalidate_rac_all();
43
44        flags = bos_enter_critical();
45#ifdef CONFIG_AOV_SDRAM_1G
46        //*((volatile unsigned int *)RAC_ADDRESS_RANGE_REGISTER) = 0x00FF0000;  /* 0 - 16M */
47        *((volatile unsigned int *)RAC_ADDRESS_RANGE_REGISTER) = 0x007FF0000;  /* 0 - 128M */
48#else
49        *((volatile unsigned int *)RAC_ADDRESS_RANGE_REGISTER) = 0x0FFF0000;  /* 0 - 256M */
50#endif
51        /* set to default - C_INV='0'b, PF_D='1'b, PF_I='1'b, RAC_D='1'b, RAC_I='1'b */
52        *((volatile unsigned int *)RAC_CONFIGURATION_REGISTER) |= 0x0000000F;
53
54        /* CP0_BRCM_CONFIG0 */
55    __asm__("mfc0 %0, $22":"=r"(tmp));
56    tmp |= (1L << 20);  /* CLF mode */
57    __asm__("mtc0 %0, $22"::"r"(tmp));
58
59        /* CP0_BRCM_CONFIG1 */
60    __asm__("mfc0 %0, $22, 5":"=r"(tmp));
61    tmp &= ~(1L << 16);  /* enable branch mode */
62    __asm__("mtc0 %0, $22, 5"::"r"(tmp));
63
64        bos_exit_critical(flags);
65}
66
67void calc_cache_sizes(void)
68{
69    volatile unsigned int val;
70        int da,dl,ds,ia,il,is;
71
72        rac_init();
73
74        val = bcm_read_cp0($16, 1);
75        da = (val & (0x7 << 7)) >> 7;
76        ia = (val & (0x7 << 16)) >> 16;
77        dl = (val & (0x7 << 10)) >> 10;
78        il = (val & (0x7 << 19)) >> 19;
79        ds = (val & (0x7 << 13)) >> 13;
80        is = (val & (0x7 << 22)) >> 22;
81
82        dcache_linesize =(0x2 << dl);
83        dcache_size =  (da + 1) * dcache_linesize * (64 << ds);
84        icache_linesize = (0x2 << il);
85        icache_size = (ia + 1) * icache_linesize * (64 << is);
86}
87
88void print_cache_sizes(void)
89{
90    volatile unsigned int val;
91    int da,dl,ds,ia,il,is;
92    val = bcm_read_cp0($16, 1);
93    da = (val & (0x7 << 7)) >> 7;
94    ia = (val & (0x7 << 16)) >> 16;
95    dl = (val & (0x7 << 10)) >> 10;
96    il = (val & (0x7 << 19)) >> 19;
97    ds = (val & (0x7 << 13)) >> 13;
98    is = (val & (0x7 << 22)) >> 22;
99
100    dcache_linesize =(0x2 << dl);
101    dcache_size =  (da + 1) * dcache_linesize * (64 << ds);
102    icache_linesize = (0x2 << il);
103    icache_size = (ia + 1) * icache_linesize * (64 << is);
104
105    CU_DBG(("CONFIG1[0x%08x]\n",val));
106    CU_DBG(("D[%d,%d,%d]\n",da,dl,ds));
107    CU_DBG(("I[%d,%d,%d]\n",ia,il,is));
108    CU_DBG(("D[linesize = %d, size = %d]\n",dcache_linesize,dcache_size ));
109    CU_DBG(("I[linesize = %d, size = %d]\n",icache_linesize,icache_size ));
110}
111
112#define cache_op(op,addr)                                               \
113        __asm__ __volatile__(                                           \
114        "       .set    noreorder                               \n"     \
115        "       .set    mips3\n\t                               \n"     \
116        "       cache   %0, %1                                  \n"     \
117        "       .set    mips0                                   \n"     \
118        "       .set    reorder"                                        \
119        :                                                               \
120        : "i" (op), "m" (*(unsigned char *)(addr)))
121
122#define Index_Invalidate_I      0x00
123#define Index_Writeback_Inv_D   0x01
124#define Index_Load_Tag_I        0x04
125#define Index_Load_Tag_D        0x05
126#define Index_Store_Tag_I       0x08
127#define Index_Store_Tag_D       0x09
128#define Hit_Invalidate_I        0x10
129#define Hit_Invalidate_D        0x11
130#define Hit_Writeback_Inv_D     0x15
131
132void invalidate_icache_all(void)
133{
134        unsigned int addr;
135        __asm__ (" .set push\n .set mips32\n sync \n .set pop\n");
136
137        __asm__ (" .set push\n .set mips32\n mtc0 $0,$28 \n mtc0 $0,$29 \n .set pop\n");
138        for (addr = 0x80000000; addr < (0x80000000 + icache_size); addr += icache_linesize)
139        {
140                cache_op(Index_Store_Tag_I,addr);
141        }
142        __asm__ (" nop\n nop\n nop\n nop\n\n");
143        invalidate_rac_all();
144}
145
146void flush_dcache_all(void)
147{
148        unsigned int addr=0x80000000;
149        unsigned end = addr+dcache_size;
150        unsigned linesize = dcache_linesize;
151
152        for (; addr < end ; addr += linesize)
153        {
154                cache_op(Index_Writeback_Inv_D,addr); 
155        }
156        __asm__ (" .set push\n .set mips32\n sync \n .set pop\n");
157        invalidate_rac_all();
158}
159
160void flush_dcache(unsigned int start, unsigned int end)
161{
162        unsigned int addr;
163        unsigned linesize = dcache_linesize;
164
165        end += linesize;
166
167        if (end  >= (start + dcache_size))
168        {
169                flush_dcache_all();
170                return;
171        }
172
173        for (addr = start; addr < end; addr += linesize)
174        {
175                cache_op(Hit_Writeback_Inv_D,addr); 
176        }
177        __asm__ (" .set push\n .set mips32\n sync \n .set pop\n");
178        invalidate_rac_all();
179}
180
181
182
183void invalidate_dcache_all(void)
184{
185        unsigned int addr=0x80000000;
186        unsigned end = addr+dcache_size;
187        unsigned linesize = dcache_linesize;
188
189        for (; addr < end ; addr += linesize)
190        {
191                cache_op(Index_Writeback_Inv_D,addr); 
192        }
193        __asm__ (" .set push\n .set mips32\n sync \n .set pop\n");
194        invalidate_rac_all();
195}
196
197void invalidate_dcache(unsigned int start, unsigned int end)
198{
199        unsigned int addr;
200        unsigned linesize = dcache_linesize;
201
202        end += linesize;
203
204        if (end  >= (start + dcache_size))
205        {
206                invalidate_dcache_all();
207                return;
208        }
209
210        for (addr = start; addr < end; addr += linesize)
211        {
212                cache_op(Hit_Invalidate_D,addr); 
213        }
214        __asm__ (" .set push\n .set mips32\n sync \n .set pop\n");
215        invalidate_rac_all();
216}
Note: See TracBrowser for help on using the repository browser.