- Removed unused HandleEvent method.
[AROS.git] / arch / m68k-all / exec / cachepredma_.S
blob34aac9a0ea077bc54a27c23111ead974e015a696
1 /*
2     Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3     $Id$
4 */
6 /*****************************************************************************
7  
8     NAME
9  
10         AROS_LH3(APTR, CachePreDMA,
12     SYNOPSIS
13         AROS_LHA(APTR,    address, A0),
14         AROS_LHA(ULONG *, length,  A1),
15         AROS_LHA(ULONG,   flags,  D0),
17     LOCATION
18         struct ExecBase *, SysBase, 127, Exec)
20     FUNCTION
21         Do everything necessary to make CPU caches aware that a DMA will happen.
22         Virtual memory systems will make it possible that your memory is not at
23         one block and not at the address you thought. This function gives you
24         all the information you need to split the DMA request up and to convert
25         virtual to physical addresses.
27     INPUTS
28         address - Virtual address of memory affected by the DMA
29         *length - Number of bytes affected
30         flags   - DMA_Continue    - This is a call to continue a request that
31                                     was broken up.
32                   DMA_ReadFromRAM - Indicate that the DMA goes from RAM
33                                     to the device. Set this bit in bot calls.
35     RESULT
36         The physical address in memory.
37         *length contains the number of contiguous bytes in physical memory.
39     NOTES
40         DMA must follow a call to CachePreDMA() and must be followed
41         by a call to CachePostDMA().
43     EXAMPLE
45     BUGS
47     SEE ALSO
48         CachePostDMA()
50     INTERNALS
52     HISTORY
54 ******************************************************************************/
57    XDEF AROS_SLIB_ENTRY(CachePreDMA,Exec,127)           ; for 68000/10/20/30
58    XDEF AROS_SLIB_ENTRY(CachePreDMA_40,Exec,127)        ; for 68040+
61         #include "aros/m68k/asm.h"
62         #include "cache.h"
64         #define DMAB_Continue       1  /* Continuation flag for CachePreDMA */
65         #define DMAB_NoModify       2  /* Set if DMA does not update memory */
66         #define DMAB_ReadFromRAM    3  /* Set if DMA goes *FROM* RAM to device */
68         .text
69         .balign 4
70         .globl  AROS_SLIB_ENTRY(CachePreDMA_00,Exec,127)
71         .type   AROS_SLIB_ENTRY(CachePreDMA_00,Exec,127),@function
72 AROS_SLIB_ENTRY(CachePreDMA_00,Exec,127):
74 #if CACHEDEBUG
75         bsr             cachedebug
76 #endif
78         move.l  %a0,%d0 /* return input address */
79         rts
81         .text
82         .balign 4
83         .globl  AROS_SLIB_ENTRY(CachePreDMA_40,Exec,127)
84         .type   AROS_SLIB_ENTRY(CachePreDMA_40,Exec,127),@function
85 AROS_SLIB_ENTRY(CachePreDMA_40,Exec,127):
87 #if CACHEDEBUG
88         bsr             cachedebug
89 #endif
91         movem.l %a0/%a3/%a5,-(%sp)
93         btst    #DMAB_Continue,%d0
94         bne.s   0f
95         btst    #DMAB_ReadFromRAM,%d0
96         bne.s   0f
98         move.l %a0,%d1
99         or.l %a1@,%d1
100         and.w #0x000f,%d1
101         beq.s 0f
102         /*
103          * Not cache line aligned.
104          *
105          * Details can be read here:
106          * http://groups.google.com/group/comp.sys.amiga.hardware/browse_thread/thread/6e5caefab6a68a1e/16f93d291b0b1440?hl=en&ie=UTF-8
107          *
108          * We assume MMU is already configured.
109          */
111         move.l %a6@(eb_KernelBase),%a3
112         move.l %a3@(kb_PlatformData),%a3
113         tst.l MMU_Level_A(%a3)
114         beq.s 0f
115         move.l %a1@,%d0
116         moveq #0,%d1
117         lea cacheprepostset,%a5
118         jsr Supervisor(%a6)
120 #if CACHEFULLFLUSH
121         jsr -0x27C(%a6) /* CacheClearU() */
122 #else
123         move.l #0x0800,%d1
124         move.l %a1@,%d0
125         jsr -0x282(%a6) /* CacheClearE() */
126 #endif
128         movem.l (%sp)+,%a0/%a3/%a5
129         move.l %a0,%d0
130         rts
132 .globl cacheprepostset
133         // a0 = address
134         // d0 = length
135         // d1 = copyback mode. on=1 off=0
136 cacheprepostset:
137         movem.l %a0/%a2,-(%sp)
138         or.w #0x0700,%sr
139         sub.l %a2,%a2
140         // start address
141         bsr copybackchange
142         add.l %d0,%a0
143         // end address
144         bsr copybackchange
145         movem.l (%sp)+,%a0/%a2
146         rte
148 copybackchange:
149         movem.l %d0-%d3/%a0-%a1,-(%sp)
150         move.l %d1,%d2
151         move.l %a0,%d0
152         and.w #0x000f,%d0
153         beq.s 1f // cache line aligned -> nothing to do
154         move.l %a0,%d0
155         and.w #~4095,%d0
156         cmp.l %a2,%d0
157         beq.s 1f // end == start
158         move.l %d0,%a2
159         move.l %a2,%a0
160         bsr getpagedesc
161 #if CACHEDEBUG
162         bsr cachedebug2
163 #endif
164         /* adjust page descriptor cache flags */
165         addq.l #3,%a0
166         move.b (%a0),%d0
167         btst #6,%d0
168         bne.s 1f // bit 6 set = noncacheable
169         bclr #5,%d0 // disable copyback
170         tst.b %d2
171         beq.s 2f
172         bset #5,%d0 // enable copyback
173 2:      pflusha
174         move.b %d0,(%a0)
175         cpushl %dc,(%a0)
176 1:      movem.l (%sp)+,%d0-%d3/%a0-%a1
177         rts
179         /* Fetch page descriptor address. No error checks. */
180 getpagedesc:
181         move.l MMU_Level_A(%a3),%a1
182         move.l %a0,%d1
183         bfextu %d1{0:7},%d0
184         move.l 0(%a1,%d0.w*4),%d0
185         clr.b %d0
186         move.l %d0,%a1
187         bfextu %d1{7:7},%d0
188         move.l 0(%a1,%d0.w*4),%d0
189         clr.b %d0
190         move.l %d0,%a1
191         bfextu %d1{14:6},%d0
192         lea 0(%a1,%d0.w*4),%a0
193         rts
195 #if CACHEDEBUG
196 cachedebug:
197         movem.l %d0-%d1/%a0-%a1,-(%sp)
198         move.l %d0,-(%sp)
199         move.l (%a1),-(%sp)
200         move.l %a0,-(%sp)
201         pea format
202         jsr kprintf
203         lea 16(%sp),%sp
204         movem.l (%sp)+,%d0-%d1/%a0-%a1
205         rts
207 cachedebug2:
208         movem.l %d0-%d1/%a0-%a1,-(%sp)
209         move.l %d2,-(%sp)
210         move.l (%a0),-(%sp)
211         move.l %a0,-(%sp)
212         move.l %a2,-(%sp)
213         pea format2
214         jsr kprintf
215         lea 20(%sp),%sp
216         movem.l (%sp)+,%d0-%d1/%a0-%a1
217         rts
219 format:
220         .string "PreDMA(%p,%x,%x)\n"
221 format2:
222         .string "CB(%08x,%08x[%08x],%d)\n"
224 #endif