From 4aca87515a5083ae0e31ce3177189fd43b6d05ac Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 3 Jan 2015 13:58:15 +0100 Subject: patch to Vanilla Tomato 1.28 --- .../linux/arch/mips/brcm-boards/bcm947xx/prom.c | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/prom.c') diff --git a/release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/prom.c b/release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/prom.c index 242dafb9..cb35926d 100644 --- a/release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/prom.c +++ b/release/src/linux/linux/arch/mips/brcm-boards/bcm947xx/prom.c @@ -1,7 +1,7 @@ /* * Early initialization code for BCM94710 boards * - * Copyright 2005, Broadcom Corporation + * Copyright 2006, Broadcom Corporation * All Rights Reserved. * * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY @@ -9,7 +9,7 @@ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. * - * $Id: prom.c,v 1.1.1.7 2005/03/07 07:30:37 kanki Exp $ + * $Id$ */ #include @@ -18,24 +18,39 @@ #include #include -void __init -prom_init(int argc, const char **argv) +void __init prom_init(int argc, char **argv, char **envp, int *prom_vec) { - unsigned long mem; + unsigned long mem, before, offset; - mips_machgroup = MACH_GROUP_BRCM; - mips_machtype = MACH_BCM947XX; + mips_machgroup = MACH_GROUP_BRCM; + mips_machtype = MACH_BCM947XX; - /* Figure out memory size by finding aliases */ - for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) { - if (*(unsigned long *)((unsigned long)(prom_init) + mem) == - *(unsigned long *)(prom_init)) + /* Figure out memory size by finding aliases. + * + * We assume that there will be no more than 128 MB of memory, + * and that the memory size will be a multiple of 1 MB. + * + * We set 'before' to be the amount of memory (in MB) before this + * function, i.e. one MB less than the number of MB of memory that we + * *know* we have. And we set 'offset' to be the address of 'prominit' + * minus 'before', so that KSEG0 or KSEG1 base + offset < 1 MB. + * This prevents us from overrunning 128 MB and causing a bus error. + */ + before = ((unsigned long) &prom_init) & (127 << 20); + offset = ((unsigned long) &prom_init) - before; + for (mem = before + (1 << 20); mem < (128 << 20); mem += (1 << 20)) + if (*(unsigned long *)(offset + mem) == + *(unsigned long *)(prom_init)) { + /* + * We may already be well past the end of memory at + * this point, so we'll have to compensate for it. + */ + mem -= before; break; - } + } add_memory_region(0, mem, BOOT_MEM_RAM); } -void __init -prom_free_prom_memory(void) +void __init prom_free_prom_memory(void) { } -- cgit v1.2.3-54-g00ecf