1 | /** |
---|
2 | * \file reset_inval.c |
---|
3 | * \date December 14, 2014 |
---|
4 | * \author Cesar Fuguet |
---|
5 | */ |
---|
6 | |
---|
7 | #include <reset_inval.h> |
---|
8 | #include <io.h> |
---|
9 | #include <defs.h> |
---|
10 | |
---|
11 | #ifndef SEG_MMC_BASE |
---|
12 | # error "SEG_MMC_BASE constant must be defined in the hard_config.h file" |
---|
13 | #endif |
---|
14 | |
---|
15 | static int* const mcc_address = (int* const)SEG_MMC_BASE; |
---|
16 | |
---|
17 | enum memc_registers |
---|
18 | { |
---|
19 | MCC_LOCK = 0, |
---|
20 | MCC_ADDR_LO = 1, |
---|
21 | MCC_ADDR_HI = 2, |
---|
22 | MCC_LENGTH = 3, |
---|
23 | MCC_CMD = 4 |
---|
24 | }; |
---|
25 | |
---|
26 | enum memc_operations |
---|
27 | { |
---|
28 | MCC_CMD_NOP = 0, |
---|
29 | MCC_CMD_INVAL = 1, |
---|
30 | MCC_CMD_SYNC = 2 |
---|
31 | }; |
---|
32 | |
---|
33 | /** |
---|
34 | * \brief Invalidate all data cache lines corresponding to a memory buffer |
---|
35 | * (identified by an address and a size) in L2 cache. |
---|
36 | */ |
---|
37 | void reset_mcc_invalidate (void* const buffer, size_t size) |
---|
38 | { |
---|
39 | // get the hard lock assuring exclusive access to MEMC |
---|
40 | while (ioread32(&mcc_address[MCC_LOCK])); |
---|
41 | |
---|
42 | // write invalidate paremeters on the memory cache this preloader |
---|
43 | // use only the cluster 0 and then the HI bits are not used |
---|
44 | |
---|
45 | iowrite32(&mcc_address[MCC_ADDR_LO], (unsigned int) buffer); |
---|
46 | iowrite32(&mcc_address[MCC_ADDR_HI], (unsigned int) 0); |
---|
47 | iowrite32(&mcc_address[MCC_LENGTH] , (unsigned int) size); |
---|
48 | iowrite32(&mcc_address[MCC_CMD] , (unsigned int) MCC_CMD_INVAL); |
---|
49 | |
---|
50 | // release the lock protecting MEMC |
---|
51 | iowrite32(&mcc_address[MCC_LOCK], (unsigned int) 0); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * \brief Invalidate all data cache lines corresponding to a memory buffer |
---|
56 | * (identified by an address and a size) in L1 cache and L2 cache. |
---|
57 | */ |
---|
58 | void reset_buf_invalidate (void* const buffer, size_t size, int inval_memc) |
---|
59 | { |
---|
60 | unsigned int i; |
---|
61 | |
---|
62 | /* |
---|
63 | * iterate on cache lines containing target buffer to invalidate them |
---|
64 | */ |
---|
65 | for (i = 0; i <= size; i += CACHE_LINE_SIZE) |
---|
66 | { |
---|
67 | asm volatile( |
---|
68 | " cache %0, %1" |
---|
69 | : /* no outputs */ |
---|
70 | : "i" (0x11), "R" (*((char*)buffer + i)) |
---|
71 | : "memory" |
---|
72 | ); |
---|
73 | } |
---|
74 | |
---|
75 | if (inval_memc) reset_mcc_invalidate(buffer, size); |
---|
76 | } |
---|
77 | |
---|
78 | /* |
---|
79 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
80 | */ |
---|