17aec1d6cindi/*
23ad553agavinm * CDDL HEADER START
33ad553agavinm *
43ad553agavinm * The contents of this file are subject to the terms of the
53ad553agavinm * Common Development and Distribution License (the "License").
63ad553agavinm * You may not use this file except in compliance with the License.
73ad553agavinm *
83ad553agavinm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93ad553agavinm * or http://www.opensolaris.org/os/licensing.
103ad553agavinm * See the License for the specific language governing permissions
113ad553agavinm * and limitations under the License.
123ad553agavinm *
133ad553agavinm * When distributing Covered Code, include this CDDL HEADER in each
143ad553agavinm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153ad553agavinm * If applicable, add the following below this CDDL HEADER, with the
163ad553agavinm * fields enclosed by brackets "[]" replaced with your own identifying
173ad553agavinm * information: Portions Copyright [yyyy] [name of copyright owner]
183ad553agavinm *
193ad553agavinm * CDDL HEADER END
203ad553agavinm */
213ad553agavinm
223ad553agavinm/*
23a311483Gerry Liu * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247aec1d6cindi * Use is subject to license terms.
252a613b5Robert Mustacchi * Copyright (c) 2018, Joyent, Inc.
267aec1d6cindi */
277aec1d6cindi
287aec1d6cindi/*
297aec1d6cindi * Public interface to routines implemented by CPU modules
307aec1d6cindi */
317aec1d6cindi
3220c794bgavinm#include <sys/types.h>
3320c794bgavinm#include <sys/atomic.h>
347aec1d6cindi#include <sys/x86_archext.h>
357aec1d6cindi#include <sys/cpu_module_impl.h>
3620c794bgavinm#include <sys/cpu_module_ms.h>
377aec1d6cindi#include <sys/fm/util.h>
387aec1d6cindi#include <sys/reboot.h>
397aec1d6cindi#include <sys/modctl.h>
407aec1d6cindi#include <sys/param.h>
417aec1d6cindi#include <sys/cmn_err.h>
427aec1d6cindi#include <sys/systm.h>
4320c794bgavinm#include <sys/fm/protocol.h>
4420c794bgavinm#include <sys/pcb.h>
4520c794bgavinm#include <sys/ontrap.h>
4620c794bgavinm#include <sys/psw.h>
4720c794bgavinm#include <sys/privregs.h>
48e4b8688Cheng Sean Ye#include <sys/machsystm.h>
497aec1d6cindi
5020c794bgavinm/*
5120c794bgavinm * Set to force cmi_init to fail.
5220c794bgavinm */
5320c794bgavinmint cmi_no_init = 0;
547aec1d6cindi
5520c794bgavinm/*
5620c794bgavinm * Set to avoid MCA initialization.
5720c794bgavinm */
5820c794bgavinmint cmi_no_mca_init = 0;
597aec1d6cindi
607aec1d6cindi/*
618a40a69gavinm * If cleared for debugging we will not attempt to load a model-specific
628a40a69gavinm * cpu module but will load the generic cpu module instead.
638a40a69gavinm */
648a40a69gavinmint cmi_force_generic = 0;
658a40a69gavinm
668a40a69gavinm/*
677aec1d6cindi * If cleared for debugging, we will suppress panicking on fatal hardware
687aec1d6cindi * errors.  This should *only* be used for debugging; it use can and will
697aec1d6cindi * cause data corruption if actual hardware errors are detected by the system.
707aec1d6cindi */
717aec1d6cindiint cmi_panic_on_uncorrectable_error = 1;
727aec1d6cindi
73e3d60c9Adrian Frost/*
7420c794bgavinm * Subdirectory (relative to the module search path) in which we will
7520c794bgavinm * look for cpu modules.
7620c794bgavinm */
7720c794bgavinm#define	CPUMOD_SUBDIR	"cpu"
7820c794bgavinm
7920c794bgavinm/*
8020c794bgavinm * CPU modules have a filenames such as "cpu.AuthenticAMD.15" and
8120c794bgavinm * "cpu.generic" - the "cpu" prefix is specified by the following.
8220c794bgavinm */
8320c794bgavinm#define	CPUMOD_PREFIX	"cpu"
8420c794bgavinm
8520c794bgavinm/*
8620c794bgavinm * Structure used to keep track of cpu modules we have loaded and their ops
8720c794bgavinm */
8820c794bgavinmtypedef struct cmi {
8920c794bgavinm	struct cmi *cmi_next;
9020c794bgavinm	struct cmi *cmi_prev;
9120c794bgavinm	const cmi_ops_t *cmi_ops;
9220c794bgavinm	struct modctl *cmi_modp;
9320c794bgavinm	uint_t cmi_refcnt;
9420c794bgavinm} cmi_t;
9520c794bgavinm
967aec1d6cindistatic cmi_t *cmi_list;
97a311483Gerry Liustatic const cmi_mc_ops_t *cmi_mc_global_ops;
98a311483Gerry Liustatic void *cmi_mc_global_data;
997aec1d6cindistatic kmutex_t cmi_load_lock;
1007aec1d6cindi
10120c794bgavinm/*
10220c794bgavinm * Functions we need from cmi_hw.c that are not part of the cpu_module.h
10320c794bgavinm * interface.
10420c794bgavinm */
105e4b8688Cheng Sean Yeextern cmi_hdl_t cmi_hdl_create(enum cmi_hdl_class, uint_t, uint_t, uint_t);
106a311483Gerry Liuextern void cmi_hdl_destroy(cmi_hdl_t ophdl);
10720c794bgavinmextern void cmi_hdl_setcmi(cmi_hdl_t, void *, void *);
10820c794bgavinmextern void *cmi_hdl_getcmi(cmi_hdl_t);
10920c794bgavinmextern void cmi_hdl_setmc(cmi_hdl_t, const struct cmi_mc_ops *, void *);
110e4b8688Cheng Sean Yeextern void cmi_hdl_inj_begin(cmi_hdl_t);
111e4b8688Cheng Sean Yeextern void cmi_hdl_inj_end(cmi_hdl_t);
112074bb90Tom Pothierextern void cmi_read_smbios(cmi_hdl_t);
11320c794bgavinm
11420c794bgavinm#define	HDL2CMI(hdl)		cmi_hdl_getcmi(hdl)
11520c794bgavinm
11620c794bgavinm#define	CMI_OPS(cmi)		(cmi)->cmi_ops
11720c794bgavinm#define	CMI_OP_PRESENT(cmi, op)	((cmi) && CMI_OPS(cmi)->op != NULL)
118<