#include <sys/types.h>
#include <sys/cmn_err.h>
#include <sys/sunddi.h>
#include <sys/note.h>
#include <sys/sysevent.h>
#include <sys/sysevent/dr.h>
#include <sys/sysevent/eventdefs.h>
#include <sys/ldoms.h>
#include <sys/memlist.h>
#include <sys/dr_util.h>
extern int ppvm_enable;
boolean_t
dr_is_disabled(dr_type_t type)
{
_NOTE(ARGUNUSED(type))
if (!domaining_enabled()) {
cmn_err(CE_NOTE, "!Kernel CIF handler is not enabled, DR "
"is not available\n");
return (B_TRUE);
}
if (type == DR_TYPE_MEM && ppvm_enable == 0) {
cmn_err(CE_NOTE, "!Memory DR is disabled\n");
return (B_TRUE);
}
return (B_FALSE);
}
void
dr_generate_event(dr_type_t type, int se_hint)
{
int rv;
sysevent_id_t eid;
sysevent_t *ev = NULL;
sysevent_attr_list_t *evnt_attr_list = NULL;
sysevent_value_t evnt_val;
static char pubname[] = SUNW_KERN_PUB"dr";
DR_DBG_ALL("generate_event: type=%s, hint=%s\n", DR_TYPE2STR(type),
SE_HINT2STR(se_hint));
ev = sysevent_alloc(EC_DR, ESC_DR_AP_STATE_CHANGE, pubname, KM_SLEEP);
evnt_val.value_type = SE_DATA_TYPE_STRING;
evnt_val.value.sv_string = DR_TYPE2STR(type);
rv = sysevent_add_attr(&evnt_attr_list, DR_AP_ID, &evnt_val, KM_SLEEP);
if (rv != 0) {
DR_DBG_ALL("generate_event: failed to add attr '%s' for "
"'%s' event\n", DR_AP_ID, EC_DR);
goto done;
}
evnt_val.value_type = SE_DATA_TYPE_STRING;
evnt_val.value.sv_string = SE_HINT2STR(se_hint);
rv = sysevent_add_attr(&evnt_attr_list, DR_HINT, &evnt_val, KM_SLEEP);
if (rv != 0) {
DR_DBG_ALL("generate_event: failed to add attr '%s' for "
"'%s' event\n", DR_HINT, EC_DR);
sysevent_free_attr(evnt_attr_list);
goto done;
}
rv = sysevent_attach_attributes(ev, evnt_attr_list);
if (rv != 0) {
DR_DBG_ALL("generate_event: failed to add attr list for "
"'%s' event\n", EC_DR);
sysevent_free_attr(evnt_attr_list);
goto done;
}
rv = log_sysevent(ev, KM_NOSLEEP, &eid);
if (rv != 0) {
DR_DBG_ALL("generate_event: failed to log event (%d)\n", rv);
}
done:
if (ev != NULL)
sysevent_free(ev);
}
struct memlist *
dr_memlist_dup(struct memlist *mlist)
{
struct memlist *hl = NULL, *tl, **mlp;
if (mlist == NULL)
return (NULL);
mlp = &hl;
tl = *mlp;
for (; mlist; mlist = mlist->ml_next) {
*mlp = (struct memlist *)kmem_zalloc(sizeof (struct memlist),\
KM_SLEEP);
(*mlp)->ml_address = mlist->ml_address;
(*mlp)->ml_size = mlist->ml_size;
(*mlp)->ml_prev = tl;
tl = *mlp;
mlp = &((*mlp)->ml_next);
}
*mlp = NULL;
return (hl);
}
void
dr_memlist_delete(struct memlist *mlist)
{
register struct memlist *ml;
for (ml = mlist; ml; ml = mlist) {
mlist = ml->ml_next;
kmem_free((void *)ml, sizeof (struct memlist));
}
}
#ifdef DEBUG
uint_t dr_debug = 0x0;
#define BYTESPERLINE 8
#define LINEWIDTH ((BYTESPERLINE * 3) + (BYTESPERLINE + 2) + 1)
#define ASCIIOFFSET ((BYTESPERLINE * 3) + 2)
#define ISPRINT(c) ((c >= ' ') && (c <= '~'))
void
dr_dbg_dump_msg(void *buf, size_t len)
{
int i, j;
char *msg = buf;
char *curr;
char *aoff;
char line[LINEWIDTH];
if (!(dr_debug & DR_DBG_FLAG_TRANS)) {
return;
}
for (i = 0; i < len; i += BYTESPERLINE) {
bzero(line, LINEWIDTH);
curr = line;
aoff = line + ASCIIOFFSET;
for (j = 0; (j < BYTESPERLINE) && ((i + j) < len); j++) {
(void) sprintf(curr, " %02x", msg[i + j]);
*aoff = (ISPRINT(msg[i + j])) ? msg[i + j] : '.';
curr += 3;
aoff++;
}
while (curr != (line + ASCIIOFFSET))
*curr++ = ' ';
DR_DBG_TRANS("%s\n", line);
}
}
#endif