xref: /rk3399_rockchip-uboot/arch/powerpc/lib/ppccache.S (revision 98f705c9cefdfdba62c069821bbba10273a0a8ed)
1a47a12beSStefan Roese/*
2a47a12beSStefan Roese * Copyright (C) 1998  Dan Malek <dmalek@jlc.net>
3a47a12beSStefan Roese * Copyright (C) 1999  Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4a47a12beSStefan Roese * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de>
5a47a12beSStefan Roese * Copyright Freescale Semiconductor, Inc. 2004, 2006.
6a47a12beSStefan Roese *
71a459660SWolfgang Denk * SPDX-License-Identifier:	GPL-2.0+
8a47a12beSStefan Roese */
9a47a12beSStefan Roese
10a47a12beSStefan Roese#include <config.h>
11a47a12beSStefan Roese#include <ppc_asm.tmpl>
12ac337168SValentin Longchamp#include <ppc_defs.h>
13ac337168SValentin Longchamp
14ac337168SValentin Longchamp#include <asm/cache.h>
15a47a12beSStefan Roese
16a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
17a47a12beSStefan Roese/* Function:	 ppcDcbf */
18a47a12beSStefan Roese/* Description:	 Data Cache block flush */
19a47a12beSStefan Roese/* Input:	 r3 = effective address */
20a47a12beSStefan Roese/* Output:	 none. */
21a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
22a47a12beSStefan Roese	.globl	ppcDcbf
23a47a12beSStefan RoeseppcDcbf:
24a47a12beSStefan Roese	dcbf	r0,r3
25a47a12beSStefan Roese	blr
26a47a12beSStefan Roese
27a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
28a47a12beSStefan Roese/* Function:	 ppcDcbi */
29a47a12beSStefan Roese/* Description:	 Data Cache block Invalidate */
30a47a12beSStefan Roese/* Input:	 r3 = effective address */
31a47a12beSStefan Roese/* Output:	 none. */
32a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
33a47a12beSStefan Roese	.globl	ppcDcbi
34a47a12beSStefan RoeseppcDcbi:
35a47a12beSStefan Roese	dcbi	r0,r3
36a47a12beSStefan Roese	blr
37a47a12beSStefan Roese
38a47a12beSStefan Roese/*--------------------------------------------------------------------------
39a47a12beSStefan Roese * Function:	 ppcDcbz
40a47a12beSStefan Roese * Description:	 Data Cache block zero.
41a47a12beSStefan Roese * Input:	 r3 = effective address
42a47a12beSStefan Roese * Output:	 none.
43a47a12beSStefan Roese *-------------------------------------------------------------------------- */
44a47a12beSStefan Roese
45a47a12beSStefan Roese	.globl	ppcDcbz
46a47a12beSStefan RoeseppcDcbz:
47a47a12beSStefan Roese	dcbz	r0,r3
48a47a12beSStefan Roese	blr
49a47a12beSStefan Roese
50a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
51a47a12beSStefan Roese/* Function:	 ppcSync */
52a47a12beSStefan Roese/* Description:	 Processor Synchronize */
53a47a12beSStefan Roese/* Input:	 none. */
54a47a12beSStefan Roese/* Output:	 none. */
55a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
56a47a12beSStefan Roese	.globl	ppcSync
57a47a12beSStefan RoeseppcSync:
58a47a12beSStefan Roese	sync
59a47a12beSStefan Roese	blr
60ac337168SValentin Longchamp
61ac337168SValentin Longchamp/*
62ac337168SValentin Longchamp * Write any modified data cache blocks out to memory and invalidate them.
63ac337168SValentin Longchamp * Does not invalidate the corresponding instruction cache blocks.
64ac337168SValentin Longchamp *
65ac337168SValentin Longchamp * flush_dcache_range(unsigned long start, unsigned long stop)
66ac337168SValentin Longchamp */
67ac337168SValentin Longchamp_GLOBAL(flush_dcache_range)
68*98f705c9SHeiko Schocher#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
69ac337168SValentin Longchamp	li	r5,L1_CACHE_BYTES-1
70ac337168SValentin Longchamp	andc	r3,r3,r5
71ac337168SValentin Longchamp	subf	r4,r3,r4
72ac337168SValentin Longchamp	add	r4,r4,r5
73ac337168SValentin Longchamp	srwi.	r4,r4,L1_CACHE_SHIFT
74ac337168SValentin Longchamp	beqlr
75ac337168SValentin Longchamp	mtctr	r4
76ac337168SValentin Longchamp
77ac337168SValentin Longchamp1:	dcbf	0,r3
78ac337168SValentin Longchamp	addi	r3,r3,L1_CACHE_BYTES
79ac337168SValentin Longchamp	bdnz	1b
80ac337168SValentin Longchamp	sync				/* wait for dcbst's to get to ram */
81cb1629f9SYork Sun#endif
82ac337168SValentin Longchamp	blr
83ac337168SValentin Longchamp
84ac337168SValentin Longchamp/*
85ac337168SValentin Longchamp * Like above, but invalidate the D-cache.  This is used by the 8xx
86ac337168SValentin Longchamp * to invalidate the cache so the PPC core doesn't get stale data
87ac337168SValentin Longchamp * from the CPM (no cache snooping here :-).
88ac337168SValentin Longchamp *
89ac337168SValentin Longchamp * invalidate_dcache_range(unsigned long start, unsigned long stop)
90ac337168SValentin Longchamp */
91ac337168SValentin Longchamp_GLOBAL(invalidate_dcache_range)
92*98f705c9SHeiko Schocher#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
93ac337168SValentin Longchamp	li	r5,L1_CACHE_BYTES-1
94ac337168SValentin Longchamp	andc	r3,r3,r5
95ac337168SValentin Longchamp	subf	r4,r3,r4
96ac337168SValentin Longchamp	add	r4,r4,r5
97ac337168SValentin Longchamp	srwi.	r4,r4,L1_CACHE_SHIFT
98ac337168SValentin Longchamp	beqlr
99ac337168SValentin Longchamp	mtctr	r4
100ac337168SValentin Longchamp
101ac337168SValentin Longchamp	sync
102ac337168SValentin Longchamp1:	dcbi	0,r3
103ac337168SValentin Longchamp	addi	r3,r3,L1_CACHE_BYTES
104ac337168SValentin Longchamp	bdnz	1b
105ac337168SValentin Longchamp	sync				/* wait for dcbi's to get to ram */
106cb1629f9SYork Sun#endif
107ac337168SValentin Longchamp	blr
108ac337168SValentin Longchamp
109