linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Albert Herranz <albert_herranz@yahoo.es>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [RFC PATCH v2 1/4] wii: bootwrapper: add fixup to calc useable mem2
Date: Sat, 12 Dec 2009 09:03:46 +1100	[thread overview]
Message-ID: <1260569026.16132.367.camel@pasglop> (raw)
In-Reply-To: <1260297833-17625-2-git-send-email-albert_herranz@yahoo.es>

On Tue, 2009-12-08 at 19:43 +0100, Albert Herranz wrote:
> The top portion of MEM2 (the second 64MB memory block) in the Nintendo
> Wii video game console is used by the firmware running on the Starlet
> processor.
> 
> Add code to calculate the portion of MEM2 safely useable by the
> Broadway processor. When running under the 'mini' firmware this is
> easily determined from an in-memory header. Otherwise, a safe default
> is used.
> 
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/boot/wii.c |  118 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 115 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
> index d0e2625..2ebaec0 100644
> --- a/arch/powerpc/boot/wii.c
> +++ b/arch/powerpc/boot/wii.c
> @@ -22,10 +22,120 @@
>  
>  BSS_STACK(8192);
>  
> -#define HW_REG(x)	((void *)(x))
> +#define HW_REG(x)		((void *)(x))
>  
> -#define EXI_CTRL	HW_REG(0x0d800070)
> -#define EXI_CTRL_ENABLE	(1<<0)
> +#define EXI_CTRL		HW_REG(0x0d800070)
> +#define EXI_CTRL_ENABLE		(1<<0)
> +
> +#define MEM2_TOP		(0x10000000 + 64*1024*1024)
> +#define FIRMWARE_DEFAULT_SIZE	(12*1024*1024)
> +
> +
> +struct mipc_infohdr {
> +	char magic[3];
> +	u8 version;
> +	u32 mem2_boundary;
> +	u32 ipc_in;
> +	size_t ipc_in_size;
> +	u32 ipc_out;
> +	size_t ipc_out_size;
> +};
> +
> +static int mipc_check_address(u32 pa)
> +{
> +	/* only MEM2 addresses */
> +	if (pa < 0x10000000 || pa > 0x14000000)
> +		return -EINVAL;
> +	return 0;
> +}
> +
> +static struct mipc_infohdr *mipc_get_infohdr(void)
> +{
> +	struct mipc_infohdr **hdrp, *hdr;
> +
> +	/* 'mini' header pointer is the last word of MEM2 memory */
> +	hdrp = (struct mipc_infohdr **)0x13fffffc;
> +	if (mipc_check_address((u32)hdrp)) {
> +		printf("mini: invalid hdrp %08X\n", (u32)hdrp);
> +		hdr = NULL;
> +		goto out;
> +	}
> +
> +	hdr = *hdrp;
> +	if (mipc_check_address((u32)hdr)) {
> +		printf("mini: invalid hdr %08X\n", (u32)hdr);
> +		hdr = NULL;
> +		goto out;
> +	}
> +	if (memcmp(hdr->magic, "IPC", 3)) {
> +		printf("mini: invalid magic\n");
> +		hdr = NULL;
> +		goto out;
> +	}
> +
> +out:
> +	return hdr;
> +}
> +
> +static int mipc_get_mem2_boundary(u32 *mem2_boundary)
> +{
> +	struct mipc_infohdr *hdr;
> +	int error;
> +
> +	hdr = mipc_get_infohdr();
> +	if (!hdr) {
> +		error = -1;
> +		goto out;
> +	}
> +
> +	if (mipc_check_address(hdr->mem2_boundary)) {
> +		printf("mini: invalid mem2_boundary %08X\n",
> +		       hdr->mem2_boundary);
> +		error = -EINVAL;
> +		goto out;
> +	}
> +	*mem2_boundary = hdr->mem2_boundary;
> +	error = 0;
> +out:
> +	return error;
> +
> +}
> +
> +static void platform_fixups(void)
> +{
> +	void *mem;
> +	u32 reg[4];
> +	u32 mem2_boundary;
> +	int len;
> +	int error;
> +
> +	mem = finddevice("/memory");
> +	if (!mem)
> +		fatal("Can't find memory node\n");
> +
> +	/* two ranges of (address, size) words */
> +	len = getprop(mem, "reg", reg, sizeof(reg));
> +	if (len != sizeof(reg)) {
> +		/* nothing to do */
> +		goto out;
> +	}
> +
> +	/* retrieve MEM2 boundary from 'mini' */
> +	error = mipc_get_mem2_boundary(&mem2_boundary);
> +	if (error) {
> +		/* if that fails use a sane value */
> +		mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
> +	}
> +
> +	if (mem2_boundary > reg[2] && mem2_boundary < reg[2] + reg[3]) {
> +		reg[3] = mem2_boundary - reg[2];
> +		printf("top of MEM2 @ %08X\n", reg[2] + reg[3]);
> +		setprop(mem, "reg", reg, sizeof(reg));
> +	}
> +
> +out:
> +	return;
> +}
>  
>  void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
>  {
> @@ -42,5 +152,7 @@ void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
>  
>  	if (ug_probe())
>  		console_ops.write = ug_console_write;
> +
> +	platform_ops.fixups = platform_fixups;
>  }
>  

  reply	other threads:[~2009-12-11 22:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08 18:43 [RFC PATCH v2 0/4] powerpc: wii: mem2 as ram support Albert Herranz
2009-12-08 18:43 ` [RFC PATCH v2 1/4] wii: bootwrapper: add fixup to calc useable mem2 Albert Herranz
2009-12-11 22:03   ` Benjamin Herrenschmidt [this message]
2009-12-08 18:43 ` [RFC PATCH v2 2/4] wii: use both mem1 and mem2 as ram Albert Herranz
2009-12-11 22:05   ` Benjamin Herrenschmidt
2009-12-08 18:43 ` [RFC PATCH v2 3/4] powerpc: allow ioremap within reserved memory regions Albert Herranz
2009-12-11 22:13   ` Benjamin Herrenschmidt
2009-12-12  0:33     ` Albert Herranz
2009-12-12  4:24       ` Benjamin Herrenschmidt
2009-12-08 18:43 ` [RFC PATCH v2 4/4] powerpc: wii: allow ioremap within the memory hole Albert Herranz
2009-12-11 22:13   ` Benjamin Herrenschmidt

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=1260569026.16132.367.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=albert_herranz@yahoo.es \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /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).