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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Copyright (c) 2010, Intel Corporation.
28 * All rights reserved.
32 * Generic x86 CPU Module
34 * This CPU module is used for generic x86 CPUs when Solaris has no other
35 * CPU-specific support module available. Code in this module should be the
36 * absolute bare-bones support and must be cognizant of both Intel and AMD etc.
39 #include <sys/types.h>
40 #include <sys/cpu_module_impl.h>
41 #include <sys/cpuvar.h>
43 #include <sys/modctl.h>
49 * Prevent generic cpu support from loading.
53 #define GCPU_MAX_CHIPID 32
54 static struct gcpu_chipshared
*gcpu_shared
[GCPU_MAX_CHIPID
];
57 * Our cmi_init entry point, called during startup of each cpu instance.
60 gcpu_init(cmi_hdl_t hdl
, void **datap
)
62 uint_t chipid
= cmi_hdl_chipid(hdl
);
63 struct gcpu_chipshared
*sp
, *osp
;
66 if (gcpu_disable
|| chipid
>= GCPU_MAX_CHIPID
)
70 * Allocate the state structure for this cpu. We will only
71 * allocate the bank logout areas in gcpu_mca_init once we
72 * know how many banks there are.
74 gcpu
= *datap
= kmem_zalloc(sizeof (gcpu_data_t
), KM_SLEEP
);
75 cmi_hdl_hold(hdl
); /* release in gcpu_fini */
79 * Allocate a chipshared structure if no sibling cpu has already
80 * allocated it, but allow for the fact that a sibling core may
81 * be starting up in parallel.
83 if ((sp
= gcpu_shared
[chipid
]) == NULL
) {
84 sp
= kmem_zalloc(sizeof (struct gcpu_chipshared
), KM_SLEEP
);
85 mutex_init(&sp
->gcpus_poll_lock
, NULL
, MUTEX_DRIVER
, NULL
);
86 mutex_init(&sp
->gcpus_cfglock
, NULL
, MUTEX_DRIVER
, NULL
);
87 osp
= atomic_cas_ptr(&gcpu_shared
[chipid
], NULL
, sp
);
89 mutex_destroy(&sp
->gcpus_cfglock
);
90 mutex_destroy(&sp
->gcpus_poll_lock
);
91 kmem_free(sp
, sizeof (struct gcpu_chipshared
));
96 atomic_inc_32(&sp
->gcpus_actv_cnt
);
97 gcpu
->gcpu_shared
= sp
;
103 * deconfigure gcpu_init()
106 gcpu_fini(cmi_hdl_t hdl
)
108 uint_t chipid
= cmi_hdl_chipid(hdl
);
109 gcpu_data_t
*gcpu
= cmi_hdl_getcmidata(hdl
);
110 struct gcpu_chipshared
*sp
;
112 if (gcpu_disable
|| chipid
>= GCPU_MAX_CHIPID
)
118 * Keep shared data in cache for reuse.
120 sp
= gcpu_shared
[chipid
];
122 atomic_dec_32(&sp
->gcpus_actv_cnt
);
125 kmem_free(gcpu
, sizeof (gcpu_data_t
));
127 /* Release reference count held in gcpu_init(). */
132 gcpu_post_startup(cmi_hdl_t hdl
)
134 gcpu_data_t
*gcpu
= cmi_hdl_getcmidata(hdl
);
140 cms_post_startup(hdl
);
144 gcpu_post_mpstartup(cmi_hdl_t hdl
)
149 cms_post_mpstartup(hdl
);
152 * All cpu handles are initialized only once all cpus
153 * are started, so we can begin polling post mp startup.
155 gcpu_mca_poll_start(hdl
);
158 #define GCPU_OP(ntvop, xpvop) ntvop
160 cmi_api_ver_t _cmi_api_version
= CMI_API_VERSION_3
;
162 const cmi_ops_t _cmi_ops
= {
163 gcpu_init
, /* cmi_init */
164 gcpu_post_startup
, /* cmi_post_startup */
165 gcpu_post_mpstartup
, /* cmi_post_mpstartup */
166 gcpu_faulted_enter
, /* cmi_faulted_enter */
167 gcpu_faulted_exit
, /* cmi_faulted_exit */
168 gcpu_mca_init
, /* cmi_mca_init */
169 GCPU_OP(gcpu_mca_trap
, NULL
), /* cmi_mca_trap */
170 GCPU_OP(gcpu_cmci_trap
, NULL
), /* cmi_cmci_trap */
171 gcpu_msrinject
, /* cmi_msrinject */
172 GCPU_OP(gcpu_hdl_poke
, NULL
), /* cmi_hdl_poke */
173 gcpu_fini
, /* cmi_fini */
174 GCPU_OP(NULL
, gcpu_xpv_panic_callback
), /* cmi_panic_callback */
177 static struct modlcpu modlcpu
= {
179 "Generic x86 CPU Module"
182 static struct modlinkage modlinkage
= {
191 return (mod_install(&modlinkage
));
195 _info(struct modinfo
*modinfop
)
197 return (mod_info(&modlinkage
, modinfop
));
203 return (mod_remove(&modlinkage
));