Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ucodeadm/ucodeadm.c
+++ new/usr/src/cmd/ucodeadm/ucodeadm.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
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 +/*
27 + * Copyright (c) 2018, Joyent, Inc.
28 + */
29 +
26 30 #include <sys/types.h>
27 31 #include <sys/processor.h>
28 32 #include <sys/ucode.h>
29 33 #include <sys/ioctl.h>
30 34 #include <sys/stat.h>
31 35 #include <unistd.h>
32 36 #include <dirent.h>
33 37 #include <fcntl.h>
34 38 #include <errno.h>
35 39 #include <stdio.h>
36 40 #include <stdlib.h>
37 41 #include <stdarg.h>
38 42 #include <string.h>
39 43 #include <errno.h>
40 44 #include <syslog.h>
41 45 #include <time.h>
42 46 #include <ctype.h>
43 47 #include <assert.h>
44 48 #include <libgen.h>
45 49 #include <locale.h>
46 50 #include <libintl.h>
47 51
48 52 #define UCODE_OPT_INSTALL 0x0001
49 53 #define UCODE_OPT_UPDATE 0x0002
50 54 #define UCODE_OPT_VERSION 0x0004
51 55
52 56 static const char ucode_dev[] = "/dev/" UCODE_DRIVER_NAME;
53 57
54 58 static char *cmdname;
55 59
56 60 static char ucode_vendor_str[UCODE_MAX_VENDORS_NAME_LEN];
57 61 static char ucode_install_path[] = UCODE_INSTALL_PATH;
58 62
59 63 static int ucode_debug = 0;
60 64
61 65 static int ucode_convert_amd(const char *, uint8_t *, size_t);
62 66 static int ucode_convert_intel(const char *, uint8_t *, size_t);
63 67
64 68 static ucode_errno_t ucode_gen_files_amd(uint8_t *, int, char *);
65 69 static ucode_errno_t ucode_gen_files_intel(uint8_t *, int, char *);
66 70
67 71 static const struct ucode_ops ucode_ops[] = {
68 72 { ucode_convert_intel, ucode_gen_files_intel, ucode_validate_intel },
69 73 { ucode_convert_amd, ucode_gen_files_amd, ucode_validate_amd },
70 74 };
71 75
72 76 const struct ucode_ops *ucode;
73 77
74 78 static void
75 79 dprintf(const char *format, ...)
76 80 {
77 81 if (ucode_debug) {
78 82 va_list alist;
79 83 va_start(alist, format);
80 84 (void) vfprintf(stderr, format, alist);
81 85 va_end(alist);
82 86 }
83 87 }
84 88
85 89 static void
86 90 usage(int verbose)
87 91 {
88 92 (void) fprintf(stderr, gettext("usage:\n"));
89 93 (void) fprintf(stderr, "\t%s -v\n", cmdname);
90 94 if (verbose) {
91 95 (void) fprintf(stderr,
92 96 gettext("\t\t Shows running microcode version.\n\n"));
93 97 }
94 98
95 99 (void) fprintf(stderr, "\t%s -u microcode-file\n", cmdname);
96 100 if (verbose) {
97 101 (void) fprintf(stderr, gettext("\t\t Updates microcode to the "
98 102 "latest matching version found in\n"
99 103 "\t\t microcode-file.\n\n"));
100 104 }
101 105
102 106 (void) fprintf(stderr, "\t%s -i [-R path] microcode-file\n", cmdname);
103 107 if (verbose) {
104 108 (void) fprintf(stderr, gettext("\t\t Installs microcode to be "
105 109 "used for subsequent boots.\n\n"));
106 110 (void) fprintf(stderr, gettext("Microcode file name must start "
107 111 "with vendor name, such as \"intel\" or \"amd\".\n\n"));
108 112 }
109 113 }
110 114
111 115 static void
112 116 ucode_perror(const char *str, ucode_errno_t rc)
113 117 {
114 118 (void) fprintf(stderr, "%s: %s: %s\n", cmdname, str,
115 119 errno == 0 ? ucode_strerror(rc) : strerror(errno));
116 120 errno = 0;
117 121 }
118 122
119 123 #define LINESIZE 120 /* copyright line sometimes is longer than 80 */
120 124
121 125 /*
122 126 * Convert text format microcode release into binary format.
123 127 * Return the number of characters read.
124 128 */
125 129 static int
126 130 ucode_convert_amd(const char *infile, uint8_t *buf, size_t size)
127 131 {
128 132 int fd;
129 133
130 134 if (infile == NULL || buf == NULL || size == 0)
131 135 return (0);
132 136
133 137 if ((fd = open(infile, O_RDONLY)) < 0)
134 138 return (0);
135 139
136 140 size = read(fd, buf, size);
137 141
138 142 (void) close(fd);
139 143
140 144 return (size);
141 145 }
142 146
143 147 static int
144 148 ucode_convert_intel(const char *infile, uint8_t *buf, size_t size)
145 149 {
146 150 char linebuf[LINESIZE];
147 151 FILE *infd = NULL;
148 152 int count = 0, firstline = 1;
149 153 uint32_t *intbuf = (uint32_t *)(intptr_t)buf;
150 154
151 155 if (infile == NULL || buf == NULL || size == 0)
152 156 return (0);
153 157
154 158 if ((infd = fopen(infile, "r")) == NULL)
155 159 return (0);
156 160
157 161 while (fgets(linebuf, LINESIZE, infd)) {
158 162
159 163 /* Check to see if we are processing a binary file */
160 164 if (firstline && !isprint(linebuf[0])) {
161 165 if (fseek(infd, 0, SEEK_SET) == 0)
162 166 count = fread(buf, 1, size, infd);
163 167
164 168 (void) fclose(infd);
165 169 return (count);
166 170 }
167 171
168 172 firstline = 0;
169 173
170 174 /* Skip blank lines */
171 175 if (strlen(linebuf) == 1)
172 176 continue;
173 177
174 178 /* Skip lines with all spaces or tabs */
175 179 if (strcspn(linebuf, " \t") == 0)
176 180 continue;
177 181
178 182 /* Text file. Skip comments. */
179 183 if (linebuf[0] == '/')
180 184 continue;
181 185
182 186 if (sscanf(linebuf, "%x, %x, %x, %x",
183 187 &intbuf[count], &intbuf[count+1],
184 188 &intbuf[count+2], &intbuf[count+3]) != 4)
185 189 break;
186 190
187 191 count += 4;
188 192 }
189 193
190 194 (void) fclose(infd);
191 195
192 196 /*
193 197 * If we get here, we are processing a text format file
194 198 * where "count" is used to count the number of integers
195 199 * read. Convert it to number of characters read.
196 200 */
197 201 return (count * sizeof (int));
198 202 }
199 203
200 204 /*
201 205 * Returns 0 if no need to update the link; -1 otherwise
202 206 */
203 207 static int
204 208 ucode_should_update_intel(char *filename, uint32_t new_rev)
205 209 {
206 210 int fd;
207 211 struct stat statbuf;
208 212 ucode_header_intel_t header;
209 213
210 214 /*
211 215 * If the file or link already exists, check to see if
212 216 * it is necessary to update it.
213 217 */
214 218 if (stat(filename, &statbuf) == 0) {
215 219 if ((fd = open(filename, O_RDONLY)) == -1)
216 220 return (-1);
217 221
218 222 if (read(fd, &header, sizeof (header)) == -1) {
219 223 (void) close(fd);
220 224 return (-1);
221 225 }
222 226
223 227 (void) close(fd);
224 228
225 229 if (header.uh_rev >= new_rev)
226 230 return (0);
227 231 }
228 232
229 233 return (-1);
230 234 }
231 235
232 236 /*
233 237 * Generate microcode binary files. Must be called after ucode_validate().
234 238 */
235 239 static ucode_errno_t
236 240 ucode_gen_files_amd(uint8_t *buf, int size, char *path)
237 241 {
238 242 /* LINTED: pointer alignment */
239 243 uint32_t *ptr = (uint32_t *)buf;
240 244 char common_path[PATH_MAX];
241 245 int fd, count, counter;
242 246 ucode_header_amd_t *uh;
243 247 int last_cpu_rev = 0;
244 248
245 249
246 250 /* write container file */
247 251 (void) snprintf(common_path, PATH_MAX, "%s/%s", path, "container");
248 252
249 253 dprintf("path = %s\n", common_path);
250 254 fd = open(common_path, O_WRONLY | O_CREAT | O_TRUNC,
251 255 S_IRUSR | S_IRGRP | S_IROTH);
252 256
253 257 if (fd == -1) {
254 258 ucode_perror(common_path, EM_SYS);
255 259 return (EM_SYS);
256 260 }
257 261
258 262 if (write(fd, buf, size) != size) {
259 263 (void) close(fd);
260 264 ucode_perror(common_path, EM_SYS);
261 265 return (EM_SYS);
262 266 }
263 267
264 268 (void) close(fd);
265 269
266 270 /* skip over magic number & equivalence table header */
267 271 ptr += 2; size -= 8;
268 272
269 273 count = *ptr++; size -= 4;
270 274
271 275 /* equivalence table uses special name */
272 276 (void) snprintf(common_path, PATH_MAX, "%s/%s", path,
273 277 "equivalence-table");
274 278
275 279 for (;;) {
276 280 dprintf("path = %s\n", common_path);
277 281 fd = open(common_path, O_WRONLY | O_CREAT | O_TRUNC,
278 282 S_IRUSR | S_IRGRP | S_IROTH);
279 283
280 284 if (fd == -1) {
281 285 ucode_perror(common_path, EM_SYS);
282 286 return (EM_SYS);
283 287 }
284 288
285 289 if (write(fd, ptr, count) != count) {
286 290 (void) close(fd);
287 291 ucode_perror(common_path, EM_SYS);
288 292 return (EM_SYS);
289 293 }
290 294
291 295 (void) close(fd);
292 296 ptr += count >> 2; size -= count;
293 297
294 298 if (!size)
295 299 return (EM_OK);
296 300
297 301 ptr++; size -= 4;
298 302 count = *ptr++; size -= 4;
299 303
300 304 /* construct name from header information */
301 305 uh = (ucode_header_amd_t *)ptr;
302 306
303 307 if (uh->uh_cpu_rev != last_cpu_rev) {
304 308 last_cpu_rev = uh->uh_cpu_rev;
305 309 counter = 0;
306 310 }
307 311
308 312 (void) snprintf(common_path, PATH_MAX, "%s/%04X-%02X", path,
309 313 uh->uh_cpu_rev, counter++);
310 314 }
311 315 }
312 316
313 317 static ucode_errno_t
314 318 ucode_gen_files_intel(uint8_t *buf, int size, char *path)
315 319 {
316 320 int remaining;
317 321 char common_path[PATH_MAX];
318 322 DIR *dirp;
319 323 struct dirent *dp;
320 324
321 325 (void) snprintf(common_path, PATH_MAX, "%s/%s", path,
322 326 UCODE_INSTALL_COMMON_PATH);
323 327
324 328 if (mkdirp(common_path, 0755) == -1 && errno != EEXIST) {
325 329 ucode_perror(common_path, EM_SYS);
326 330 return (EM_SYS);
327 331 }
328 332
329 333 for (remaining = size; remaining > 0; ) {
330 334 uint32_t total_size, body_size, offset;
331 335 char firstname[PATH_MAX];
332 336 char name[PATH_MAX];
333 337 int i;
334 338 uint8_t *curbuf = &buf[size - remaining];
335 339 ucode_header_intel_t *uhp;
336 340 ucode_ext_table_intel_t *extp;
337 341
338 342 uhp = (ucode_header_intel_t *)(intptr_t)curbuf;
339 343
340 344 total_size = UCODE_TOTAL_SIZE_INTEL(uhp->uh_total_size);
341 345 body_size = UCODE_BODY_SIZE_INTEL(uhp->uh_body_size);
342 346
343 347 remaining -= total_size;
344 348
345 349 (void) snprintf(firstname, PATH_MAX, "%s/%08X-%02X",
346 350 common_path, uhp->uh_signature, uhp->uh_proc_flags);
347 351 dprintf("firstname = %s\n", firstname);
348 352
349 353 if (ucode_should_update_intel(firstname, uhp->uh_rev) != 0) {
350 354 int fd;
351 355
352 356 /* Remove the existing one first */
353 357 (void) unlink(firstname);
354 358
355 359 if ((fd = open(firstname, O_WRONLY | O_CREAT | O_TRUNC,
356 360 S_IRUSR | S_IRGRP | S_IROTH)) == -1) {
357 361 ucode_perror(firstname, EM_SYS);
358 362 return (EM_SYS);
359 363 }
360 364
361 365 if (write(fd, curbuf, total_size) != total_size) {
362 366 (void) close(fd);
363 367 ucode_perror(firstname, EM_SYS);
364 368 return (EM_SYS);
365 369 }
366 370
367 371 (void) close(fd);
368 372 }
369 373
370 374 /*
371 375 * Only 1 byte of the proc_flags field is used, therefore
372 376 * we only need to match 8 potential platform ids.
373 377 */
374 378 for (i = 0; i < 8; i++) {
375 379 uint32_t platid = uhp->uh_proc_flags & (1 << i);
376 380
377 381 if (platid == 0 && uhp->uh_proc_flags != 0)
378 382 continue;
379 383
380 384 (void) snprintf(name, PATH_MAX,
381 385 "%s/%08X-%02X", path, uhp->uh_signature, platid);
382 386
383 387 dprintf("proc_flags = %x, platid = %x, name = %s\n",
384 388 uhp->uh_proc_flags, platid, name);
385 389
386 390 if (ucode_should_update_intel(name, uhp->uh_rev) != 0) {
387 391
388 392 /* Remove the existing one first */
389 393 (void) unlink(name);
390 394
391 395 if (link(firstname, name) == -1) {
392 396 ucode_perror(name, EM_SYS);
393 397 return (EM_SYS);
394 398 }
395 399 }
396 400
397 401 if (uhp->uh_proc_flags == 0)
398 402 break;
399 403 }
400 404
401 405 offset = UCODE_HEADER_SIZE_INTEL + body_size;
402 406
403 407 /* Check to see if there is extended signature table */
404 408 if (total_size == offset)
405 409 continue;
406 410
407 411 /* There is extended signature table. More processing. */
408 412 extp = (ucode_ext_table_intel_t *)(uintptr_t)&curbuf[offset];
409 413
410 414 for (i = 0; i < extp->uet_count; i++) {
411 415 ucode_ext_sig_intel_t *uesp = &extp->uet_ext_sig[i];
412 416 int j;
413 417
414 418 for (j = 0; j < 8; j++) {
415 419 uint32_t id = uesp->ues_proc_flags & (1 << j);
416 420
417 421 if (id == 0 && uesp->ues_proc_flags)
418 422 continue;
419 423
420 424 (void) snprintf(name, PATH_MAX,
421 425 "%s/%08X-%02X", path, extp->uet_ext_sig[i],
422 426 id);
423 427
424 428 if (ucode_should_update_intel(name, uhp->uh_rev)
425 429 != 0) {
426 430
427 431 /* Remove the existing one first */
428 432 (void) unlink(name);
429 433 if (link(firstname, name) == -1) {
430 434 ucode_perror(name, EM_SYS);
431 435 return (EM_SYS);
432 436 }
433 437 }
434 438
435 439 if (uesp->ues_proc_flags == 0)
436 440 break;
437 441 }
438 442 }
439 443
440 444 }
441 445
442 446 /*
443 447 * Remove files with no links to them. These are probably
444 448 * obsolete microcode files.
445 449 */
446 450 if ((dirp = opendir(common_path)) == NULL) {
447 451 ucode_perror(common_path, EM_SYS);
448 452 return (EM_SYS);
449 453 }
450 454
451 455 while ((dp = readdir(dirp)) != NULL) {
452 456 char filename[PATH_MAX];
453 457 struct stat statbuf;
454 458
455 459 (void) snprintf(filename, PATH_MAX,
456 460 "%s/%s", common_path, dp->d_name);
457 461 if (stat(filename, &statbuf) == -1)
458 462 continue;
459 463
460 464 if ((statbuf.st_mode & S_IFMT) == S_IFREG) {
461 465 if (statbuf.st_nlink == 1)
462 466 (void) unlink(filename);
463 467 }
464 468 }
465 469
466 470 (void) closedir(dirp);
467 471
468 472 return (EM_OK);
469 473 }
470 474
471 475 /*
472 476 * Returns 0 on success, 2 on usage error, and 3 on operation error.
473 477 */
474 478 int
475 479 main(int argc, char *argv[])
476 480 {
477 481 int c;
478 482 int action = 0;
479 483 int actcount = 0;
480 484 char *path = NULL;
481 485 char *filename = NULL;
482 486 int errflg = 0;
483 487 int dev_fd = -1;
484 488 int fd = -1;
485 489 int verbose = 0;
486 490 uint8_t *buf = NULL;
487 491 ucode_errno_t rc = EM_OK;
488 492 processorid_t cpuid_max;
489 493 struct stat filestat;
490 494 uint32_t ucode_size;
491 495
492 496 (void) setlocale(LC_ALL, "");
493 497
494 498 #if !defined(TEXT_DOMAIN)
495 499 #define TEXT_DOMAIN "SYS_TEST"
496 500 #endif
497 501 (void) textdomain(TEXT_DOMAIN);
498 502
499 503 cmdname = basename(argv[0]);
500 504
501 505 while ((c = getopt(argc, argv, "idhuvVR:")) != EOF) {
502 506 switch (c) {
503 507
504 508 case 'i':
505 509 action |= UCODE_OPT_INSTALL;
506 510 actcount++;
507 511 break;
508 512
509 513 case 'u':
510 514 action |= UCODE_OPT_UPDATE;
511 515 actcount++;
512 516 break;
513 517
514 518 case 'v':
515 519 action |= UCODE_OPT_VERSION;
516 520 actcount++;
517 521 break;
518 522
519 523 case 'd':
520 524 ucode_debug = 1;
521 525 break;
522 526
523 527 case 'R':
524 528 if (optarg[0] == '-')
525 529 errflg++;
526 530 else if (strlen(optarg) > UCODE_MAX_PATH_LEN) {
527 531 (void) fprintf(stderr,
528 532 gettext("Alternate path too long\n"));
529 533 errflg++;
530 534 } else if ((path = strdup(optarg)) == NULL) {
531 535 errflg++;
532 536 }
533 537
534 538 break;
535 539
536 540 case 'V':
537 541 verbose = 1;
538 542 break;
539 543
540 544 case 'h':
541 545 usage(1);
542 546 return (0);
543 547
544 548 default:
545 549 usage(verbose);
546 550 return (2);
547 551 }
548 552 }
549 553
550 554 if (actcount != 1) {
551 555 (void) fprintf(stderr, gettext("%s: options -v, -i and -u "
552 556 "are mutually exclusive.\n"), cmdname);
553 557 usage(verbose);
554 558 return (2);
555 559 }
556 560
557 561 if (optind <= argc - 1)
558 562 filename = argv[optind];
559 563 else if (!(action & UCODE_OPT_VERSION))
560 564 errflg++;
561 565
562 566 if (errflg || action == 0) {
563 567 usage(verbose);
564 568 return (2);
565 569 }
566 570
567 571 /*
568 572 * Convert from text format to binary format
569 573 */
570 574 if ((action & UCODE_OPT_INSTALL) || (action & UCODE_OPT_UPDATE)) {
571 575 int i;
572 576 UCODE_VENDORS;
573 577
574 578 for (i = 0; ucode_vendors[i].filestr != NULL; i++) {
575 579 dprintf("i = %d, filestr = %s, filename = %s\n",
576 580 i, ucode_vendors[i].filestr, filename);
577 581 if (strncasecmp(ucode_vendors[i].filestr,
578 582 basename(filename),
579 583 strlen(ucode_vendors[i].filestr)) == 0) {
580 584 ucode = &ucode_ops[i];
581 585 (void) strncpy(ucode_vendor_str,
582 586 ucode_vendors[i].vendorstr,
583 587 sizeof (ucode_vendor_str));
584 588 break;
585 589 }
586 590 }
587 591
588 592 if (ucode_vendors[i].filestr == NULL) {
589 593 rc = EM_NOVENDOR;
590 594 ucode_perror(basename(filename), rc);
591 595 goto err_out;
592 596 }
593 597
594 598 if ((stat(filename, &filestat)) < 0) {
595 599 rc = EM_SYS;
596 600 ucode_perror(filename, rc);
597 601 goto err_out;
598 602 }
599 603
600 604 if ((filestat.st_mode & S_IFMT) != S_IFREG &&
601 605 (filestat.st_mode & S_IFMT) != S_IFLNK) {
602 606 rc = EM_FILEFORMAT;
603 607 ucode_perror(filename, rc);
604 608 goto err_out;
605 609 }
606 610
607 611 if ((buf = malloc(filestat.st_size)) == NULL) {
608 612 rc = EM_SYS;
609 613 ucode_perror(filename, rc);
610 614 goto err_out;
611 615 }
612 616
613 617 ucode_size = ucode->convert(filename, buf, filestat.st_size);
614 618
615 619 dprintf("ucode_size = %d\n", ucode_size);
616 620
617 621 if (ucode_size == 0) {
618 622 rc = EM_FILEFORMAT;
619 623 ucode_perror(filename, rc);
620 624 goto err_out;
621 625 }
622 626
623 627 if ((rc = ucode->validate(buf, ucode_size)) != EM_OK) {
624 628 ucode_perror(filename, rc);
625 629 goto err_out;
626 630 }
627 631 }
628 632
629 633 /*
630 634 * For the install option, the microcode file must start with
631 635 * "intel" for Intel microcode, and "amd" for AMD microcode.
632 636 */
633 637 if (action & UCODE_OPT_INSTALL) {
634 638 /*
635 639 * If no path is provided by the -R option, put the files in
636 640 * /ucode_install_path/ucode_vendor_str/.
637 641 */
638 642 if (path == NULL) {
639 643 if ((path = malloc(PATH_MAX)) == NULL) {
640 644 rc = EM_SYS;
641 645 ucode_perror("malloc", rc);
642 646 goto err_out;
643 647 }
644 648
645 649 (void) snprintf(path, PATH_MAX, "/%s/%s",
646 650 ucode_install_path, ucode_vendor_str);
647 651 }
648 652
649 653 if (mkdirp(path, 0755) == -1 && errno != EEXIST) {
650 654 rc = EM_SYS;
651 655 ucode_perror(path, rc);
652 656 goto err_out;
653 657 }
654 658
655 659 rc = ucode->gen_files(buf, ucode_size, path);
656 660
657 661 goto err_out;
658 662 }
659 663
660 664 if ((dev_fd = open(ucode_dev, O_RDONLY)) == -1) {
↓ open down ↓ |
625 lines elided |
↑ open up ↑ |
661 665 rc = EM_SYS;
662 666 ucode_perror(ucode_dev, rc);
663 667 goto err_out;
664 668 }
665 669
666 670 if (action & UCODE_OPT_VERSION) {
667 671 int tmprc;
668 672 uint32_t *revp = NULL;
669 673 int i;
670 674 #if defined(_SYSCALL32_IMPL)
671 - struct ucode_get_rev_struct32 inf32;
675 + struct ucode_get_rev_struct32 inf32;
672 676 #else
673 - struct ucode_get_rev_struct info;
677 + struct ucode_get_rev_struct info;
674 678 #endif
675 679
676 680 cpuid_max = (processorid_t)sysconf(_SC_CPUID_MAX);
677 681
678 682 if ((revp = (uint32_t *)
679 683 malloc(cpuid_max * sizeof (uint32_t))) == NULL) {
680 684 rc = EM_SYS;
681 685 ucode_perror("malloc", rc);
682 686 goto err_out;
683 687 }
684 688
685 689 for (i = 0; i < cpuid_max; i++)
686 690 revp[i] = (uint32_t)-1;
687 691
688 692 #if defined(_SYSCALL32_IMPL)
689 693 info32.ugv_rev = (caddr32_t)revp;
690 694 info32.ugv_size = cpuid_max;
691 695 info32.ugv_errno = EM_OK;
692 696 tmprc = ioctl(dev_fd, UCODE_GET_VERSION, &info32);
693 697 rc = info32.ugv_errno;
694 698 #else
695 699 info.ugv_rev = revp;
696 700 info.ugv_size = cpuid_max;
697 701 info.ugv_errno = EM_OK;
698 702 tmprc = ioctl(dev_fd, UCODE_GET_VERSION, &info);
699 703 rc = info.ugv_errno;
700 704 #endif
701 705
702 706 if (tmprc && rc == EM_OK) {
703 707 rc = EM_SYS;
704 708 }
705 709
706 710 if (rc == EM_OK) {
707 711 (void) printf(gettext("CPU\tMicrocode Version\n"));
708 712 for (i = 0; i < cpuid_max; i++) {
709 713 if (info.ugv_rev[i] == (uint32_t)-1)
710 714 continue;
711 715 (void) printf("%d\t0x%x\n", i, info.ugv_rev[i]);
712 716 }
713 717 } else {
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
714 718 ucode_perror(gettext("get microcode version"), rc);
715 719 }
716 720
717 721 if (revp)
718 722 free(revp);
719 723 }
720 724
721 725 if (action & UCODE_OPT_UPDATE) {
722 726 int tmprc;
723 727 #if defined(_SYSCALL32_IMPL)
724 - struct ucode_write_struct32 uw_struct32;
728 + struct ucode_write_struct32 uw_struct32;
725 729 #else
726 - struct ucode_write_struct uw_struct;
730 + struct ucode_write_struct uw_struct;
727 731 #endif
728 732
729 733 #if defined(_SYSCALL32_IMPL)
730 734 uw_struct32.uw_size = ucode_size;
731 735 uw_struct32.uw_ucode = (caddr32_t)buf;
732 736 uw_struct32.uw_errno = EM_OK;
733 737 tmprc = ioctl(dev_fd, UCODE_UPDATE, &uw_struct32);
734 738 rc = uw_struct32.uw_errno;
735 739
736 740 #else
737 741 uw_struct.uw_size = ucode_size;
738 742 uw_struct.uw_ucode = buf;
739 743 uw_struct.uw_errno = EM_OK;
740 744 tmprc = ioctl(dev_fd, UCODE_UPDATE, &uw_struct);
741 745 rc = uw_struct.uw_errno;
742 746 #endif
743 747
744 748 if (rc == EM_OK) {
745 749 if (tmprc) {
746 750 rc = EM_SYS;
747 751 ucode_perror(ucode_dev, rc);
748 752 }
749 753 } else if (rc == EM_NOMATCH || rc == EM_HIGHERREV) {
750 754 ucode_perror(filename, rc);
751 755 } else {
752 756 ucode_perror(gettext("microcode update"), rc);
753 757 }
754 758 }
755 759
756 760 err_out:
757 761 if (dev_fd != -1)
758 762 (void) close(dev_fd);
759 763
760 764 if (fd != -1)
761 765 (void) close(fd);
762 766
763 767 free(buf);
764 768 free(path);
765 769
766 770 if (rc != EM_OK)
767 771 return (3);
768 772
769 773 return (0);
770 774 }
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX