Home | History | Annotate | Line # | Download | only in bootaa64
cache.S revision 1.1.2.2
      1  1.1.2.2  pgoyette /*	$NetBSD: cache.S,v 1.1.2.2 2018/09/06 06:56:47 pgoyette Exp $	*/
      2  1.1.2.2  pgoyette 
      3  1.1.2.2  pgoyette /*-
      4  1.1.2.2  pgoyette  * Copyright (c) 2014 Robin Randhawa
      5  1.1.2.2  pgoyette  * Copyright (c) 2015 The FreeBSD Foundation
      6  1.1.2.2  pgoyette  * All rights reserved.
      7  1.1.2.2  pgoyette  *
      8  1.1.2.2  pgoyette  * Portions of this software were developed by Andrew Turner
      9  1.1.2.2  pgoyette  * under sponsorship from the FreeBSD Foundation
     10  1.1.2.2  pgoyette  *
     11  1.1.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
     12  1.1.2.2  pgoyette  * modification, are permitted provided that the following conditions
     13  1.1.2.2  pgoyette  * are met:
     14  1.1.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     15  1.1.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     16  1.1.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     18  1.1.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     19  1.1.2.2  pgoyette  *
     20  1.1.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21  1.1.2.2  pgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.1.2.2  pgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.1.2.2  pgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     24  1.1.2.2  pgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  1.1.2.2  pgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  1.1.2.2  pgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.1.2.2  pgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.1.2.2  pgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.1.2.2  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.1.2.2  pgoyette  * SUCH DAMAGE.
     31  1.1.2.2  pgoyette  *
     32  1.1.2.2  pgoyette  * $FreeBSD: head/sys/arm64/arm64/cpufunc_asm.S 313347 2017-02-06 17:50:09Z andrew $
     33  1.1.2.2  pgoyette  */
     34  1.1.2.2  pgoyette 
     35  1.1.2.2  pgoyette #include <aarch64/asm.h>
     36  1.1.2.2  pgoyette 
     37  1.1.2.2  pgoyette 	.text
     38  1.1.2.2  pgoyette 	.align	2
     39  1.1.2.2  pgoyette 
     40  1.1.2.2  pgoyette /*
     41  1.1.2.2  pgoyette  * Macro to handle the cache. This takes the start address in x0, length
     42  1.1.2.2  pgoyette  * in x1. It will corrupt x0, x1, x2, and x3.
     43  1.1.2.2  pgoyette  */
     44  1.1.2.2  pgoyette .macro cache_handle_range dcop = 0, ic = 0, icop = 0
     45  1.1.2.2  pgoyette .if \ic == 0
     46  1.1.2.2  pgoyette 	mrs	x3, ctr_el0
     47  1.1.2.2  pgoyette 	ubfx	x3, x3, #16, #4		/* x3 = D cache shift */
     48  1.1.2.2  pgoyette 	mov	x2, #4			/* size of word */
     49  1.1.2.2  pgoyette 	lsl	x3, x2, x3		/* x3 = D cache line size */
     50  1.1.2.2  pgoyette .else
     51  1.1.2.2  pgoyette 	mrs	x3, ctr_el0
     52  1.1.2.2  pgoyette 	ubfx	x2, x3, #16, #4		/* x2 = D cache shift */
     53  1.1.2.2  pgoyette 	and	x3, x3, #15		/* x3 = I cache shift */
     54  1.1.2.2  pgoyette 	cmp	x3, x2
     55  1.1.2.2  pgoyette 	bcs	1f
     56  1.1.2.2  pgoyette 	mov	x3, x2
     57  1.1.2.2  pgoyette 1:					/* x3 = MAX(IcacheShift,DcacheShift) */
     58  1.1.2.2  pgoyette 	mov	x2, #4			/* size of word */
     59  1.1.2.2  pgoyette 	lsl	x3, x2, x3		/* x3 = cache line size */
     60  1.1.2.2  pgoyette .endif
     61  1.1.2.2  pgoyette 	sub	x4, x3, #1		/* Get the address mask */
     62  1.1.2.2  pgoyette 	and	x2, x0, x4		/* Get the low bits of the address */
     63  1.1.2.2  pgoyette 	add	x1, x1, x2		/* Add these to the size */
     64  1.1.2.2  pgoyette 	bic	x0, x0, x4		/* Clear the low bit of the address */
     65  1.1.2.2  pgoyette 1:
     66  1.1.2.2  pgoyette 	dc	\dcop, x0
     67  1.1.2.2  pgoyette 	dsb	ish
     68  1.1.2.2  pgoyette .if \ic != 0
     69  1.1.2.2  pgoyette 	ic	\icop, x0
     70  1.1.2.2  pgoyette 	dsb	ish
     71  1.1.2.2  pgoyette .endif
     72  1.1.2.2  pgoyette 	add	x0, x0, x3		/* Move to the next line */
     73  1.1.2.2  pgoyette 	subs	x1, x1, x3		/* Reduce the size */
     74  1.1.2.2  pgoyette 	b.hi	1b			/* Check if we are done */
     75  1.1.2.2  pgoyette .if \ic != 0
     76  1.1.2.2  pgoyette 	isb
     77  1.1.2.2  pgoyette .endif
     78  1.1.2.2  pgoyette 	ret
     79  1.1.2.2  pgoyette .endm
     80  1.1.2.2  pgoyette 
     81  1.1.2.2  pgoyette 
     82  1.1.2.2  pgoyette /*
     83  1.1.2.2  pgoyette  * void aarch64_dcache_wbinv_range(vaddr_t, vsize_t)
     84  1.1.2.2  pgoyette  */
     85  1.1.2.2  pgoyette ENTRY(aarch64_dcache_wbinv_range)
     86  1.1.2.2  pgoyette 	cache_handle_range	dcop = civac
     87  1.1.2.2  pgoyette END(aarch64_dcache_wbinv_range)
     88  1.1.2.2  pgoyette 
     89  1.1.2.2  pgoyette /*
     90  1.1.2.2  pgoyette  * void aarch64_icache_inv_all(void)
     91  1.1.2.2  pgoyette  */
     92  1.1.2.2  pgoyette ENTRY(aarch64_icache_inv_all)
     93  1.1.2.2  pgoyette 	dsb	ish
     94  1.1.2.2  pgoyette 	ic	ialluis
     95  1.1.2.2  pgoyette 	dsb	ish
     96  1.1.2.2  pgoyette 	isb
     97  1.1.2.2  pgoyette 	ret
     98  1.1.2.2  pgoyette END(aarch64_icache_inv_all)
     99