#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/systm.h>
#include <sys/sysmacros.h>
#include <sys/param.h>
#include <sys/mutex.h>
#include <sys/kmem.h>
#include <sys/machparam.h>
#include <sys/machsystm.h>
#include <sys/machthread.h>
#include <sys/cpu.h>
#include <sys/cpuvar.h>
#include <vm/page.h>
#include <vm/hat.h>
#include <vm/seg.h>
#include <vm/seg_kmem.h>
#include <sys/vmsystm.h>
#include <sys/vmem.h>
#include <sys/mman.h>
#include <sys/cmn_err.h>
#include <sys/time.h>
#include <sys/async.h>
#include <sys/spl.h>
#include <sys/trap.h>
#include <sys/machtrap.h>
#include <sys/promif.h>
#include <sys/prom_plat.h>
#include <sys/debug.h>
#include <sys/x_call.h>
#include <sys/membar.h>
#include <sys/ivintr.h>
#include <sys/cred.h>
#include <sys/cpu_module.h>
#include <sys/ontrap.h>
#include <sys/sdt.h>
#include <sys/errorq.h>
#define MAX_CE_FLTS 10
#define MAX_ASYNC_FLTS 6
errorq_t *ue_queue;
errorq_t *ce_queue;
int ce_verbose_memory = 1;
int ce_verbose_other = 1;
int ce_show_data = 0;
int ce_debug = 0;
int ue_debug = 0;
int reset_debug = 0;
int aft_verbose = 0;
int aft_panic = 0;
int aft_testfatal = 0;
struct async_flt panic_aflt;
extern kmutex_t bfd_lock;
void
bus_async_log_err(struct async_flt *aflt)
{
char unum[UNUM_NAMLEN];
int len;
if (aflt->flt_in_memory)
cpu_check_allcpus(aflt);
(void) cpu_get_mem_unum_aflt(AFLT_STAT_INVALID, aflt,
unum, UNUM_NAMLEN, &len);
aflt->flt_func(aflt, unum);
}
void
ecc_cpu_call(struct async_flt *ecc, char *unum, int err_type)
{
int len;
if (ecc->flt_in_memory)
cpu_check_allcpus(ecc);
(void) cpu_get_mem_unum(AFLT_STAT_VALID, ecc->flt_synd,
(uint64_t)-1, ecc->flt_addr,
ecc->flt_bus_id, ecc->flt_in_memory,
ecc->flt_status, unum,
UNUM_NAMLEN, &len);
if (err_type == ECC_IO_CE)
cpu_ce_count_unum(ecc, len, unum);
}
static void
ue_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
{
cpu_ue_log_err(aflt);
}
static void
ce_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
{
cpu_ce_log_err(aflt, eqep);
}
void
ce_scrub(struct async_flt *aflt)
{
if (aflt->flt_in_memory)
cpu_ce_scrub_mem_err(aflt, B_FALSE);
}
void
error_init(void)
{
char tmp_name[MAXSYSNAME];
pnode_t node;
size_t size = cpu_aflt_size();
ue_queue = errorq_create("ue_queue", (errorq_func_t)ue_drain, NULL,
MAX_ASYNC_FLTS * (max_ncpus + 1), size, PIL_2, ERRORQ_VITAL);
ce_queue = errorq_create("ce_queue", (errorq_func_t)ce_drain, NULL,
MAX_CE_FLTS * (max_ncpus + 1), size, PIL_1, 0);
if (ue_queue == NULL || ce_queue == NULL)
panic("failed to create required system error queue");
mutex_init(&bfd_lock, NULL, MUTEX_SPIN, (void *)PIL_15);
node = prom_rootnode();
if ((node == OBP_NONODE) || (node == OBP_BADNODE)) {
cmn_err(CE_CONT, "error_init: node 0x%x\n", (uint_t)node);
return;
}
if (((size = prom_getproplen(node, "reset-reason")) != -1) &&
(size <= MAXSYSNAME) &&
(prom_getprop(node, "reset-reason", tmp_name) != -1)) {
if (reset_debug) {
cmn_err(CE_CONT, "System booting after %s\n", tmp_name);
} else if (strncmp(tmp_name, "FATAL", 5) == 0) {
cmn_err(CE_CONT,
"System booting after fatal error %s\n", tmp_name);
}
}
if (&cpu_error_init) {
cpu_error_init((MAX_ASYNC_FLTS + MAX_CE_FLTS) *
(max_ncpus + 1));
}
}
#define PAGE_ZERO_SUCCESS 0
#define PAGE_ZERO_FAIL_NOLOCK 1
#define PAGE_ZERO_FAIL_ONTRAP 2
void
ecc_page_zero(void *arg)
{
uint64_t pa = (uint64_t)arg;
int ret, success_flag;
page_t *pp = page_numtopp_nolock(mmu_btop(pa));
if (page_retire_check(pa, NULL) != 0)
return;
ret = page_lock_es(pp, SE_SHARED, (kmutex_t *)NULL,
P_NO_RECLAIM, SE_RETIRED);
if (ret > 0) {
on_trap_data_t otd;
if (!on_trap(&otd, OT_DATA_EC)) {
pagezero(pp, 0, PAGESIZE);
success_flag = PAGE_ZERO_SUCCESS;
} else {
success_flag = PAGE_ZERO_FAIL_ONTRAP;
}
no_trap();
page_unlock(pp);
} else {
success_flag = PAGE_ZERO_FAIL_NOLOCK;
}
DTRACE_PROBE2(page_zero_result, int, success_flag, uint64_t, pa);
}