Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / docs / mmi / mmi_register_config_cb.html
<html>
<head>
<title>SPARC Architectural Model: Device and Utility API</title>
</head>
<body bgcolor="#FFFFFF" LANG="en-US">
&nbsp;
<h2>
mmi_register_config_cb</h2>
<h4>
NAME</h4>
<ul>mmi_register_config_cb - Register callback for configuration events</ul>
<h4>
SYNOPSIS</h4>
<ul>
<font color="#0000FF">#include "mmi.h"</font>
<p>typedef enum {MMI_CONFIG_NEW_MODULE, MMI_CONFIG_DELETE_MODULE, MMI_CONFIG_INIT_DONE} mmi_config_t;
<p>typedef void (*<i>fn_config_cb</i>) (void *<i>cb_data</i>,
module_t *<i>target</i>, const char *<i>target_name</i>, mmi_config_t <i>event</i>);
<p>bool_t mmi_register_config_cb (module_t *<i>module</i>, fn_config_cb <i>config_cb</i>);
</ul>
<h4>
DESCRIPTION</h4>
<ul>
Register <i>config_cb</i> callback for <i>module</i>.
</ul>
<ul>
The callback is used to act on configuration events:
<p>MMI_CONFIG_NEW_MODULE: reports that <i>target</i> has been loaded.
At this point, it is possible to call <b>mmi_get_interface</b> for <i>target</i>.
<p>MMI_CONFIG_DELETE_MODULE: reports that <i>target</i> has been unloaded.
There are two uses:
<ul>
1) A module detects that itself is being unloaded, and frees any resources.
</ul>
<ul>
2) A module detects that another module it has in interface or other reference to is unloaded. Dangling pointers must be deleted.
</ul>
<p>MMI_CONFIG_INIT_DONE: reports that simulator initialization is complete.
The module can reference CPU and other data structures at this point.
</ul>
<ul>
<p><b>mmi_register_config_cb</b> has several side effects:
<ul>
1) all other modules are notified that the caller is available (MMI_CONFIG_NEW_MODULE),
</ul>
<ul>
2) the caller is notified of all modules already loaded (MMI_CONFIG_NEW_MODULE),
and
</ul>
<ul>
3) the caller is notified immediately if simulator initialization is complete (MMI_CONFIG_INIT_DONE).
</ul>
</ul>
<h4>
RETURN VALUES</h4>
<h4>
ERRORS</h4>
<h4>
USAGE</h4>
<ul>
<font size=-1>
<pre>
// config callback
static void module_reconfig(void *cb_data, module_t *target, const char *target_name, mmi_config_t ev)
{
Module *module = (Module*)cb_data;
if (target == module->getInstance()) {
if (ev == MMI_CONFIG_DELETE_MODULE)
delete module;
else if (ev == MMI_CONFIG_INIT_DONE)
module->init_done();
} else if (ev == MMI_CONFIG_NEW_MODULE) {
module->module_added(target, target_name);
} else if (ev == MMI_CONFIG_DELETE_MODULE) {
module->module_deleted(target, target_name);
}
}
// called during ldm and sysconf, after _init
static void module_create_instance(const char *modname, const char *instance_name)
{
module_t *instance = mmi_register_module(modname, instance_name, Module::get_help_string());
if (instance) {
Module *module = Module::create(modname, instance_name);
if (!module) {
fprintf(stderr, "Module: Could not create object for <%s>\n", instance_name);
mmi_unregister_module(instance);
} else {
fprintf(stderr, "Module: modname <%s> instance_name <%s>\n", modname, instance_name);
module_parse_args(module, instance);
if (!module->check_args()) {
mmi_unregister_module(instance);
} else {
mmi_register_cb_data(instance, module);
mmi_register_interface_cb(instance, module_get_interface);
mmi_register_modinfo_cb(instance, module_get_modinfo);
mmi_register_config_cb(instance, module_reconfig);
}
}
}
}
// module init, called during dlopen
extern "C" void _init()
{
fprintf (stderr, MODNAME ": _init()\n");
if (! mmi_register_instance_creator (MODNAME, module_create_instance )) {
fprintf (stderr, MODNAME ": Failed to load\n");
}
}
// called by dlclose during uldm and exit
extern "C" void _fini()
{
}
</pre>
</font>
</ul>
<h4>
SEE ALSO</h4>
<ul>
<a href="intro.html">intro</a>,
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="mmi_register_module.html">mmi_unregister_module</a>
</ul>
<h4>
WARNINGS</h4>
&nbsp;
</body>
</html>