Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Copyright 2007-2009 Analog Devices Inc. |
| 3 | * Philippe Gerum <rpm@xenomai.org> |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 4 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 5 | * Licensed under the GPL-2 or later. |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <asm/smp.h> |
| 13 | #include <asm/dma.h> |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 14 | #include <asm/time.h> |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 15 | |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 16 | static DEFINE_SPINLOCK(boot_lock); |
| 17 | |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 18 | /* |
| 19 | * platform_init_cpus() - Tell the world about how many cores we |
| 20 | * have. This is called while setting up the architecture support |
| 21 | * (setup_arch()), so don't be too demanding here with respect to |
| 22 | * available kernel services. |
| 23 | */ |
| 24 | |
| 25 | void __init platform_init_cpus(void) |
| 26 | { |
KOSAKI Motohiro | 3cb8a39 | 2011-04-26 10:55:41 +0900 | [diff] [blame] | 27 | struct cpumask mask; |
| 28 | |
| 29 | cpumask_set_cpu(0, &mask); /* CoreA */ |
| 30 | cpumask_set_cpu(1, &mask); /* CoreB */ |
| 31 | init_cpu_possible(&mask); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void __init platform_prepare_cpus(unsigned int max_cpus) |
| 35 | { |
KOSAKI Motohiro | 3cb8a39 | 2011-04-26 10:55:41 +0900 | [diff] [blame] | 36 | struct cpumask mask; |
| 37 | |
Sonic Zhang | c6345ab | 2010-08-05 07:49:26 +0000 | [diff] [blame] | 38 | bfin_relocate_coreb_l1_mem(); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 39 | |
| 40 | /* Both cores ought to be present on a bf561! */ |
KOSAKI Motohiro | 3cb8a39 | 2011-04-26 10:55:41 +0900 | [diff] [blame] | 41 | cpumask_set_cpu(0, &mask); /* CoreA */ |
| 42 | cpumask_set_cpu(1, &mask); /* CoreB */ |
| 43 | init_cpu_present(&mask); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | int __init setup_profiling_timer(unsigned int multiplier) /* not supported */ |
| 47 | { |
| 48 | return -EINVAL; |
| 49 | } |
| 50 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 51 | void platform_secondary_init(unsigned int cpu) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 52 | { |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 53 | /* Clone setup for peripheral interrupt sources from CoreA. */ |
Mike Frysinger | 39c9996 | 2010-10-19 18:44:23 +0000 | [diff] [blame] | 54 | bfin_write_SICB_IMASK0(bfin_read_SIC_IMASK0()); |
| 55 | bfin_write_SICB_IMASK1(bfin_read_SIC_IMASK1()); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 56 | SSYNC(); |
| 57 | |
| 58 | /* Clone setup for IARs from CoreA. */ |
Mike Frysinger | 39c9996 | 2010-10-19 18:44:23 +0000 | [diff] [blame] | 59 | bfin_write_SICB_IAR0(bfin_read_SIC_IAR0()); |
| 60 | bfin_write_SICB_IAR1(bfin_read_SIC_IAR1()); |
| 61 | bfin_write_SICB_IAR2(bfin_read_SIC_IAR2()); |
| 62 | bfin_write_SICB_IAR3(bfin_read_SIC_IAR3()); |
| 63 | bfin_write_SICB_IAR4(bfin_read_SIC_IAR4()); |
| 64 | bfin_write_SICB_IAR5(bfin_read_SIC_IAR5()); |
| 65 | bfin_write_SICB_IAR6(bfin_read_SIC_IAR6()); |
| 66 | bfin_write_SICB_IAR7(bfin_read_SIC_IAR7()); |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 67 | bfin_write_SICB_IWR0(IWR_DISABLE_ALL); |
| 68 | bfin_write_SICB_IWR1(IWR_DISABLE_ALL); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 69 | SSYNC(); |
| 70 | |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 71 | /* We are done with local CPU inits, unblock the boot CPU. */ |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 72 | spin_lock(&boot_lock); |
| 73 | spin_unlock(&boot_lock); |
| 74 | } |
| 75 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 76 | int platform_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 77 | { |
| 78 | unsigned long timeout; |
| 79 | |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 80 | printk(KERN_INFO "Booting Core B.\n"); |
| 81 | |
| 82 | spin_lock(&boot_lock); |
| 83 | |
Mike Frysinger | 94a038c | 2010-10-27 10:06:32 -0400 | [diff] [blame] | 84 | if ((bfin_read_SYSCR() & COREB_SRAM_INIT) == 0) { |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 85 | /* CoreB already running, sending ipi to wakeup it */ |
Bob Liu | d0014be | 2011-12-12 11:04:05 +0800 | [diff] [blame] | 86 | smp_send_reschedule(cpu); |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 87 | } else { |
| 88 | /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */ |
Mike Frysinger | 94a038c | 2010-10-27 10:06:32 -0400 | [diff] [blame] | 89 | bfin_write_SYSCR(bfin_read_SYSCR() & ~COREB_SRAM_INIT); |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 90 | SSYNC(); |
| 91 | } |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 92 | |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 93 | timeout = jiffies + HZ; |
| 94 | /* release the lock and let coreb run */ |
| 95 | spin_unlock(&boot_lock); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 96 | while (time_before(jiffies, timeout)) { |
Graf Yang | 682f5dc | 2009-12-28 09:27:27 +0000 | [diff] [blame] | 97 | if (cpu_online(cpu)) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 98 | break; |
| 99 | udelay(100); |
| 100 | barrier(); |
| 101 | } |
| 102 | |
Graf Yang | 682f5dc | 2009-12-28 09:27:27 +0000 | [diff] [blame] | 103 | if (cpu_online(cpu)) { |
Yi Li | 578d36f | 2009-12-02 07:58:12 +0000 | [diff] [blame] | 104 | return 0; |
| 105 | } else |
| 106 | panic("CPU%u: processor failed to boot\n", cpu); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 109 | static const char supple0[] = "IRQ_SUPPLE_0"; |
| 110 | static const char supple1[] = "IRQ_SUPPLE_1"; |
| 111 | void __init platform_request_ipi(int irq, void *handler) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 112 | { |
| 113 | int ret; |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 114 | const char *name = (irq == IRQ_SUPPLE_0) ? supple0 : supple1; |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 115 | |
Bob Liu | 16df366 | 2011-12-12 10:59:48 +0800 | [diff] [blame] | 116 | ret = request_irq(irq, handler, IRQF_PERCPU | IRQF_NO_SUSPEND | |
| 117 | IRQF_FORCE_RESUME, name, handler); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 118 | if (ret) |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 119 | panic("Cannot request %s for IPI service", name); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 120 | } |
| 121 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 122 | void platform_send_ipi(cpumask_t callmap, int irq) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 123 | { |
| 124 | unsigned int cpu; |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 125 | int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8; |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 126 | |
| 127 | for_each_cpu_mask(cpu, callmap) { |
| 128 | BUG_ON(cpu >= 2); |
| 129 | SSYNC(); |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 130 | bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu))); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 131 | SSYNC(); |
| 132 | } |
| 133 | } |
| 134 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 135 | void platform_send_ipi_cpu(unsigned int cpu, int irq) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 136 | { |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 137 | int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8; |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 138 | BUG_ON(cpu >= 2); |
| 139 | SSYNC(); |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 140 | bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu))); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 141 | SSYNC(); |
| 142 | } |
| 143 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 144 | void platform_clear_ipi(unsigned int cpu, int irq) |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 145 | { |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 146 | int offset = (irq == IRQ_SUPPLE_0) ? 10 : 12; |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 147 | BUG_ON(cpu >= 2); |
| 148 | SSYNC(); |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 149 | bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu))); |
Graf Yang | c51b448 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 150 | SSYNC(); |
| 151 | } |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Setup core B's local core timer. |
| 155 | * In SMP, core timer is used for clock event device. |
| 156 | */ |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 157 | void bfin_local_timer_setup(void) |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 158 | { |
| 159 | #if defined(CONFIG_TICKSOURCE_CORETMR) |
Thomas Gleixner | 1907d8b | 2011-03-24 17:21:01 +0100 | [diff] [blame] | 160 | struct irq_data *data = irq_get_irq_data(IRQ_CORETMR); |
| 161 | struct irq_chip *chip = irq_data_get_irq_chip(data); |
Mike Frysinger | 91796c2 | 2011-03-18 03:03:23 -0400 | [diff] [blame] | 162 | |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 163 | bfin_coretmr_init(); |
| 164 | bfin_coretmr_clockevent_init(); |
Mike Frysinger | 91796c2 | 2011-03-18 03:03:23 -0400 | [diff] [blame] | 165 | |
Thomas Gleixner | 1907d8b | 2011-03-24 17:21:01 +0100 | [diff] [blame] | 166 | chip->irq_unmask(data); |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 167 | #else |
| 168 | /* Power down the core timer, just to play safe. */ |
| 169 | bfin_write_TCNTL(0); |
| 170 | #endif |
| 171 | |
| 172 | } |