From patchwork Tue Oct 11 17:32:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 119026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1022FB6F67 for ; Wed, 12 Oct 2011 04:34:17 +1100 (EST) Received: from localhost ([::1]:49215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDgDW-0000T2-21 for incoming@patchwork.ozlabs.org; Tue, 11 Oct 2011 13:34:14 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDgDK-0000HJ-Ds for qemu-devel@nongnu.org; Tue, 11 Oct 2011 13:34:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDgDI-0001CK-KG for qemu-devel@nongnu.org; Tue, 11 Oct 2011 13:34:02 -0400 Received: from e32.co.us.ibm.com ([32.97.110.150]:50200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDgDI-0001Bl-5c for qemu-devel@nongnu.org; Tue, 11 Oct 2011 13:34:00 -0400 Received: from /spool/local by us.ibm.com with XMail ESMTP for from ; Tue, 11 Oct 2011 11:33:52 -0600 Received: from d03relay05.boulder.ibm.com ([9.17.195.107]) by us.ibm.com ([192.168.1.132]) with XMail ESMTP; Tue, 11 Oct 2011 11:33:28 -0600 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9BHX7jF060594 for ; Tue, 11 Oct 2011 11:33:10 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9BHX6KJ013440 for ; Tue, 11 Oct 2011 11:33:06 -0600 Received: from localhost.localdomain (d941e-10.watson.ibm.com [9.59.241.154]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p9BHX5Ob013393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Oct 2011 11:33:06 -0600 Received: from localhost.localdomain (d941e-10 [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.3) with ESMTP id p9BHX5Hh027693; Tue, 11 Oct 2011 13:33:05 -0400 Received: (from root@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) id p9BHX5ve027692; Tue, 11 Oct 2011 13:33:05 -0400 Message-Id: <20111011173305.173995155@linux.vnet.ibm.com> User-Agent: quilt/0.48-1 Date: Tue, 11 Oct 2011 13:32:19 -0400 From: Stefan Berger To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org References: <20111011173216.247822737@linux.vnet.ibm.com> Content-Disposition: inline; filename=qemu_tpm_tis_debugreg.diff x-cbid: 11101117-3270-0000-0000-000000C88204 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.150 Cc: mst@redhat.com, andreas.niederl@iaik.tugraz.at, serge@hallyn.com Subject: [Qemu-devel] [PATCH V12 3/8] Add a debug register X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) Index: qemu-git.pt/hw/tpm_tis.c =================================================================== --- qemu-git.pt.orig/hw/tpm_tis.c +++ qemu-git.pt/hw/tpm_tis.c @@ -47,6 +47,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) @@ -92,6 +95,11 @@ #define TPM_TIS_NO_DATA_BYTE 0xff +/* local prototypes */ +static uint64_t tpm_tis_mmio_read(void *opaque, target_phys_addr_t addr, + unsigned size); + + #ifdef DEBUG_TIS static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *string) { @@ -319,6 +327,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], + (uint32_t)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); + } + + 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 +459,11 @@ static uint64_t tpm_tis_mmio_read(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);