[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

Xen patchbot-unstable
# HG changeset patch
# User [hidden email]
# Date 1172001502 25200
# Node ID d907467f08cd4b55604961f4da4224d3ad5fe9d4
# Parent  04c23c1ef8885cf37b1c17a2f406695272ba036d
# Parent  ecb6cd61a9cfa70be364aace1cb183bae03b04fd
merge with xen-unstable.hg
---
 linux-2.6-xen-sparse/drivers/char/tpm/tpm.c                         | 1222 ---------
 linux-2.6-xen-sparse/include/linux/pfn.h                            |    9
 tools/libxc/xc_linux_build.c                                        | 1319 ----------
 tools/libxc/xc_load_bin.c                                           |  306 --
 tools/libxc/xc_load_elf.c                                           |  684 -----
 xen/common/elf.c                                                    |  520 ---
 extras/mini-os/Makefile                                             |    5
 extras/mini-os/arch/x86/Makefile                                    |    5
 extras/mini-os/arch/x86/arch.mk                                     |    5
 extras/mini-os/minios.mk                                            |   17
 extras/mini-os/xenbus/xenbus.c                                      |    2
 linux-2.6-xen-sparse/arch/i386/kernel/Makefile                      |    1
 linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S                    |    4
 linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c                   |   38
 linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c                    |   30
 linux-2.6-xen-sparse/arch/i386/mach-xen/setup.c                     |    2
 linux-2.6-xen-sparse/arch/i386/mm/fault-xen.c                       |    2
 linux-2.6-xen-sparse/arch/ia64/xen/util.c                           |   12
 linux-2.6-xen-sparse/arch/x86_64/kernel/Makefile                    |    1
 linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c                  |   11
 linux-2.6-xen-sparse/arch/x86_64/kernel/early_printk-xen.c          |   11
 linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S                 |    4
 linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S                  |    7
 linux-2.6-xen-sparse/arch/x86_64/kernel/mpparse-xen.c               |    2
 linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c               |    4
 linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c                 |   15
 linux-2.6-xen-sparse/arch/x86_64/mm/fault-xen.c                     |    3
 linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c                      |   26
 linux-2.6-xen-sparse/drivers/char/tpm/Kconfig                       |    2
 linux-2.6-xen-sparse/drivers/char/tpm/tpm.h                         |   24
 linux-2.6-xen-sparse/drivers/char/tpm/tpm_vtpm.c                    |    3
 linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c                  |    6
 linux-2.6-xen-sparse/drivers/xen/blkback/interface.c                |   14
 linux-2.6-xen-sparse/drivers/xen/blktap/interface.c                 |   14
 linux-2.6-xen-sparse/drivers/xen/core/gnttab.c                      |  251 +
 linux-2.6-xen-sparse/drivers/xen/core/smpboot.c                     |    3
 linux-2.6-xen-sparse/drivers/xen/netback/interface.c                |   26
 linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c                |   14
 linux-2.6-xen-sparse/drivers/xen/util.c                             |   31
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c     |   16
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h     |    3
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/irqflags.h       |   17
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h          |   25
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h           |   53
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h |    7
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h |   27
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable.h        |   38
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h         |    3
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/irqflags.h     |   17
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h        |   15
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h         |   28
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h      |   62
 linux-2.6-xen-sparse/include/xen/driver_util.h                      |    4
 linux-2.6-xen-sparse/include/xen/gnttab.h                           |   13
 patches/linux-2.6.18/x86-elfnote-as-preprocessor-macro.patch        |    5
 tools/blktap/drivers/Makefile                                       |   16
 tools/blktap/drivers/block-aio.c                                    |  132 -
 tools/blktap/drivers/block-qcow.c                                   |  563 ++--
 tools/blktap/drivers/block-ram.c                                    |  125
 tools/blktap/drivers/block-sync.c                                   |   95
 tools/blktap/drivers/block-vmdk.c                                   |   99
 tools/blktap/drivers/img2qcow.c                                     |   28
 tools/blktap/drivers/qcow2raw.c                                     |   75
 tools/blktap/drivers/tapdisk.c                                      |  372 ++
 tools/blktap/drivers/tapdisk.h                                      |   62
 tools/blktap/lib/blktaplib.h                                        |   13
 tools/blktap/lib/xs_api.c                                           |    8
 tools/check/check_zlib_lib                                          |    4
 tools/console/daemon/io.c                                           |    8
 tools/firmware/hvmloader/acpi/build.c                               |   81
 tools/firmware/hvmloader/acpi/dsdt.asl                              |    8
 tools/firmware/hvmloader/acpi/dsdt.c                                |  866 +++---
 tools/firmware/rombios/32bit/Makefile                               |    2
 tools/firmware/rombios/32bit/tcgbios/Makefile                       |    2
 tools/ioemu/hw/tpm_tis.c                                            |    3
 tools/libfsimage/common/fsimage.c                                   |    4
 tools/libfsimage/common/fsimage.h                                   |    2
 tools/libfsimage/common/fsimage_grub.c                              |    4
 tools/libfsimage/common/fsimage_grub.h                              |    2
 tools/libfsimage/common/fsimage_plugin.c                            |    4
 tools/libfsimage/common/fsimage_plugin.h                            |    2
 tools/libfsimage/common/fsimage_priv.h                              |    2
 tools/libfsimage/ext2fs-lib/ext2fs-lib.c                            |    2
 tools/libfsimage/ext2fs/fsys_ext2fs.c                               |    2
 tools/libfsimage/reiserfs/fsys_reiserfs.c                           |    2
 tools/libfsimage/ufs/fsys_ufs.c                                     |    2
 tools/libxc/Makefile                                                |    4
 tools/libxc/xc_dom.h                                                |    2
 tools/libxc/xc_domain.c                                             |    4
 tools/libxc/xc_hvm_build.c                                          |    9
 tools/libxc/xc_linux_restore.c                                      |    6
 tools/libxc/xc_linux_save.c                                         |    8
 tools/libxc/xc_pagetab.c                                            |    4
 tools/libxc/xc_private.c                                            |   20
 tools/libxc/xg_private.h                                            |   84
 tools/pygrub/src/fsimage/fsimage.c                                  |   14
 tools/python/xen/xend/XendDomainInfo.py                             |   21
 tools/python/xen/xend/image.py                                      |    1
 tools/security/xensec_ezpolicy                                      |    6
 tools/xcutils/readnotes.c                                           |  138 -
 xen/acm/acm_simple_type_enforcement_hooks.c                         |   18
 xen/arch/ia64/xen/domain.c                                          |   10
 xen/arch/ia64/xen/mm.c                                              |    4
 xen/arch/x86/domain_build.c                                         |    4
 xen/arch/x86/hvm/io.c                                               |    5
 xen/arch/x86/hvm/platform.c                                         |   31
 xen/arch/x86/hvm/svm/svm.c                                          |   32
 xen/arch/x86/hvm/vlapic.c                                           |    2
 xen/arch/x86/hvm/vmx/vmx.c                                          |   18
 xen/arch/x86/mm.c                                                   |   36
 xen/arch/x86/mm/shadow/common.c                                     |  177 -
 xen/arch/x86/mm/shadow/multi.c                                      |  179 -
 xen/arch/x86/mm/shadow/private.h                                    |   17
 xen/arch/x86/mm/shadow/types.h                                      |    1
 xen/arch/x86/traps.c                                                |   29
 xen/arch/x86/x86_32/seg_fixup.c                                     |    5
 xen/common/compat/grant_table.c                                     |    3
 xen/common/grant_table.c                                            |  502 ++-
 xen/common/libelf/libelf-dominfo.c                                  |  119
 xen/common/libelf/libelf-tools.c                                    |   11
 xen/include/asm-ia64/bug.h                                          |    6
 xen/include/asm-ia64/grant_table.h                                  |   43
 xen/include/asm-powerpc/bug.h                                       |    6
 xen/include/asm-powerpc/grant_table.h                               |    2
 xen/include/asm-x86/bug.h                                           |   13
 xen/include/asm-x86/grant_table.h                                   |    6
 xen/include/asm-x86/hvm/io.h                                        |    1
 xen/include/asm-x86/processor.h                                     |    5
 xen/include/asm-x86/x86_32/bug.h                                    |   19
 xen/include/asm-x86/x86_64/bug.h                                    |   19
 xen/include/asm-x86/x86_64/page.h                                   |   14
 xen/include/public/arch-ia64.h                                      |    2
 xen/include/public/arch-powerpc.h                                   |    2
 xen/include/public/arch-x86/xen.h                                   |    2
 xen/include/public/elfnote.h                                        |    8
 xen/include/public/grant_table.h                                    |   19
 xen/include/public/hvm/save.h                                       |   13
 xen/include/public/libelf.h                                         |    3
 xen/include/xen/grant_table.h                                       |   38
 xen/include/xen/lib.h                                               |    5
 xen/include/xen/sched.h                                             |    9
 141 files changed, 3077 insertions(+), 6260 deletions(-)

diff -r 04c23c1ef888 -r d907467f08cd extras/mini-os/Makefile
--- a/extras/mini-os/Makefile Sun Feb 18 16:13:13 2007 -0700
+++ b/extras/mini-os/Makefile Tue Feb 20 12:58:22 2007 -0700
@@ -44,10 +44,6 @@ ARCH_LINKS =
 # This can be overwritten from arch specific rules.
 EXTRA_INC =
 
-# Special build dependencies.
-# Build all after touching this/these file(s) (see minios.mk)
-SPEC_DEPENDS = minios.mk
-
 # Include the architecture family's special makerules.
 # This must be before include minios.mk!
 include $(TARGET_ARCH_DIR)/arch.mk
@@ -57,7 +53,6 @@ include minios.mk
 
 # Define some default flags for linking.
 LDLIBS :=
-LDFLAGS :=
 LDARCHLIB := -L$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
 LDFLAGS_FINAL := -N -T $(TARGET_ARCH_DIR)/minios-$(TARGET_ARCH).lds
 
diff -r 04c23c1ef888 -r d907467f08cd extras/mini-os/arch/x86/Makefile
--- a/extras/mini-os/arch/x86/Makefile Sun Feb 18 16:13:13 2007 -0700
+++ b/extras/mini-os/arch/x86/Makefile Tue Feb 20 12:58:22 2007 -0700
@@ -2,9 +2,6 @@
 # x86 architecture specific makefiles.
 # It's is used for x86_32, x86_32y and x86_64
 #
-
-# Rebuild all after touching this/these extra file(s) (see mini-os.mk)
-SPEC_DEP = arch.mk
 
 # include arch.mk has to be before mini-os.mk!
 include arch.mk
@@ -25,5 +22,5 @@ all: $(ARCH_LIB)
  $(AR) rv $(ARCH_LIB) $(ARCH_OBJS)
 
 clean:
- rm -f $(ARCH_LIB) $(ARCH_OBJS)
+ rm -f $(ARCH_LIB) $(ARCH_OBJS) $(HEAD_ARCH_OBJ)
 
diff -r 04c23c1ef888 -r d907467f08cd extras/mini-os/arch/x86/arch.mk
--- a/extras/mini-os/arch/x86/arch.mk Sun Feb 18 16:13:13 2007 -0700
+++ b/extras/mini-os/arch/x86/arch.mk Tue Feb 20 12:58:22 2007 -0700
@@ -6,6 +6,7 @@ ifeq ($(TARGET_ARCH),x86_32)
 ifeq ($(TARGET_ARCH),x86_32)
 ARCH_CFLAGS  := -m32 -march=i686
 ARCH_LDFLAGS := -m elf_i386
+ARCH_ASFLAGS := -m32
 EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
 EXTRA_SRC += arch/$(EXTRA_INC)
 endif
@@ -19,10 +20,10 @@ endif
 
 ifeq ($(TARGET_ARCH),x86_64)
 ARCH_CFLAGS := -m64 -mno-red-zone -fpic -fno-reorder-blocks
-ARCH_CFLAGS := -fno-asynchronous-unwind-tables
+ARCH_CFLAGS += -fno-asynchronous-unwind-tables
+ARCH_ASFLAGS := -m64
 ARCH_LDFLAGS := -m elf_x86_64
 EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
 EXTRA_SRC += arch/$(EXTRA_INC)
 endif
 
-
diff -r 04c23c1ef888 -r d907467f08cd extras/mini-os/minios.mk
--- a/extras/mini-os/minios.mk Sun Feb 18 16:13:13 2007 -0700
+++ b/extras/mini-os/minios.mk Tue Feb 20 12:58:22 2007 -0700
@@ -11,6 +11,7 @@ DEF_CFLAGS += -D__XEN_INTERFACE_VERSION_
 DEF_CFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
 
 DEF_ASFLAGS = -D__ASSEMBLY__
+DEF_LDFLAGS =
 
 ifeq ($(debug),y)
 DEF_CFLAGS += -g
@@ -23,21 +24,27 @@ endif
 # ARCH_... flags may be defined in arch/$(TARGET_ARCH_FAM/rules.mk
 CFLAGS := $(DEF_CFLAGS) $(ARCH_CFLAGS)
 ASFLAGS := $(DEF_ASFLAGS) $(ARCH_ASFLAGS)
+LDFLAGS := $(DEF_LDFLAGS) $(ARCH_LDFLAGS)
 
 # The path pointing to the architecture specific header files.
-ARCH_SPEC_INC := $(MINI-OS_ROOT)/include/$(TARGET_ARCH_FAM)
+ARCH_INC := $(MINI-OS_ROOT)/include/$(TARGET_ARCH_FAM)
+
+# Special build dependencies.
+# Rebuild all after touching this/these file(s)
+EXTRA_DEPS = $(MINI-OS_ROOT)/minios.mk \
+ $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
 
 # Find all header files for checking dependencies.
 HDRS := $(wildcard $(MINI-OS_ROOT)/include/*.h)
 HDRS += $(wildcard $(MINI-OS_ROOT)/include/xen/*.h)
-HDRS += $(wildcard $(ARCH_SPEC_INC)/*.h)
+HDRS += $(wildcard $(ARCH_INC)/*.h)
 # For special wanted header directories.
 extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h))
 HDRS += $(extra_heads)
 
 # Add the special header directories to the include paths.
 extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
-override CPPFLAGS := -I$(MINI-OS_ROOT)/include $(CPPFLAGS) -I$(ARCH_SPEC_INC) $(extra_incl)
+override CPPFLAGS := -I$(MINI-OS_ROOT)/include $(CPPFLAGS) -I$(ARCH_INC) $(extra_incl)
 
 # The name of the architecture specific library.
 # This is on x86_32: libx86_32.a
@@ -51,10 +58,10 @@ HEAD_OBJ := $(TARGET_ARCH_DIR)/$(HEAD_AR
 HEAD_OBJ := $(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ)
 
 
-%.o: %.c $(HDRS) Makefile $(SPEC_DEPENDS)
+%.o: %.c $(HDRS) Makefile $(EXTRA_DEPS)
  $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
 
-%.o: %.S $(HDRS) Makefile $(SPEC_DEPENDS)
+%.o: %.S $(HDRS) Makefile $(EXTRA_DEPS)
  $(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
 
 
diff -r 04c23c1ef888 -r d907467f08cd extras/mini-os/xenbus/xenbus.c
--- a/extras/mini-os/xenbus/xenbus.c Sun Feb 18 16:13:13 2007 -0700
+++ b/extras/mini-os/xenbus/xenbus.c Tue Feb 20 12:58:22 2007 -0700
@@ -210,7 +210,7 @@ static int allocate_xenbus_id(void)
     }
     nr_live_reqs++;
     req_info[o_probe].in_use = 1;
-    probe = o_probe + 1;
+    probe = (o_probe + 1) % NR_REQS;
     spin_unlock(&req_lock);
     init_waitqueue_head(&req_info[o_probe].waitq);
 
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/kernel/Makefile
--- a/linux-2.6-xen-sparse/arch/i386/kernel/Makefile Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/Makefile Tue Feb 20 12:58:22 2007 -0700
@@ -98,4 +98,5 @@ obj-y := $(call filterxen, $(obj-y), $(n
 obj-y := $(call filterxen, $(obj-y), $(n-obj-xen))
 obj-y := $(call cherrypickxen, $(obj-y))
 extra-y := $(call cherrypickxen, $(extra-y))
+%/head-xen.o %/head-xen.s: EXTRA_AFLAGS :=
 endif
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S
--- a/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S Tue Feb 20 12:58:22 2007 -0700
@@ -11,6 +11,8 @@
 #include <asm/asm-offsets.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/elfnote.h>
+
+#define _PAGE_PRESENT 0x1
 
 /*
  * References to members of the new_cpu_data structure.
@@ -198,7 +200,9 @@ ENTRY(cpu_gdt_table)
  ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,       .asciz, "writable_page_tables|writable_descriptor_tables|auto_translated_physmap|pae_pgdir_above_4gb|supervisor_mode_kernel")
 #ifdef CONFIG_X86_PAE
  ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz, "yes")
+ ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,   .quad,  _PAGE_PRESENT,_PAGE_PRESENT)
 #else
  ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz, "no")
+ ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,   .long,  _PAGE_PRESENT,_PAGE_PRESENT)
 #endif
  ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz, "generic")
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -1034,8 +1034,16 @@ e820_all_mapped(unsigned long s, unsigne
  u64 start = s;
  u64 end = e;
  int i;
+
+#ifndef CONFIG_XEN
  for (i = 0; i < e820.nr_map; i++) {
  struct e820entry *ei = &e820.map[i];
+#else
+ if (!is_initial_xendomain())
+ return 0;
+ for (i = 0; i < machine_e820.nr_map; ++i) {
+ const struct e820entry *ei = &machine_e820.map[i];
+#endif
  if (type && ei->type != type)
  continue;
  /* is the region (part) in overlap with the current region ?*/
@@ -1505,9 +1513,6 @@ e820_setup_gap(struct e820entry *e820, i
  */
 static int __init request_standard_resources(void)
 {
-#ifdef CONFIG_XEN
- struct xen_memory_map memmap;
-#endif
  int      i;
 
  /* Nothing to do if not running in dom0. */
@@ -1516,13 +1521,6 @@ static int __init request_standard_resou
 
  printk("Setting up standard PCI resources\n");
 #ifdef CONFIG_XEN
- memmap.nr_entries = E820MAX;
- set_xen_guest_handle(memmap.buffer, machine_e820.map);
-
- if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap))
- BUG();
- machine_e820.nr_map = memmap.nr_entries;
-
  legacy_init_iomem_resources(machine_e820.map, machine_e820.nr_map,
     &code_resource, &data_resource);
 #else
@@ -1546,12 +1544,22 @@ subsys_initcall(request_standard_resourc
 
 static void __init register_memory(void)
 {
-
 #ifdef CONFIG_XEN
- e820_setup_gap(machine_e820.map, machine_e820.nr_map);
-#else
- e820_setup_gap(e820.map, e820.nr_map);
-#endif
+ if (is_initial_xendomain()) {
+ struct xen_memory_map memmap;
+
+ memmap.nr_entries = E820MAX;
+ set_xen_guest_handle(memmap.buffer, machine_e820.map);
+
+ if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap))
+ BUG();
+
+ machine_e820.nr_map = memmap.nr_entries;
+ e820_setup_gap(machine_e820.map, machine_e820.nr_map);
+ }
+ else
+#endif
+ e820_setup_gap(e820.map, e820.nr_map);
 }
 
 #ifdef CONFIG_MCA
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -222,8 +222,7 @@ void init_cpu_khz(void)
 void init_cpu_khz(void)
 {
  u64 __cpu_khz = 1000000ULL << 32;
- struct vcpu_time_info *info;
- info = &HYPERVISOR_shared_info->vcpu_info[0].time;
+ struct vcpu_time_info *info = &vcpu_info(0)->time;
  do_div(__cpu_khz, info->tsc_to_system_mul);
  if (info->tsc_shift < 0)
  cpu_khz = __cpu_khz << -info->tsc_shift;
@@ -293,14 +292,13 @@ static void update_wallclock(void)
  * Reads a consistent set of time-base values from Xen, into a shadow data
  * area.
  */
-static void get_time_values_from_xen(void)
-{
- shared_info_t           *s = HYPERVISOR_shared_info;
+static void get_time_values_from_xen(int cpu)
+{
  struct vcpu_time_info   *src;
  struct shadow_time_info *dst;
 
- src = &s->vcpu_info[smp_processor_id()].time;
- dst = &per_cpu(shadow_time, smp_processor_id());
+ src = &vcpu_info(cpu)->time;
+ dst = &per_cpu(shadow_time, cpu);
 
  do {
  dst->version = src->version;
@@ -320,7 +318,7 @@ static inline int time_values_up_to_date
  struct vcpu_time_info   *src;
  struct shadow_time_info *dst;
 
- src = &HYPERVISOR_shared_info->vcpu_info[cpu].time;
+ src = &vcpu_info(cpu)->time;
  dst = &per_cpu(shadow_time, cpu);
 
  rmb();
@@ -412,7 +410,7 @@ void do_gettimeofday(struct timeval *tv)
  * overflowed). Detect that and recalculate
  * with fresh values.
  */
- get_time_values_from_xen();
+ get_time_values_from_xen(cpu);
  continue;
  }
  } while (read_seqretry(&xtime_lock, seq) ||
@@ -456,7 +454,7 @@ int do_settimeofday(struct timespec *tv)
  nsec = tv->tv_nsec - get_nsec_offset(shadow);
  if (time_values_up_to_date(cpu))
  break;
- get_time_values_from_xen();
+ get_time_values_from_xen(cpu);
  }
  sec = tv->tv_sec;
  __normalize_time(&sec, &nsec);
@@ -551,7 +549,7 @@ unsigned long long monotonic_clock(void)
  barrier();
  time = shadow->system_timestamp + get_nsec_offset(shadow);
  if (!time_values_up_to_date(cpu))
- get_time_values_from_xen();
+ get_time_values_from_xen(cpu);
  barrier();
  } while (local_time_version != shadow->version);
 
@@ -621,7 +619,7 @@ irqreturn_t timer_interrupt(int irq, voi
  write_seqlock(&xtime_lock);
 
  do {
- get_time_values_from_xen();
+ get_time_values_from_xen(cpu);
 
  /* Obtain a consistent snapshot of elapsed wallclock cycles. */
  delta = delta_cpu =
@@ -708,7 +706,7 @@ irqreturn_t timer_interrupt(int irq, voi
  if (delta_cpu > 0) {
  do_div(delta_cpu, NS_PER_TICK);
  per_cpu(processed_system_time, cpu) += delta_cpu * NS_PER_TICK;
- if (user_mode(regs))
+ if (user_mode_vm(regs))
  account_user_time(current, (cputime_t)delta_cpu);
  else
  account_system_time(current, HARDIRQ_OFFSET,
@@ -722,7 +720,7 @@ irqreturn_t timer_interrupt(int irq, voi
  /* Local timer processing (see update_process_times()). */
  run_local_timers();
  if (rcu_pending(cpu))
- rcu_check_callbacks(cpu, user_mode(regs));
+ rcu_check_callbacks(cpu, user_mode_vm(regs));
  scheduler_tick();
  run_posix_cpu_timers(current);
  profile_tick(CPU_PROFILING, regs);
@@ -921,7 +919,7 @@ void __init time_init(void)
  return;
  }
 #endif
- get_time_values_from_xen();
+ get_time_values_from_xen(0);
 
  processed_system_time = per_cpu(shadow_time, 0).system_timestamp;
  per_cpu(processed_system_time, 0) = processed_system_time;
@@ -1029,7 +1027,7 @@ void time_resume(void)
 {
  init_cpu_khz();
 
- get_time_values_from_xen();
+ get_time_values_from_xen(0);
 
  processed_system_time = per_cpu(shadow_time, 0).system_timestamp;
  per_cpu(processed_system_time, 0) = processed_system_time;
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/mach-xen/setup.c
--- a/linux-2.6-xen-sparse/arch/i386/mach-xen/setup.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/mach-xen/setup.c Tue Feb 20 12:58:22 2007 -0700
@@ -67,7 +67,7 @@ char * __init machine_specific_memory_se
  if ( rc == -ENOSYS ) {
  memmap.nr_entries = 1;
  map[0].addr = 0ULL;
- map[0].size = PFN_PHYS(xen_start_info->nr_pages);
+ map[0].size = PFN_PHYS((unsigned long long)xen_start_info->nr_pages);
  /* 8MB slack (to balance backend allocations). */
  map[0].size += 8ULL << 20;
  map[0].type = E820_RAM;
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/i386/mm/fault-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/mm/fault-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/i386/mm/fault-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -731,7 +731,7 @@ do_sigbus:
  force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
 }
 
-#ifndef CONFIG_X86_PAE
+#if !HAVE_SHARED_KERNEL_PMD
 void vmalloc_sync_all(void)
 {
  /*
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/ia64/xen/util.c
--- a/linux-2.6-xen-sparse/arch/ia64/xen/util.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/ia64/xen/util.c Tue Feb 20 12:58:22 2007 -0700
@@ -95,18 +95,6 @@ void free_vm_area(struct vm_struct *area
 }
 EXPORT_SYMBOL_GPL(free_vm_area);
 
-void lock_vm_area(struct vm_struct *area)
-{
- // nothing
-}
-EXPORT_SYMBOL_GPL(lock_vm_area);
-
-void unlock_vm_area(struct vm_struct *area)
-{
- // nothing
-}
-EXPORT_SYMBOL_GPL(unlock_vm_area);
-
 /*
  * Local variables:
  *  c-file-style: "linux"
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/Makefile
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/Makefile Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/Makefile Tue Feb 20 12:58:22 2007 -0700
@@ -72,4 +72,5 @@ obj-y := $(call filterxen, $(obj-y), $(n
 obj-y := $(call filterxen, $(obj-y), $(n-obj-xen))
 obj-y := $(call cherrypickxen, $(obj-y))
 extra-y := $(call cherrypickxen, $(extra-y))
+%/head-xen.o %/head-xen.s: EXTRA_AFLAGS :=
 endif
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -127,8 +127,19 @@ int __init e820_all_mapped(unsigned long
 int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
 {
  int i;
+
+#ifndef CONFIG_XEN
  for (i = 0; i < e820.nr_map; i++) {
  struct e820entry *ei = &e820.map[i];
+#else
+ extern struct e820map machine_e820;
+
+ if (!is_initial_xendomain())
+ return 0;
+ for (i = 0; i < machine_e820.nr_map; i++) {
+ const struct e820entry *ei = &machine_e820.map[i];
+#endif
+
  if (type && ei->type != type)
  continue;
  /* is the region (part) in overlap with the current region ?*/
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/early_printk-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/early_printk-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/early_printk-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -18,9 +18,8 @@
 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
 #endif
 
+#ifndef CONFIG_XEN
 static int max_ypos = 25, max_xpos = 80;
-
-#ifndef CONFIG_XEN
 static int current_ypos = 25, current_xpos = 0;
 
 static void early_vga_write(struct console *con, const char *str, unsigned n)
@@ -154,10 +153,6 @@ static __init void early_serial_init(cha
 
 #else /* CONFIG_XEN */
 
-#undef SCREEN_INFO
-#define SCREEN_INFO screen_info
-extern struct screen_info screen_info;
-
 static void
 early_serial_write(struct console *con, const char *s, unsigned count)
 {
@@ -273,11 +268,13 @@ int __init setup_early_printk(char *opt)
  early_serial_init(buf);
  early_console = &early_serial_console;
  } else if (!strncmp(buf, "vga", 3)
+#ifndef CONFIG_XEN
            && SCREEN_INFO.orig_video_isVGA == 1) {
  max_xpos = SCREEN_INFO.orig_video_cols;
  max_ypos = SCREEN_INFO.orig_video_lines;
-#ifndef CONFIG_XEN
  current_ypos = SCREEN_INFO.orig_y;
+#else
+           || !strncmp(buf, "xen", 3)) {
 #endif
  early_console = &early_vga_console;
  } else if (!strncmp(buf, "simnow", 6)) {
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S Tue Feb 20 12:58:22 2007 -0700
@@ -32,9 +32,6 @@
  */
 
 #define ASSEMBLY 1
-#ifdef CONFIG_DEBUG_INFO
-#undef CONFIG_DEBUG_INFO
-#endif
 #include <linux/linkage.h>
 #include <asm/segment.h>
 #include <asm/smp.h>
@@ -537,6 +534,7 @@ END(stub_rt_sigreturn)
  */
 
 retint_check:
+ CFI_DEFAULT_STACK
  movl threadinfo_flags(%rcx),%edx
  andl %edi,%edx
  CFI_REMEMBER_STATE
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S Tue Feb 20 12:58:22 2007 -0700
@@ -25,7 +25,9 @@
 
 #include <xen/interface/elfnote.h>
 
- .text
+#define _PAGE_PRESENT 0x1
+
+ .section .bootstrap.text, "ax", @progbits
  .code64
 #define VIRT_ENTRY_OFFSET 0x0
 .org VIRT_ENTRY_OFFSET
@@ -49,7 +51,7 @@ ENTRY(_stext)
 #define NEXT_PAGE(name) \
  $page = $page + 1; \
  .org $page * 0x1000; \
- phys_/**/name = $page * 0x1000 + __PHYSICAL_START; \
+ phys_##name = $page * 0x1000 + __PHYSICAL_START; \
 ENTRY(name)
 
 NEXT_PAGE(init_level4_pgt)
@@ -181,5 +183,6 @@ ENTRY(empty_zero_page)
 #endif /* !CONFIG_XEN_COMPAT_030002 */
  ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          .quad,  startup_64)
  ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .quad,  hypercall_page)
+ ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,   .quad,  _PAGE_PRESENT,_PAGE_PRESENT)
  ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,       .asciz, "writable_page_tables|writable_descriptor_tables|auto_translated_physmap|pae_pgdir_above_4gb|supervisor_mode_kernel")
  ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz, "generic")
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/mpparse-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/mpparse-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/mpparse-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -170,7 +170,7 @@ static void __cpuinit MP_processor_info
  cpu_set(cpu, cpu_present_map);
 }
 #else
-void __init MP_processor_info (struct mpc_config_processor *m)
+static void __cpuinit MP_processor_info (struct mpc_config_processor *m)
 {
  num_processors++;
 }
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -499,8 +499,6 @@ __switch_to(struct task_struct *prev_p,
  * This is basically '__unlazy_fpu', except that we queue a
  * multicall to indicate FPU task switch, rather than
  * synchronously trapping to Xen.
- * This must be here to ensure both math_state_restore() and
- * kernel_fpu_begin() work consistently.
  * The AMD workaround requires it to be after DS reload, or
  * after DS has been cleared, which we do in __prepare_arch_switch.
  */
@@ -579,7 +577,7 @@ __switch_to(struct task_struct *prev_p,
  HYPERVISOR_set_segment_base(SEGBASE_GS_USER, next->gs);
 
  /*
- * Switch the PDA and FPU contexts.
+ * Switch the PDA context.
  */
  prev->userrsp = read_pda(oldrsp);
  write_pda(oldrsp, next->userrsp);
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -90,9 +90,6 @@ extern char hypercall_page[PAGE_SIZE];
 extern char hypercall_page[PAGE_SIZE];
 EXPORT_SYMBOL(hypercall_page);
 
-/* Allows setting of maximum possible memory size  */
-unsigned long xen_override_max_pfn;
-
 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
 static struct notifier_block xen_panic_block = {
  xen_panic_event, NULL, 0 /* try to go last */
@@ -580,13 +577,13 @@ static void discover_ebda(void)
  if (ebda_size > 64*1024)
  ebda_size = 64*1024;
 }
+#else
+#define discover_ebda() ((void)0)
 #endif
 
 void __init setup_arch(char **cmdline_p)
 {
 #ifdef CONFIG_XEN
- struct xen_memory_map memmap;
-
  /* Register a call for panic conditions. */
  atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
 
@@ -675,9 +672,7 @@ void __init setup_arch(char **cmdline_p)
 
  check_efer();
 
-#ifndef CONFIG_XEN
  discover_ebda();
-#endif
 
  init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
 
@@ -719,7 +714,6 @@ void __init setup_arch(char **cmdline_p)
  /* reserve ebda region */
  if (ebda_addr)
  reserve_bootmem_generic(ebda_addr, ebda_size);
-#endif
 
 #ifdef CONFIG_SMP
  /*
@@ -731,6 +725,7 @@ void __init setup_arch(char **cmdline_p)
 
  /* Reserve SMP trampoline */
  reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
+#endif
 #endif
 
 #ifdef CONFIG_ACPI_SLEEP
@@ -895,6 +890,8 @@ void __init setup_arch(char **cmdline_p)
  probe_roms();
 #ifdef CONFIG_XEN
  if (is_initial_xendomain()) {
+ struct xen_memory_map memmap;
+
  memmap.nr_entries = E820MAX;
  set_xen_guest_handle(memmap.buffer, machine_e820.map);
 
@@ -1378,9 +1375,7 @@ void __cpuinit identify_cpu(struct cpuin
  c->x86_capability[2] = cpuid_edx(0x80860001);
  }
 
-#ifdef CONFIG_X86_XEN_GENAPIC
  c->apicid = phys_pkg_id(0);
-#endif
 
  /*
  * Vendor-specific initialization.  In this section we
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/mm/fault-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/mm/fault-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/mm/fault-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -411,8 +411,7 @@ asmlinkage void __kprobes do_page_fault(
  prefetchw(&mm->mmap_sem);
 
  /* get the address */
- address = HYPERVISOR_shared_info->vcpu_info[
- smp_processor_id()].arch.cr2;
+ address = current_vcpu_info()->arch.cr2;
 
  info.si_code = SEGV_MAPERR;
 
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c Tue Feb 20 12:58:22 2007 -0700
@@ -77,7 +77,7 @@ extern unsigned long start_pfn;
  (((mfn_to_pfn((addr) >> PAGE_SHIFT)) << PAGE_SHIFT) + \
  __START_KERNEL_map)))
 
-static void early_make_page_readonly(void *va, unsigned int feature)
+static void __meminit early_make_page_readonly(void *va, unsigned int feature)
 {
  unsigned long addr, _va = (unsigned long)va;
  pte_t pte, *ptep;
@@ -279,8 +279,8 @@ static __init void set_pte_phys(unsigned
  __flush_tlb_one(vaddr);
 }
 
-static void set_pte_phys_ma(unsigned long vaddr,
- unsigned long phys, pgprot_t prot)
+static __init void set_pte_phys_ma(unsigned long vaddr,
+   unsigned long phys, pgprot_t prot)
 {
  pgd_t *pgd;
  pud_t *pud;
@@ -361,9 +361,10 @@ __set_fixmap (enum fixed_addresses idx,
 }
 
 /*
- * At this point it only supports vsyscall area.
+ * This only supports vsyscall area.
  */
-void __set_fixmap_user (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
+void __init
+__set_fixmap_user (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
 {
  unsigned long address = __fix_to_virt(idx);
 
@@ -376,15 +377,6 @@ void __set_fixmap_user (enum fixed_addre
 }
 
 unsigned long __initdata table_start, table_end;
-
-unsigned long get_machine_pfn(unsigned long addr)
-{
- pud_t* pud = pud_offset_k(NULL, addr);
- pmd_t* pmd = pmd_offset(pud, addr);
- pte_t *pte = pte_offset_kernel(pmd, addr);
-
- return pte_mfn(*pte);
-}
 
 static __meminit void *alloc_static_page(unsigned long *phys)
 {
@@ -531,10 +523,6 @@ void __init xen_init_pt(void)
 {
  unsigned long addr, *page;
 
- memset((void *)init_level4_pgt,   0, PAGE_SIZE);
- memset((void *)level3_kernel_pgt, 0, PAGE_SIZE);
- memset((void *)level2_kernel_pgt, 0, PAGE_SIZE);
-
  /* Find the initial pte page that was built for us. */
  page = (unsigned long *)xen_start_info->pt_base;
  addr = page[pgd_index(__START_KERNEL_map)];
@@ -595,7 +583,7 @@ void __init xen_init_pt(void)
  mk_kernel_pgd(__pa_symbol(level3_user_pgt)));
 }
 
-void __init extend_init_mapping(unsigned long tables_space)
+static void __init extend_init_mapping(unsigned long tables_space)
 {
  unsigned long va = __START_KERNEL_map;
  unsigned long phys, addr, *pte_page;
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/drivers/char/tpm/Kconfig
--- a/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig Sun Feb 18 16:13:13 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig Tue Feb 20 12:58:22 2007 -0700
@@ -22,7 +22,7 @@ config TCG_TPM
 
 config TCG_TIS
  tristate "TPM Interface Specification 1.2 Interface"
- depends on TCG_TPM
+ depends on TCG_TPM && PNPACPI
  ---help---
   If you have a TPM security chip that is compliant with the
   TCG TIS 1.2 TPM specification say Yes and it will be accessible
diff -r 04c23c1ef888 -r d907467f08cd linux-2.6-xen-sparse/drivers/char/tpm/tpm.c
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c Sun Feb 18 16:13:13 2007 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1222 +0,0 @@
-/*
- * Copyright (C) 2004 IBM Corporation
- *
- * Authors:
- * Leendert van Doorn <[hidden email]>
- * Dave Safford <[hidden email]>
- * Reiner Sailer <[hidden email]>
- * Kylene Hall <[hidden email]>
- *
- * Maintained by: <[hidden email]>
- *
- * Device driver for TCG/TCPA TPM (trusted platform module).
- * Specifications at www.trustedcomputinggroup.org
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, version 2 of the
- * License.
- *
- * Note, the TPM chip is not interrupt driven (only polling)
- * and can have very long timeouts (minutes!). Hence the unusual
- * calls to msleep.
- *
- */
-
-#include <linux/sched.h>
-#include <linux/poll.h>
-#include <linux/spinlock.h>
-#include "tpm.h"
-
-enum tpm_const {
- TPM_MINOR = 224, /* officially assigned */
-#ifndef CONFIG_XEN
- TPM_BUFSIZE = 2048,
-#endif
- TPM_NUM_DEVICES = 256,
-};
-
-enum tpm_duration {
- TPM_SHORT = 0,
- TPM_MEDIUM = 1,
- TPM_LONG = 2,
- TPM_UNDEFINED,
-};
-
-#define TPM_MAX_ORDINAL 243
-#define TPM_MAX_PROTECTED_ORDINAL 12
-#define TPM_PROTECTED_ORDINAL_MASK 0xFF
-
-static LIST_HEAD(tpm_chip_list);
-static DEFINE_SPINLOCK(driver_lock);
-static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES);
-
-/*
- * Array with one entry per ordinal defining the maximum amount
- * of time the chip could take to return the result.  The ordinal
- * designation of short, medium or long is defined in a table in
- * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
- * values of the SHORT, MEDIUM, and LONG durations are retrieved
- * from the chip during initialization with a call to tpm_get_timeouts.
- */
-static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = {
- TPM_UNDEFINED, /* 0 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 5 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 10 */
- TPM_SHORT,
-};
-
-static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
- TPM_UNDEFINED, /* 0 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 5 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 10 */
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_LONG,
- TPM_LONG,
- TPM_MEDIUM, /* 15 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_LONG,
- TPM_SHORT, /* 20 */
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_SHORT, /* 25 */
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_SHORT,
- TPM_SHORT,
- TPM_MEDIUM, /* 30 */
- TPM_LONG,
- TPM_MEDIUM,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT, /* 35 */
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_MEDIUM, /* 40 */
- TPM_LONG,
- TPM_MEDIUM,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT, /* 45 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_LONG,
- TPM_MEDIUM, /* 50 */
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 55 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_MEDIUM, /* 60 */
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_SHORT,
- TPM_SHORT,
- TPM_MEDIUM, /* 65 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 70 */
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 75 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_LONG, /* 80 */
- TPM_UNDEFINED,
- TPM_MEDIUM,
- TPM_LONG,
- TPM_SHORT,
- TPM_UNDEFINED, /* 85 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 90 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED, /* 95 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_MEDIUM, /* 100 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 105 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 110 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT, /* 115 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_LONG, /* 120 */
- TPM_LONG,
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_SHORT,
- TPM_SHORT, /* 125 */
- TPM_SHORT,
- TPM_LONG,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT, /* 130 */
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_UNDEFINED, /* 135 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 140 */
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 145 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 150 */
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED, /* 155 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 160 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 165 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_LONG, /* 170 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 175 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_MEDIUM, /* 180 */
- TPM_SHORT,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_MEDIUM, /* 185 */
- TPM_SHORT,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 190 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 195 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 200 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT,
- TPM_SHORT, /* 205 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_MEDIUM, /* 210 */
- TPM_UNDEFINED,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_MEDIUM,
- TPM_UNDEFINED, /* 215 */
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT,
- TPM_SHORT, /* 220 */
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_SHORT,
- TPM_UNDEFINED, /* 225 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 230 */
- TPM_LONG,
- TPM_MEDIUM,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED, /* 235 */
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_UNDEFINED,
- TPM_SHORT, /* 240 */
- TPM_UNDEFINED,
- TPM_MEDIUM,
-};
-
-static void user_reader_timeout(unsigned long ptr)
-{
- struct tpm_chip *chip = (struct tpm_chip *) ptr;
-
- schedule_work(&chip->work);
-}
-
-static void timeout_work(void *ptr)
-{
- struct tpm_chip *chip = ptr;
-
- down(&chip->buffer_mutex);
- atomic_set(&chip->data_pending, 0);
-#ifndef CONFIG_XEN
- memset(chip->data_buffer, 0, TPM_BUFSIZE);
-#else
- memset(chip->data_buffer, 0, get_chip_buffersize(chip));
-#endif
- up(&chip->buffer_mutex);
-}
-
-/*
- * Returns max number of jiffies to wait
- */
-unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
-   u32 ordinal)
-{
- int duration_idx = TPM_UNDEFINED;
- int duration = 0;
-
- if (ordinal < TPM_MAX_ORDINAL)
- duration_idx = tpm_ordinal_duration[ordinal];
- else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
- TPM_MAX_PROTECTED_ORDINAL)
- duration_idx =
-    tpm_protected_ordinal_duration[ordinal &
-   TPM_PROTECTED_ORDINAL_MASK];
-
- if (duration_idx != TPM_UNDEFINED)
- duration = chip->vendor.duration[duration_idx];
- if (duration <= 0)
- return 2 * 60 * HZ;
- else
- return duration;
-}
-EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
-
-/*
- * Internal kernel interface to transmit TPM commands
- */
-static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
-    size_t bufsiz)
-{
- ssize_t rc;
- u32 count, ordinal;
- unsigned long stop;
-
- count = be32_to_cpu(*((__be32 *) (buf + 2)));
- ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
- if (count == 0)
- return -ENODATA;
- if (count > bufsiz) {
- dev_err(chip->dev,
- "invalid count value %x %zx \n", count, bufsiz);
- return -E2BIG;
- }
-
- down(&chip->tpm_mutex);
-
- if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) {
- dev_err(chip->dev,
- "tpm_transmit: tpm_send: error %zd\n", rc);
- goto out;
- }
-
- if (chip->vendor.irq)
- goto out_recv;
-
- stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
- do {
- u8 status = chip->vendor.status(chip);
- if ((status & chip->vendor.req_complete_mask) ==
-    chip->vendor.req_complete_val)
- goto out_recv;
-
- if ((status == chip->vendor.req_canceled)) {
- dev_err(chip->dev, "Operation Canceled\n");
- rc = -ECANCELED;
- goto out;
- }
-
- msleep(TPM_TIMEOUT); /* CHECK */
- rmb();
- } while (time_before(jiffies, stop));
-
- chip->vendor.cancel(chip);
- dev_err(chip->dev, "Operation Timed out\n");
- rc = -ETIME;
- goto out;
-
-out_recv:
- rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz);
- if (rc < 0)
- dev_err(chip->dev,
- "tpm_transmit: tpm_recv: error %zd\n", rc);
-out:
- up(&chip->tpm_mutex);
- return rc;
-}
-
-#define TPM_DIGEST_SIZE 20
-#define TPM_ERROR_SIZE 10
-#define TPM_RET_CODE_IDX 6
-#define TPM_GET_CAP_RET_SIZE_IDX 10
-#define TPM_GET_CAP_RET_UINT32_1_IDX 14
-#define TPM_GET_CAP_RET_UINT32_2_IDX 18
-#define TPM_GET_CAP_RET_UINT32_3_IDX 22
-#define TPM_GET_CAP_RET_UINT32_4_IDX 26
-#define TPM_GET_CAP_PERM_DISABLE_IDX 16
-#define TPM_GET_CAP_PERM_INACTIVE_IDX 18
-#define TPM_GET_CAP_RET_BOOL_1_IDX 14
-#define TPM_GET_CAP_TEMP_INACTIVE_IDX 16
-
-#define TPM_CAP_IDX 13
-#define TPM_CAP_SUBCAP_IDX 21
-
-enum tpm_capabilities {
- TPM_CAP_FLAG = 4,
- TPM_CAP_PROP = 5,
-};
-
-enum tpm_sub_capabilities {
- TPM_CAP_PROP_PCR = 0x1,
- TPM_CAP_PROP_MANUFACTURER = 0x3,
- TPM_CAP_FLAG_PERM = 0x8,
- TPM_CAP_FLAG_VOL = 0x9,
- TPM_CAP_PROP_OWNER = 0x11,
- TPM_CAP_PROP_TIS_TIMEOUT = 0x15,
- TPM_CAP_PROP_TIS_DURATION = 0x20,
-};
-
-/*
- * This is a semi generic GetCapability command for use
- * with the capability type TPM_CAP_PROP or TPM_CAP_FLAG
- * and their associated sub_capabilities.
- */
-
-static const u8 tpm_cap[] = {
- 0, 193, /* TPM_TAG_RQU_COMMAND */
- 0, 0, 0, 22, /* length */
- 0, 0, 0, 101, /* TPM_ORD_GetCapability */
- 0, 0, 0, 0, /* TPM_CAP_<TYPE> */
- 0, 0, 0, 4, /* TPM_CAP_SUB_<TYPE> size */
- 0, 0, 1, 0 /* TPM_CAP_SUB_<TYPE> */
-};
-
-static ssize_t transmit_cmd(struct tpm_chip *chip, u8 *data, int len,
-    char *desc)
-{
- int err;
-
- len = tpm_transmit(chip, data, len);
- if (len <  0)
- return len;
- if (len == TPM_ERROR_SIZE) {
- err = be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)));
- dev_dbg(chip->dev, "A TPM error (%d) occurred %s\n", err, desc);
- return err;
- }
- return 0;
-}
-
-void tpm_gen_interrupt(struct tpm_chip *chip)
-{
- u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)];
- ssize_t rc;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the timeouts");
-}
-EXPORT_SYMBOL_GPL(tpm_gen_interrupt);
-
-void tpm_get_timeouts(struct tpm_chip *chip)
-{
- u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)];
- ssize_t rc;
- u32 timeout;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the timeouts");
- if (rc)
- goto duration;
-
- if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX)))
-    != 4 * sizeof(u32))
- goto duration;
-
- /* Don't overwrite default if value is 0 */
- timeout =
-    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
- if (timeout)
- chip->vendor.timeout_a = msecs_to_jiffies(timeout);
- timeout =
-    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
- if (timeout)
- chip->vendor.timeout_b = msecs_to_jiffies(timeout);
- timeout =
-    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
- if (timeout)
- chip->vendor.timeout_c = msecs_to_jiffies(timeout);
- timeout =
-    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
- if (timeout)
- chip->vendor.timeout_d = msecs_to_jiffies(timeout);
-
-duration:
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_DURATION;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the durations");
- if (rc)
- return;
-
- if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX)))
-    != 3 * sizeof(u32))
- return;
-
- chip->vendor.duration[TPM_SHORT] =
-    msecs_to_jiffies(be32_to_cpu
-     (*((__be32 *) (data +
-    TPM_GET_CAP_RET_UINT32_1_IDX))));
- chip->vendor.duration[TPM_MEDIUM] =
-    msecs_to_jiffies(be32_to_cpu
-     (*((__be32 *) (data +
-    TPM_GET_CAP_RET_UINT32_2_IDX))));
- chip->vendor.duration[TPM_LONG] =
-    msecs_to_jiffies(be32_to_cpu
-     (*((__be32 *) (data +
-    TPM_GET_CAP_RET_UINT32_3_IDX))));
-}
-EXPORT_SYMBOL_GPL(tpm_get_timeouts);
-
-void tpm_continue_selftest(struct tpm_chip *chip)
-{
- u8 data[] = {
- 0, 193, /* TPM_TAG_RQU_COMMAND */
- 0, 0, 0, 10, /* length */
- 0, 0, 0, 83, /* TPM_ORD_GetCapability */
- };
-
- tpm_transmit(chip, data, sizeof(data));
-}
-EXPORT_SYMBOL_GPL(tpm_continue_selftest);
-
-ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr,
- char *buf)
-{
- u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)];
- ssize_t rc;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_FLAG;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attemtping to determine the permanent state");
- if (rc)
- return 0;
- return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_DISABLE_IDX]);
-}
-EXPORT_SYMBOL_GPL(tpm_show_enabled);
-
-ssize_t tpm_show_active(struct device * dev, struct device_attribute * attr,
- char *buf)
-{
- u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)];
- ssize_t rc;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_FLAG;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attemtping to determine the permanent state");
- if (rc)
- return 0;
- return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_INACTIVE_IDX]);
-}
-EXPORT_SYMBOL_GPL(tpm_show_active);
-
-ssize_t tpm_show_owned(struct device * dev, struct device_attribute * attr,
- char *buf)
-{
- u8 data[sizeof(tpm_cap)];
- ssize_t rc;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_OWNER;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the owner state");
- if (rc)
- return 0;
- return sprintf(buf, "%d\n", data[TPM_GET_CAP_RET_BOOL_1_IDX]);
-}
-EXPORT_SYMBOL_GPL(tpm_show_owned);
-
-ssize_t tpm_show_temp_deactivated(struct device * dev,
- struct device_attribute * attr, char *buf)
-{
- u8 data[sizeof(tpm_cap)];
- ssize_t rc;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_FLAG;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_VOL;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the temporary state");
- if (rc)
- return 0;
- return sprintf(buf, "%d\n", data[TPM_GET_CAP_TEMP_INACTIVE_IDX]);
-}
-EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated);
-
-static const u8 pcrread[] = {
- 0, 193, /* TPM_TAG_RQU_COMMAND */
- 0, 0, 0, 14, /* length */
- 0, 0, 0, 21, /* TPM_ORD_PcrRead */
- 0, 0, 0, 0 /* PCR index */
-};
-
-ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
-      char *buf)
-{
- u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(pcrread)), 30)];
- ssize_t rc;
- int i, j, num_pcrs;
- __be32 index;
- char *str = buf;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the number of PCRS");
- if (rc)
- return 0;
-
- num_pcrs = be32_to_cpu(*((__be32 *) (data + 14)));
- for (i = 0; i < num_pcrs; i++) {
- memcpy(data, pcrread, sizeof(pcrread));
- index = cpu_to_be32(i);
- memcpy(data + 10, &index, 4);
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to read a PCR");
- if (rc)
- goto out;
- str += sprintf(str, "PCR-%02d: ", i);
- for (j = 0; j < TPM_DIGEST_SIZE; j++)
- str += sprintf(str, "%02X ", *(data + 10 + j));
- str += sprintf(str, "\n");
- }
-out:
- return str - buf;
-}
-EXPORT_SYMBOL_GPL(tpm_show_pcrs);
-
-#define  READ_PUBEK_RESULT_SIZE 314
-static const u8 readpubek[] = {
- 0, 193, /* TPM_TAG_RQU_COMMAND */
- 0, 0, 0, 30, /* length */
- 0, 0, 0, 124, /* TPM_ORD_ReadPubek */
-};
-
-ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
-       char *buf)
-{
- u8 *data;
- ssize_t err;
- int i, rc;
- char *str = buf;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
- if (!data)
- return -ENOMEM;
-
- memcpy(data, readpubek, sizeof(readpubek));
-
- err = transmit_cmd(chip, data, READ_PUBEK_RESULT_SIZE,
- "attempting to read the PUBEK");
- if (err)
- goto out;
-
- /*
-   ignore header 10 bytes
-   algorithm 32 bits (1 == RSA )
-   encscheme 16 bits
-   sigscheme 16 bits
-   parameters (RSA 12->bytes: keybit, #primes, expbit)  
-   keylenbytes 32 bits
-   256 byte modulus
-   ignore checksum 20 bytes
- */
-
- str +=
-    sprintf(str,
-    "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n"
-    "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X"
-    " %02X %02X %02X %02X %02X %02X %02X %02X\n"
-    "Modulus length: %d\nModulus: \n",
-    data[10], data[11], data[12], data[13], data[14],
-    data[15], data[16], data[17], data[22], data[23],
-    data[24], data[25], data[26], data[27], data[28],
-    data[29], data[30], data[31], data[32], data[33],
-    be32_to_cpu(*((__be32 *) (data + 34))));
-
- for (i = 0; i < 256; i++) {
- str += sprintf(str, "%02X ", data[i + 38]);
- if ((i + 1) % 16 == 0)
- str += sprintf(str, "\n");
- }
-out:
- rc = str - buf;
- kfree(data);
- return rc;
-}
-EXPORT_SYMBOL_GPL(tpm_show_pubek);
-
-#define CAP_VERSION_1_1 6
-#define CAP_VERSION_1_2 0x1A
-#define CAP_VERSION_IDX 13
-static const u8 cap_version[] = {
- 0, 193, /* TPM_TAG_RQU_COMMAND */
- 0, 0, 0, 18, /* length */
- 0, 0, 0, 101, /* TPM_ORD_GetCapability */
- 0, 0, 0, 0,
- 0, 0, 0, 0
-};
-
-ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
-      char *buf)
-{
- u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)];
- ssize_t rc;
- char *str = buf;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
-
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the manufacturer");
- if (rc)
- return 0;
-
- str += sprintf(str, "Manufacturer: 0x%x\n",
-       be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))));
-
- memcpy(data, cap_version, sizeof(cap_version));
- data[CAP_VERSION_IDX] = CAP_VERSION_1_1;
- rc = transmit_cmd(chip, data, sizeof(data),
- "attempting to determine the 1.1 version");
- if (rc)
- goto out;
-
- str += sprintf(str,
-       "TCG version: %d.%d\nFirmware version: %d.%d\n",
-       (int) data[14], (int) data[15], (int) data[16],
-       (int) data[17]);
-
-out:
- return str - buf;
-}
-EXPORT_SYMBOL_GPL(tpm_show_caps);
-
-ssize_t tpm_show_caps_1_2(struct device * dev,
-  struct device_attribute * attr, char *buf)
-{
- u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)];
- ssize_t len;
- char *str = buf;
-
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return -ENODEV;
-
- memcpy(data, tpm_cap, sizeof(tpm_cap));
- data[TPM_CAP_IDX] = TPM_CAP_PROP;
- data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
-
- if ((len = tpm_transmit(chip, data, sizeof(data))) <=
-    TPM_ERROR_SIZE) {
- dev_dbg(chip->dev, "A TPM error (%d) occurred "
- "attempting to determine the manufacturer\n",
- be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
- return 0;
- }
-
- str += sprintf(str, "Manufacturer: 0x%x\n",
-       be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))));
-
- memcpy(data, cap_version, sizeof(cap_version));
- data[CAP_VERSION_IDX] = CAP_VERSION_1_2;
-
- if ((len = tpm_transmit(chip, data, sizeof(data))) <=
-    TPM_ERROR_SIZE) {
- dev_err(chip->dev, "A TPM error (%d) occurred "
- "attempting to determine the 1.2 version\n",
- be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
- goto out;
- }
- str += sprintf(str,
-       "TCG version: %d.%d\nFirmware version: %d.%d\n",
-       (int) data[16], (int) data[17], (int) data[18],
-       (int) data[19]);
-
-out:
- return str - buf;
-}
-EXPORT_SYMBOL_GPL(tpm_show_caps_1_2);
-
-ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct tpm_chip *chip = dev_get_drvdata(dev);
- if (chip == NULL)
- return 0;
-
- chip->vendor.cancel(chip);
- return count;
-}
-EXPORT_SYMBOL_GPL(tpm_store_cancel);
-
-/*
- * Device file system interface to the TPM
- */
-int tpm_open(struct inode *inode, struct file *file)
-{
- int rc = 0, minor = iminor(inode);
- struct tpm_chip *chip = NULL, *pos;
-
- spin_lock(&driver_lock);
-
- list_for_each_entry(pos, &tpm_chip_list, list) {
- if (pos->vendor.miscdev.minor == minor) {
- chip = pos;
- break;
- }
- }
-
- if (chip == NULL) {
- rc = -ENODEV;
- goto err_out;
- }
-
- if (chip->num_opens) {
- dev_dbg(chip->dev, "Another process owns this TPM\n");
- rc = -EBUSY;
- goto err_out;
- }
-
- chip->num_opens++;
- get_device(chip->dev);
-
- spin_unlock(&driver_lock);
-
-#ifndef CONFIG_XEN
- chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
-#else
- chip->data_buffer = kmalloc(get_chip_buffersize(chip) * sizeof(u8),
-                            GFP_KERNEL);
-#endif
- if (chip->data_buffer == NULL) {
- chip->num_opens--;
- put_device(chip->dev);
- return -ENOMEM;
- }
-
- atomic_set(&chip->data_pending, 0);
-
- file->private_data = chip;
- return 0;
-
-err_out:
- spin_unlock(&driver_lock);
- return rc;
-}
-EXPORT_SYMBOL_GPL(tpm_open);
-
-int tpm_release(struct inode *inode, struct file *file)
-{
- struct tpm_chip *chip = file->private_data;
-
- spin_lock(&driver_lock);
- file->private_data = NULL;
- chip->num_opens--;
- del_singleshot_timer_sync(&chip->user_read_timer);
- flush_scheduled_work();
- atomic_set(&chip->data_pending, 0);
- put_device(chip->dev);
- kfree(chip->data_buffer);
- spin_unlock(&driver_lock);
- return 0;
-}
-EXPORT_SYMBOL_GPL(tpm_release);
-
-ssize_t tpm_write(struct file *file, const char __user *buf,
-  size_t size, loff_t *off)
-{
- struct tpm_chip *chip = file->private_data;
- int in_size = size, out_size;
-
- /* cannot perform a write until the read has cleared
-   either via tpm_read or a user_read_timer timeout */
- while (atomic_read(&chip->data_pending) != 0)
- msleep(TPM_TIMEOUT);
-
- down(&chip->buffer_mutex);
-
-#ifndef CONFIG_XEN
- if (in_size > TPM_BUFSIZE)
- in_size = TPM_BUFSIZE;
-#else
- if (in_size > get_chip_buffersize(chip))
- in_size = get_chip_buffersize(chip);
-#endif
-
- if (copy_from_user
-    (chip->data_buffer, (void __user *) buf, in_size)) {
- up(&chip->buffer_mutex);
- return -EFAULT;
- }
-
- /* atomic tpm command send and result receive */
-#