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 std::string cls_name(module_name);
64 cls_name += "_cci_global";
65 std::replace(cls_name.begin(), cls_name.end(), '-', '_');
66 conf_class_t *cls = SIM_get_class(cls_name.c_str());
67 if (SIM_clear_exception() == SimExc_No_Exception) {
68 return cls;
69 }
70
71 auto new_cls = make_class<CciGlobal>(
72 cls_name.c_str(),
73 "Global CCI parameters.",
74 "All CCI parameters on a global level.",
75 Sim_Class_Kind_Pseudo);
76#if INTC_EXT && USE_SIMICS_CCI
78 std::vector <cci::cci_param_handle> parameters =
79 cfg.getParameters(NULL);
80 std::vector <cci::cci_param_handle>::iterator i;
81 for (i = parameters.begin(); i != parameters.end(); ++i) {
82 const char *type = cfg.simicsType(*i);
83 if (!type)
84 continue;
85
86 int key = awareness::CciAttribute::define(i->name());
87 awareness::ProxyAttributeName attribute_name(cfg.simicsName(*i));
88 if (attribute_name.transformed()) {
89 SIM_LOG_INFO(4, obj, Log_Awareness,
90 "CCI Attribute %s is now %s.", i->name(),
91 attribute_name.c_str());
92 }
93
94 // SIM_register_typed_attribute expects a parameter of type void*.
95 // On windows, casting int to void* fails because int has a
96 // a different size compared to void*. According to spec, any
97 // pointer can be cast to void* and size of char is one.
98 char *key_arg = NULL;
99 key_arg += key;
100 SIM_register_typed_attribute(
101 *new_cls.get(), attribute_name.c_str(),
104 Sim_Attr_Pseudo, cfg.simicsType(*i), 0,
105 i->get_description().c_str());
106 if (SIM_clear_exception() != SimExc_No_Exception) {
107 SIM_LOG_ERROR(obj, Log_Awareness,
108 "Failed to register CCI attribute: '%s'",
109 attribute_name.c_str());
110 }
111 }
112#endif
113
114 return SIM_get_class(cls_name.c_str());
115 }
116
117 private:
118 awareness::Attributes *attributes_;
119};
120
121} // namespace systemc
122} // namespace simics
123
124#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: pci_bus_interface.h:24