summaryrefslogtreecommitdiff
path: root/release/src/linux/linux/include/asm-cris/smp_lock.h
blob: 9370c91e13151efcefa8f19cb66e46b988e6c691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __CRIS_SMPLOCK_H
#define __CRIS_SMPLOCK_H

#include <linux/config.h>

#ifdef CONFIG_SMP

#error "SMP is not supported for CRIS"

/*
 *	Locking the kernel 
 */
 
extern __inline void lock_kernel(void)
{
	unsigned long flags;
	int proc = smp_processor_id();

	save_flags(flags);
	cli();
	/* set_bit works atomic in SMP machines */
	while(set_bit(0, (void *)&kernel_flag)) 
	{
		/*
		 *	We just start another level if we have the lock 
		 */
		if (proc == active_kernel_processor)
			break;
		do 
		{
#ifdef __SMP_PROF__		
			smp_spins[smp_processor_id()]++;
#endif			
			/*
			 *	Doing test_bit here doesn't lock the bus 
			 */
			if (test_bit(proc, (void *)&smp_invalidate_needed))
				if (clear_bit(proc, (void *)&smp_invalidate_needed))
					local_flush_tlb();
		}
		while(test_bit(0, (void *)&kernel_flag));
	}
	/* 
	 *	We got the lock, so tell the world we are here and increment
	 *	the level counter 
	 */
	active_kernel_processor = proc;
	kernel_counter++;
	restore_flags(flags);
}

extern __inline void unlock_kernel(void)
{
	unsigned long flags;
	save_flags(flags);
	cli();
	/*
	 *	If it's the last level we have in the kernel, then
	 *	free the lock 
	 */
	if (kernel_counter == 0)
		panic("Kernel counter wrong.\n"); 
	
	if(! --kernel_counter) 
	{
		active_kernel_processor = NO_PROC_ID;
		clear_bit(0, (void *)&kernel_flag);
	}
	restore_flags(flags);
}

#endif
#endif