blob: 69358b590c9156953ee3c45deb471e4833c7d370 [file] [log] [blame]
David S. Millerd113fcd2007-11-16 03:06:07 -08001/* cache.h: Cache specific code for the Sparc. These include flushing
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * and direct tag/data line access.
3 *
David S. Millerd113fcd2007-11-16 03:06:07 -08004 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
7#ifndef _SPARC_CACHE_H
8#define _SPARC_CACHE_H
9
David S. Miller273fca02010-05-18 15:23:58 -070010#define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#define L1_CACHE_SHIFT 5
13#define L1_CACHE_BYTES 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
David S. Millerd113fcd2007-11-16 03:06:07 -080015#ifdef CONFIG_SPARC32
16#define SMP_CACHE_BYTES_SHIFT 5
17#else
18#define SMP_CACHE_BYTES_SHIFT 6
19#endif
20
21#define SMP_CACHE_BYTES (1 << SMP_CACHE_BYTES_SHIFT)
22
Denys Vlasenko54cb27a2010-02-20 01:03:44 +010023#define __read_mostly __attribute__((__section__(".data..read_mostly")))
David S. Millerd113fcd2007-11-16 03:06:07 -080024
25#ifdef CONFIG_SPARC32
26#include <asm/asi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* Direct access to the instruction cache is provided through and
29 * alternate address space. The IDC bit must be off in the ICCR on
30 * HyperSparcs for these accesses to work. The code below does not do
31 * any checking, the caller must do so. These routines are for
32 * diagnostics only, but could end up being useful. Use with care.
33 * Also, you are asking for trouble if you execute these in one of the
34 * three instructions following a %asr/%psr access or modification.
35 */
36
37/* First, cache-tag access. */
Adrian Bunk31156242005-10-03 17:37:02 -070038static inline unsigned int get_icache_tag(int setnum, int tagnum)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 unsigned int vaddr, retval;
41
42 vaddr = ((setnum&1) << 12) | ((tagnum&0x7f) << 5);
43 __asm__ __volatile__("lda [%1] %2, %0\n\t" :
44 "=r" (retval) :
45 "r" (vaddr), "i" (ASI_M_TXTC_TAG));
46 return retval;
47}
48
Adrian Bunk31156242005-10-03 17:37:02 -070049static inline void put_icache_tag(int setnum, int tagnum, unsigned int entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 unsigned int vaddr;
52
53 vaddr = ((setnum&1) << 12) | ((tagnum&0x7f) << 5);
54 __asm__ __volatile__("sta %0, [%1] %2\n\t" : :
55 "r" (entry), "r" (vaddr), "i" (ASI_M_TXTC_TAG) :
56 "memory");
57}
58
59/* Second cache-data access. The data is returned two-32bit quantities
60 * at a time.
61 */
Adrian Bunk31156242005-10-03 17:37:02 -070062static inline void get_icache_data(int setnum, int tagnum, int subblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned int *data)
64{
65 unsigned int value1, value2, vaddr;
66
67 vaddr = ((setnum&0x1) << 12) | ((tagnum&0x7f) << 5) |
68 ((subblock&0x3) << 3);
69 __asm__ __volatile__("ldda [%2] %3, %%g2\n\t"
70 "or %%g0, %%g2, %0\n\t"
71 "or %%g0, %%g3, %1\n\t" :
72 "=r" (value1), "=r" (value2) :
73 "r" (vaddr), "i" (ASI_M_TXTC_DATA) :
74 "g2", "g3");
75 data[0] = value1; data[1] = value2;
76}
77
Adrian Bunk31156242005-10-03 17:37:02 -070078static inline void put_icache_data(int setnum, int tagnum, int subblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned int *data)
80{
81 unsigned int value1, value2, vaddr;
82
83 vaddr = ((setnum&0x1) << 12) | ((tagnum&0x7f) << 5) |
84 ((subblock&0x3) << 3);
85 value1 = data[0]; value2 = data[1];
86 __asm__ __volatile__("or %%g0, %0, %%g2\n\t"
87 "or %%g0, %1, %%g3\n\t"
88 "stda %%g2, [%2] %3\n\t" : :
89 "r" (value1), "r" (value2),
90 "r" (vaddr), "i" (ASI_M_TXTC_DATA) :
91 "g2", "g3", "memory" /* no joke */);
92}
93
94/* Different types of flushes with the ICACHE. Some of the flushes
95 * affect both the ICACHE and the external cache. Others only clear
96 * the ICACHE entries on the cpu itself. V8's (most) allow
97 * granularity of flushes on the packet (element in line), whole line,
98 * and entire cache (ie. all lines) level. The ICACHE only flushes are
99 * ROSS HyperSparc specific and are in ross.h
100 */
101
102/* Flushes which clear out both the on-chip and external caches */
Adrian Bunk31156242005-10-03 17:37:02 -0700103static inline void flush_ei_page(unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
106 "r" (addr), "i" (ASI_M_FLUSH_PAGE) :
107 "memory");
108}
109
Adrian Bunk31156242005-10-03 17:37:02 -0700110static inline void flush_ei_seg(unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
113 "r" (addr), "i" (ASI_M_FLUSH_SEG) :
114 "memory");
115}
116
Adrian Bunk31156242005-10-03 17:37:02 -0700117static inline void flush_ei_region(unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
120 "r" (addr), "i" (ASI_M_FLUSH_REGION) :
121 "memory");
122}
123
Adrian Bunk31156242005-10-03 17:37:02 -0700124static inline void flush_ei_ctx(unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
127 "r" (addr), "i" (ASI_M_FLUSH_CTX) :
128 "memory");
129}
130
Adrian Bunk31156242005-10-03 17:37:02 -0700131static inline void flush_ei_user(unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
134 "r" (addr), "i" (ASI_M_FLUSH_USER) :
135 "memory");
136}
David S. Millerd113fcd2007-11-16 03:06:07 -0800137#endif /* CONFIG_SPARC32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139#endif /* !(_SPARC_CACHE_H) */