From patchwork Thu Jul 7 15:50:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 953432 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p67G3aJZ027819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 7 Jul 2011 16:03:57 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qer1L-00023O-FE; Thu, 07 Jul 2011 16:01:43 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QequR-0005qw-87; Thu, 07 Jul 2011 15:54:35 +0000 Received: from service88.mimecast.com ([195.130.217.12]) by canuck.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1QeqtM-0005Qw-26 for linux-arm-kernel@lists.infradead.org; Thu, 07 Jul 2011 15:53:29 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 07 Jul 2011 16:52:30 +0100 Received: from e102568-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 7 Jul 2011 16:50:54 +0100 From: Lorenzo Pieralisi To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 14/17] ARM: kernel: save/restore 1:1 page tables Date: Thu, 7 Jul 2011 16:50:27 +0100 Message-Id: <1310053830-23779-15-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1310053830-23779-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1310053830-23779-1-git-send-email-lorenzo.pieralisi@arm.com> X-OriginalArrivalTime: 07 Jul 2011 15:50:54.0795 (UTC) FILETIME=[A7C2D1B0:01CC3CBD] X-MC-Unique: 111070716523001001 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110707_115328_809544_F0CBEB68 X-CRM114-Status: GOOD ( 16.48 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [195.130.217.12 listed in list.dnswl.org] Cc: Kevin Hilman , Lorenzo Pieralisi , Russell King , Catalin Marinas , Amit Kucheria , Frank Hofmann , Magnus Damm , Santosh Shilimkar , Amit Kachhap , Colin Cross , Linaro Dev X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 07 Jul 2011 16:03:57 +0000 (UTC) This patch adds the code required to allocate and populate page tables that are needed by save/restore code to deal with MMU off/on transactions. MMU is enabled early in the resume path which allows to call into Linux subsystems with init_mm virtual mappings (cloned at boot). Current thread page table pointer and context id is saved on power down from active_mm and restored on warm boot. Currently the translation tables contains 1:1 mappings of the Linux kernel code and data, and 1:1 UNCACHED mapping of control code required when MMU is turned off in the restore code path. Signed-off-by: Lorenzo Pieralisi --- arch/arm/kernel/sr_mapping.c | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 arch/arm/kernel/sr_mapping.c diff --git a/arch/arm/kernel/sr_mapping.c b/arch/arm/kernel/sr_mapping.c new file mode 100644 index 0000000..32640dc --- /dev/null +++ b/arch/arm/kernel/sr_mapping.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2008-2011 ARM Limited + * Author(s): Jon Callan, Lorenzo Pieralisi + * + * 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. + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include "sr_helpers.h" +#include "sr.h" + +#define PROT_PTE_DEVICE (L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN) + +static pgd_t *pgd; + +static void *linux_sr_map_page(void *addr, unsigned int size, + pgprot_t prot) +{ + pmd_t *pmd; + pte_t *pte; + u64 pfn; + unsigned long end = (unsigned long) (addr) + size; + unsigned long vaddr = (unsigned long) (addr); + + pmd = pmd_offset(pgd + pgd_index(vaddr), vaddr); + pfn = vaddr >> PAGE_SHIFT; + pte = pte_alloc_kernel(pmd, vaddr); + + do { + if (!pte) + return NULL; + set_pte_ext(pte, pfn_pte(pfn, prot), 0); + outer_clean_range(__pa(pte), __pa(pte + 1)); + pfn++; + } while (pte++, vaddr += PAGE_SIZE, vaddr != end); + + return addr; +} + +int linux_sr_setup_translation_tables(void) +{ + pgd = pgd_alloc(&init_mm); + + if (!pgd) + return -ENOMEM; + /* + * These kernel identity mappings are not strictly necessary + * since resume code creates them on the fly. + * They are left for completeness in case the suspend + * code had to turn MMU off for a power down failure and + * the call to (*sr_sleep) returns. + */ + identity_mapping_add(pgd, __pa(_stext), __pa(_etext)); + identity_mapping_add(pgd, __pa(_sdata), __pa(_edata)); + + linux_sr_map_page(context_memory_uncached, + CONTEXT_SPACE_UNCACHED, + __pgprot(PROT_PTE_DEVICE | + L_PTE_MT_UNCACHED | L_PTE_SHARED)); + + /* save pgd of translation tables for cpu_switch_mm */ + main_table.fw_mmu_context = pgd; + + __cpuc_flush_dcache_area(pgd, sizeof(pgd)); + outer_clean_range(__pa(pgd), __pa(pgd + 1)); + return 0; +}