1a47a12beSStefan Roese /*
2a47a12beSStefan Roese * Copyright 2008-2010 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese *
4*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
5a47a12beSStefan Roese */
6a47a12beSStefan Roese
7a47a12beSStefan Roese #include <common.h>
8a47a12beSStefan Roese #include <asm/processor.h>
9a47a12beSStefan Roese #include <asm/mmu.h>
10a47a12beSStefan Roese #include <ioports.h>
11a47a12beSStefan Roese #include <lmb.h>
12a47a12beSStefan Roese #include <asm/io.h>
13a47a12beSStefan Roese #include <asm/mp.h>
14a47a12beSStefan Roese
15a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
16a47a12beSStefan Roese
cpu_reset(int nr)17a47a12beSStefan Roese int cpu_reset(int nr)
18a47a12beSStefan Roese {
19a47a12beSStefan Roese /* dummy function so common/cmd_mp.c will build
20a47a12beSStefan Roese * should be implemented in the future, when cpu_release()
21a47a12beSStefan Roese * is supported. Be aware there may be a similiar bug
22a47a12beSStefan Roese * as exists on MPC85xx w/its PIC having a timing window
23a47a12beSStefan Roese * associated to resetting the core */
24a47a12beSStefan Roese return 1;
25a47a12beSStefan Roese }
26a47a12beSStefan Roese
cpu_status(int nr)27a47a12beSStefan Roese int cpu_status(int nr)
28a47a12beSStefan Roese {
29a47a12beSStefan Roese /* dummy function so common/cmd_mp.c will build */
30a47a12beSStefan Roese return 0;
31a47a12beSStefan Roese }
32a47a12beSStefan Roese
cpu_disable(int nr)33a47a12beSStefan Roese int cpu_disable(int nr)
34a47a12beSStefan Roese {
35a47a12beSStefan Roese volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
36a47a12beSStefan Roese volatile ccsr_gur_t *gur = &immap->im_gur;
37a47a12beSStefan Roese
38a47a12beSStefan Roese switch (nr) {
39a47a12beSStefan Roese case 0:
40a47a12beSStefan Roese setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU0);
41a47a12beSStefan Roese break;
42a47a12beSStefan Roese case 1:
43a47a12beSStefan Roese setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU1);
44a47a12beSStefan Roese break;
45a47a12beSStefan Roese default:
46a47a12beSStefan Roese printf("Invalid cpu number for disable %d\n", nr);
47a47a12beSStefan Roese return 1;
48a47a12beSStefan Roese }
49a47a12beSStefan Roese
50a47a12beSStefan Roese return 0;
51a47a12beSStefan Roese }
52a47a12beSStefan Roese
is_core_disabled(int nr)538f3a7fa4SKumar Gala int is_core_disabled(int nr) {
548f3a7fa4SKumar Gala immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
558f3a7fa4SKumar Gala ccsr_gur_t *gur = &immap->im_gur;
568f3a7fa4SKumar Gala u32 devdisr = in_be32(&gur->devdisr);
578f3a7fa4SKumar Gala
588f3a7fa4SKumar Gala switch (nr) {
598f3a7fa4SKumar Gala case 0:
608f3a7fa4SKumar Gala return (devdisr & MPC86xx_DEVDISR_CPU0);
618f3a7fa4SKumar Gala case 1:
628f3a7fa4SKumar Gala return (devdisr & MPC86xx_DEVDISR_CPU1);
638f3a7fa4SKumar Gala default:
648f3a7fa4SKumar Gala printf("Invalid cpu number for disable %d\n", nr);
658f3a7fa4SKumar Gala }
668f3a7fa4SKumar Gala
678f3a7fa4SKumar Gala return 0;
688f3a7fa4SKumar Gala }
698f3a7fa4SKumar Gala
cpu_release(int nr,int argc,char * const argv[])7054841ab5SWolfgang Denk int cpu_release(int nr, int argc, char * const argv[])
71a47a12beSStefan Roese {
72a47a12beSStefan Roese /* dummy function so common/cmd_mp.c will build
73a47a12beSStefan Roese * should be implemented in the future */
74a47a12beSStefan Roese return 1;
75a47a12beSStefan Roese }
76a47a12beSStefan Roese
determine_mp_bootpg(unsigned int * pagesize)77eb539412SYork Sun u32 determine_mp_bootpg(unsigned int *pagesize)
78a47a12beSStefan Roese {
79eb539412SYork Sun if (pagesize)
80eb539412SYork Sun *pagesize = 4096;
81eb539412SYork Sun
82a47a12beSStefan Roese /* if we have 4G or more of memory, put the boot page at 4Gb-1M */
83a47a12beSStefan Roese if ((u64)gd->ram_size > 0xfffff000)
84a47a12beSStefan Roese return (0xfff00000);
85a47a12beSStefan Roese
86a47a12beSStefan Roese return (gd->ram_size - (1024 * 1024));
87a47a12beSStefan Roese }
88a47a12beSStefan Roese
cpu_mp_lmb_reserve(struct lmb * lmb)89a47a12beSStefan Roese void cpu_mp_lmb_reserve(struct lmb *lmb)
90a47a12beSStefan Roese {
91eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL);
92a47a12beSStefan Roese
93a47a12beSStefan Roese /* tell u-boot we stole a page */
94a47a12beSStefan Roese lmb_reserve(lmb, bootpg, 4096);
95a47a12beSStefan Roese }
96a47a12beSStefan Roese
97a47a12beSStefan Roese /*
98a47a12beSStefan Roese * Copy the code for other cpus to execute into an
99a47a12beSStefan Roese * aligned location accessible via BPTR
100a47a12beSStefan Roese */
setup_mp(void)101a47a12beSStefan Roese void setup_mp(void)
102a47a12beSStefan Roese {
103a47a12beSStefan Roese extern ulong __secondary_start_page;
104a47a12beSStefan Roese ulong fixup = (ulong)&__secondary_start_page;
105eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL);
106a47a12beSStefan Roese u32 bootpg_va;
107a47a12beSStefan Roese
108a47a12beSStefan Roese if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE) {
109a47a12beSStefan Roese /* We're not covered by the DDR mapping, set up BAT */
110a47a12beSStefan Roese write_bat(DBAT7, CONFIG_SYS_SCRATCH_VA | BATU_BL_128K |
111a47a12beSStefan Roese BATU_VS | BATU_VP,
112a47a12beSStefan Roese bootpg | BATL_PP_RW | BATL_MEMCOHERENCE);
113a47a12beSStefan Roese bootpg_va = CONFIG_SYS_SCRATCH_VA;
114a47a12beSStefan Roese } else {
115a47a12beSStefan Roese bootpg_va = bootpg;
116a47a12beSStefan Roese }
117a47a12beSStefan Roese
118a47a12beSStefan Roese memcpy((void *)bootpg_va, (void *)fixup, 4096);
119a47a12beSStefan Roese flush_cache(bootpg_va, 4096);
120a47a12beSStefan Roese
121a47a12beSStefan Roese /* remove the temporary BAT mapping */
122a47a12beSStefan Roese if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE)
123a47a12beSStefan Roese write_bat(DBAT7, 0, 0);
124a47a12beSStefan Roese
125a47a12beSStefan Roese /* If the physical location of bootpg is not at fff00000, set BPTR */
126a47a12beSStefan Roese if (bootpg != 0xfff00000)
127a47a12beSStefan Roese out_be32((uint *)(CONFIG_SYS_CCSRBAR + 0x20), 0x80000000 |
128a47a12beSStefan Roese (bootpg >> 12));
129a47a12beSStefan Roese }
130