From bd2be1500337f0349f70802e4d8d43f5aca61477 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 9 Apr 2013 15:26:55 +0100 Subject: arm: fix location of some include files The recent rearrangement of include files had some minor errors: devices.h is not ARM specific and should not be in arm/ arm.h should be in arm/ Move these two headers to correct this. Signed-off-by: Peter Maydell Signed-off-by: Paolo Bonzini --- hw/alpha/typhoon.c | 2 +- hw/arm/armv7m.c | 2 +- hw/arm/boot.c | 2 +- hw/arm/collie.c | 4 +- hw/arm/exynos4210.c | 2 +- hw/arm/exynos4_boards.c | 2 +- hw/arm/gumstix.c | 2 +- hw/arm/highbank.c | 4 +- hw/arm/integratorcp.c | 4 +- hw/arm/kzm.c | 4 +- hw/arm/mainstone.c | 4 +- hw/arm/musicpal.c | 4 +- hw/arm/nseries.c | 4 +- hw/arm/omap1.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/omap_sx1.c | 2 +- hw/arm/palm.c | 4 +- hw/arm/pic_cpu.c | 2 +- hw/arm/realview.c | 4 +- hw/arm/spitz.c | 4 +- hw/arm/stellaris.c | 4 +- hw/arm/strongarm.c | 2 +- hw/arm/tosa.c | 4 +- hw/arm/versatilepb.c | 4 +- hw/arm/vexpress.c | 4 +- hw/arm/xilinx_zynq.c | 2 +- hw/arm/z2.c | 4 +- hw/block/m25p80.c | 2 +- hw/display/blizzard.c | 2 +- hw/display/sm501.c | 2 +- hw/display/tc6393xb.c | 2 +- hw/input/stellaris_input.c | 2 +- hw/input/tsc2005.c | 2 +- hw/input/tsc210x.c | 2 +- hw/intc/armv7m_nvic.c | 2 +- hw/lm32/lm32_boards.c | 2 +- hw/lm32/milkymist.c | 2 +- hw/microblaze/petalogix_ml605_mmu.c | 2 +- hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +- hw/misc/cbus.c | 2 +- hw/net/lan9118.c | 2 +- hw/net/smc91c111.c | 2 +- hw/ppc/virtex_ml507.c | 2 +- hw/sh4/r2d.c | 2 +- hw/timer/tusb6010.c | 2 +- include/hw/arm.h | 70 -------------------------------- include/hw/arm/arm.h | 70 ++++++++++++++++++++++++++++++++ include/hw/arm/devices.h | 70 -------------------------------- include/hw/devices.h | 70 ++++++++++++++++++++++++++++++++ target-arm/arm-semi.c | 2 +- target-arm/kvm.c | 2 +- 51 files changed, 202 insertions(+), 202 deletions(-) delete mode 100644 include/hw/arm.h create mode 100644 include/hw/arm/arm.h delete mode 100644 include/hw/arm/devices.h create mode 100644 include/hw/devices.h diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c index faec8dcebd..68420f40cb 100644 --- a/hw/alpha/typhoon.c +++ b/hw/alpha/typhoon.c @@ -9,7 +9,7 @@ #include "cpu.h" #include "exec/exec-all.h" #include "hw/hw.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "sysemu/sysemu.h" #include "alpha_sys.h" #include "exec/address-spaces.h" diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index a4bdd5f30f..2ae3576760 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -8,7 +8,7 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/loader.h" #include "elf.h" diff --git a/hw/arm/boot.c b/hw/arm/boot.c index c79c590171..e9c09454ac 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -9,7 +9,7 @@ #include "config.h" #include "hw/hw.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/loader.h" diff --git a/hw/arm/collie.c b/hw/arm/collie.c index 5420bb4ba8..a19857aaaf 100644 --- a/hw/arm/collie.c +++ b/hw/arm/collie.c @@ -11,9 +11,9 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "hw/boards.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "strongarm.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/block/flash.h" #include "sysemu/blockdev.h" #include "exec/address-spaces.h" diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c index 78b8b7407a..c8101d3e84 100644 --- a/hw/arm/exynos4210.c +++ b/hw/arm/exynos4210.c @@ -24,7 +24,7 @@ #include "hw/boards.h" #include "sysemu/sysemu.h" #include "hw/sysbus.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/loader.h" #include "hw/arm/exynos4210.h" #include "hw/usb/hcd-ehci.h" diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c index ba14a1fd09..74f110ba61 100644 --- a/hw/arm/exynos4_boards.c +++ b/hw/arm/exynos4_boards.c @@ -24,7 +24,7 @@ #include "sysemu/sysemu.h" #include "hw/sysbus.h" #include "net/net.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "exec/address-spaces.h" #include "hw/arm/exynos4210.h" #include "hw/boards.h" diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c index 4d800c9547..b8cab10ba6 100644 --- a/hw/arm/gumstix.c +++ b/hw/arm/gumstix.c @@ -38,7 +38,7 @@ #include "hw/arm/pxa.h" #include "net/net.h" #include "hw/block/flash.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "sysemu/blockdev.h" #include "exec/address-spaces.h" diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index 58f73c1bd3..0fd9465cfa 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -18,8 +18,8 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "hw/loader.h" #include "net/net.h" #include "sysemu/sysemu.h" diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c index 8d0fb7584a..cca29719ec 100644 --- a/hw/arm/integratorcp.c +++ b/hw/arm/integratorcp.c @@ -8,9 +8,9 @@ */ #include "hw/sysbus.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "net/net.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c index 46264cdeac..cf90f5dc71 100644 --- a/hw/arm/kzm.c +++ b/hw/arm/kzm.c @@ -16,8 +16,8 @@ #include "hw/sysbus.h" #include "exec/address-spaces.h" #include "hw/hw.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/boards.h" diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c index b78e6f00d3..260e31481d 100644 --- a/hw/arm/mainstone.c +++ b/hw/arm/mainstone.c @@ -13,9 +13,9 @@ */ #include "hw/hw.h" #include "hw/arm/pxa.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "net/net.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "hw/block/flash.h" #include "sysemu/blockdev.h" diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index 97b13405e6..d2247fa1b9 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -10,8 +10,8 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/boards.h" diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c index ba8dc3e01a..4976438ae6 100644 --- a/hw/arm/nseries.c +++ b/hw/arm/nseries.c @@ -21,12 +21,12 @@ #include "qemu-common.h" #include "sysemu/sysemu.h" #include "hw/arm/omap.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/irq.h" #include "ui/console.h" #include "hw/boards.h" #include "hw/i2c/i2c.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/block/flash.h" #include "hw/hw.h" #include "hw/bt.h" diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 17caa61822..f59f0f291a 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -17,7 +17,7 @@ * with this program; if not, see . */ #include "hw/hw.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/arm/omap.h" #include "sysemu/sysemu.h" #include "hw/arm/soc_dma.h" diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index 010c483e8c..a4b414621d 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -20,7 +20,7 @@ #include "sysemu/blockdev.h" #include "hw/hw.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/arm/omap.h" #include "sysemu/sysemu.h" #include "qemu/timer.h" diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c index aa85602aa6..e421ece026 100644 --- a/hw/arm/omap_sx1.c +++ b/hw/arm/omap_sx1.c @@ -29,7 +29,7 @@ #include "ui/console.h" #include "hw/arm/omap.h" #include "hw/boards.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/block/flash.h" #include "sysemu/blockdev.h" #include "exec/address-spaces.h" diff --git a/hw/arm/palm.c b/hw/arm/palm.c index 0bc11aed2b..b13d8108a4 100644 --- a/hw/arm/palm.c +++ b/hw/arm/palm.c @@ -22,8 +22,8 @@ #include "ui/console.h" #include "hw/arm/omap.h" #include "hw/boards.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "hw/loader.h" #include "exec/address-spaces.h" diff --git a/hw/arm/pic_cpu.c b/hw/arm/pic_cpu.c index 787767f51f..875280aa97 100644 --- a/hw/arm/pic_cpu.c +++ b/hw/arm/pic_cpu.c @@ -8,7 +8,7 @@ */ #include "hw/hw.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "sysemu/kvm.h" /* Input 0 is IRQ and input 1 is FIQ. */ diff --git a/hw/arm/realview.c b/hw/arm/realview.c index afd52d31be..feabfc58d4 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -8,9 +8,9 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/arm/primecell.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/pci/pci.h" #include "net/net.h" #include "sysemu/sysemu.h" diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c index fa434dc68e..c42668ae49 100644 --- a/hw/arm/spitz.c +++ b/hw/arm/spitz.c @@ -12,14 +12,14 @@ #include "hw/hw.h" #include "hw/arm/pxa.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "sysemu/sysemu.h" #include "hw/pcmcia.h" #include "hw/i2c/i2c.h" #include "hw/ssi.h" #include "hw/block/flash.h" #include "qemu/timer.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/arm/sharpsl.h" #include "ui/console.h" #include "block/block.h" diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index 952087ce2d..2b61e3c7f8 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -9,8 +9,8 @@ #include "hw/sysbus.h" #include "hw/ssi.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "qemu/timer.h" #include "hw/i2c/i2c.h" #include "net/net.h" diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c index 5873a3c956..75a813e618 100644 --- a/hw/arm/strongarm.c +++ b/hw/arm/strongarm.c @@ -29,7 +29,7 @@ #include "hw/sysbus.h" #include "strongarm.h" #include "qemu/error-report.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "char/char.h" #include "sysemu/sysemu.h" #include "hw/ssi.h" diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c index c4362d4313..47818a5d01 100644 --- a/hw/arm/tosa.c +++ b/hw/arm/tosa.c @@ -13,8 +13,8 @@ #include "hw/hw.h" #include "hw/arm/pxa.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "hw/arm/sharpsl.h" #include "hw/pcmcia.h" #include "block/block.h" diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c index d9be604481..25c665ab27 100644 --- a/hw/arm/versatilepb.c +++ b/hw/arm/versatilepb.c @@ -8,8 +8,8 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/pci/pci.h" diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index 96e098579f..a077c62744 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -22,9 +22,9 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "hw/arm/primecell.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/boards.h" diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c index 8d65f796f9..41505c32ba 100644 --- a/hw/arm/xilinx_zynq.c +++ b/hw/arm/xilinx_zynq.c @@ -16,7 +16,7 @@ */ #include "hw/sysbus.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "net/net.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" diff --git a/hw/arm/z2.c b/hw/arm/z2.c index 3e272088f5..07a127b498 100644 --- a/hw/arm/z2.c +++ b/hw/arm/z2.c @@ -13,8 +13,8 @@ #include "hw/hw.h" #include "hw/arm/pxa.h" -#include "hw/arm.h" -#include "hw/arm/devices.h" +#include "hw/arm/arm.h" +#include "hw/devices.h" #include "hw/i2c/i2c.h" #include "hw/ssi.h" #include "hw/boards.h" diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index cd560e3747..55e9d0d37a 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -24,7 +24,7 @@ #include "hw/hw.h" #include "sysemu/blockdev.h" #include "hw/ssi.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #ifdef M25P80_ERR_DEBUG #define DB_PRINT(...) do { \ diff --git a/hw/display/blizzard.c b/hw/display/blizzard.c index 175c5cdd00..de7ccf87dc 100644 --- a/hw/display/blizzard.c +++ b/hw/display/blizzard.c @@ -20,7 +20,7 @@ #include "qemu-common.h" #include "ui/console.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "vga_int.h" #include "ui/pixel_ops.h" diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 6b660ac1c0..9878df4af6 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -26,7 +26,7 @@ #include "hw/hw.h" #include "hw/char/serial.h" #include "ui/console.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/sysbus.h" #include "hw/qdev-addr.h" #include "qemu/range.h" diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c index e252ce945f..178a21fd8d 100644 --- a/hw/display/tc6393xb.c +++ b/hw/display/tc6393xb.c @@ -11,7 +11,7 @@ * GNU GPL, version 2 or (at your option) any later version. */ #include "hw/hw.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/block/flash.h" #include "ui/console.h" #include "ui/pixel_ops.h" diff --git a/hw/input/stellaris_input.c b/hw/input/stellaris_input.c index f83fc3f288..4e407922a0 100644 --- a/hw/input/stellaris_input.c +++ b/hw/input/stellaris_input.c @@ -7,7 +7,7 @@ * This code is licensed under the GPL. */ #include "hw/hw.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "ui/console.h" typedef struct { diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c index 34ee1fb3cf..a771cd5e52 100644 --- a/hw/input/tsc2005.c +++ b/hw/input/tsc2005.c @@ -21,7 +21,7 @@ #include "hw/hw.h" #include "qemu/timer.h" #include "ui/console.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #define TSC_CUT_RESOLUTION(value, p) ((value) >> (16 - (p ? 12 : 10))) diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c index e6c217c8db..9b854e77dd 100644 --- a/hw/input/tsc210x.c +++ b/hw/input/tsc210x.c @@ -24,7 +24,7 @@ #include "qemu/timer.h" #include "ui/console.h" #include "hw/arm/omap.h" /* For I2SCodec and uWireSlave */ -#include "hw/arm/devices.h" +#include "hw/devices.h" #define TSC_DATA_REGISTERS_PAGE 0x0 #define TSC_CONTROL_REGISTERS_PAGE 0x1 diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 67dbe68cdc..25fa43cb2d 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -12,7 +12,7 @@ #include "hw/sysbus.h" #include "qemu/timer.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #include "exec/address-spaces.h" #include "gic_internal.h" diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c index 6555a97e2e..1ca94980fb 100644 --- a/hw/lm32/lm32_boards.c +++ b/hw/lm32/lm32_boards.c @@ -20,7 +20,7 @@ #include "hw/sysbus.h" #include "hw/hw.h" #include "hw/block/flash.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "hw/loader.h" #include "sysemu/blockdev.h" diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c index d02ca0cc04..cca93748aa 100644 --- a/hw/lm32/milkymist.c +++ b/hw/lm32/milkymist.c @@ -21,7 +21,7 @@ #include "hw/hw.h" #include "hw/block/flash.h" #include "sysemu/sysemu.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "hw/loader.h" #include "elf.h" diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index f61818b42b..ae7ff44423 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -30,7 +30,7 @@ #include "net/net.h" #include "hw/block/flash.h" #include "sysemu/sysemu.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "hw/xilinx.h" #include "sysemu/blockdev.h" diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c index eedd60e38c..7c258f03af 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -28,7 +28,7 @@ #include "net/net.h" #include "hw/block/flash.h" #include "sysemu/sysemu.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "hw/xilinx.h" #include "sysemu/blockdev.h" diff --git a/hw/misc/cbus.c b/hw/misc/cbus.c index 3d9027f692..29b467b61f 100644 --- a/hw/misc/cbus.c +++ b/hw/misc/cbus.c @@ -22,7 +22,7 @@ #include "qemu-common.h" #include "hw/irq.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "sysemu/sysemu.h" //#define DEBUG diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index 04cf267f13..403fb868ae 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -12,7 +12,7 @@ #include "hw/sysbus.h" #include "net/net.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "sysemu/sysemu.h" #include "hw/ptimer.h" /* For crc32 */ diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index f659256d6e..c2feae6eb8 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -9,7 +9,7 @@ #include "hw/sysbus.h" #include "net/net.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" /* For crc32 */ #include diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index 92b43947f7..6728ba7ea0 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -27,7 +27,7 @@ #include "hw/char/serial.h" #include "hw/block/flash.h" #include "sysemu/sysemu.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/boards.h" #include "sysemu/device_tree.h" #include "hw/loader.h" diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c index fe82bd62fe..3e4818e170 100644 --- a/hw/sh4/r2d.c +++ b/hw/sh4/r2d.c @@ -26,7 +26,7 @@ #include "hw/sysbus.h" #include "hw/hw.h" #include "hw/sh4/sh.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/pci/pci.h" diff --git a/hw/timer/tusb6010.c b/hw/timer/tusb6010.c index 533938a9b4..50edc063d1 100644 --- a/hw/timer/tusb6010.c +++ b/hw/timer/tusb6010.c @@ -23,7 +23,7 @@ #include "hw/usb.h" #include "hw/arm/omap.h" #include "hw/irq.h" -#include "hw/arm/devices.h" +#include "hw/devices.h" #include "hw/sysbus.h" typedef struct TUSBState { diff --git a/include/hw/arm.h b/include/hw/arm.h deleted file mode 100644 index 7b2b02daaf..0000000000 --- a/include/hw/arm.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Misc ARM declarations - * - * Copyright (c) 2006 CodeSourcery. - * Written by Paul Brook - * - * This code is licensed under the LGPL. - * - */ - -#ifndef ARM_MISC_H -#define ARM_MISC_H 1 - -#include "exec/memory.h" -#include "hw/irq.h" - -/* The CPU is also modelled as an interrupt controller. */ -#define ARM_PIC_CPU_IRQ 0 -#define ARM_PIC_CPU_FIQ 1 -qemu_irq *arm_pic_init_cpu(ARMCPU *cpu); - -/* armv7m.c */ -qemu_irq *armv7m_init(MemoryRegion *address_space_mem, - int flash_size, int sram_size, - const char *kernel_filename, const char *cpu_model); - -/* arm_boot.c */ -struct arm_boot_info { - uint64_t ram_size; - const char *kernel_filename; - const char *kernel_cmdline; - const char *initrd_filename; - const char *dtb_filename; - hwaddr loader_start; - /* multicore boards that use the default secondary core boot functions - * need to put the address of the secondary boot code, the boot reg, - * and the GIC address in the next 3 values, respectively. boards that - * have their own boot functions can use these values as they want. - */ - hwaddr smp_loader_start; - hwaddr smp_bootreg_addr; - hwaddr gic_cpu_if_addr; - int nb_cpus; - int board_id; - int (*atag_board)(const struct arm_boot_info *info, void *p); - /* multicore boards that use the default secondary core boot functions - * can ignore these two function calls. If the default functions won't - * work, then write_secondary_boot() should write a suitable blob of - * code mimicking the secondary CPU startup process used by the board's - * boot loader/boot ROM code, and secondary_cpu_reset_hook() should - * perform any necessary CPU reset handling and set the PC for the - * secondary CPUs to point at this boot blob. - */ - void (*write_secondary_boot)(ARMCPU *cpu, - const struct arm_boot_info *info); - void (*secondary_cpu_reset_hook)(ARMCPU *cpu, - const struct arm_boot_info *info); - /* Used internally by arm_boot.c */ - int is_linux; - hwaddr initrd_start; - hwaddr initrd_size; - hwaddr entry; -}; -void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); - -/* Multiplication factor to convert from system clock ticks to qemu timer - ticks. */ -extern int system_clock_scale; - -#endif /* !ARM_MISC_H */ diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h new file mode 100644 index 0000000000..7b2b02daaf --- /dev/null +++ b/include/hw/arm/arm.h @@ -0,0 +1,70 @@ +/* + * Misc ARM declarations + * + * Copyright (c) 2006 CodeSourcery. + * Written by Paul Brook + * + * This code is licensed under the LGPL. + * + */ + +#ifndef ARM_MISC_H +#define ARM_MISC_H 1 + +#include "exec/memory.h" +#include "hw/irq.h" + +/* The CPU is also modelled as an interrupt controller. */ +#define ARM_PIC_CPU_IRQ 0 +#define ARM_PIC_CPU_FIQ 1 +qemu_irq *arm_pic_init_cpu(ARMCPU *cpu); + +/* armv7m.c */ +qemu_irq *armv7m_init(MemoryRegion *address_space_mem, + int flash_size, int sram_size, + const char *kernel_filename, const char *cpu_model); + +/* arm_boot.c */ +struct arm_boot_info { + uint64_t ram_size; + const char *kernel_filename; + const char *kernel_cmdline; + const char *initrd_filename; + const char *dtb_filename; + hwaddr loader_start; + /* multicore boards that use the default secondary core boot functions + * need to put the address of the secondary boot code, the boot reg, + * and the GIC address in the next 3 values, respectively. boards that + * have their own boot functions can use these values as they want. + */ + hwaddr smp_loader_start; + hwaddr smp_bootreg_addr; + hwaddr gic_cpu_if_addr; + int nb_cpus; + int board_id; + int (*atag_board)(const struct arm_boot_info *info, void *p); + /* multicore boards that use the default secondary core boot functions + * can ignore these two function calls. If the default functions won't + * work, then write_secondary_boot() should write a suitable blob of + * code mimicking the secondary CPU startup process used by the board's + * boot loader/boot ROM code, and secondary_cpu_reset_hook() should + * perform any necessary CPU reset handling and set the PC for the + * secondary CPUs to point at this boot blob. + */ + void (*write_secondary_boot)(ARMCPU *cpu, + const struct arm_boot_info *info); + void (*secondary_cpu_reset_hook)(ARMCPU *cpu, + const struct arm_boot_info *info); + /* Used internally by arm_boot.c */ + int is_linux; + hwaddr initrd_start; + hwaddr initrd_size; + hwaddr entry; +}; +void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); + +/* Multiplication factor to convert from system clock ticks to qemu timer + ticks. */ +extern int system_clock_scale; + +#endif /* !ARM_MISC_H */ diff --git a/include/hw/arm/devices.h b/include/hw/arm/devices.h deleted file mode 100644 index c60bcabae3..0000000000 --- a/include/hw/arm/devices.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef QEMU_DEVICES_H -#define QEMU_DEVICES_H - -#include "hw/irq.h" - -/* ??? Not all users of this file can include cpu-common.h. */ -struct MemoryRegion; - -/* Devices that have nowhere better to go. */ - -/* smc91c111.c */ -void smc91c111_init(NICInfo *, uint32_t, qemu_irq); - -/* lan9118.c */ -void lan9118_init(NICInfo *, uint32_t, qemu_irq); - -/* tsc210x.c */ -uWireSlave *tsc2102_init(qemu_irq pint); -uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav); -I2SCodec *tsc210x_codec(uWireSlave *chip); -uint32_t tsc210x_txrx(void *opaque, uint32_t value, int len); -void tsc210x_set_transform(uWireSlave *chip, - MouseTransformInfo *info); -void tsc210x_key_event(uWireSlave *chip, int key, int down); - -/* tsc2005.c */ -void *tsc2005_init(qemu_irq pintdav); -uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len); -void tsc2005_set_transform(void *opaque, MouseTransformInfo *info); - -/* stellaris_input.c */ -void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode); - -/* blizzard.c */ -void *s1d13745_init(qemu_irq gpio_int); -void s1d13745_write(void *opaque, int dc, uint16_t value); -void s1d13745_write_block(void *opaque, int dc, - void *buf, size_t len, int pitch); -uint16_t s1d13745_read(void *opaque, int dc); - -/* cbus.c */ -typedef struct { - qemu_irq clk; - qemu_irq dat; - qemu_irq sel; -} CBus; -CBus *cbus_init(qemu_irq dat_out); -void cbus_attach(CBus *bus, void *slave_opaque); - -void *retu_init(qemu_irq irq, int vilma); -void *tahvo_init(qemu_irq irq, int betty); - -void retu_key_event(void *retu, int state); - -/* tc6393xb.c */ -typedef struct TC6393xbState TC6393xbState; -#define TC6393XB_RAM 0x110000 /* amount of ram for Video and USB */ -TC6393xbState *tc6393xb_init(struct MemoryRegion *sysmem, - uint32_t base, qemu_irq irq); -void tc6393xb_gpio_out_set(TC6393xbState *s, int line, - qemu_irq handler); -qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s); -qemu_irq tc6393xb_l3v_get(TC6393xbState *s); - -/* sm501.c */ -void sm501_init(struct MemoryRegion *address_space_mem, uint32_t base, - uint32_t local_mem_bytes, qemu_irq irq, - CharDriverState *chr); - -#endif diff --git a/include/hw/devices.h b/include/hw/devices.h new file mode 100644 index 0000000000..c60bcabae3 --- /dev/null +++ b/include/hw/devices.h @@ -0,0 +1,70 @@ +#ifndef QEMU_DEVICES_H +#define QEMU_DEVICES_H + +#include "hw/irq.h" + +/* ??? Not all users of this file can include cpu-common.h. */ +struct MemoryRegion; + +/* Devices that have nowhere better to go. */ + +/* smc91c111.c */ +void smc91c111_init(NICInfo *, uint32_t, qemu_irq); + +/* lan9118.c */ +void lan9118_init(NICInfo *, uint32_t, qemu_irq); + +/* tsc210x.c */ +uWireSlave *tsc2102_init(qemu_irq pint); +uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav); +I2SCodec *tsc210x_codec(uWireSlave *chip); +uint32_t tsc210x_txrx(void *opaque, uint32_t value, int len); +void tsc210x_set_transform(uWireSlave *chip, + MouseTransformInfo *info); +void tsc210x_key_event(uWireSlave *chip, int key, int down); + +/* tsc2005.c */ +void *tsc2005_init(qemu_irq pintdav); +uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len); +void tsc2005_set_transform(void *opaque, MouseTransformInfo *info); + +/* stellaris_input.c */ +void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode); + +/* blizzard.c */ +void *s1d13745_init(qemu_irq gpio_int); +void s1d13745_write(void *opaque, int dc, uint16_t value); +void s1d13745_write_block(void *opaque, int dc, + void *buf, size_t len, int pitch); +uint16_t s1d13745_read(void *opaque, int dc); + +/* cbus.c */ +typedef struct { + qemu_irq clk; + qemu_irq dat; + qemu_irq sel; +} CBus; +CBus *cbus_init(qemu_irq dat_out); +void cbus_attach(CBus *bus, void *slave_opaque); + +void *retu_init(qemu_irq irq, int vilma); +void *tahvo_init(qemu_irq irq, int betty); + +void retu_key_event(void *retu, int state); + +/* tc6393xb.c */ +typedef struct TC6393xbState TC6393xbState; +#define TC6393XB_RAM 0x110000 /* amount of ram for Video and USB */ +TC6393xbState *tc6393xb_init(struct MemoryRegion *sysmem, + uint32_t base, qemu_irq irq); +void tc6393xb_gpio_out_set(TC6393xbState *s, int line, + qemu_irq handler); +qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s); +qemu_irq tc6393xb_l3v_get(TC6393xbState *s); + +/* sm501.c */ +void sm501_init(struct MemoryRegion *address_space_mem, uint32_t base, + uint32_t local_mem_bytes, qemu_irq irq, + CharDriverState *chr); + +#endif diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c index 77718c4caa..f0637a43f2 100644 --- a/target-arm/arm-semi.c +++ b/target-arm/arm-semi.c @@ -34,7 +34,7 @@ #else #include "qemu-common.h" #include "exec/gdbstub.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" #endif #define TARGET_SYS_OPEN 0x01 diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 6bfb10350b..d8acace9b7 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -21,7 +21,7 @@ #include "sysemu/kvm.h" #include "kvm_arm.h" #include "cpu.h" -#include "hw/arm.h" +#include "hw/arm/arm.h" const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO -- cgit v1.2.3 From fd123245b98fd6e13d829878f25b30a9417f4bfc Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 10 Apr 2013 10:29:47 +0200 Subject: Add linux-headers to QEMU_INCLUDES virtio/dataplane/vring.c requires the Linux headers and is built for all targets. So we need to add the corresponding include to QEMU_INCLUDES to avoid that outdated distribution headers are used. Signed-off-by: Jan Kiszka Signed-off-by: Paolo Bonzini --- configure | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/configure b/configure index 73df181406..258c82abac 100755 --- a/configure +++ b/configure @@ -544,6 +544,7 @@ Haiku) if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then audio_possible_drivers="$audio_possible_drivers fmod" fi + QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers $QEMU_INCLUDES" ;; esac @@ -4227,10 +4228,6 @@ else fi includes="-I\$(SRC_PATH)/tcg $includes" -if test "$linux" = "yes" ; then - includes="-I\$(SRC_PATH)/linux-headers $includes" -fi - for i in $ARCH $TARGET_BASE_ARCH ; do case "$i" in alpha) -- cgit v1.2.3 From 35b2028f47eef4e20752f94f7cff650d828bfaee Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Wed, 10 Apr 2013 16:43:09 +0800 Subject: Fix failure to create q35 machine This is a regression introduced by c0907c9e6417c. How to reproduce: $ qemu-system-x86_64 -nodefaults -vnc :0 -M q35 qemu-system-x86_64: Unknown device 'q35-pcihost' for default sysbus Aborted (core dumped) Tested-by: Markus Armbruster Signed-off-by: Hu Tao Signed-off-by: Paolo Bonzini --- default-configs/i386-softmmu.mak | 2 +- default-configs/x86_64-softmmu.mak | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 4ac0694470..6d9d364ff8 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -42,6 +42,6 @@ CONFIG_ISA_TESTDEV=y CONFIG_VMPORT=y CONFIG_SGA=y CONFIG_LPC_ICH9=y -CONFIG_Q35=y +CONFIG_PCI_Q35=y CONFIG_APIC=y CONFIG_IOAPIC=y diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index bf4091c4dd..3b063101cf 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -42,6 +42,6 @@ CONFIG_ISA_TESTDEV=y CONFIG_VMPORT=y CONFIG_SGA=y CONFIG_LPC_ICH9=y -CONFIG_Q35=y +CONFIG_PCI_Q35=y CONFIG_APIC=y CONFIG_IOAPIC=y -- cgit v1.2.3 From 174d5d990c7b08e75677402a71c834b000171c94 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 14 Apr 2013 22:52:50 +0200 Subject: hw: Add lost ARM core again Commit 0434e30afb6175212389811e0b28b948eb3c1e40 accidentally removed the compilation of arm11mpcore.c. Signed-off-by: Stefan Weil Signed-off-by: Paolo Bonzini --- default-configs/arm-softmmu.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 31725a97f9..27cbe3d088 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -34,8 +34,8 @@ CONFIG_PFLASH_CFI02=y CONFIG_MICRODRIVE=y CONFIG_USB_MUSB=y -CONFIG_ARM5MPCORE=y CONFIG_ARM9MPCORE=y +CONFIG_ARM11MPCORE=y CONFIG_ARM15MPCORE=y CONFIG_ARM_GIC=y -- cgit v1.2.3 From 0445259ba686f9ddf395f700c7d5b1ac400a451c Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Mon, 15 Apr 2013 09:19:22 +0300 Subject: acpi: move declarations from pc.h to acpi.h Functions defined in acpi/ should be declared in acpi.h Signed-off-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini --- arch_init.c | 1 + hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + include/hw/acpi/acpi.h | 7 +++++++ include/hw/i386/pc.h | 8 -------- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arch_init.c b/arch_init.c index 769ce77e61..fba0889bc7 100644 --- a/arch_init.c +++ b/arch_init.c @@ -49,6 +49,7 @@ #include "qmp-commands.h" #include "trace.h" #include "exec/cpu-all.h" +#include "hw/acpi/acpi.h" #ifdef DEBUG_ARCH_INIT #define DPRINTF(fmt, ...) \ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8d75b34218..0d6e72b209 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -52,6 +52,7 @@ #include "sysemu/arch_init.h" #include "qemu/bitmap.h" #include "qemu/config-file.h" +#include "hw/acpi/acpi.h" /* debug PC/ISA interrupts */ //#define DEBUG_IRQ diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index cff8013b83..943758ad30 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -43,6 +43,7 @@ #include "hw/xen/xen.h" #include "exec/memory.h" #include "exec/address-spaces.h" +#include "hw/acpi/acpi.h" #include "cpu.h" #ifdef CONFIG_XEN # include diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h index e18ef28fd3..4cd52c1b36 100644 --- a/include/hw/acpi/acpi.h +++ b/include/hw/acpi/acpi.h @@ -154,4 +154,11 @@ void acpi_gpe_reset(ACPIREGS *ar); void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val); uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr); +/* acpi.c */ +extern int acpi_enabled; +extern char unsigned *acpi_tables; +extern size_t acpi_tables_len; + +void acpi_table_add(const QemuOpts *opts, Error **errp); + #endif /* !QEMU_HW_ACPI_H */ diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 5d40914f49..9bcc8193b7 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -107,14 +107,6 @@ void cpu_smm_register(cpu_set_smm_t callback, void *arg); void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); -/* acpi.c */ -extern int acpi_enabled; -extern char unsigned *acpi_tables; -extern size_t acpi_tables_len; - -void acpi_bios_init(void); -void acpi_table_add(const QemuOpts *opts, Error **errp); - /* acpi_piix.c */ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, -- cgit v1.2.3 From e53339cf7cf90cf5c7a6bca64d0e7c0956f53a66 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Mon, 15 Apr 2013 11:12:50 +0300 Subject: acpi.h: make it self contained Headers shouldn't assume another header is included, pull in everything necessary. Signed-off-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini --- include/hw/acpi/acpi.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h index 4cd52c1b36..635be7be10 100644 --- a/include/hw/acpi/acpi.h +++ b/include/hw/acpi/acpi.h @@ -19,6 +19,12 @@ * . */ +#include "qapi/error.h" +#include "qemu/typedefs.h" +#include "qemu/notify.h" +#include "qemu/option.h" +#include "exec/memory.h" + /* from linux include/acpi/actype.h */ /* Default ACPI register widths */ -- cgit v1.2.3 From 3b8acc11d3f60792f9f716f2a93c258e729af980 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 18 Mar 2013 16:37:50 +0100 Subject: configure: fix TPM logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A non-native i386 or x86_64 emulator should not have TPM passthrough support, since the TPM is only present for those hosts. Reviewed-by: Andreas Färber Signed-off-by: Paolo Bonzini --- configure | 24 ++++++++++++++++++------ default-configs/i386-softmmu.mak | 3 +-- default-configs/x86_64-softmmu.mak | 3 +-- tpm/Makefile.objs | 4 +--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 258c82abac..1c1e3694e8 100755 --- a/configure +++ b/configure @@ -2336,6 +2336,15 @@ EOF fi fi +########################################## +# TPM passthrough is only on x86 Linux + +if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64; then + tpm_passthrough=$tpm +else + tpm_passthrough=no +fi + ########################################## # adjust virtio-blk-data-plane based on linux-aio @@ -3436,6 +3445,7 @@ echo "virtio-blk-data-plane $virtio_blk_data_plane" echo "gcov $gcov_tool" echo "gcov enabled $gcov" echo "TPM support $tpm" +echo "TPM passthrough $tpm_passthrough" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -3811,6 +3821,14 @@ bsd) ;; esac +# TPM passthrough support? +if test "$tpm" = "yes"; then + echo 'CONFIG_TPM=$(CONFIG_SOFTMMU)' >> $config_host_mak + if test "$tpm_passthrough" = "yes"; then + echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak + fi +fi + # use default implementation for tracing backend-specific routines trace_default=yes echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak @@ -4338,12 +4356,6 @@ if test "$gprof" = "yes" ; then fi fi -if test "$tpm" = "yes"; then - if test "$target_softmmu" = "yes" ; then - echo "CONFIG_TPM=y" >> $config_host_mak - fi -fi - if test "$ARCH" = "tci"; then linker_script="" else diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 6d9d364ff8..368a776166 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -27,8 +27,7 @@ CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y CONFIG_PFLASH_CFI01=y -CONFIG_TPM_TIS=y -CONFIG_TPM_PASSTHROUGH=y +CONFIG_TPM_TIS=$(CONFIG_TPM) CONFIG_PCI_HOTPLUG=y CONFIG_MC146818RTC=y CONFIG_PAM=y diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 3b063101cf..2711b83bf0 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -27,8 +27,7 @@ CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y CONFIG_PFLASH_CFI01=y -CONFIG_TPM_TIS=y -CONFIG_TPM_PASSTHROUGH=y +CONFIG_TPM_TIS=$(CONFIG_TPM) CONFIG_PCI_HOTPLUG=y CONFIG_MC146818RTC=y CONFIG_PAM=y diff --git a/tpm/Makefile.objs b/tpm/Makefile.objs index 86768244e4..366e4a7128 100644 --- a/tpm/Makefile.objs +++ b/tpm/Makefile.objs @@ -1,6 +1,4 @@ common-obj-y = tpm.o -ifeq ($(CONFIG_TPM),y) -common-obj-y += tpm_backend.o +common-obj-$(CONFIG_TPM) += tpm_backend.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -endif -- cgit v1.2.3 From bdee56f5466a724f043e6cfcfcf69866cc48cc94 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 2 Apr 2013 18:28:41 +0200 Subject: tpm: reorganize headers and split hardware part The TPM subsystem does not have a full front-end/back-end separation. The sole available backend, tpm_passthrough, depends on the data structures of the sole available frontend, tpm_tis. However, we can at least try to split the user interface (tpm.c) from the implementation (hw/tpm). The patches makes tpm.c not include tpm_int.h, which is shared between tpm_tis.c and tpm_passthrough.c; instead it moves more stuff to tpm_backend.h. Signed-off-by: Paolo Bonzini --- Makefile.objs | 2 +- backends/tpm.c | 38 +- hw/Makefile.objs | 1 + hw/tpm/Makefile.objs | 2 + hw/tpm/tpm_int.h | 60 +++ hw/tpm/tpm_passthrough.c | 576 ++++++++++++++++++++++++ hw/tpm/tpm_tis.c | 930 +++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_tis.h | 75 ++++ include/backends/tpm.h | 41 +- include/sysemu/tpm.h | 23 + include/sysemu/tpm_backend_int.h | 45 ++ include/tpm/tpm.h | 25 -- monitor.c | 2 +- tpm.c | 350 +++++++++++++++ tpm/Makefile.objs | 4 - tpm/tpm.c | 365 --------------- tpm/tpm_backend.c | 58 --- tpm/tpm_backend.h | 45 -- tpm/tpm_int.h | 95 ---- tpm/tpm_passthrough.c | 560 ----------------------- tpm/tpm_tis.c | 930 --------------------------------------- tpm/tpm_tis.h | 80 ---- vl.c | 2 +- 23 files changed, 2142 insertions(+), 2167 deletions(-) create mode 100644 hw/tpm/Makefile.objs create mode 100644 hw/tpm/tpm_int.h create mode 100644 hw/tpm/tpm_passthrough.c create mode 100644 hw/tpm/tpm_tis.c create mode 100644 hw/tpm/tpm_tis.h create mode 100644 include/sysemu/tpm.h create mode 100644 include/sysemu/tpm_backend_int.h delete mode 100644 include/tpm/tpm.h create mode 100644 tpm.c delete mode 100644 tpm/Makefile.objs delete mode 100644 tpm/tpm.c delete mode 100644 tpm/tpm_backend.c delete mode 100644 tpm/tpm_backend.h delete mode 100644 tpm/tpm_int.h delete mode 100644 tpm/tpm_passthrough.c delete mode 100644 tpm/tpm_tis.c delete mode 100644 tpm/tpm_tis.h diff --git a/Makefile.objs b/Makefile.objs index e568c018b3..a473348dc2 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -65,7 +65,7 @@ common-obj-y += bt-host.o bt-vhci.o common-obj-y += dma-helpers.o common-obj-y += vl.o -common-obj-y += tpm/ +common-obj-y += tpm.o common-obj-$(CONFIG_SLIRP) += slirp/ diff --git a/backends/tpm.c b/backends/tpm.c index 28148c23cf..0580108c5f 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -13,8 +13,10 @@ */ #include "backends/tpm.h" -#include "tpm/tpm_int.h" #include "qapi/qmp/qerror.h" +#include "sysemu/tpm.h" +#include "qemu/thread.h" +#include "sysemu/tpm_backend_int.h" enum TpmType tpm_backend_get_type(TPMBackend *s) { @@ -137,6 +139,40 @@ static void tpm_backend_instance_init(Object *obj) NULL); } +void tpm_backend_thread_deliver_request(TPMBackendThread *tbt) +{ + g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL); +} + +void tpm_backend_thread_create(TPMBackendThread *tbt, + GFunc func, gpointer user_data) +{ + if (!tbt->pool) { + tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL); + g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL); + } +} + +void tpm_backend_thread_end(TPMBackendThread *tbt) +{ + if (tbt->pool) { + g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL); + g_thread_pool_free(tbt->pool, FALSE, TRUE); + tbt->pool = NULL; + } +} + +void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, + GFunc func, gpointer user_data) +{ + if (!tbt->pool) { + tpm_backend_thread_create(tbt, func, user_data); + } else { + g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_TPM_RESET, + NULL); + } +} + static const TypeInfo tpm_backend_info = { .name = TYPE_TPM_BACKEND, .parent = TYPE_OBJECT, diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 1cb86fa323..b7a1613612 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -22,6 +22,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += scsi/ devices-dirs-$(CONFIG_SOFTMMU) += sd/ devices-dirs-$(CONFIG_SOFTMMU) += ssi/ devices-dirs-$(CONFIG_SOFTMMU) += timer/ +devices-dirs-$(CONFIG_TPM) += tpm/ devices-dirs-$(CONFIG_SOFTMMU) += usb/ devices-dirs-$(CONFIG_SOFTMMU) += virtio/ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs new file mode 100644 index 0000000000..99f5983143 --- /dev/null +++ b/hw/tpm/Makefile.objs @@ -0,0 +1,2 @@ +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h new file mode 100644 index 0000000000..08f87cb9a8 --- /dev/null +++ b/hw/tpm/tpm_int.h @@ -0,0 +1,60 @@ +/* + * TPM configuration + * + * Copyright (C) 2011-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef TPM_TPM_INT_H +#define TPM_TPM_INT_H + +#include "exec/memory.h" +#include "tpm_tis.h" + +/* overall state of the TPM interface */ +struct TPMState { + ISADevice busdev; + MemoryRegion mmio; + + union { + TPMTISEmuState tis; + } s; + + uint8_t locty_number; + TPMLocality *locty_data; + + char *backend; + TPMBackend *be_driver; +}; + +#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) + +struct tpm_req_hdr { + uint16_t tag; + uint32_t len; + uint32_t ordinal; +} QEMU_PACKED; + +struct tpm_resp_hdr { + uint16_t tag; + uint32_t len; + uint32_t errcode; +} QEMU_PACKED; + +#define TPM_TAG_RQU_COMMAND 0xc1 +#define TPM_TAG_RQU_AUTH1_COMMAND 0xc2 +#define TPM_TAG_RQU_AUTH2_COMMAND 0xc3 + +#define TPM_TAG_RSP_COMMAND 0xc4 +#define TPM_TAG_RSP_AUTH1_COMMAND 0xc5 +#define TPM_TAG_RSP_AUTH2_COMMAND 0xc6 + +#define TPM_FAIL 9 + +#define TPM_ORD_GetTicks 0xf1 + +#endif /* TPM_TPM_INT_H */ diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c new file mode 100644 index 0000000000..578127723f --- /dev/null +++ b/hw/tpm/tpm_passthrough.c @@ -0,0 +1,576 @@ +/* + * passthrough TPM driver + * + * Copyright (c) 2010 - 2013 IBM Corporation + * Authors: + * Stefan Berger + * + * Copyright (C) 2011 IAIK, Graz University of Technology + * Author: Andreas Niederl + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include + +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "backends/tpm.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" + +/* #define DEBUG_TPM */ + +#ifdef DEBUG_TPM +#define DPRINTF(fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) \ + do { } while (0) +#endif + +#define TYPE_TPM_PASSTHROUGH "tpm-passthrough" +#define TPM_PASSTHROUGH(obj) \ + OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) + +static const TPMDriverOps tpm_passthrough_driver; + +/* data structures */ +typedef struct TPMPassthruThreadParams { + TPMState *tpm_state; + + TPMRecvDataCB *recv_data_callback; + TPMBackend *tb; +} TPMPassthruThreadParams; + +struct TPMPassthruState { + TPMBackend parent; + + TPMBackendThread tbt; + + TPMPassthruThreadParams tpm_thread_params; + + char *tpm_dev; + int tpm_fd; + bool tpm_executing; + bool tpm_op_canceled; + int cancel_fd; + bool had_startup_error; +}; + +typedef struct TPMPassthruState TPMPassthruState; + +#define TPM_PASSTHROUGH_DEFAULT_DEVICE "/dev/tpm0" + +/* functions */ + +static void tpm_passthrough_cancel_cmd(TPMBackend *tb); + +static int tpm_passthrough_unix_write(int fd, const uint8_t *buf, uint32_t len) +{ + return send_all(fd, buf, len); +} + +static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len) +{ + return recv_all(fd, buf, len, true); +} + +static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf) +{ + struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)buf; + + return be32_to_cpu(resp->len); +} + +/* + * Write an error message in the given output buffer. + */ +static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) +{ + if (out_len >= sizeof(struct tpm_resp_hdr)) { + struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; + + resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); + resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); + resp->errcode = cpu_to_be32(TPM_FAIL); + } +} + +static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, + const uint8_t *in, uint32_t in_len, + uint8_t *out, uint32_t out_len) +{ + int ret; + + tpm_pt->tpm_op_canceled = false; + tpm_pt->tpm_executing = true; + + ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len); + if (ret != in_len) { + if (!tpm_pt->tpm_op_canceled || + (tpm_pt->tpm_op_canceled && errno != ECANCELED)) { + error_report("tpm_passthrough: error while transmitting data " + "to TPM: %s (%i)\n", + strerror(errno), errno); + } + goto err_exit; + } + + tpm_pt->tpm_executing = false; + + ret = tpm_passthrough_unix_read(tpm_pt->tpm_fd, out, out_len); + if (ret < 0) { + if (!tpm_pt->tpm_op_canceled || + (tpm_pt->tpm_op_canceled && errno != ECANCELED)) { + error_report("tpm_passthrough: error while reading data from " + "TPM: %s (%i)\n", + strerror(errno), errno); + } + } else if (ret < sizeof(struct tpm_resp_hdr) || + tpm_passthrough_get_size_from_buffer(out) != ret) { + ret = -1; + error_report("tpm_passthrough: received invalid response " + "packet from TPM\n"); + } + +err_exit: + if (ret < 0) { + tpm_write_fatal_error_response(out, out_len); + } + + tpm_pt->tpm_executing = false; + + return ret; +} + +static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, + const TPMLocality *locty_data) +{ + return tpm_passthrough_unix_tx_bufs(tpm_pt, + locty_data->w_buffer.buffer, + locty_data->w_offset, + locty_data->r_buffer.buffer, + locty_data->r_buffer.size); +} + +static void tpm_passthrough_worker_thread(gpointer data, + gpointer user_data) +{ + TPMPassthruThreadParams *thr_parms = user_data; + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(thr_parms->tb); + TPMBackendCmd cmd = (TPMBackendCmd)data; + + DPRINTF("tpm_passthrough: processing command type %d\n", cmd); + + switch (cmd) { + case TPM_BACKEND_CMD_PROCESS_CMD: + tpm_passthrough_unix_transfer(tpm_pt, + thr_parms->tpm_state->locty_data); + + thr_parms->recv_data_callback(thr_parms->tpm_state, + thr_parms->tpm_state->locty_number); + break; + case TPM_BACKEND_CMD_INIT: + case TPM_BACKEND_CMD_END: + case TPM_BACKEND_CMD_TPM_RESET: + /* nothing to do */ + break; + } +} + +/* + * Start the TPM (thread). If it had been started before, then terminate + * and start it again. + */ +static int tpm_passthrough_startup_tpm(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + /* terminate a running TPM */ + tpm_backend_thread_end(&tpm_pt->tbt); + + tpm_backend_thread_create(&tpm_pt->tbt, + tpm_passthrough_worker_thread, + &tpm_pt->tpm_thread_params); + + return 0; +} + +static void tpm_passthrough_reset(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + DPRINTF("tpm_passthrough: CALL TO TPM_RESET!\n"); + + tpm_passthrough_cancel_cmd(tb); + + tpm_backend_thread_end(&tpm_pt->tbt); + + tpm_pt->had_startup_error = false; +} + +static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, + TPMRecvDataCB *recv_data_cb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + tpm_pt->tpm_thread_params.tpm_state = s; + tpm_pt->tpm_thread_params.recv_data_callback = recv_data_cb; + tpm_pt->tpm_thread_params.tb = tb; + + return 0; +} + +static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb) +{ + return false; +} + +static bool tpm_passthrough_get_startup_error(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + return tpm_pt->had_startup_error; +} + +static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb) +{ + size_t wanted_size = 4096; /* Linux tpm.c buffer size */ + + if (sb->size != wanted_size) { + sb->buffer = g_realloc(sb->buffer, wanted_size); + sb->size = wanted_size; + } + return sb->size; +} + +static void tpm_passthrough_deliver_request(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + tpm_backend_thread_deliver_request(&tpm_pt->tbt); +} + +static void tpm_passthrough_cancel_cmd(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + int n; + + /* + * As of Linux 3.7 the tpm_tis driver does not properly cancel + * commands on all TPM manufacturers' TPMs. + * Only cancel if we're busy so we don't cancel someone else's + * command, e.g., a command executed on the host. + */ + if (tpm_pt->tpm_executing) { + if (tpm_pt->cancel_fd >= 0) { + n = write(tpm_pt->cancel_fd, "-", 1); + if (n != 1) { + error_report("Canceling TPM command failed: %s\n", + strerror(errno)); + } else { + tpm_pt->tpm_op_canceled = true; + } + } else { + error_report("Cannot cancel TPM command due to missing " + "TPM sysfs cancel entry"); + } + } +} + +static const char *tpm_passthrough_create_desc(void) +{ + return "Passthrough TPM backend driver"; +} + +/* + * A basic test of a TPM device. We expect a well formatted response header + * (error response is fine) within one second. + */ +static int tpm_passthrough_test_tpmdev(int fd) +{ + struct tpm_req_hdr req = { + .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), + .len = cpu_to_be32(sizeof(req)), + .ordinal = cpu_to_be32(TPM_ORD_GetTicks), + }; + struct tpm_resp_hdr *resp; + fd_set readfds; + int n; + struct timeval tv = { + .tv_sec = 1, + .tv_usec = 0, + }; + unsigned char buf[1024]; + + n = write(fd, &req, sizeof(req)); + if (n < 0) { + return errno; + } + if (n != sizeof(req)) { + return EFAULT; + } + + FD_ZERO(&readfds); + FD_SET(fd, &readfds); + + /* wait for a second */ + n = select(fd + 1, &readfds, NULL, NULL, &tv); + if (n != 1) { + return errno; + } + + n = read(fd, &buf, sizeof(buf)); + if (n < sizeof(struct tpm_resp_hdr)) { + return EFAULT; + } + + resp = (struct tpm_resp_hdr *)buf; + /* check the header */ + if (be16_to_cpu(resp->tag) != TPM_TAG_RSP_COMMAND || + be32_to_cpu(resp->len) != n) { + return EBADMSG; + } + + return 0; +} + +/* + * Check whether the given base path, e.g., /sys/class/misc/tpm0/device, + * is the sysfs directory of a TPM. A TPM sysfs directory should be uniquely + * recognizable by the file entries 'pcrs' and 'cancel'. + * Upon success 'true' is returned and the basebath buffer has '/cancel' + * appended. + */ +static bool tpm_passthrough_check_sysfs_cancel(char *basepath, size_t bufsz) +{ + char path[PATH_MAX]; + struct stat statbuf; + + snprintf(path, sizeof(path), "%s/pcrs", basepath); + if (stat(path, &statbuf) == -1 || !S_ISREG(statbuf.st_mode)) { + return false; + } + + snprintf(path, sizeof(path), "%s/cancel", basepath); + if (stat(path, &statbuf) == -1 || !S_ISREG(statbuf.st_mode)) { + return false; + } + + strncpy(basepath, path, bufsz); + + return true; +} + +/* + * Unless path or file descriptor set has been provided by user, + * determine the sysfs cancel file following kernel documentation + * in Documentation/ABI/stable/sysfs-class-tpm. + */ +static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) +{ + int fd = -1; + unsigned int idx; + DIR *pnp_dir; + char path[PATH_MAX]; + struct dirent entry, *result; + int len; + + if (tb->cancel_path) { + fd = qemu_open(tb->cancel_path, O_WRONLY); + if (fd < 0) { + error_report("Could not open TPM cancel path : %s", + strerror(errno)); + } + return fd; + } + + snprintf(path, sizeof(path), "/sys/class/misc"); + pnp_dir = opendir(path); + if (pnp_dir != NULL) { + while (readdir_r(pnp_dir, &entry, &result) == 0 && + result != NULL) { + /* + * only allow /sys/class/misc/tpm%u type of paths + */ + if (sscanf(entry.d_name, "tpm%u%n", &idx, &len) < 1 || + len <= strlen("tpm") || + len != strlen(entry.d_name)) { + continue; + } + + snprintf(path, sizeof(path), "/sys/class/misc/%s/device", + entry.d_name); + if (!tpm_passthrough_check_sysfs_cancel(path, sizeof(path))) { + continue; + } + + fd = qemu_open(path, O_WRONLY); + break; + } + closedir(pnp_dir); + } + + if (fd >= 0) { + tb->cancel_path = g_strdup(path); + } + + return fd; +} + +static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + const char *value; + + value = qemu_opt_get(opts, "cancel-path"); + if (value) { + tb->cancel_path = g_strdup(value); + } + + value = qemu_opt_get(opts, "path"); + if (!value) { + value = TPM_PASSTHROUGH_DEFAULT_DEVICE; + } + + tpm_pt->tpm_dev = g_strdup(value); + + tb->path = g_strdup(tpm_pt->tpm_dev); + + tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR); + if (tpm_pt->tpm_fd < 0) { + error_report("Cannot access TPM device using '%s': %s\n", + tpm_pt->tpm_dev, strerror(errno)); + goto err_free_parameters; + } + + if (tpm_passthrough_test_tpmdev(tpm_pt->tpm_fd)) { + error_report("'%s' is not a TPM device.\n", + tpm_pt->tpm_dev); + goto err_close_tpmdev; + } + + return 0; + + err_close_tpmdev: + qemu_close(tpm_pt->tpm_fd); + tpm_pt->tpm_fd = -1; + + err_free_parameters: + g_free(tb->path); + tb->path = NULL; + + g_free(tpm_pt->tpm_dev); + tpm_pt->tpm_dev = NULL; + + return 1; +} + +static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) +{ + Object *obj = object_new(TYPE_TPM_PASSTHROUGH); + TPMBackend *tb = TPM_BACKEND(obj); + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + tb->id = g_strdup(id); + /* let frontend set the fe_model to proper value */ + tb->fe_model = -1; + + tb->ops = &tpm_passthrough_driver; + + if (tpm_passthrough_handle_device_opts(opts, tb)) { + goto err_exit; + } + + tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tb); + if (tpm_pt->cancel_fd < 0) { + goto err_exit; + } + + return tb; + +err_exit: + g_free(tb->id); + + return NULL; +} + +static void tpm_passthrough_destroy(TPMBackend *tb) +{ + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + tpm_passthrough_cancel_cmd(tb); + + tpm_backend_thread_end(&tpm_pt->tbt); + + qemu_close(tpm_pt->tpm_fd); + qemu_close(tpm_pt->cancel_fd); + + g_free(tb->id); + g_free(tb->path); + g_free(tb->cancel_path); + g_free(tpm_pt->tpm_dev); +} + +static const TPMDriverOps tpm_passthrough_driver = { + .type = TPM_TYPE_PASSTHROUGH, + .desc = tpm_passthrough_create_desc, + .create = tpm_passthrough_create, + .destroy = tpm_passthrough_destroy, + .init = tpm_passthrough_init, + .startup_tpm = tpm_passthrough_startup_tpm, + .realloc_buffer = tpm_passthrough_realloc_buffer, + .reset = tpm_passthrough_reset, + .had_startup_error = tpm_passthrough_get_startup_error, + .deliver_request = tpm_passthrough_deliver_request, + .cancel_cmd = tpm_passthrough_cancel_cmd, + .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, +}; + +static void tpm_passthrough_inst_init(Object *obj) +{ +} + +static void tpm_passthrough_inst_finalize(Object *obj) +{ +} + +static void tpm_passthrough_class_init(ObjectClass *klass, void *data) +{ + TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass); + + tbc->ops = &tpm_passthrough_driver; +} + +static const TypeInfo tpm_passthrough_info = { + .name = TYPE_TPM_PASSTHROUGH, + .parent = TYPE_TPM_BACKEND, + .instance_size = sizeof(TPMPassthruState), + .class_init = tpm_passthrough_class_init, + .instance_init = tpm_passthrough_inst_init, + .instance_finalize = tpm_passthrough_inst_finalize, +}; + +static void tpm_passthrough_register(void) +{ + type_register_static(&tpm_passthrough_info); + tpm_register_driver(&tpm_passthrough_driver); +} + +type_init(tpm_passthrough_register) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c new file mode 100644 index 0000000000..faa3cecafe --- /dev/null +++ b/hw/tpm/tpm_tis.c @@ -0,0 +1,930 @@ +/* + * tpm_tis.c - QEMU's TPM TIS interface emulator + * + * Copyright (C) 2006,2010-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * David Safford + * + * Xen 4 support: Andrease Niederl + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * Implementation of the TIS interface according to specs found at + * http://www.trustedcomputinggroup.org. This implementation currently + * supports version 1.21, revision 1.0. + * In the developers menu choose the PC Client section then find the TIS + * specification. + */ + +#include "backends/tpm.h" +#include "tpm_int.h" +#include "block/block.h" +#include "exec/address-spaces.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/pci/pci_ids.h" +#include "tpm_tis.h" +#include "qemu-common.h" + +/*#define DEBUG_TIS */ + +#ifdef DEBUG_TIS +#define DPRINTF(fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) \ + do { } while (0) +#endif + +/* whether the STS interrupt is supported */ +#define RAISE_STS_IRQ + +/* tis registers */ +#define TPM_TIS_REG_ACCESS 0x00 +#define TPM_TIS_REG_INT_ENABLE 0x08 +#define TPM_TIS_REG_INT_VECTOR 0x0c +#define TPM_TIS_REG_INT_STATUS 0x10 +#define TPM_TIS_REG_INTF_CAPABILITY 0x14 +#define TPM_TIS_REG_STS 0x18 +#define TPM_TIS_REG_DATA_FIFO 0x24 +#define TPM_TIS_REG_DID_VID 0xf00 +#define TPM_TIS_REG_RID 0xf04 + +/* vendor-specific registers */ +#define TPM_TIS_REG_DEBUG 0xf90 + +#define TPM_TIS_STS_VALID (1 << 7) +#define TPM_TIS_STS_COMMAND_READY (1 << 6) +#define TPM_TIS_STS_TPM_GO (1 << 5) +#define TPM_TIS_STS_DATA_AVAILABLE (1 << 4) +#define TPM_TIS_STS_EXPECT (1 << 3) +#define TPM_TIS_STS_RESPONSE_RETRY (1 << 1) + +#define TPM_TIS_BURST_COUNT_SHIFT 8 +#define TPM_TIS_BURST_COUNT(X) \ + ((X) << TPM_TIS_BURST_COUNT_SHIFT) + +#define TPM_TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) +#define TPM_TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) +#define TPM_TIS_ACCESS_BEEN_SEIZED (1 << 4) +#define TPM_TIS_ACCESS_SEIZE (1 << 3) +#define TPM_TIS_ACCESS_PENDING_REQUEST (1 << 2) +#define TPM_TIS_ACCESS_REQUEST_USE (1 << 1) +#define TPM_TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) + +#define TPM_TIS_INT_ENABLED (1 << 31) +#define TPM_TIS_INT_DATA_AVAILABLE (1 << 0) +#define TPM_TIS_INT_STS_VALID (1 << 1) +#define TPM_TIS_INT_LOCALITY_CHANGED (1 << 2) +#define TPM_TIS_INT_COMMAND_READY (1 << 7) + +#define TPM_TIS_INT_POLARITY_MASK (3 << 3) +#define TPM_TIS_INT_POLARITY_LOW_LEVEL (1 << 3) + +#ifndef RAISE_STS_IRQ + +#define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ + TPM_TIS_INT_DATA_AVAILABLE | \ + TPM_TIS_INT_COMMAND_READY) + +#else + +#define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ + TPM_TIS_INT_DATA_AVAILABLE | \ + TPM_TIS_INT_STS_VALID | \ + TPM_TIS_INT_COMMAND_READY) + +#endif + +#define TPM_TIS_CAP_INTERRUPT_LOW_LEVEL (1 << 4) /* support is mandatory */ +#define TPM_TIS_CAPABILITIES_SUPPORTED (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \ + TPM_TIS_INTERRUPTS_SUPPORTED) + +#define TPM_TIS_TPM_DID 0x0001 +#define TPM_TIS_TPM_VID PCI_VENDOR_ID_IBM +#define TPM_TIS_TPM_RID 0x0001 + +#define TPM_TIS_NO_DATA_BYTE 0xff + +/* local prototypes */ + +static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, + unsigned size); + +/* utility functions */ + +static uint8_t tpm_tis_locality_from_addr(hwaddr addr) +{ + return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); +} + +static uint32_t tpm_tis_get_size_from_buffer(const TPMSizedBuffer *sb) +{ + return be32_to_cpu(*(uint32_t *)&sb->buffer[2]); +} + +static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *string) +{ +#ifdef DEBUG_TIS + uint32_t len, i; + + len = tpm_tis_get_size_from_buffer(sb); + DPRINTF("tpm_tis: %s length = %d\n", string, len); + for (i = 0; i < len; i++) { + if (i && !(i % 16)) { + DPRINTF("\n"); + } + DPRINTF("%.2X ", sb->buffer[i]); + } + DPRINTF("\n"); +#endif +} + +/* + * Send a request to the TPM. + */ +static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) +{ + TPMTISEmuState *tis = &s->s.tis; + + tpm_tis_show_buffer(&tis->loc[locty].w_buffer, "tpm_tis: To TPM"); + + s->locty_number = locty; + s->locty_data = &tis->loc[locty]; + + /* + * w_offset serves as length indicator for length of data; + * it's reset when the response comes back + */ + tis->loc[locty].state = TPM_TIS_STATE_EXECUTION; + + tpm_backend_deliver_request(s->be_driver); +} + +/* raise an interrupt if allowed */ +static void tpm_tis_raise_irq(TPMState *s, uint8_t locty, uint32_t irqmask) +{ + TPMTISEmuState *tis = &s->s.tis; + + if (!TPM_TIS_IS_VALID_LOCTY(locty)) { + return; + } + + if ((tis->loc[locty].inte & TPM_TIS_INT_ENABLED) && + (tis->loc[locty].inte & irqmask)) { + DPRINTF("tpm_tis: Raising IRQ for flag %08x\n", irqmask); + qemu_irq_raise(s->s.tis.irq); + tis->loc[locty].ints |= irqmask; + } +} + +static uint32_t tpm_tis_check_request_use_except(TPMState *s, uint8_t locty) +{ + uint8_t l; + + for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) { + if (l == locty) { + continue; + } + if ((s->s.tis.loc[l].access & TPM_TIS_ACCESS_REQUEST_USE)) { + return 1; + } + } + + return 0; +} + +static void tpm_tis_new_active_locality(TPMState *s, uint8_t new_active_locty) +{ + TPMTISEmuState *tis = &s->s.tis; + bool change = (s->s.tis.active_locty != new_active_locty); + bool is_seize; + uint8_t mask; + + if (change && TPM_TIS_IS_VALID_LOCTY(s->s.tis.active_locty)) { + is_seize = TPM_TIS_IS_VALID_LOCTY(new_active_locty) && + tis->loc[new_active_locty].access & TPM_TIS_ACCESS_SEIZE; + + if (is_seize) { + mask = ~(TPM_TIS_ACCESS_ACTIVE_LOCALITY); + } else { + mask = ~(TPM_TIS_ACCESS_ACTIVE_LOCALITY| + TPM_TIS_ACCESS_REQUEST_USE); + } + /* reset flags on the old active locality */ + tis->loc[s->s.tis.active_locty].access &= mask; + + if (is_seize) { + tis->loc[tis->active_locty].access |= TPM_TIS_ACCESS_BEEN_SEIZED; + } + } + + tis->active_locty = new_active_locty; + + DPRINTF("tpm_tis: Active locality is now %d\n", s->s.tis.active_locty); + + if (TPM_TIS_IS_VALID_LOCTY(new_active_locty)) { + /* set flags on the new active locality */ + tis->loc[new_active_locty].access |= TPM_TIS_ACCESS_ACTIVE_LOCALITY; + tis->loc[new_active_locty].access &= ~(TPM_TIS_ACCESS_REQUEST_USE | + TPM_TIS_ACCESS_SEIZE); + } + + if (change) { + tpm_tis_raise_irq(s, tis->active_locty, TPM_TIS_INT_LOCALITY_CHANGED); + } +} + +/* abort -- this function switches the locality */ +static void tpm_tis_abort(TPMState *s, uint8_t locty) +{ + TPMTISEmuState *tis = &s->s.tis; + + tis->loc[locty].r_offset = 0; + tis->loc[locty].w_offset = 0; + + DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", tis->next_locty); + + /* + * Need to react differently depending on who's aborting now and + * which locality will become active afterwards. + */ + if (tis->aborting_locty == tis->next_locty) { + tis->loc[tis->aborting_locty].state = TPM_TIS_STATE_READY; + tis->loc[tis->aborting_locty].sts = TPM_TIS_STS_COMMAND_READY; + tpm_tis_raise_irq(s, tis->aborting_locty, TPM_TIS_INT_COMMAND_READY); + } + + /* locality after abort is another one than the current one */ + tpm_tis_new_active_locality(s, tis->next_locty); + + tis->next_locty = TPM_TIS_NO_LOCALITY; + /* nobody's aborting a command anymore */ + tis->aborting_locty = TPM_TIS_NO_LOCALITY; +} + +/* prepare aborting current command */ +static void tpm_tis_prep_abort(TPMState *s, uint8_t locty, uint8_t newlocty) +{ + TPMTISEmuState *tis = &s->s.tis; + uint8_t busy_locty; + + tis->aborting_locty = locty; + tis->next_locty = newlocty; /* locality after successful abort */ + + /* + * only abort a command using an interrupt if currently executing + * a command AND if there's a valid connection to the vTPM. + */ + for (busy_locty = 0; busy_locty < TPM_TIS_NUM_LOCALITIES; busy_locty++) { + if (tis->loc[busy_locty].state == TPM_TIS_STATE_EXECUTION) { + /* + * request the backend to cancel. Some backends may not + * support it + */ + tpm_backend_cancel_cmd(s->be_driver); + return; + } + } + + tpm_tis_abort(s, locty); +} + +static void tpm_tis_receive_bh(void *opaque) +{ + TPMState *s = opaque; + TPMTISEmuState *tis = &s->s.tis; + uint8_t locty = s->locty_number; + + tis->loc[locty].sts = TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE; + tis->loc[locty].state = TPM_TIS_STATE_COMPLETION; + tis->loc[locty].r_offset = 0; + tis->loc[locty].w_offset = 0; + + if (TPM_TIS_IS_VALID_LOCTY(tis->next_locty)) { + tpm_tis_abort(s, locty); + } + +#ifndef RAISE_STS_IRQ + tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE); +#else + tpm_tis_raise_irq(s, locty, + TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); +#endif +} + +/* + * Callback from the TPM to indicate that the response was received. + */ +static void tpm_tis_receive_cb(TPMState *s, uint8_t locty) +{ + TPMTISEmuState *tis = &s->s.tis; + + assert(s->locty_number == locty); + + qemu_bh_schedule(tis->bh); +} + +/* + * Read a byte of response data + */ +static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) +{ + TPMTISEmuState *tis = &s->s.tis; + uint32_t ret = TPM_TIS_NO_DATA_BYTE; + uint16_t len; + + if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { + len = tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); + + ret = tis->loc[locty].r_buffer.buffer[tis->loc[locty].r_offset++]; + if (tis->loc[locty].r_offset >= len) { + /* got last byte */ + tis->loc[locty].sts = TPM_TIS_STS_VALID; +#ifdef RAISE_STS_IRQ + tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); +#endif + } + DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", + ret, tis->loc[locty].r_offset-1); + } + + return ret; +} + +#ifdef DEBUG_TIS +static void tpm_tis_dump_state(void *opaque, hwaddr addr) +{ + static const unsigned regs[] = { + TPM_TIS_REG_ACCESS, + TPM_TIS_REG_INT_ENABLE, + TPM_TIS_REG_INT_VECTOR, + TPM_TIS_REG_INT_STATUS, + TPM_TIS_REG_INTF_CAPABILITY, + TPM_TIS_REG_STS, + TPM_TIS_REG_DID_VID, + TPM_TIS_REG_RID, + 0xfff}; + int idx; + uint8_t locty = tpm_tis_locality_from_addr(addr); + hwaddr base = addr & ~0xfff; + TPMState *s = opaque; + TPMTISEmuState *tis = &s->s.tis; + + DPRINTF("tpm_tis: active locality : %d\n" + "tpm_tis: state of locality %d : %d\n" + "tpm_tis: register dump:\n", + tis->active_locty, + locty, tis->loc[locty].state); + + for (idx = 0; regs[idx] != 0xfff; idx++) { + DPRINTF("tpm_tis: 0x%04x : 0x%08x\n", regs[idx], + (uint32_t)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); + } + + DPRINTF("tpm_tis: read offset : %d\n" + "tpm_tis: result buffer : ", + tis->loc[locty].r_offset); + for (idx = 0; + idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); + idx++) { + DPRINTF("%c%02x%s", + tis->loc[locty].r_offset == idx ? '>' : ' ', + tis->loc[locty].r_buffer.buffer[idx], + ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); + } + DPRINTF("\n" + "tpm_tis: write offset : %d\n" + "tpm_tis: request buffer: ", + tis->loc[locty].w_offset); + for (idx = 0; + idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].w_buffer); + idx++) { + DPRINTF("%c%02x%s", + tis->loc[locty].w_offset == idx ? '>' : ' ', + tis->loc[locty].w_buffer.buffer[idx], + ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); + } + DPRINTF("\n"); +} +#endif + +/* + * Read a register of the TIS interface + * See specs pages 33-63 for description of the registers + */ +static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + TPMState *s = opaque; + TPMTISEmuState *tis = &s->s.tis; + uint16_t offset = addr & 0xffc; + uint8_t shift = (addr & 0x3) * 8; + uint32_t val = 0xffffffff; + uint8_t locty = tpm_tis_locality_from_addr(addr); + uint32_t avail; + + if (tpm_backend_had_startup_error(s->be_driver)) { + return val; + } + + switch (offset) { + case TPM_TIS_REG_ACCESS: + /* never show the SEIZE flag even though we use it internally */ + val = tis->loc[locty].access & ~TPM_TIS_ACCESS_SEIZE; + /* the pending flag is always calculated */ + if (tpm_tis_check_request_use_except(s, locty)) { + val |= TPM_TIS_ACCESS_PENDING_REQUEST; + } + val |= !tpm_backend_get_tpm_established_flag(s->be_driver); + break; + case TPM_TIS_REG_INT_ENABLE: + val = tis->loc[locty].inte; + break; + case TPM_TIS_REG_INT_VECTOR: + val = tis->irq_num; + break; + case TPM_TIS_REG_INT_STATUS: + val = tis->loc[locty].ints; + break; + case TPM_TIS_REG_INTF_CAPABILITY: + val = TPM_TIS_CAPABILITIES_SUPPORTED; + break; + case TPM_TIS_REG_STS: + if (tis->active_locty == locty) { + if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { + val = TPM_TIS_BURST_COUNT( + tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer) + - tis->loc[locty].r_offset) | tis->loc[locty].sts; + } else { + avail = tis->loc[locty].w_buffer.size + - tis->loc[locty].w_offset; + /* + * byte-sized reads should not return 0x00 for 0x100 + * available bytes. + */ + if (size == 1 && avail > 0xff) { + avail = 0xff; + } + val = TPM_TIS_BURST_COUNT(avail) | tis->loc[locty].sts; + } + } + break; + case TPM_TIS_REG_DATA_FIFO: + if (tis->active_locty == locty) { + switch (tis->loc[locty].state) { + case TPM_TIS_STATE_COMPLETION: + val = tpm_tis_data_read(s, locty); + break; + default: + val = TPM_TIS_NO_DATA_BYTE; + break; + } + } + break; + case TPM_TIS_REG_DID_VID: + val = (TPM_TIS_TPM_DID << 16) | TPM_TIS_TPM_VID; + break; + case TPM_TIS_REG_RID: + val = TPM_TIS_TPM_RID; + break; +#ifdef DEBUG_TIS + case TPM_TIS_REG_DEBUG: + tpm_tis_dump_state(opaque, addr); + break; +#endif + } + + if (shift) { + val >>= shift; + } + + DPRINTF("tpm_tis: read.%u(%08x) = %08x\n", size, (int)addr, (uint32_t)val); + + return val; +} + +/* + * Write a value to a register of the TIS interface + * See specs pages 33-63 for description of the registers + */ +static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr, + uint64_t val, unsigned size, + bool hw_access) +{ + TPMState *s = opaque; + TPMTISEmuState *tis = &s->s.tis; + uint16_t off = addr & 0xfff; + uint8_t locty = tpm_tis_locality_from_addr(addr); + uint8_t active_locty, l; + int c, set_new_locty = 1; + uint16_t len; + + DPRINTF("tpm_tis: write.%u(%08x) = %08x\n", size, (int)addr, (uint32_t)val); + + if (locty == 4 && !hw_access) { + DPRINTF("tpm_tis: Access to locality 4 only allowed from hardware\n"); + return; + } + + if (tpm_backend_had_startup_error(s->be_driver)) { + return; + } + + switch (off) { + case TPM_TIS_REG_ACCESS: + + if ((val & TPM_TIS_ACCESS_SEIZE)) { + val &= ~(TPM_TIS_ACCESS_REQUEST_USE | + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + } + + active_locty = tis->active_locty; + + if ((val & TPM_TIS_ACCESS_ACTIVE_LOCALITY)) { + /* give up locality if currently owned */ + if (tis->active_locty == locty) { + DPRINTF("tpm_tis: Releasing locality %d\n", locty); + + uint8_t newlocty = TPM_TIS_NO_LOCALITY; + /* anybody wants the locality ? */ + for (c = TPM_TIS_NUM_LOCALITIES - 1; c >= 0; c--) { + if ((tis->loc[c].access & TPM_TIS_ACCESS_REQUEST_USE)) { + DPRINTF("tpm_tis: Locality %d requests use.\n", c); + newlocty = c; + break; + } + } + DPRINTF("tpm_tis: TPM_TIS_ACCESS_ACTIVE_LOCALITY: " + "Next active locality: %d\n", + newlocty); + + if (TPM_TIS_IS_VALID_LOCTY(newlocty)) { + set_new_locty = 0; + tpm_tis_prep_abort(s, locty, newlocty); + } else { + active_locty = TPM_TIS_NO_LOCALITY; + } + } else { + /* not currently the owner; clear a pending request */ + tis->loc[locty].access &= ~TPM_TIS_ACCESS_REQUEST_USE; + } + } + + if ((val & TPM_TIS_ACCESS_BEEN_SEIZED)) { + tis->loc[locty].access &= ~TPM_TIS_ACCESS_BEEN_SEIZED; + } + + if ((val & TPM_TIS_ACCESS_SEIZE)) { + /* + * allow seize if a locality is active and the requesting + * locality is higher than the one that's active + * OR + * allow seize for requesting locality if no locality is + * active + */ + while ((TPM_TIS_IS_VALID_LOCTY(tis->active_locty) && + locty > tis->active_locty) || + !TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { + bool higher_seize = FALSE; + + /* already a pending SEIZE ? */ + if ((tis->loc[locty].access & TPM_TIS_ACCESS_SEIZE)) { + break; + } + + /* check for ongoing seize by a higher locality */ + for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES; l++) { + if ((tis->loc[l].access & TPM_TIS_ACCESS_SEIZE)) { + higher_seize = TRUE; + break; + } + } + + if (higher_seize) { + break; + } + + /* cancel any seize by a lower locality */ + for (l = 0; l < locty - 1; l++) { + tis->loc[l].access &= ~TPM_TIS_ACCESS_SEIZE; + } + + tis->loc[locty].access |= TPM_TIS_ACCESS_SEIZE; + DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: " + "Locality %d seized from locality %d\n", + locty, tis->active_locty); + DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: Initiating abort.\n"); + set_new_locty = 0; + tpm_tis_prep_abort(s, tis->active_locty, locty); + break; + } + } + + if ((val & TPM_TIS_ACCESS_REQUEST_USE)) { + if (tis->active_locty != locty) { + if (TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { + tis->loc[locty].access |= TPM_TIS_ACCESS_REQUEST_USE; + } else { + /* no locality active -> make this one active now */ + active_locty = locty; + } + } + } + + if (set_new_locty) { + tpm_tis_new_active_locality(s, active_locty); + } + + break; + case TPM_TIS_REG_INT_ENABLE: + if (tis->active_locty != locty) { + break; + } + + tis->loc[locty].inte = (val & (TPM_TIS_INT_ENABLED | + TPM_TIS_INT_POLARITY_MASK | + TPM_TIS_INTERRUPTS_SUPPORTED)); + break; + case TPM_TIS_REG_INT_VECTOR: + /* hard wired -- ignore */ + break; + case TPM_TIS_REG_INT_STATUS: + if (tis->active_locty != locty) { + break; + } + + /* clearing of interrupt flags */ + if (((val & TPM_TIS_INTERRUPTS_SUPPORTED)) && + (tis->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) { + tis->loc[locty].ints &= ~val; + if (tis->loc[locty].ints == 0) { + qemu_irq_lower(tis->irq); + DPRINTF("tpm_tis: Lowering IRQ\n"); + } + } + tis->loc[locty].ints &= ~(val & TPM_TIS_INTERRUPTS_SUPPORTED); + break; + case TPM_TIS_REG_STS: + if (tis->active_locty != locty) { + break; + } + + val &= (TPM_TIS_STS_COMMAND_READY | TPM_TIS_STS_TPM_GO | + TPM_TIS_STS_RESPONSE_RETRY); + + if (val == TPM_TIS_STS_COMMAND_READY) { + switch (tis->loc[locty].state) { + + case TPM_TIS_STATE_READY: + tis->loc[locty].w_offset = 0; + tis->loc[locty].r_offset = 0; + break; + + case TPM_TIS_STATE_IDLE: + tis->loc[locty].sts = TPM_TIS_STS_COMMAND_READY; + tis->loc[locty].state = TPM_TIS_STATE_READY; + tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); + break; + + case TPM_TIS_STATE_EXECUTION: + case TPM_TIS_STATE_RECEPTION: + /* abort currently running command */ + DPRINTF("tpm_tis: %s: Initiating abort.\n", + __func__); + tpm_tis_prep_abort(s, locty, locty); + break; + + case TPM_TIS_STATE_COMPLETION: + tis->loc[locty].w_offset = 0; + tis->loc[locty].r_offset = 0; + /* shortcut to ready state with C/R set */ + tis->loc[locty].state = TPM_TIS_STATE_READY; + if (!(tis->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { + tis->loc[locty].sts = TPM_TIS_STS_COMMAND_READY; + tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); + } + tis->loc[locty].sts &= ~(TPM_TIS_STS_DATA_AVAILABLE); + break; + + } + } else if (val == TPM_TIS_STS_TPM_GO) { + switch (tis->loc[locty].state) { + case TPM_TIS_STATE_RECEPTION: + if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) == 0) { + tpm_tis_tpm_send(s, locty); + } + break; + default: + /* ignore */ + break; + } + } else if (val == TPM_TIS_STS_RESPONSE_RETRY) { + switch (tis->loc[locty].state) { + case TPM_TIS_STATE_COMPLETION: + tis->loc[locty].r_offset = 0; + tis->loc[locty].sts = TPM_TIS_STS_VALID | + TPM_TIS_STS_DATA_AVAILABLE; + break; + default: + /* ignore */ + break; + } + } + break; + case TPM_TIS_REG_DATA_FIFO: + /* data fifo */ + if (tis->active_locty != locty) { + break; + } + + if (tis->loc[locty].state == TPM_TIS_STATE_IDLE || + tis->loc[locty].state == TPM_TIS_STATE_EXECUTION || + tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) { + /* drop the byte */ + } else { + DPRINTF("tpm_tis: Byte to send to TPM: %02x\n", (uint8_t)val); + if (tis->loc[locty].state == TPM_TIS_STATE_READY) { + tis->loc[locty].state = TPM_TIS_STATE_RECEPTION; + tis->loc[locty].sts = TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID; + } + + if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { + if (tis->loc[locty].w_offset < tis->loc[locty].w_buffer.size) { + tis->loc[locty].w_buffer. + buffer[tis->loc[locty].w_offset++] = (uint8_t)val; + } else { + tis->loc[locty].sts = TPM_TIS_STS_VALID; + } + } + + /* check for complete packet */ + if (tis->loc[locty].w_offset > 5 && + (tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { + /* we have a packet length - see if we have all of it */ +#ifdef RAISE_STS_IRQ + bool needIrq = !(tis->loc[locty].sts & TPM_TIS_STS_VALID); +#endif + len = tpm_tis_get_size_from_buffer(&tis->loc[locty].w_buffer); + if (len > tis->loc[locty].w_offset) { + tis->loc[locty].sts = TPM_TIS_STS_EXPECT | + TPM_TIS_STS_VALID; + } else { + /* packet complete */ + tis->loc[locty].sts = TPM_TIS_STS_VALID; + } +#ifdef RAISE_STS_IRQ + if (needIrq) { + tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); + } +#endif + } + } + break; + } +} + +static void tpm_tis_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + return tpm_tis_mmio_write_intern(opaque, addr, val, size, false); +} + +static const MemoryRegionOps tpm_tis_memory_ops = { + .read = tpm_tis_mmio_read, + .write = tpm_tis_mmio_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 4, + }, +}; + +static int tpm_tis_do_startup_tpm(TPMState *s) +{ + return tpm_backend_startup_tpm(s->be_driver); +} + +/* + * This function is called when the machine starts, resets or due to + * S3 resume. + */ +static void tpm_tis_reset(DeviceState *dev) +{ + TPMState *s = TPM(dev); + TPMTISEmuState *tis = &s->s.tis; + int c; + + tpm_backend_reset(s->be_driver); + + tis->active_locty = TPM_TIS_NO_LOCALITY; + tis->next_locty = TPM_TIS_NO_LOCALITY; + tis->aborting_locty = TPM_TIS_NO_LOCALITY; + + for (c = 0; c < TPM_TIS_NUM_LOCALITIES; c++) { + tis->loc[c].access = TPM_TIS_ACCESS_TPM_REG_VALID_STS; + tis->loc[c].sts = 0; + tis->loc[c].inte = TPM_TIS_INT_POLARITY_LOW_LEVEL; + tis->loc[c].ints = 0; + tis->loc[c].state = TPM_TIS_STATE_IDLE; + + tis->loc[c].w_offset = 0; + tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].w_buffer); + tis->loc[c].r_offset = 0; + tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].r_buffer); + } + + tpm_tis_do_startup_tpm(s); +} + +static const VMStateDescription vmstate_tpm_tis = { + .name = "tpm", + .unmigratable = 1, +}; + +static Property tpm_tis_properties[] = { + DEFINE_PROP_UINT32("irq", TPMState, + s.tis.irq_num, TPM_TIS_IRQ), + DEFINE_PROP_STRING("tpmdev", TPMState, backend), + DEFINE_PROP_END_OF_LIST(), +}; + +static void tpm_tis_realizefn(DeviceState *dev, Error **errp) +{ + TPMState *s = TPM(dev); + TPMTISEmuState *tis = &s->s.tis; + + s->be_driver = qemu_find_tpm(s->backend); + if (!s->be_driver) { + error_setg(errp, "tpm_tis: backend driver with id %s could not be " + "found", s->backend); + return; + } + + s->be_driver->fe_model = TPM_MODEL_TPM_TIS; + + if (tpm_backend_init(s->be_driver, s, tpm_tis_receive_cb)) { + error_setg(errp, "tpm_tis: backend driver with id %s could not be " + "initialized", s->backend); + return; + } + + if (tis->irq_num > 15) { + error_setg(errp, "tpm_tis: IRQ %d for TPM TIS is outside valid range " + "of 0 to 15.\n", tis->irq_num); + return; + } + + tis->bh = qemu_bh_new(tpm_tis_receive_bh, s); + + isa_init_irq(&s->busdev, &tis->irq, tis->irq_num); +} + +static void tpm_tis_initfn(Object *obj) +{ + ISADevice *dev = ISA_DEVICE(obj); + TPMState *s = TPM(obj); + + memory_region_init_io(&s->mmio, &tpm_tis_memory_ops, s, "tpm-tis-mmio", + TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); + memory_region_add_subregion(isa_address_space(dev), TPM_TIS_ADDR_BASE, + &s->mmio); +} + +static void tpm_tis_uninitfn(Object *obj) +{ + TPMState *s = TPM(obj); + + memory_region_del_subregion(get_system_memory(), &s->mmio); + memory_region_destroy(&s->mmio); +} + +static void tpm_tis_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = tpm_tis_realizefn; + dc->props = tpm_tis_properties; + dc->reset = tpm_tis_reset; + dc->vmsd = &vmstate_tpm_tis; +} + +static const TypeInfo tpm_tis_info = { + .name = TYPE_TPM_TIS, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(TPMState), + .instance_init = tpm_tis_initfn, + .instance_finalize = tpm_tis_uninitfn, + .class_init = tpm_tis_class_init, +}; + +static void tpm_tis_register(void) +{ + type_register_static(&tpm_tis_info); + tpm_register_model(TPM_MODEL_TPM_TIS); +} + +type_init(tpm_tis_register) diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h new file mode 100644 index 0000000000..916152ae3e --- /dev/null +++ b/hw/tpm/tpm_tis.h @@ -0,0 +1,75 @@ +/* + * tpm_tis.h - QEMU's TPM TIS interface emulator + * + * Copyright (C) 2006, 2010-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * David Safford + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * Implementation of the TIS interface according to specs found at + * http://www.trustedcomputinggroup.org + * + */ +#ifndef TPM_TPM_TIS_H +#define TPM_TPM_TIS_H + +#include "hw/isa/isa.h" +#include "qemu-common.h" + +#define TPM_TIS_ADDR_BASE 0xFED40000 + +#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ +#define TPM_TIS_LOCALITY_SHIFT 12 +#define TPM_TIS_NO_LOCALITY 0xff + +#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) + +#define TPM_TIS_IRQ 5 + +#define TPM_TIS_BUFFER_MAX 4096 + +#define TYPE_TPM_TIS "tpm-tis" + + +typedef enum { + TPM_TIS_STATE_IDLE = 0, + TPM_TIS_STATE_READY, + TPM_TIS_STATE_COMPLETION, + TPM_TIS_STATE_EXECUTION, + TPM_TIS_STATE_RECEPTION, +} TPMTISState; + +/* locality data -- all fields are persisted */ +typedef struct TPMLocality { + TPMTISState state; + uint8_t access; + uint8_t sts; + uint32_t inte; + uint32_t ints; + + uint16_t w_offset; + uint16_t r_offset; + TPMSizedBuffer w_buffer; + TPMSizedBuffer r_buffer; +} TPMLocality; + +typedef struct TPMTISEmuState { + QEMUBH *bh; + uint32_t offset; + uint8_t buf[TPM_TIS_BUFFER_MAX]; + + uint8_t active_locty; + uint8_t aborting_locty; + uint8_t next_locty; + + TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; + + qemu_irq irq; + uint32_t irq_num; +} TPMTISEmuState; + +#endif /* TPM_TPM_TIS_H */ diff --git a/include/backends/tpm.h b/include/backends/tpm.h index 9e93cc5060..466787453d 100644 --- a/include/backends/tpm.h +++ b/include/backends/tpm.h @@ -18,7 +18,7 @@ #include "qapi/error.h" #include "qapi-types.h" #include "qemu/option.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #define TYPE_TPM_BACKEND "tpm-backend" #define TPM_BACKEND(obj) \ @@ -56,6 +56,39 @@ struct TPMBackend { QLIST_ENTRY(TPMBackend) list; }; +typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); + +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +struct TPMDriverOps { + enum TpmType type; + /* get a descriptive text of the backend to display to the user */ + const char *(*desc)(void); + + TPMBackend *(*create)(QemuOpts *opts, const char *id); + void (*destroy)(TPMBackend *t); + + /* initialize the backend */ + int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb); + /* start up the TPM on the backend */ + int (*startup_tpm)(TPMBackend *t); + /* returns true if nothing will ever answer TPM requests */ + bool (*had_startup_error)(TPMBackend *t); + + size_t (*realloc_buffer)(TPMSizedBuffer *sb); + + void (*deliver_request)(TPMBackend *t); + + void (*reset)(TPMBackend *t); + + void (*cancel_cmd)(TPMBackend *t); + + bool (*get_tpm_established_flag)(TPMBackend *t); +}; + /** * tpm_backend_get_type: @@ -167,4 +200,10 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s); */ void tpm_backend_open(TPMBackend *s, Error **errp); +TPMBackend *qemu_find_tpm(const char *id); + +const TPMDriverOps *tpm_get_backend_driver(const char *type); +int tpm_register_model(enum TpmModel model); +int tpm_register_driver(const TPMDriverOps *tdo); + #endif diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h new file mode 100644 index 0000000000..13febddbee --- /dev/null +++ b/include/sysemu/tpm.h @@ -0,0 +1,23 @@ +/* + * Public TPM functions + * + * Copyright (C) 2011-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef QEMU_TPM_H +#define QEMU_TPM_H + +#include "qemu/option.h" + +typedef struct TPMState TPMState; + +int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); +int tpm_init(void); +void tpm_cleanup(void); + +#endif /* QEMU_TPM_H */ diff --git a/include/sysemu/tpm_backend_int.h b/include/sysemu/tpm_backend_int.h new file mode 100644 index 0000000000..05d94d0f5b --- /dev/null +++ b/include/sysemu/tpm_backend_int.h @@ -0,0 +1,45 @@ +/* + * common TPM backend driver functions + * + * Copyright (c) 2012-2013 IBM Corporation + * Authors: + * Stefan Berger + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef TPM_TPM_BACKEND_H +#define TPM_TPM_BACKEND_H + +#include + +typedef struct TPMBackendThread { + GThreadPool *pool; +} TPMBackendThread; + +void tpm_backend_thread_deliver_request(TPMBackendThread *tbt); +void tpm_backend_thread_create(TPMBackendThread *tbt, + GFunc func, gpointer user_data); +void tpm_backend_thread_end(TPMBackendThread *tbt); +void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, + GFunc func, gpointer user_data); + +typedef enum TPMBackendCmd { + TPM_BACKEND_CMD_INIT = 1, + TPM_BACKEND_CMD_PROCESS_CMD, + TPM_BACKEND_CMD_END, + TPM_BACKEND_CMD_TPM_RESET, +} TPMBackendCmd; + +#endif /* TPM_TPM_BACKEND_H */ diff --git a/include/tpm/tpm.h b/include/tpm/tpm.h deleted file mode 100644 index 2d457c4439..0000000000 --- a/include/tpm/tpm.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Public TPM functions - * - * Copyright (C) 2011-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#ifndef QEMU_TPM_H -#define QEMU_TPM_H - -#include "qemu/option.h" - -typedef struct TPMState TPMState; -typedef struct TPMSizedBuffer TPMSizedBuffer; -typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); - -int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); -int tpm_init(void); -void tpm_cleanup(void); - -#endif /* QEMU_TPM_H */ diff --git a/monitor.c b/monitor.c index c897e8033f..e605822445 100644 --- a/monitor.c +++ b/monitor.c @@ -47,7 +47,7 @@ #include "migration/migration.h" #include "sysemu/kvm.h" #include "qemu/acl.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qfloat.h" #include "qapi/qmp/qlist.h" diff --git a/tpm.c b/tpm.c new file mode 100644 index 0000000000..1e943148d2 --- /dev/null +++ b/tpm.c @@ -0,0 +1,350 @@ +/* + * TPM configuration + * + * Copyright (C) 2011-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * Based on net.c + */ +#include "config-host.h" + +#include "monitor/monitor.h" +#include "qapi/qmp/qerror.h" +#include "backends/tpm.h" +#include "sysemu/tpm.h" +#include "qemu/config-file.h" +#include "qmp-commands.h" + +static QLIST_HEAD(, TPMBackend) tpm_backends = + QLIST_HEAD_INITIALIZER(tpm_backends); + + +#define TPM_MAX_MODELS 1 +#define TPM_MAX_DRIVERS 1 + +static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = { + NULL, +}; + +static enum TpmModel tpm_models[TPM_MAX_MODELS] = { + -1, +}; + +int tpm_register_model(enum TpmModel model) +{ + int i; + + for (i = 0; i < TPM_MAX_MODELS; i++) { + if (tpm_models[i] == -1) { + tpm_models[i] = model; + return 0; + } + } + error_report("Could not register TPM model"); + return 1; +} + +static bool tpm_model_is_registered(enum TpmModel model) +{ + int i; + + for (i = 0; i < TPM_MAX_MODELS; i++) { + if (tpm_models[i] == model) { + return true; + } + } + return false; +} + +const TPMDriverOps *tpm_get_backend_driver(const char *type) +{ + int i; + + for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { + if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) { + return be_drivers[i]; + } + } + + return NULL; +} + +#ifdef CONFIG_TPM + +int tpm_register_driver(const TPMDriverOps *tdo) +{ + int i; + + for (i = 0; i < TPM_MAX_DRIVERS; i++) { + if (!be_drivers[i]) { + be_drivers[i] = tdo; + return 0; + } + } + error_report("Could not register TPM driver"); + return 1; +} + +/* + * Walk the list of available TPM backend drivers and display them on the + * screen. + */ +static void tpm_display_backend_drivers(void) +{ + int i; + + fprintf(stderr, "Supported TPM types (choose only one):\n"); + + for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { + fprintf(stderr, "%12s %s\n", + TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc()); + } + fprintf(stderr, "\n"); +} + +/* + * Find the TPM with the given Id + */ +TPMBackend *qemu_find_tpm(const char *id) +{ + TPMBackend *drv; + + if (id) { + QLIST_FOREACH(drv, &tpm_backends, list) { + if (!strcmp(drv->id, id)) { + return drv; + } + } + } + + return NULL; +} + +static int configure_tpm(QemuOpts *opts) +{ + const char *value; + const char *id; + const TPMDriverOps *be; + TPMBackend *drv; + Error *local_err = NULL; + + if (!QLIST_EMPTY(&tpm_backends)) { + error_report("Only one TPM is allowed.\n"); + return 1; + } + + id = qemu_opts_id(opts); + if (id == NULL) { + qerror_report(QERR_MISSING_PARAMETER, "id"); + return 1; + } + + value = qemu_opt_get(opts, "type"); + if (!value) { + qerror_report(QERR_MISSING_PARAMETER, "type"); + tpm_display_backend_drivers(); + return 1; + } + + be = tpm_get_backend_driver(value); + if (be == NULL) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", + "a TPM backend type"); + tpm_display_backend_drivers(); + return 1; + } + + drv = be->create(opts, id); + if (!drv) { + return 1; + } + + tpm_backend_open(drv, &local_err); + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return 1; + } + + QLIST_INSERT_HEAD(&tpm_backends, drv, list); + + return 0; +} + +static int tpm_init_tpmdev(QemuOpts *opts, void *dummy) +{ + return configure_tpm(opts); +} + +/* + * Walk the list of TPM backend drivers that are in use and call their + * destroy function to have them cleaned up. + */ +void tpm_cleanup(void) +{ + TPMBackend *drv, *next; + + QLIST_FOREACH_SAFE(drv, &tpm_backends, list, next) { + QLIST_REMOVE(drv, list); + tpm_backend_destroy(drv); + } +} + +/* + * Initialize the TPM. Process the tpmdev command line options describing the + * TPM backend. + */ +int tpm_init(void) +{ + if (qemu_opts_foreach(qemu_find_opts("tpmdev"), + tpm_init_tpmdev, NULL, 1) != 0) { + return -1; + } + + atexit(tpm_cleanup); + + return 0; +} + +/* + * Parse the TPM configuration options. + * To display all available TPM backends the user may use '-tpmdev help' + */ +int tpm_config_parse(QemuOptsList *opts_list, const char *optarg) +{ + QemuOpts *opts; + + if (!strcmp(optarg, "help")) { + tpm_display_backend_drivers(); + return -1; + } + opts = qemu_opts_parse(opts_list, optarg, 1); + if (!opts) { + return -1; + } + return 0; +} + +#endif /* CONFIG_TPM */ + +static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) +{ + int i; + + for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { + if (be_drivers[i]->type == type) { + return be_drivers[i]; + } + } + return NULL; +} + +static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) +{ + TPMInfo *res = g_new0(TPMInfo, 1); + TPMPassthroughOptions *tpo; + + res->id = g_strdup(drv->id); + res->model = drv->fe_model; + res->options = g_new0(TpmTypeOptions, 1); + + switch (drv->ops->type) { + case TPM_TYPE_PASSTHROUGH: + res->options->kind = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; + tpo = g_new0(TPMPassthroughOptions, 1); + res->options->passthrough = tpo; + if (drv->path) { + tpo->path = g_strdup(drv->path); + tpo->has_path = true; + } + if (drv->cancel_path) { + tpo->cancel_path = g_strdup(drv->cancel_path); + tpo->has_cancel_path = true; + } + break; + case TPM_TYPE_MAX: + break; + } + + return res; +} + +/* + * Walk the list of active TPM backends and collect information about them + * following the schema description in qapi-schema.json. + */ +TPMInfoList *qmp_query_tpm(Error **errp) +{ + TPMBackend *drv; + TPMInfoList *info, *head = NULL, *cur_item = NULL; + + QLIST_FOREACH(drv, &tpm_backends, list) { + if (!tpm_model_is_registered(drv->fe_model)) { + continue; + } + info = g_new0(TPMInfoList, 1); + info->value = qmp_query_tpm_inst(drv); + + if (!cur_item) { + head = cur_item = info; + } else { + cur_item->next = info; + cur_item = info; + } + } + + return head; +} + +TpmTypeList *qmp_query_tpm_types(Error **errp) +{ + unsigned int i = 0; + TpmTypeList *head = NULL, *prev = NULL, *cur_item; + + for (i = 0; i < TPM_TYPE_MAX; i++) { + if (!tpm_driver_find_by_type(i)) { + continue; + } + cur_item = g_new0(TpmTypeList, 1); + cur_item->value = i; + + if (prev) { + prev->next = cur_item; + } + if (!head) { + head = cur_item; + } + prev = cur_item; + } + + return head; +} + +TpmModelList *qmp_query_tpm_models(Error **errp) +{ + unsigned int i = 0; + TpmModelList *head = NULL, *prev = NULL, *cur_item; + + for (i = 0; i < TPM_MODEL_MAX; i++) { + if (!tpm_model_is_registered(i)) { + continue; + } + cur_item = g_new0(TpmModelList, 1); + cur_item->value = i; + + if (prev) { + prev->next = cur_item; + } + if (!head) { + head = cur_item; + } + prev = cur_item; + } + + return head; +} diff --git a/tpm/Makefile.objs b/tpm/Makefile.objs deleted file mode 100644 index 366e4a7128..0000000000 --- a/tpm/Makefile.objs +++ /dev/null @@ -1,4 +0,0 @@ -common-obj-y = tpm.o -common-obj-$(CONFIG_TPM) += tpm_backend.o -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o -common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o diff --git a/tpm/tpm.c b/tpm/tpm.c deleted file mode 100644 index 1f4ac8da00..0000000000 --- a/tpm/tpm.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * TPM configuration - * - * Copyright (C) 2011-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - * - * Based on net.c - */ -#include "config-host.h" - -#include "monitor/monitor.h" -#include "qapi/qmp/qerror.h" -#include "backends/tpm.h" -#include "tpm_int.h" -#include "tpm/tpm.h" -#include "qemu/config-file.h" -#include "qmp-commands.h" - -static QLIST_HEAD(, TPMBackend) tpm_backends = - QLIST_HEAD_INITIALIZER(tpm_backends); - - -#define TPM_MAX_MODELS 1 -#define TPM_MAX_DRIVERS 1 - -static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = { - NULL, -}; - -static enum TpmModel tpm_models[TPM_MAX_MODELS] = { - -1, -}; - -int tpm_register_model(enum TpmModel model) -{ - int i; - - for (i = 0; i < TPM_MAX_MODELS; i++) { - if (tpm_models[i] == -1) { - tpm_models[i] = model; - return 0; - } - } - error_report("Could not register TPM model"); - return 1; -} - -static bool tpm_model_is_registered(enum TpmModel model) -{ - int i; - - for (i = 0; i < TPM_MAX_MODELS; i++) { - if (tpm_models[i] == model) { - return true; - } - } - return false; -} - -/* - * Write an error message in the given output buffer. - */ -void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) -{ - if (out_len >= sizeof(struct tpm_resp_hdr)) { - struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; - - resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); - resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); - resp->errcode = cpu_to_be32(TPM_FAIL); - } -} - -const TPMDriverOps *tpm_get_backend_driver(const char *type) -{ - int i; - - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { - if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) { - return be_drivers[i]; - } - } - - return NULL; -} - -#ifdef CONFIG_TPM - -int tpm_register_driver(const TPMDriverOps *tdo) -{ - int i; - - for (i = 0; i < TPM_MAX_DRIVERS; i++) { - if (!be_drivers[i]) { - be_drivers[i] = tdo; - return 0; - } - } - error_report("Could not register TPM driver"); - return 1; -} - -/* - * Walk the list of available TPM backend drivers and display them on the - * screen. - */ -void tpm_display_backend_drivers(void) -{ - int i; - - fprintf(stderr, "Supported TPM types (choose only one):\n"); - - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { - fprintf(stderr, "%12s %s\n", - TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc()); - } - fprintf(stderr, "\n"); -} - -/* - * Find the TPM with the given Id - */ -TPMBackend *qemu_find_tpm(const char *id) -{ - TPMBackend *drv; - - if (id) { - QLIST_FOREACH(drv, &tpm_backends, list) { - if (!strcmp(drv->id, id)) { - return drv; - } - } - } - - return NULL; -} - -static int configure_tpm(QemuOpts *opts) -{ - const char *value; - const char *id; - const TPMDriverOps *be; - TPMBackend *drv; - Error *local_err = NULL; - - if (!QLIST_EMPTY(&tpm_backends)) { - error_report("Only one TPM is allowed.\n"); - return 1; - } - - id = qemu_opts_id(opts); - if (id == NULL) { - qerror_report(QERR_MISSING_PARAMETER, "id"); - return 1; - } - - value = qemu_opt_get(opts, "type"); - if (!value) { - qerror_report(QERR_MISSING_PARAMETER, "type"); - tpm_display_backend_drivers(); - return 1; - } - - be = tpm_get_backend_driver(value); - if (be == NULL) { - qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", - "a TPM backend type"); - tpm_display_backend_drivers(); - return 1; - } - - drv = be->create(opts, id); - if (!drv) { - return 1; - } - - tpm_backend_open(drv, &local_err); - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return 1; - } - - QLIST_INSERT_HEAD(&tpm_backends, drv, list); - - return 0; -} - -static int tpm_init_tpmdev(QemuOpts *opts, void *dummy) -{ - return configure_tpm(opts); -} - -/* - * Walk the list of TPM backend drivers that are in use and call their - * destroy function to have them cleaned up. - */ -void tpm_cleanup(void) -{ - TPMBackend *drv, *next; - - QLIST_FOREACH_SAFE(drv, &tpm_backends, list, next) { - QLIST_REMOVE(drv, list); - tpm_backend_destroy(drv); - } -} - -/* - * Initialize the TPM. Process the tpmdev command line options describing the - * TPM backend. - */ -int tpm_init(void) -{ - if (qemu_opts_foreach(qemu_find_opts("tpmdev"), - tpm_init_tpmdev, NULL, 1) != 0) { - return -1; - } - - atexit(tpm_cleanup); - - return 0; -} - -/* - * Parse the TPM configuration options. - * To display all available TPM backends the user may use '-tpmdev help' - */ -int tpm_config_parse(QemuOptsList *opts_list, const char *optarg) -{ - QemuOpts *opts; - - if (!strcmp(optarg, "help")) { - tpm_display_backend_drivers(); - return -1; - } - opts = qemu_opts_parse(opts_list, optarg, 1); - if (!opts) { - return -1; - } - return 0; -} - -#endif /* CONFIG_TPM */ - -static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) -{ - int i; - - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { - if (be_drivers[i]->type == type) { - return be_drivers[i]; - } - } - return NULL; -} - -static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) -{ - TPMInfo *res = g_new0(TPMInfo, 1); - TPMPassthroughOptions *tpo; - - res->id = g_strdup(drv->id); - res->model = drv->fe_model; - res->options = g_new0(TpmTypeOptions, 1); - - switch (drv->ops->type) { - case TPM_TYPE_PASSTHROUGH: - res->options->kind = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; - tpo = g_new0(TPMPassthroughOptions, 1); - res->options->passthrough = tpo; - if (drv->path) { - tpo->path = g_strdup(drv->path); - tpo->has_path = true; - } - if (drv->cancel_path) { - tpo->cancel_path = g_strdup(drv->cancel_path); - tpo->has_cancel_path = true; - } - break; - case TPM_TYPE_MAX: - break; - } - - return res; -} - -/* - * Walk the list of active TPM backends and collect information about them - * following the schema description in qapi-schema.json. - */ -TPMInfoList *qmp_query_tpm(Error **errp) -{ - TPMBackend *drv; - TPMInfoList *info, *head = NULL, *cur_item = NULL; - - QLIST_FOREACH(drv, &tpm_backends, list) { - if (!tpm_model_is_registered(drv->fe_model)) { - continue; - } - info = g_new0(TPMInfoList, 1); - info->value = qmp_query_tpm_inst(drv); - - if (!cur_item) { - head = cur_item = info; - } else { - cur_item->next = info; - cur_item = info; - } - } - - return head; -} - -TpmTypeList *qmp_query_tpm_types(Error **errp) -{ - unsigned int i = 0; - TpmTypeList *head = NULL, *prev = NULL, *cur_item; - - for (i = 0; i < TPM_TYPE_MAX; i++) { - if (!tpm_driver_find_by_type(i)) { - continue; - } - cur_item = g_new0(TpmTypeList, 1); - cur_item->value = i; - - if (prev) { - prev->next = cur_item; - } - if (!head) { - head = cur_item; - } - prev = cur_item; - } - - return head; -} - -TpmModelList *qmp_query_tpm_models(Error **errp) -{ - unsigned int i = 0; - TpmModelList *head = NULL, *prev = NULL, *cur_item; - - for (i = 0; i < TPM_MODEL_MAX; i++) { - if (!tpm_model_is_registered(i)) { - continue; - } - cur_item = g_new0(TpmModelList, 1); - cur_item->value = i; - - if (prev) { - prev->next = cur_item; - } - if (!head) { - head = cur_item; - } - prev = cur_item; - } - - return head; -} diff --git a/tpm/tpm_backend.c b/tpm/tpm_backend.c deleted file mode 100644 index 4144ef7d76..0000000000 --- a/tpm/tpm_backend.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * common TPM backend driver functions - * - * Copyright (c) 2012-2013 IBM Corporation - * Authors: - * Stefan Berger - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - */ - -#include "tpm/tpm.h" -#include "qemu/thread.h" -#include "tpm_backend.h" - -void tpm_backend_thread_deliver_request(TPMBackendThread *tbt) -{ - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL); -} - -void tpm_backend_thread_create(TPMBackendThread *tbt, - GFunc func, gpointer user_data) -{ - if (!tbt->pool) { - tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL); - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL); - } -} - -void tpm_backend_thread_end(TPMBackendThread *tbt) -{ - if (tbt->pool) { - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL); - g_thread_pool_free(tbt->pool, FALSE, TRUE); - tbt->pool = NULL; - } -} - -void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, - GFunc func, gpointer user_data) -{ - if (!tbt->pool) { - tpm_backend_thread_create(tbt, func, user_data); - } else { - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_TPM_RESET, - NULL); - } -} diff --git a/tpm/tpm_backend.h b/tpm/tpm_backend.h deleted file mode 100644 index 05d94d0f5b..0000000000 --- a/tpm/tpm_backend.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * common TPM backend driver functions - * - * Copyright (c) 2012-2013 IBM Corporation - * Authors: - * Stefan Berger - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - */ - -#ifndef TPM_TPM_BACKEND_H -#define TPM_TPM_BACKEND_H - -#include - -typedef struct TPMBackendThread { - GThreadPool *pool; -} TPMBackendThread; - -void tpm_backend_thread_deliver_request(TPMBackendThread *tbt); -void tpm_backend_thread_create(TPMBackendThread *tbt, - GFunc func, gpointer user_data); -void tpm_backend_thread_end(TPMBackendThread *tbt); -void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, - GFunc func, gpointer user_data); - -typedef enum TPMBackendCmd { - TPM_BACKEND_CMD_INIT = 1, - TPM_BACKEND_CMD_PROCESS_CMD, - TPM_BACKEND_CMD_END, - TPM_BACKEND_CMD_TPM_RESET, -} TPMBackendCmd; - -#endif /* TPM_TPM_BACKEND_H */ diff --git a/tpm/tpm_int.h b/tpm/tpm_int.h deleted file mode 100644 index 340bfd52f1..0000000000 --- a/tpm/tpm_int.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * TPM configuration - * - * Copyright (C) 2011-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#ifndef TPM_TPM_INT_H -#define TPM_TPM_INT_H - -#include "exec/memory.h" -#include "tpm/tpm_tis.h" - -/* overall state of the TPM interface */ -struct TPMState { - ISADevice busdev; - MemoryRegion mmio; - - union { - TPMTISEmuState tis; - } s; - - uint8_t locty_number; - TPMLocality *locty_data; - - char *backend; - TPMBackend *be_driver; -}; - -#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) - -struct TPMDriverOps { - enum TpmType type; - /* get a descriptive text of the backend to display to the user */ - const char *(*desc)(void); - - TPMBackend *(*create)(QemuOpts *opts, const char *id); - void (*destroy)(TPMBackend *t); - - /* initialize the backend */ - int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb); - /* start up the TPM on the backend */ - int (*startup_tpm)(TPMBackend *t); - /* returns true if nothing will ever answer TPM requests */ - bool (*had_startup_error)(TPMBackend *t); - - size_t (*realloc_buffer)(TPMSizedBuffer *sb); - - void (*deliver_request)(TPMBackend *t); - - void (*reset)(TPMBackend *t); - - void (*cancel_cmd)(TPMBackend *t); - - bool (*get_tpm_established_flag)(TPMBackend *t); -}; - -struct tpm_req_hdr { - uint16_t tag; - uint32_t len; - uint32_t ordinal; -} QEMU_PACKED; - -struct tpm_resp_hdr { - uint16_t tag; - uint32_t len; - uint32_t errcode; -} QEMU_PACKED; - -#define TPM_TAG_RQU_COMMAND 0xc1 -#define TPM_TAG_RQU_AUTH1_COMMAND 0xc2 -#define TPM_TAG_RQU_AUTH2_COMMAND 0xc3 - -#define TPM_TAG_RSP_COMMAND 0xc4 -#define TPM_TAG_RSP_AUTH1_COMMAND 0xc5 -#define TPM_TAG_RSP_AUTH2_COMMAND 0xc6 - -#define TPM_FAIL 9 - -#define TPM_ORD_GetTicks 0xf1 - -TPMBackend *qemu_find_tpm(const char *id); -int tpm_register_model(enum TpmModel model); -int tpm_register_driver(const TPMDriverOps *tdo); -void tpm_display_backend_drivers(void); -const TPMDriverOps *tpm_get_backend_driver(const char *type); -void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len); - -extern const TPMDriverOps tpm_passthrough_driver; - -#endif /* TPM_TPM_INT_H */ diff --git a/tpm/tpm_passthrough.c b/tpm/tpm_passthrough.c deleted file mode 100644 index 1fdd66d356..0000000000 --- a/tpm/tpm_passthrough.c +++ /dev/null @@ -1,560 +0,0 @@ -/* - * passthrough TPM driver - * - * Copyright (c) 2010 - 2013 IBM Corporation - * Authors: - * Stefan Berger - * - * Copyright (C) 2011 IAIK, Graz University of Technology - * Author: Andreas Niederl - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - */ - -#include - -#include "qemu-common.h" -#include "qapi/error.h" -#include "qemu/sockets.h" -#include "backends/tpm.h" -#include "tpm_int.h" -#include "hw/hw.h" -#include "hw/i386/pc.h" -#include "tpm_tis.h" -#include "tpm_backend.h" - -/* #define DEBUG_TPM */ - -#ifdef DEBUG_TPM -#define DPRINTF(fmt, ...) \ - do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -#define TYPE_TPM_PASSTHROUGH "tpm-passthrough" -#define TPM_PASSTHROUGH(obj) \ - OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) - -/* data structures */ -typedef struct TPMPassthruThreadParams { - TPMState *tpm_state; - - TPMRecvDataCB *recv_data_callback; - TPMBackend *tb; -} TPMPassthruThreadParams; - -struct TPMPassthruState { - TPMBackend parent; - - TPMBackendThread tbt; - - TPMPassthruThreadParams tpm_thread_params; - - char *tpm_dev; - int tpm_fd; - bool tpm_executing; - bool tpm_op_canceled; - int cancel_fd; - bool had_startup_error; -}; - -typedef struct TPMPassthruState TPMPassthruState; - -#define TPM_PASSTHROUGH_DEFAULT_DEVICE "/dev/tpm0" - -/* functions */ - -static void tpm_passthrough_cancel_cmd(TPMBackend *tb); - -static int tpm_passthrough_unix_write(int fd, const uint8_t *buf, uint32_t len) -{ - return send_all(fd, buf, len); -} - -static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len) -{ - return recv_all(fd, buf, len, true); -} - -static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf) -{ - struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)buf; - - return be32_to_cpu(resp->len); -} - -static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, - const uint8_t *in, uint32_t in_len, - uint8_t *out, uint32_t out_len) -{ - int ret; - - tpm_pt->tpm_op_canceled = false; - tpm_pt->tpm_executing = true; - - ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len); - if (ret != in_len) { - if (!tpm_pt->tpm_op_canceled || - (tpm_pt->tpm_op_canceled && errno != ECANCELED)) { - error_report("tpm_passthrough: error while transmitting data " - "to TPM: %s (%i)\n", - strerror(errno), errno); - } - goto err_exit; - } - - tpm_pt->tpm_executing = false; - - ret = tpm_passthrough_unix_read(tpm_pt->tpm_fd, out, out_len); - if (ret < 0) { - if (!tpm_pt->tpm_op_canceled || - (tpm_pt->tpm_op_canceled && errno != ECANCELED)) { - error_report("tpm_passthrough: error while reading data from " - "TPM: %s (%i)\n", - strerror(errno), errno); - } - } else if (ret < sizeof(struct tpm_resp_hdr) || - tpm_passthrough_get_size_from_buffer(out) != ret) { - ret = -1; - error_report("tpm_passthrough: received invalid response " - "packet from TPM\n"); - } - -err_exit: - if (ret < 0) { - tpm_write_fatal_error_response(out, out_len); - } - - tpm_pt->tpm_executing = false; - - return ret; -} - -static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, - const TPMLocality *locty_data) -{ - return tpm_passthrough_unix_tx_bufs(tpm_pt, - locty_data->w_buffer.buffer, - locty_data->w_offset, - locty_data->r_buffer.buffer, - locty_data->r_buffer.size); -} - -static void tpm_passthrough_worker_thread(gpointer data, - gpointer user_data) -{ - TPMPassthruThreadParams *thr_parms = user_data; - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(thr_parms->tb); - TPMBackendCmd cmd = (TPMBackendCmd)data; - - DPRINTF("tpm_passthrough: processing command type %d\n", cmd); - - switch (cmd) { - case TPM_BACKEND_CMD_PROCESS_CMD: - tpm_passthrough_unix_transfer(tpm_pt, - thr_parms->tpm_state->locty_data); - - thr_parms->recv_data_callback(thr_parms->tpm_state, - thr_parms->tpm_state->locty_number); - break; - case TPM_BACKEND_CMD_INIT: - case TPM_BACKEND_CMD_END: - case TPM_BACKEND_CMD_TPM_RESET: - /* nothing to do */ - break; - } -} - -/* - * Start the TPM (thread). If it had been started before, then terminate - * and start it again. - */ -static int tpm_passthrough_startup_tpm(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - /* terminate a running TPM */ - tpm_backend_thread_end(&tpm_pt->tbt); - - tpm_backend_thread_create(&tpm_pt->tbt, - tpm_passthrough_worker_thread, - &tpm_pt->tpm_thread_params); - - return 0; -} - -static void tpm_passthrough_reset(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - DPRINTF("tpm_passthrough: CALL TO TPM_RESET!\n"); - - tpm_passthrough_cancel_cmd(tb); - - tpm_backend_thread_end(&tpm_pt->tbt); - - tpm_pt->had_startup_error = false; -} - -static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, - TPMRecvDataCB *recv_data_cb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - tpm_pt->tpm_thread_params.tpm_state = s; - tpm_pt->tpm_thread_params.recv_data_callback = recv_data_cb; - tpm_pt->tpm_thread_params.tb = tb; - - return 0; -} - -static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb) -{ - return false; -} - -static bool tpm_passthrough_get_startup_error(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - return tpm_pt->had_startup_error; -} - -static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb) -{ - size_t wanted_size = 4096; /* Linux tpm.c buffer size */ - - if (sb->size != wanted_size) { - sb->buffer = g_realloc(sb->buffer, wanted_size); - sb->size = wanted_size; - } - return sb->size; -} - -static void tpm_passthrough_deliver_request(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - tpm_backend_thread_deliver_request(&tpm_pt->tbt); -} - -static void tpm_passthrough_cancel_cmd(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - int n; - - /* - * As of Linux 3.7 the tpm_tis driver does not properly cancel - * commands on all TPM manufacturers' TPMs. - * Only cancel if we're busy so we don't cancel someone else's - * command, e.g., a command executed on the host. - */ - if (tpm_pt->tpm_executing) { - if (tpm_pt->cancel_fd >= 0) { - n = write(tpm_pt->cancel_fd, "-", 1); - if (n != 1) { - error_report("Canceling TPM command failed: %s\n", - strerror(errno)); - } else { - tpm_pt->tpm_op_canceled = true; - } - } else { - error_report("Cannot cancel TPM command due to missing " - "TPM sysfs cancel entry"); - } - } -} - -static const char *tpm_passthrough_create_desc(void) -{ - return "Passthrough TPM backend driver"; -} - -/* - * A basic test of a TPM device. We expect a well formatted response header - * (error response is fine) within one second. - */ -static int tpm_passthrough_test_tpmdev(int fd) -{ - struct tpm_req_hdr req = { - .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), - .len = cpu_to_be32(sizeof(req)), - .ordinal = cpu_to_be32(TPM_ORD_GetTicks), - }; - struct tpm_resp_hdr *resp; - fd_set readfds; - int n; - struct timeval tv = { - .tv_sec = 1, - .tv_usec = 0, - }; - unsigned char buf[1024]; - - n = write(fd, &req, sizeof(req)); - if (n < 0) { - return errno; - } - if (n != sizeof(req)) { - return EFAULT; - } - - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - - /* wait for a second */ - n = select(fd + 1, &readfds, NULL, NULL, &tv); - if (n != 1) { - return errno; - } - - n = read(fd, &buf, sizeof(buf)); - if (n < sizeof(struct tpm_resp_hdr)) { - return EFAULT; - } - - resp = (struct tpm_resp_hdr *)buf; - /* check the header */ - if (be16_to_cpu(resp->tag) != TPM_TAG_RSP_COMMAND || - be32_to_cpu(resp->len) != n) { - return EBADMSG; - } - - return 0; -} - -/* - * Check whether the given base path, e.g., /sys/class/misc/tpm0/device, - * is the sysfs directory of a TPM. A TPM sysfs directory should be uniquely - * recognizable by the file entries 'pcrs' and 'cancel'. - * Upon success 'true' is returned and the basebath buffer has '/cancel' - * appended. - */ -static bool tpm_passthrough_check_sysfs_cancel(char *basepath, size_t bufsz) -{ - char path[PATH_MAX]; - struct stat statbuf; - - snprintf(path, sizeof(path), "%s/pcrs", basepath); - if (stat(path, &statbuf) == -1 || !S_ISREG(statbuf.st_mode)) { - return false; - } - - snprintf(path, sizeof(path), "%s/cancel", basepath); - if (stat(path, &statbuf) == -1 || !S_ISREG(statbuf.st_mode)) { - return false; - } - - strncpy(basepath, path, bufsz); - - return true; -} - -/* - * Unless path or file descriptor set has been provided by user, - * determine the sysfs cancel file following kernel documentation - * in Documentation/ABI/stable/sysfs-class-tpm. - */ -static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) -{ - int fd = -1; - unsigned int idx; - DIR *pnp_dir; - char path[PATH_MAX]; - struct dirent entry, *result; - int len; - - if (tb->cancel_path) { - fd = qemu_open(tb->cancel_path, O_WRONLY); - if (fd < 0) { - error_report("Could not open TPM cancel path : %s", - strerror(errno)); - } - return fd; - } - - snprintf(path, sizeof(path), "/sys/class/misc"); - pnp_dir = opendir(path); - if (pnp_dir != NULL) { - while (readdir_r(pnp_dir, &entry, &result) == 0 && - result != NULL) { - /* - * only allow /sys/class/misc/tpm%u type of paths - */ - if (sscanf(entry.d_name, "tpm%u%n", &idx, &len) < 1 || - len <= strlen("tpm") || - len != strlen(entry.d_name)) { - continue; - } - - snprintf(path, sizeof(path), "/sys/class/misc/%s/device", - entry.d_name); - if (!tpm_passthrough_check_sysfs_cancel(path, sizeof(path))) { - continue; - } - - fd = qemu_open(path, O_WRONLY); - break; - } - closedir(pnp_dir); - } - - if (fd >= 0) { - tb->cancel_path = g_strdup(path); - } - - return fd; -} - -static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - const char *value; - - value = qemu_opt_get(opts, "cancel-path"); - if (value) { - tb->cancel_path = g_strdup(value); - } - - value = qemu_opt_get(opts, "path"); - if (!value) { - value = TPM_PASSTHROUGH_DEFAULT_DEVICE; - } - - tpm_pt->tpm_dev = g_strdup(value); - - tb->path = g_strdup(tpm_pt->tpm_dev); - - tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR); - if (tpm_pt->tpm_fd < 0) { - error_report("Cannot access TPM device using '%s': %s\n", - tpm_pt->tpm_dev, strerror(errno)); - goto err_free_parameters; - } - - if (tpm_passthrough_test_tpmdev(tpm_pt->tpm_fd)) { - error_report("'%s' is not a TPM device.\n", - tpm_pt->tpm_dev); - goto err_close_tpmdev; - } - - return 0; - - err_close_tpmdev: - qemu_close(tpm_pt->tpm_fd); - tpm_pt->tpm_fd = -1; - - err_free_parameters: - g_free(tb->path); - tb->path = NULL; - - g_free(tpm_pt->tpm_dev); - tpm_pt->tpm_dev = NULL; - - return 1; -} - -static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) -{ - Object *obj = object_new(TYPE_TPM_PASSTHROUGH); - TPMBackend *tb = TPM_BACKEND(obj); - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - tb->id = g_strdup(id); - /* let frontend set the fe_model to proper value */ - tb->fe_model = -1; - - tb->ops = &tpm_passthrough_driver; - - if (tpm_passthrough_handle_device_opts(opts, tb)) { - goto err_exit; - } - - tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tb); - if (tpm_pt->cancel_fd < 0) { - goto err_exit; - } - - return tb; - -err_exit: - g_free(tb->id); - - return NULL; -} - -static void tpm_passthrough_destroy(TPMBackend *tb) -{ - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - - tpm_passthrough_cancel_cmd(tb); - - tpm_backend_thread_end(&tpm_pt->tbt); - - qemu_close(tpm_pt->tpm_fd); - qemu_close(tpm_pt->cancel_fd); - - g_free(tb->id); - g_free(tb->path); - g_free(tb->cancel_path); - g_free(tpm_pt->tpm_dev); -} - -const TPMDriverOps tpm_passthrough_driver = { - .type = TPM_TYPE_PASSTHROUGH, - .desc = tpm_passthrough_create_desc, - .create = tpm_passthrough_create, - .destroy = tpm_passthrough_destroy, - .init = tpm_passthrough_init, - .startup_tpm = tpm_passthrough_startup_tpm, - .realloc_buffer = tpm_passthrough_realloc_buffer, - .reset = tpm_passthrough_reset, - .had_startup_error = tpm_passthrough_get_startup_error, - .deliver_request = tpm_passthrough_deliver_request, - .cancel_cmd = tpm_passthrough_cancel_cmd, - .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, -}; - -static void tpm_passthrough_inst_init(Object *obj) -{ -} - -static void tpm_passthrough_inst_finalize(Object *obj) -{ -} - -static void tpm_passthrough_class_init(ObjectClass *klass, void *data) -{ - TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass); - - tbc->ops = &tpm_passthrough_driver; -} - -static const TypeInfo tpm_passthrough_info = { - .name = TYPE_TPM_PASSTHROUGH, - .parent = TYPE_TPM_BACKEND, - .instance_size = sizeof(TPMPassthruState), - .class_init = tpm_passthrough_class_init, - .instance_init = tpm_passthrough_inst_init, - .instance_finalize = tpm_passthrough_inst_finalize, -}; - -static void tpm_passthrough_register(void) -{ - type_register_static(&tpm_passthrough_info); - tpm_register_driver(&tpm_passthrough_driver); -} - -type_init(tpm_passthrough_register) diff --git a/tpm/tpm_tis.c b/tpm/tpm_tis.c deleted file mode 100644 index f0a4584607..0000000000 --- a/tpm/tpm_tis.c +++ /dev/null @@ -1,930 +0,0 @@ -/* - * tpm_tis.c - QEMU's TPM TIS interface emulator - * - * Copyright (C) 2006,2010-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * David Safford - * - * Xen 4 support: Andrease Niederl - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - * - * Implementation of the TIS interface according to specs found at - * http://www.trustedcomputinggroup.org. This implementation currently - * supports version 1.21, revision 1.0. - * In the developers menu choose the PC Client section then find the TIS - * specification. - */ - -#include "backends/tpm.h" -#include "tpm_int.h" -#include "block/block.h" -#include "exec/address-spaces.h" -#include "hw/hw.h" -#include "hw/i386/pc.h" -#include "hw/pci/pci_ids.h" -#include "tpm/tpm_tis.h" -#include "qemu-common.h" - -/*#define DEBUG_TIS */ - -#ifdef DEBUG_TIS -#define DPRINTF(fmt, ...) \ - do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -/* whether the STS interrupt is supported */ -#define RAISE_STS_IRQ - -/* tis registers */ -#define TPM_TIS_REG_ACCESS 0x00 -#define TPM_TIS_REG_INT_ENABLE 0x08 -#define TPM_TIS_REG_INT_VECTOR 0x0c -#define TPM_TIS_REG_INT_STATUS 0x10 -#define TPM_TIS_REG_INTF_CAPABILITY 0x14 -#define TPM_TIS_REG_STS 0x18 -#define TPM_TIS_REG_DATA_FIFO 0x24 -#define TPM_TIS_REG_DID_VID 0xf00 -#define TPM_TIS_REG_RID 0xf04 - -/* vendor-specific registers */ -#define TPM_TIS_REG_DEBUG 0xf90 - -#define TPM_TIS_STS_VALID (1 << 7) -#define TPM_TIS_STS_COMMAND_READY (1 << 6) -#define TPM_TIS_STS_TPM_GO (1 << 5) -#define TPM_TIS_STS_DATA_AVAILABLE (1 << 4) -#define TPM_TIS_STS_EXPECT (1 << 3) -#define TPM_TIS_STS_RESPONSE_RETRY (1 << 1) - -#define TPM_TIS_BURST_COUNT_SHIFT 8 -#define TPM_TIS_BURST_COUNT(X) \ - ((X) << TPM_TIS_BURST_COUNT_SHIFT) - -#define TPM_TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) -#define TPM_TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) -#define TPM_TIS_ACCESS_BEEN_SEIZED (1 << 4) -#define TPM_TIS_ACCESS_SEIZE (1 << 3) -#define TPM_TIS_ACCESS_PENDING_REQUEST (1 << 2) -#define TPM_TIS_ACCESS_REQUEST_USE (1 << 1) -#define TPM_TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) - -#define TPM_TIS_INT_ENABLED (1 << 31) -#define TPM_TIS_INT_DATA_AVAILABLE (1 << 0) -#define TPM_TIS_INT_STS_VALID (1 << 1) -#define TPM_TIS_INT_LOCALITY_CHANGED (1 << 2) -#define TPM_TIS_INT_COMMAND_READY (1 << 7) - -#define TPM_TIS_INT_POLARITY_MASK (3 << 3) -#define TPM_TIS_INT_POLARITY_LOW_LEVEL (1 << 3) - -#ifndef RAISE_STS_IRQ - -#define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ - TPM_TIS_INT_DATA_AVAILABLE | \ - TPM_TIS_INT_COMMAND_READY) - -#else - -#define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ - TPM_TIS_INT_DATA_AVAILABLE | \ - TPM_TIS_INT_STS_VALID | \ - TPM_TIS_INT_COMMAND_READY) - -#endif - -#define TPM_TIS_CAP_INTERRUPT_LOW_LEVEL (1 << 4) /* support is mandatory */ -#define TPM_TIS_CAPABILITIES_SUPPORTED (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \ - TPM_TIS_INTERRUPTS_SUPPORTED) - -#define TPM_TIS_TPM_DID 0x0001 -#define TPM_TIS_TPM_VID PCI_VENDOR_ID_IBM -#define TPM_TIS_TPM_RID 0x0001 - -#define TPM_TIS_NO_DATA_BYTE 0xff - -/* local prototypes */ - -static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, - unsigned size); - -/* utility functions */ - -static uint8_t tpm_tis_locality_from_addr(hwaddr addr) -{ - return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); -} - -static uint32_t tpm_tis_get_size_from_buffer(const TPMSizedBuffer *sb) -{ - return be32_to_cpu(*(uint32_t *)&sb->buffer[2]); -} - -static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *string) -{ -#ifdef DEBUG_TIS - uint32_t len, i; - - len = tpm_tis_get_size_from_buffer(sb); - DPRINTF("tpm_tis: %s length = %d\n", string, len); - for (i = 0; i < len; i++) { - if (i && !(i % 16)) { - DPRINTF("\n"); - } - DPRINTF("%.2X ", sb->buffer[i]); - } - DPRINTF("\n"); -#endif -} - -/* - * Send a request to the TPM. - */ -static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) -{ - TPMTISEmuState *tis = &s->s.tis; - - tpm_tis_show_buffer(&tis->loc[locty].w_buffer, "tpm_tis: To TPM"); - - s->locty_number = locty; - s->locty_data = &tis->loc[locty]; - - /* - * w_offset serves as length indicator for length of data; - * it's reset when the response comes back - */ - tis->loc[locty].state = TPM_TIS_STATE_EXECUTION; - - tpm_backend_deliver_request(s->be_driver); -} - -/* raise an interrupt if allowed */ -static void tpm_tis_raise_irq(TPMState *s, uint8_t locty, uint32_t irqmask) -{ - TPMTISEmuState *tis = &s->s.tis; - - if (!TPM_TIS_IS_VALID_LOCTY(locty)) { - return; - } - - if ((tis->loc[locty].inte & TPM_TIS_INT_ENABLED) && - (tis->loc[locty].inte & irqmask)) { - DPRINTF("tpm_tis: Raising IRQ for flag %08x\n", irqmask); - qemu_irq_raise(s->s.tis.irq); - tis->loc[locty].ints |= irqmask; - } -} - -static uint32_t tpm_tis_check_request_use_except(TPMState *s, uint8_t locty) -{ - uint8_t l; - - for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) { - if (l == locty) { - continue; - } - if ((s->s.tis.loc[l].access & TPM_TIS_ACCESS_REQUEST_USE)) { - return 1; - } - } - - return 0; -} - -static void tpm_tis_new_active_locality(TPMState *s, uint8_t new_active_locty) -{ - TPMTISEmuState *tis = &s->s.tis; - bool change = (s->s.tis.active_locty != new_active_locty); - bool is_seize; - uint8_t mask; - - if (change && TPM_TIS_IS_VALID_LOCTY(s->s.tis.active_locty)) { - is_seize = TPM_TIS_IS_VALID_LOCTY(new_active_locty) && - tis->loc[new_active_locty].access & TPM_TIS_ACCESS_SEIZE; - - if (is_seize) { - mask = ~(TPM_TIS_ACCESS_ACTIVE_LOCALITY); - } else { - mask = ~(TPM_TIS_ACCESS_ACTIVE_LOCALITY| - TPM_TIS_ACCESS_REQUEST_USE); - } - /* reset flags on the old active locality */ - tis->loc[s->s.tis.active_locty].access &= mask; - - if (is_seize) { - tis->loc[tis->active_locty].access |= TPM_TIS_ACCESS_BEEN_SEIZED; - } - } - - tis->active_locty = new_active_locty; - - DPRINTF("tpm_tis: Active locality is now %d\n", s->s.tis.active_locty); - - if (TPM_TIS_IS_VALID_LOCTY(new_active_locty)) { - /* set flags on the new active locality */ - tis->loc[new_active_locty].access |= TPM_TIS_ACCESS_ACTIVE_LOCALITY; - tis->loc[new_active_locty].access &= ~(TPM_TIS_ACCESS_REQUEST_USE | - TPM_TIS_ACCESS_SEIZE); - } - - if (change) { - tpm_tis_raise_irq(s, tis->active_locty, TPM_TIS_INT_LOCALITY_CHANGED); - } -} - -/* abort -- this function switches the locality */ -static void tpm_tis_abort(TPMState *s, uint8_t locty) -{ - TPMTISEmuState *tis = &s->s.tis; - - tis->loc[locty].r_offset = 0; - tis->loc[locty].w_offset = 0; - - DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", tis->next_locty); - - /* - * Need to react differently depending on who's aborting now and - * which locality will become active afterwards. - */ - if (tis->aborting_locty == tis->next_locty) { - tis->loc[tis->aborting_locty].state = TPM_TIS_STATE_READY; - tis->loc[tis->aborting_locty].sts = TPM_TIS_STS_COMMAND_READY; - tpm_tis_raise_irq(s, tis->aborting_locty, TPM_TIS_INT_COMMAND_READY); - } - - /* locality after abort is another one than the current one */ - tpm_tis_new_active_locality(s, tis->next_locty); - - tis->next_locty = TPM_TIS_NO_LOCALITY; - /* nobody's aborting a command anymore */ - tis->aborting_locty = TPM_TIS_NO_LOCALITY; -} - -/* prepare aborting current command */ -static void tpm_tis_prep_abort(TPMState *s, uint8_t locty, uint8_t newlocty) -{ - TPMTISEmuState *tis = &s->s.tis; - uint8_t busy_locty; - - tis->aborting_locty = locty; - tis->next_locty = newlocty; /* locality after successful abort */ - - /* - * only abort a command using an interrupt if currently executing - * a command AND if there's a valid connection to the vTPM. - */ - for (busy_locty = 0; busy_locty < TPM_TIS_NUM_LOCALITIES; busy_locty++) { - if (tis->loc[busy_locty].state == TPM_TIS_STATE_EXECUTION) { - /* - * request the backend to cancel. Some backends may not - * support it - */ - tpm_backend_cancel_cmd(s->be_driver); - return; - } - } - - tpm_tis_abort(s, locty); -} - -static void tpm_tis_receive_bh(void *opaque) -{ - TPMState *s = opaque; - TPMTISEmuState *tis = &s->s.tis; - uint8_t locty = s->locty_number; - - tis->loc[locty].sts = TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE; - tis->loc[locty].state = TPM_TIS_STATE_COMPLETION; - tis->loc[locty].r_offset = 0; - tis->loc[locty].w_offset = 0; - - if (TPM_TIS_IS_VALID_LOCTY(tis->next_locty)) { - tpm_tis_abort(s, locty); - } - -#ifndef RAISE_STS_IRQ - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE); -#else - tpm_tis_raise_irq(s, locty, - TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); -#endif -} - -/* - * Callback from the TPM to indicate that the response was received. - */ -static void tpm_tis_receive_cb(TPMState *s, uint8_t locty) -{ - TPMTISEmuState *tis = &s->s.tis; - - assert(s->locty_number == locty); - - qemu_bh_schedule(tis->bh); -} - -/* - * Read a byte of response data - */ -static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) -{ - TPMTISEmuState *tis = &s->s.tis; - uint32_t ret = TPM_TIS_NO_DATA_BYTE; - uint16_t len; - - if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len = tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); - - ret = tis->loc[locty].r_buffer.buffer[tis->loc[locty].r_offset++]; - if (tis->loc[locty].r_offset >= len) { - /* got last byte */ - tis->loc[locty].sts = TPM_TIS_STS_VALID; -#ifdef RAISE_STS_IRQ - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); -#endif - } - DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", - ret, tis->loc[locty].r_offset-1); - } - - return ret; -} - -#ifdef DEBUG_TIS -static void tpm_tis_dump_state(void *opaque, hwaddr addr) -{ - static const unsigned regs[] = { - TPM_TIS_REG_ACCESS, - TPM_TIS_REG_INT_ENABLE, - TPM_TIS_REG_INT_VECTOR, - TPM_TIS_REG_INT_STATUS, - TPM_TIS_REG_INTF_CAPABILITY, - TPM_TIS_REG_STS, - TPM_TIS_REG_DID_VID, - TPM_TIS_REG_RID, - 0xfff}; - int idx; - uint8_t locty = tpm_tis_locality_from_addr(addr); - hwaddr base = addr & ~0xfff; - TPMState *s = opaque; - TPMTISEmuState *tis = &s->s.tis; - - DPRINTF("tpm_tis: active locality : %d\n" - "tpm_tis: state of locality %d : %d\n" - "tpm_tis: register dump:\n", - tis->active_locty, - locty, tis->loc[locty].state); - - for (idx = 0; regs[idx] != 0xfff; idx++) { - DPRINTF("tpm_tis: 0x%04x : 0x%08x\n", regs[idx], - (uint32_t)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); - } - - DPRINTF("tpm_tis: read offset : %d\n" - "tpm_tis: result buffer : ", - tis->loc[locty].r_offset); - for (idx = 0; - idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); - idx++) { - DPRINTF("%c%02x%s", - tis->loc[locty].r_offset == idx ? '>' : ' ', - tis->loc[locty].r_buffer.buffer[idx], - ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); - } - DPRINTF("\n" - "tpm_tis: write offset : %d\n" - "tpm_tis: request buffer: ", - tis->loc[locty].w_offset); - for (idx = 0; - idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].w_buffer); - idx++) { - DPRINTF("%c%02x%s", - tis->loc[locty].w_offset == idx ? '>' : ' ', - tis->loc[locty].w_buffer.buffer[idx], - ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); - } - DPRINTF("\n"); -} -#endif - -/* - * Read a register of the TIS interface - * See specs pages 33-63 for description of the registers - */ -static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, - unsigned size) -{ - TPMState *s = opaque; - TPMTISEmuState *tis = &s->s.tis; - uint16_t offset = addr & 0xffc; - uint8_t shift = (addr & 0x3) * 8; - uint32_t val = 0xffffffff; - uint8_t locty = tpm_tis_locality_from_addr(addr); - uint32_t avail; - - if (tpm_backend_had_startup_error(s->be_driver)) { - return val; - } - - switch (offset) { - case TPM_TIS_REG_ACCESS: - /* never show the SEIZE flag even though we use it internally */ - val = tis->loc[locty].access & ~TPM_TIS_ACCESS_SEIZE; - /* the pending flag is always calculated */ - if (tpm_tis_check_request_use_except(s, locty)) { - val |= TPM_TIS_ACCESS_PENDING_REQUEST; - } - val |= !tpm_backend_get_tpm_established_flag(s->be_driver); - break; - case TPM_TIS_REG_INT_ENABLE: - val = tis->loc[locty].inte; - break; - case TPM_TIS_REG_INT_VECTOR: - val = tis->irq_num; - break; - case TPM_TIS_REG_INT_STATUS: - val = tis->loc[locty].ints; - break; - case TPM_TIS_REG_INTF_CAPABILITY: - val = TPM_TIS_CAPABILITIES_SUPPORTED; - break; - case TPM_TIS_REG_STS: - if (tis->active_locty == locty) { - if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - val = TPM_TIS_BURST_COUNT( - tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer) - - tis->loc[locty].r_offset) | tis->loc[locty].sts; - } else { - avail = tis->loc[locty].w_buffer.size - - tis->loc[locty].w_offset; - /* - * byte-sized reads should not return 0x00 for 0x100 - * available bytes. - */ - if (size == 1 && avail > 0xff) { - avail = 0xff; - } - val = TPM_TIS_BURST_COUNT(avail) | tis->loc[locty].sts; - } - } - break; - case TPM_TIS_REG_DATA_FIFO: - if (tis->active_locty == locty) { - switch (tis->loc[locty].state) { - case TPM_TIS_STATE_COMPLETION: - val = tpm_tis_data_read(s, locty); - break; - default: - val = TPM_TIS_NO_DATA_BYTE; - break; - } - } - break; - case TPM_TIS_REG_DID_VID: - val = (TPM_TIS_TPM_DID << 16) | TPM_TIS_TPM_VID; - break; - case TPM_TIS_REG_RID: - val = TPM_TIS_TPM_RID; - break; -#ifdef DEBUG_TIS - case TPM_TIS_REG_DEBUG: - tpm_tis_dump_state(opaque, addr); - break; -#endif - } - - if (shift) { - val >>= shift; - } - - DPRINTF("tpm_tis: read.%u(%08x) = %08x\n", size, (int)addr, (uint32_t)val); - - return val; -} - -/* - * Write a value to a register of the TIS interface - * See specs pages 33-63 for description of the registers - */ -static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr, - uint64_t val, unsigned size, - bool hw_access) -{ - TPMState *s = opaque; - TPMTISEmuState *tis = &s->s.tis; - uint16_t off = addr & 0xfff; - uint8_t locty = tpm_tis_locality_from_addr(addr); - uint8_t active_locty, l; - int c, set_new_locty = 1; - uint16_t len; - - DPRINTF("tpm_tis: write.%u(%08x) = %08x\n", size, (int)addr, (uint32_t)val); - - if (locty == 4 && !hw_access) { - DPRINTF("tpm_tis: Access to locality 4 only allowed from hardware\n"); - return; - } - - if (tpm_backend_had_startup_error(s->be_driver)) { - return; - } - - switch (off) { - case TPM_TIS_REG_ACCESS: - - if ((val & TPM_TIS_ACCESS_SEIZE)) { - val &= ~(TPM_TIS_ACCESS_REQUEST_USE | - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - } - - active_locty = tis->active_locty; - - if ((val & TPM_TIS_ACCESS_ACTIVE_LOCALITY)) { - /* give up locality if currently owned */ - if (tis->active_locty == locty) { - DPRINTF("tpm_tis: Releasing locality %d\n", locty); - - uint8_t newlocty = TPM_TIS_NO_LOCALITY; - /* anybody wants the locality ? */ - for (c = TPM_TIS_NUM_LOCALITIES - 1; c >= 0; c--) { - if ((tis->loc[c].access & TPM_TIS_ACCESS_REQUEST_USE)) { - DPRINTF("tpm_tis: Locality %d requests use.\n", c); - newlocty = c; - break; - } - } - DPRINTF("tpm_tis: TPM_TIS_ACCESS_ACTIVE_LOCALITY: " - "Next active locality: %d\n", - newlocty); - - if (TPM_TIS_IS_VALID_LOCTY(newlocty)) { - set_new_locty = 0; - tpm_tis_prep_abort(s, locty, newlocty); - } else { - active_locty = TPM_TIS_NO_LOCALITY; - } - } else { - /* not currently the owner; clear a pending request */ - tis->loc[locty].access &= ~TPM_TIS_ACCESS_REQUEST_USE; - } - } - - if ((val & TPM_TIS_ACCESS_BEEN_SEIZED)) { - tis->loc[locty].access &= ~TPM_TIS_ACCESS_BEEN_SEIZED; - } - - if ((val & TPM_TIS_ACCESS_SEIZE)) { - /* - * allow seize if a locality is active and the requesting - * locality is higher than the one that's active - * OR - * allow seize for requesting locality if no locality is - * active - */ - while ((TPM_TIS_IS_VALID_LOCTY(tis->active_locty) && - locty > tis->active_locty) || - !TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { - bool higher_seize = FALSE; - - /* already a pending SEIZE ? */ - if ((tis->loc[locty].access & TPM_TIS_ACCESS_SEIZE)) { - break; - } - - /* check for ongoing seize by a higher locality */ - for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES; l++) { - if ((tis->loc[l].access & TPM_TIS_ACCESS_SEIZE)) { - higher_seize = TRUE; - break; - } - } - - if (higher_seize) { - break; - } - - /* cancel any seize by a lower locality */ - for (l = 0; l < locty - 1; l++) { - tis->loc[l].access &= ~TPM_TIS_ACCESS_SEIZE; - } - - tis->loc[locty].access |= TPM_TIS_ACCESS_SEIZE; - DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: " - "Locality %d seized from locality %d\n", - locty, tis->active_locty); - DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: Initiating abort.\n"); - set_new_locty = 0; - tpm_tis_prep_abort(s, tis->active_locty, locty); - break; - } - } - - if ((val & TPM_TIS_ACCESS_REQUEST_USE)) { - if (tis->active_locty != locty) { - if (TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { - tis->loc[locty].access |= TPM_TIS_ACCESS_REQUEST_USE; - } else { - /* no locality active -> make this one active now */ - active_locty = locty; - } - } - } - - if (set_new_locty) { - tpm_tis_new_active_locality(s, active_locty); - } - - break; - case TPM_TIS_REG_INT_ENABLE: - if (tis->active_locty != locty) { - break; - } - - tis->loc[locty].inte = (val & (TPM_TIS_INT_ENABLED | - TPM_TIS_INT_POLARITY_MASK | - TPM_TIS_INTERRUPTS_SUPPORTED)); - break; - case TPM_TIS_REG_INT_VECTOR: - /* hard wired -- ignore */ - break; - case TPM_TIS_REG_INT_STATUS: - if (tis->active_locty != locty) { - break; - } - - /* clearing of interrupt flags */ - if (((val & TPM_TIS_INTERRUPTS_SUPPORTED)) && - (tis->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) { - tis->loc[locty].ints &= ~val; - if (tis->loc[locty].ints == 0) { - qemu_irq_lower(tis->irq); - DPRINTF("tpm_tis: Lowering IRQ\n"); - } - } - tis->loc[locty].ints &= ~(val & TPM_TIS_INTERRUPTS_SUPPORTED); - break; - case TPM_TIS_REG_STS: - if (tis->active_locty != locty) { - break; - } - - val &= (TPM_TIS_STS_COMMAND_READY | TPM_TIS_STS_TPM_GO | - TPM_TIS_STS_RESPONSE_RETRY); - - if (val == TPM_TIS_STS_COMMAND_READY) { - switch (tis->loc[locty].state) { - - case TPM_TIS_STATE_READY: - tis->loc[locty].w_offset = 0; - tis->loc[locty].r_offset = 0; - break; - - case TPM_TIS_STATE_IDLE: - tis->loc[locty].sts = TPM_TIS_STS_COMMAND_READY; - tis->loc[locty].state = TPM_TIS_STATE_READY; - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); - break; - - case TPM_TIS_STATE_EXECUTION: - case TPM_TIS_STATE_RECEPTION: - /* abort currently running command */ - DPRINTF("tpm_tis: %s: Initiating abort.\n", - __func__); - tpm_tis_prep_abort(s, locty, locty); - break; - - case TPM_TIS_STATE_COMPLETION: - tis->loc[locty].w_offset = 0; - tis->loc[locty].r_offset = 0; - /* shortcut to ready state with C/R set */ - tis->loc[locty].state = TPM_TIS_STATE_READY; - if (!(tis->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { - tis->loc[locty].sts = TPM_TIS_STS_COMMAND_READY; - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); - } - tis->loc[locty].sts &= ~(TPM_TIS_STS_DATA_AVAILABLE); - break; - - } - } else if (val == TPM_TIS_STS_TPM_GO) { - switch (tis->loc[locty].state) { - case TPM_TIS_STATE_RECEPTION: - if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) == 0) { - tpm_tis_tpm_send(s, locty); - } - break; - default: - /* ignore */ - break; - } - } else if (val == TPM_TIS_STS_RESPONSE_RETRY) { - switch (tis->loc[locty].state) { - case TPM_TIS_STATE_COMPLETION: - tis->loc[locty].r_offset = 0; - tis->loc[locty].sts = TPM_TIS_STS_VALID | - TPM_TIS_STS_DATA_AVAILABLE; - break; - default: - /* ignore */ - break; - } - } - break; - case TPM_TIS_REG_DATA_FIFO: - /* data fifo */ - if (tis->active_locty != locty) { - break; - } - - if (tis->loc[locty].state == TPM_TIS_STATE_IDLE || - tis->loc[locty].state == TPM_TIS_STATE_EXECUTION || - tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) { - /* drop the byte */ - } else { - DPRINTF("tpm_tis: Byte to send to TPM: %02x\n", (uint8_t)val); - if (tis->loc[locty].state == TPM_TIS_STATE_READY) { - tis->loc[locty].state = TPM_TIS_STATE_RECEPTION; - tis->loc[locty].sts = TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID; - } - - if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { - if (tis->loc[locty].w_offset < tis->loc[locty].w_buffer.size) { - tis->loc[locty].w_buffer. - buffer[tis->loc[locty].w_offset++] = (uint8_t)val; - } else { - tis->loc[locty].sts = TPM_TIS_STS_VALID; - } - } - - /* check for complete packet */ - if (tis->loc[locty].w_offset > 5 && - (tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { - /* we have a packet length - see if we have all of it */ -#ifdef RAISE_STS_IRQ - bool needIrq = !(tis->loc[locty].sts & TPM_TIS_STS_VALID); -#endif - len = tpm_tis_get_size_from_buffer(&tis->loc[locty].w_buffer); - if (len > tis->loc[locty].w_offset) { - tis->loc[locty].sts = TPM_TIS_STS_EXPECT | - TPM_TIS_STS_VALID; - } else { - /* packet complete */ - tis->loc[locty].sts = TPM_TIS_STS_VALID; - } -#ifdef RAISE_STS_IRQ - if (needIrq) { - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); - } -#endif - } - } - break; - } -} - -static void tpm_tis_mmio_write(void *opaque, hwaddr addr, - uint64_t val, unsigned size) -{ - return tpm_tis_mmio_write_intern(opaque, addr, val, size, false); -} - -static const MemoryRegionOps tpm_tis_memory_ops = { - .read = tpm_tis_mmio_read, - .write = tpm_tis_mmio_write, - .endianness = DEVICE_LITTLE_ENDIAN, - .valid = { - .min_access_size = 1, - .max_access_size = 4, - }, -}; - -static int tpm_tis_do_startup_tpm(TPMState *s) -{ - return tpm_backend_startup_tpm(s->be_driver); -} - -/* - * This function is called when the machine starts, resets or due to - * S3 resume. - */ -static void tpm_tis_reset(DeviceState *dev) -{ - TPMState *s = TPM(dev); - TPMTISEmuState *tis = &s->s.tis; - int c; - - tpm_backend_reset(s->be_driver); - - tis->active_locty = TPM_TIS_NO_LOCALITY; - tis->next_locty = TPM_TIS_NO_LOCALITY; - tis->aborting_locty = TPM_TIS_NO_LOCALITY; - - for (c = 0; c < TPM_TIS_NUM_LOCALITIES; c++) { - tis->loc[c].access = TPM_TIS_ACCESS_TPM_REG_VALID_STS; - tis->loc[c].sts = 0; - tis->loc[c].inte = TPM_TIS_INT_POLARITY_LOW_LEVEL; - tis->loc[c].ints = 0; - tis->loc[c].state = TPM_TIS_STATE_IDLE; - - tis->loc[c].w_offset = 0; - tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].w_buffer); - tis->loc[c].r_offset = 0; - tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].r_buffer); - } - - tpm_tis_do_startup_tpm(s); -} - -static const VMStateDescription vmstate_tpm_tis = { - .name = "tpm", - .unmigratable = 1, -}; - -static Property tpm_tis_properties[] = { - DEFINE_PROP_UINT32("irq", TPMState, - s.tis.irq_num, TPM_TIS_IRQ), - DEFINE_PROP_STRING("tpmdev", TPMState, backend), - DEFINE_PROP_END_OF_LIST(), -}; - -static void tpm_tis_realizefn(DeviceState *dev, Error **errp) -{ - TPMState *s = TPM(dev); - TPMTISEmuState *tis = &s->s.tis; - - s->be_driver = qemu_find_tpm(s->backend); - if (!s->be_driver) { - error_setg(errp, "tpm_tis: backend driver with id %s could not be " - "found", s->backend); - return; - } - - s->be_driver->fe_model = TPM_MODEL_TPM_TIS; - - if (tpm_backend_init(s->be_driver, s, tpm_tis_receive_cb)) { - error_setg(errp, "tpm_tis: backend driver with id %s could not be " - "initialized", s->backend); - return; - } - - if (tis->irq_num > 15) { - error_setg(errp, "tpm_tis: IRQ %d for TPM TIS is outside valid range " - "of 0 to 15.\n", tis->irq_num); - return; - } - - tis->bh = qemu_bh_new(tpm_tis_receive_bh, s); - - isa_init_irq(&s->busdev, &tis->irq, tis->irq_num); -} - -static void tpm_tis_initfn(Object *obj) -{ - ISADevice *dev = ISA_DEVICE(obj); - TPMState *s = TPM(obj); - - memory_region_init_io(&s->mmio, &tpm_tis_memory_ops, s, "tpm-tis-mmio", - TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); - memory_region_add_subregion(isa_address_space(dev), TPM_TIS_ADDR_BASE, - &s->mmio); -} - -static void tpm_tis_uninitfn(Object *obj) -{ - TPMState *s = TPM(obj); - - memory_region_del_subregion(get_system_memory(), &s->mmio); - memory_region_destroy(&s->mmio); -} - -static void tpm_tis_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - - dc->realize = tpm_tis_realizefn; - dc->props = tpm_tis_properties; - dc->reset = tpm_tis_reset; - dc->vmsd = &vmstate_tpm_tis; -} - -static const TypeInfo tpm_tis_info = { - .name = TYPE_TPM_TIS, - .parent = TYPE_ISA_DEVICE, - .instance_size = sizeof(TPMState), - .instance_init = tpm_tis_initfn, - .instance_finalize = tpm_tis_uninitfn, - .class_init = tpm_tis_class_init, -}; - -static void tpm_tis_register(void) -{ - type_register_static(&tpm_tis_info); - tpm_register_model(TPM_MODEL_TPM_TIS); -} - -type_init(tpm_tis_register) diff --git a/tpm/tpm_tis.h b/tpm/tpm_tis.h deleted file mode 100644 index 1be4ddc8a1..0000000000 --- a/tpm/tpm_tis.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * tpm_tis.h - QEMU's TPM TIS interface emulator - * - * Copyright (C) 2006, 2010-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * David Safford - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - * - * Implementation of the TIS interface according to specs found at - * http://www.trustedcomputinggroup.org - * - */ -#ifndef TPM_TPM_TIS_H -#define TPM_TPM_TIS_H - -#include "hw/isa/isa.h" -#include "qemu-common.h" - -#define TPM_TIS_ADDR_BASE 0xFED40000 - -#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ -#define TPM_TIS_LOCALITY_SHIFT 12 -#define TPM_TIS_NO_LOCALITY 0xff - -#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) - -#define TPM_TIS_IRQ 5 - -#define TPM_TIS_BUFFER_MAX 4096 - -#define TYPE_TPM_TIS "tpm-tis" - - -struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -}; - -typedef enum { - TPM_TIS_STATE_IDLE = 0, - TPM_TIS_STATE_READY, - TPM_TIS_STATE_COMPLETION, - TPM_TIS_STATE_EXECUTION, - TPM_TIS_STATE_RECEPTION, -} TPMTISState; - -/* locality data -- all fields are persisted */ -typedef struct TPMLocality { - TPMTISState state; - uint8_t access; - uint8_t sts; - uint32_t inte; - uint32_t ints; - - uint16_t w_offset; - uint16_t r_offset; - TPMSizedBuffer w_buffer; - TPMSizedBuffer r_buffer; -} TPMLocality; - -typedef struct TPMTISEmuState { - QEMUBH *bh; - uint32_t offset; - uint8_t buf[TPM_TIS_BUFFER_MAX]; - - uint8_t active_locty; - uint8_t aborting_locty; - uint8_t next_locty; - - TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; - - qemu_irq irq; - uint32_t irq_num; -} TPMTISEmuState; - -#endif /* TPM_TPM_TIS_H */ diff --git a/vl.c b/vl.c index d694a9039b..ce7bed7141 100644 --- a/vl.c +++ b/vl.c @@ -139,7 +139,7 @@ int main(int argc, char **argv) #include "sysemu/blockdev.h" #include "hw/block/block.h" #include "migration/block.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #include "sysemu/dma.h" #include "audio/audio.h" #include "migration/migration.h" -- cgit v1.2.3 From dccfcd0e5f8f37360ebda11ccc4dab164c04d5a3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Apr 2013 16:55:25 +0200 Subject: sysemu: avoid proliferation of include/ subdirectories Signed-off-by: Paolo Bonzini --- backends/baum.c | 2 +- backends/msmouse.c | 2 +- backends/rng-egd.c | 4 +- backends/rng-random.c | 4 +- backends/rng.c | 2 +- backends/tpm.c | 2 +- bt-host.c | 2 +- bt-vhci.c | 2 +- gdbstub.c | 2 +- hmp.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/strongarm.c | 2 +- hw/bt/core.c | 2 +- hw/bt/hci-csr.c | 4 +- hw/bt/hci.c | 2 +- hw/char/cadence_uart.c | 2 +- hw/char/debugcon.c | 2 +- hw/char/escc.c | 2 +- hw/char/etraxfs_ser.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/grlib_apbuart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/ipoctal232.c | 2 +- hw/char/lm32_juart.c | 2 +- hw/char/lm32_uart.c | 2 +- hw/char/mcf_uart.c | 2 +- hw/char/milkymist-uart.c | 2 +- hw/char/omap_uart.c | 2 +- hw/char/parallel.c | 2 +- hw/char/pl011.c | 2 +- hw/char/sclpconsole.c | 2 +- hw/char/serial.c | 2 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/char/xen_console.c | 2 +- hw/char/xilinx_uartlite.c | 2 +- hw/core/qdev-properties-system.c | 2 +- hw/core/qdev-properties.c | 2 +- hw/display/xenfb.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/misc/ivshmem.c | 2 +- hw/net/xgmac.c | 2 +- hw/ppc/spapr_events.c | 2 +- hw/ppc/spapr_rtas.c | 2 +- hw/sparc/leon3.c | 2 +- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 2 +- hw/usb/ccid-card-emulated.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-bluetooth.c | 2 +- hw/usb/dev-serial.c | 2 +- hw/usb/redirect.c | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/xen/xen_backend.c | 2 +- hw/xtensa/xtensa_lx60.c | 2 +- include/backends/tpm.h | 209 -------------------------- include/bt/bt.h | 20 --- include/char/char.h | 306 --------------------------------------- include/hw/virtio/virtio-rng.h | 4 +- include/qemu/rng-random.h | 22 --- include/qemu/rng.h | 93 ------------ include/sysemu/bt.h | 20 +++ include/sysemu/char.h | 306 +++++++++++++++++++++++++++++++++++++++ include/sysemu/rng-random.h | 22 +++ include/sysemu/rng.h | 93 ++++++++++++ include/sysemu/tpm_backend.h | 209 ++++++++++++++++++++++++++ monitor.c | 2 +- net/slirp.c | 2 +- qemu-char.c | 2 +- qmp.c | 2 +- qtest.c | 2 +- slirp/slirp.c | 2 +- spice-qemu-char.c | 2 +- tpm.c | 2 +- ui/console.c | 2 +- ui/gtk.c | 2 +- util/event_notifier-posix.c | 2 +- vl.c | 4 +- xen-all.c | 2 +- 83 files changed, 728 insertions(+), 728 deletions(-) delete mode 100644 include/backends/tpm.h delete mode 100644 include/bt/bt.h delete mode 100644 include/char/char.h delete mode 100644 include/qemu/rng-random.h delete mode 100644 include/qemu/rng.h create mode 100644 include/sysemu/bt.h create mode 100644 include/sysemu/char.h create mode 100644 include/sysemu/rng-random.h create mode 100644 include/sysemu/rng.h create mode 100644 include/sysemu/tpm_backend.h diff --git a/backends/baum.c b/backends/baum.c index ea9ffe88fb..4cba79fc7d 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #include "qemu-common.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/timer.h" #include "hw/usb.h" #include diff --git a/backends/msmouse.c b/backends/msmouse.c index 61052fe783..0ac05a0d10 100644 --- a/backends/msmouse.c +++ b/backends/msmouse.c @@ -23,7 +23,7 @@ */ #include #include "qemu-common.h" -#include "char/char.h" +#include "sysemu/char.h" #include "ui/console.h" #define MSMOUSE_LO6(n) ((n) & 0x3f) diff --git a/backends/rng-egd.c b/backends/rng-egd.c index cc6f5ee28e..9e5a5366f7 100644 --- a/backends/rng-egd.c +++ b/backends/rng-egd.c @@ -10,8 +10,8 @@ * See the COPYING file in the top-level directory. */ -#include "qemu/rng.h" -#include "char/char.h" +#include "sysemu/rng.h" +#include "sysemu/char.h" #include "qapi/qmp/qerror.h" #include "hw/qdev.h" /* just for DEFINE_PROP_CHR */ diff --git a/backends/rng-random.c b/backends/rng-random.c index acd20afad2..d5761f2cce 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -10,8 +10,8 @@ * See the COPYING file in the top-level directory. */ -#include "qemu/rng-random.h" -#include "qemu/rng.h" +#include "sysemu/rng-random.h" +#include "sysemu/rng.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" diff --git a/backends/rng.c b/backends/rng.c index 3d3389802e..85cb83f5e1 100644 --- a/backends/rng.c +++ b/backends/rng.c @@ -10,7 +10,7 @@ * See the COPYING file in the top-level directory. */ -#include "qemu/rng.h" +#include "sysemu/rng.h" #include "qapi/qmp/qerror.h" void rng_backend_request_entropy(RngBackend *s, size_t size, diff --git a/backends/tpm.c b/backends/tpm.c index 0580108c5f..b73580134c 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -12,7 +12,7 @@ * Based on backends/rng.c by Anthony Liguori */ -#include "backends/tpm.h" +#include "sysemu/tpm_backend.h" #include "qapi/qmp/qerror.h" #include "sysemu/tpm.h" #include "qemu/thread.h" diff --git a/bt-host.c b/bt-host.c index 2da3c32204..49205bf288 100644 --- a/bt-host.c +++ b/bt-host.c @@ -18,7 +18,7 @@ */ #include "qemu-common.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "qemu/main-loop.h" #ifndef _WIN32 diff --git a/bt-vhci.c b/bt-vhci.c index a6a7ab0329..e267c8ad15 100644 --- a/bt-vhci.c +++ b/bt-vhci.c @@ -18,7 +18,7 @@ */ #include "qemu-common.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "hw/bt.h" #include "qemu/main-loop.h" diff --git a/gdbstub.c b/gdbstub.c index 22ab12c68c..e80e1d32b1 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -30,7 +30,7 @@ #include "qemu.h" #else #include "monitor/monitor.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/sysemu.h" #include "exec/gdbstub.h" #endif diff --git a/hmp.c b/hmp.c index dbe9b9043e..1675e77cf0 100644 --- a/hmp.c +++ b/hmp.c @@ -15,7 +15,7 @@ #include "hmp.h" #include "net/net.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/option.h" #include "qemu/timer.h" #include "qmp-commands.h" diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index a4b414621d..2ff43710e4 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -24,7 +24,7 @@ #include "hw/arm/omap.h" #include "sysemu/sysemu.h" #include "qemu/timer.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/block/flash.h" #include "hw/arm/soc_dma.h" #include "hw/sysbus.h" diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c index bbecc770ed..24b03a0d29 100644 --- a/hw/arm/pxa2xx.c +++ b/hw/arm/pxa2xx.c @@ -13,7 +13,7 @@ #include "hw/char/serial.h" #include "hw/i2c/i2c.h" #include "hw/ssi.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/blockdev.h" static struct { diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c index 75a813e618..4d49306dd0 100644 --- a/hw/arm/strongarm.c +++ b/hw/arm/strongarm.c @@ -30,7 +30,7 @@ #include "strongarm.h" #include "qemu/error-report.h" #include "hw/arm/arm.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/sysemu.h" #include "hw/ssi.h" diff --git a/hw/bt/core.c b/hw/bt/core.c index 24ef4de49d..49012e028c 100644 --- a/hw/bt/core.c +++ b/hw/bt/core.c @@ -18,7 +18,7 @@ */ #include "qemu-common.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "hw/bt.h" /* Slave implementations can ignore this */ diff --git a/hw/bt/hci-csr.c b/hw/bt/hci-csr.c index 55c819b085..16a25cb349 100644 --- a/hw/bt/hci-csr.c +++ b/hw/bt/hci-csr.c @@ -19,10 +19,10 @@ */ #include "qemu-common.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/timer.h" #include "hw/irq.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "hw/bt.h" struct csrhci_s { diff --git a/hw/bt/hci.c b/hw/bt/hci.c index a76edea2c9..b53cd5dea2 100644 --- a/hw/bt/hci.c +++ b/hw/bt/hci.c @@ -21,7 +21,7 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "hw/usb.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "hw/bt.h" struct bt_hci_s { diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index 421ec998d6..c2a783430b 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -17,7 +17,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/timer.h" #ifdef CADENCE_UART_ERR_DEBUG diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c index 0588eebb77..02c9577024 100644 --- a/hw/char/debugcon.c +++ b/hw/char/debugcon.c @@ -25,7 +25,7 @@ */ #include "hw/hw.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/isa/isa.h" #include "hw/i386/pc.h" diff --git a/hw/char/escc.c b/hw/char/escc.c index 067b055fee..c2cb07f3bd 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -25,7 +25,7 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "hw/char/escc.h" -#include "char/char.h" +#include "sysemu/char.h" #include "ui/console.h" #include "trace.h" diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c index b7499d775b..11820f5864 100644 --- a/hw/char/etraxfs_ser.c +++ b/hw/char/etraxfs_ser.c @@ -23,7 +23,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/log.h" #define D(x) diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c index 8b4e72ca11..5751816c62 100644 --- a/hw/char/exynos4210_uart.c +++ b/hw/char/exynos4210_uart.c @@ -21,7 +21,7 @@ #include "hw/sysbus.h" #include "sysemu/sysemu.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/arm/exynos4210.h" diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c index 62f799083c..a64453fb18 100644 --- a/hw/char/grlib_apbuart.c +++ b/hw/char/grlib_apbuart.c @@ -23,7 +23,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" #include "trace.h" diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c index d7ec2090fd..2a2c230c55 100644 --- a/hw/char/imx_serial.c +++ b/hw/char/imx_serial.c @@ -20,7 +20,7 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/arm/imx.h" //#define DEBUG_SERIAL 1 diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c index fcd0af31b4..c9698a6bc4 100644 --- a/hw/char/ipoctal232.c +++ b/hw/char/ipoctal232.c @@ -10,7 +10,7 @@ #include "ipack.h" #include "qemu/bitops.h" -#include "char/char.h" +#include "sysemu/char.h" /* #define DEBUG_IPOCTAL */ diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c index 93f0d1534e..839f3ebfe7 100644 --- a/hw/char/lm32_juart.c +++ b/hw/char/lm32_juart.c @@ -20,7 +20,7 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "trace.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/lm32/lm32_juart.h" diff --git a/hw/char/lm32_uart.c b/hw/char/lm32_uart.c index 32bc37ac96..99721ab78d 100644 --- a/hw/char/lm32_uart.c +++ b/hw/char/lm32_uart.c @@ -25,7 +25,7 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "trace.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/error-report.h" enum { diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c index 6724b1b718..3ec4705867 100644 --- a/hw/char/mcf_uart.c +++ b/hw/char/mcf_uart.c @@ -7,7 +7,7 @@ */ #include "hw/hw.h" #include "hw/m68k/mcf.h" -#include "char/char.h" +#include "sysemu/char.h" #include "exec/address-spaces.h" typedef struct { diff --git a/hw/char/milkymist-uart.c b/hw/char/milkymist-uart.c index f3bdf6991a..cbc7d73a6e 100644 --- a/hw/char/milkymist-uart.c +++ b/hw/char/milkymist-uart.c @@ -24,7 +24,7 @@ #include "hw/hw.h" #include "hw/sysbus.h" #include "trace.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/error-report.h" enum { diff --git a/hw/char/omap_uart.c b/hw/char/omap_uart.c index 26c14266fc..5bb36ed2c1 100644 --- a/hw/char/omap_uart.c +++ b/hw/char/omap_uart.c @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License along * with this program; if not, see . */ -#include "char/char.h" +#include "sysemu/char.h" #include "hw/hw.h" #include "hw/arm/omap.h" #include "hw/char/serial.h" diff --git a/hw/char/parallel.c b/hw/char/parallel.c index 863a6fb4a9..b5e867f21c 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -23,7 +23,7 @@ * THE SOFTWARE. */ #include "hw/hw.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/isa/isa.h" #include "hw/i386/pc.h" #include "sysemu/sysemu.h" diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 332d5b970c..7079ef6be1 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -8,7 +8,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" typedef struct { SysBusDevice busdev; diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c index 42ed54c9ab..bcc7893230 100644 --- a/hw/char/sclpconsole.c +++ b/hw/char/sclpconsole.c @@ -18,7 +18,7 @@ #include "hw/s390x/sclp.h" #include "hw/s390x/event-facility.h" -#include "char/char.h" +#include "sysemu/char.h" typedef struct ASCIIConsoleData { EventBufferHeader ebh; diff --git a/hw/char/serial.c b/hw/char/serial.c index 1151bf1bab..66b6348867 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -24,7 +24,7 @@ */ #include "hw/char/serial.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/timer.h" #include "exec/address-spaces.h" diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c index 450c7d8551..b3286438ca 100644 --- a/hw/char/sh_serial.c +++ b/hw/char/sh_serial.c @@ -26,7 +26,7 @@ */ #include "hw/hw.h" #include "hw/sh4/sh.h" -#include "char/char.h" +#include "sysemu/char.h" #include "exec/address-spaces.h" //#define DEBUG_SERIAL diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 9df018a230..afcec1f182 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -1,5 +1,5 @@ #include "hw/qdev.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 31f672c9a3..50350303cd 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -10,7 +10,7 @@ * the COPYING file in the top-level directory. */ -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/error-report.h" #include "trace.h" #include "hw/virtio/virtio-serial.h" diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index efc32320fa..eb7f450aba 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -30,7 +30,7 @@ #include #include "hw/hw.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/xen/xen_backend.h" #include diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c index 079f4d4e1a..3f7e989f35 100644 --- a/hw/char/xilinx_uartlite.c +++ b/hw/char/xilinx_uartlite.c @@ -23,7 +23,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" #define DUART(x) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 8c2e15205c..0eada32dcf 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -17,7 +17,7 @@ #include "hw/block/block.h" #include "net/hub.h" #include "qapi/visitor.h" -#include "char/char.h" +#include "sysemu/char.h" static void get_pointer(Object *obj, Visitor *v, Property *prop, const char *(*print)(void *ptr), diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 9a0872d3b9..ddde18e6b4 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -5,7 +5,7 @@ #include "hw/block/block.h" #include "net/hub.h" #include "qapi/visitor.h" -#include "char/char.h" +#include "sysemu/char.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 8e4266142d..e371569585 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -37,7 +37,7 @@ #include "hw/hw.h" #include "ui/console.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/xen/xen_backend.h" #include diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c index 9f5e185685..82f7c80f9c 100644 --- a/hw/isa/pc87312.c +++ b/hw/isa/pc87312.c @@ -27,7 +27,7 @@ #include "qemu/error-report.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" -#include "char/char.h" +#include "sysemu/char.h" #include "trace.h" diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 3cf27fa822..1aac93a414 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -30,7 +30,7 @@ #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" #include "hw/pci/pci.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/sysemu.h" #include "audio/audio.h" #include "qemu/log.h" diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index a3e936b77f..86f42b2ede 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -34,7 +34,7 @@ #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" #include "hw/pci/pci.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/sysemu.h" #include "sysemu/arch_init.h" #include "hw/boards.h" diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index f92ce19dde..a19a6d6d8c 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -24,7 +24,7 @@ #include "migration/migration.h" #include "qapi/qmp/qerror.h" #include "qemu/event_notifier.h" -#include "char/char.h" +#include "sysemu/char.h" #include #include diff --git a/hw/net/xgmac.c b/hw/net/xgmac.c index 5275f4810d..1d9074a1d0 100644 --- a/hw/net/xgmac.c +++ b/hw/net/xgmac.c @@ -25,7 +25,7 @@ */ #include "hw/sysbus.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/log.h" #include "net/net.h" #include "net/checksum.h" diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index ff87ac31d1..c0d7e62f32 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -26,7 +26,7 @@ */ #include "cpu.h" #include "sysemu/sysemu.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/qdev.h" #include "sysemu/device_tree.h" diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index b71b59c5cf..8ecaa5f8ec 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -26,7 +26,7 @@ */ #include "cpu.h" #include "sysemu/sysemu.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/qdev.h" #include "sysemu/device_tree.h" diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c index 3b27d4019a..78c77eff46 100644 --- a/hw/sparc/leon3.c +++ b/hw/sparc/leon3.c @@ -24,7 +24,7 @@ #include "hw/hw.h" #include "qemu/timer.h" #include "hw/ptimer.h" -#include "char/char.h" +#include "sysemu/char.h" #include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/loader.h" diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 578127723f..416b9b65c7 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -27,7 +27,7 @@ #include "qemu-common.h" #include "qapi/error.h" #include "qemu/sockets.h" -#include "backends/tpm.h" +#include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "hw/hw.h" #include "hw/i386/pc.h" diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index faa3cecafe..d4d8152875 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -19,7 +19,7 @@ * specification. */ -#include "backends/tpm.h" +#include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "block/block.h" #include "exec/address-spaces.h" diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index 29dcd7acbf..d534c94c1a 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -32,7 +32,7 @@ #include #include "qemu/thread.h" -#include "char/char.h" +#include "sysemu/char.h" #include "monitor/monitor.h" #include "ccid.h" diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 5e017ae0ca..71a45f674f 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -8,7 +8,7 @@ * See the COPYING file in the top-level directory. */ -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/sockets.h" #include "monitor/monitor.h" #include "ccid.h" diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c index 0f8aa48c85..68cc1d4fab 100644 --- a/hw/usb/dev-bluetooth.c +++ b/hw/usb/dev-bluetooth.c @@ -21,7 +21,7 @@ #include "qemu-common.h" #include "hw/usb.h" #include "hw/usb/desc.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "hw/bt.h" struct USBBtState { diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index 7c314dc59d..dd0a608bff 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -12,7 +12,7 @@ #include "qemu/error-report.h" #include "hw/usb.h" #include "hw/usb/desc.h" -#include "char/char.h" +#include "sysemu/char.h" //#define DEBUG_Serial diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 0ddb0818d8..a594e954e4 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -30,7 +30,7 @@ #include "monitor/monitor.h" #include "sysemu/sysemu.h" #include "qemu/iov.h" -#include "char/char.h" +#include "sysemu/char.h" #include #include diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index 6079b2a3a9..fcc223af06 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -14,7 +14,7 @@ #include "qapi/qmp/qerror.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-rng.h" -#include "qemu/rng.h" +#include "sysemu/rng.h" static bool is_guest_ready(VirtIORNG *vrng) { diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 2a8c9f5d1a..d82ce5d8a6 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -35,7 +35,7 @@ #include #include "hw/hw.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/log.h" #include "hw/xen/xen_backend.h" diff --git a/hw/xtensa/xtensa_lx60.c b/hw/xtensa/xtensa_lx60.c index 2682eda2ad..650dd31c98 100644 --- a/hw/xtensa/xtensa_lx60.c +++ b/hw/xtensa/xtensa_lx60.c @@ -36,7 +36,7 @@ #include "hw/sysbus.h" #include "hw/block/flash.h" #include "sysemu/blockdev.h" -#include "char/char.h" +#include "sysemu/char.h" #include "xtensa_bootparam.h" typedef struct LxBoardDesc { diff --git a/include/backends/tpm.h b/include/backends/tpm.h deleted file mode 100644 index 466787453d..0000000000 --- a/include/backends/tpm.h +++ /dev/null @@ -1,209 +0,0 @@ -/* - * QEMU TPM Backend - * - * Copyright IBM, Corp. 2013 - * - * Authors: - * Stefan Berger - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ - -#ifndef _QEMU_TPM_H -#define _QEMU_TPM_H - -#include "qom/object.h" -#include "qemu-common.h" -#include "qapi/error.h" -#include "qapi-types.h" -#include "qemu/option.h" -#include "sysemu/tpm.h" - -#define TYPE_TPM_BACKEND "tpm-backend" -#define TPM_BACKEND(obj) \ - OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND) -#define TPM_BACKEND_GET_CLASS(obj) \ - OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND) -#define TPM_BACKEND_CLASS(klass) \ - OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND) - -typedef struct TPMBackendClass TPMBackendClass; -typedef struct TPMBackend TPMBackend; - -typedef struct TPMDriverOps TPMDriverOps; - -struct TPMBackendClass { - ObjectClass parent_class; - - const TPMDriverOps *ops; - - void (*opened)(TPMBackend *s, Error **errp); -}; - -struct TPMBackend { - Object parent; - - /*< protected >*/ - bool opened; - - char *id; - enum TpmModel fe_model; - char *path; - char *cancel_path; - const TPMDriverOps *ops; - - QLIST_ENTRY(TPMBackend) list; -}; - -typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); - -typedef struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -} TPMSizedBuffer; - -struct TPMDriverOps { - enum TpmType type; - /* get a descriptive text of the backend to display to the user */ - const char *(*desc)(void); - - TPMBackend *(*create)(QemuOpts *opts, const char *id); - void (*destroy)(TPMBackend *t); - - /* initialize the backend */ - int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb); - /* start up the TPM on the backend */ - int (*startup_tpm)(TPMBackend *t); - /* returns true if nothing will ever answer TPM requests */ - bool (*had_startup_error)(TPMBackend *t); - - size_t (*realloc_buffer)(TPMSizedBuffer *sb); - - void (*deliver_request)(TPMBackend *t); - - void (*reset)(TPMBackend *t); - - void (*cancel_cmd)(TPMBackend *t); - - bool (*get_tpm_established_flag)(TPMBackend *t); -}; - - -/** - * tpm_backend_get_type: - * @s: the backend - * - * Returns the TpmType of the backend. - */ -enum TpmType tpm_backend_get_type(TPMBackend *s); - -/** - * tpm_backend_get_desc: - * @s: the backend - * - * Returns a human readable description of the backend. - */ -const char *tpm_backend_get_desc(TPMBackend *s); - -/** - * tpm_backend_destroy: - * @s: the backend to destroy - */ -void tpm_backend_destroy(TPMBackend *s); - -/** - * tpm_backend_init: - * @s: the backend to initialized - * @state: TPMState - * @datacb: callback for sending data to frontend - * - * Initialize the backend with the given variables. - * - * Returns 0 on success. - */ -int tpm_backend_init(TPMBackend *s, TPMState *state, - TPMRecvDataCB *datacb); - -/** - * tpm_backend_startup_tpm: - * @s: the backend whose TPM support is to be started - * - * Returns 0 on success. - */ -int tpm_backend_startup_tpm(TPMBackend *s); - -/** - * tpm_backend_had_startup_error: - * @s: the backend to query for a statup error - * - * Check whether the backend had an error during startup. Returns - * false if no error occurred and the backend can be used, true - * otherwise. - */ -bool tpm_backend_had_startup_error(TPMBackend *s); - -/** - * tpm_backend_realloc_buffer: - * @s: the backend - * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the - * backend. - * - * This function returns the size of the allocated buffer - */ -size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb); - -/** - * tpm_backend_deliver_request: - * @s: the backend to send the request to - * - * Send a request to the backend. The backend will then send the request - * to the TPM implementation. - */ -void tpm_backend_deliver_request(TPMBackend *s); - -/** - * tpm_backend_reset: - * @s: the backend to reset - * - * Reset the backend into a well defined state with all previous errors - * reset. - */ -void tpm_backend_reset(TPMBackend *s); - -/** - * tpm_backend_cancel_cmd: - * @s: the backend - * - * Cancel any ongoing command being processed by the TPM implementation - * on behalf of the QEMU guest. - */ -void tpm_backend_cancel_cmd(TPMBackend *s); - -/** - * tpm_backend_get_tpm_established_flag: - * @s: the backend - * - * Get the TPM establishment flag. This function may be called very - * frequently by the frontend since for example in the TIS implementation - * this flag is part of a register. - */ -bool tpm_backend_get_tpm_established_flag(TPMBackend *s); - -/** - * tpm_backend_open: - * @s: the backend to open - * @errp: a pointer to return the #Error object if an error occurs. - * - * This function will open the backend if it is not already open. Calling this - * function on an already opened backend will not result in an error. - */ -void tpm_backend_open(TPMBackend *s, Error **errp); - -TPMBackend *qemu_find_tpm(const char *id); - -const TPMDriverOps *tpm_get_backend_driver(const char *type); -int tpm_register_model(enum TpmModel model); -int tpm_register_driver(const TPMDriverOps *tdo); - -#endif diff --git a/include/bt/bt.h b/include/bt/bt.h deleted file mode 100644 index 2bc6d53cca..0000000000 --- a/include/bt/bt.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef BT_HOST_H -#define BT_HOST_H - -/* BT HCI info */ - -struct HCIInfo { - int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); - void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); - void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); - void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); - void *opaque; - void (*evt_recv)(void *opaque, const uint8_t *data, int len); - void (*acl_recv)(void *opaque, const uint8_t *data, int len); -}; - -/* bt-host.c */ -struct HCIInfo *bt_host_hci(const char *id); -struct HCIInfo *qemu_next_hci(void); - -#endif diff --git a/include/char/char.h b/include/char/char.h deleted file mode 100644 index 9d1ea46117..0000000000 --- a/include/char/char.h +++ /dev/null @@ -1,306 +0,0 @@ -#ifndef QEMU_CHAR_H -#define QEMU_CHAR_H - -#include "qemu-common.h" -#include "qemu/queue.h" -#include "qemu/option.h" -#include "qemu/config-file.h" -#include "block/aio.h" -#include "qapi/qmp/qobject.h" -#include "qapi/qmp/qstring.h" -#include "qemu/main-loop.h" - -/* character device */ - -#define CHR_EVENT_BREAK 0 /* serial break char */ -#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ -#define CHR_EVENT_OPENED 2 /* new connection established */ -#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */ -#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */ -#define CHR_EVENT_CLOSED 5 /* connection closed */ - - -#define CHR_IOCTL_SERIAL_SET_PARAMS 1 -typedef struct { - int speed; - int parity; - int data_bits; - int stop_bits; -} QEMUSerialSetParams; - -#define CHR_IOCTL_SERIAL_SET_BREAK 2 - -#define CHR_IOCTL_PP_READ_DATA 3 -#define CHR_IOCTL_PP_WRITE_DATA 4 -#define CHR_IOCTL_PP_READ_CONTROL 5 -#define CHR_IOCTL_PP_WRITE_CONTROL 6 -#define CHR_IOCTL_PP_READ_STATUS 7 -#define CHR_IOCTL_PP_EPP_READ_ADDR 8 -#define CHR_IOCTL_PP_EPP_READ 9 -#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10 -#define CHR_IOCTL_PP_EPP_WRITE 11 -#define CHR_IOCTL_PP_DATA_DIR 12 - -#define CHR_IOCTL_SERIAL_SET_TIOCM 13 -#define CHR_IOCTL_SERIAL_GET_TIOCM 14 - -#define CHR_TIOCM_CTS 0x020 -#define CHR_TIOCM_CAR 0x040 -#define CHR_TIOCM_DSR 0x100 -#define CHR_TIOCM_RI 0x080 -#define CHR_TIOCM_DTR 0x002 -#define CHR_TIOCM_RTS 0x004 - -typedef void IOEventHandler(void *opaque, int event); - -struct CharDriverState { - void (*init)(struct CharDriverState *s); - int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); - GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); - void (*chr_update_read_handler)(struct CharDriverState *s); - int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); - int (*get_msgfd)(struct CharDriverState *s); - int (*chr_add_client)(struct CharDriverState *chr, int fd); - IOEventHandler *chr_event; - IOCanReadHandler *chr_can_read; - IOReadHandler *chr_read; - void *handler_opaque; - void (*chr_close)(struct CharDriverState *chr); - void (*chr_accept_input)(struct CharDriverState *chr); - void (*chr_set_echo)(struct CharDriverState *chr, bool echo); - void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); - void *opaque; - int idle_tag; - char *label; - char *filename; - int be_open; - int fe_open; - int explicit_fe_open; - int avail_connections; - QemuOpts *opts; - QTAILQ_ENTRY(CharDriverState) next; -}; - -/** - * @qemu_chr_new_from_opts: - * - * Create a new character backend from a QemuOpts list. - * - * @opts see qemu-config.c for a list of valid options - * @init not sure.. - * - * Returns: a new character backend - */ -CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, - void (*init)(struct CharDriverState *s), - Error **errp); - -/** - * @qemu_chr_new: - * - * Create a new character backend from a URI. - * - * @label the name of the backend - * @filename the URI - * @init not sure.. - * - * Returns: a new character backend - */ -CharDriverState *qemu_chr_new(const char *label, const char *filename, - void (*init)(struct CharDriverState *s)); - -/** - * @qemu_chr_delete: - * - * Destroy a character backend. - */ -void qemu_chr_delete(CharDriverState *chr); - -/** - * @qemu_chr_fe_set_echo: - * - * Ask the backend to override its normal echo setting. This only really - * applies to the stdio backend and is used by the QMP server such that you - * can see what you type if you try to type QMP commands. - * - * @echo true to enable echo, false to disable echo - */ -void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo); - -/** - * @qemu_chr_fe_set_open: - * - * Set character frontend open status. This is an indication that the - * front end is ready (or not) to begin doing I/O. - */ -void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open); - -/** - * @qemu_chr_fe_printf: - * - * Write to a character backend using a printf style interface. - * - * @fmt see #printf - */ -void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...) - GCC_FMT_ATTR(2, 3); - -int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, - GIOFunc func, void *user_data); - -/** - * @qemu_chr_fe_write: - * - * Write data to a character backend from the front end. This function will - * send data from the front end to the back end. - * - * @buf the data - * @len the number of bytes to send - * - * Returns: the number of bytes consumed - */ -int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); - -/** - * @qemu_chr_fe_write_all: - * - * Write data to a character backend from the front end. This function will - * send data from the front end to the back end. Unlike @qemu_chr_fe_write, - * this function will block if the back end cannot consume all of the data - * attempted to be written. - * - * @buf the data - * @len the number of bytes to send - * - * Returns: the number of bytes consumed - */ -int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); - -/** - * @qemu_chr_fe_ioctl: - * - * Issue a device specific ioctl to a backend. - * - * @cmd see CHR_IOCTL_* - * @arg the data associated with @cmd - * - * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the - * return value depends on the semantics of @cmd - */ -int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg); - -/** - * @qemu_chr_fe_get_msgfd: - * - * For backends capable of fd passing, return the latest file descriptor passed - * by a client. - * - * Returns: -1 if fd passing isn't supported or there is no pending file - * descriptor. If a file descriptor is returned, subsequent calls to - * this function will return -1 until a client sends a new file - * descriptor. - */ -int qemu_chr_fe_get_msgfd(CharDriverState *s); - -/** - * @qemu_chr_fe_claim: - * - * Claim a backend before using it, should be called before calling - * qemu_chr_add_handlers(). - * - * Returns: -1 if the backend is already in use by another frontend, 0 on - * success. - */ -int qemu_chr_fe_claim(CharDriverState *s); - -/** - * @qemu_chr_fe_claim_no_fail: - * - * Like qemu_chr_fe_claim, but will exit qemu with an error when the - * backend is already in use. - */ -void qemu_chr_fe_claim_no_fail(CharDriverState *s); - -/** - * @qemu_chr_fe_claim: - * - * Release a backend for use by another frontend. - * - * Returns: -1 if the backend is already in use by another frontend, 0 on - * success. - */ -void qemu_chr_fe_release(CharDriverState *s); - -/** - * @qemu_chr_be_can_write: - * - * Determine how much data the front end can currently accept. This function - * returns the number of bytes the front end can accept. If it returns 0, the - * front end cannot receive data at the moment. The function must be polled - * to determine when data can be received. - * - * Returns: the number of bytes the front end can receive via @qemu_chr_be_write - */ -int qemu_chr_be_can_write(CharDriverState *s); - -/** - * @qemu_chr_be_write: - * - * Write data from the back end to the front end. Before issuing this call, - * the caller should call @qemu_chr_be_can_write to determine how much data - * the front end can currently accept. - * - * @buf a buffer to receive data from the front end - * @len the number of bytes to receive from the front end - */ -void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len); - - -/** - * @qemu_chr_be_event: - * - * Send an event from the back end to the front end. - * - * @event the event to send - */ -void qemu_chr_be_event(CharDriverState *s, int event); - -void qemu_chr_add_handlers(CharDriverState *s, - IOCanReadHandler *fd_can_read, - IOReadHandler *fd_read, - IOEventHandler *fd_event, - void *opaque); - -void qemu_chr_be_generic_open(CharDriverState *s); -void qemu_chr_accept_input(CharDriverState *s); -int qemu_chr_add_client(CharDriverState *s, int fd); -void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); -void qemu_chr_info(Monitor *mon, QObject **ret_data); -CharDriverState *qemu_chr_find(const char *name); - -QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); - -void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *)); -void register_char_driver_qapi(const char *name, int kind, - void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)); - -/* add an eventfd to the qemu devices that are polled */ -CharDriverState *qemu_chr_open_eventfd(int eventfd); - -extern int term_escape_char; - -/* memory chardev */ -void qemu_chr_init_mem(CharDriverState *chr); -void qemu_chr_close_mem(CharDriverState *chr); -QString *qemu_chr_mem_to_qs(CharDriverState *chr); -size_t qemu_chr_mem_osize(const CharDriverState *chr); - -CharDriverState *qemu_char_get_next_serial(void); - -/* msmouse */ -CharDriverState *qemu_chr_open_msmouse(void); - -/* baum.c */ -CharDriverState *chr_baum_init(void); - -#endif diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h index 3711c97a70..c9cadc24b6 100644 --- a/include/hw/virtio/virtio-rng.h +++ b/include/hw/virtio/virtio-rng.h @@ -12,8 +12,8 @@ #ifndef _QEMU_VIRTIO_RNG_H #define _QEMU_VIRTIO_RNG_H -#include "qemu/rng.h" -#include "qemu/rng-random.h" +#include "sysemu/rng.h" +#include "sysemu/rng-random.h" /* The Virtio ID for the virtio rng device */ #define VIRTIO_ID_RNG 4 diff --git a/include/qemu/rng-random.h b/include/qemu/rng-random.h deleted file mode 100644 index 4332772a24..0000000000 --- a/include/qemu/rng-random.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * QEMU Random Number Generator Backend - * - * Copyright IBM, Corp. 2012 - * - * Authors: - * Anthony Liguori - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#ifndef QEMU_RNG_RANDOM_H -#define QEMU_RNG_RANDOM_H - -#include "qom/object.h" - -#define TYPE_RNG_RANDOM "rng-random" -#define RNG_RANDOM(obj) OBJECT_CHECK(RndRandom, (obj), TYPE_RNG_RANDOM) - -typedef struct RndRandom RndRandom; - -#endif diff --git a/include/qemu/rng.h b/include/qemu/rng.h deleted file mode 100644 index 509abd023d..0000000000 --- a/include/qemu/rng.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * QEMU Random Number Generator Backend - * - * Copyright IBM, Corp. 2012 - * - * Authors: - * Anthony Liguori - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ - -#ifndef QEMU_RNG_H -#define QEMU_RNG_H - -#include "qom/object.h" -#include "qemu-common.h" -#include "qapi/error.h" - -#define TYPE_RNG_BACKEND "rng-backend" -#define RNG_BACKEND(obj) \ - OBJECT_CHECK(RngBackend, (obj), TYPE_RNG_BACKEND) -#define RNG_BACKEND_GET_CLASS(obj) \ - OBJECT_GET_CLASS(RngBackendClass, (obj), TYPE_RNG_BACKEND) -#define RNG_BACKEND_CLASS(klass) \ - OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND) - -typedef struct RngBackendClass RngBackendClass; -typedef struct RngBackend RngBackend; - -typedef void (EntropyReceiveFunc)(void *opaque, - const void *data, - size_t size); - -struct RngBackendClass -{ - ObjectClass parent_class; - - void (*request_entropy)(RngBackend *s, size_t size, - EntropyReceiveFunc *recieve_entropy, void *opaque); - void (*cancel_requests)(RngBackend *s); - - void (*opened)(RngBackend *s, Error **errp); -}; - -struct RngBackend -{ - Object parent; - - /*< protected >*/ - bool opened; -}; - -/** - * rng_backend_request_entropy: - * @s: the backend to request entropy from - * @size: the number of bytes of data to request - * @receive_entropy: a function to be invoked when entropy is available - * @opaque: data that should be passed to @receive_entropy - * - * This function is used by the front-end to request entropy from an entropy - * source. This function can be called multiple times before @receive_entropy - * is invoked with different values of @receive_entropy and @opaque. The - * backend will queue each request and handle appropriately. - * - * The backend does not need to pass the full amount of data to @receive_entropy - * but will pass a value greater than 0. - */ -void rng_backend_request_entropy(RngBackend *s, size_t size, - EntropyReceiveFunc *receive_entropy, - void *opaque); - -/** - * rng_backend_cancel_requests: - * @s: the backend to cancel all pending requests in - * - * Cancels all pending requests submitted by @rng_backend_request_entropy. This - * should be used by a device during reset or in preparation for live migration - * to stop tracking any request. - */ -void rng_backend_cancel_requests(RngBackend *s); - -/** - * rng_backend_open: - * @s: the backend to open - * @errp: a pointer to return the #Error object if an error occurs. - * - * This function will open the backend if it is not already open. Calling this - * function on an already opened backend will not result in an error. - */ -void rng_backend_open(RngBackend *s, Error **errp); - -#endif diff --git a/include/sysemu/bt.h b/include/sysemu/bt.h new file mode 100644 index 0000000000..2bc6d53cca --- /dev/null +++ b/include/sysemu/bt.h @@ -0,0 +1,20 @@ +#ifndef BT_HOST_H +#define BT_HOST_H + +/* BT HCI info */ + +struct HCIInfo { + int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); + void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); + void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); + void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); + void *opaque; + void (*evt_recv)(void *opaque, const uint8_t *data, int len); + void (*acl_recv)(void *opaque, const uint8_t *data, int len); +}; + +/* bt-host.c */ +struct HCIInfo *bt_host_hci(const char *id); +struct HCIInfo *qemu_next_hci(void); + +#endif diff --git a/include/sysemu/char.h b/include/sysemu/char.h new file mode 100644 index 0000000000..9d1ea46117 --- /dev/null +++ b/include/sysemu/char.h @@ -0,0 +1,306 @@ +#ifndef QEMU_CHAR_H +#define QEMU_CHAR_H + +#include "qemu-common.h" +#include "qemu/queue.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "block/aio.h" +#include "qapi/qmp/qobject.h" +#include "qapi/qmp/qstring.h" +#include "qemu/main-loop.h" + +/* character device */ + +#define CHR_EVENT_BREAK 0 /* serial break char */ +#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ +#define CHR_EVENT_OPENED 2 /* new connection established */ +#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */ +#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */ +#define CHR_EVENT_CLOSED 5 /* connection closed */ + + +#define CHR_IOCTL_SERIAL_SET_PARAMS 1 +typedef struct { + int speed; + int parity; + int data_bits; + int stop_bits; +} QEMUSerialSetParams; + +#define CHR_IOCTL_SERIAL_SET_BREAK 2 + +#define CHR_IOCTL_PP_READ_DATA 3 +#define CHR_IOCTL_PP_WRITE_DATA 4 +#define CHR_IOCTL_PP_READ_CONTROL 5 +#define CHR_IOCTL_PP_WRITE_CONTROL 6 +#define CHR_IOCTL_PP_READ_STATUS 7 +#define CHR_IOCTL_PP_EPP_READ_ADDR 8 +#define CHR_IOCTL_PP_EPP_READ 9 +#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10 +#define CHR_IOCTL_PP_EPP_WRITE 11 +#define CHR_IOCTL_PP_DATA_DIR 12 + +#define CHR_IOCTL_SERIAL_SET_TIOCM 13 +#define CHR_IOCTL_SERIAL_GET_TIOCM 14 + +#define CHR_TIOCM_CTS 0x020 +#define CHR_TIOCM_CAR 0x040 +#define CHR_TIOCM_DSR 0x100 +#define CHR_TIOCM_RI 0x080 +#define CHR_TIOCM_DTR 0x002 +#define CHR_TIOCM_RTS 0x004 + +typedef void IOEventHandler(void *opaque, int event); + +struct CharDriverState { + void (*init)(struct CharDriverState *s); + int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); + GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); + void (*chr_update_read_handler)(struct CharDriverState *s); + int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); + int (*get_msgfd)(struct CharDriverState *s); + int (*chr_add_client)(struct CharDriverState *chr, int fd); + IOEventHandler *chr_event; + IOCanReadHandler *chr_can_read; + IOReadHandler *chr_read; + void *handler_opaque; + void (*chr_close)(struct CharDriverState *chr); + void (*chr_accept_input)(struct CharDriverState *chr); + void (*chr_set_echo)(struct CharDriverState *chr, bool echo); + void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); + void *opaque; + int idle_tag; + char *label; + char *filename; + int be_open; + int fe_open; + int explicit_fe_open; + int avail_connections; + QemuOpts *opts; + QTAILQ_ENTRY(CharDriverState) next; +}; + +/** + * @qemu_chr_new_from_opts: + * + * Create a new character backend from a QemuOpts list. + * + * @opts see qemu-config.c for a list of valid options + * @init not sure.. + * + * Returns: a new character backend + */ +CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, + void (*init)(struct CharDriverState *s), + Error **errp); + +/** + * @qemu_chr_new: + * + * Create a new character backend from a URI. + * + * @label the name of the backend + * @filename the URI + * @init not sure.. + * + * Returns: a new character backend + */ +CharDriverState *qemu_chr_new(const char *label, const char *filename, + void (*init)(struct CharDriverState *s)); + +/** + * @qemu_chr_delete: + * + * Destroy a character backend. + */ +void qemu_chr_delete(CharDriverState *chr); + +/** + * @qemu_chr_fe_set_echo: + * + * Ask the backend to override its normal echo setting. This only really + * applies to the stdio backend and is used by the QMP server such that you + * can see what you type if you try to type QMP commands. + * + * @echo true to enable echo, false to disable echo + */ +void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo); + +/** + * @qemu_chr_fe_set_open: + * + * Set character frontend open status. This is an indication that the + * front end is ready (or not) to begin doing I/O. + */ +void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open); + +/** + * @qemu_chr_fe_printf: + * + * Write to a character backend using a printf style interface. + * + * @fmt see #printf + */ +void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); + +int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data); + +/** + * @qemu_chr_fe_write: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); + +/** + * @qemu_chr_fe_write_all: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. Unlike @qemu_chr_fe_write, + * this function will block if the back end cannot consume all of the data + * attempted to be written. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); + +/** + * @qemu_chr_fe_ioctl: + * + * Issue a device specific ioctl to a backend. + * + * @cmd see CHR_IOCTL_* + * @arg the data associated with @cmd + * + * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the + * return value depends on the semantics of @cmd + */ +int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg); + +/** + * @qemu_chr_fe_get_msgfd: + * + * For backends capable of fd passing, return the latest file descriptor passed + * by a client. + * + * Returns: -1 if fd passing isn't supported or there is no pending file + * descriptor. If a file descriptor is returned, subsequent calls to + * this function will return -1 until a client sends a new file + * descriptor. + */ +int qemu_chr_fe_get_msgfd(CharDriverState *s); + +/** + * @qemu_chr_fe_claim: + * + * Claim a backend before using it, should be called before calling + * qemu_chr_add_handlers(). + * + * Returns: -1 if the backend is already in use by another frontend, 0 on + * success. + */ +int qemu_chr_fe_claim(CharDriverState *s); + +/** + * @qemu_chr_fe_claim_no_fail: + * + * Like qemu_chr_fe_claim, but will exit qemu with an error when the + * backend is already in use. + */ +void qemu_chr_fe_claim_no_fail(CharDriverState *s); + +/** + * @qemu_chr_fe_claim: + * + * Release a backend for use by another frontend. + * + * Returns: -1 if the backend is already in use by another frontend, 0 on + * success. + */ +void qemu_chr_fe_release(CharDriverState *s); + +/** + * @qemu_chr_be_can_write: + * + * Determine how much data the front end can currently accept. This function + * returns the number of bytes the front end can accept. If it returns 0, the + * front end cannot receive data at the moment. The function must be polled + * to determine when data can be received. + * + * Returns: the number of bytes the front end can receive via @qemu_chr_be_write + */ +int qemu_chr_be_can_write(CharDriverState *s); + +/** + * @qemu_chr_be_write: + * + * Write data from the back end to the front end. Before issuing this call, + * the caller should call @qemu_chr_be_can_write to determine how much data + * the front end can currently accept. + * + * @buf a buffer to receive data from the front end + * @len the number of bytes to receive from the front end + */ +void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len); + + +/** + * @qemu_chr_be_event: + * + * Send an event from the back end to the front end. + * + * @event the event to send + */ +void qemu_chr_be_event(CharDriverState *s, int event); + +void qemu_chr_add_handlers(CharDriverState *s, + IOCanReadHandler *fd_can_read, + IOReadHandler *fd_read, + IOEventHandler *fd_event, + void *opaque); + +void qemu_chr_be_generic_open(CharDriverState *s); +void qemu_chr_accept_input(CharDriverState *s); +int qemu_chr_add_client(CharDriverState *s, int fd); +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); +void qemu_chr_info(Monitor *mon, QObject **ret_data); +CharDriverState *qemu_chr_find(const char *name); + +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); + +void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *)); +void register_char_driver_qapi(const char *name, int kind, + void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)); + +/* add an eventfd to the qemu devices that are polled */ +CharDriverState *qemu_chr_open_eventfd(int eventfd); + +extern int term_escape_char; + +/* memory chardev */ +void qemu_chr_init_mem(CharDriverState *chr); +void qemu_chr_close_mem(CharDriverState *chr); +QString *qemu_chr_mem_to_qs(CharDriverState *chr); +size_t qemu_chr_mem_osize(const CharDriverState *chr); + +CharDriverState *qemu_char_get_next_serial(void); + +/* msmouse */ +CharDriverState *qemu_chr_open_msmouse(void); + +/* baum.c */ +CharDriverState *chr_baum_init(void); + +#endif diff --git a/include/sysemu/rng-random.h b/include/sysemu/rng-random.h new file mode 100644 index 0000000000..4332772a24 --- /dev/null +++ b/include/sysemu/rng-random.h @@ -0,0 +1,22 @@ +/* + * QEMU Random Number Generator Backend + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef QEMU_RNG_RANDOM_H +#define QEMU_RNG_RANDOM_H + +#include "qom/object.h" + +#define TYPE_RNG_RANDOM "rng-random" +#define RNG_RANDOM(obj) OBJECT_CHECK(RndRandom, (obj), TYPE_RNG_RANDOM) + +typedef struct RndRandom RndRandom; + +#endif diff --git a/include/sysemu/rng.h b/include/sysemu/rng.h new file mode 100644 index 0000000000..509abd023d --- /dev/null +++ b/include/sysemu/rng.h @@ -0,0 +1,93 @@ +/* + * QEMU Random Number Generator Backend + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_RNG_H +#define QEMU_RNG_H + +#include "qom/object.h" +#include "qemu-common.h" +#include "qapi/error.h" + +#define TYPE_RNG_BACKEND "rng-backend" +#define RNG_BACKEND(obj) \ + OBJECT_CHECK(RngBackend, (obj), TYPE_RNG_BACKEND) +#define RNG_BACKEND_GET_CLASS(obj) \ + OBJECT_GET_CLASS(RngBackendClass, (obj), TYPE_RNG_BACKEND) +#define RNG_BACKEND_CLASS(klass) \ + OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND) + +typedef struct RngBackendClass RngBackendClass; +typedef struct RngBackend RngBackend; + +typedef void (EntropyReceiveFunc)(void *opaque, + const void *data, + size_t size); + +struct RngBackendClass +{ + ObjectClass parent_class; + + void (*request_entropy)(RngBackend *s, size_t size, + EntropyReceiveFunc *recieve_entropy, void *opaque); + void (*cancel_requests)(RngBackend *s); + + void (*opened)(RngBackend *s, Error **errp); +}; + +struct RngBackend +{ + Object parent; + + /*< protected >*/ + bool opened; +}; + +/** + * rng_backend_request_entropy: + * @s: the backend to request entropy from + * @size: the number of bytes of data to request + * @receive_entropy: a function to be invoked when entropy is available + * @opaque: data that should be passed to @receive_entropy + * + * This function is used by the front-end to request entropy from an entropy + * source. This function can be called multiple times before @receive_entropy + * is invoked with different values of @receive_entropy and @opaque. The + * backend will queue each request and handle appropriately. + * + * The backend does not need to pass the full amount of data to @receive_entropy + * but will pass a value greater than 0. + */ +void rng_backend_request_entropy(RngBackend *s, size_t size, + EntropyReceiveFunc *receive_entropy, + void *opaque); + +/** + * rng_backend_cancel_requests: + * @s: the backend to cancel all pending requests in + * + * Cancels all pending requests submitted by @rng_backend_request_entropy. This + * should be used by a device during reset or in preparation for live migration + * to stop tracking any request. + */ +void rng_backend_cancel_requests(RngBackend *s); + +/** + * rng_backend_open: + * @s: the backend to open + * @errp: a pointer to return the #Error object if an error occurs. + * + * This function will open the backend if it is not already open. Calling this + * function on an already opened backend will not result in an error. + */ +void rng_backend_open(RngBackend *s, Error **errp); + +#endif diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h new file mode 100644 index 0000000000..466787453d --- /dev/null +++ b/include/sysemu/tpm_backend.h @@ -0,0 +1,209 @@ +/* + * QEMU TPM Backend + * + * Copyright IBM, Corp. 2013 + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef _QEMU_TPM_H +#define _QEMU_TPM_H + +#include "qom/object.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "qapi-types.h" +#include "qemu/option.h" +#include "sysemu/tpm.h" + +#define TYPE_TPM_BACKEND "tpm-backend" +#define TPM_BACKEND(obj) \ + OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND) +#define TPM_BACKEND_GET_CLASS(obj) \ + OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND) +#define TPM_BACKEND_CLASS(klass) \ + OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND) + +typedef struct TPMBackendClass TPMBackendClass; +typedef struct TPMBackend TPMBackend; + +typedef struct TPMDriverOps TPMDriverOps; + +struct TPMBackendClass { + ObjectClass parent_class; + + const TPMDriverOps *ops; + + void (*opened)(TPMBackend *s, Error **errp); +}; + +struct TPMBackend { + Object parent; + + /*< protected >*/ + bool opened; + + char *id; + enum TpmModel fe_model; + char *path; + char *cancel_path; + const TPMDriverOps *ops; + + QLIST_ENTRY(TPMBackend) list; +}; + +typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); + +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +struct TPMDriverOps { + enum TpmType type; + /* get a descriptive text of the backend to display to the user */ + const char *(*desc)(void); + + TPMBackend *(*create)(QemuOpts *opts, const char *id); + void (*destroy)(TPMBackend *t); + + /* initialize the backend */ + int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb); + /* start up the TPM on the backend */ + int (*startup_tpm)(TPMBackend *t); + /* returns true if nothing will ever answer TPM requests */ + bool (*had_startup_error)(TPMBackend *t); + + size_t (*realloc_buffer)(TPMSizedBuffer *sb); + + void (*deliver_request)(TPMBackend *t); + + void (*reset)(TPMBackend *t); + + void (*cancel_cmd)(TPMBackend *t); + + bool (*get_tpm_established_flag)(TPMBackend *t); +}; + + +/** + * tpm_backend_get_type: + * @s: the backend + * + * Returns the TpmType of the backend. + */ +enum TpmType tpm_backend_get_type(TPMBackend *s); + +/** + * tpm_backend_get_desc: + * @s: the backend + * + * Returns a human readable description of the backend. + */ +const char *tpm_backend_get_desc(TPMBackend *s); + +/** + * tpm_backend_destroy: + * @s: the backend to destroy + */ +void tpm_backend_destroy(TPMBackend *s); + +/** + * tpm_backend_init: + * @s: the backend to initialized + * @state: TPMState + * @datacb: callback for sending data to frontend + * + * Initialize the backend with the given variables. + * + * Returns 0 on success. + */ +int tpm_backend_init(TPMBackend *s, TPMState *state, + TPMRecvDataCB *datacb); + +/** + * tpm_backend_startup_tpm: + * @s: the backend whose TPM support is to be started + * + * Returns 0 on success. + */ +int tpm_backend_startup_tpm(TPMBackend *s); + +/** + * tpm_backend_had_startup_error: + * @s: the backend to query for a statup error + * + * Check whether the backend had an error during startup. Returns + * false if no error occurred and the backend can be used, true + * otherwise. + */ +bool tpm_backend_had_startup_error(TPMBackend *s); + +/** + * tpm_backend_realloc_buffer: + * @s: the backend + * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the + * backend. + * + * This function returns the size of the allocated buffer + */ +size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb); + +/** + * tpm_backend_deliver_request: + * @s: the backend to send the request to + * + * Send a request to the backend. The backend will then send the request + * to the TPM implementation. + */ +void tpm_backend_deliver_request(TPMBackend *s); + +/** + * tpm_backend_reset: + * @s: the backend to reset + * + * Reset the backend into a well defined state with all previous errors + * reset. + */ +void tpm_backend_reset(TPMBackend *s); + +/** + * tpm_backend_cancel_cmd: + * @s: the backend + * + * Cancel any ongoing command being processed by the TPM implementation + * on behalf of the QEMU guest. + */ +void tpm_backend_cancel_cmd(TPMBackend *s); + +/** + * tpm_backend_get_tpm_established_flag: + * @s: the backend + * + * Get the TPM establishment flag. This function may be called very + * frequently by the frontend since for example in the TIS implementation + * this flag is part of a register. + */ +bool tpm_backend_get_tpm_established_flag(TPMBackend *s); + +/** + * tpm_backend_open: + * @s: the backend to open + * @errp: a pointer to return the #Error object if an error occurs. + * + * This function will open the backend if it is not already open. Calling this + * function on an already opened backend will not result in an error. + */ +void tpm_backend_open(TPMBackend *s, Error **errp); + +TPMBackend *qemu_find_tpm(const char *id); + +const TPMDriverOps *tpm_get_backend_driver(const char *type); +int tpm_register_model(enum TpmModel model); +int tpm_register_driver(const TPMDriverOps *tdo); + +#endif diff --git a/monitor.c b/monitor.c index e605822445..2909ca1985 100644 --- a/monitor.c +++ b/monitor.c @@ -33,7 +33,7 @@ #include "exec/gdbstub.h" #include "net/net.h" #include "net/slirp.h" -#include "char/char.h" +#include "sysemu/char.h" #include "ui/qemu-spice.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" diff --git a/net/slirp.c b/net/slirp.c index eabfee6d4f..b3f35d5861 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -35,7 +35,7 @@ #include "monitor/monitor.h" #include "qemu/sockets.h" #include "slirp/libslirp.h" -#include "char/char.h" +#include "sysemu/char.h" static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) { diff --git a/qemu-char.c b/qemu-char.c index eae17fc61c..14707eac68 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -26,7 +26,7 @@ #include "ui/console.h" #include "sysemu/sysemu.h" #include "qemu/timer.h" -#include "char/char.h" +#include "sysemu/char.h" #include "hw/usb.h" #include "qmp-commands.h" diff --git a/qmp.c b/qmp.c index 55b056b558..ed6c7ef3ae 100644 --- a/qmp.c +++ b/qmp.c @@ -16,7 +16,7 @@ #include "qemu-common.h" #include "sysemu/sysemu.h" #include "qmp-commands.h" -#include "char/char.h" +#include "sysemu/char.h" #include "ui/qemu-spice.h" #include "ui/vnc.h" #include "sysemu/kvm.h" diff --git a/qtest.c b/qtest.c index b03b68adb3..3bba3e5751 100644 --- a/qtest.c +++ b/qtest.c @@ -13,7 +13,7 @@ #include "sysemu/qtest.h" #include "hw/qdev.h" -#include "char/char.h" +#include "sysemu/char.h" #include "exec/ioport.h" #include "exec/memory.h" #include "hw/irq.h" diff --git a/slirp/slirp.c b/slirp/slirp.c index bd9b7cb644..80b28ea89e 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -23,7 +23,7 @@ */ #include "qemu-common.h" #include "qemu/timer.h" -#include "char/char.h" +#include "sysemu/char.h" #include "slirp.h" #include "hw/hw.h" diff --git a/spice-qemu-char.c b/spice-qemu-char.c index 535f955ca8..c9403de8af 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -1,7 +1,7 @@ #include "config-host.h" #include "trace.h" #include "ui/qemu-spice.h" -#include "char/char.h" +#include "sysemu/char.h" #include #include #include diff --git a/tpm.c b/tpm.c index 1e943148d2..c91da43cf1 100644 --- a/tpm.c +++ b/tpm.c @@ -15,7 +15,7 @@ #include "monitor/monitor.h" #include "qapi/qmp/qerror.h" -#include "backends/tpm.h" +#include "sysemu/tpm_backend.h" #include "sysemu/tpm.h" #include "qemu/config-file.h" #include "qmp-commands.h" diff --git a/ui/console.c b/ui/console.c index e84ba8b40a..0ed4211986 100644 --- a/ui/console.c +++ b/ui/console.c @@ -25,7 +25,7 @@ #include "ui/console.h" #include "qemu/timer.h" #include "qmp-commands.h" -#include "char/char.h" +#include "sysemu/char.h" //#define DEBUG_CONSOLE #define DEFAULT_BACKSCROLL 512 diff --git a/ui/gtk.c b/ui/gtk.c index 1a6bee616a..1e105e2fc7 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -62,7 +62,7 @@ #include "qmp-commands.h" #include "x_keymap.h" #include "keymaps.h" -#include "char/char.h" +#include "sysemu/char.h" //#define DEBUG_GTK diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index 713d7560d0..8442c6e63c 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -12,7 +12,7 @@ #include "qemu-common.h" #include "qemu/event_notifier.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/main-loop.h" #ifdef CONFIG_EVENTFD diff --git a/vl.c b/vl.c index ce7bed7141..cdadad09ec 100644 --- a/vl.c +++ b/vl.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) #include "hw/qdev.h" #include "hw/loader.h" #include "monitor/qdev.h" -#include "bt/bt.h" +#include "sysemu/bt.h" #include "net/net.h" #include "net/slirp.h" #include "monitor/monitor.h" @@ -134,7 +134,7 @@ int main(int argc, char **argv) #include "sysemu/sysemu.h" #include "exec/gdbstub.h" #include "qemu/timer.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/cache-utils.h" #include "sysemu/blockdev.h" #include "hw/block/block.h" diff --git a/xen-all.c b/xen-all.c index 31f28fc1ae..539a1549a5 100644 --- a/xen-all.c +++ b/xen-all.c @@ -16,7 +16,7 @@ #include "hw/xen/xen_backend.h" #include "qmp-commands.h" -#include "char/char.h" +#include "sysemu/char.h" #include "qemu/range.h" #include "sysemu/xen-mapcache.h" #include "trace.h" -- cgit v1.2.3 From 0bc3cd624f1d59456cad769bb07e84066a2ddaf9 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Apr 2013 17:29:59 +0200 Subject: include: avoid useless includes of exec/ headers Headers in include/exec/ are for the deepest innards of QEMU, they should almost never be included directly. Signed-off-by: Paolo Bonzini --- arch_init.c | 1 - dump.c | 6 +++++- hw/alpha/typhoon.c | 1 - hw/ide/ahci.c | 1 - hw/ide/internal.h | 1 - hw/net/vmxnet_tx_pkt.c | 2 +- hw/usb/libhw.c | 2 +- kvm-stub.c | 1 - translate-all.c | 5 ++--- 9 files changed, 9 insertions(+), 11 deletions(-) diff --git a/arch_init.c b/arch_init.c index fba0889bc7..92de1bde49 100644 --- a/arch_init.c +++ b/arch_init.c @@ -40,7 +40,6 @@ #include "hw/audio/audio.h" #include "sysemu/kvm.h" #include "migration/migration.h" -#include "exec/gdbstub.h" #include "hw/i386/smbios.h" #include "exec/address-spaces.h" #include "hw/audio/pcspk.h" diff --git a/dump.c b/dump.c index a25f5096eb..b34f143c42 100644 --- a/dump.c +++ b/dump.c @@ -23,7 +23,6 @@ #include "sysemu/memory_mapping.h" #include "qapi/error.h" #include "qmp-commands.h" -#include "exec/gdbstub.h" static uint16_t cpu_convert_to_target16(uint16_t val, int endian) { @@ -268,6 +267,11 @@ static int write_elf64_note(DumpState *s) return 0; } +static inline int cpu_index(CPUState *cpu) +{ + return cpu->cpu_index + 1; +} + static int write_elf64_notes(DumpState *s) { CPUArchState *env; diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c index 68420f40cb..1ead1877c7 100644 --- a/hw/alpha/typhoon.c +++ b/hw/alpha/typhoon.c @@ -7,7 +7,6 @@ */ #include "cpu.h" -#include "exec/exec-all.h" #include "hw/hw.h" #include "hw/devices.h" #include "sysemu/sysemu.h" diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index d0ae8afba2..3405583f59 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -29,7 +29,6 @@ #include "monitor/monitor.h" #include "sysemu/dma.h" -#include "exec/cpu-common.h" #include "internal.h" #include #include diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 2c89b50c5e..0efb2da19b 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -8,7 +8,6 @@ */ #include #include -#include "exec/iorange.h" #include "sysemu/dma.h" #include "sysemu/sysemu.h" #include "hw/block/block.h" diff --git a/hw/net/vmxnet_tx_pkt.c b/hw/net/vmxnet_tx_pkt.c index b1e795b3b2..fc01e4da3c 100644 --- a/hw/net/vmxnet_tx_pkt.c +++ b/hw/net/vmxnet_tx_pkt.c @@ -15,6 +15,7 @@ * */ +#include "hw/hw.h" #include "vmxnet_tx_pkt.h" #include "net/eth.h" #include "qemu-common.h" @@ -22,7 +23,6 @@ #include "net/checksum.h" #include "net/tap.h" #include "net/net.h" -#include "exec/cpu-common.h" enum { VMXNET_TX_PKT_VHDR_FRAG = 0, diff --git a/hw/usb/libhw.c b/hw/usb/libhw.c index 75f022f4ec..d2d4b51b94 100644 --- a/hw/usb/libhw.c +++ b/hw/usb/libhw.c @@ -20,7 +20,7 @@ * THE SOFTWARE. */ #include "qemu-common.h" -#include "exec/cpu-common.h" +#include "hw/hw.h" #include "hw/usb.h" #include "sysemu/dma.h" diff --git a/kvm-stub.c b/kvm-stub.c index 760aadc874..f6137d343a 100644 --- a/kvm-stub.c +++ b/kvm-stub.c @@ -14,7 +14,6 @@ #include "hw/hw.h" #include "hw/pci/msi.h" #include "cpu.h" -#include "exec/gdbstub.h" #include "sysemu/kvm.h" KVMState *kvm_state; diff --git a/translate-all.c b/translate-all.c index a98c646d92..08dd038816 100644 --- a/translate-all.c +++ b/translate-all.c @@ -35,9 +35,6 @@ #include "cpu.h" #include "disas/disas.h" #include "tcg.h" -#include "qemu/timer.h" -#include "exec/memory.h" -#include "exec/address-spaces.h" #if defined(CONFIG_USER_ONLY) #include "qemu.h" #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -55,6 +52,8 @@ #include #endif #endif +#else +#include "exec/address-spaces.h" #endif #include "exec/cputlb.h" -- cgit v1.2.3 From b421d9c6aba0ba3338c00b56cf45edbc150c42f3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 9 Apr 2013 11:10:27 +0200 Subject: memory: move core typedefs to qemu/typedefs.h Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 5 ----- include/qemu/typedefs.h | 4 ++++ target-ppc/kvm_ppc.h | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 2322732dce..9e88320113 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -27,7 +27,6 @@ #include "qemu/int128.h" typedef struct MemoryRegionOps MemoryRegionOps; -typedef struct MemoryRegion MemoryRegion; typedef struct MemoryRegionPortio MemoryRegionPortio; typedef struct MemoryRegionMmio MemoryRegionMmio; @@ -157,8 +156,6 @@ struct MemoryRegionPortio { #define PORTIO_END_OF_LIST() { } -typedef struct AddressSpace AddressSpace; - /** * AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ @@ -173,8 +170,6 @@ struct AddressSpace { QTAILQ_ENTRY(AddressSpace) address_spaces_link; }; -typedef struct MemoryRegionSection MemoryRegionSection; - /** * MemoryRegionSection: describes a fragment of a #MemoryRegion * diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index fd532a268d..93aae81a82 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -18,6 +18,10 @@ typedef struct DeviceState DeviceState; typedef struct BusState BusState; typedef struct BusClass BusClass; +typedef struct AddressSpace AddressSpace; +typedef struct MemoryRegion MemoryRegion; +typedef struct MemoryRegionSection MemoryRegionSection; + typedef struct NICInfo NICInfo; typedef struct HCIInfo HCIInfo; typedef struct AudioState AudioState; diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index c30b006674..6bcc5cc36c 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -9,8 +9,6 @@ #ifndef __KVM_PPC_H__ #define __KVM_PPC_H__ -#include "exec/memory.h" - #define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU void kvmppc_init(void); -- cgit v1.2.3 From c72dd2d04bd28f7ec6b073316270258684ba5fc3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Apr 2013 18:26:41 +0200 Subject: exec: remove useless declarations from memory-internal.h Signed-off-by: Paolo Bonzini --- include/exec/memory-internal.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 977467bb57..1b156fd58f 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -49,12 +49,6 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); void qemu_ram_free(ram_addr_t addr); void qemu_ram_free_from_ptr(ram_addr_t addr); -struct MemoryRegion; -struct MemoryRegionSection; - -void qemu_register_coalesced_mmio(hwaddr addr, ram_addr_t size); -void qemu_unregister_coalesced_mmio(hwaddr addr, ram_addr_t size); - #define VGA_DIRTY_FLAG 0x01 #define CODE_DIRTY_FLAG 0x02 #define MIGRATION_DIRTY_FLAG 0x08 -- cgit v1.2.3