From patchwork Mon Sep 8 03:53:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 36932 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41F9620491 for ; Mon, 8 Sep 2014 03:56:08 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id v10sf30706493pde.2 for ; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=EnRvruPLcDzbah5BvxUPe/1YFPqarbYycarShuqYfXQ=; b=gWsXKCcH7Ru/7R2RiU3I/Mw6SGGqcl2yhTUlPXyfRzXpztDq9rZ5KXcwNq2v5Bh7yp VrJGxLN0tOAgTVdNAd5+plA/ny5UBZRISdrFYZfupalnpnHsBuHdKKVgWaKi9chzoGo9 TRLzNq/qC7s1303nrE53n8MW0SARrXE4ya4nGgN6Gz3xpQTvmYa9EpG9Gg6o1lfcWbIi 1I+rOZDkrMAxsmrZOTAtZByMNatxSSGk1Xqz8N5lbBwlb4hq7mRH0sktqKk/XU1n4Cm1 2y/T9XQ+FsQOkefIlwZbAcgyh1i1M+whSDZ2vut4jLF803naJ5iUIMma8Hkj5tvPho9d QDcQ== X-Gm-Message-State: ALoCoQmv/or5Qx2XXkBaiS5JCIMSxG2ZYBjpSgTXo1UIHFGuyFZBcV4GJ6tppu/LChR1VB7I5fzj X-Received: by 10.66.157.197 with SMTP id wo5mr2777684pab.43.1410148567575; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.230 with SMTP id j93ls1519055qgd.40.gmail; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) X-Received: by 10.52.26.206 with SMTP id n14mr19640832vdg.0.1410148567477; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id 9si3485577vcq.96.2014.09.07.20.56.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 07 Sep 2014 20:56:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so14486863vcb.22 for ; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) X-Received: by 10.52.137.2 with SMTP id qe2mr19557824vdb.11.1410148567382; Sun, 07 Sep 2014 20:56:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp76444vcb; Sun, 7 Sep 2014 20:56:07 -0700 (PDT) X-Received: by 10.140.106.66 with SMTP id d60mr18002105qgf.23.1410148566894; Sun, 07 Sep 2014 20:56:06 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id a8si9647071qas.130.2014.09.07.20.56.06 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 07 Sep 2014 20:56:06 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XQq2J-00076A-Ig; Mon, 08 Sep 2014 03:54:39 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XQq2G-00072W-Il for xen-devel@lists.xen.org; Mon, 08 Sep 2014 03:54:36 +0000 Received: from [85.158.139.211:25877] by server-14.bemta-5.messagelabs.com id D1/49-12422-B782D045; Mon, 08 Sep 2014 03:54:35 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-3.tower-206.messagelabs.com!1410148473!5444094!1 X-Originating-IP: [209.85.220.50] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5004 invoked from network); 8 Sep 2014 03:54:34 -0000 Received: from mail-pa0-f50.google.com (HELO mail-pa0-f50.google.com) (209.85.220.50) by server-3.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 8 Sep 2014 03:54:34 -0000 Received: by mail-pa0-f50.google.com with SMTP id bj1so255761pad.9 for ; Sun, 07 Sep 2014 20:54:33 -0700 (PDT) X-Received: by 10.68.238.99 with SMTP id vj3mr4755131pbc.43.1410148473003; Sun, 07 Sep 2014 20:54:33 -0700 (PDT) Received: from rfranz-i7.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id qy1sm7524053pbc.27.2014.09.07.20.54.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Sep 2014 20:54:32 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Sun, 7 Sep 2014 20:53:59 -0700 Message-Id: <1410148441-18684-14-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410148441-18684-1-git-send-email-roy.franz@linaro.org> References: <1410148441-18684-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH V3 13/15] add arm64 cache flushing code from linux v3.16 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: __flush_dcache_all added from arch/arm64/mm/cache.S, with helper macros from arch/arm64/include/asm/assembler.h, from v3.16. The cache flushing is required when transitioning from EFI code that runs with cache enable to XEN startup code which expects the cache to be disabled. Signed-off-by: Roy Franz Acked-by: Ian Campbell --- xen/arch/arm/arm64/Makefile | 1 + xen/arch/arm/arm64/cache.S | 100 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 xen/arch/arm/arm64/cache.S diff --git a/xen/arch/arm/arm64/Makefile b/xen/arch/arm/arm64/Makefile index d2d5875..c7243f5 100644 --- a/xen/arch/arm/arm64/Makefile +++ b/xen/arch/arm/arm64/Makefile @@ -7,5 +7,6 @@ obj-y += domain.o obj-y += vfp.o obj-y += smpboot.o obj-y += domctl.o +obj-y += cache.o obj-$(EARLY_PRINTK) += debug.o diff --git a/xen/arch/arm/arm64/cache.S b/xen/arch/arm/arm64/cache.S new file mode 100644 index 0000000..fb6dff1 --- /dev/null +++ b/xen/arch/arm/arm64/cache.S @@ -0,0 +1,100 @@ +/* + * Cache maintenance + * + * Copyright (C) 2001 Deep Blue Solutions Ltd. + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 1996-2000 Russell King + * Copyright (C) 2012 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + */ + +/* + * Enable and disable interrupts. + */ + .macro disable_irq + msr daifset, #2 + .endm + + .macro enable_irq + msr daifclr, #2 + .endm + +/* + * Save/disable and restore interrupts. + */ + .macro save_and_disable_irqs, olddaif + mrs \olddaif, daif + disable_irq + .endm + + .macro restore_irqs, olddaif + msr daif, \olddaif + .endm + +/* + * __flush_dcache_all() + * + * Flush the whole D-cache. + * + * Corrupted registers: x0-x7, x9-x11 + */ + ENTRY(__flush_dcache_all) +__flush_dcache_all: + dmb sy // ensure ordering with previous memory accesses + mrs x0, clidr_el1 // read clidr + and x3, x0, #0x7000000 // extract loc from clidr + lsr x3, x3, #23 // left align loc bit field + cbz x3, finished // if loc is 0, then no need to clean + mov x10, #0 // start clean at cache level 0 +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 of the bits for current cache only + cmp x1, #2 // see what cache we have at this level + b.lt skip // skip if no cache, or just i-cache + save_and_disable_irqs x9 // make CSSELR and CCSIDR access atomic + 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 + restore_irqs x9 + and x2, x1, #7 // extract the length of the cache lines + add x2, x2, #4 // add 4 (line length offset) + mov x4, #0x3ff + and x4, x4, x1, lsr #3 // find maximum number on the way size + clz w5, w4 // find bit position of way size increment + mov x7, #0x7fff + and x7, x7, x1, lsr #13 // extract max number of the index size +loop2: + mov x9, x4 // create working copy of max way size +loop3: + lsl x6, x9, x5 + orr x11, x10, x6 // factor way and cache number into x11 + lsl x6, x7, x2 + orr x11, x11, x6 // factor index number into x11 + dc cisw, x11 // clean & invalidate by set/way + subs x9, x9, #1 // decrement the way + b.ge loop3 + subs x7, x7, #1 // decrement the index + b.ge loop2 +skip: + add x10, x10, #2 // increment cache number + cmp x3, x10 + b.gt loop1 +finished: + mov x10, #0 // swith back to cache level 0 + msr csselr_el1, x10 // select current cache level in csselr + dsb sy + isb + ret +ENDPROC(__flush_dcache_all)