blob: e6795e06c98b852c6f77caee2e1f3b34103a44e7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala006e2c82010-01-12 11:42:43 -06002/*
3 * Copyright 2008-2010 Freescale Semiconductor, Inc.
Kumar Gala006e2c82010-01-12 11:42:43 -06004 */
5
Becky Bruced1cb6cb2008-11-03 15:44:01 -06006#include <common.h>
Simon Glass970b61e2019-11-14 12:57:09 -07007#include <cpu_func.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Becky Bruced1cb6cb2008-11-03 15:44:01 -06009#include <asm/processor.h>
10#include <asm/mmu.h>
11#include <ioports.h>
12#include <lmb.h>
13#include <asm/io.h>
Kumar Gala56d150e2009-03-31 23:02:38 -050014#include <asm/mp.h>
Becky Bruced1cb6cb2008-11-03 15:44:01 -060015
16DECLARE_GLOBAL_DATA_PTR;
17
Michal Simek1669e182018-06-13 08:56:31 +020018int cpu_reset(u32 nr)
Kumar Gala56d150e2009-03-31 23:02:38 -050019{
20 /* dummy function so common/cmd_mp.c will build
21 * should be implemented in the future, when cpu_release()
22 * is supported. Be aware there may be a similiar bug
23 * as exists on MPC85xx w/its PIC having a timing window
24 * associated to resetting the core */
25 return 1;
26}
27
Michal Simek1669e182018-06-13 08:56:31 +020028int cpu_status(u32 nr)
Becky Bruced1cb6cb2008-11-03 15:44:01 -060029{
Kumar Gala56d150e2009-03-31 23:02:38 -050030 /* dummy function so common/cmd_mp.c will build */
31 return 0;
32}
33
Michal Simek1669e182018-06-13 08:56:31 +020034int cpu_disable(u32 nr)
Kumar Gala006e2c82010-01-12 11:42:43 -060035{
Kumar Gala84c70bd2010-01-12 11:51:52 -060036 volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
37 volatile ccsr_gur_t *gur = &immap->im_gur;
38
39 switch (nr) {
40 case 0:
41 setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU0);
42 break;
43 case 1:
44 setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU1);
45 break;
46 default:
47 printf("Invalid cpu number for disable %d\n", nr);
48 return 1;
49 }
50
51 return 0;
Kumar Gala006e2c82010-01-12 11:42:43 -060052}
53
Kumar Gala819a4792010-06-09 22:33:53 -050054int is_core_disabled(int nr) {
55 immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
56 ccsr_gur_t *gur = &immap->im_gur;
57 u32 devdisr = in_be32(&gur->devdisr);
58
59 switch (nr) {
60 case 0:
61 return (devdisr & MPC86xx_DEVDISR_CPU0);
62 case 1:
63 return (devdisr & MPC86xx_DEVDISR_CPU1);
64 default:
65 printf("Invalid cpu number for disable %d\n", nr);
66 }
67
68 return 0;
69}
70
Simon Glassed38aef2020-05-10 11:40:03 -060071int cpu_release(u32 nr, int argc, char *const argv[])
Kumar Gala56d150e2009-03-31 23:02:38 -050072{
73 /* dummy function so common/cmd_mp.c will build
74 * should be implemented in the future */
75 return 1;
76}
Becky Bruced1cb6cb2008-11-03 15:44:01 -060077
York Suna28496f2012-10-08 07:44:25 +000078u32 determine_mp_bootpg(unsigned int *pagesize)
Kumar Gala56d150e2009-03-31 23:02:38 -050079{
York Suna28496f2012-10-08 07:44:25 +000080 if (pagesize)
81 *pagesize = 4096;
82
Becky Bruced1cb6cb2008-11-03 15:44:01 -060083 /* if we have 4G or more of memory, put the boot page at 4Gb-1M */
84 if ((u64)gd->ram_size > 0xfffff000)
Kumar Gala56d150e2009-03-31 23:02:38 -050085 return (0xfff00000);
86
87 return (gd->ram_size - (1024 * 1024));
88}
89
90void cpu_mp_lmb_reserve(struct lmb *lmb)
91{
York Suna28496f2012-10-08 07:44:25 +000092 u32 bootpg = determine_mp_bootpg(NULL);
Becky Bruced1cb6cb2008-11-03 15:44:01 -060093
94 /* tell u-boot we stole a page */
95 lmb_reserve(lmb, bootpg, 4096);
96}
97
98/*
99 * Copy the code for other cpus to execute into an
100 * aligned location accessible via BPTR
101 */
102void setup_mp(void)
103{
104 extern ulong __secondary_start_page;
105 ulong fixup = (ulong)&__secondary_start_page;
York Suna28496f2012-10-08 07:44:25 +0000106 u32 bootpg = determine_mp_bootpg(NULL);
Becky Bruced1cb6cb2008-11-03 15:44:01 -0600107 u32 bootpg_va;
108
Becky Bruced1cb6cb2008-11-03 15:44:01 -0600109 if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE) {
110 /* We're not covered by the DDR mapping, set up BAT */
111 write_bat(DBAT7, CONFIG_SYS_SCRATCH_VA | BATU_BL_128K |
112 BATU_VS | BATU_VP,
113 bootpg | BATL_PP_RW | BATL_MEMCOHERENCE);
114 bootpg_va = CONFIG_SYS_SCRATCH_VA;
115 } else {
116 bootpg_va = bootpg;
117 }
118
119 memcpy((void *)bootpg_va, (void *)fixup, 4096);
120 flush_cache(bootpg_va, 4096);
121
122 /* remove the temporary BAT mapping */
123 if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE)
124 write_bat(DBAT7, 0, 0);
125
126 /* If the physical location of bootpg is not at fff00000, set BPTR */
127 if (bootpg != 0xfff00000)
128 out_be32((uint *)(CONFIG_SYS_CCSRBAR + 0x20), 0x80000000 |
129 (bootpg >> 12));
130}