SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
cci_global.h
Go to the documentation of this file.
1/*
2 © 2020 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_CCI_GLOBAL_H
15#define SIMICS_SYSTEMC_CCI_GLOBAL_H
16
17#include <simics/cc-api.h>
18#include <simics/simulator/sim-get-class.h>
19
24
25#include <algorithm>
26#include <string>
27#include <vector>
28
29namespace simics {
30namespace systemc {
31
33class CciGlobal : public ConfObject {
34 public:
35 explicit CciGlobal(ConfObjectRef o) : ConfObject(o), attributes_(NULL) {
36 }
37 void init(awareness::Attributes *attributes) {
38 attributes_ = attributes;
39 }
40
41 static attr_value_t getAttribute(lang_void *ptr, conf_object_t *obj,
42 attr_value_t *idx) {
43 uintptr_t key = reinterpret_cast<intptr_t>(ptr);
44 CciGlobal *o = simics::from_obj<CciGlobal>(obj);
45 attr_value_t result = o->attributes_->attribute<
46 awareness::CciAttribute>(key)->get();
47 return result;
48 }
49
50 static set_error_t setAttribute(lang_void *ptr, conf_object_t *obj,
51 attr_value_t *val, attr_value_t *idx) {
52 uintptr_t key = reinterpret_cast<intptr_t>(ptr);
53 CciGlobal *o = simics::from_obj<CciGlobal>(obj);
54 set_error_t result = o->attributes_->attribute<
55 awareness::CciAttribute>(key)->set(val);
56 return result;
57 }
58
59 static conf_class_t *initClass(const char *module_name,
60 ConfObjectRef obj) {
61 assert(module_name != NULL);
62 std::string cls_name(module_name);
63 cls_name += "_cci_global";
64 std::replace(cls_name.begin(), cls_name.end(), '-', '_');
65 conf_class_t *cls = SIM_get_class(cls_name.c_str());
66 if (SIM_clear_exception() == SimExc_No_Exception) {
67 return cls;
68 }
69
70 auto new_cls = make_class<CciGlobal>(
71 cls_name.c_str(),
72 "Global CCI parameters.",
73 "All CCI parameters on a global level.",
74 Sim_Class_Kind_Pseudo);
75#if INTC_EXT && USE_SIMICS_CCI
77 for (const auto &parameter : cfg.getParameters(NULL)) {
78 const char *type = cfg.simicsType(parameter);
79 if (!type)
80 continue;
81
82 int key = awareness::CciAttribute::define(parameter.name());
83 awareness::ProxyAttributeName attribute_name(
84 cfg.simicsName(parameter));
85 if (attribute_name.transformed()) {
86 SIM_LOG_INFO(4, obj, Log_Awareness,
87 "CCI Attribute %s is now %s.",
88 parameter.name(),
89 attribute_name.c_str());
90 }
91
92 // SIM_register_typed_attribute expects a parameter of type void*.
93 // On windows, casting int to void* fails because int has a
94 // a different size compared to void*. According to spec, any
95 // pointer can be cast to void* and size of char is one.
96 char *key_arg = NULL;
97 key_arg += key;
98 SIM_register_typed_attribute(
99 *new_cls.get(), attribute_name.c_str(),
102 Sim_Attr_Pseudo, cfg.simicsType(parameter), 0,
103 parameter.get_description().c_str());
104 if (SIM_clear_exception() != SimExc_No_Exception) {
105 SIM_LOG_ERROR(obj, Log_Awareness,
106 "Failed to register CCI attribute: '%s'",
107 attribute_name.c_str());
108 }
109 }
110#endif
111
112 return SIM_get_class(cls_name.c_str());
113 }
114
115 private:
116 awareness::Attributes *attributes_;
117};
118
119} // namespace systemc
120} // namespace simics
121
122#endif
Definition: cci_configuration.h:35
Definition: cci_global.h:33
static attr_value_t getAttribute(lang_void *ptr, conf_object_t *obj, attr_value_t *idx)
Definition: cci_global.h:41
CciGlobal(ConfObjectRef o)
Definition: cci_global.h:35
static conf_class_t * initClass(const char *module_name, ConfObjectRef obj)
Definition: cci_global.h:59
static set_error_t setAttribute(lang_void *ptr, conf_object_t *obj, attr_value_t *val, attr_value_t *idx)
Definition: cci_global.h:50
void init(awareness::Attributes *attributes)
Definition: cci_global.h:37
Definition: attributes.h:26
T * attribute(int key)
Definition: attributes.h:37
Definition: cci_attribute.h:32
static int define(std::string parameter_name)
Definition: proxy_attribute_name.h:30
conf_class_t * SIM_get_class(const char *NOTNULL name)
@ Log_Awareness
Definition: adapter_log_groups.h:24
Definition: adapter.h:79