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