From patchwork Tue Jul 9 23:54:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 18292 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 549D525E04 for ; Tue, 9 Jul 2013 23:55:18 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id d10sf7857674vea.4 for ; Tue, 09 Jul 2013 16:55:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=eIj3neJac7BZdu2mgLGnU6CyyvAOKRng4qpg+p4FSXI=; b=kJV+Bf1yeNLXwvzwWnhF+2y/kQPiaR/VYll2odCntBIXdYI9P7pbiCmZvfo/yefu6t wIvW4o9ZkoYpWM67FSChj0QZs2JasfN56DnFAq+cWifcUGDRdzPq2iQf/4uf+Egda7Kb EW7IR7T0VybrVNK0iOkkfmagwcVEfDMAUsqmWl93KCMUN2J1f1xVQ5Av67I2rs+kUrAa XH1R0uYxIgZgPHNM7AG8X1iBq3y4aHyEio9+AXVnkUzABeGeA03BzYzYXi+3ZjxtG4Lu jc6olySyNrZp9fe+ukIXChMsKviwPZfbds9o/D0wFLn1XWaZw0SSM4vV/b7uWP8A9H3o k6xA== X-Received: by 10.236.42.116 with SMTP id i80mr15262408yhb.26.1373414117722; Tue, 09 Jul 2013 16:55:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.118.227 with SMTP id kp3ls2391413qeb.19.gmail; Tue, 09 Jul 2013 16:55:17 -0700 (PDT) X-Received: by 10.58.31.106 with SMTP id z10mr17897222veh.61.1373414117596; Tue, 09 Jul 2013 16:55:17 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id k4si8448237vdi.28.2013.07.09.16.55.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hf12so4889280vcb.29 for ; Tue, 09 Jul 2013 16:55:17 -0700 (PDT) X-Received: by 10.52.23.83 with SMTP id k19mr2035356vdf.106.1373414117429; Tue, 09 Jul 2013 16:55:17 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.149.77 with SMTP id s13csp57405vcv; Tue, 9 Jul 2013 16:55:16 -0700 (PDT) X-Received: by 10.194.93.74 with SMTP id cs10mr16611948wjb.9.1373414116229; Tue, 09 Jul 2013 16:55:16 -0700 (PDT) Received: from mail-we0-f180.google.com (mail-we0-f180.google.com [74.125.82.180]) by mx.google.com with ESMTPS id n1si9376590wiw.40.2013.07.09.16.55.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:16 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.180 is neither permitted nor denied by best guess record for domain of andre.przywara@linaro.org) client-ip=74.125.82.180; Received: by mail-we0-f180.google.com with SMTP id w56so5187638wes.25 for ; Tue, 09 Jul 2013 16:55:15 -0700 (PDT) X-Received: by 10.194.109.104 with SMTP id hr8mr16389738wjb.32.1373414115489; Tue, 09 Jul 2013 16:55:15 -0700 (PDT) Received: from localhost.localdomain ([193.120.41.118]) by mx.google.com with ESMTPSA id fs8sm64073738wib.0.2013.07.09.16.55.13 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:14 -0700 (PDT) From: Andre Przywara To: trini@ti.com, albert.u.boot@aribaud.net, christoffer.dall@linaro.org Cc: u-boot@lists.denx.de, marc.zyngier@arm.com, peter.maydell@linaro.org, geoff.levand@linaro.org, agraf@suse.de, kvmarm@lists.cs.columbia.edu, yamada.m@jp.panasonic.com, nicknickolaev@gmail.com, patches@linaro.org Subject: [PATCH v3 2/7] ARM: add secure monitor handler to switch to non-secure state Date: Wed, 10 Jul 2013 01:54:14 +0200 Message-Id: <1373414059-22779-3-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1373414059-22779-1-git-send-email-andre.przywara@linaro.org> References: <1373414059-22779-1-git-send-email-andre.przywara@linaro.org> X-Gm-Message-State: ALoCoQnvccsJfh1ar/GFF1o+4DaGQDDPrMhKvFBqbKZRBWhjeBIH+Ab+5RrUhrel/DSg84aNU8VC X-Original-Sender: andre.przywara@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , A prerequisite for using virtualization is to be in HYP mode, which requires the CPU to be in non-secure state first. Add new file in arch/arm/cpu/armv7 to hold a monitor handler routine which switches the CPU to non-secure state by setting the NS and associated bits. According to the ARM architecture reference manual this should not be done in SVC mode, so we have to setup a SMC handler for this. We create a new vector table to avoid interference with other boards. The MVBAR register will be programmed later just before the smc call. Signed-off-by: Andre Przywara --- arch/arm/cpu/armv7/Makefile | 4 +++ arch/arm/cpu/armv7/nonsec_virt.S | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 arch/arm/cpu/armv7/nonsec_virt.S diff --git a/arch/arm/cpu/armv7/Makefile b/arch/arm/cpu/armv7/Makefile index 7a8c2d0..5d75077 100644 --- a/arch/arm/cpu/armv7/Makefile +++ b/arch/arm/cpu/armv7/Makefile @@ -36,6 +36,10 @@ ifneq ($(CONFIG_AM33XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX)$(CONFIG_TEGRA)$(CONF SOBJS += lowlevel_init.o endif +ifneq ($(CONFIG_ARMV7_NONSEC),) +SOBJS += nonsec_virt.o +endif + SRCS := $(START:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS)) START := $(addprefix $(obj),$(START)) diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S new file mode 100644 index 0000000..68a6b38 --- /dev/null +++ b/arch/arm/cpu/armv7/nonsec_virt.S @@ -0,0 +1,54 @@ +/* + * code for switching cores into non-secure state + * + * Copyright (c) 2013 Andre Przywara + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include + +/* the vector table for secure state */ +_monitor_vectors: + .word 0 /* reset */ + .word 0 /* undef */ + adr pc, _secure_monitor + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 /* pad */ + +/* + * software interrupt aka. secure monitor handler + * This is executed on a "smc" instruction, we use a "smc #0" to switch + * to non-secure state. + * We use only r0 and r1 here, due to constraints in the caller. + */ + .align 5 +_secure_monitor: + mrc p15, 0, r1, c1, c1, 0 @ read SCR + bic r1, r1, #0x4e @ clear IRQ, FIQ, EA, nET bits + orr r1, r1, #0x31 @ enable NS, AW, FW bits + + mcr p15, 0, r1, c1, c1, 0 @ write SCR (with NS bit set) + + movs pc, lr @ return to non-secure SVC +