tools/testing/selftests/powerpc/nx-gzip/gunz_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/nx-gzip/gunz_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/nx-gzip/gunz_test.c
Extension
.c
Size
28085 bytes
Lines
1029
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (total > buf_sz) {
			buf_len = NX_MIN(buf_len, total - buf_sz);
			nxu_touch_pages((void *)buf_addr, buf_len, page_sz, wr);
			NXPRT(fprintf(stderr, "touch loop break len 0x%x ",
				      buf_len));
			NXPRT(fprintf(stderr, "ddead %p\n", (void *)buf_addr));
			break;
		}
		nxu_touch_pages((void *)buf_addr, buf_len, page_sz, wr);
	}
	return ERR_NX_OK;
}

/*
 * Src and dst buffers are supplied in scatter gather lists.
 * NX function code and other parameters supplied in cmdp.
 */
static int nx_submit_job(struct nx_dde_t *src, struct nx_dde_t *dst,
			 struct nx_gzip_crb_cpb_t *cmdp, void *handle)
{
	uint64_t csbaddr;

	memset((void *)&cmdp->crb.csb, 0, sizeof(cmdp->crb.csb));

	cmdp->crb.source_dde = *src;
	cmdp->crb.target_dde = *dst;

	/* Status, output byte count in tpbc */
	csbaddr = ((uint64_t) &cmdp->crb.csb) & csb_address_mask;
	put64(cmdp->crb, csb_address, csbaddr);

	/* NX reports input bytes in spbc; cleared */
	cmdp->cpb.out_spbc_comp_wrap = 0;
	cmdp->cpb.out_spbc_comp_with_count = 0;
	cmdp->cpb.out_spbc_decomp = 0;

	/* Clear output */
	put32(cmdp->cpb, out_crc, INIT_CRC);
	put32(cmdp->cpb, out_adler, INIT_ADLER);

	/* Submit the crb, the job descriptor, to the accelerator. */
	return nxu_submit_job(cmdp, handle);
}

int decompress_file(int argc, char **argv, void *devhandle)
{
	FILE *inpf = NULL;
	FILE *outf = NULL;

	int c, expect, i, cc, rc = 0;
	char gzfname[FNAME_MAX];

	/* Queuing, file ops, byte counting */
	char *fifo_in, *fifo_out;
	int used_in, cur_in, used_out, cur_out, read_sz, n;
	int first_free, last_free, first_used, last_used;
	int first_offset, last_offset;
	int write_sz, free_space, source_sz;
	int source_sz_estimate, target_sz_estimate;
	uint64_t last_comp_ratio = 0; /* 1000 max */
	uint64_t total_out = 0;
	int is_final, is_eof;

	/* nx hardware */
	int sfbt, subc, spbc, tpbc, nx_ce, fc, resuming = 0;
	int history_len = 0;
	struct nx_gzip_crb_cpb_t cmd, *cmdp;
	struct nx_dde_t *ddl_in;
	struct nx_dde_t dde_in[6] __aligned(128);
	struct nx_dde_t *ddl_out;
	struct nx_dde_t dde_out[6] __aligned(128);
	int pgfault_retries;

	/* when using mmap'ed files */
	off_t input_file_offset;

	if (argc > 2) {
		fprintf(stderr, "usage: %s <fname> or stdin\n", argv[0]);
		fprintf(stderr, "    writes to stdout or <fname>.nx.gunzip\n");
		return -1;
	}

	if (argc == 1) {
		inpf = stdin;
		outf = stdout;
	} else if (argc == 2) {
		char w[1024];
		char *wp;

		inpf = fopen(argv[1], "r");

Annotation

Implementation Notes