mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 01:34:12 +00:00
MMU: add cache operations by set/way
this embeds a slightly modified file taken from arm-trusted-firmware. Signed-off-by: Sven Peter <sven@svenpeter.dev>
This commit is contained in:
parent
f244919c98
commit
2f84b33ba8
5 changed files with 204 additions and 1 deletions
26
3rdparty_licenses/LICENSE.BSD-3.arm
Normal file
26
3rdparty_licenses/LICENSE.BSD-3.arm
Normal file
|
@ -0,0 +1,26 @@
|
|||
Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Arm nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2
Makefile
2
Makefile
|
@ -17,7 +17,7 @@ TINF_OBJECTS := $(patsubst %,tinf/%, \
|
|||
adler32.o crc32.o tinfgzip.o tinflate.o tinfzlib.o)
|
||||
|
||||
OBJECTS := adt.o bootlogo_128.o bootlogo_256.o chickens.o exception.o exception_asm.o fb.o \
|
||||
main.o memory.o proxy.o smp.o start.o startup.o string.o uart.o uartproxy.o utils.o \
|
||||
main.o memory.o memory_asm.o proxy.o smp.o start.o startup.o string.o uart.o uartproxy.o utils.o \
|
||||
utils_asm.o vsprintf.o $(MINILZLIB_OBJECTS) $(TINF_OBJECTS)
|
||||
|
||||
DTS := apple-j274.dts
|
||||
|
|
|
@ -32,3 +32,9 @@ m1n1 embeds a slightly modified version of [tinf](https://github.com/jibsen/tinf
|
|||
[ZLIB](3rdparty_licenses/LICENSE.tinf) licensed and copyright:
|
||||
|
||||
* Copyright (c) 2003-2019 Joergen Ibsen
|
||||
|
||||
m1n1 embeds portions taken from
|
||||
[arm-trusted-firwmare](https://github.com/ARM-software/arm-trusted-firmware), which is
|
||||
[BSD](3rdparty_licenses/LICENSE.BSD-3.arm) licensed and copyright:
|
||||
|
||||
* Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
|
||||
|
|
|
@ -12,6 +12,11 @@ void dc_cvac_range(void *addr, size_t length);
|
|||
void dc_cvau_range(void *addr, size_t length);
|
||||
void dc_civac_range(void *addr, size_t length);
|
||||
|
||||
#define DCSW_OP_DCISW 0x0
|
||||
#define DCSW_OP_DCCISW 0x1
|
||||
#define DCSW_OP_DCCSW 0x2
|
||||
void dcsw_op_all(u64 op_type);
|
||||
|
||||
void mmu_init(void);
|
||||
void mmu_shutdown(void);
|
||||
#endif
|
||||
|
|
166
src/memory_asm.S
Normal file
166
src/memory_asm.S
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LOC_SHIFT 24
|
||||
#define CLIDR_FIELD_WIDTH 3
|
||||
#define LEVEL_SHIFT 1
|
||||
|
||||
.macro func, name
|
||||
.globl \name
|
||||
.type \name, @function
|
||||
\name:
|
||||
.endm
|
||||
|
||||
.globl dcsw_op_all
|
||||
|
||||
/*
|
||||
* This macro can be used for implementing various data cache operations `op`
|
||||
*/
|
||||
.macro do_dcache_maintenance_by_mva op
|
||||
/* Exit early if size is zero */
|
||||
cbz x1, exit_loop_\op
|
||||
dcache_line_size x2, x3
|
||||
add x1, x0, x1
|
||||
sub x3, x2, #1
|
||||
bic x0, x0, x3
|
||||
loop_\op:
|
||||
dc \op, x0
|
||||
add x0, x0, x2
|
||||
cmp x0, x1
|
||||
b.lo loop_\op
|
||||
dsb sy
|
||||
exit_loop_\op:
|
||||
ret
|
||||
.endm
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Data cache operations by set/way to the level specified
|
||||
*
|
||||
* The main function, do_dcsw_op requires:
|
||||
* x0: The operation type (0-2), as defined in arch.h
|
||||
* x3: The last cache level to operate on
|
||||
* x9: clidr_el1
|
||||
* x10: The cache level to begin operation from
|
||||
* and will carry out the operation on each data cache from level 0
|
||||
* to the level in x3 in sequence
|
||||
*
|
||||
* The dcsw_op macro sets up the x3 and x9 parameters based on
|
||||
* clidr_el1 cache information before invoking the main function
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
.macro dcsw_op shift, fw, ls
|
||||
mrs x9, clidr_el1
|
||||
ubfx x3, x9, \shift, \fw
|
||||
lsl x3, x3, \ls
|
||||
mov x10, xzr
|
||||
b do_dcsw_op
|
||||
.endm
|
||||
|
||||
func do_dcsw_op
|
||||
cbz x3, exit
|
||||
adr x14, dcsw_loop_table // compute inner loop address
|
||||
add x14, x14, x0, lsl #5 // inner loop is 8x32-bit instructions
|
||||
mov x0, x9
|
||||
mov w8, #1
|
||||
loop1:
|
||||
add x2, x10, x10, lsr #1 // work out 3x current cache level
|
||||
lsr x1, x0, x2 // extract cache type bits from clidr
|
||||
and x1, x1, #7 // mask the bits for current cache only
|
||||
cmp x1, #2 // see what cache we have at this level
|
||||
b.lo level_done // nothing to do if no cache or icache
|
||||
|
||||
msr csselr_el1, x10 // select current cache level in csselr
|
||||
isb // isb to sych the new cssr&csidr
|
||||
mrs x1, ccsidr_el1 // read the new ccsidr
|
||||
and x2, x1, #7 // extract the length of the cache lines
|
||||
add x2, x2, #4 // add 4 (line length offset)
|
||||
ubfx x4, x1, #3, #10 // maximum way number
|
||||
clz w5, w4 // bit position of way size increment
|
||||
lsl w9, w4, w5 // w9 = aligned max way number
|
||||
lsl w16, w8, w5 // w16 = way number loop decrement
|
||||
orr w9, w10, w9 // w9 = combine way and cache number
|
||||
ubfx w6, w1, #13, #15 // w6 = max set number
|
||||
lsl w17, w8, w2 // w17 = set number loop decrement
|
||||
dsb sy // barrier before we start this level
|
||||
br x14 // jump to DC operation specific loop
|
||||
|
||||
.macro dcsw_loop _op
|
||||
loop2_\_op:
|
||||
lsl w7, w6, w2 // w7 = aligned max set number
|
||||
|
||||
loop3_\_op:
|
||||
orr w11, w9, w7 // combine cache, way and set number
|
||||
dc \_op, x11
|
||||
subs w7, w7, w17 // decrement set number
|
||||
b.hs loop3_\_op
|
||||
|
||||
subs x9, x9, x16 // decrement way number
|
||||
b.hs loop2_\_op
|
||||
|
||||
b level_done
|
||||
.endm
|
||||
|
||||
level_done:
|
||||
add x10, x10, #2 // increment cache number
|
||||
cmp x3, x10
|
||||
b.hi loop1
|
||||
msr csselr_el1, xzr // select cache level 0 in csselr
|
||||
dsb sy // barrier to complete final cache operation
|
||||
isb
|
||||
exit:
|
||||
ret
|
||||
|
||||
dcsw_loop_table:
|
||||
dcsw_loop isw
|
||||
dcsw_loop cisw
|
||||
dcsw_loop csw
|
||||
|
||||
|
||||
func dcsw_op_all
|
||||
dcsw_op #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Helper macro for data cache operations by set/way for the
|
||||
* level specified
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
.macro dcsw_op_level level
|
||||
mrs x9, clidr_el1
|
||||
mov x3, \level
|
||||
sub x10, x3, #2
|
||||
b do_dcsw_op
|
||||
.endm
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Data cache operations by set/way for level 1 cache
|
||||
*
|
||||
* The main function, do_dcsw_op requires:
|
||||
* x0: The operation type (0-2), as defined in arch.h
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
func dcsw_op_level1
|
||||
dcsw_op_level #(1 << LEVEL_SHIFT)
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Data cache operations by set/way for level 2 cache
|
||||
*
|
||||
* The main function, do_dcsw_op requires:
|
||||
* x0: The operation type (0-2), as defined in arch.h
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
func dcsw_op_level2
|
||||
dcsw_op_level #(2 << LEVEL_SHIFT)
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Data cache operations by set/way for level 3 cache
|
||||
*
|
||||
* The main function, do_dcsw_op requires:
|
||||
* x0: The operation type (0-2), as defined in arch.h
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
func dcsw_op_level3
|
||||
dcsw_op_level #(3 << LEVEL_SHIFT)
|
Loading…
Reference in a new issue