source: rtems/c/src/lib/libcpu/bfin/cache/cache.c @ 479f8768

4.115
Last change on this file since 479f8768 was 479f8768, checked in by Sebastian Huber <sebastian.huber@…>, on 06/07/11 at 07:54:26

2011-06-07 Sebastian Huber <sebastian.huber@…>

  • cache/cache_.h: Include required header file.
  • cache/cache.c: Removed superfuous header file.
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*  Blackfin Cache Support
2 *
3 *  Copyright (c) 2008 Kallisti Labs, Los Gatos, CA, USA
4 *             written by Allan Hessenflow <allanh@kallisti.com>
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.com/license/LICENSE.
9 *
10 *  $Id$
11 */
12
13
14#include <rtems.h>
15#include <bsp.h>
16#include <libcpu/memoryRegs.h>
17#include "cache_.h"
18
19
20/* There are many syncs in the following code because they should be
21   harmless except for wasting time, and this is easier than figuring out
22   exactly where they're needed to protect from the effects of write
23   buffers and queued reads.  Many of them are likely unnecessary. */
24
25
26void _CPU_cache_flush_1_data_line(const void *d_addr) {
27
28  __asm__ __volatile__ ("ssync; flush [%0]; ssync" :: "a" (d_addr));
29}
30
31/* Blackfins can't just invalidate cache; they can only do flush +
32   invalidate.  If the line isn't dirty then this is equivalent to
33   just an invalidate.  Even if it is dirty, this should still be
34   okay since with a pure invalidate method the caller would have no
35   way to insure the dirty line hadn't been written out anyway prior
36   to the invalidate. */
37void _CPU_cache_invalidate_1_data_line(const void *d_addr) {
38
39  __asm__ __volatile__ ("ssync; flushinv [%0]; ssync" :: "a" (d_addr));
40}
41
42void _CPU_cache_freeze_data(void) {
43}
44
45void _CPU_cache_unfreeze_data(void) {
46}
47
48void _CPU_cache_invalidate_1_instruction_line(const void *d_addr) {
49
50  __asm__ __volatile__ ("ssync; iflush [%0]; ssync" :: "a" (d_addr));
51}
52
53void _CPU_cache_freeze_instruction(void) {
54}
55
56void _CPU_cache_unfreeze_instruction(void) {
57}
58
59/* incredibly inefficient...  It would be better to make use of the
60   DTEST_COMMAND/DTEST_DATAx registers to find the addresses in each
61   cache line and flush just those.  However the documentation I've
62   seen on those is a bit sketchy, and I sure wouldn't want to get it
63   wrong. */
64void _CPU_cache_flush_entire_data(void) {
65  uint32_t i;
66
67  i = 0;
68  __asm__ __volatile__ ("ssync");
69  do {
70      __asm__ __volatile__ ("flush [%0]" :: "a" (i));
71      i += CPU_DATA_CACHE_ALIGNMENT;
72  } while (i);
73  __asm__ __volatile__ ("ssync");
74}
75
76void _CPU_cache_invalidate_entire_data(void) {
77  uint32_t dmemControl;
78
79  __asm__ __volatile__ ("ssync");
80  dmemControl = *(uint32_t volatile *) DMEM_CONTROL;
81  *(uint32_t volatile *) DMEM_CONTROL = dmemControl & ~DMEM_CONTROL_DMC_MASK;
82  *(uint32_t volatile *) DMEM_CONTROL = dmemControl;
83  __asm__ __volatile__ ("ssync");
84}
85
86/* this does not actually enable data cache unless CPLBs are also enabled.
87   LIBCPU_DATA_CACHE_CONFIG contains the DMEM_CONTROL_DMC bits to set. */
88void _CPU_cache_enable_data(void) {
89
90  __asm__ __volatile__ ("ssync");
91  *(uint32_t volatile *) DMEM_CONTROL |= LIBCPU_DATA_CACHE_CONFIG;
92  __asm__ __volatile__ ("ssync");
93}
94
95void _CPU_cache_disable_data(void) {
96
97  __asm__ __volatile__ ("ssync");
98  *(uint32_t volatile *) DMEM_CONTROL &= ~DMEM_CONTROL_DMC_MASK;
99  __asm__ __volatile__ ("ssync");
100}
101
102void _CPU_cache_invalidate_entire_instruction(void) {
103  uint32_t imemControl;
104
105  __asm__ __volatile__ ("ssync");
106  imemControl = *(uint32_t volatile *) IMEM_CONTROL;
107  *(uint32_t volatile *) IMEM_CONTROL = imemControl & ~IMEM_CONTROL_IMC;
108  *(uint32_t volatile *) IMEM_CONTROL = imemControl;
109  __asm__ __volatile__ ("ssync");
110}
111
112/* this only actually enables the instruction cache if the CPLBs are also
113   enabled. */
114void _CPU_cache_enable_instruction(void) {
115
116  __asm__ __volatile__ ("ssync");
117  *(uint32_t volatile *) IMEM_CONTROL |= IMEM_CONTROL_IMC;
118  __asm__ __volatile__ ("ssync");
119}
120
121void _CPU_cache_disable_instruction(void) {
122
123  __asm__ __volatile__ ("ssync");
124  *(uint32_t volatile *) IMEM_CONTROL &= ~IMEM_CONTROL_IMC;
125  __asm__ __volatile__ ("ssync");
126}
127
Note: See TracBrowser for help on using the repository browser.