Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / docs / mmi / mmi_register_config_cb.html
CommitLineData
920dae64
AT
1<html>
2<head>
3 <title>SPARC Architectural Model: Device and Utility API</title>
4</head>
5<body bgcolor="#FFFFFF" LANG="en-US">
6&nbsp;
7<h2>
8mmi_register_config_cb</h2>
9
10<h4>
11NAME</h4>
12
13<ul>mmi_register_config_cb - Register callback for configuration events</ul>
14
15<h4>
16SYNOPSIS</h4>
17
18<ul>
19<font color="#0000FF">#include "mmi.h"</font>
20<p>typedef enum {MMI_CONFIG_NEW_MODULE, MMI_CONFIG_DELETE_MODULE, MMI_CONFIG_INIT_DONE} mmi_config_t;
21<p>typedef void (*<i>fn_config_cb</i>) (void *<i>cb_data</i>,
22module_t *<i>target</i>, const char *<i>target_name</i>, mmi_config_t <i>event</i>);
23<p>bool_t mmi_register_config_cb (module_t *<i>module</i>, fn_config_cb <i>config_cb</i>);
24</ul>
25
26<h4>
27DESCRIPTION</h4>
28
29<ul>
30Register <i>config_cb</i> callback for <i>module</i>.
31</ul>
32
33<ul>
34The callback is used to act on configuration events:
35<p>MMI_CONFIG_NEW_MODULE: reports that <i>target</i> has been loaded.
36At this point, it is possible to call <b>mmi_get_interface</b> for <i>target</i>.
37
38<p>MMI_CONFIG_DELETE_MODULE: reports that <i>target</i> has been unloaded.
39There are two uses:
40<ul>
411) A module detects that itself is being unloaded, and frees any resources.
42</ul>
43<ul>
442) A module detects that another module it has in interface or other reference to is unloaded. Dangling pointers must be deleted.
45</ul>
46
47<p>MMI_CONFIG_INIT_DONE: reports that simulator initialization is complete.
48The module can reference CPU and other data structures at this point.
49</ul>
50
51<ul>
52<p><b>mmi_register_config_cb</b> has several side effects:
53<ul>
541) all other modules are notified that the caller is available (MMI_CONFIG_NEW_MODULE),
55</ul>
56<ul>
572) the caller is notified of all modules already loaded (MMI_CONFIG_NEW_MODULE),
58and
59</ul>
60<ul>
613) the caller is notified immediately if simulator initialization is complete (MMI_CONFIG_INIT_DONE).
62</ul>
63</ul>
64
65<h4>
66RETURN VALUES</h4>
67
68<h4>
69ERRORS</h4>
70
71<h4>
72USAGE</h4>
73<ul>
74<font size=-1>
75<pre>
76
77// config callback
78static void module_reconfig(void *cb_data, module_t *target, const char *target_name, mmi_config_t ev)
79{
80 Module *module = (Module*)cb_data;
81
82 if (target == module->getInstance()) {
83 if (ev == MMI_CONFIG_DELETE_MODULE)
84 delete module;
85 else if (ev == MMI_CONFIG_INIT_DONE)
86 module->init_done();
87 } else if (ev == MMI_CONFIG_NEW_MODULE) {
88 module->module_added(target, target_name);
89 } else if (ev == MMI_CONFIG_DELETE_MODULE) {
90 module->module_deleted(target, target_name);
91 }
92}
93
94// called during ldm and sysconf, after _init
95static void module_create_instance(const char *modname, const char *instance_name)
96{
97 module_t *instance = mmi_register_module(modname, instance_name, Module::get_help_string());
98 if (instance) {
99 Module *module = Module::create(modname, instance_name);
100 if (!module) {
101 fprintf(stderr, "Module: Could not create object for <%s>\n", instance_name);
102 mmi_unregister_module(instance);
103 } else {
104 fprintf(stderr, "Module: modname <%s> instance_name <%s>\n", modname, instance_name);
105 module_parse_args(module, instance);
106 if (!module->check_args()) {
107 mmi_unregister_module(instance);
108 } else {
109 mmi_register_cb_data(instance, module);
110 mmi_register_interface_cb(instance, module_get_interface);
111 mmi_register_modinfo_cb(instance, module_get_modinfo);
112 mmi_register_config_cb(instance, module_reconfig);
113 }
114 }
115 }
116}
117
118// module init, called during dlopen
119extern "C" void _init()
120{
121 fprintf (stderr, MODNAME ": _init()\n");
122 if (! mmi_register_instance_creator (MODNAME, module_create_instance )) {
123 fprintf (stderr, MODNAME ": Failed to load\n");
124 }
125}
126
127// called by dlclose during uldm and exit
128extern "C" void _fini()
129{
130}
131
132</pre>
133</font>
134</ul>
135<h4>
136SEE ALSO</h4>
137<ul>
138<a href="intro.html">intro</a>,
139&nbsp;&nbsp;&nbsp;&nbsp;
140<a href="mmi_register_module.html">mmi_unregister_module</a>
141</ul>
142<h4>
143WARNINGS</h4>
144&nbsp;
145</body>
146</html>