Thomas Gleixner | fd534e9 | 2019-05-23 11:14:39 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org> |
| 4 | * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org> |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 5 | */ |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 6 | #include <linux/memblock.h> |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 7 | #include <linux/init.h> |
| 8 | #include <linux/mm.h> |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 9 | #include <linux/pfn.h> |
| 10 | #include <linux/proc_fs.h> |
| 11 | #include <linux/string.h> |
| 12 | #include <linux/swap.h> |
| 13 | |
| 14 | #include <asm/bootinfo.h> |
| 15 | #include <asm/page.h> |
| 16 | #include <asm/sections.h> |
| 17 | |
| 18 | #include <asm/mach-ar7/ar7.h> |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 19 | |
| 20 | static int __init memsize(void) |
| 21 | { |
| 22 | u32 size = (64 << 20); |
| 23 | u32 *addr = (u32 *)KSEG1ADDR(AR7_SDRAM_BASE + size - 4); |
| 24 | u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end)); |
| 25 | u32 *tmpaddr = addr; |
| 26 | |
| 27 | while (tmpaddr > kernel_end) { |
| 28 | *tmpaddr = (u32)tmpaddr; |
| 29 | size >>= 1; |
| 30 | tmpaddr -= size >> 2; |
| 31 | } |
| 32 | |
| 33 | do { |
| 34 | tmpaddr += size >> 2; |
| 35 | if (*tmpaddr != (u32)tmpaddr) |
| 36 | break; |
| 37 | size <<= 1; |
| 38 | } while (size < (64 << 20)); |
| 39 | |
Florian Fainelli | dd34b5a | 2009-07-21 12:38:10 +0200 | [diff] [blame] | 40 | writel((u32)tmpaddr, &addr); |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 41 | |
| 42 | return size; |
| 43 | } |
| 44 | |
| 45 | void __init prom_meminit(void) |
| 46 | { |
| 47 | unsigned long pages; |
| 48 | |
| 49 | pages = memsize() >> PAGE_SHIFT; |
Thomas Bogendoerfer | e7ae8d1 | 2020-10-09 14:14:46 +0200 | [diff] [blame] | 50 | memblock_add(PHYS_OFFSET, pages << PAGE_SHIFT); |
Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 51 | } |