Path: blob/master/arch/mn10300/mm/cache-inv-icache.c
10817 views
/* Invalidate icache when dcache doesn't need invalidation as it's in1* write-through mode2*3* Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.4* Written by David Howells ([email protected])5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public Licence8* as published by the Free Software Foundation; either version9* 2 of the Licence, or (at your option) any later version.10*/11#include <linux/module.h>12#include <linux/mm.h>13#include <asm/cacheflush.h>14#include <asm/smp.h>15#include "cache-smp.h"1617/**18* flush_icache_page_range - Flush dcache and invalidate icache for part of a19* single page20* @start: The starting virtual address of the page part.21* @end: The ending virtual address of the page part.22*23* Invalidate the icache for part of a single page, as determined by the24* virtual addresses given. The page must be in the paged area. The dcache is25* not flushed as the cache must be in write-through mode to get here.26*/27static void flush_icache_page_range(unsigned long start, unsigned long end)28{29unsigned long addr, size, off;30struct page *page;31pgd_t *pgd;32pud_t *pud;33pmd_t *pmd;34pte_t *ppte, pte;3536/* work out how much of the page to flush */37off = start & ~PAGE_MASK;38size = end - start;3940/* get the physical address the page is mapped to from the page41* tables */42pgd = pgd_offset(current->mm, start);43if (!pgd || !pgd_val(*pgd))44return;4546pud = pud_offset(pgd, start);47if (!pud || !pud_val(*pud))48return;4950pmd = pmd_offset(pud, start);51if (!pmd || !pmd_val(*pmd))52return;5354ppte = pte_offset_map(pmd, start);55if (!ppte)56return;57pte = *ppte;58pte_unmap(ppte);5960if (pte_none(pte))61return;6263page = pte_page(pte);64if (!page)65return;6667addr = page_to_phys(page);6869/* invalidate the icache coverage on that region */70mn10300_local_icache_inv_range2(addr + off, size);71smp_cache_call(SMP_ICACHE_INV_RANGE, start, end);72}7374/**75* flush_icache_range - Globally flush dcache and invalidate icache for region76* @start: The starting virtual address of the region.77* @end: The ending virtual address of the region.78*79* This is used by the kernel to globally flush some code it has just written80* from the dcache back to RAM and then to globally invalidate the icache over81* that region so that that code can be run on all CPUs in the system.82*/83void flush_icache_range(unsigned long start, unsigned long end)84{85unsigned long start_page, end_page;86unsigned long flags;8788flags = smp_lock_cache();8990if (end > 0x80000000UL) {91/* addresses above 0xa0000000 do not go through the cache */92if (end > 0xa0000000UL) {93end = 0xa0000000UL;94if (start >= end)95goto done;96}9798/* kernel addresses between 0x80000000 and 0x9fffffff do not99* require page tables, so we just map such addresses100* directly */101start_page = (start >= 0x80000000UL) ? start : 0x80000000UL;102mn10300_icache_inv_range(start_page, end);103smp_cache_call(SMP_ICACHE_INV_RANGE, start, end);104if (start_page == start)105goto done;106end = start_page;107}108109start_page = start & PAGE_MASK;110end_page = (end - 1) & PAGE_MASK;111112if (start_page == end_page) {113/* the first and last bytes are on the same page */114flush_icache_page_range(start, end);115} else if (start_page + 1 == end_page) {116/* split over two virtually contiguous pages */117flush_icache_page_range(start, end_page);118flush_icache_page_range(end_page, end);119} else {120/* more than 2 pages; just flush the entire cache */121mn10300_local_icache_inv();122smp_cache_call(SMP_ICACHE_INV, 0, 0);123}124125done:126smp_unlock_cache(flags);127}128EXPORT_SYMBOL(flush_icache_range);129130131