linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wu Zhangjin <wuzhangjin@gmail.com>
To: linux-mips <linux-mips@linux-mips.org>
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>,
	ralf@linux-mips.org, rjw@sisk.pl,
	Sergei Shtylyov <sshtylyov@ru.mvista.com>,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH -v1] MIPS: fix pfn_valid() for FLATMEM
Date: Sat, 10 Oct 2009 00:20:13 +0800	[thread overview]
Message-ID: <1255105213.3658.124.camel@falcon> (raw)
In-Reply-To: <1255104936-14921-1-git-send-email-wuzhangjin@gmail.com>

On Sat, 2009-10-10 at 00:15 +0800, Wu Zhangjin wrote:
> When CONFIG_FLATMEM enabled, STD/Hiberation will fail on YeeLoong
> laptop, This patch fixes it:
> 
> if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will
> return TRUE, but if the memory is not continuous, for example:
> 
> $ cat /proc/iomem | grep "System RAM"
> 00000000-0fffffff : System RAM
> 90000000-bfffffff : System RAM
> 
> as we can see, it is not continuous, so, some of the memory is not
> valid, and at last make STD/Hibernate fail when shrinking a too large
> number of invalid memory.
> 
> the "invalid" memory here include the memory space we never used.
> 
> 10000000-3fffffff
> 80000000-8fffffff
> 
> and also include the meory space we have mapped into pci space.
> 
> 40000000-7fffffff : pci memory space
> 

what about the "pci memory space"?

> Here, we fix it via checking pfn is in the "System RAM" or not. and
> Seems pfn_valid() is not called in assembly code, we move it to
> "!__ASSEMBLY__" to ensure we can simply declare it via "extern int
> pfn_valid(unsigned long)" without Compiling Error.
> 
> (This -v1 version incorporates feedback from Pavel Machek <pavel@ucw.cz>
>  and Sergei Shtylyov <sshtylyov@ru.mvista.com> and Ralf)
> 
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> ---
>  arch/mips/include/asm/page.h |   50 ++++++++++++++++++-----------------------
>  arch/mips/mm/page.c          |   18 +++++++++++++++
>  2 files changed, 40 insertions(+), 28 deletions(-)
> 
> diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
> index f266295..dc28d0a 100644
> --- a/arch/mips/include/asm/page.h
> +++ b/arch/mips/include/asm/page.h
> @@ -146,36 +146,9 @@ typedef struct { unsigned long pgprot; } pgprot_t;
>   */
>  #define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
>  
> -#endif /* !__ASSEMBLY__ */
> -
> -/*
> - * __pa()/__va() should be used only during mem init.
> - */
> -#ifdef CONFIG_64BIT
> -#define __pa(x)								\
> -({									\
> -    unsigned long __x = (unsigned long)(x);				\
> -    __x < CKSEG0 ? XPHYSADDR(__x) : CPHYSADDR(__x);			\
> -})
> -#else
> -#define __pa(x)								\
> -    ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
> -#endif
> -#define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
> -#define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
> -
> -#define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
> -
>  #ifdef CONFIG_FLATMEM
>  
> -#define pfn_valid(pfn)							\
> -({									\
> -	unsigned long __pfn = (pfn);					\
> -	/* avoid <linux/bootmem.h> include hell */			\
> -	extern unsigned long min_low_pfn;				\
> -									\
> -	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
> -})
> +extern int pfn_valid(unsigned long);
>  
>  #elif defined(CONFIG_SPARSEMEM)
>  
> @@ -194,6 +167,27 @@ typedef struct { unsigned long pgprot; } pgprot_t;
>  
>  #endif
>  
> +
> +#endif /* !__ASSEMBLY__ */
> +
> +/*
> + * __pa()/__va() should be used only during mem init.
> + */
> +#ifdef CONFIG_64BIT
> +#define __pa(x)								\
> +({									\
> +    unsigned long __x = (unsigned long)(x);				\
> +    __x < CKSEG0 ? XPHYSADDR(__x) : CPHYSADDR(__x);			\
> +})
> +#else
> +#define __pa(x)								\
> +    ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
> +#endif
> +#define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
> +#define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
> +
> +#define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
> +
>  #define virt_to_page(kaddr)	pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))
>  #define virt_addr_valid(kaddr)	pfn_valid(PFN_DOWN(virt_to_phys(kaddr)))
>  
> diff --git a/arch/mips/mm/page.c b/arch/mips/mm/page.c
> index f5c7375..203d805 100644
> --- a/arch/mips/mm/page.c
> +++ b/arch/mips/mm/page.c
> @@ -689,3 +689,21 @@ void copy_page(void *to, void *from)
>  }
>  
>  #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */
> +
> +#ifdef CONFIG_FLATMEM
> +int pfn_valid(unsigned long pfn)
> +{
> +	int i;
> +
> +	for (i = 0; i < boot_mem_map.nr_map; i++) {
> +		if ((boot_mem_map.map[i].type == BOOT_MEM_RAM) ||
> +			(boot_mem_map.map[i].type == BOOT_MEM_ROM_DATA)) {
> +			if ((pfn >= PFN_DOWN(boot_mem_map.map[i].addr)) &&
> +				(pfn < PFN_UP(boot_mem_map.map[i].addr +
> +					boot_mem_map.map[i].size)))
> +				return 1;
> +		}
> +	}
> +	return 0;
> +}
> +#endif

  reply	other threads:[~2009-10-09 16:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09 16:15 [PATCH -v1] MIPS: fix pfn_valid() for FLATMEM Wu Zhangjin
2009-10-09 16:20 ` Wu Zhangjin [this message]
2009-10-10 14:38 ` Wu Zhangjin
2009-10-10 19:19   ` Wu Zhangjin
  -- strict thread matches above, loose matches on Subject: below --
2009-10-08 11:32 Wu Zhangjin
2009-10-08 20:21 ` Rafael J. Wysocki
2009-10-08 20:44   ` Ralf Baechle
2009-10-09  2:08     ` Wu Zhangjin
2009-10-09 16:02       ` Wu Zhangjin
2009-10-13 22:04         ` Ralf Baechle
2009-10-14  1:06           ` Wu Zhangjin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1255105213.3658.124.camel@falcon \
    --to=wuzhangjin@gmail.com \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=linux-mips@linux-mips.org \
    --cc=pavel@ucw.cz \
    --cc=ralf@linux-mips.org \
    --cc=rjw@sisk.pl \
    --cc=sshtylyov@ru.mvista.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).