Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
| 24 | #include <asm/processor.h> |
| 25 | #include <ioports.h> |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 26 | #include <lmb.h> |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 27 | #include <asm/io.h> |
| 28 | #include "mp.h" |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 32 | u32 get_my_id() |
| 33 | { |
| 34 | return mfspr(SPRN_PIR); |
| 35 | } |
| 36 | |
| 37 | int cpu_reset(int nr) |
| 38 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 40 | out_be32(&pic->pir, 1 << nr); |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame^] | 41 | /* the dummy read works around an errata on early 85xx MP PICs */ |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 42 | (void)in_be32(&pic->pir); |
| 43 | out_be32(&pic->pir, 0x0); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | int cpu_status(int nr) |
| 49 | { |
| 50 | u32 *table, id = get_my_id(); |
| 51 | |
| 52 | if (nr == id) { |
| 53 | table = (u32 *)get_spin_addr(); |
Kumar Gala | 275f4c1 | 2008-07-14 14:03:02 -0500 | [diff] [blame] | 54 | printf("table base @ 0x%p\n", table); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 55 | } else { |
| 56 | table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY; |
| 57 | printf("Running on cpu %d\n", id); |
| 58 | printf("\n"); |
Kumar Gala | 275f4c1 | 2008-07-14 14:03:02 -0500 | [diff] [blame] | 59 | printf("table @ 0x%p\n", table); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 60 | printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 61 | printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 62 | printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]); |
| 63 | printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 69 | static u8 boot_entry_map[4] = { |
| 70 | 0, |
| 71 | BOOT_ENTRY_PIR, |
| 72 | BOOT_ENTRY_R3_LOWER, |
| 73 | BOOT_ENTRY_R6_LOWER, |
| 74 | }; |
| 75 | |
| 76 | int cpu_release(int nr, int argc, char *argv[]) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 77 | { |
| 78 | u32 i, val, *table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY; |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 79 | u64 boot_addr; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 80 | |
| 81 | if (nr == get_my_id()) { |
| 82 | printf("Invalid to release the boot core.\n\n"); |
| 83 | return 1; |
| 84 | } |
| 85 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 86 | if (argc != 4) { |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 87 | printf("Invalid number of arguments to release.\n\n"); |
| 88 | return 1; |
| 89 | } |
| 90 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | #ifdef CONFIG_SYS_64BIT_STRTOUL |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 92 | boot_addr = simple_strtoull(argv[0], NULL, 16); |
| 93 | #else |
| 94 | boot_addr = simple_strtoul(argv[0], NULL, 16); |
| 95 | #endif |
| 96 | |
| 97 | /* handle pir, r3, r6 */ |
| 98 | for (i = 1; i < 4; i++) { |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 99 | if (argv[i][0] != '-') { |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 100 | u8 entry = boot_entry_map[i]; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 101 | val = simple_strtoul(argv[i], NULL, 16); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 102 | table[entry] = val; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 106 | table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32); |
Kumar Gala | 398dcd6 | 2008-04-28 02:24:04 -0500 | [diff] [blame] | 107 | |
| 108 | /* ensure all table updates complete before final address write */ |
| 109 | eieio(); |
| 110 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 111 | table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame^] | 116 | u32 determine_mp_bootpg(void) |
| 117 | { |
| 118 | /* if we have 4G or more of memory, put the boot page at 4Gb-4k */ |
| 119 | if ((u64)gd->ram_size > 0xfffff000) |
| 120 | return (0xfffff000); |
| 121 | |
| 122 | return (gd->ram_size - 4096); |
| 123 | } |
| 124 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 125 | ulong get_spin_addr(void) |
| 126 | { |
| 127 | extern ulong __secondary_start_page; |
| 128 | extern ulong __spin_table; |
| 129 | |
| 130 | ulong addr = |
| 131 | (ulong)&__spin_table - (ulong)&__secondary_start_page; |
| 132 | addr += 0xfffff000; |
| 133 | |
| 134 | return addr; |
| 135 | } |
| 136 | |
| 137 | static void pq3_mp_up(unsigned long bootpg) |
| 138 | { |
| 139 | u32 up, cpu_up_mask, whoami; |
| 140 | u32 *table = (u32 *)get_spin_addr(); |
| 141 | volatile u32 bpcr; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR); |
| 143 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 144 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 145 | u32 devdisr; |
| 146 | int timeout = 10; |
| 147 | |
| 148 | whoami = in_be32(&pic->whoami); |
| 149 | out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12)); |
| 150 | |
| 151 | /* disable time base at the platform */ |
| 152 | devdisr = in_be32(&gur->devdisr); |
| 153 | if (whoami) |
| 154 | devdisr |= MPC85xx_DEVDISR_TB0; |
| 155 | else |
| 156 | devdisr |= MPC85xx_DEVDISR_TB1; |
| 157 | out_be32(&gur->devdisr, devdisr); |
| 158 | |
| 159 | /* release the hounds */ |
Kumar Gala | ccdeac7 | 2008-08-11 11:29:28 -0500 | [diff] [blame] | 160 | up = ((1 << CONFIG_NUM_CPUS) - 1); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 161 | bpcr = in_be32(&ecm->eebpcr); |
| 162 | bpcr |= (up << 24); |
| 163 | out_be32(&ecm->eebpcr, bpcr); |
| 164 | asm("sync; isync; msync"); |
| 165 | |
| 166 | cpu_up_mask = 1 << whoami; |
| 167 | /* wait for everyone */ |
| 168 | while (timeout) { |
| 169 | int i; |
Kumar Gala | ccdeac7 | 2008-08-11 11:29:28 -0500 | [diff] [blame] | 170 | for (i = 0; i < CONFIG_NUM_CPUS; i++) { |
Kumar Gala | 615f14d | 2008-04-09 04:20:57 -0500 | [diff] [blame] | 171 | if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER]) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 172 | cpu_up_mask |= (1 << i); |
| 173 | }; |
| 174 | |
| 175 | if ((cpu_up_mask & up) == up) |
| 176 | break; |
| 177 | |
| 178 | udelay(100); |
| 179 | timeout--; |
| 180 | } |
| 181 | |
Kumar Gala | 615f14d | 2008-04-09 04:20:57 -0500 | [diff] [blame] | 182 | if (timeout == 0) |
| 183 | printf("CPU up timeout. CPU up mask is %x should be %x\n", |
| 184 | cpu_up_mask, up); |
| 185 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 186 | /* enable time base at the platform */ |
| 187 | if (whoami) |
| 188 | devdisr |= MPC85xx_DEVDISR_TB1; |
| 189 | else |
| 190 | devdisr |= MPC85xx_DEVDISR_TB0; |
| 191 | out_be32(&gur->devdisr, devdisr); |
| 192 | mtspr(SPRN_TBWU, 0); |
| 193 | mtspr(SPRN_TBWL, 0); |
| 194 | |
| 195 | devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1); |
| 196 | out_be32(&gur->devdisr, devdisr); |
| 197 | } |
| 198 | |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 199 | void cpu_mp_lmb_reserve(struct lmb *lmb) |
| 200 | { |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame^] | 201 | u32 bootpg = determine_mp_bootpg(); |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 202 | |
| 203 | lmb_reserve(lmb, bootpg, 4096); |
| 204 | } |
| 205 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 206 | void setup_mp(void) |
| 207 | { |
| 208 | extern ulong __secondary_start_page; |
| 209 | ulong fixup = (ulong)&__secondary_start_page; |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame^] | 210 | u32 bootpg = determine_mp_bootpg(); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 211 | |
| 212 | memcpy((void *)bootpg, (void *)fixup, 4096); |
| 213 | flush_cache(bootpg, 4096); |
| 214 | |
| 215 | pq3_mp_up(bootpg); |
| 216 | } |