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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [src/] [alt_dcache_flush.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
/******************************************************************************
2
*                                                                             *
3
* License Agreement                                                           *
4
*                                                                             *
5
* Copyright (c) 2003-2005 Altera Corporation, San Jose, California, USA.      *
6
* All rights reserved.                                                        *
7
*                                                                             *
8
* Permission is hereby granted, free of charge, to any person obtaining a     *
9
* copy of this software and associated documentation files (the "Software"),  *
10
* to deal in the Software without restriction, including without limitation   *
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
12
* and/or sell copies of the Software, and to permit persons to whom the       *
13
* Software is furnished to do so, subject to the following conditions:        *
14
*                                                                             *
15
* The above copyright notice and this permission notice shall be included in  *
16
* all copies or substantial portions of the Software.                         *
17
*                                                                             *
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
24
* DEALINGS IN THE SOFTWARE.                                                   *
25
*                                                                             *
26
* This agreement shall be governed in all respects by the laws of the State   *
27
* of California and by the laws of the United States of America.              *
28
*                                                                             *
29
******************************************************************************/
30
 
31
#include "nios2.h"
32
#include "system.h"
33
 
34
#include "alt_types.h"
35
#include "sys/alt_cache.h" 
36
 
37
/*
38
 * Nios II version 1.2 and newer supports the "flush by address" instruction, in
39
 * addition to the "flush by line" instruction provided by older versions of
40
 * the core. This newer instruction is used by preference when it is
41
 * available.
42
 */
43
 
44
#ifdef NIOS2_FLUSHDA_SUPPORTED
45
#define ALT_FLUSH_DATA(i) __asm__ volatile ("flushda (%0)" :: "r" (i));
46
#else
47
#define ALT_FLUSH_DATA(i) __asm__ volatile ("flushd (%0)" :: "r" (i));
48
#endif /* NIOS2_FLUSHDA_SUPPORTED */
49
 
50
/*
51
 * alt_dcache_flush() is called to flush the data cache for a memory
52
 * region of length "len" bytes, starting at address "start".
53
 *
54
 * Any dirty lines in the data cache are written back to memory.
55
 */
56
 
57
void alt_dcache_flush (void* start, alt_u32 len)
58
{
59
#if NIOS2_DCACHE_SIZE > 0
60
 
61
  char* i;
62
  char* end;
63
 
64
  /*
65
   * This is the most we would ever need to flush.
66
   *
67
   * SPR 196942, 2006.01.13: The cache flush loop below will use the
68
   * 'flushda' instruction if its available; in that case each line
69
   * must be flushed individually, and thus 'len' cannot be trimmed.
70
   */
71
  #ifndef NIOS2_FLUSHDA_SUPPORTED
72
  if (len > NIOS2_DCACHE_SIZE)
73
  {
74
    len = NIOS2_DCACHE_SIZE;
75
  }
76
  #endif
77
 
78
  end = ((char*) start) + len;
79
 
80
  for (i = start; i < end; i+= NIOS2_DCACHE_LINE_SIZE)
81
  {
82
    ALT_FLUSH_DATA(i);
83
  }
84
 
85
  /*
86
   * For an unaligned flush request, we've got one more line left.
87
   * Note that this is dependent on NIOS2_DCACHE_LINE_SIZE to be a
88
   * multiple of 2 (which it always is).
89
   */
90
 
91
  if (((alt_u32) start) & (NIOS2_DCACHE_LINE_SIZE - 1))
92
  {
93
    ALT_FLUSH_DATA(i);
94
  }
95
 
96
#endif /* NIOS2_DCACHE_SIZE > 0 */
97
}

powered by: WebSVN 2.1.0

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