1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2228d5505STony Breeds /*
3228d5505STony Breeds * Copyright © 2011 Tony Breeds IBM Corporation
4228d5505STony Breeds *
5228d5505STony Breeds * Based on earlier code:
6228d5505STony Breeds * Copyright (C) Paul Mackerras 1997.
7228d5505STony Breeds *
8228d5505STony Breeds * Matt Porter <mporter@kernel.crashing.org>
9228d5505STony Breeds * Copyright 2002-2005 MontaVista Software Inc.
10228d5505STony Breeds *
11228d5505STony Breeds * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
12228d5505STony Breeds * Copyright (c) 2003, 2004 Zultys Technologies
13228d5505STony Breeds *
14228d5505STony Breeds * Copyright 2007 David Gibson, IBM Corporation.
15228d5505STony Breeds * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
16228d5505STony Breeds * Copyright © 2011 David Kleikamp IBM Corporation
17228d5505STony Breeds */
18228d5505STony Breeds #include <stdarg.h>
19228d5505STony Breeds #include <stddef.h>
20228d5505STony Breeds #include "types.h"
21228d5505STony Breeds #include "elf.h"
22228d5505STony Breeds #include "string.h"
23228d5505STony Breeds #include "stdio.h"
24228d5505STony Breeds #include "page.h"
25228d5505STony Breeds #include "ops.h"
26228d5505STony Breeds #include "reg.h"
27228d5505STony Breeds #include "io.h"
28228d5505STony Breeds #include "dcr.h"
29228d5505STony Breeds #include "4xx.h"
30228d5505STony Breeds #include "44x.h"
31228d5505STony Breeds #include "libfdt.h"
32228d5505STony Breeds
33228d5505STony Breeds BSS_STACK(4096);
34228d5505STony Breeds
35228d5505STony Breeds #define MAX_RANKS 0x4
36228d5505STony Breeds #define DDR3_MR0CF 0x80010011U
37228d5505STony Breeds
38228d5505STony Breeds static unsigned long long ibm_currituck_memsize;
ibm_currituck_detect_memsize(void)39228d5505STony Breeds static unsigned long long ibm_currituck_detect_memsize(void)
40228d5505STony Breeds {
41228d5505STony Breeds u32 reg;
42228d5505STony Breeds unsigned i;
43228d5505STony Breeds unsigned long long memsize = 0;
44228d5505STony Breeds
45228d5505STony Breeds for(i = 0; i < MAX_RANKS; i++){
46228d5505STony Breeds reg = mfdcrx(DDR3_MR0CF + i);
47228d5505STony Breeds
48228d5505STony Breeds if (!(reg & 1))
49228d5505STony Breeds continue;
50228d5505STony Breeds
51228d5505STony Breeds reg &= 0x0000f000;
52228d5505STony Breeds reg >>= 12;
53228d5505STony Breeds memsize += (0x800000ULL << reg);
54228d5505STony Breeds }
55228d5505STony Breeds
56228d5505STony Breeds return memsize;
57228d5505STony Breeds }
58228d5505STony Breeds
ibm_currituck_fixups(void)59228d5505STony Breeds static void ibm_currituck_fixups(void)
60228d5505STony Breeds {
61228d5505STony Breeds void *devp = finddevice("/");
62228d5505STony Breeds u32 dma_ranges[7];
63228d5505STony Breeds
64228d5505STony Breeds dt_fixup_memory(0x0ULL, ibm_currituck_memsize);
65228d5505STony Breeds
66228d5505STony Breeds while ((devp = find_node_by_devtype(devp, "pci"))) {
67228d5505STony Breeds if (getprop(devp, "dma-ranges", dma_ranges, sizeof(dma_ranges)) < 0) {
68228d5505STony Breeds printf("%s: Failed to get dma-ranges\r\n", __func__);
69228d5505STony Breeds continue;
70228d5505STony Breeds }
71228d5505STony Breeds
72228d5505STony Breeds dma_ranges[5] = ibm_currituck_memsize >> 32;
73228d5505STony Breeds dma_ranges[6] = ibm_currituck_memsize & 0xffffffffUL;
74228d5505STony Breeds
75228d5505STony Breeds setprop(devp, "dma-ranges", dma_ranges, sizeof(dma_ranges));
76228d5505STony Breeds }
77228d5505STony Breeds }
78228d5505STony Breeds
79446957baSAdam Buchbinder #define SPRN_PIR 0x11E /* Processor Identification Register */
platform_init(void)80228d5505STony Breeds void platform_init(void)
81228d5505STony Breeds {
82228d5505STony Breeds unsigned long end_of_ram, avail_ram;
83228d5505STony Breeds u32 pir_reg;
84228d5505STony Breeds int node, size;
85228d5505STony Breeds const u32 *timebase;
86228d5505STony Breeds
87228d5505STony Breeds ibm_currituck_memsize = ibm_currituck_detect_memsize();
88228d5505STony Breeds if (ibm_currituck_memsize >> 32)
89228d5505STony Breeds end_of_ram = ~0UL;
90228d5505STony Breeds else
91228d5505STony Breeds end_of_ram = ibm_currituck_memsize;
92228d5505STony Breeds avail_ram = end_of_ram - (unsigned long)_end;
93228d5505STony Breeds
94228d5505STony Breeds simple_alloc_init(_end, avail_ram, 128, 64);
95228d5505STony Breeds platform_ops.fixups = ibm_currituck_fixups;
96228d5505STony Breeds platform_ops.exit = ibm44x_dbcr_reset;
97228d5505STony Breeds pir_reg = mfspr(SPRN_PIR);
98228d5505STony Breeds
99228d5505STony Breeds /* Make sure FDT blob is sane */
100228d5505STony Breeds if (fdt_check_header(_dtb_start) != 0)
101228d5505STony Breeds fatal("Invalid device tree blob\n");
102228d5505STony Breeds
103228d5505STony Breeds node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
104228d5505STony Breeds "cpu", sizeof("cpu"));
105228d5505STony Breeds if (!node)
106228d5505STony Breeds fatal("Cannot find cpu node\n");
107228d5505STony Breeds timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
108228d5505STony Breeds if (timebase && (size == 4))
109228d5505STony Breeds timebase_period_ns = 1000000000 / *timebase;
110228d5505STony Breeds
111228d5505STony Breeds fdt_set_boot_cpuid_phys(_dtb_start, pir_reg);
112228d5505STony Breeds fdt_init(_dtb_start);
113228d5505STony Breeds
114228d5505STony Breeds serial_console_init();
115228d5505STony Breeds }
116