Welcome to Euroland
[AROS.git] / arch / m68k-all / exec / cachepostdma_.S
blobe3ad43068a0ab90499535bc4529e8b935e1d83d9
1 /*
2     Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3     $Id$
4 */
6 /******************************************************************************
7  
8     NAME
9  
10         AROS_LH3(void, CachePostDMA,
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, 128, Exec)
20     FUNCTION
21         Do everything necessary to make CPU caches aware that a DMA has
22         happened.
24     INPUTS
25         address - Virtual address of memory affected by the DMA
26         *length - Number of bytes affected
27         flags   - DMA_NoModify    - Indicate that the memory did not change.
28                   DMA_ReadFromRAM - Indicate that the DMA goes from RAM
29                                     to the device. Set this bit in bot calls.
31     RESULT
33     NOTES
34         DMA must follow a call to CachePreDMA() and must be followed
35         by a call to CachePostDMA().
37     EXAMPLE
39     BUGS
41     SEE ALSO
42         CachePreDMA()
44     INTERNALS
46     HISTORY
48 ******************************************************************************/
51    XDEF AROS_SLIB_ENTRY(CachePostDMA_00,Exec,128)       ; for 68000/10/20
52    XDEF AROS_SLIB_ENTRY(CachePostDMA_30,Exec,128)       ; for 68030+
53    XDEF AROS_SLIB_ENTRY(CachePostDMA_40,Exec,128)       ; for 68040/68060
56         #include "aros/m68k/asm.h"
57         #include "cache.h"
59         #define DMAB_Continue       1  /* Continuation flag for CachePreDMA */
60         #define DMAB_NoModify       2  /* Set if DMA does not update memory */
61         #define DMAB_ReadFromRAM    3  /* Set if DMA goes *FROM* RAM to device */
63         .text
64         .balign 4
65         .globl  AROS_SLIB_ENTRY(CachePostDMA_00,Exec,128)
66         .type   AROS_SLIB_ENTRY(CachePostDMA_00,Exec,128),@function
67 AROS_SLIB_ENTRY(CachePostDMA_00,Exec,128):
69 #if CACHEDEBUG
70         bsr             cachedebug
71 #endif
73         rts
75         .text
76         .balign 4
77         .globl  AROS_SLIB_ENTRY(CachePostDMA_30,Exec,128)
78         .type   AROS_SLIB_ENTRY(CachePostDMA_30,Exec,128),@function
79 AROS_SLIB_ENTRY(CachePostDMA_30,Exec,128):
81 #if CACHEDEBUG
82         bsr             cachedebug
83 #endif
85         btst.l  #DMAB_NoModify,%d0      /* Has DMA modified data in mem? */
86         bne.s   cpd_30_end              /* nope, just exit */
87         move.l  %a5,%a1
88         lea.l   cachepostdmasup_30,%a5
89         jsr     Supervisor(%a6)
90 cpd_30_end:
91         rts
93 cachepostdmasup_30:
94         move.l  %a1,%a5
95         /* A DMA device has changed data in main memory. We have to clear
96            the data cache, so we get the chance to see this new data. */
97         or.w    #0x0700,%sr     /* Disable interrupts */
98         movec   %cacr,%d0
99         bset.l  #11,%d0         /* Set CD Clear Data cache bit */
100         movec   %d0,%cacr
101         rte
103         .text
104         .balign 4
105         .globl  AROS_SLIB_ENTRY(CachePostDMA_40,Exec,128)
106         .type   AROS_SLIB_ENTRY(CachePostDMA_40,Exec,128),@function
107 AROS_SLIB_ENTRY(CachePostDMA_40,Exec,128):
109 #if CACHEDEBUG
110         bsr             cachedebug
111 #endif
113         movem.l %a3/%a5,-(%sp)
115         btst    #DMAB_ReadFromRAM,%d0
116         bne.s   0f
118         move.l %a0,%d1
119         or.l %a1@,%d1
120         and.w #0x000f,%d1
121         beq.s 0f
122         /* Not cache line aligned.
123          * Check CachePreDMA for details. */
124         move.l %a6@(eb_KernelBase),%a3
125         move.l %a3@(kb_PlatformData),%a3
126         tst.l MMU_Level_A(%a3)
127         beq.s 0f
128         move.l %a1@,%d0
129         moveq #1,%d1
130         lea cacheprepostset,%a5
131         jsr Supervisor(%a6)
133 #if CACHEFULLFLUSH
134         jsr -0x27C(%a6) /* CacheClearU() */
135 #else
136         move.l #0x0800,%d1
137         move.l %a1@,%d0
138         jsr -0x282(%a6) /* CacheClearE() */
139 #endif
141         movem.l (%sp)+,%a3/%a5
142         rts
145 #if CACHEDEBUG
146 cachedebug:
147         movem.l %d0-%d1/%a0-%a1,-(%sp)
148         move.l %d0,-(%sp)
149         move.l (%a1),-(%sp)
150         move.l %a0,-(%sp)
151         pea format
152         jsr kprintf
153         lea 16(%sp),%sp
154         movem.l (%sp)+,%d0-%d1/%a0-%a1
155         rts
156 format:
157         .string "PostDMA(%p,%x,%x)\n"
158 #endif