tgsi: rename fields of tgsi_full_declaration to reduce verbosity
[mesa.git] / src / gallium / drivers / cell / spu / spu_dcache.c
1 /*
2 * (C) Copyright IBM Corporation 2008
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "cell/common.h"
26 #include "spu_main.h"
27 #include "spu_dcache.h"
28
29 #define CACHELINE_LOG2SIZE 7
30 #define LINE_SIZE (1U << 7)
31 #define ALIGN_MASK (~(LINE_SIZE - 1))
32
33 #define CACHE_NAME data
34 #define CACHED_TYPE qword
35 #define CACHE_TYPE CACHE_TYPE_RO
36 #define CACHE_SET_TAGID(set) (((set) & 0x03) + TAG_DCACHE0)
37 #define CACHE_LOG2NNWAY 2
38 #define CACHE_LOG2NSETS 6
39 #ifdef DEBUG
40 #define CACHE_STATS 1
41 #endif
42 #include <cache-api.h>
43
44 /* Yes folks, this is ugly.
45 */
46 #undef CACHE_NWAY
47 #undef CACHE_NSETS
48 #define CACHE_NAME data
49 #define CACHE_NWAY 4
50 #define CACHE_NSETS (1U << 6)
51
52
53 /**
54 * Fetch between arbitrary number of bytes from an unaligned address
55 *
56 * \param dst Destination data buffer
57 * \param ea Main memory effective address of source data
58 * \param size Number of bytes to read
59 *
60 * \warning
61 * As is hinted by the type of the \c dst pointer, this function writes
62 * multiples of 16-bytes.
63 */
64 void
65 spu_dcache_fetch_unaligned(qword *dst, unsigned ea, unsigned size)
66 {
67 const int shift = ea & 0x0f;
68 const unsigned read_size = ROUNDUP16(size + shift);
69 const unsigned last_read = ROUNDUP16(ea + size);
70 const qword *const last_write = dst + (ROUNDUP16(size) / 16);
71 unsigned i;
72
73
74 if (shift == 0) {
75 /* Data is already aligned. Fetch directly into the destination buffer.
76 */
77 for (i = 0; i < size; i += 16) {
78 *(dst++) = cache_rd(data, ea + i);
79 }
80 } else {
81 qword hi;
82
83
84 /* Please exercise extreme caution when modifying this code. This code
85 * must not read past the end of the page containing the source data,
86 * and it must not write more than ((size + 15) / 16) qwords to the
87 * destination buffer.
88 */
89 ea &= ~0x0f;
90 hi = cache_rd(data, ea);
91 for (i = 16; i < read_size; i += 16) {
92 qword lo = cache_rd(data, ea + i);
93
94 *(dst++) = si_or((qword) spu_slqwbyte(hi, shift),
95 (qword) spu_rlmaskqwbyte(lo, shift - 16));
96 hi = lo;
97 }
98
99 if (dst != last_write) {
100 *(dst++) = si_or((qword) spu_slqwbyte(hi, shift), si_il(0));
101 }
102 }
103
104 ASSERT((ea + i) == last_read);
105 ASSERT(dst == last_write);
106 }
107
108
109 /**
110 * Notify the cache that a range of main memory may have been modified
111 */
112 void
113 spu_dcache_mark_dirty(unsigned ea, unsigned size)
114 {
115 unsigned i;
116 const unsigned aligned_start = (ea & ALIGN_MASK);
117 const unsigned aligned_end = (ea + size + (LINE_SIZE - 1))
118 & ALIGN_MASK;
119
120
121 for (i = 0; i < (CACHE_NWAY * CACHE_NSETS); i++) {
122 const unsigned entry = __cache_dir[i];
123 const unsigned addr = entry & ~0x0f;
124
125 __cache_dir[i] = ((addr >= aligned_start) && (addr < aligned_end))
126 ? (entry & ~CACHELINE_VALID) : entry;
127 }
128 }
129
130
131 /**
132 * Print cache utilization report
133 */
134 void
135 spu_dcache_report(void)
136 {
137 #ifdef CACHE_STATS
138 if (spu.init.id == 0) {
139 printf("SPU 0: Texture cache report:\n");
140 cache_pr_stats(data);
141 }
142 #endif
143 }
144
145