From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8EBi-0005NR-QT for qemu-devel@nongnu.org; Mon, 26 Sep 2011 12:37:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8EBc-0002cZ-VW for qemu-devel@nongnu.org; Mon, 26 Sep 2011 12:37:50 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:49354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8EBc-0002cE-RY for qemu-devel@nongnu.org; Mon, 26 Sep 2011 12:37:44 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p8QGDNlU006588 for ; Mon, 26 Sep 2011 12:13:23 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p8QGbXt6215082 for ; Mon, 26 Sep 2011 12:37:33 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p8QGbWit013169 for ; Mon, 26 Sep 2011 10:37:33 -0600 Message-Id: <20110926163730.266368183@linux.vnet.ibm.com> Date: Mon, 26 Sep 2011 12:35:12 -0400 From: Stefan Berger References: <20110926163509.020984459@linux.vnet.ibm.com> Content-Disposition: inline; filename=qemu_tpm_tis_debugreg.diff Subject: [Qemu-devel] [PATCH V9 3/5] Add a debug register List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org Cc: anbang.ruan@cs.ox.ac.uk, mst@redhat.com, andreas.niederl@iaik.tugraz.at, serge@hallyn.com This patch uses the possibility to add a vendor-specific register and adds a debug register useful for dumping the TIS's internal state. This register is only active in a debug build (#define DEBUG_TIS). v9: - prefixing all function with tpm_tis_ and all constants with TPM_TIS_ v3: - all output goes to stderr Signed-off-by: Stefan Berger --- hw/tpm_tis.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) Index: qemu-git.pt/hw/tpm_tis.c =================================================================== --- qemu-git.pt.orig/hw/tpm_tis.c +++ qemu-git.pt/hw/tpm_tis.c @@ -45,6 +45,9 @@ #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) @@ -320,6 +323,66 @@ static uint32_t tpm_tis_data_read(TPMSta return ret; } +#ifdef DEBUG_TIS +static void tpm_tis_dump_state(void *opaque, target_phys_addr_t 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); + target_phys_addr_t base = addr & ~0xfff; + TPMState *s = opaque; + TPMTISState *tis = &s->s.tis; + + fprintf(stderr, + "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++) { + fprintf(stderr, "tpm_tis: 0x%04x : 0x%08x\n", regs[idx], + tpm_tis_mem_readl(opaque, base + regs[idx])); + } + + fprintf(stderr, + "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++) { + fprintf(stderr, "%c%02x%s", + tis->loc[locty].r_offset == idx ? '>' : ' ', + tis->loc[locty].r_buffer.buffer[idx], + ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); + } + fprintf(stderr, + "\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++) { + fprintf(stderr, "%c%02x%s", + tis->loc[locty].w_offset == idx ? '>' : ' ', + tis->loc[locty].w_buffer.buffer[idx], + ((idx & 0xf) == 0xf) ? "\ntpm_tis: " : ""); + } + fprintf(stderr, "\n"); +} +#endif + /* * Read a register of the TIS interface * See specs pages 33-63 for description of the registers @@ -391,6 +454,11 @@ static uint32_t tpm_tis_mem_readl(void * 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 } qemu_mutex_unlock(&s->state_lock);