/*
 * drivers/base/decompress.c
 *
 * decompress driver
 *
 * Copyright 2008 Sony Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/module.h>
#include <linux/decompress_driver.h>

static LIST_HEAD(drivers);

u32 call_decompress_driver(u32 flags, void *dst, u32 dstlen, void *src, u32 srclen)
{
	struct decompress_driver *p;

	list_for_each_entry(p, &drivers, list) {
		if ((flags & p->flag) && p->decompress) {
			int fill = p->decompress(dst, dstlen, src, srclen, p->data);
			if (unlikely(fill < 0)) {
				printk("Failed: decompress, dst:0x%p, dstlen:%d, src:0x%p, srclen:%d\n",
					dst, dstlen, src, srclen);
				fill = 0;
			}
			return fill;
		}
	}

	return 0;
}

int decompress_driver_register(struct decompress_driver *p)
{
	list_add(&p->list, &drivers);

	return 0;
}

void decompress_driver_unregister(struct decompress_driver *p)
{
	list_del(&p->list);
}

EXPORT_SYMBOL(call_decompress_driver);
EXPORT_SYMBOL(decompress_driver_register);
EXPORT_SYMBOL(decompress_driver_unregister);
