summaryrefslogtreecommitdiff
path: root/utils/regtools/include/soc_desc.hpp
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-02-06 15:01:24 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2016-02-06 15:12:55 +0000
commit0f701a64bee43e79f95970ae9c0ec43ea7fcdf17 (patch)
treec8ac6b5516eac120797eb6a06f633919e9f48f9b /utils/regtools/include/soc_desc.hpp
parent16c915ec1826dcef2e58ecc055a3f5dfcefb235a (diff)
downloadrockbox-0f701a64bee43e79f95970ae9c0ec43ea7fcdf17.tar.gz
rockbox-0f701a64bee43e79f95970ae9c0ec43ea7fcdf17.zip
regtools: update v2 specification, library and tools
A v2 register description file can now include register variants and instances addresses can now be a list (previously it could only be a stride or a formula). Update the library to deal with that. The convert option of swiss_knife was updated and one incompatible change was introduce: if a v1 device has several addresses, those are converted to a single v2 instance with list (instead of several single instances). This should have been the behaviour from the start. Swiss_knife can now also convert regdumps, in which case it needs to be given both the dump and register description file. Also introduce two register descriptions files (vsoc1000 and vsoc2000) which give more complicated examples of v2 register description files. Change-Id: Id9415b8363269ffaf9216abfc6dd1bd1adbfcf8d
Diffstat (limited to 'utils/regtools/include/soc_desc.hpp')
-rw-r--r--utils/regtools/include/soc_desc.hpp139
1 files changed, 132 insertions, 7 deletions
diff --git a/utils/regtools/include/soc_desc.hpp b/utils/regtools/include/soc_desc.hpp
index 66f2e3b6e1..f6c5cca28f 100644
--- a/utils/regtools/include/soc_desc.hpp
+++ b/utils/regtools/include/soc_desc.hpp
@@ -125,11 +125,30 @@ struct field_t
125 } 125 }
126}; 126};
127 127
128/** Register variant information
129 *
130 * A register variant provides an alternative access to the register, potentially
131 * we special semantics. Although there are no constraints on the type string,
132 * the following types have well-defined semantics:
133 * - alias: the same register at another address
134 * - set: writing to this register will set the 1s bits and ignore the 0s
135 * - clr: writing to this register will clear the 1s bits and ignore the 0s
136 * - tog: writing to this register will toggle the 1s bits and ignore the 0s
137 */
138struct variant_t
139{
140 soc_id_t id; /** ID (must be unique among register variants) */
141 std::string type; /** type of the variant */
142 soc_addr_t offset; /** offset of the variant */
143};
144
128/** Register information */ 145/** Register information */
129struct register_t 146struct register_t
130{ 147{
131 size_t width; /** Size in bits */ 148 size_t width; /** Size in bits */
149 std::string desc; /** Optional description of the register */
132 std::vector< field_t > field; /** List of fields */ 150 std::vector< field_t > field; /** List of fields */
151 std::vector< variant_t > variant; /** List of variants */
133}; 152};
134 153
135/** Node address range information */ 154/** Node address range information */
@@ -138,16 +157,24 @@ struct range_t
138 enum type_t 157 enum type_t
139 { 158 {
140 STRIDE, /** Addresses are given by a base address and a stride */ 159 STRIDE, /** Addresses are given by a base address and a stride */
141 FORMULA /** Addresses are given by a formula */ 160 FORMULA, /** Addresses are given by a formula */
161 LIST, /** Addresses are given by a list */
142 }; 162 };
143 163
144 type_t type; /** Range type */ 164 type_t type; /** Range type */
145 size_t first; /** First index in the range */ 165 size_t first; /** First index in the range */
146 size_t count; /** Number of indexes in the range */ 166 size_t count; /** Number of indexes in the range (for STRIDE and RANGE) */
147 soc_word_t base; /** Base address (for STRIDE) */ 167 soc_word_t base; /** Base address (for STRIDE) */
148 soc_word_t stride; /** Stride value (for STRIDE) */ 168 soc_word_t stride; /** Stride value (for STRIDE) */
149 std::string formula; /** Formula (for FORMULA) */ 169 std::string formula; /** Formula (for FORMULA) */
150 std::string variable; /** Formula variable name (for FORMULA) */ 170 std::string variable; /** Formula variable name (for FORMULA) */
171 std::vector< soc_word_t > list; /** Address list (for LIST) */
172
173 /** Return the number of indexes (based on count or list) */
174 size_t size()
175 {
176 return type == LIST ? list.size() : count;
177 }
151}; 178};
152 179
153/** Node instance information */ 180/** Node instance information */
@@ -197,6 +224,12 @@ bool parse_xml(const std::string& filename, soc_t& soc, error_context_t& error_c
197/** Write a SoC description to a XML file, overwriting it. A file can contain 224/** Write a SoC description to a XML file, overwriting it. A file can contain
198 * multiple Soc descriptions */ 225 * multiple Soc descriptions */
199bool produce_xml(const std::string& filename, const soc_t& soc, error_context_t& error_ctx); 226bool produce_xml(const std::string& filename, const soc_t& soc, error_context_t& error_ctx);
227/** Normalise a soc description by reordering elements so that:
228 * - nodes are sorted by lowest address of an instance
229 * - instances are sorted by lowest address
230 * - fields are sorted by last bit
231 * - enum are sorted by value */
232void normalize(soc_t& soc);
200/** Formula parser: try to parse and evaluate a formula with some variables */ 233/** Formula parser: try to parse and evaluate a formula with some variables */
201bool evaluate_formula(const std::string& formula, 234bool evaluate_formula(const std::string& formula,
202 const std::map< std::string, soc_word_t>& var, soc_word_t& result, 235 const std::map< std::string, soc_word_t>& var, soc_word_t& result,
@@ -219,6 +252,8 @@ class soc_ref_t;
219class node_ref_t; 252class node_ref_t;
220class register_ref_t; 253class register_ref_t;
221class field_ref_t; 254class field_ref_t;
255class enum_ref_t;
256class variant_ref_t;
222class node_inst_t; 257class node_inst_t;
223 258
224/** SoC reference */ 259/** SoC reference */
@@ -241,6 +276,9 @@ public:
241 /** Compare this reference to another */ 276 /** Compare this reference to another */
242 bool operator==(const soc_ref_t& r) const; 277 bool operator==(const soc_ref_t& r) const;
243 inline bool operator!=(const soc_ref_t& r) const { return !operator==(r); } 278 inline bool operator!=(const soc_ref_t& r) const { return !operator==(r); }
279 bool operator<(const soc_ref_t& r) const { return m_soc < r.m_soc; }
280 /** Make this reference invalid */
281 void reset();
244}; 282};
245 283
246/** SoC node reference 284/** SoC node reference
@@ -265,8 +303,10 @@ public:
265 node_t *get() const; 303 node_t *get() const;
266 /** Returns a reference to the soc */ 304 /** Returns a reference to the soc */
267 soc_ref_t soc() const; 305 soc_ref_t soc() const;
268 /** Returns a reference to the parent node */ 306 /** Returns a reference to the n-th parent node, 0-th is itself, 1-th is parent */
269 node_ref_t parent() const; 307 node_ref_t parent(unsigned level = 1) const;
308 /** Returns reference depth, root is 0, below root is 1 and so on */
309 unsigned depth() const;
270 /** Returns a reference to the register (which may be on a parent node) */ 310 /** Returns a reference to the register (which may be on a parent node) */
271 register_ref_t reg() const; 311 register_ref_t reg() const;
272 /** Returns a list of references to the sub-nodes */ 312 /** Returns a list of references to the sub-nodes */
@@ -280,6 +320,16 @@ public:
280 /** Compare this reference to another */ 320 /** Compare this reference to another */
281 bool operator==(const node_ref_t& r) const; 321 bool operator==(const node_ref_t& r) const;
282 inline bool operator!=(const node_ref_t& r) const { return !operator==(r); } 322 inline bool operator!=(const node_ref_t& r) const { return !operator==(r); }
323 /** Delete the node (and children) pointed by the reference, invalidating it
324 * NOTE: if reference points to the root node, deletes all nodes
325 * NOTE: does nothing if the reference is not valid */
326 void remove();
327 /** Create a new child node and returns a reference to it */
328 node_ref_t create() const;
329 /** Create a register and returns a reference to it */
330 register_ref_t create_reg(size_t width = 32) const;
331 /** Make this reference invalid */
332 void reset();
283}; 333};
284 334
285/** SoC register reference */ 335/** SoC register reference */
@@ -300,11 +350,24 @@ public:
300 node_ref_t node() const; 350 node_ref_t node() const;
301 /** Returns a list of references to the fields of the register */ 351 /** Returns a list of references to the fields of the register */
302 std::vector< field_ref_t > fields() const; 352 std::vector< field_ref_t > fields() const;
353 /** Returns a list of references to the variants of the register */
354 std::vector< variant_ref_t > variants() const;
303 /** Returns a reference to a particular field */ 355 /** Returns a reference to a particular field */
304 field_ref_t field(const std::string& name) const; 356 field_ref_t field(const std::string& name) const;
357 /** Returns a reference to a particular variant */
358 variant_ref_t variant(const std::string& type) const;
305 /** Compare this reference to another */ 359 /** Compare this reference to another */
306 bool operator==(const register_ref_t& r) const; 360 bool operator==(const register_ref_t& r) const;
307 inline bool operator!=(const register_ref_t& r) const { return !operator==(r); } 361 inline bool operator!=(const register_ref_t& r) const { return !operator==(r); }
362 /** Delete the register pointed by the reference, invalidating it
363 * NOTE: does nothing if the reference is not valid */
364 void remove();
365 /** Create a new field and returns a reference to it */
366 field_ref_t create_field() const;
367 /** Create a new variant and returns a reference to it */
368 variant_ref_t create_variant() const;
369 /** Make this reference invalid */
370 void reset();
308}; 371};
309 372
310/** SoC register field reference */ 373/** SoC register field reference */
@@ -312,7 +375,7 @@ class field_ref_t
312{ 375{
313 friend class register_ref_t; 376 friend class register_ref_t;
314 register_ref_t m_reg; /* reference to the register */ 377 register_ref_t m_reg; /* reference to the register */
315 soc_id_t m_id; /* field name */ 378 soc_id_t m_id; /* field id */
316 379
317 field_ref_t(register_ref_t reg, soc_id_t id); 380 field_ref_t(register_ref_t reg, soc_id_t id);
318public: 381public:
@@ -324,9 +387,67 @@ public:
324 field_t *get() const; 387 field_t *get() const;
325 /** Returns a reference to the register containing the field */ 388 /** Returns a reference to the register containing the field */
326 register_ref_t reg() const; 389 register_ref_t reg() const;
390 /** Returns a list of references to the enums of the field */
391 std::vector< enum_ref_t > enums() const;
392 /** Compare this reference to another */
393 bool operator==(const field_ref_t& r) const;
394 inline bool operator!=(const field_ref_t& r) const { return !operator==(r); }
395 /** Make this reference invalid */
396 void reset();
397 /** Create a new enum and returns a reference to it */
398 enum_ref_t create_enum() const;
399};
400
401/** SoC register field enum reference */
402class enum_ref_t
403{
404 friend class field_ref_t;
405 field_ref_t m_field; /* reference to the field */
406 soc_id_t m_id; /* enum id */
407
408 enum_ref_t(field_ref_t reg, soc_id_t id);
409public:
410 /** Builds an invalid reference */
411 enum_ref_t();
412 /** Check whether this reference is valid/exists */
413 bool valid() const;
414 /** Returns a pointer to the enum, or 0 */
415 enum_t *get() const;
416 /** Returns a reference to the field containing the enum */
417 field_ref_t field() const;
327 /** Compare this reference to another */ 418 /** Compare this reference to another */
328 bool operator==(const field_ref_t& r) const; 419 bool operator==(const field_ref_t& r) const;
329 inline bool operator!=(const field_ref_t& r) const { return !operator==(r); } 420 inline bool operator!=(const field_ref_t& r) const { return !operator==(r); }
421 /** Make this reference invalid */
422 void reset();
423};
424
425/** SoC register variant reference */
426class variant_ref_t
427{
428 friend class register_ref_t;
429 register_ref_t m_reg; /* reference to the register */
430 soc_id_t m_id; /* variant name */
431
432 variant_ref_t(register_ref_t reg, soc_id_t id);
433public:
434 /** Builds an invalid reference */
435 variant_ref_t();
436 /** Check whether this reference is valid/exists */
437 bool valid() const;
438 /** Returns a pointer to the variant, or 0 */
439 variant_t *get() const;
440 /** Returns a reference to the register containing the field */
441 register_ref_t reg() const;
442 /** Returns variant type */
443 std::string type() const;
444 /** Returns variant offset */
445 soc_word_t offset() const;
446 /** Compare this reference to another */
447 bool operator==(const variant_ref_t& r) const;
448 inline bool operator!=(const variant_ref_t& r) const { return !operator==(r); }
449 /** Make this reference invalid */
450 void reset();
330}; 451};
331 452
332/** SoC node instance 453/** SoC node instance
@@ -353,8 +474,10 @@ public:
353 node_ref_t node() const; 474 node_ref_t node() const;
354 /** Check whether this reference is the root node instance */ 475 /** Check whether this reference is the root node instance */
355 bool is_root() const; 476 bool is_root() const;
356 /** Returns a reference to the parent instance */ 477 /** Returns a reference to the n-th parent instance, 0-th is itself, and so on */
357 node_inst_t parent() const; 478 node_inst_t parent(unsigned level = 1) const;
479 /** Returns reference depth, 0 is root, and so on */
480 unsigned depth() const;
358 /** Returns a pointer to the instance of the node, or 0 */ 481 /** Returns a pointer to the instance of the node, or 0 */
359 instance_t *get() const; 482 instance_t *get() const;
360 /** Returns the address of this instance */ 483 /** Returns the address of this instance */
@@ -377,6 +500,8 @@ public:
377 /** Compare this reference to another */ 500 /** Compare this reference to another */
378 bool operator==(const node_inst_t& r) const; 501 bool operator==(const node_inst_t& r) const;
379 inline bool operator!=(const node_inst_t& r) const { return !operator==(r); } 502 inline bool operator!=(const node_inst_t& r) const { return !operator==(r); }
503 /** Make this reference invalid */
504 void reset();
380}; 505};
381 506
382} // soc_desc 507} // soc_desc