Commit 84997341 authored by Patrick Mochel's avatar Patrick Mochel

[Power Mgmt] Remove duplicate relocate_pagedir() from pmdisk.

- Expose and use version in swsusp.
parent 0ce7a587
...@@ -732,93 +732,6 @@ int pmdisk_resume(void) ...@@ -732,93 +732,6 @@ int pmdisk_resume(void)
/* More restore stuff */ /* More restore stuff */
#define does_collide(addr) does_collide_order(pm_pagedir_nosave, addr, 0)
/*
* Returns true if given address/order collides with any orig_address
*/
static int __init does_collide_order(suspend_pagedir_t *pagedir,
unsigned long addr, int order)
{
int i;
unsigned long addre = addr + (PAGE_SIZE<<order);
for(i=0; i < pmdisk_pages; i++)
if((pagedir+i)->orig_address >= addr &&
(pagedir+i)->orig_address < addre)
return 1;
return 0;
}
/*
* We check here that pagedir & pages it points to won't collide with pages
* where we're going to restore from the loaded pages later
*/
static int __init check_pagedir(void)
{
int i;
for(i=0; i < pmdisk_pages; i++) {
unsigned long addr;
do {
addr = get_zeroed_page(GFP_ATOMIC);
if(!addr)
return -ENOMEM;
} while (does_collide(addr));
(pm_pagedir_nosave+i)->address = addr;
}
return 0;
}
static int __init relocate_pagedir(void)
{
/*
* We have to avoid recursion (not to overflow kernel stack),
* and that's why code looks pretty cryptic
*/
suspend_pagedir_t *old_pagedir = pm_pagedir_nosave;
void **eaten_memory = NULL;
void **c = eaten_memory, *m, *f;
int err;
pr_debug("pmdisk: Relocating pagedir\n");
if(!does_collide_order(old_pagedir, (unsigned long)old_pagedir, pagedir_order)) {
pr_debug("pmdisk: Relocation not necessary\n");
return 0;
}
err = -ENOMEM;
while ((m = (void *) __get_free_pages(GFP_ATOMIC, pagedir_order)) != NULL) {
if (!does_collide_order(old_pagedir, (unsigned long)m,
pagedir_order)) {
pm_pagedir_nosave =
memcpy(m, old_pagedir,
PAGE_SIZE << pagedir_order);
err = 0;
break;
}
eaten_memory = m;
printk( "." );
*eaten_memory = c;
c = eaten_memory;
}
c = eaten_memory;
while(c) {
printk(":");
f = c;
c = *c;
free_pages((unsigned long)f, pagedir_order);
}
printk("|\n");
return err;
}
static struct block_device * resume_bdev; static struct block_device * resume_bdev;
...@@ -1041,9 +954,7 @@ static int __init read_suspend_image(void) ...@@ -1041,9 +954,7 @@ static int __init read_suspend_image(void)
return error; return error;
if ((error = read_pagedir())) if ((error = read_pagedir()))
return error; return error;
if ((error = relocate_pagedir())) if ((error = swsusp_pagedir_relocate()))
goto FreePagedir;
if ((error = check_pagedir()))
goto FreePagedir; goto FreePagedir;
if ((error = read_image_data())) if ((error = read_image_data()))
goto FreePagedir; goto FreePagedir;
......
...@@ -19,6 +19,8 @@ static inline int pm_suspend_disk(void) ...@@ -19,6 +19,8 @@ static inline int pm_suspend_disk(void)
} }
#endif #endif
extern int swsusp_pagedir_relocate(void);
extern struct semaphore pm_sem; extern struct semaphore pm_sem;
#define power_attr(_name) \ #define power_attr(_name) \
static struct subsys_attribute _name##_attr = { \ static struct subsys_attribute _name##_attr = { \
......
...@@ -874,7 +874,7 @@ int software_suspend(void) ...@@ -874,7 +874,7 @@ int software_suspend(void)
/* /*
* Returns true if given address/order collides with any orig_address * Returns true if given address/order collides with any orig_address
*/ */
static int does_collide_order(suspend_pagedir_t *pagedir, unsigned long addr, static int __init does_collide_order(suspend_pagedir_t *pagedir, unsigned long addr,
int order) int order)
{ {
int i; int i;
...@@ -892,7 +892,7 @@ static int does_collide_order(suspend_pagedir_t *pagedir, unsigned long addr, ...@@ -892,7 +892,7 @@ static int does_collide_order(suspend_pagedir_t *pagedir, unsigned long addr,
* We check here that pagedir & pages it points to won't collide with pages * We check here that pagedir & pages it points to won't collide with pages
* where we're going to restore from the loaded pages later * where we're going to restore from the loaded pages later
*/ */
static int check_pagedir(void) static int __init check_pagedir(void)
{ {
int i; int i;
...@@ -910,7 +910,7 @@ static int check_pagedir(void) ...@@ -910,7 +910,7 @@ static int check_pagedir(void)
return 0; return 0;
} }
static int relocate_pagedir(void) int __init swsusp_pagedir_relocate(void)
{ {
/* /*
* We have to avoid recursion (not to overflow kernel stack), * We have to avoid recursion (not to overflow kernel stack),
...@@ -953,7 +953,7 @@ static int relocate_pagedir(void) ...@@ -953,7 +953,7 @@ static int relocate_pagedir(void)
free_pages((unsigned long)f, pagedir_order); free_pages((unsigned long)f, pagedir_order);
} }
printk("|\n"); printk("|\n");
return ret; return check_pagedir();
} }
/* /*
...@@ -1089,9 +1089,7 @@ static int __init __read_suspend_image(struct block_device *bdev, union diskpage ...@@ -1089,9 +1089,7 @@ static int __init __read_suspend_image(struct block_device *bdev, union diskpage
} }
BUG_ON (next.val); BUG_ON (next.val);
if (relocate_pagedir()) if (swsusp_pagedir_relocate())
return -ENOMEM;
if (check_pagedir())
return -ENOMEM; return -ENOMEM;
printk( "Reading image data (%d pages): ", nr_copy_pages ); printk( "Reading image data (%d pages): ", nr_copy_pages );
......
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