blob: 6e5e0d60d0c8c9b887a19fe9e9f7a193ee298882 [file] [log] [blame]
Dan Streetman7011a122015-05-07 13:49:17 -04001/*
2 * Driver frontend for IBM Power 842 compression accelerator
3 *
4 * Copyright (C) 2015 Dan Streetman, IBM Corp
5 *
6 * Designer of the Power data compression engine:
7 * Bulent Abali <abali@us.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include "nx-842.h"
23
Dan Streetman7011a122015-05-07 13:49:17 -040024MODULE_LICENSE("GPL");
25MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
26MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors");
27
Dan Streetman959e6652015-05-07 13:49:18 -040028/**
29 * nx842_constraints
30 *
31 * This provides the driver's constraints. Different nx842 implementations
32 * may have varying requirements. The constraints are:
33 * @alignment: All buffers should be aligned to this
34 * @multiple: All buffer lengths should be a multiple of this
35 * @minimum: Buffer lengths must not be less than this amount
36 * @maximum: Buffer lengths must not be more than this amount
37 *
38 * The constraints apply to all buffers and lengths, both input and output,
39 * for both compression and decompression, except for the minimum which
40 * only applies to compression input and decompression output; the
41 * compressed data can be less than the minimum constraint. It can be
42 * assumed that compressed data will always adhere to the multiple
43 * constraint.
44 *
45 * The driver may succeed even if these constraints are violated;
46 * however the driver can return failure or suffer reduced performance
47 * if any constraint is not met.
48 */
49int nx842_constraints(struct nx842_constraints *c)
50{
Dan Streetman3e648cb2015-05-28 16:21:31 -040051 memcpy(c, nx842_platform_driver()->constraints, sizeof(*c));
52 return 0;
Dan Streetman959e6652015-05-07 13:49:18 -040053}
54EXPORT_SYMBOL_GPL(nx842_constraints);
55
Dan Streetman2c6f6ea2015-06-12 10:58:47 -040056/**
57 * nx842_workmem_size
58 *
59 * Get the amount of working memory the driver requires.
60 */
61size_t nx842_workmem_size(void)
62{
63 return nx842_platform_driver()->workmem_size;
64}
65EXPORT_SYMBOL_GPL(nx842_workmem_size);
66
Dan Streetman3e648cb2015-05-28 16:21:31 -040067int nx842_compress(const unsigned char *in, unsigned int ilen,
68 unsigned char *out, unsigned int *olen, void *wmem)
Dan Streetman7011a122015-05-07 13:49:17 -040069{
Dan Streetman3e648cb2015-05-28 16:21:31 -040070 return nx842_platform_driver()->compress(in, ilen, out, olen, wmem);
Dan Streetman7011a122015-05-07 13:49:17 -040071}
72EXPORT_SYMBOL_GPL(nx842_compress);
73
Dan Streetman3e648cb2015-05-28 16:21:31 -040074int nx842_decompress(const unsigned char *in, unsigned int ilen,
75 unsigned char *out, unsigned int *olen, void *wmem)
Dan Streetman7011a122015-05-07 13:49:17 -040076{
Dan Streetman3e648cb2015-05-28 16:21:31 -040077 return nx842_platform_driver()->decompress(in, ilen, out, olen, wmem);
Dan Streetman7011a122015-05-07 13:49:17 -040078}
79EXPORT_SYMBOL_GPL(nx842_decompress);
80
81static __init int nx842_init(void)
82{
Dan Streetman3e648cb2015-05-28 16:21:31 -040083 request_module("nx-compress-powernv");
84 request_module("nx-compress-pseries");
Dan Streetman7011a122015-05-07 13:49:17 -040085
Dan Streetman3e648cb2015-05-28 16:21:31 -040086 /* we prevent loading if there's no platform driver, and we get the
87 * module that set it so it won't unload, so we don't need to check
88 * if it's set in any of the above functions
89 */
90 if (!nx842_platform_driver_get()) {
Dan Streetman7011a122015-05-07 13:49:17 -040091 pr_err("no nx842 driver found.\n");
Dan Streetman3e648cb2015-05-28 16:21:31 -040092 return -ENODEV;
93 }
Dan Streetman7011a122015-05-07 13:49:17 -040094
95 return 0;
96}
97module_init(nx842_init);
98
99static void __exit nx842_exit(void)
100{
Dan Streetman3e648cb2015-05-28 16:21:31 -0400101 nx842_platform_driver_put();
Dan Streetman7011a122015-05-07 13:49:17 -0400102}
103module_exit(nx842_exit);