Commit f49b7572 authored by Raphael Moreira Zinsly's avatar Raphael Moreira Zinsly Committed by Michael Ellerman

selftests/powerpc: Add header files for NX compresion/decompression

Add files to be able to compress and decompress files using the
powerpc NX-GZIP engine.
Signed-off-by: default avatarBulent Abali <abali@us.ibm.com>
Signed-off-by: default avatarRaphael Moreira Zinsly <rzinsly@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200420205538.25181-3-rzinsly@linux.ibm.com
parent d53979b5
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* From asm-compat.h */
#define __stringify_in_c(...) #__VA_ARGS__
#define stringify_in_c(...) __stringify_in_c(__VA_ARGS__) " "
/*
* Macros taken from arch/powerpc/include/asm/ppc-opcode.h and other
* header files.
*/
#define ___PPC_RA(a) (((a) & 0x1f) << 16)
#define ___PPC_RB(b) (((b) & 0x1f) << 11)
#define PPC_INST_COPY 0x7c20060c
#define PPC_INST_PASTE 0x7c20070d
#define PPC_COPY(a, b) stringify_in_c(.long PPC_INST_COPY | \
___PPC_RA(a) | ___PPC_RB(b))
#define PPC_PASTE(a, b) stringify_in_c(.long PPC_INST_PASTE | \
___PPC_RA(a) | ___PPC_RB(b))
#define CR0_SHIFT 28
#define CR0_MASK 0xF
/*
* Copy/paste instructions:
*
* copy RA,RB
* Copy contents of address (RA) + effective_address(RB)
* to internal copy-buffer.
*
* paste RA,RB
* Paste contents of internal copy-buffer to the address
* (RA) + effective_address(RB)
*/
static inline int vas_copy(void *crb, int offset)
{
asm volatile(PPC_COPY(%0, %1)";"
:
: "b" (offset), "b" (crb)
: "memory");
return 0;
}
static inline int vas_paste(void *paste_address, int offset)
{
__u32 cr;
cr = 0;
asm volatile(PPC_PASTE(%1, %2)";"
"mfocrf %0, 0x80;"
: "=r" (cr)
: "b" (offset), "b" (paste_address)
: "memory", "cr0");
return (cr >> CR0_SHIFT) & CR0_MASK;
}
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright 2020 IBM Corporation
*
*/
#ifndef _NXU_DBG_H_
#define _NXU_DBG_H_
#include <sys/file.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
extern FILE * nx_gzip_log;
extern int nx_gzip_trace;
extern unsigned int nx_gzip_inflate_impl;
extern unsigned int nx_gzip_deflate_impl;
extern unsigned int nx_gzip_inflate_flags;
extern unsigned int nx_gzip_deflate_flags;
extern int nx_dbg;
pthread_mutex_t mutex_log;
#define nx_gzip_trace_enabled() (nx_gzip_trace & 0x1)
#define nx_gzip_hw_trace_enabled() (nx_gzip_trace & 0x2)
#define nx_gzip_sw_trace_enabled() (nx_gzip_trace & 0x4)
#define nx_gzip_gather_statistics() (nx_gzip_trace & 0x8)
#define nx_gzip_per_stream_stat() (nx_gzip_trace & 0x10)
#define prt(fmt, ...) do { \
pthread_mutex_lock(&mutex_log); \
flock(nx_gzip_log->_fileno, LOCK_EX); \
time_t t; struct tm *m; time(&t); m = localtime(&t); \
fprintf(nx_gzip_log, "[%04d/%02d/%02d %02d:%02d:%02d] " \
"pid %d: " fmt, \
(int)m->tm_year + 1900, (int)m->tm_mon+1, (int)m->tm_mday, \
(int)m->tm_hour, (int)m->tm_min, (int)m->tm_sec, \
(int)getpid(), ## __VA_ARGS__); \
fflush(nx_gzip_log); \
flock(nx_gzip_log->_fileno, LOCK_UN); \
pthread_mutex_unlock(&mutex_log); \
} while (0)
/* Use in case of an error */
#define prt_err(fmt, ...) do { if (nx_dbg >= 0) { \
prt("%s:%u: Error: "fmt, \
__FILE__, __LINE__, ## __VA_ARGS__); \
}} while (0)
/* Use in case of an warning */
#define prt_warn(fmt, ...) do { if (nx_dbg >= 1) { \
prt("%s:%u: Warning: "fmt, \
__FILE__, __LINE__, ## __VA_ARGS__); \
}} while (0)
/* Informational printouts */
#define prt_info(fmt, ...) do { if (nx_dbg >= 2) { \
prt("Info: "fmt, ## __VA_ARGS__); \
}} while (0)
/* Trace zlib wrapper code */
#define prt_trace(fmt, ...) do { if (nx_gzip_trace_enabled()) { \
prt("### "fmt, ## __VA_ARGS__); \
}} while (0)
/* Trace statistics */
#define prt_stat(fmt, ...) do { if (nx_gzip_gather_statistics()) { \
prt("### "fmt, ## __VA_ARGS__); \
}} while (0)
/* Trace zlib hardware implementation */
#define hw_trace(fmt, ...) do { \
if (nx_gzip_hw_trace_enabled()) \
fprintf(nx_gzip_log, "hhh " fmt, ## __VA_ARGS__); \
} while (0)
/* Trace zlib software implementation */
#define sw_trace(fmt, ...) do { \
if (nx_gzip_sw_trace_enabled()) \
fprintf(nx_gzip_log, "sss " fmt, ## __VA_ARGS__); \
} while (0)
/**
* str_to_num - Convert string into number and copy with endings like
* KiB for kilobyte
* MiB for megabyte
* GiB for gigabyte
*/
uint64_t str_to_num(char *str);
void nx_lib_debug(int onoff);
#endif /* _NXU_DBG_H_ */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment