From patchwork Thu Sep 19 16:06:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 20454 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B1BE123906 for ; Thu, 19 Sep 2013 16:08:29 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id a11sf8877234qen.10 for ; Thu, 19 Sep 2013 09:08:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=tXrcH7F5lV4/UZ/QH/iCPGzs4GpzngT1p1m4ZACG1xA=; b=BODQxYtzfL0We4UqyA9ZYzfweHcxfVizDT0jQGRgETcLGCL6eIqrTPC9+9irjQs7SY oPGe+4Giht4x6AskUxQ9uoxOakE5elbyUamBVNcibmzNuy1Sm0cl2KtfkBR7VCTZUJXt R42wD/+4HJYze3V5NnaM0Tb/DgYNGr1Xz17gyJyUVKkeYEPQ8W5xBi0m/UIOH+Nw23Vm YValgrZVSMXXASlzPHS2yIwBkr5Y5tmJNe99D7AEA23bkdsY2e7Wnj31UzcHvjOknscm mzDA/gZweRnrvHroMBggfflDpLNI7tVIiqWdSrOdDRNB/utIpQV60BpSjTGUtrH7FowG 8KKw== X-Gm-Message-State: ALoCoQlOTOvkpzEFujGOzv5KBX1cMHw5fMqIgpuy9gnDKtDo8ML7koifjhT3jaQbZ1LSy/plZxJK X-Received: by 10.236.97.7 with SMTP id s7mr581579yhf.56.1379606909543; Thu, 19 Sep 2013 09:08:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.87.36 with SMTP id u4ls3902682qez.56.gmail; Thu, 19 Sep 2013 09:08:29 -0700 (PDT) X-Received: by 10.58.74.38 with SMTP id q6mr1876293vev.9.1379606909461; Thu, 19 Sep 2013 09:08:29 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id zw10si1957176vdb.109.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 09:08:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id ld13so4236695vcb.25 for ; Thu, 19 Sep 2013 09:08:29 -0700 (PDT) X-Received: by 10.52.103.35 with SMTP id ft3mr1589306vdb.5.1379606909330; Thu, 19 Sep 2013 09:08:29 -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.174.196 with SMTP id u4csp286290vcz; Thu, 19 Sep 2013 09:08:28 -0700 (PDT) X-Received: by 10.182.28.134 with SMTP id b6mr1789801obh.27.1379606908494; Thu, 19 Sep 2013 09:08:28 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id gw9si3586464obc.85.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 09:08:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of andre.przywara@linaro.org) client-ip=209.85.214.178; Received: by mail-ob0-f178.google.com with SMTP id uy5so10290479obc.9 for ; Thu, 19 Sep 2013 09:08:28 -0700 (PDT) X-Received: by 10.182.88.129 with SMTP id bg1mr1770695obb.36.1379606907975; Thu, 19 Sep 2013 09:08:27 -0700 (PDT) Received: from slackpad.drs.calxeda.com (f053081156.adsl.alicedsl.de. [78.53.81.156]) by mx.google.com with ESMTPSA id s9sm4867327obu.4.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 09:08:27 -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, agraf@suse.de, geoff.levand@linaro.org, kvmarm@lists.cs.columbia.edu, Masahiro Yamada , Nikolay Nikolaev , patches@linaro.org, Andre Przywara Subject: [PATCH v5 2/8] ARM: add secure monitor handler to switch to non-secure state Date: Thu, 19 Sep 2013 18:06:40 +0200 Message-Id: <1379606806-439-3-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1379606806-439-1-git-send-email-andre.przywara@linaro.org> References: <1379606806-439-1-git-send-email-andre.przywara@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: andre.przywara@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 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 a 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 Changes: v3..v4: clarify comments, w/s fixes v4..v5: remove unneeded padding in the exception table diff --git a/arch/arm/cpu/armv7/Makefile b/arch/arm/cpu/armv7/Makefile index b723e22..3466c7a 100644 --- a/arch/arm/cpu/armv7/Makefile +++ b/arch/arm/cpu/armv7/Makefile @@ -20,6 +20,10 @@ ifneq ($(CONFIG_AM43XX)$(CONFIG_AM33XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX)$(CON 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..c21bca3 --- /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 + +/* + * secure monitor handler + * U-boot calls this "software interrupt" in start.S + * 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 +