Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2008-2010 Freescale Semiconductor, Inc. |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 970b61e | 2019-11-14 12:57:09 -0700 | [diff] [blame^] | 7 | #include <cpu_func.h> |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 8 | #include <asm/processor.h> |
| 9 | #include <asm/mmu.h> |
| 10 | #include <ioports.h> |
| 11 | #include <lmb.h> |
| 12 | #include <asm/io.h> |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 13 | #include <asm/mp.h> |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 17 | int cpu_reset(u32 nr) |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 18 | { |
| 19 | /* dummy function so common/cmd_mp.c will build |
| 20 | * should be implemented in the future, when cpu_release() |
| 21 | * is supported. Be aware there may be a similiar bug |
| 22 | * as exists on MPC85xx w/its PIC having a timing window |
| 23 | * associated to resetting the core */ |
| 24 | return 1; |
| 25 | } |
| 26 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 27 | int cpu_status(u32 nr) |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 28 | { |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 29 | /* dummy function so common/cmd_mp.c will build */ |
| 30 | return 0; |
| 31 | } |
| 32 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 33 | int cpu_disable(u32 nr) |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 34 | { |
Kumar Gala | 84c70bd | 2010-01-12 11:51:52 -0600 | [diff] [blame] | 35 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR; |
| 36 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 37 | |
| 38 | switch (nr) { |
| 39 | case 0: |
| 40 | setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU0); |
| 41 | break; |
| 42 | case 1: |
| 43 | setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_CPU1); |
| 44 | break; |
| 45 | default: |
| 46 | printf("Invalid cpu number for disable %d\n", nr); |
| 47 | return 1; |
| 48 | } |
| 49 | |
| 50 | return 0; |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 51 | } |
| 52 | |
Kumar Gala | 819a479 | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 53 | int is_core_disabled(int nr) { |
| 54 | immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR; |
| 55 | ccsr_gur_t *gur = &immap->im_gur; |
| 56 | u32 devdisr = in_be32(&gur->devdisr); |
| 57 | |
| 58 | switch (nr) { |
| 59 | case 0: |
| 60 | return (devdisr & MPC86xx_DEVDISR_CPU0); |
| 61 | case 1: |
| 62 | return (devdisr & MPC86xx_DEVDISR_CPU1); |
| 63 | default: |
| 64 | printf("Invalid cpu number for disable %d\n", nr); |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 70 | int cpu_release(u32 nr, int argc, char * const argv[]) |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 71 | { |
| 72 | /* dummy function so common/cmd_mp.c will build |
| 73 | * should be implemented in the future */ |
| 74 | return 1; |
| 75 | } |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 76 | |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 77 | u32 determine_mp_bootpg(unsigned int *pagesize) |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 78 | { |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 79 | if (pagesize) |
| 80 | *pagesize = 4096; |
| 81 | |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 82 | /* if we have 4G or more of memory, put the boot page at 4Gb-1M */ |
| 83 | if ((u64)gd->ram_size > 0xfffff000) |
Kumar Gala | 56d150e | 2009-03-31 23:02:38 -0500 | [diff] [blame] | 84 | return (0xfff00000); |
| 85 | |
| 86 | return (gd->ram_size - (1024 * 1024)); |
| 87 | } |
| 88 | |
| 89 | void cpu_mp_lmb_reserve(struct lmb *lmb) |
| 90 | { |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 91 | u32 bootpg = determine_mp_bootpg(NULL); |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 92 | |
| 93 | /* tell u-boot we stole a page */ |
| 94 | lmb_reserve(lmb, bootpg, 4096); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Copy the code for other cpus to execute into an |
| 99 | * aligned location accessible via BPTR |
| 100 | */ |
| 101 | void setup_mp(void) |
| 102 | { |
| 103 | extern ulong __secondary_start_page; |
| 104 | ulong fixup = (ulong)&__secondary_start_page; |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 105 | u32 bootpg = determine_mp_bootpg(NULL); |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 106 | u32 bootpg_va; |
| 107 | |
Becky Bruce | d1cb6cb | 2008-11-03 15:44:01 -0600 | [diff] [blame] | 108 | if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE) { |
| 109 | /* We're not covered by the DDR mapping, set up BAT */ |
| 110 | write_bat(DBAT7, CONFIG_SYS_SCRATCH_VA | BATU_BL_128K | |
| 111 | BATU_VS | BATU_VP, |
| 112 | bootpg | BATL_PP_RW | BATL_MEMCOHERENCE); |
| 113 | bootpg_va = CONFIG_SYS_SCRATCH_VA; |
| 114 | } else { |
| 115 | bootpg_va = bootpg; |
| 116 | } |
| 117 | |
| 118 | memcpy((void *)bootpg_va, (void *)fixup, 4096); |
| 119 | flush_cache(bootpg_va, 4096); |
| 120 | |
| 121 | /* remove the temporary BAT mapping */ |
| 122 | if (bootpg >= CONFIG_SYS_MAX_DDR_BAT_SIZE) |
| 123 | write_bat(DBAT7, 0, 0); |
| 124 | |
| 125 | /* If the physical location of bootpg is not at fff00000, set BPTR */ |
| 126 | if (bootpg != 0xfff00000) |
| 127 | out_be32((uint *)(CONFIG_SYS_CCSRBAR + 0x20), 0x80000000 | |
| 128 | (bootpg >> 12)); |
| 129 | } |