Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_ExternalMemory.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | ||
24 | #ifndef __SS_ExternalMemory_h__ | |
25 | #define __SS_ExternalMemory_h__ | |
26 | #include <iostream.h> | |
27 | #include "BL_Memory.h" | |
28 | #include "SS_Types.h" | |
29 | ||
30 | // SS_ExternalMemory is a class the leaves the implementation of memory to | |
31 | // some external object. The api between the external object and this class | |
32 | // is a simple load store functon pair. The api is used elsewhere so | |
33 | // that means that this can NOT be changed. | |
34 | ||
35 | class SS_ExternalMemory : public BL_Memory | |
36 | { | |
37 | public: | |
38 | // The load callback is called for each load and the call returns the memory values. | |
39 | // The store callback is called for each store telling what value s being stored. | |
40 | // This essentially forms an alternate memory system for the CPU, usually RTL-directed. | |
41 | ||
42 | enum MemFlag | |
43 | { | |
44 | NORMAL = 0, // Normal load/store access | |
45 | ATOMIC = 1, // Atomic operation | |
46 | TABLEWALK = 2, // Operation from the cpu hardware table walker | |
47 | CODEFETCH = 4, // Code fetch from cpu | |
48 | DEVICE = 8 // Memory access requests initiated by device (IMU) | |
49 | }; | |
50 | ||
51 | // The pa is always 8-byte aligned. | |
52 | // data bits 00-07 is the byte at (address + 7), and is byte_mask bit 0 | |
53 | // data bits 56-63 is the byte at (address + 0), and is byte_mask bit 7 | |
54 | ||
55 | typedef void (*LdCallBack)( uint_t strand_id, SS_Paddr pa, MemFlag flag, uint_t byte_mask, uint64_t *data ); | |
56 | typedef void (*StCallBack)( uint_t strand_id, SS_Paddr pa, MemFlag flag, uint_t byte_mask, uint64_t data ); | |
57 | ||
58 | // These methods are used to set the load and store callbacks | |
59 | ||
60 | void set_ld_callback( LdCallBack _ld ) { ld_callback = _ld; } | |
61 | void set_st_callback( StCallBack _st ) { st_callback = _st; } | |
62 | ||
63 | // cas and casx are the only atomics that do load and maybe a store. | |
64 | // This seems inbalanced and hence we add the option to change this. | |
65 | // Default is to always do a store. However, in case the cas fails the | |
66 | // store mask is 0, effectively no store. At startup you can switch off | |
67 | // the dummy store behaviour by calling no_dummy_st_for_cas(). | |
68 | ||
69 | void no_dummy_st_for_cas() { dummy_st_for_cas = true; } | |
70 | ||
71 | // Supported User Interface Operations | |
72 | ||
73 | void poke8( uint64_t addr, uint8_t data ) { st8(addr,data); } | |
74 | void poke16( uint64_t addr, uint16_t data ) { st16(addr,data); } | |
75 | void poke32( uint64_t addr, uint32_t data ) { st32(addr,data); } | |
76 | void poke64( uint64_t addr, uint64_t data ) { st64(addr,data); } | |
77 | uint8_t peek8u( uint64_t addr ) { return ld8u(addr); } | |
78 | int8_t peek8s( uint64_t addr ) { return ld8s(addr); } | |
79 | uint16_t peek16u( uint64_t addr ) { return ld16u(addr); } | |
80 | int16_t peek16s( uint64_t addr ) { return ld16s(addr); } | |
81 | uint32_t peek32u( uint64_t addr ) { return ld32u(addr); } | |
82 | int32_t peek32s( uint64_t addr ) { return ld32s(addr); } | |
83 | uint64_t peek64( uint64_t addr ) { return ld64(addr); } | |
84 | ||
85 | // Supported Fetch Operation (instruction fetch) | |
86 | ||
87 | uint32_t fetch32 ( uint64_t addr ); | |
88 | void fetch256( uint64_t addr, uint64_t data[4] ); | |
89 | void fetch512( uint64_t addr, uint64_t data[8] ); | |
90 | ||
91 | // Supported Load Operations. ld8[su]() to ld64() are quaranteed to be atomic. ld128() and | |
92 | // above are atomic at the 64 bit granularity. | |
93 | ||
94 | uint8_t ld8u ( uint64_t addr ); | |
95 | int8_t ld8s ( uint64_t addr ); | |
96 | uint16_t ld16u( uint64_t addr ); | |
97 | int16_t ld16s( uint64_t addr ); | |
98 | uint32_t ld32u( uint64_t addr ); | |
99 | int32_t ld32s( uint64_t addr ); | |
100 | uint64_t ld64 ( uint64_t addr ); | |
101 | void ld128( uint64_t addr, uint64_t data[2] ); | |
102 | void ld256( uint64_t addr, uint64_t data[4] ); | |
103 | void ld512( uint64_t addr, uint64_t data[8] ); | |
104 | ||
105 | // Supported Store Operations. st8(), st16(), st32() and st64() are gueranteed to be atomic. | |
106 | // st128() and st512() are atomic per 64bit quantity. | |
107 | ||
108 | void st8 ( uint64_t addr, uint8_t data ); | |
109 | void st16 ( uint64_t addr, uint16_t data ); | |
110 | void st32 ( uint64_t addr, uint32_t data ); | |
111 | void st64 ( uint64_t addr, uint64_t data ); | |
112 | void st128( uint64_t addr, uint64_t data[2] ); | |
113 | void st512( uint64_t addr, uint64_t data[8] ); | |
114 | ||
115 | // st64partial() performs 8 byte partial store. The bytes to store are specified by mask. A 1 in bit N of | |
116 | // mask denotes that byte (data >> (8*N)) & 0xff should be written to memory | |
117 | ||
118 | void st64partial( uint64_t addr, uint64_t data, uint64_t mask ); | |
119 | ||
120 | // ld128atomic() (aka load twin double, load quad atomic) atomically loads two | |
121 | // 64bit values from memory at addr into rd. rd[0] is the value at addr, rd[1] | |
122 | // is the value at addr + 8. Note ld128 does() not guarantee atomicity. | |
123 | ||
124 | void ld128atomic( uint64_t addr, uint64_t data[2] ); | |
125 | ||
126 | // ldstub() return a byte from memory at addr, and set the byte at addr | |
127 | // to 0xff. The ldstub() operation is atomic. | |
128 | ||
129 | uint8_t ldstub( uint64_t addr ); | |
130 | ||
131 | // swap() stores the 32bit value rd with the 32bit value at addr. | |
132 | // The old 32bit value at addr is returned. The operation is atomic. | |
133 | ||
134 | uint32_t swap( uint64_t addr, uint32_t rd ); | |
135 | ||
136 | // casx() compares the 64bit value rs2 with the 64bit value at addr. | |
137 | // If the two values are equal, the value rd is stored in the | |
138 | // 64bit value at addr. In both cases the old 64bit value at addr is | |
139 | // returned, that is the value at addr before the storei happened. | |
140 | // The casx() operation is atomic. | |
141 | ||
142 | uint64_t casx( uint64_t addr, uint64_t rd, uint64_t rs2 ); | |
143 | ||
144 | // cas() is as casx, but for 32bit. | |
145 | ||
146 | uint32_t cas( uint64_t addr, uint32_t rd, uint32_t rs2 ); | |
147 | ||
148 | // prefetch() prefetches data from memory into the cache hierarchy. | |
149 | ||
150 | void prefetch( uint64_t addr, uint_t size ); | |
151 | ||
152 | // flush() writes dirty data in the cache back to memory. | |
153 | ||
154 | void flush( uint64_t addr, uint_t size ); | |
155 | ||
156 | static SS_ExternalMemory memory; | |
157 | ||
158 | int block_read( uint64_t addr, uint8_t *tgt, int _size ) | |
159 | { | |
160 | assert(0); | |
161 | return 0; | |
162 | } | |
163 | ||
164 | int block_write( uint64_t addr, const uint8_t *src, int _size ) | |
165 | { | |
166 | assert(0); | |
167 | return 0; | |
168 | } | |
169 | ||
170 | void set_strand_id( uint_t strand_id ) { sid = strand_id; } | |
171 | ||
172 | protected: | |
173 | bool dummy_st_for_cas; // When true cas and casx always do ld followed by st | |
174 | LdCallBack ld_callback; | |
175 | StCallBack st_callback; | |
176 | uint_t sid; // Record the strand id of each operation | |
177 | }; | |
178 | ||
179 | #endif |