xref: /illumos-gate/usr/src/uts/i86pc/cpu/amd_opteron/ao_main.c (revision 76716eaced8d7659d4594350eb3f343c31fe2806)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * The CPU module for the AMD Athlon64 and Opteron processors
31  */
32 
33 #include <sys/types.h>
34 #include <sys/cmn_err.h>
35 #include <sys/sunddi.h>
36 #include <sys/cpu_module_impl.h>
37 #include <sys/cpuvar.h>
38 #include <sys/x86_archext.h>
39 #include <sys/kmem.h>
40 #include <sys/modctl.h>
41 #include <sys/mc.h>
42 
43 #include "ao.h"
44 
45 /*
46  * At present this CPU module only supports the features for Athlon64 and
47  * Opteron up to and including the Rev E processor.  If we detect Rev F or
48  * later, return ENOTSUP and let the generic x86 CPU module load instead.
49  * Opteron Rev F is currently defined as Family 0xF Model [0x40 .. 0x5F].
50  */
51 uint_t ao_model_limit = 0x40;
52 
53 static int
54 ao_init(cpu_t *cp, void **datap)
55 {
56 	ao_data_t *ao;
57 
58 	if (cpuid_getmodel(cp) >= ao_model_limit)
59 		return (ENOTSUP);
60 
61 	ao = *datap = kmem_zalloc(sizeof (ao_data_t), KM_SLEEP);
62 	ao->ao_cpu = cp;
63 
64 	return (0);
65 }
66 
67 /*ARGSUSED*/
68 static void
69 ao_post_mpstartup(void *data)
70 {
71 	(void) ddi_install_driver("mc-amd");
72 }
73 
74 static void
75 ao_fini(void *data)
76 {
77 	kmem_free(data, sizeof (ao_data_t));
78 }
79 
80 const cmi_ops_t _cmi_ops = {
81 	ao_init,
82 	ao_mca_post_init,
83 	ao_post_mpstartup,
84 	ao_fini,
85 	ao_faulted_enter,
86 	ao_faulted_exit,
87 	ao_scrubber_enable,
88 	ao_mca_init,
89 	ao_mca_trap,
90 	ao_mca_inject,
91 	ao_mca_poke,
92 	ao_mc_register,
93 	ao_mc_getops
94 };
95 
96 static struct modlcpu modlcpu = {
97 	&mod_cpuops,
98 	"AMD Athlon64/Opteron CPU Module"
99 };
100 
101 static struct modlinkage modlinkage = {
102 	MODREV_1,
103 	(void *)&modlcpu,
104 	NULL
105 };
106 
107 int
108 _init(void)
109 {
110 	int err;
111 
112 	ao_mca_queue = errorq_create("ao_mca_queue",
113 	    ao_mca_drain, NULL, AO_MCA_MAX_ERRORS * (max_ncpus + 1),
114 	    sizeof (ao_cpu_logout_t), 1, ERRORQ_VITAL);
115 
116 	if (ao_mca_queue == NULL)
117 		return (EAGAIN); /* errorq_create() logs a message for us */
118 
119 	if ((err = mod_install(&modlinkage)) != 0) {
120 		errorq_destroy(ao_mca_queue);
121 		ao_mca_queue = NULL;
122 	}
123 
124 	return (err);
125 }
126 
127 int
128 _info(struct modinfo *modinfop)
129 {
130 	return (mod_info(&modlinkage, modinfop));
131 }
132 
133 int
134 _fini(void)
135 {
136 	int err;
137 
138 	if ((err = mod_remove(&modlinkage)) == 0)
139 		errorq_destroy(ao_mca_queue);
140 
141 	return (err);
142 }
143