From c3397311a658ceea5cb5c4e632861616edda5a7d Mon Sep 17 00:00:00 2001 From: Boris Ostrovsky Date: Wed, 28 Sep 2016 09:21:48 -0400 Subject: [PATCH] acpi: Prevent GPL-only code from seeping into non-GPL binaries Some code (specifically, introduced by commit 801d469ad ("[HVM] ACPI support patch 3 of 4: ACPI _PRT table.")) has only been licensed under GPLv2. We want to prevent this code from showing up in non-GPL binaries which might become possible after we make ACPI builder code available to users other than hvmloader. There are two pieces that we need to be careful about: (1) A small chunk of code in dsdt.asl that implements _PIC method (2) A chunk of ASL generator in mk_dsdt.c that describes with PCI interrupt routing. This code will now be generated by a GPL-only script which will be invoked only when ACPI builder's Makefile is called with GPL variable set. We also strip license header from generated ASL files to prevent inadverent use of those files with incorrect license. Signed-off-by: Boris Ostrovsky Reviewed-by: Wei Liu Reviewed-by: Jan Beulich --- tools/firmware/hvmloader/Makefile | 3 + tools/firmware/hvmloader/acpi/Makefile | 14 ++- tools/firmware/hvmloader/acpi/dsdt.asl | 14 --- .../hvmloader/acpi/gpl/mk_dsdt_gpl.sh | 117 ++++++++++++++++++ tools/firmware/hvmloader/acpi/mk_dsdt.c | 68 +--------- 5 files changed, 132 insertions(+), 84 deletions(-) create mode 100755 tools/firmware/hvmloader/acpi/gpl/mk_dsdt_gpl.sh diff --git a/tools/firmware/hvmloader/Makefile b/tools/firmware/hvmloader/Makefile index 9f7357f2b9..a1844d0c7e 100644 --- a/tools/firmware/hvmloader/Makefile +++ b/tools/firmware/hvmloader/Makefile @@ -65,6 +65,9 @@ ROMBIOS_ROM := $(ROMBIOS_DIR)/BIOS-bochs-latest ROMS += $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) $(ETHERBOOT_ROMS) endif +# Certain parts of ACPI builder are GPL-only +export GPL := y + .PHONY: all all: subdirs-all $(MAKE) hvmloader diff --git a/tools/firmware/hvmloader/acpi/Makefile b/tools/firmware/hvmloader/acpi/Makefile index f63e734622..c23626da67 100644 --- a/tools/firmware/hvmloader/acpi/Makefile +++ b/tools/firmware/hvmloader/acpi/Makefile @@ -17,7 +17,8 @@ XEN_ROOT = $(CURDIR)/../../../.. include $(XEN_ROOT)/tools/firmware/Rules.mk -C_SRC = build.c dsdt_anycpu.c dsdt_15cpu.c static_tables.c dsdt_anycpu_qemu_xen.c +C_SRC-$(GPL) = build.c dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c +C_SRC = build.c static_tables.c $(C_SRC-y) OBJS = $(patsubst %.c,%.o,$(C_SRC)) CFLAGS += $(CFLAGS_xeninclude) @@ -36,18 +37,25 @@ ssdt_s3.h ssdt_s4.h ssdt_pm.h ssdt_tpm.h: %.h: %.asl iasl mk_dsdt: mk_dsdt.c $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -o $@ mk_dsdt.c -dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl mk_dsdt +ifeq ($(GPL),y) +dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl gpl/mk_dsdt_gpl.sh mk_dsdt awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) + # Strip license comment + sed -i '1,/\*\//{/\/\*/,/\*\//d}' $@.$(TMP_SUFFIX) + $(SHELL) gpl/mk_dsdt_gpl.sh >> $@.$(TMP_SUFFIX) cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) ./mk_dsdt --debug=$(debug) --dm-version qemu-xen >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@ # NB. awk invocation is a portable alternative to 'head -n -1' -dsdt_%cpu.asl: dsdt.asl dsdt_acpi_info.asl mk_dsdt +dsdt_%cpu.asl: dsdt.asl dsdt_acpi_info.asl gpl/mk_dsdt_gpl.sh mk_dsdt awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) + sed -i '1,/\*\//{/\/\*/,/\*\//d}' $@.$(TMP_SUFFIX) + $(SHELL) gpl/mk_dsdt_gpl.sh >> $@.$(TMP_SUFFIX) cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) ./mk_dsdt --debug=$(debug) --maxcpu $* >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@ +endif $(filter dsdt_%.c,$(C_SRC)): %.c: iasl %.asl iasl -vs -p $* -tc $*.asl diff --git a/tools/firmware/hvmloader/acpi/dsdt.asl b/tools/firmware/hvmloader/acpi/dsdt.asl index 4f6db79395..13811cff60 100644 --- a/tools/firmware/hvmloader/acpi/dsdt.asl +++ b/tools/firmware/hvmloader/acpi/dsdt.asl @@ -26,20 +26,6 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Name (\APCL, 0x00010000) Name (\PUID, 0x00) - /* _S3 and _S4 are in separate SSDTs */ - Name (\_S5, Package (0x04) - { - 0x00, /* PM1a_CNT.SLP_TYP */ - 0x00, /* PM1b_CNT.SLP_TYP */ - 0x00, /* reserved */ - 0x00 /* reserved */ - }) - - Name(PICD, 0) - Method(_PIC, 1) - { - Store(Arg0, PICD) - } Scope (\_SB) { diff --git a/tools/firmware/hvmloader/acpi/gpl/mk_dsdt_gpl.sh b/tools/firmware/hvmloader/acpi/gpl/mk_dsdt_gpl.sh new file mode 100755 index 0000000000..38fe01abd8 --- /dev/null +++ b/tools/firmware/hvmloader/acpi/gpl/mk_dsdt_gpl.sh @@ -0,0 +1,117 @@ +#!/bin/sh + +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; If not, see . +# + +cat <<'EndOfASL' + /* Beginning of GPL-only code */ + + /* _S3 and _S4 are in separate SSDTs */ + Name (\_S5, Package (0x04) { + 0x00, /* PM1a_CNT.SLP_TYP */ + 0x00, /* PM1b_CNT.SLP_TYP */ + 0x00, /* reserved */ + 0x00 /* reserved */ + }) + Name(PICD, 0) + Method(_PIC, 1) { + Store(Arg0, PICD) + } +EndOfASL + +# PCI-ISA link definitions +# BUFA: List of ISA IRQs available for linking to PCI INTx. +# BUFB: IRQ descriptor for returning from link-device _CRS methods. +cat <<'EndOfASL' + Scope ( \_SB.PCI0 ) { + Name ( BUFA, ResourceTemplate() { IRQ(Level, ActiveLow, Shared) { 5, 10, 11 } } ) + Name ( BUFB, Buffer() { 0x23, 0x00, 0x00, 0x18, 0x79, 0 } ) + CreateWordField ( BUFB, 0x01, IRQV ) +EndOfASL + +for i in $(seq 1 4) +do + link=`echo "A B C D" | cut -d" " -f $i` + cat <