From nobody Tue Nov 4 16:02:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504040743214945.43291723948; Tue, 29 Aug 2017 14:05:43 -0700 (PDT) Received: from localhost ([::1]:46990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmnhd-0000yQ-26 for importer@patchew.org; Tue, 29 Aug 2017 17:05:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmnSO-0003mp-L5 for qemu-devel@nongnu.org; Tue, 29 Aug 2017 16:49:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmnSN-0001zf-ID for qemu-devel@nongnu.org; Tue, 29 Aug 2017 16:49:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dmnSI-0001x2-T9; Tue, 29 Aug 2017 16:49:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D893791FFE; Tue, 29 Aug 2017 20:49:49 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 448C66268F; Tue, 29 Aug 2017 20:49:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D893791FFE Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jsnow@redhat.com From: John Snow To: qemu-block@nongnu.org Date: Tue, 29 Aug 2017 16:49:33 -0400 Message-Id: <20170829204934.9039-9-jsnow@redhat.com> In-Reply-To: <20170829204934.9039-1-jsnow@redhat.com> References: <20170829204934.9039-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 29 Aug 2017 20:49:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 8/9] AHCI: pretty-print FIS to buffer instead of stderr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , qemu-devel@nongnu.org, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current FIS printing routines dump the FIS to screen. adjust this such that it dumps to buffer instead, then use this ability to have FIS dump mechanisms via trace-events instead of compiled defines. Signed-off-by: John Snow --- hw/ide/ahci.c | 54 +++++++++++++++++++++++++++++++++++++++++++------= ---- hw/ide/trace-events | 4 ++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index a0a4dd6..2e75f9b 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -644,20 +644,45 @@ static void ahci_reset_port(AHCIState *s, int port) ahci_init_d2h(d); } =20 -static void debug_print_fis(uint8_t *fis, int cmd_len) +/* Buffer pretty output based on a raw FIS structure. */ +static void ahci_pretty_buffer_fis(uint8_t *fis, int cmd_len, char **out) { -#if DEBUG_AHCI + size_t bufsize; + char *pbuf; + char *pptr; + size_t lines =3D DIV_ROUND_UP(cmd_len, 16); + const char *preamble =3D "FIS:"; int i; =20 - fprintf(stderr, "fis:"); + /* Total amount of memory to store FISes in HBA memory */ + g_assert_cmpint(cmd_len, <=3D, 0x100); + g_assert(out); + + /* Printed like: + * FIS:\n + * 0x00: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee \n + * 0x10: ff \n + * \0 + * + * Four bytes for the preamble, seven for each line prefix (including a + * newline to start a new line), three bytes for each source byte, + * a trailing newline and a terminal null byte. + */ + + bufsize =3D strlen(preamble) + ((6 + 1) * lines) + (3 * cmd_len) + 1 += 1; + pbuf =3D g_malloc(bufsize); + pptr =3D pbuf; + pptr +=3D sprintf(pptr, "%s", preamble); for (i =3D 0; i < cmd_len; i++) { if ((i & 0xf) =3D=3D 0) { - fprintf(stderr, "\n%02x:",i); + pptr +=3D sprintf(pptr, "\n0x%02x: ", i); } - fprintf(stderr, "%02x ",fis[i]); + pptr +=3D sprintf(pptr, "%02x ", fis[i]); } - fprintf(stderr, "\n"); -#endif + pptr +=3D sprintf(pptr, "\n"); + pptr +=3D 1; /* \0 */ + g_assert(pbuf + bufsize =3D=3D pptr); + *out =3D pbuf; } =20 static bool ahci_map_fis_address(AHCIDevice *ad) @@ -1201,7 +1226,12 @@ static void handle_reg_h2d_fis(AHCIState *s, int por= t, * table to ide_state->io_buffer */ if (opts & AHCI_CMD_ATAPI) { memcpy(ide_state->io_buffer, &cmd_fis[AHCI_COMMAND_TABLE_ACMD], 0x= 10); - debug_print_fis(ide_state->io_buffer, 0x10); + if (TRACE_HANDLE_REG_H2D_FIS_DUMP_ENABLED) { + char *pretty_fis; + ahci_pretty_buffer_fis(ide_state->io_buffer, 0x10, &pretty_fis= ); + trace_handle_reg_h2d_fis_dump(s, port, pretty_fis); + g_free(pretty_fis); + } s->dev[port].done_atapi_packet =3D false; /* XXX send PIO setup FIS */ } @@ -1256,8 +1286,12 @@ static int handle_cmd(AHCIState *s, int port, uint8_= t slot) trace_handle_cmd_badmap(s, port, cmd_len); goto out; } - debug_print_fis(cmd_fis, 0x80); - + if (TRACE_HANDLE_CMD_FIS_DUMP_ENABLED) { + char *pretty_fis; + ahci_pretty_buffer_fis(cmd_fis, 0x80, &pretty_fis); + trace_handle_cmd_fis_dump(s, port, pretty_fis); + g_free(pretty_fis); + } switch (cmd_fis[0]) { case SATA_FIS_TYPE_REGISTER_H2D: handle_reg_h2d_fis(s, port, slot, cmd_fis); diff --git a/hw/ide/trace-events b/hw/ide/trace-events index e15fd77..77ed3c1 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -105,3 +105,7 @@ ahci_cmd_done(void *s, int port) "ahci(%p)[%d]: cmd don= e" ahci_reset(void *s) "ahci(%p): HBA reset" allwinner_ahci_mem_read(void *s, void *a, uint64_t addr, uint64_t val, uns= igned size) "ahci(%p): read a=3D%p addr=3D0x%"HWADDR_PRIx" val=3D0x%"PRIx64= ", size=3D%d" allwinner_ahci_mem_write(void *s, void *a, uint64_t addr, uint64_t val, un= signed size) "ahci(%p): write a=3D%p addr=3D0x%"HWADDR_PRIx" val=3D0x%"PRIx= 64", size=3D%d" + +# Warning: Verbose +handle_reg_h2d_fis_dump(void *s, int port, char *fis) "ahci(%p)[%d]: %s" +handle_cmd_fis_dump(void *s, int port, char *fis) "ahci(%p)[%d]: %s" --=20 2.9.5