Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/intel_nhm/intel_nhmdrv.c
+++ new/usr/src/uts/intel/io/intel_nhm/intel_nhmdrv.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #include <sys/types.h>
28 28 #include <sys/time.h>
29 29 #include <sys/nvpair.h>
30 30 #include <sys/cmn_err.h>
31 31 #include <sys/cred.h>
32 32 #include <sys/open.h>
33 33 #include <sys/ddi.h>
34 34 #include <sys/sunddi.h>
35 35 #include <sys/conf.h>
36 36 #include <sys/modctl.h>
37 37 #include <sys/cyclic.h>
38 38 #include <sys/errorq.h>
39 39 #include <sys/stat.h>
40 40 #include <sys/cpuvar.h>
41 41 #include <sys/mc_intel.h>
42 42 #include <sys/mc.h>
43 43 #include <sys/fm/protocol.h>
44 44 #include "nhm_log.h"
45 45 #include "intel_nhm.h"
46 46
47 47 int max_bus_number = 0xff;
48 48
49 49 nvlist_t *inhm_mc_nvl[MAX_CPU_NODES];
50 50 krwlock_t inhm_mc_lock;
51 51
52 52 char *inhm_mc_snapshot[MAX_CPU_NODES];
53 53 uint_t nhm_config_gen;
54 54 uint_t inhm_mc_snapshotgen;
55 55 size_t inhm_mc_snapshotsz[MAX_CPU_NODES];
56 56 static dev_info_t *inhm_dip;
57 57 int nhm_allow_detach = 0;
58 58
59 59 extern int nhm_patrol_scrub;
60 60 extern int nhm_demand_scrub;
61 61 extern int nhm_no_smbios;
62 62 extern int nhm_smbios_serial;
63 63 extern int nhm_smbios_manufacturer;
64 64 extern int nhm_smbios_part_number;
65 65 extern int nhm_smbios_version;
66 66 extern int nhm_smbios_label;
67 67
68 68 extern void inhm_create_nvl(int);
69 69 extern char *inhm_mc_name(void);
70 70 extern void init_dimms(void);
71 71 extern void nhm_smbios();
72 72
73 73 static void
74 74 inhm_mc_snapshot_destroy()
75 75 {
76 76 int i;
77 77
78 78 ASSERT(RW_LOCK_HELD(&inhm_mc_lock));
79 79
80 80 for (i = 0; i < MAX_CPU_NODES; i++) {
81 81 if (inhm_mc_snapshot[i] == NULL)
82 82 continue;
83 83
84 84 kmem_free(inhm_mc_snapshot[i], inhm_mc_snapshotsz[i]);
85 85 inhm_mc_snapshot[i] = NULL;
86 86 inhm_mc_snapshotsz[i] = 0;
87 87 }
88 88 inhm_mc_snapshotgen++;
89 89 }
90 90
91 91 static int
92 92 inhm_mc_snapshot_update()
93 93 {
94 94 int i;
95 95 int rt = 0;
96 96
97 97 ASSERT(RW_LOCK_HELD(&inhm_mc_lock));
98 98
99 99 for (i = 0; i < MAX_CPU_NODES; i++) {
100 100 if (inhm_mc_snapshot[i] != NULL)
101 101 continue;
102 102
103 103 if (nvlist_pack(inhm_mc_nvl[i], &inhm_mc_snapshot[i],
104 104 &inhm_mc_snapshotsz[i], NV_ENCODE_XDR, KM_SLEEP) != 0)
105 105 rt = -1;
106 106 }
107 107
108 108 return (rt);
109 109 }
110 110
111 111 /*ARGSUSED*/
112 112 static int
113 113 inhm_mc_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
114 114 int *rvalp)
115 115 {
116 116 int rc = 0;
117 117 int chip;
118 118 mc_snapshot_info_t mcs;
119 119
120 120 if (cmd != MC_IOC_SNAPSHOT_INFO && cmd != MC_IOC_SNAPSHOT)
121 121 return (EINVAL);
122 122
123 123 rw_enter(&inhm_mc_lock, RW_READER);
124 124 chip = getminor(dev) % MAX_CPU_NODES;
125 125 if (inhm_mc_nvl[chip] == NULL ||
126 126 inhm_mc_snapshotgen != nhm_config_gen) {
127 127 if (!rw_tryupgrade(&inhm_mc_lock)) {
128 128 rw_exit(&inhm_mc_lock);
129 129 return (EAGAIN);
130 130 }
131 131 if (inhm_mc_nvl[chip])
132 132 inhm_mc_snapshot_destroy();
133 133 inhm_create_nvl(chip);
134 134 nhm_config_gen = inhm_mc_snapshotgen;
135 135 (void) inhm_mc_snapshot_update();
136 136 }
137 137 switch (cmd) {
138 138 case MC_IOC_SNAPSHOT_INFO:
139 139 mcs.mcs_size = (uint32_t)inhm_mc_snapshotsz[chip];
140 140 mcs.mcs_gen = inhm_mc_snapshotgen;
141 141
142 142 if (ddi_copyout(&mcs, (void *)arg, sizeof (mc_snapshot_info_t),
143 143 mode) < 0)
144 144 rc = EFAULT;
145 145 break;
146 146 case MC_IOC_SNAPSHOT:
147 147 if (ddi_copyout(inhm_mc_snapshot[chip], (void *)arg,
148 148 inhm_mc_snapshotsz[chip], mode) < 0)
149 149 rc = EFAULT;
150 150 break;
151 151 }
152 152 rw_exit(&inhm_mc_lock);
153 153 return (rc);
154 154 }
155 155
156 156 /*ARGSUSED*/
157 157 static int
158 158 inhm_mc_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
159 159 void **result)
160 160 {
161 161 if ((infocmd != DDI_INFO_DEVT2DEVINFO &&
162 162 infocmd != DDI_INFO_DEVT2INSTANCE) || inhm_dip == NULL) {
163 163 *result = NULL;
164 164 return (DDI_FAILURE);
165 165 }
166 166 if (infocmd == DDI_INFO_DEVT2DEVINFO)
167 167 *result = inhm_dip;
168 168 else
169 169 *result = (void *)(uintptr_t)ddi_get_instance(inhm_dip);
170 170 return (0);
171 171 }
172 172
173 173 static int
174 174 inhm_mc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
175 175 {
176 176 int i;
177 177 char buf[64];
178 178
179 179 if (cmd == DDI_RESUME) {
180 180 nhm_dev_reinit();
181 181 nhm_scrubber_enable();
182 182 nhm_smbios();
183 183 return (DDI_SUCCESS);
184 184 }
185 185 if (cmd != DDI_ATTACH)
186 186 return (DDI_FAILURE);
187 187 if (inhm_dip == NULL) {
188 188 inhm_dip = dip;
189 189 nhm_pci_cfg_setup(dip);
190 190 (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, "model",
191 191 inhm_mc_name());
192 192 if (nhm_dev_init()) {
193 193 nhm_pci_cfg_free();
194 194 inhm_dip = NULL;
195 195 return (DDI_FAILURE);
196 196 }
197 197 ddi_set_name_addr(dip, "1");
198 198 for (i = 0; i < MAX_CPU_NODES; i++) {
199 199 (void) snprintf(buf, sizeof (buf), "mc-intel-%d", i);
200 200 if (ddi_create_minor_node(dip, buf, S_IFCHR,
201 201 i, "ddi_mem_ctrl", 0) != DDI_SUCCESS) {
202 202 cmn_err(CE_WARN, "failed to create minor node"
203 203 " for memory controller %d\n", i);
204 204 }
205 205 }
206 206 cmi_hdl_walk(inhm_mc_register, NULL, NULL, NULL);
207 207 nhm_patrol_scrub = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
208 208 DDI_PROP_DONTPASS, "patrol-scrub", 0);
209 209 nhm_demand_scrub = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
210 210 DDI_PROP_DONTPASS, "demand-scrub", 0);
211 211 nhm_no_smbios = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
212 212 DDI_PROP_DONTPASS, "no-smbios", 0);
213 213 nhm_smbios_serial = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
214 214 DDI_PROP_DONTPASS, "smbios-dimm-serial", 1);
215 215 nhm_smbios_manufacturer = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
216 216 DDI_PROP_DONTPASS, "smbios-dimm-manufacturer", 1);
217 217 nhm_smbios_part_number = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
218 218 DDI_PROP_DONTPASS, "smbios-dimm-part-number", 1);
219 219 nhm_smbios_version = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
220 220 DDI_PROP_DONTPASS, "smbios-dimme-version", 1);
221 221 nhm_smbios_label = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
222 222 DDI_PROP_DONTPASS, "smbios-dimm-label", 1);
223 223 nhm_scrubber_enable();
224 224 nhm_smbios();
225 225 }
226 226
227 227 return (DDI_SUCCESS);
228 228 }
229 229
230 230 /*ARGSUSED*/
231 231 static int
232 232 inhm_mc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
233 233 {
234 234 if (nhm_allow_detach && cmd == DDI_DETACH && dip == inhm_dip) {
235 235 rw_enter(&inhm_mc_lock, RW_WRITER);
236 236 inhm_mc_snapshot_destroy();
237 237 rw_exit(&inhm_mc_lock);
238 238 inhm_dip = NULL;
239 239 return (DDI_SUCCESS);
240 240 } else if (cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND) {
241 241 return (DDI_SUCCESS);
242 242 } else {
243 243 return (DDI_FAILURE);
244 244 }
245 245 }
246 246
247 247 /*ARGSUSED*/
248 248 static int
249 249 inhm_mc_open(dev_t *devp, int flag, int otyp, cred_t *credp)
250 250 {
251 251 if (otyp != OTYP_CHR)
252 252 return (EINVAL);
253 253
254 254 rw_enter(&inhm_mc_lock, RW_READER);
255 255 if (getminor(*devp) >= MAX_CPU_NODES) {
256 256 rw_exit(&inhm_mc_lock);
257 257 return (EINVAL);
258 258 }
259 259 rw_exit(&inhm_mc_lock);
260 260
261 261 return (0);
262 262 }
263 263
264 264 /*ARGSUSED*/
265 265 static int
266 266 inhm_mc_close(dev_t dev, int flag, int otyp, cred_t *credp)
267 267 {
268 268 return (0);
269 269 }
270 270
271 271
272 272 static struct cb_ops inhm_mc_cb_ops = {
273 273 inhm_mc_open,
274 274 inhm_mc_close,
275 275 nodev, /* not a block driver */
276 276 nodev, /* no print routine */
277 277 nodev, /* no dump routine */
278 278 nodev, /* no read routine */
279 279 nodev, /* no write routine */
280 280 inhm_mc_ioctl,
281 281 nodev, /* no devmap routine */
282 282 nodev, /* no mmap routine */
283 283 nodev, /* no segmap routine */
284 284 nochpoll, /* no chpoll routine */
285 285 ddi_prop_op,
286 286 0, /* not a STREAMS driver */
287 287 D_NEW | D_MP, /* safe for multi-thread/multi-processor */
288 288 };
289 289
290 290 static struct dev_ops inhm_mc_ops = {
291 291 DEVO_REV, /* devo_rev */
292 292 0, /* devo_refcnt */
293 293 inhm_mc_getinfo, /* devo_getinfo */
294 294 nulldev, /* devo_identify */
295 295 nulldev, /* devo_probe */
296 296 inhm_mc_attach, /* devo_attach */
297 297 inhm_mc_detach, /* devo_detach */
298 298 nodev, /* devo_reset */
299 299 &inhm_mc_cb_ops, /* devo_cb_ops */
300 300 NULL, /* devo_bus_ops */
301 301 NULL, /* devo_power */
302 302 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
302 lines elided |
↑ open up ↑ |
303 303 };
304 304
305 305 static struct modldrv modldrv = {
306 306 &mod_driverops,
307 307 "Intel QuickPath Memory Controller Hub Module",
308 308 &inhm_mc_ops
309 309 };
310 310
311 311 static struct modlinkage modlinkage = {
312 312 MODREV_1,
313 - (void *)&modldrv,
314 - NULL
313 + { (void *)&modldrv, NULL }
315 314 };
316 315
317 316 int
318 317 _init(void)
319 318 {
320 319 int err;
321 320
322 321 err = nhm_init();
323 322 if (err == 0 && (err = mod_install(&modlinkage)) == 0) {
324 323 rw_init(&inhm_mc_lock, NULL, RW_DRIVER, NULL);
325 324 init_dimms();
326 325 }
327 326
328 327 return (err);
329 328 }
330 329
331 330 int
332 331 _info(struct modinfo *modinfop)
333 332 {
334 333 return (mod_info(&modlinkage, modinfop));
335 334 }
336 335
337 336 int
338 337 _fini(void)
339 338 {
340 339 int err;
341 340
342 341 if ((err = mod_remove(&modlinkage)) == 0) {
343 342 nhm_unload();
344 343 rw_destroy(&inhm_mc_lock);
345 344 }
346 345
347 346 return (err);
348 347 }
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX