From patchwork Fri Oct 31 11:33:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 5204031 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E47B2C11AC for ; Fri, 31 Oct 2014 11:33:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EED32015A for ; Fri, 31 Oct 2014 11:33:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 32B0120123 for ; Fri, 31 Oct 2014 11:33:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B5CF56E13D; Fri, 31 Oct 2014 04:33:31 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from relay.fireflyinternet.com (hostedrelay.fireflyinternet.com [109.228.30.76]) by gabe.freedesktop.org (Postfix) with ESMTP id 631EC6E13D for ; Fri, 31 Oct 2014 04:33:30 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by relay.fireflyinternet.com (FireflyRelay1) with ESMTP id 12382235-1305619 for multiple; Fri, 31 Oct 2014 11:38:31 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 31 Oct 2014 11:33:25 +0000 Message-Id: <1414755205-18888-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1414755171-18844-1-git-send-email-chris@chris-wilson.co.uk> References: <1414755171-18844-1-git-send-email-chris@chris-wilson.co.uk> X-Authenticated-User: chris.alporthouse@surfanytime.net Subject: [Intel-gfx] [PATCH] intel_error_decode: Inflate compressed error state X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Recent kernels compress the active objects using zlib + ascii85 encoding. This adapts the tool to decompress those inplace. Signed-off-by: Chris Wilson --- tools/Makefile.sources | 1 + tools/intel_error_decode.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/tools/Makefile.sources b/tools/Makefile.sources index 48b89db..94c070c 100644 --- a/tools/Makefile.sources +++ b/tools/Makefile.sources @@ -42,6 +42,7 @@ intel_dump_decode_SOURCES = \ intel_error_decode_SOURCES = \ intel_error_decode.c +intel_error_decode_LDFLAGS = -lz intel_bios_reader_SOURCES = \ intel_bios_reader.c \ diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c index 14589a3..b443e35 100644 --- a/tools/intel_error_decode.c +++ b/tools/intel_error_decode.c @@ -51,6 +51,7 @@ #include #include #include +#include #include "intel_chipset.h" #include "intel_io.h" @@ -334,6 +335,87 @@ static void decode(struct drm_intel_decode *ctx, bool is_batch, *count = 0; } +static int zlib_inflate(uint32_t **ptr, int len) +{ + struct z_stream_s zstream; + void *out; + + memset(&zstream, 0, sizeof(zstream)); + + zstream.next_in = (unsigned char *)*ptr; + zstream.avail_in = 4*len; + + if (inflateInit(&zstream) != Z_OK) + return 0; + + out = malloc(128*4096); /* approximate obj size */ + zstream.next_out = out; + zstream.avail_out = 40*len; + + do { + switch (inflate(&zstream, Z_SYNC_FLUSH)) { + case Z_STREAM_END: + goto end; + case Z_OK: + break; + default: + inflateEnd(&zstream); + return 0; + } + + if (zstream.avail_out) + break; + + out = realloc(out, 2*zstream.total_out); + if (out == NULL) { + inflateEnd(&zstream); + return 0; + } + + zstream.next_out = (unsigned char *)out + zstream.total_out; + zstream.avail_out = zstream.total_out; + } while (1); +end: + inflateEnd(&zstream); + free(*ptr); + *ptr = out; + return zstream.total_out / 4; +} + +static int ascii85_decode(const char *in, uint32_t **out) +{ + int len = 0, size = 1024; + + *out = realloc(*out, sizeof(uint32_t)*size); + if (*out == NULL) + return 0; + + while (*in != '\n') { + uint32_t v = 0; + + if (len == size) { + size *= 2; + *out = realloc(*out, sizeof(uint32_t)*size); + if (*out == NULL) + return 0; + } + + if (*in == 'z') { + in++; + } else { + v += in[0] - 33; v *= 85; + v += in[1] - 33; v *= 85; + v += in[2] - 33; v *= 85; + v += in[3] - 33; v *= 85; + v += in[4] - 33; + in += 5; + } + (*out)[len++] = v; + } + + return zlib_inflate(out, len); +} + static void read_data_file(FILE *file) { @@ -387,6 +469,17 @@ read_data_file(FILE *file) } } + if (line[0] == ':') { + count = ascii85_decode(line+1, &data); + if (count == 0) { + fprintf(stderr, "ASCII85 decode failed.\n"); + exit(1); + } + decode(decode_ctx, is_batch, ring_name, gtt_offset, + data, &count); + continue; + } + matched = sscanf(line, "%08x : %08x", &offset, &value); if (matched != 2) { unsigned int reg;