18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Based on earlier code:
68c2ecf20Sopenharmony_ci *   Copyright (C) Paul Mackerras 1997.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *   Matt Porter <mporter@kernel.crashing.org>
98c2ecf20Sopenharmony_ci *   Copyright 2002-2005 MontaVista Software Inc.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *   Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
128c2ecf20Sopenharmony_ci *   Copyright (c) 2003, 2004 Zultys Technologies
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *    Copyright 2007 David Gibson, IBM Corporation.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#include <stdarg.h>
178c2ecf20Sopenharmony_ci#include <stddef.h>
188c2ecf20Sopenharmony_ci#include "types.h"
198c2ecf20Sopenharmony_ci#include "elf.h"
208c2ecf20Sopenharmony_ci#include "string.h"
218c2ecf20Sopenharmony_ci#include "stdio.h"
228c2ecf20Sopenharmony_ci#include "page.h"
238c2ecf20Sopenharmony_ci#include "ops.h"
248c2ecf20Sopenharmony_ci#include "reg.h"
258c2ecf20Sopenharmony_ci#include "io.h"
268c2ecf20Sopenharmony_ci#include "dcr.h"
278c2ecf20Sopenharmony_ci#include "4xx.h"
288c2ecf20Sopenharmony_ci#include "44x.h"
298c2ecf20Sopenharmony_ci#include "libfdt.h"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciBSS_STACK(4096);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistatic u32 ibm4xx_memstart;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic void iss_4xx_fixups(void)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	void *memory;
388c2ecf20Sopenharmony_ci	u32 reg[3];
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	memory = finddevice("/memory");
418c2ecf20Sopenharmony_ci	if (!memory)
428c2ecf20Sopenharmony_ci		fatal("Can't find memory node\n");
438c2ecf20Sopenharmony_ci	/* This assumes #address-cells = 2, #size-cells =1 and that */
448c2ecf20Sopenharmony_ci	getprop(memory, "reg", reg, sizeof(reg));
458c2ecf20Sopenharmony_ci	if (reg[2])
468c2ecf20Sopenharmony_ci		/* If the device tree specifies the memory range, use it */
478c2ecf20Sopenharmony_ci		ibm4xx_memstart = reg[1];
488c2ecf20Sopenharmony_ci	else
498c2ecf20Sopenharmony_ci		/* othersize, read it from the SDRAM controller */
508c2ecf20Sopenharmony_ci		ibm4xx_sdram_fixup_memsize();
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic void *iss_4xx_vmlinux_alloc(unsigned long size)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	return (void *)ibm4xx_memstart;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define SPRN_PIR	0x11E	/* Processor Identification Register */
598c2ecf20Sopenharmony_civoid platform_init(void)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	unsigned long end_of_ram = 0x08000000;
628c2ecf20Sopenharmony_ci	unsigned long avail_ram = end_of_ram - (unsigned long)_end;
638c2ecf20Sopenharmony_ci	u32 pir_reg;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	simple_alloc_init(_end, avail_ram, 128, 64);
668c2ecf20Sopenharmony_ci	platform_ops.fixups = iss_4xx_fixups;
678c2ecf20Sopenharmony_ci	platform_ops.vmlinux_alloc = iss_4xx_vmlinux_alloc;
688c2ecf20Sopenharmony_ci	platform_ops.exit = ibm44x_dbcr_reset;
698c2ecf20Sopenharmony_ci	pir_reg = mfspr(SPRN_PIR);
708c2ecf20Sopenharmony_ci	fdt_set_boot_cpuid_phys(_dtb_start, pir_reg);
718c2ecf20Sopenharmony_ci	fdt_init(_dtb_start);
728c2ecf20Sopenharmony_ci	serial_console_init();
738c2ecf20Sopenharmony_ci}
74