diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2011-07-09 00:27:32 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2011-07-09 00:27:32 +0000 |
commit | 4ff7f3396e6db142a6e6ef5741ab2ca0cd151f5f (patch) | |
tree | 81f9699d75ad60ffe8760637d0bd0b3b57de1d94 /sys/arch | |
parent | de3c53b89e0b6224f4c4f0d0dc76254ad73c29b9 (diff) |
Add zlib reset, alloc, and free functions for hibernate image compression
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/i386/i386/hibernate_machdep.c | 36 | ||||
-rw-r--r-- | sys/arch/i386/include/hibernate.h | 1 |
2 files changed, 36 insertions, 1 deletions
diff --git a/sys/arch/i386/i386/hibernate_machdep.c b/sys/arch/i386/i386/hibernate_machdep.c index c5a81b837bb..39c04951d2b 100644 --- a/sys/arch/i386/i386/hibernate_machdep.c +++ b/sys/arch/i386/i386/hibernate_machdep.c @@ -54,6 +54,7 @@ void hibernate_populate_resume_pt(paddr_t *, paddr_t *); int get_hibernate_info_md(union hibernate_info *); int hibernate_write_signature(void); int hibernate_clear_signature(void); + union hibernate_info *global_hiber_info; paddr_t global_image_start; @@ -64,13 +65,46 @@ extern char *disk_readlabel(struct disklabel *, dev_t, char *, size_t); extern caddr_t start, end; extern int ndumpmem; extern struct dumpmem dumpmem[]; - +extern struct hibernate_state *hibernate_state; /* * i386 MD Hibernate functions */ /* + * hibernate_zlib_reset + * + * Reset the zlib stream state and allocate a new hiballoc area for either + * inflate or deflate. This function is called once for each hibernate chunk + * Calling hiballoc_init multiple times is acceptable since the memory it is + * provided is unmanaged memory (stolen). + * + */ +int +hibernate_zlib_reset(int deflate) +{ + hibernate_state = (struct hibernate_state *)HIBERNATE_ZLIB_SCRATCH; + + bzero((caddr_t)HIBERNATE_ZLIB_START, HIBERNATE_ZLIB_SIZE); + bzero((caddr_t)HIBERNATE_ZLIB_SCRATCH, PAGE_SIZE); + + /* Set up stream structure */ + hibernate_state->hib_stream.zalloc = (alloc_func)hibernate_zlib_alloc; + hibernate_state->hib_stream.zfree = (free_func)hibernate_zlib_free; + + /* Initialize the hiballoc arena for zlib allocs/frees */ + hiballoc_init(&hibernate_state->hiballoc_arena, + (caddr_t)HIBERNATE_ZLIB_START, HIBERNATE_ZLIB_SIZE); + + if (deflate) { + return deflateInit(&hibernate_state->hib_stream, + Z_DEFAULT_COMPRESSION); + } + else + return inflateInit(&hibernate_state->hib_stream); +} + +/* * get_hibernate_io_function * * Returns the hibernate write I/O function to use on this machine diff --git a/sys/arch/i386/include/hibernate.h b/sys/arch/i386/include/hibernate.h index 352de896b7c..8efe8d2e31c 100644 --- a/sys/arch/i386/include/hibernate.h +++ b/sys/arch/i386/include/hibernate.h @@ -19,5 +19,6 @@ /* i386 hibernate support structures and functions */ int get_hibernate_info_md(union hibernate_info *); +int hibernate_zlib_reset(int); int hibernate_suspend(void); void hibernate_resume(void); |