···11+/*22+ * Cache definitions for the Hexagon architecture33+ *44+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 and88+ * only version 2 as published by the Free Software Foundation.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program; if not, write to the Free Software1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA1818+ * 02110-1301, USA.1919+ */2020+2121+#ifndef __ASM_CACHE_H2222+#define __ASM_CACHE_H2323+2424+/* Bytes per L1 cache line */2525+#define L1_CACHE_SHIFT (5)2626+#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)2727+2828+#define __cacheline_aligned __aligned(L1_CACHE_BYTES)2929+#define ____cacheline_aligned __aligned(L1_CACHE_BYTES)3030+3131+/* See http://kerneltrap.org/node/15100 */3232+#define __read_mostly3333+3434+#endif
+99
arch/hexagon/include/asm/cacheflush.h
···11+/*22+ * Cache flush operations for the Hexagon architecture33+ *44+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 and88+ * only version 2 as published by the Free Software Foundation.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program; if not, write to the Free Software1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA1818+ * 02110-1301, USA.1919+ */2020+2121+#ifndef _ASM_CACHEFLUSH_H2222+#define _ASM_CACHEFLUSH_H2323+2424+#include <linux/cache.h>2525+#include <linux/mm.h>2626+#include <asm/string.h>2727+#include <asm-generic/cacheflush.h>2828+2929+/* Cache flushing:3030+ *3131+ * - flush_cache_all() flushes entire cache3232+ * - flush_cache_mm(mm) flushes the specified mm context's cache lines3333+ * - flush_cache_page(mm, vmaddr, pfn) flushes a single page3434+ * - flush_cache_range(vma, start, end) flushes a range of pages3535+ * - flush_icache_range(start, end) flush a range of instructions3636+ * - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache3737+ * - flush_icache_page(vma, pg) flushes(invalidates) a page for icache3838+ *3939+ * Need to doublecheck which one is really needed for ptrace stuff to work.4040+ */4141+#define LINESIZE 324242+#define LINEBITS 54343+4444+/*4545+ * Flush Dcache range through current map.4646+ */4747+extern void flush_dcache_range(unsigned long start, unsigned long end);4848+4949+/*5050+ * Flush Icache range through current map.5151+ */5252+#undef flush_icache_range5353+extern void flush_icache_range(unsigned long start, unsigned long end);5454+5555+/*5656+ * Memory-management related flushes are there to ensure in non-physically5757+ * indexed cache schemes that stale lines belonging to a given ASID aren't5858+ * in the cache to confuse things. The prototype Hexagon Virtual Machine5959+ * only uses a single ASID for all user-mode maps, which should6060+ * mean that they aren't necessary. A brute-force, flush-everything6161+ * implementation, with the name xxxxx_hexagon() is present in6262+ * arch/hexagon/mm/cache.c, but let's not wire it up until we know6363+ * it is needed.6464+ */6565+extern void flush_cache_all_hexagon(void);6666+6767+/*6868+ * This may or may not ever have to be non-null, depending on the6969+ * virtual machine MMU. For a native kernel, it's definitiely a no-op7070+ *7171+ * This is also the place where deferred cache coherency stuff seems7272+ * to happen, classically... but instead we do it like ia64 and7373+ * clean the cache when the PTE is set.7474+ *7575+ */7676+static inline void update_mmu_cache(struct vm_area_struct *vma,7777+ unsigned long address, pte_t *ptep)7878+{7979+ /* generic_ptrace_pokedata doesn't wind up here, does it? */8080+}8181+8282+#undef copy_to_user_page8383+static inline void copy_to_user_page(struct vm_area_struct *vma,8484+ struct page *page,8585+ unsigned long vaddr,8686+ void *dst, void *src, int len)8787+{8888+ memcpy(dst, src, len);8989+ if (vma->vm_flags & VM_EXEC) {9090+ flush_icache_range((unsigned long) dst,9191+ (unsigned long) dst + len);9292+ }9393+}9494+9595+9696+extern void hexagon_inv_dcache_range(unsigned long start, unsigned long end);9797+extern void hexagon_clean_dcache_range(unsigned long start, unsigned long end);9898+9999+#endif
+128
arch/hexagon/mm/cache.c
···11+/*22+ * Cache management functions for Hexagon33+ *44+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 and88+ * only version 2 as published by the Free Software Foundation.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program; if not, write to the Free Software1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA1818+ * 02110-1301, USA.1919+ */2020+2121+#include <linux/mm.h>2222+#include <asm/cacheflush.h>2323+#include <asm/hexagon_vm.h>2424+2525+#define spanlines(start, end) \2626+ (((end - (start & ~(LINESIZE - 1))) >> LINEBITS) + 1)2727+2828+void flush_dcache_range(unsigned long start, unsigned long end)2929+{3030+ unsigned long lines = spanlines(start, end-1);3131+ unsigned long i, flags;3232+3333+ start &= ~(LINESIZE - 1);3434+3535+ local_irq_save(flags);3636+3737+ for (i = 0; i < lines; i++) {3838+ __asm__ __volatile__ (3939+ " dccleaninva(%0); "4040+ :4141+ : "r" (start)4242+ );4343+ start += LINESIZE;4444+ }4545+ local_irq_restore(flags);4646+}4747+4848+void flush_icache_range(unsigned long start, unsigned long end)4949+{5050+ unsigned long lines = spanlines(start, end-1);5151+ unsigned long i, flags;5252+5353+ start &= ~(LINESIZE - 1);5454+5555+ local_irq_save(flags);5656+5757+ for (i = 0; i < lines; i++) {5858+ __asm__ __volatile__ (5959+ " dccleana(%0); "6060+ " icinva(%0); "6161+ :6262+ : "r" (start)6363+ );6464+ start += LINESIZE;6565+ }6666+ __asm__ __volatile__ (6767+ "isync"6868+ );6969+ local_irq_restore(flags);7070+}7171+7272+void hexagon_clean_dcache_range(unsigned long start, unsigned long end)7373+{7474+ unsigned long lines = spanlines(start, end-1);7575+ unsigned long i, flags;7676+7777+ start &= ~(LINESIZE - 1);7878+7979+ local_irq_save(flags);8080+8181+ for (i = 0; i < lines; i++) {8282+ __asm__ __volatile__ (8383+ " dccleana(%0); "8484+ :8585+ : "r" (start)8686+ );8787+ start += LINESIZE;8888+ }8989+ local_irq_restore(flags);9090+}9191+9292+void hexagon_inv_dcache_range(unsigned long start, unsigned long end)9393+{9494+ unsigned long lines = spanlines(start, end-1);9595+ unsigned long i, flags;9696+9797+ start &= ~(LINESIZE - 1);9898+9999+ local_irq_save(flags);100100+101101+ for (i = 0; i < lines; i++) {102102+ __asm__ __volatile__ (103103+ " dcinva(%0); "104104+ :105105+ : "r" (start)106106+ );107107+ start += LINESIZE;108108+ }109109+ local_irq_restore(flags);110110+}111111+112112+113113+114114+115115+/*116116+ * This is just really brutal and shouldn't be used anyways,117117+ * especially on V2. Left here just in case.118118+ */119119+void flush_cache_all_hexagon(void)120120+{121121+ unsigned long flags;122122+ local_irq_save(flags);123123+ __vmcache_ickill();124124+ __vmcache_dckill();125125+ __vmcache_l2kill();126126+ local_irq_restore(flags);127127+ mb();128128+}