1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/compiler.h>
34#include <linux/irqflags.h>
35#include <asm/octeon/cvmx.h>
36#include <asm/octeon/cvmx-l2c.h>
37#include <asm/octeon/cvmx-spinlock.h>
38
39
40
41
42
43
44
45
46
47cvmx_spinlock_t cvmx_l2c_spinlock;
48
49int cvmx_l2c_get_core_way_partition(uint32_t core)
50{
51 uint32_t field;
52
53
54 if (core >= cvmx_octeon_num_cores())
55 return -1;
56
57 if (OCTEON_IS_MODEL(OCTEON_CN63XX))
58 return cvmx_read_csr(CVMX_L2C_WPAR_PPX(core)) & 0xffff;
59
60
61
62
63
64 field = (core & 0x3) * 8;
65
66
67
68
69
70
71 switch (core & 0xC) {
72 case 0x0:
73 return (cvmx_read_csr(CVMX_L2C_SPAR0) & (0xFF << field)) >> field;
74 case 0x4:
75 return (cvmx_read_csr(CVMX_L2C_SPAR1) & (0xFF << field)) >> field;
76 case 0x8:
77 return (cvmx_read_csr(CVMX_L2C_SPAR2) & (0xFF << field)) >> field;
78 case 0xC:
79 return (cvmx_read_csr(CVMX_L2C_SPAR3) & (0xFF << field)) >> field;
80 }
81 return 0;
82}
83
84int cvmx_l2c_set_core_way_partition(uint32_t core, uint32_t mask)
85{
86 uint32_t field;
87 uint32_t valid_mask;
88
89 valid_mask = (0x1 << cvmx_l2c_get_num_assoc()) - 1;
90
91 mask &= valid_mask;
92
93
94 if (mask == valid_mask && !OCTEON_IS_MODEL(OCTEON_CN63XX))
95 return -1;
96
97
98 if (core >= cvmx_octeon_num_cores())
99 return -1;
100
101 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
102 cvmx_write_csr(CVMX_L2C_WPAR_PPX(core), mask);
103 return 0;
104 }
105
106
107
108
109
110 field = (core & 0x3) * 8;
111
112
113
114
115
116
117 switch (core & 0xC) {
118 case 0x0:
119 cvmx_write_csr(CVMX_L2C_SPAR0,
120 (cvmx_read_csr(CVMX_L2C_SPAR0) & ~(0xFF << field)) |
121 mask << field);
122 break;
123 case 0x4:
124 cvmx_write_csr(CVMX_L2C_SPAR1,
125 (cvmx_read_csr(CVMX_L2C_SPAR1) & ~(0xFF << field)) |
126 mask << field);
127 break;
128 case 0x8:
129 cvmx_write_csr(CVMX_L2C_SPAR2,
130 (cvmx_read_csr(CVMX_L2C_SPAR2) & ~(0xFF << field)) |
131 mask << field);
132 break;
133 case 0xC:
134 cvmx_write_csr(CVMX_L2C_SPAR3,
135 (cvmx_read_csr(CVMX_L2C_SPAR3) & ~(0xFF << field)) |
136 mask << field);
137 break;
138 }
139 return 0;
140}
141
142int cvmx_l2c_set_hw_way_partition(uint32_t mask)
143{
144 uint32_t valid_mask;
145
146 valid_mask = (0x1 << cvmx_l2c_get_num_assoc()) - 1;
147 mask &= valid_mask;
148
149
150 if (mask == valid_mask && !OCTEON_IS_MODEL(OCTEON_CN63XX))
151 return -1;
152
153 if (OCTEON_IS_MODEL(OCTEON_CN63XX))
154 cvmx_write_csr(CVMX_L2C_WPAR_IOBX(0), mask);
155 else
156 cvmx_write_csr(CVMX_L2C_SPAR4,
157 (cvmx_read_csr(CVMX_L2C_SPAR4) & ~0xFF) | mask);
158 return 0;
159}
160
161int cvmx_l2c_get_hw_way_partition(void)
162{
163 if (OCTEON_IS_MODEL(OCTEON_CN63XX))
164 return cvmx_read_csr(CVMX_L2C_WPAR_IOBX(0)) & 0xffff;
165 else
166 return cvmx_read_csr(CVMX_L2C_SPAR4) & (0xFF);
167}
168
169void cvmx_l2c_config_perf(uint32_t counter, enum cvmx_l2c_event event,
170 uint32_t clear_on_read)
171{
172 if (OCTEON_IS_MODEL(OCTEON_CN5XXX) || OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
173 union cvmx_l2c_pfctl pfctl;
174
175 pfctl.u64 = cvmx_read_csr(CVMX_L2C_PFCTL);
176
177 switch (counter) {
178 case 0:
179 pfctl.s.cnt0sel = event;
180 pfctl.s.cnt0ena = 1;
181 pfctl.s.cnt0rdclr = clear_on_read;
182 break;
183 case 1:
184 pfctl.s.cnt1sel = event;
185 pfctl.s.cnt1ena = 1;
186 pfctl.s.cnt1rdclr = clear_on_read;
187 break;
188 case 2:
189 pfctl.s.cnt2sel = event;
190 pfctl.s.cnt2ena = 1;
191 pfctl.s.cnt2rdclr = clear_on_read;
192 break;
193 case 3:
194 default:
195 pfctl.s.cnt3sel = event;
196 pfctl.s.cnt3ena = 1;
197 pfctl.s.cnt3rdclr = clear_on_read;
198 break;
199 }
200
201 cvmx_write_csr(CVMX_L2C_PFCTL, pfctl.u64);
202 } else {
203 union cvmx_l2c_tadx_prf l2c_tadx_prf;
204 int tad;
205
206 cvmx_dprintf("L2C performance counter events are different for this chip, mapping 'event' to cvmx_l2c_tad_event_t\n");
207 if (clear_on_read)
208 cvmx_dprintf("L2C counters don't support clear on read for this chip\n");
209
210 l2c_tadx_prf.u64 = cvmx_read_csr(CVMX_L2C_TADX_PRF(0));
211
212 switch (counter) {
213 case 0:
214 l2c_tadx_prf.s.cnt0sel = event;
215 break;
216 case 1:
217 l2c_tadx_prf.s.cnt1sel = event;
218 break;
219 case 2:
220 l2c_tadx_prf.s.cnt2sel = event;
221 break;
222 default:
223 case 3:
224 l2c_tadx_prf.s.cnt3sel = event;
225 break;
226 }
227 for (tad = 0; tad < CVMX_L2C_TADS; tad++)
228 cvmx_write_csr(CVMX_L2C_TADX_PRF(tad),
229 l2c_tadx_prf.u64);
230 }
231}
232
233uint64_t cvmx_l2c_read_perf(uint32_t counter)
234{
235 switch (counter) {
236 case 0:
237 if (OCTEON_IS_MODEL(OCTEON_CN5XXX) || OCTEON_IS_MODEL(OCTEON_CN3XXX))
238 return cvmx_read_csr(CVMX_L2C_PFC0);
239 else {
240 uint64_t counter = 0;
241 int tad;
242
243 for (tad = 0; tad < CVMX_L2C_TADS; tad++)
244 counter += cvmx_read_csr(CVMX_L2C_TADX_PFC0(tad));
245 return counter;
246 }
247 case 1:
248 if (OCTEON_IS_MODEL(OCTEON_CN5XXX) || OCTEON_IS_MODEL(OCTEON_CN3XXX))
249 return cvmx_read_csr(CVMX_L2C_PFC1);
250 else {
251 uint64_t counter = 0;
252 int tad;
253
254 for (tad = 0; tad < CVMX_L2C_TADS; tad++)
255 counter += cvmx_read_csr(CVMX_L2C_TADX_PFC1(tad));
256 return counter;
257 }
258 case 2:
259 if (OCTEON_IS_MODEL(OCTEON_CN5XXX) || OCTEON_IS_MODEL(OCTEON_CN3XXX))
260 return cvmx_read_csr(CVMX_L2C_PFC2);
261 else {
262 uint64_t counter = 0;
263 int tad;
264
265 for (tad = 0; tad < CVMX_L2C_TADS; tad++)
266 counter += cvmx_read_csr(CVMX_L2C_TADX_PFC2(tad));
267 return counter;
268 }
269 case 3:
270 default:
271 if (OCTEON_IS_MODEL(OCTEON_CN5XXX) || OCTEON_IS_MODEL(OCTEON_CN3XXX))
272 return cvmx_read_csr(CVMX_L2C_PFC3);
273 else {
274 uint64_t counter = 0;
275 int tad;
276
277 for (tad = 0; tad < CVMX_L2C_TADS; tad++)
278 counter += cvmx_read_csr(CVMX_L2C_TADX_PFC3(tad));
279 return counter;
280 }
281 }
282}
283
284
285
286
287
288
289
290
291static void fault_in(uint64_t addr, int len)
292{
293 char *ptr;
294
295
296
297
298
299 len += addr & CVMX_CACHE_LINE_MASK;
300 addr &= ~CVMX_CACHE_LINE_MASK;
301 ptr = cvmx_phys_to_ptr(addr);
302
303
304
305
306 CVMX_DCACHE_INVALIDATE;
307 while (len > 0) {
308 READ_ONCE(*ptr);
309 len -= CVMX_CACHE_LINE_SIZE;
310 ptr += CVMX_CACHE_LINE_SIZE;
311 }
312}
313
314int cvmx_l2c_lock_line(uint64_t addr)
315{
316 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
317 int shift = CVMX_L2C_TAG_ADDR_ALIAS_SHIFT;
318 uint64_t assoc = cvmx_l2c_get_num_assoc();
319 uint64_t tag = addr >> shift;
320 uint64_t index = CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, cvmx_l2c_address_to_index(addr) << CVMX_L2C_IDX_ADDR_SHIFT);
321 uint64_t way;
322 union cvmx_l2c_tadx_tag l2c_tadx_tag;
323
324 CVMX_CACHE_LCKL2(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, addr), 0);
325
326
327 for (way = 0; way < assoc; way++) {
328 CVMX_CACHE_LTGL2I(index | (way << shift), 0);
329
330 CVMX_SYNC;
331 l2c_tadx_tag.u64 = cvmx_read_csr(CVMX_L2C_TADX_TAG(0));
332 if (l2c_tadx_tag.s.valid && l2c_tadx_tag.s.tag == tag)
333 break;
334 }
335
336
337 if (way >= assoc) {
338
339 return -1;
340 }
341
342
343 if (!l2c_tadx_tag.s.lock) {
344
345 return -1;
346 }
347 return way;
348 } else {
349 int retval = 0;
350 union cvmx_l2c_dbg l2cdbg;
351 union cvmx_l2c_lckbase lckbase;
352 union cvmx_l2c_lckoff lckoff;
353 union cvmx_l2t_err l2t_err;
354
355 cvmx_spinlock_lock(&cvmx_l2c_spinlock);
356
357 l2cdbg.u64 = 0;
358 lckbase.u64 = 0;
359 lckoff.u64 = 0;
360
361
362 l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
363 l2t_err.s.lckerr = 1;
364 l2t_err.s.lckerr2 = 1;
365 cvmx_write_csr(CVMX_L2T_ERR, l2t_err.u64);
366
367 addr &= ~CVMX_CACHE_LINE_MASK;
368
369
370 l2cdbg.s.ppnum = cvmx_get_core_num();
371 CVMX_SYNC;
372 cvmx_write_csr(CVMX_L2C_DBG, l2cdbg.u64);
373 cvmx_read_csr(CVMX_L2C_DBG);
374
375 lckoff.s.lck_offset = 0;
376 cvmx_write_csr(CVMX_L2C_LCKOFF, lckoff.u64);
377 cvmx_read_csr(CVMX_L2C_LCKOFF);
378
379 if (((union cvmx_l2c_cfg)(cvmx_read_csr(CVMX_L2C_CFG))).s.idxalias) {
380 int alias_shift = CVMX_L2C_IDX_ADDR_SHIFT + 2 * CVMX_L2_SET_BITS - 1;
381 uint64_t addr_tmp = addr ^ (addr & ((1 << alias_shift) - 1)) >> CVMX_L2_SET_BITS;
382
383 lckbase.s.lck_base = addr_tmp >> 7;
384
385 } else {
386 lckbase.s.lck_base = addr >> 7;
387 }
388
389 lckbase.s.lck_ena = 1;
390 cvmx_write_csr(CVMX_L2C_LCKBASE, lckbase.u64);
391
392 cvmx_read_csr(CVMX_L2C_LCKBASE);
393
394 fault_in(addr, CVMX_CACHE_LINE_SIZE);
395
396 lckbase.s.lck_ena = 0;
397 cvmx_write_csr(CVMX_L2C_LCKBASE, lckbase.u64);
398
399 cvmx_read_csr(CVMX_L2C_LCKBASE);
400
401
402 cvmx_write_csr(CVMX_L2C_DBG, 0);
403 cvmx_read_csr(CVMX_L2C_DBG);
404
405 l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
406 if (l2t_err.s.lckerr || l2t_err.s.lckerr2)
407 retval = 1;
408
409 cvmx_spinlock_unlock(&cvmx_l2c_spinlock);
410 return retval;
411 }
412}
413
414int cvmx_l2c_lock_mem_region(uint64_t start, uint64_t len)
415{
416 int retval = 0;
417
418
419 len += start & CVMX_CACHE_LINE_MASK;
420 start &= ~CVMX_CACHE_LINE_MASK;
421 len = (len + CVMX_CACHE_LINE_MASK) & ~CVMX_CACHE_LINE_MASK;
422
423 while (len) {
424 retval += cvmx_l2c_lock_line(start);
425 start += CVMX_CACHE_LINE_SIZE;
426 len -= CVMX_CACHE_LINE_SIZE;
427 }
428 return retval;
429}
430
431void cvmx_l2c_flush(void)
432{
433 uint64_t assoc, set;
434 uint64_t n_assoc, n_set;
435
436 n_set = cvmx_l2c_get_num_sets();
437 n_assoc = cvmx_l2c_get_num_assoc();
438
439 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
440 uint64_t address;
441
442 int assoc_shift = CVMX_L2C_TAG_ADDR_ALIAS_SHIFT;
443 int set_shift = CVMX_L2C_IDX_ADDR_SHIFT;
444
445 for (set = 0; set < n_set; set++) {
446 for (assoc = 0; assoc < n_assoc; assoc++) {
447 address = CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
448 (assoc << assoc_shift) | (set << set_shift));
449 CVMX_CACHE_WBIL2I(address, 0);
450 }
451 }
452 } else {
453 for (set = 0; set < n_set; set++)
454 for (assoc = 0; assoc < n_assoc; assoc++)
455 cvmx_l2c_flush_line(assoc, set);
456 }
457}
458
459
460int cvmx_l2c_unlock_line(uint64_t address)
461{
462
463 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
464 int assoc;
465 union cvmx_l2c_tag tag;
466 uint32_t tag_addr;
467 uint32_t index = cvmx_l2c_address_to_index(address);
468
469 tag_addr = ((address >> CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) & ((1 << CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) - 1));
470
471
472
473
474
475
476
477 for (assoc = 0; assoc < CVMX_L2_ASSOC; assoc++) {
478 tag = cvmx_l2c_get_tag(assoc, index);
479
480 if (tag.s.V && (tag.s.addr == tag_addr)) {
481 CVMX_CACHE_WBIL2(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, address), 0);
482 return tag.s.L;
483 }
484 }
485 } else {
486 int assoc;
487 union cvmx_l2c_tag tag;
488 uint32_t tag_addr;
489
490 uint32_t index = cvmx_l2c_address_to_index(address);
491
492
493 tag_addr = ((address >> CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) & ((1 << CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) - 1));
494 for (assoc = 0; assoc < CVMX_L2_ASSOC; assoc++) {
495 tag = cvmx_l2c_get_tag(assoc, index);
496
497 if (tag.s.V && (tag.s.addr == tag_addr)) {
498 cvmx_l2c_flush_line(assoc, index);
499 return tag.s.L;
500 }
501 }
502 }
503 return 0;
504}
505
506int cvmx_l2c_unlock_mem_region(uint64_t start, uint64_t len)
507{
508 int num_unlocked = 0;
509
510 len += start & CVMX_CACHE_LINE_MASK;
511 start &= ~CVMX_CACHE_LINE_MASK;
512 len = (len + CVMX_CACHE_LINE_MASK) & ~CVMX_CACHE_LINE_MASK;
513 while (len > 0) {
514 num_unlocked += cvmx_l2c_unlock_line(start);
515 start += CVMX_CACHE_LINE_SIZE;
516 len -= CVMX_CACHE_LINE_SIZE;
517 }
518
519 return num_unlocked;
520}
521
522
523
524
525
526union __cvmx_l2c_tag {
527 uint64_t u64;
528 struct cvmx_l2c_tag_cn50xx {
529 __BITFIELD_FIELD(uint64_t reserved:40,
530 __BITFIELD_FIELD(uint64_t V:1,
531 __BITFIELD_FIELD(uint64_t D:1,
532 __BITFIELD_FIELD(uint64_t L:1,
533 __BITFIELD_FIELD(uint64_t U:1,
534 __BITFIELD_FIELD(uint64_t addr:20,
535 ;))))))
536 } cn50xx;
537 struct cvmx_l2c_tag_cn30xx {
538 __BITFIELD_FIELD(uint64_t reserved:41,
539 __BITFIELD_FIELD(uint64_t V:1,
540 __BITFIELD_FIELD(uint64_t D:1,
541 __BITFIELD_FIELD(uint64_t L:1,
542 __BITFIELD_FIELD(uint64_t U:1,
543 __BITFIELD_FIELD(uint64_t addr:19,
544 ;))))))
545 } cn30xx;
546 struct cvmx_l2c_tag_cn31xx {
547 __BITFIELD_FIELD(uint64_t reserved:42,
548 __BITFIELD_FIELD(uint64_t V:1,
549 __BITFIELD_FIELD(uint64_t D:1,
550 __BITFIELD_FIELD(uint64_t L:1,
551 __BITFIELD_FIELD(uint64_t U:1,
552 __BITFIELD_FIELD(uint64_t addr:18,
553 ;))))))
554 } cn31xx;
555 struct cvmx_l2c_tag_cn38xx {
556 __BITFIELD_FIELD(uint64_t reserved:43,
557 __BITFIELD_FIELD(uint64_t V:1,
558 __BITFIELD_FIELD(uint64_t D:1,
559 __BITFIELD_FIELD(uint64_t L:1,
560 __BITFIELD_FIELD(uint64_t U:1,
561 __BITFIELD_FIELD(uint64_t addr:17,
562 ;))))))
563 } cn38xx;
564 struct cvmx_l2c_tag_cn58xx {
565 __BITFIELD_FIELD(uint64_t reserved:44,
566 __BITFIELD_FIELD(uint64_t V:1,
567 __BITFIELD_FIELD(uint64_t D:1,
568 __BITFIELD_FIELD(uint64_t L:1,
569 __BITFIELD_FIELD(uint64_t U:1,
570 __BITFIELD_FIELD(uint64_t addr:16,
571 ;))))))
572 } cn58xx;
573 struct cvmx_l2c_tag_cn58xx cn56xx;
574 struct cvmx_l2c_tag_cn31xx cn52xx;
575};
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591static union __cvmx_l2c_tag __read_l2_tag(uint64_t assoc, uint64_t index)
592{
593
594 uint64_t debug_tag_addr = CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, (index << 7) + 96);
595 uint64_t core = cvmx_get_core_num();
596 union __cvmx_l2c_tag tag_val;
597 uint64_t dbg_addr = CVMX_L2C_DBG;
598 unsigned long flags;
599 union cvmx_l2c_dbg debug_val;
600
601 debug_val.u64 = 0;
602
603
604
605
606
607 debug_val.s.ppnum = core;
608 debug_val.s.l2t = 1;
609 debug_val.s.set = assoc;
610
611 local_irq_save(flags);
612
613
614
615
616 CVMX_SYNC;
617
618 CVMX_DCACHE_INVALIDATE;
619
620
621
622
623
624
625
626
627
628
629 asm volatile (
630 ".set push\n\t"
631 ".set mips64\n\t"
632 ".set noreorder\n\t"
633 "sd %[dbg_val], 0(%[dbg_addr])\n\t"
634 "ld $0, 0(%[dbg_addr])\n\t"
635 "ld %[tag_val], 0(%[tag_addr])\n\t"
636 "sd $0, 0(%[dbg_addr])\n\t"
637 "ld $0, 0(%[dbg_addr])\n\t"
638 "cache 9, 0($0)\n\t"
639 ".set pop"
640 : [tag_val] "=r" (tag_val)
641 : [dbg_addr] "r" (dbg_addr), [dbg_val] "r" (debug_val), [tag_addr] "r" (debug_tag_addr)
642 : "memory");
643
644 local_irq_restore(flags);
645
646 return tag_val;
647}
648
649
650union cvmx_l2c_tag cvmx_l2c_get_tag(uint32_t association, uint32_t index)
651{
652 union cvmx_l2c_tag tag;
653
654 tag.u64 = 0;
655 if ((int)association >= cvmx_l2c_get_num_assoc()) {
656 cvmx_dprintf("ERROR: cvmx_l2c_get_tag association out of range\n");
657 return tag;
658 }
659 if ((int)index >= cvmx_l2c_get_num_sets()) {
660 cvmx_dprintf("ERROR: cvmx_l2c_get_tag index out of range (arg: %d, max: %d)\n",
661 (int)index, cvmx_l2c_get_num_sets());
662 return tag;
663 }
664 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
665 union cvmx_l2c_tadx_tag l2c_tadx_tag;
666 uint64_t address = CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
667 (association << CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) |
668 (index << CVMX_L2C_IDX_ADDR_SHIFT));
669
670
671
672
673
674
675 CVMX_CACHE_LTGL2I(address, 0);
676 CVMX_SYNC;
677 l2c_tadx_tag.u64 = cvmx_read_csr(CVMX_L2C_TADX_TAG(0));
678
679 tag.s.V = l2c_tadx_tag.s.valid;
680 tag.s.D = l2c_tadx_tag.s.dirty;
681 tag.s.L = l2c_tadx_tag.s.lock;
682 tag.s.U = l2c_tadx_tag.s.use;
683 tag.s.addr = l2c_tadx_tag.s.tag;
684 } else {
685 union __cvmx_l2c_tag tmp_tag;
686
687 tmp_tag = __read_l2_tag(association, index);
688
689
690
691
692
693 if (OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN56XX)) {
694 tag.s.V = tmp_tag.cn58xx.V;
695 tag.s.D = tmp_tag.cn58xx.D;
696 tag.s.L = tmp_tag.cn58xx.L;
697 tag.s.U = tmp_tag.cn58xx.U;
698 tag.s.addr = tmp_tag.cn58xx.addr;
699 } else if (OCTEON_IS_MODEL(OCTEON_CN38XX)) {
700 tag.s.V = tmp_tag.cn38xx.V;
701 tag.s.D = tmp_tag.cn38xx.D;
702 tag.s.L = tmp_tag.cn38xx.L;
703 tag.s.U = tmp_tag.cn38xx.U;
704 tag.s.addr = tmp_tag.cn38xx.addr;
705 } else if (OCTEON_IS_MODEL(OCTEON_CN31XX) || OCTEON_IS_MODEL(OCTEON_CN52XX)) {
706 tag.s.V = tmp_tag.cn31xx.V;
707 tag.s.D = tmp_tag.cn31xx.D;
708 tag.s.L = tmp_tag.cn31xx.L;
709 tag.s.U = tmp_tag.cn31xx.U;
710 tag.s.addr = tmp_tag.cn31xx.addr;
711 } else if (OCTEON_IS_MODEL(OCTEON_CN30XX)) {
712 tag.s.V = tmp_tag.cn30xx.V;
713 tag.s.D = tmp_tag.cn30xx.D;
714 tag.s.L = tmp_tag.cn30xx.L;
715 tag.s.U = tmp_tag.cn30xx.U;
716 tag.s.addr = tmp_tag.cn30xx.addr;
717 } else if (OCTEON_IS_MODEL(OCTEON_CN50XX)) {
718 tag.s.V = tmp_tag.cn50xx.V;
719 tag.s.D = tmp_tag.cn50xx.D;
720 tag.s.L = tmp_tag.cn50xx.L;
721 tag.s.U = tmp_tag.cn50xx.U;
722 tag.s.addr = tmp_tag.cn50xx.addr;
723 } else {
724 cvmx_dprintf("Unsupported OCTEON Model in %s\n", __func__);
725 }
726 }
727 return tag;
728}
729
730uint32_t cvmx_l2c_address_to_index(uint64_t addr)
731{
732 uint64_t idx = addr >> CVMX_L2C_IDX_ADDR_SHIFT;
733 int indxalias = 0;
734
735 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
736 union cvmx_l2c_ctl l2c_ctl;
737
738 l2c_ctl.u64 = cvmx_read_csr(CVMX_L2C_CTL);
739 indxalias = !l2c_ctl.s.disidxalias;
740 } else {
741 union cvmx_l2c_cfg l2c_cfg;
742
743 l2c_cfg.u64 = cvmx_read_csr(CVMX_L2C_CFG);
744 indxalias = l2c_cfg.s.idxalias;
745 }
746
747 if (indxalias) {
748 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
749 uint32_t a_14_12 = (idx / (CVMX_L2C_MEMBANK_SELECT_SIZE/(1<<CVMX_L2C_IDX_ADDR_SHIFT))) & 0x7;
750
751 idx ^= idx / cvmx_l2c_get_num_sets();
752 idx ^= a_14_12;
753 } else {
754 idx ^= ((addr & CVMX_L2C_ALIAS_MASK) >> CVMX_L2C_TAG_ADDR_ALIAS_SHIFT);
755 }
756 }
757 idx &= CVMX_L2C_IDX_MASK;
758 return idx;
759}
760
761int cvmx_l2c_get_cache_size_bytes(void)
762{
763 return cvmx_l2c_get_num_sets() * cvmx_l2c_get_num_assoc() *
764 CVMX_CACHE_LINE_SIZE;
765}
766
767
768
769
770
771int cvmx_l2c_get_set_bits(void)
772{
773 int l2_set_bits;
774
775 if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN58XX))
776 l2_set_bits = 11;
777 else if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN63XX))
778 l2_set_bits = 10;
779 else if (OCTEON_IS_MODEL(OCTEON_CN31XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
780 l2_set_bits = 9;
781 else if (OCTEON_IS_MODEL(OCTEON_CN30XX))
782 l2_set_bits = 8;
783 else if (OCTEON_IS_MODEL(OCTEON_CN50XX))
784 l2_set_bits = 7;
785 else {
786 cvmx_dprintf("Unsupported OCTEON Model in %s\n", __func__);
787 l2_set_bits = 11;
788 }
789 return l2_set_bits;
790}
791
792
793int cvmx_l2c_get_num_sets(void)
794{
795 return 1 << cvmx_l2c_get_set_bits();
796}
797
798
799int cvmx_l2c_get_num_assoc(void)
800{
801 int l2_assoc;
802
803 if (OCTEON_IS_MODEL(OCTEON_CN56XX) ||
804 OCTEON_IS_MODEL(OCTEON_CN52XX) ||
805 OCTEON_IS_MODEL(OCTEON_CN58XX) ||
806 OCTEON_IS_MODEL(OCTEON_CN50XX) ||
807 OCTEON_IS_MODEL(OCTEON_CN38XX))
808 l2_assoc = 8;
809 else if (OCTEON_IS_MODEL(OCTEON_CN63XX))
810 l2_assoc = 16;
811 else if (OCTEON_IS_MODEL(OCTEON_CN31XX) ||
812 OCTEON_IS_MODEL(OCTEON_CN30XX))
813 l2_assoc = 4;
814 else {
815 cvmx_dprintf("Unsupported OCTEON Model in %s\n", __func__);
816 l2_assoc = 8;
817 }
818
819
820 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
821 union cvmx_mio_fus_dat3 mio_fus_dat3;
822
823 mio_fus_dat3.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT3);
824
825
826
827
828
829
830
831
832
833
834
835
836
837 if (mio_fus_dat3.s.l2c_crip == 3)
838 l2_assoc = 4;
839 else if (mio_fus_dat3.s.l2c_crip == 2)
840 l2_assoc = 8;
841 else if (mio_fus_dat3.s.l2c_crip == 1)
842 l2_assoc = 12;
843 } else {
844 uint64_t l2d_fus3;
845
846 l2d_fus3 = cvmx_read_csr(CVMX_L2D_FUS3);
847
848
849
850
851
852 if ((l2d_fus3 >> 35) & 0x1)
853 l2_assoc = l2_assoc >> 2;
854 else if ((l2d_fus3 >> 34) & 0x1)
855 l2_assoc = l2_assoc >> 1;
856 }
857 return l2_assoc;
858}
859
860
861
862
863
864
865
866
867
868void cvmx_l2c_flush_line(uint32_t assoc, uint32_t index)
869{
870
871 if (index > (uint32_t)cvmx_l2c_get_num_sets()) {
872 cvmx_dprintf("ERROR: cvmx_l2c_flush_line index out of range.\n");
873 return;
874 }
875
876
877 if (assoc > (uint32_t)cvmx_l2c_get_num_assoc()) {
878 cvmx_dprintf("ERROR: cvmx_l2c_flush_line association out of range.\n");
879 return;
880 }
881
882 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
883 uint64_t address;
884
885
886
887
888
889 address = CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
890 (assoc << CVMX_L2C_TAG_ADDR_ALIAS_SHIFT) |
891 (index << CVMX_L2C_IDX_ADDR_SHIFT));
892 CVMX_CACHE_WBIL2I(address, 0);
893 } else {
894 union cvmx_l2c_dbg l2cdbg;
895
896 l2cdbg.u64 = 0;
897 if (!OCTEON_IS_MODEL(OCTEON_CN30XX))
898 l2cdbg.s.ppnum = cvmx_get_core_num();
899 l2cdbg.s.finv = 1;
900
901 l2cdbg.s.set = assoc;
902 cvmx_spinlock_lock(&cvmx_l2c_spinlock);
903
904
905
906
907 CVMX_SYNC;
908 cvmx_write_csr(CVMX_L2C_DBG, l2cdbg.u64);
909 cvmx_read_csr(CVMX_L2C_DBG);
910
911 CVMX_PREPARE_FOR_STORE(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
912 index * CVMX_CACHE_LINE_SIZE),
913 0);
914
915 CVMX_SYNC;
916 cvmx_write_csr(CVMX_L2C_DBG, 0);
917 cvmx_read_csr(CVMX_L2C_DBG);
918 cvmx_spinlock_unlock(&cvmx_l2c_spinlock);
919 }
920}
921