Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

include: Move ascii85 functions from i915 to linux/ascii85.h

The i915 DRM driver very cleverly used ascii85 encoding for their
GPU state file. Move the encode functions to a general header file to
support other drivers that might be interested in the same
functionality.

v4: Make the return value const char * as suggested by Chris Wilson
v3: Fix error_puts -> err_puts pointed out by the 01.org bot
v2: Update API to be cleaner for the caller as suggested by Chris Wilson

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rob Clark <robdclark@gmail.com>

authored by

Jordan Crouse and committed by
Rob Clark
489cae63 2f2eb723

+42 -30
+4 -30
drivers/gpu/drm/i915/i915_gpu_error.c
··· 31 31 #include <linux/stop_machine.h> 32 32 #include <linux/zlib.h> 33 33 #include <drm/drm_print.h> 34 + #include <linux/ascii85.h> 34 35 35 36 #include "i915_gpu_error.h" 36 37 #include "i915_drv.h" ··· 518 517 va_end(args); 519 518 } 520 519 521 - static int 522 - ascii85_encode_len(int len) 523 - { 524 - return DIV_ROUND_UP(len, 4); 525 - } 526 - 527 - static bool 528 - ascii85_encode(u32 in, char *out) 529 - { 530 - int i; 531 - 532 - if (in == 0) 533 - return false; 534 - 535 - out[5] = '\0'; 536 - for (i = 5; i--; ) { 537 - out[i] = '!' + in % 85; 538 - in /= 85; 539 - } 540 - 541 - return true; 542 - } 543 - 544 520 static void print_error_obj(struct drm_i915_error_state_buf *m, 545 521 struct intel_engine_cs *engine, 546 522 const char *name, 547 523 struct drm_i915_error_object *obj) 548 524 { 549 - char out[6]; 525 + char out[ASCII85_BUFSZ]; 550 526 int page; 551 527 552 528 if (!obj) ··· 545 567 len -= obj->unused; 546 568 len = ascii85_encode_len(len); 547 569 548 - for (i = 0; i < len; i++) { 549 - if (ascii85_encode(obj->pages[page][i], out)) 550 - err_puts(m, out); 551 - else 552 - err_puts(m, "z"); 553 - } 570 + for (i = 0; i < len; i++) 571 + err_puts(m, ascii85_encode(obj->pages[page][i], out)); 554 572 } 555 573 err_puts(m, "\n"); 556 574 }
+38
include/linux/ascii85.h
··· 1 + /* 2 + * SPDX-License-Identifier: GPL-2.0 3 + * 4 + * Copyright (c) 2008 Intel Corporation 5 + * Copyright (c) 2018 The Linux Foundation. All rights reserved. 6 + */ 7 + 8 + #ifndef _ASCII85_H_ 9 + #define _ASCII85_H_ 10 + 11 + #include <linux/kernel.h> 12 + 13 + #define ASCII85_BUFSZ 6 14 + 15 + static inline long 16 + ascii85_encode_len(long len) 17 + { 18 + return DIV_ROUND_UP(len, 4); 19 + } 20 + 21 + static inline const char * 22 + ascii85_encode(u32 in, char *out) 23 + { 24 + int i; 25 + 26 + if (in == 0) 27 + return "z"; 28 + 29 + out[5] = '\0'; 30 + for (i = 5; i--; ) { 31 + out[i] = '!' + in % 85; 32 + in /= 85; 33 + } 34 + 35 + return out; 36 + } 37 + 38 + #endif