Merge ../linus
[pandora-kernel.git] / arch / um / sys-ppc / misc.S
1 /*
2  * This file contains miscellaneous low-level functions.
3  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4  *
5  * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
6  * and Paul Mackerras.
7  *
8  * A couple of functions stolen from arch/ppc/kernel/misc.S for UML
9  * by Chris Emerson.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version
14  * 2 of the License, or (at your option) any later version.
15  *
16  */
17
18 #include <linux/config.h>
19 #include <asm/processor.h>
20 #include "ppc_asm.h"
21
22 #if defined(CONFIG_4xx) || defined(CONFIG_8xx)
23 #define CACHE_LINE_SIZE         16
24 #define LG_CACHE_LINE_SIZE      4
25 #define MAX_COPY_PREFETCH       1
26 #else
27 #define CACHE_LINE_SIZE         32
28 #define LG_CACHE_LINE_SIZE      5
29 #define MAX_COPY_PREFETCH       4
30 #endif /* CONFIG_4xx || CONFIG_8xx */
31
32         .text
33
34 /*
35  * Clear a page using the dcbz instruction, which doesn't cause any
36  * memory traffic (except to write out any cache lines which get
37  * displaced).  This only works on cacheable memory.
38  */
39 _GLOBAL(clear_page)
40         li      r0,4096/CACHE_LINE_SIZE
41         mtctr   r0
42 #ifdef CONFIG_8xx
43         li      r4, 0
44 1:      stw     r4, 0(r3)
45         stw     r4, 4(r3)
46         stw     r4, 8(r3)
47         stw     r4, 12(r3)
48 #else
49 1:      dcbz    0,r3
50 #endif
51         addi    r3,r3,CACHE_LINE_SIZE
52         bdnz    1b
53         blr
54
55 /*
56  * Copy a whole page.  We use the dcbz instruction on the destination
57  * to reduce memory traffic (it eliminates the unnecessary reads of
58  * the destination into cache).  This requires that the destination
59  * is cacheable.
60  */
61 #define COPY_16_BYTES           \
62         lwz     r6,4(r4);       \
63         lwz     r7,8(r4);       \
64         lwz     r8,12(r4);      \
65         lwzu    r9,16(r4);      \
66         stw     r6,4(r3);       \
67         stw     r7,8(r3);       \
68         stw     r8,12(r3);      \
69         stwu    r9,16(r3)
70
71 _GLOBAL(copy_page)
72         addi    r3,r3,-4
73         addi    r4,r4,-4
74         li      r5,4
75
76 #ifndef CONFIG_8xx
77 #if MAX_COPY_PREFETCH > 1
78         li      r0,MAX_COPY_PREFETCH
79         li      r11,4
80         mtctr   r0
81 11:     dcbt    r11,r4
82         addi    r11,r11,CACHE_LINE_SIZE
83         bdnz    11b
84 #else /* MAX_COPY_PREFETCH == 1 */
85         dcbt    r5,r4
86         li      r11,CACHE_LINE_SIZE+4
87 #endif /* MAX_COPY_PREFETCH */
88 #endif /* CONFIG_8xx */
89
90         li      r0,4096/CACHE_LINE_SIZE
91         mtctr   r0
92 1:
93 #ifndef CONFIG_8xx
94         dcbt    r11,r4
95         dcbz    r5,r3
96 #endif
97         COPY_16_BYTES
98 #if CACHE_LINE_SIZE >= 32
99         COPY_16_BYTES
100 #if CACHE_LINE_SIZE >= 64
101         COPY_16_BYTES
102         COPY_16_BYTES
103 #if CACHE_LINE_SIZE >= 128
104         COPY_16_BYTES
105         COPY_16_BYTES
106         COPY_16_BYTES
107         COPY_16_BYTES
108 #endif
109 #endif
110 #endif
111         bdnz    1b
112         blr