Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_BaseCsr.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 | #ifndef SS_BASE_CSR_H | |
24 | #define SS_BASE_CSR_H | |
25 | /************************************************************************ | |
26 | ** | |
27 | ** Copyright (C) 2006, Sun Microsystems, Inc. | |
28 | ** | |
29 | ** Sun considers its source code as an unpublished, proprietary | |
30 | ** trade secret and it is available only under strict license provisions. | |
31 | ** This copyright notice is placed here only to protect Sun in the event | |
32 | ** the source is deemed a published work. Disassembly, decompilation, | |
33 | ** or other means of reducing the object code to human readable form | |
34 | ** is prohibited by the license agreement under which this code is | |
35 | ** provided to the user or company in possession of this copy. | |
36 | ** | |
37 | *************************************************************************/ | |
38 | #include "SS_CsrAttribute.h" | |
39 | #include "SS_Io.h" | |
40 | #include "SS_Access.h" | |
41 | #include "MemoryTransaction.h" | |
42 | #include "SS_Types.h" | |
43 | ||
44 | /** | |
45 | * class represents csr follow-me data | |
46 | */ | |
47 | class FollowMeData | |
48 | { | |
49 | public: | |
50 | FollowMeData() : addr(0), data(0), sid(-1) { } | |
51 | FollowMeData(SS_Paddr _addr, uint64_t _data, int _sid) : | |
52 | addr(_addr), data(_data), sid(_sid) { } | |
53 | ||
54 | SS_Paddr addr; | |
55 | uint64_t data; | |
56 | int sid; | |
57 | }; | |
58 | ||
59 | class SS_BaseCsr | |
60 | { | |
61 | public: | |
62 | enum Access_T { | |
63 | // make sure there is no conflict with MemoryTransaction::Access_T | |
64 | NO_FOLLOW_ME = 1 << 10 // internal access, do not pop follow-me value | |
65 | }; | |
66 | ||
67 | static void access( void* obj, | |
68 | uint_t sid, | |
69 | SS_Access::Type, | |
70 | SS_Paddr addr, | |
71 | uint_t size, | |
72 | uint64_t* data); | |
73 | ||
74 | virtual int read64( SS_Paddr addr, | |
75 | uint64_t* data, | |
76 | int access=MemoryTransaction::READ, | |
77 | int sid=-1 ); | |
78 | ||
79 | virtual int write64( SS_Paddr addr, | |
80 | uint64_t data, | |
81 | int access=MemoryTransaction::WRITE, | |
82 | int sid=-1 ); | |
83 | ||
84 | virtual std::string toString() const | |
85 | { | |
86 | return std::string("SS_BaseCs::toString() not implemented"); | |
87 | } | |
88 | ||
89 | /** | |
90 | * common methods | |
91 | */ | |
92 | enum { | |
93 | ENTRY_NOT_FOUND = -1 | |
94 | }; | |
95 | ||
96 | int64_t findAttributeEntryNdx(SS_Paddr addr, | |
97 | const RegisterAttribute *const attributeTable, | |
98 | int entries); | |
99 | ||
100 | const RegisterAttribute* const | |
101 | findAttributeEntry(SS_Paddr addr, | |
102 | const RegisterAttribute *const attributeTable, | |
103 | int entries); | |
104 | ||
105 | void warmReset(std::vector<std::vector<RegisterValue>*>* values, | |
106 | int nrAttributeEntries); | |
107 | ||
108 | uint64_t reverseByteOrder(uint64_t value, bool littleEndian); | |
109 | ||
110 | uint64_t forceWrite(uint64_t inputData, | |
111 | const RegisterAttribute* attribute, | |
112 | int access); | |
113 | ||
114 | uint64_t normalWrite(uint64_t inputData, | |
115 | uint64_t oldData, | |
116 | const RegisterAttribute* attribute, | |
117 | int access); | |
118 | ||
119 | /** | |
120 | * if a derived class needs to register its address range, the derived | |
121 | * class should overwrite the regAddrSpace() function. | |
122 | */ | |
123 | virtual void regAddrSpace() { /* default, do nothing */ } | |
124 | ||
125 | /** | |
126 | * local I/O address <-> global I/O address conversion, | |
127 | */ | |
128 | virtual SS_Paddr local2global(SS_Paddr addr, int sid) { return addr; } | |
129 | virtual SS_Paddr global2local(SS_Paddr addr) { return addr; } | |
130 | virtual SS_Paddr addr_node0(SS_Paddr addr) { return addr; } | |
131 | virtual bool is_global_addr(SS_Paddr addr) { return true; } | |
132 | virtual int get_node_id(SS_Paddr addr) { return 0; } | |
133 | ||
134 | protected: | |
135 | SS_BaseCsr(std::string className, | |
136 | const RegisterAttribute* const attributeTable, | |
137 | int nrAttributeEntries) : | |
138 | className_(className), | |
139 | attributeTable_(attributeTable), | |
140 | nrAttributeEntries_(nrAttributeEntries), | |
141 | values_(new std::vector<std::vector<RegisterValue>*>[nrAttributeEntries]) | |
142 | { | |
143 | } | |
144 | ||
145 | virtual ~SS_BaseCsr() {} | |
146 | ||
147 | // derived class name | |
148 | const std::string className_; | |
149 | ||
150 | // Attribute table for derived class | |
151 | const RegisterAttribute* const attributeTable_; | |
152 | ||
153 | // Nr entries in attribute table | |
154 | const int nrAttributeEntries_; | |
155 | ||
156 | void registerAddressSpace(RegisterAttribute *attributeTable, | |
157 | uint_t tableSize, | |
158 | const std::string &descr); | |
159 | ||
160 | // values_ is a 3-dimention structure, the top level has an 1-to-1 | |
161 | // mapping with each CSR entry in the corresponding RegisterAttribute | |
162 | // table, the second level has one entry for each node (i.e., cpu), the | |
163 | // third level is a structure of vector<RegisterValue>, where each entry | |
164 | // represents an addr entity of a (CSR,node-id,addr) triple of a particular | |
165 | // CSR in the RegisterAttribute table. The reason for having a vector at | |
166 | // the third level is that each CSR entry in the RegisterAttribute table | |
167 | // can spawn out one or more addrs, depending on the CSR's (count,stride) | |
168 | // attribute. | |
169 | std::vector<std::vector<RegisterValue>*>* values_; | |
170 | ||
171 | // the followme_ is a list of objects, each object represents a csr | |
172 | // follow-me value, the objects are kept in FIFO order, once an object | |
173 | // in the list is used, it should be removed from the list, as follow-me | |
174 | // uses "use-once-and-discard" scheme. | |
175 | std::list<FollowMeData> followme_; | |
176 | ||
177 | private: | |
178 | SS_BaseCsr() : | |
179 | className_(""), | |
180 | attributeTable_(NULL), | |
181 | nrAttributeEntries_(0) | |
182 | {} | |
183 | ||
184 | // gaddr - global I/O address, laddr - local I/O address | |
185 | int write64_notCsr( SS_Paddr gaddr, uint64_t data ); | |
186 | int read64_notCsr( SS_Paddr gaddr, SS_Paddr laddr, uint64_t* data ); | |
187 | int read_memimage( SS_Paddr gaddr, SS_Paddr laddr, uint64_t* data ); | |
188 | }; | |
189 | ||
190 | #endif // SS_BASE_CSR_H |