11.2Sskrll/* $NetBSD: sunxi_mc_mpstart.S,v 1.2 2019/02/06 13:15:59 skrll Exp $ */
21.1Sjmcneill
31.1Sjmcneill/*-
41.1Sjmcneill * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
51.1Sjmcneill * All rights reserved.
61.1Sjmcneill *
71.1Sjmcneill * Redistribution and use in source and binary forms, with or without
81.1Sjmcneill * modification, are permitted provided that the following conditions
91.1Sjmcneill * are met:
101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright
111.1Sjmcneill *    notice, this list of conditions and the following disclaimer.
121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
131.1Sjmcneill *    notice, this list of conditions and the following disclaimer in the
141.1Sjmcneill *    documentation and/or other materials provided with the distribution.
151.1Sjmcneill *
161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261.1Sjmcneill * SUCH DAMAGE.
271.1Sjmcneill */
281.1Sjmcneill
291.1Sjmcneill#include <sys/cdefs.h>
301.1Sjmcneill
311.1Sjmcneill#include <arm/asm.h>
321.1Sjmcneill#include <arm/armreg.h>
331.1Sjmcneill#include "assym.h"
341.1Sjmcneill
351.1Sjmcneill#define	CCI_SNOOP_CTRL		0x000
361.1Sjmcneill#define	 CCI_SNOOP_CTRL_DVM	__BIT(1)
371.1Sjmcneill#define	 CCI_SNOOP_CTRL_SNOOP	__BIT(0)
381.1Sjmcneill
391.1Sjmcneill	R_TMP1		.req r8
401.1Sjmcneill	R_VTOPDIFF	.req r10
411.1Sjmcneill
421.1Sjmcneill	.global _C_LABEL(sunxi_mc_mpstart)
431.1Sjmcneill_C_LABEL(sunxi_mc_mpstart):
441.1Sjmcneill
451.2Sskrll	adr     R_TMP1, sunxi_mc_mpstart
461.1Sjmcneill	ldr     R_VTOPDIFF, =sunxi_mc_mpstart
471.1Sjmcneill	sub     R_VTOPDIFF, R_VTOPDIFF, R_TMP1
481.1Sjmcneill
491.1Sjmcneill	mrc	p15, 0, r4, c0, c0, 5		// MPIDR get
501.1Sjmcneill	and	r4, #(MPIDR_AFF2|MPIDR_AFF1|MPIDR_AFF0)
511.1Sjmcneill
521.1Sjmcneill	mov	r0, #0
531.1Sjmcneill	ldr	r1, =cpu_mpidr
541.1Sjmcneill	sub	r1, R_VTOPDIFF
551.1Sjmcneill1:
561.1Sjmcneill
571.1Sjmcneill	ldr	r2, [r1, r0, lsl #2]		// r2 = cpu_mpidr[r0]
581.1Sjmcneill	cmp	r2, r4
591.1Sjmcneill	beq	2f				// found our mpidr
601.1Sjmcneill
611.1Sjmcneill	add	r0, #1
621.1Sjmcneill	cmp	r0, #MAXCPUS
631.1Sjmcneill	bne	1b
641.1Sjmcneill
651.1Sjmcneill	// Not found our mpidr in the list - use Aff0 for cpuindex
661.1Sjmcneill	and	r0, r4, #7
671.1Sjmcneill2:
681.1Sjmcneill
691.1Sjmcneill	// Find our CCI-400 interface's base address by cpuindex
701.1Sjmcneill	ldr	r1, =sunxi_mc_cci_port
711.1Sjmcneill	sub	r1, R_VTOPDIFF
721.1Sjmcneill	ldr	r2, [r1, r0, lsl #2]		// r2 = sunxi_mc_cci_port[r0]
731.1Sjmcneill
741.1Sjmcneill	cmp	r2, #0
751.1Sjmcneill	beq	3f
761.1Sjmcneill
771.1Sjmcneill	// Enable snooping and DVM broadcast on our CCI-400 interface
781.1Sjmcneill	mov	r3, #(CCI_SNOOP_CTRL_DVM|CCI_SNOOP_CTRL_SNOOP)
791.1Sjmcneill	str	r3, [r2, #CCI_SNOOP_CTRL]
801.1Sjmcneill
811.1Sjmcneill3:
821.1Sjmcneill	b cpu_mpstart
83