acpi.c (330449) | acpi.c (336161) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2012 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2012 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * |
28 * $FreeBSD: stable/11/usr.sbin/bhyve/acpi.c 330449 2018-03-05 07:26:05Z eadler $ | 28 * $FreeBSD: stable/11/usr.sbin/bhyve/acpi.c 336161 2018-07-10 04:26:32Z araujo $ |
29 */ 30 31/* 32 * bhyve ACPI table generator. 33 * 34 * Create the minimal set of ACPI tables required to boot FreeBSD (and 35 * hopefully other o/s's) by writing out ASL template files for each of 36 * the tables and the compiling them to AML with the Intel iasl compiler. --- 11 unchanged lines hidden (view full) --- 48 * FADT -> 0xf2600 (268 bytes) 49 * HPET -> 0xf2740 (56 bytes) 50 * MCFG -> 0xf2780 (60 bytes) 51 * FACS -> 0xf27C0 (64 bytes) 52 * DSDT -> 0xf2800 (variable - can go up to 0x100000) 53 */ 54 55#include <sys/cdefs.h> | 29 */ 30 31/* 32 * bhyve ACPI table generator. 33 * 34 * Create the minimal set of ACPI tables required to boot FreeBSD (and 35 * hopefully other o/s's) by writing out ASL template files for each of 36 * the tables and the compiling them to AML with the Intel iasl compiler. --- 11 unchanged lines hidden (view full) --- 48 * FADT -> 0xf2600 (268 bytes) 49 * HPET -> 0xf2740 (56 bytes) 50 * MCFG -> 0xf2780 (60 bytes) 51 * FACS -> 0xf27C0 (64 bytes) 52 * DSDT -> 0xf2800 (variable - can go up to 0x100000) 53 */ 54 55#include <sys/cdefs.h> |
56__FBSDID("$FreeBSD: stable/11/usr.sbin/bhyve/acpi.c 330449 2018-03-05 07:26:05Z eadler $"); | 56__FBSDID("$FreeBSD: stable/11/usr.sbin/bhyve/acpi.c 336161 2018-07-10 04:26:32Z araujo $"); |
57 58#include <sys/param.h> 59#include <sys/errno.h> 60#include <sys/stat.h> 61 62#include <paths.h> 63#include <stdarg.h> 64#include <stdio.h> --- 48 unchanged lines hidden (view full) --- 113 114struct basl_fio { 115 int fd; 116 FILE *fp; 117 char f_name[MAXPATHLEN]; 118}; 119 120#define EFPRINTF(...) \ | 57 58#include <sys/param.h> 59#include <sys/errno.h> 60#include <sys/stat.h> 61 62#include <paths.h> 63#include <stdarg.h> 64#include <stdio.h> --- 48 unchanged lines hidden (view full) --- 113 114struct basl_fio { 115 int fd; 116 FILE *fp; 117 char f_name[MAXPATHLEN]; 118}; 119 120#define EFPRINTF(...) \ |
121 err = fprintf(__VA_ARGS__); if (err < 0) goto err_exit; | 121 if (fprintf(__VA_ARGS__) < 0) goto err_exit; |
122 123#define EFFLUSH(x) \ | 122 123#define EFFLUSH(x) \ |
124 err = fflush(x); if (err != 0) goto err_exit; | 124 if (fflush(x) != 0) goto err_exit; |
125 126static int 127basl_fwrite_rsdp(FILE *fp) 128{ | 125 126static int 127basl_fwrite_rsdp(FILE *fp) 128{ |
129 int err; 130 131 err = 0; 132 | |
133 EFPRINTF(fp, "/*\n"); 134 EFPRINTF(fp, " * bhyve RSDP template\n"); 135 EFPRINTF(fp, " */\n"); 136 EFPRINTF(fp, "[0008]\t\tSignature : \"RSD PTR \"\n"); 137 EFPRINTF(fp, "[0001]\t\tChecksum : 43\n"); 138 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); 139 EFPRINTF(fp, "[0001]\t\tRevision : 02\n"); 140 EFPRINTF(fp, "[0004]\t\tRSDT Address : %08X\n", --- 10 unchanged lines hidden (view full) --- 151 152err_exit: 153 return (errno); 154} 155 156static int 157basl_fwrite_rsdt(FILE *fp) 158{ | 129 EFPRINTF(fp, "/*\n"); 130 EFPRINTF(fp, " * bhyve RSDP template\n"); 131 EFPRINTF(fp, " */\n"); 132 EFPRINTF(fp, "[0008]\t\tSignature : \"RSD PTR \"\n"); 133 EFPRINTF(fp, "[0001]\t\tChecksum : 43\n"); 134 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); 135 EFPRINTF(fp, "[0001]\t\tRevision : 02\n"); 136 EFPRINTF(fp, "[0004]\t\tRSDT Address : %08X\n", --- 10 unchanged lines hidden (view full) --- 147 148err_exit: 149 return (errno); 150} 151 152static int 153basl_fwrite_rsdt(FILE *fp) 154{ |
159 int err; 160 161 err = 0; 162 | |
163 EFPRINTF(fp, "/*\n"); 164 EFPRINTF(fp, " * bhyve RSDT template\n"); 165 EFPRINTF(fp, " */\n"); 166 EFPRINTF(fp, "[0004]\t\tSignature : \"RSDT\"\n"); 167 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 168 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 169 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 170 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 20 unchanged lines hidden (view full) --- 191 192err_exit: 193 return (errno); 194} 195 196static int 197basl_fwrite_xsdt(FILE *fp) 198{ | 155 EFPRINTF(fp, "/*\n"); 156 EFPRINTF(fp, " * bhyve RSDT template\n"); 157 EFPRINTF(fp, " */\n"); 158 EFPRINTF(fp, "[0004]\t\tSignature : \"RSDT\"\n"); 159 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 160 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 161 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 162 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 20 unchanged lines hidden (view full) --- 183 184err_exit: 185 return (errno); 186} 187 188static int 189basl_fwrite_xsdt(FILE *fp) 190{ |
199 int err; 200 201 err = 0; 202 | |
203 EFPRINTF(fp, "/*\n"); 204 EFPRINTF(fp, " * bhyve XSDT template\n"); 205 EFPRINTF(fp, " */\n"); 206 EFPRINTF(fp, "[0004]\t\tSignature : \"XSDT\"\n"); 207 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 208 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 209 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 210 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 20 unchanged lines hidden (view full) --- 231 232err_exit: 233 return (errno); 234} 235 236static int 237basl_fwrite_madt(FILE *fp) 238{ | 191 EFPRINTF(fp, "/*\n"); 192 EFPRINTF(fp, " * bhyve XSDT template\n"); 193 EFPRINTF(fp, " */\n"); 194 EFPRINTF(fp, "[0004]\t\tSignature : \"XSDT\"\n"); 195 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 196 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 197 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 198 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 20 unchanged lines hidden (view full) --- 219 220err_exit: 221 return (errno); 222} 223 224static int 225basl_fwrite_madt(FILE *fp) 226{ |
239 int err; | |
240 int i; 241 | 227 int i; 228 |
242 err = 0; 243 | |
244 EFPRINTF(fp, "/*\n"); 245 EFPRINTF(fp, " * bhyve MADT template\n"); 246 EFPRINTF(fp, " */\n"); 247 EFPRINTF(fp, "[0004]\t\tSignature : \"APIC\"\n"); 248 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 249 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 250 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 251 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 69 unchanged lines hidden (view full) --- 321 322err_exit: 323 return (errno); 324} 325 326static int 327basl_fwrite_fadt(FILE *fp) 328{ | 229 EFPRINTF(fp, "/*\n"); 230 EFPRINTF(fp, " * bhyve MADT template\n"); 231 EFPRINTF(fp, " */\n"); 232 EFPRINTF(fp, "[0004]\t\tSignature : \"APIC\"\n"); 233 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 234 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 235 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 236 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 69 unchanged lines hidden (view full) --- 306 307err_exit: 308 return (errno); 309} 310 311static int 312basl_fwrite_fadt(FILE *fp) 313{ |
329 int err; 330 331 err = 0; 332 | |
333 EFPRINTF(fp, "/*\n"); 334 EFPRINTF(fp, " * bhyve FADT template\n"); 335 EFPRINTF(fp, " */\n"); 336 EFPRINTF(fp, "[0004]\t\tSignature : \"FACP\"\n"); 337 EFPRINTF(fp, "[0004]\t\tTable Length : 0000010C\n"); 338 EFPRINTF(fp, "[0001]\t\tRevision : 05\n"); 339 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 340 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 201 unchanged lines hidden (view full) --- 542 543err_exit: 544 return (errno); 545} 546 547static int 548basl_fwrite_hpet(FILE *fp) 549{ | 314 EFPRINTF(fp, "/*\n"); 315 EFPRINTF(fp, " * bhyve FADT template\n"); 316 EFPRINTF(fp, " */\n"); 317 EFPRINTF(fp, "[0004]\t\tSignature : \"FACP\"\n"); 318 EFPRINTF(fp, "[0004]\t\tTable Length : 0000010C\n"); 319 EFPRINTF(fp, "[0001]\t\tRevision : 05\n"); 320 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 321 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 201 unchanged lines hidden (view full) --- 523 524err_exit: 525 return (errno); 526} 527 528static int 529basl_fwrite_hpet(FILE *fp) 530{ |
550 int err; 551 552 err = 0; 553 | |
554 EFPRINTF(fp, "/*\n"); 555 EFPRINTF(fp, " * bhyve HPET template\n"); 556 EFPRINTF(fp, " */\n"); 557 EFPRINTF(fp, "[0004]\t\tSignature : \"HPET\"\n"); 558 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 559 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 560 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 561 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 29 unchanged lines hidden (view full) --- 591 592err_exit: 593 return (errno); 594} 595 596static int 597basl_fwrite_mcfg(FILE *fp) 598{ | 531 EFPRINTF(fp, "/*\n"); 532 EFPRINTF(fp, " * bhyve HPET template\n"); 533 EFPRINTF(fp, " */\n"); 534 EFPRINTF(fp, "[0004]\t\tSignature : \"HPET\"\n"); 535 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 536 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 537 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 538 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 29 unchanged lines hidden (view full) --- 568 569err_exit: 570 return (errno); 571} 572 573static int 574basl_fwrite_mcfg(FILE *fp) 575{ |
599 int err = 0; 600 | |
601 EFPRINTF(fp, "/*\n"); 602 EFPRINTF(fp, " * bhyve MCFG template\n"); 603 EFPRINTF(fp, " */\n"); 604 EFPRINTF(fp, "[0004]\t\tSignature : \"MCFG\"\n"); 605 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 606 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 607 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 608 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 15 unchanged lines hidden (view full) --- 624 return (0); 625err_exit: 626 return (errno); 627} 628 629static int 630basl_fwrite_facs(FILE *fp) 631{ | 576 EFPRINTF(fp, "/*\n"); 577 EFPRINTF(fp, " * bhyve MCFG template\n"); 578 EFPRINTF(fp, " */\n"); 579 EFPRINTF(fp, "[0004]\t\tSignature : \"MCFG\"\n"); 580 EFPRINTF(fp, "[0004]\t\tTable Length : 00000000\n"); 581 EFPRINTF(fp, "[0001]\t\tRevision : 01\n"); 582 EFPRINTF(fp, "[0001]\t\tChecksum : 00\n"); 583 EFPRINTF(fp, "[0006]\t\tOem ID : \"BHYVE \"\n"); --- 15 unchanged lines hidden (view full) --- 599 return (0); 600err_exit: 601 return (errno); 602} 603 604static int 605basl_fwrite_facs(FILE *fp) 606{ |
632 int err; 633 634 err = 0; 635 | |
636 EFPRINTF(fp, "/*\n"); 637 EFPRINTF(fp, " * bhyve FACS template\n"); 638 EFPRINTF(fp, " */\n"); 639 EFPRINTF(fp, "[0004]\t\tSignature : \"FACS\"\n"); 640 EFPRINTF(fp, "[0004]\t\tLength : 00000040\n"); 641 EFPRINTF(fp, "[0004]\t\tHardware Signature : 00000000\n"); 642 EFPRINTF(fp, "[0004]\t\t32 Firmware Waking Vector : 00000000\n"); 643 EFPRINTF(fp, "[0004]\t\tGlobal Lock : 00000000\n"); --- 17 unchanged lines hidden (view full) --- 661 662/* 663 * Helper routines for writing to the DSDT from other modules. 664 */ 665void 666dsdt_line(const char *fmt, ...) 667{ 668 va_list ap; | 607 EFPRINTF(fp, "/*\n"); 608 EFPRINTF(fp, " * bhyve FACS template\n"); 609 EFPRINTF(fp, " */\n"); 610 EFPRINTF(fp, "[0004]\t\tSignature : \"FACS\"\n"); 611 EFPRINTF(fp, "[0004]\t\tLength : 00000040\n"); 612 EFPRINTF(fp, "[0004]\t\tHardware Signature : 00000000\n"); 613 EFPRINTF(fp, "[0004]\t\t32 Firmware Waking Vector : 00000000\n"); 614 EFPRINTF(fp, "[0004]\t\tGlobal Lock : 00000000\n"); --- 17 unchanged lines hidden (view full) --- 632 633/* 634 * Helper routines for writing to the DSDT from other modules. 635 */ 636void 637dsdt_line(const char *fmt, ...) 638{ 639 va_list ap; |
669 int err; | |
670 671 if (dsdt_error != 0) 672 return; 673 674 if (strcmp(fmt, "") != 0) { 675 if (dsdt_indent_level != 0) 676 EFPRINTF(dsdt_fp, "%*c", dsdt_indent_level * 2, ' '); 677 va_start(ap, fmt); | 640 641 if (dsdt_error != 0) 642 return; 643 644 if (strcmp(fmt, "") != 0) { 645 if (dsdt_indent_level != 0) 646 EFPRINTF(dsdt_fp, "%*c", dsdt_indent_level * 2, ' '); 647 va_start(ap, fmt); |
678 if (vfprintf(dsdt_fp, fmt, ap) < 0) | 648 if (vfprintf(dsdt_fp, fmt, ap) < 0) { 649 va_end(ap); |
679 goto err_exit; | 650 goto err_exit; |
651 } |
|
680 va_end(ap); 681 } 682 EFPRINTF(dsdt_fp, "\n"); 683 return; 684 685err_exit: 686 dsdt_error = errno; 687} --- 42 unchanged lines hidden (view full) --- 730 dsdt_line(" 0x%08X, // Address Base", base); 731 dsdt_line(" 0x%08X, // Address Length", length); 732 dsdt_line(" )"); 733} 734 735static int 736basl_fwrite_dsdt(FILE *fp) 737{ | 652 va_end(ap); 653 } 654 EFPRINTF(dsdt_fp, "\n"); 655 return; 656 657err_exit: 658 dsdt_error = errno; 659} --- 42 unchanged lines hidden (view full) --- 702 dsdt_line(" 0x%08X, // Address Base", base); 703 dsdt_line(" 0x%08X, // Address Length", length); 704 dsdt_line(" )"); 705} 706 707static int 708basl_fwrite_dsdt(FILE *fp) 709{ |
738 int err; 739 740 err = 0; | |
741 dsdt_fp = fp; 742 dsdt_error = 0; 743 dsdt_indent_level = 0; 744 745 dsdt_line("/*"); 746 dsdt_line(" * bhyve DSDT template"); 747 dsdt_line(" */"); 748 dsdt_line("DefinitionBlock (\"bhyve_dsdt.aml\", \"DSDT\", 2," --- 162 unchanged lines hidden (view full) --- 911static int 912basl_make_templates(void) 913{ 914 const char *tmpdir; 915 int err; 916 int len; 917 918 err = 0; | 710 dsdt_fp = fp; 711 dsdt_error = 0; 712 dsdt_indent_level = 0; 713 714 dsdt_line("/*"); 715 dsdt_line(" * bhyve DSDT template"); 716 dsdt_line(" */"); 717 dsdt_line("DefinitionBlock (\"bhyve_dsdt.aml\", \"DSDT\", 2," --- 162 unchanged lines hidden (view full) --- 880static int 881basl_make_templates(void) 882{ 883 const char *tmpdir; 884 int err; 885 int len; 886 887 err = 0; |
919 | 888 |
920 /* 921 * 922 */ 923 if ((tmpdir = getenv("BHYVE_TMPDIR")) == NULL || *tmpdir == '\0' || 924 (tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') { 925 tmpdir = _PATH_TMP; 926 } 927 --- 87 unchanged lines hidden --- | 889 /* 890 * 891 */ 892 if ((tmpdir = getenv("BHYVE_TMPDIR")) == NULL || *tmpdir == '\0' || 893 (tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') { 894 tmpdir = _PATH_TMP; 895 } 896 --- 87 unchanged lines hidden --- |