⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmac_smp.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
	unsigned long a;	/* may need to flush here if secondary bats aren't setup */	for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32)		asm volatile("dcbf 0,%0" : : "r" (a) : "memory");	asm volatile("sync");	if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);	out_be32(psurge_start, start);	mb();	psurge_set_ipi(nr);	udelay(10);	psurge_clr_ipi(nr);	if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354);}/* * With the dual-cpu powersurge board, the decrementers and timebases * of both cpus are frozen after the secondary cpu is started up, * until we give the secondary cpu another interrupt.  This routine * uses this to get the timebases synchronized. *  -- paulus. */static void __init psurge_dual_sync_tb(int cpu_nr){	int t;	set_dec(tb_ticks_per_jiffy);	set_tb(0, 0);	last_jiffy_stamp(cpu_nr) = 0;	if (cpu_nr > 0) {		mb();		sec_tb_reset = 1;		return;	}	/* wait for the secondary to have reset its TB before proceeding */	for (t = 10000000; t > 0 && !sec_tb_reset; --t)		;	/* now interrupt the secondary, starting both TBs */	psurge_set_ipi(1);	smp_tb_synchronized = 1;}static struct irqaction psurge_irqaction = {	.handler = psurge_primary_intr,	.flags = SA_INTERRUPT,	.mask = CPU_MASK_NONE,	.name = "primary IPI",};static void __init smp_psurge_setup_cpu(int cpu_nr){	if (cpu_nr == 0) {		/* If we failed to start the second CPU, we should still		 * send it an IPI to start the timebase & DEC or we might		 * have them stuck.		 */		if (num_online_cpus() < 2) {			if (psurge_type == PSURGE_DUAL)				psurge_set_ipi(1);			return;		}		/* reset the entry point so if we get another intr we won't		 * try to startup again */		out_be32(psurge_start, 0x100);		if (setup_irq(30, &psurge_irqaction))			printk(KERN_ERR "Couldn't get primary IPI interrupt");	}	if (psurge_type == PSURGE_DUAL)		psurge_dual_sync_tb(cpu_nr);}void __init smp_psurge_take_timebase(void){	/* Dummy implementation */}void __init smp_psurge_give_timebase(void){	/* Dummy implementation */}static int __init smp_core99_probe(void){#ifdef CONFIG_6xx	extern int powersave_nap;#endif	struct device_node *cpus, *firstcpu;	int i, ncpus = 0, boot_cpu = -1;	u32 *tbprop = NULL;	if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);	cpus = firstcpu = find_type_devices("cpu");	while(cpus != NULL) {		u32 *regprop = (u32 *)get_property(cpus, "reg", NULL);		char *stateprop = (char *)get_property(cpus, "state", NULL);		if (regprop != NULL && stateprop != NULL &&		    !strncmp(stateprop, "running", 7))			boot_cpu = *regprop;		++ncpus;		cpus = cpus->next;	}	if (boot_cpu == -1)		printk(KERN_WARNING "Couldn't detect boot CPU !\n");	if (boot_cpu != 0)		printk(KERN_WARNING "Boot CPU is %d, unsupported setup !\n", boot_cpu);	if (machine_is_compatible("MacRISC4")) {		extern struct smp_ops_t core99_smp_ops;		core99_smp_ops.take_timebase = smp_generic_take_timebase;		core99_smp_ops.give_timebase = smp_generic_give_timebase;	} else {		if (firstcpu != NULL)			tbprop = (u32 *)get_property(firstcpu, "timebase-enable", NULL);		if (tbprop)			core99_tb_gpio = *tbprop;		else			core99_tb_gpio = KL_GPIO_TB_ENABLE;	}	if (ncpus > 1) {		openpic_request_IPIs();		for (i = 1; i < ncpus; ++i)			smp_hw_index[i] = i;#ifdef CONFIG_6xx		powersave_nap = 0;#endif		core99_init_caches(0);	}	return ncpus;}static void __devinit smp_core99_kick_cpu(int nr){	unsigned long save_vector, new_vector;	unsigned long flags;	volatile unsigned long *vector		 = ((volatile unsigned long *)(KERNELBASE+0x100));	if (nr < 0 || nr > 3)		return;	if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);	local_irq_save(flags);	local_irq_disable();	/* Save reset vector */	save_vector = *vector;	/* Setup fake reset vector that does		 *   b __secondary_start_pmac_0 + nr*8 - KERNELBASE	 */	new_vector = (unsigned long) __secondary_start_pmac_0 + nr * 8;	*vector = 0x48000002 + new_vector - KERNELBASE;	/* flush data cache and inval instruction cache */	flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);	/* Put some life in our friend */	pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);	/* FIXME: We wait a bit for the CPU to take the exception, I should	 * instead wait for the entry code to set something for me. Well,	 * ideally, all that crap will be done in prom.c and the CPU left	 * in a RAM-based wait loop like CHRP.	 */	mdelay(1);	/* Restore our exception vector */	*vector = save_vector;	flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);	local_irq_restore(flags);	if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);}static void __devinit smp_core99_setup_cpu(int cpu_nr){	/* Setup L2/L3 */	if (cpu_nr != 0)		core99_init_caches(cpu_nr);	/* Setup openpic */	do_openpic_setup_cpu();	if (cpu_nr == 0) {#ifdef CONFIG_POWER4		extern void g5_phy_disable_cpu1(void);		/* If we didn't start the second CPU, we must take		 * it off the bus		 */		if (machine_is_compatible("MacRISC4") &&		    num_online_cpus() < 2)					g5_phy_disable_cpu1();#endif /* CONFIG_POWER4 */		if (ppc_md.progress) ppc_md.progress("core99_setup_cpu 0 done", 0x349);	}}/* not __init, called in sleep/wakeup code */void smp_core99_take_timebase(void){	unsigned long flags;	/* tell the primary we're here */	sec_tb_reset = 1;	mb();	/* wait for the primary to set pri_tb_hi/lo */	while (sec_tb_reset < 2)		mb();	/* set our stuff the same as the primary */	local_irq_save(flags);	set_dec(1);	set_tb(pri_tb_hi, pri_tb_lo);	last_jiffy_stamp(smp_processor_id()) = pri_tb_stamp;	mb();	/* tell the primary we're done */       	sec_tb_reset = 0;	mb();	local_irq_restore(flags);}/* not __init, called in sleep/wakeup code */void smp_core99_give_timebase(void){	unsigned long flags;	unsigned int t;	/* wait for the secondary to be in take_timebase */	for (t = 100000; t > 0 && !sec_tb_reset; --t)		udelay(10);	if (!sec_tb_reset) {		printk(KERN_WARNING "Timeout waiting sync on second CPU\n");		return;	}	/* freeze the timebase and read it */	/* disable interrupts so the timebase is disabled for the	   shortest possible time */	local_irq_save(flags);	pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4);	pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);	mb();	pri_tb_hi = get_tbu();	pri_tb_lo = get_tbl();	pri_tb_stamp = last_jiffy_stamp(smp_processor_id());	mb();	/* tell the secondary we're ready */	sec_tb_reset = 2;	mb();	/* wait for the secondary to have taken it */	for (t = 100000; t > 0 && sec_tb_reset; --t)		udelay(10);	if (sec_tb_reset)		printk(KERN_WARNING "Timeout waiting sync(2) on second CPU\n");	else		smp_tb_synchronized = 1;	/* Now, restart the timebase by leaving the GPIO to an open collector */       	pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0);        pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);	local_irq_restore(flags);}/* PowerSurge-style Macs */struct smp_ops_t psurge_smp_ops = {	.message_pass	= smp_psurge_message_pass,	.probe		= smp_psurge_probe,	.kick_cpu	= smp_psurge_kick_cpu,	.setup_cpu	= smp_psurge_setup_cpu,	.give_timebase	= smp_psurge_give_timebase,	.take_timebase	= smp_psurge_take_timebase,};/* Core99 Macs (dual G4s) */struct smp_ops_t core99_smp_ops = {	.message_pass	= smp_openpic_message_pass,	.probe		= smp_core99_probe,	.kick_cpu	= smp_core99_kick_cpu,	.setup_cpu	= smp_core99_setup_cpu,	.give_timebase	= smp_core99_give_timebase,	.take_timebase	= smp_core99_take_timebase,};#ifdef CONFIG_HOTPLUG_CPUint __cpu_disable(void){	cpu_clear(smp_processor_id(), cpu_online_map);	/* XXX reset cpu affinity here */	openpic_set_priority(0xf);	asm volatile("mtdec %0" : : "r" (0x7fffffff));	mb();	udelay(20);	asm volatile("mtdec %0" : : "r" (0x7fffffff));	return 0;}extern void low_cpu_die(void) __attribute__((noreturn)); /* in pmac_sleep.S */static int cpu_dead[NR_CPUS];void cpu_die(void){	local_irq_disable();	cpu_dead[smp_processor_id()] = 1;	mb();	low_cpu_die();}void __cpu_die(unsigned int cpu){	int timeout;	timeout = 1000;	while (!cpu_dead[cpu]) {		if (--timeout == 0) {			printk("CPU %u refused to die!\n", cpu);			break;		}		msleep(1);	}	cpu_callin_map[cpu] = 0;	cpu_dead[cpu] = 0;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -