^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on earlier code:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) Paul Mackerras 1997.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Matt Porter <mporter@kernel.crashing.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright 2002-2005 MontaVista Software Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2003, 2004 Zultys Technologies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright 2007 David Gibson, IBM Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "elf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "string.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "stdio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "page.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "reg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "dcr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "4xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "44x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "libfdt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) BSS_STACK(4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static u32 ibm4xx_memstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void iss_4xx_fixups(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void *memory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 reg[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) memory = finddevice("/memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) fatal("Can't find memory node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* This assumes #address-cells = 2, #size-cells =1 and that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) getprop(memory, "reg", reg, sizeof(reg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (reg[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* If the device tree specifies the memory range, use it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ibm4xx_memstart = reg[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* othersize, read it from the SDRAM controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ibm4xx_sdram_fixup_memsize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void *iss_4xx_vmlinux_alloc(unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return (void *)ibm4xx_memstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define SPRN_PIR 0x11E /* Processor Identification Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void platform_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned long end_of_ram = 0x08000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned long avail_ram = end_of_ram - (unsigned long)_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u32 pir_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) simple_alloc_init(_end, avail_ram, 128, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) platform_ops.fixups = iss_4xx_fixups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) platform_ops.vmlinux_alloc = iss_4xx_vmlinux_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) platform_ops.exit = ibm44x_dbcr_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) pir_reg = mfspr(SPRN_PIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) fdt_set_boot_cpuid_phys(_dtb_start, pir_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) fdt_init(_dtb_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) serial_console_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }