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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* VM - Hardware Address Translation management.
*
* This file describes the contents of the sun reference mmu (sfmmu)
* specific hat data structures and the sfmmu specific hat procedures.
* The machine independent interface is described in <vm/hat.h>.
*/
#ifndef _VM_MACH_SFMMU_H
#define _VM_MACH_SFMMU_H
#include <sys/x_call.h>
#include <sys/cheetahregs.h>
#include <sys/spitregs.h>
#include <sys/opl_olympus_regs.h>
#include <sys/mmu.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* On sun4u platforms, user TSBs are accessed via virtual address by default.
* Platforms that support ASI_SCRATCHPAD registers can define UTSB_PHYS in the
* platform Makefile to access user TSBs via physical address but must also
* designate one ASI_SCRATCHPAD register to hold the second user TSB. To
* designate the user TSB scratchpad register, platforms must provide a
* definition for SCRATCHPAD_UTSBREG2 below.
*
* Platforms that use UTSB_PHYS do not allocate 2 locked TLB entries to access
* the user TSBs.
*/
#if defined(UTSB_PHYS)
#if defined(_OPL)
#define SCRATCHPAD_UTSBREG2 OPL_SCRATCHPAD_UTSBREG4 /* 4M-256M pages */
#define SCRATCHPAD_UTSBREG3 OPL_SCRATCHPAD_UTSBREG5 /* 8K-512K pages */
#define SCRATCHPAD_UTSBREG4 OPL_SCRATCHPAD_UTSBREG6 /* 4M-256M pages */
#else
#error "Compiling UTSB_PHYS but no SCRATCHPAD_UTSBREG2 specified"
#endif /* _OPL */
#endif /* UTSB_PHYS */
#ifdef _ASM
/*
* This macro is used to set private/shared secondary context register in
* sfmmu_alloc_ctx().
* if is_shctx = 0 then we set the SCONTEXT to cnum and invalidate the
* SHARED_CONTEXT register. If is_shctx = 1 then only the SHARED_CONTEXT
* register is set.
* (See additional comments in sfmmu_alloc_ctx)
* Input:
* cnum = cnum
* is_shctx = sfmmu private/shared flag (0: private, 1: shared)
* tmp1 : %o4 scratch
* tmp2 : %o5 scratch
* label: used as local branch targets
*/
#define SET_SECCTX(cnum, is_shctx, tmp1, tmp2, label) \
/* BEGIN CSTYLED */ \
brnz,pn is_shctx, label/**/1 ;\
sethi %hi(FLUSH_ADDR), tmp2 ;\
mov MMU_SCONTEXT, tmp1 ;\
stxa cnum, [tmp1]ASI_MMU_CTX ;\
flush tmp2 ;\
sethi %hi(shctx_on), tmp1 ;\
ld [tmp1 + %lo(shctx_on)], tmp1 ;\
brz,pt tmp1, label/**/3 ;\
mov %g0, cnum ;\
ba,pt %xcc, label/**/2 ;\
label/**/1: ;\
set SHCTXREG_VALID_BIT, tmp1 ;\
sllx cnum, CTXREG_CTX_SHIFT, cnum ;\
srlx cnum, CTXREG_CTX_SHIFT, cnum ;\
or cnum, tmp1, cnum ;\
mov cnum, tmp1 ;\
sllx cnum, 32, cnum ;\
or cnum, tmp1, cnum ;\
label/**/2: ;\
mov MMU_SHARED_CONTEXT, tmp1 ;\
stxa cnum, [tmp1]ASI_MMU_CTX ;\
flush tmp2 ;\
label/**/3:
/* END CSTYLED */
/*
* This macro is used in the MMU code to check if TL should be lowered from
* 2 to 1 to pop trapstat's state. See the block comment in trapstat.c
* for details.
*/
#define TSTAT_CHECK_TL1(label, scr1, scr2) \
rdpr %tpc, scr1; \
sethi %hi(KERNELBASE), scr2; \
or scr2, %lo(KERNELBASE), scr2; \
cmp scr1, scr2; \
bgeu %xcc, 9f; \
nop; \
ba label; \
wrpr %g0, 1, %tl; \
9:
/*
* The following macros allow us to share majority of the
* SFMMU code between sun4u and sun4v platforms.
*/
#define SETUP_TSB_ASI(qlp, tmp) \
movrz qlp, ASI_N, tmp; \
movrnz qlp, ASI_MEM, tmp; \
mov tmp, %asi
/*
* Macro to swtich to alternate global register on sun4u platforms
* (not applicable to sun4v platforms)
*/
#define USE_ALTERNATE_GLOBALS(scr) \
rdpr %pstate, scr; \
wrpr scr, PSTATE_MG | PSTATE_AG, %pstate
/*
* Macro to set %gl register value on sun4v platforms
* (not applicable to sun4u platforms)
*/
#define SET_GL_REG(val)
/*
* Get MMU data tag access register value
*
* In:
* tagacc, scr1 = scratch registers
* Out:
* tagacc = MMU data tag access register value
*/
#define GET_MMU_D_TAGACC(tagacc, scr1) \
mov MMU_TAG_ACCESS, scr1; \
ldxa [scr1]ASI_DMMU, tagacc
/*
* Get MMU data tag target register
*
* In:
* ttarget, scr1 = scratch registers
* Out:
* ttarget = MMU data tag target register value
*/
#define GET_MMU_D_TTARGET(ttarget, scr1) \
ldxa [%g0]ASI_DMMU, ttarget
/*
* Get MMU data/instruction tag access register values
*
* In:
* dtagacc, itagacc, scr1, scr2 = scratch registers
* Out:
* dtagacc = MMU data tag access register value
* itagacc = MMU instruction tag access register value
*/
#define GET_MMU_BOTH_TAGACC(dtagacc, itagacc, scr1, scr2) \
mov MMU_TAG_ACCESS, scr1; \
ldxa [scr1]ASI_DMMU, dtagacc; \
ldxa [scr1]ASI_IMMU, itagacc
/*
* Get MMU data fault address from the tag access register
*
* In:
* daddr, scr1 = scratch registers
* Out:
* daddr = MMU data fault address
*/
#define GET_MMU_D_ADDR(daddr, scr1) \
mov MMU_TAG_ACCESS, scr1; \
ldxa [scr1]ASI_DMMU, daddr; \
set TAGACC_CTX_MASK, scr1; \
andn daddr, scr1, daddr
/*
* Load ITLB entry
*
* In:
* tte = reg containing tte
* scr1, scr2, scr3, scr4 = scratch registers (not used)
*/
#define ITLB_STUFF(tte, scr1, scr2, scr3, scr4) \
stxa tte, [%g0]ASI_ITLB_IN
/*
* Load DTLB entry
*
* In:
* tte = reg containing tte
* scr1, scr2, scr3, scr4 = scratch register (not used)
*/
#define DTLB_STUFF(tte, scr1, scr2, scr3, scr4) \
stxa tte, [%g0]ASI_DTLB_IN
/*
* Returns PFN given the TTE and vaddr
*
* In:
* tte = reg containing tte
* vaddr = reg containing vaddr
* scr1, scr2, scr3 = scratch registers
* Out:
* tte = PFN value
*/
#define TTETOPFN(tte, vaddr, label, scr1, scr2, scr3) \
srlx tte, TTE_SZ_SHFT, scr1; \
and scr1, TTE_SZ_BITS, scr1; /* scr1 = tte_size */ \
srlx tte, TTE_SZ2_SHFT, scr3; \
and scr3, TTE_SZ2_BITS, scr3; /* scr3 = tte_size2 */ \
or scr1, scr3, scr1; \
sllx scr1, 1, scr2; \
add scr2, scr1, scr2; /* mulx 3 */ \
sllx tte, TTE_PA_LSHIFT, tte; \
add scr2, MMU_PAGESHIFT + TTE_PA_LSHIFT, scr3; \
/* BEGIN CSTYLED */ \
brz,pt scr2, label/**/1; \
srlx tte, scr3, tte; \
/* END CSTYLED */ \
sllx tte, scr2, tte; \
set 1, scr1; \
add scr2, MMU_PAGESHIFT, scr3; \
sllx scr1, scr3, scr1; \
sub scr1, 1, scr1; /* g2=TTE_PAGE_OFFSET(ttesz) */ \
and vaddr, scr1, scr2; \
srln scr2, MMU_PAGESHIFT, scr2; \
or tte, scr2, tte; \
/* CSTYLED */ \
label/**/1:
/*
* TTE_SET_REF_ML is a macro that updates the reference bit if it is
* not already set. Older sun4u platform use the virtual address to
* flush entries from dcache, this is not available here but there are
* only two positions in the 64K dcache where the cache line can reside
* so we need to flush both of them.
*
* Parameters:
* tte = reg containing tte
* ttepa = physical pointer to tte
* tsbarea = tsb miss area
* tmp1 = tmp reg
* tmp2 = tmp reg
* label = temporary label
*/
#define TTE_SET_REF_ML(tte, ttepa, tsbarea, tmp1, tmp2, label) \
/* BEGIN CSTYLED */ \
/* check reference bit */ \
andcc tte, TTE_REF_INT, %g0; \
bnz,pt %xcc, label/**/4; /* if ref bit set-skip ahead */ \
nop; \
GET_CPU_IMPL(tmp1); \
cmp tmp1, SPITFIRE_IMPL; \
blt %icc, label/**/2; /* skip flush if FJ-OPL cpus */ \
cmp tmp1, CHEETAH_IMPL; \
bl,a %icc, label/**/1; \
/* update reference bit */ \
lduh [tsbarea + TSBMISS_DMASK], tmp1; \
stxa %g0, [ttepa]ASI_DC_INVAL; /* flush line from dcache */ \
membar #Sync; \
ba label/**/2; \
label/**/1: \
and ttepa, tmp1, tmp1; \
stxa %g0, [tmp1]ASI_DC_TAG; /* flush line1 from dcache */ \
or %g0, 1, tmp2; \
sllx tmp2, MMU_PAGESHIFT, tmp2; \
xor tmp1, tmp2, tmp1; \
stxa %g0, [tmp1]ASI_DC_TAG; /* flush line2 from dcache */ \
membar #Sync; \
label/**/2: \
or tte, TTE_REF_INT, tmp1; \
casxa [ttepa]ASI_MEM, tte, tmp1; /* update ref bit */ \
cmp tte, tmp1; \
bne,a,pn %xcc, label/**/2; \
ldxa [ttepa]ASI_MEM, tte; /* MMU_READTTE through pa */ \
or tte, TTE_REF_INT, tte; \
label/**/4: \
/* END CSTYLED */
/*
* TTE_SET_REFMOD_ML is a macro that updates the reference and modify bits
* if not already set.
*
* Parameters:
* tte = reg containing tte
* ttepa = physical pointer to tte
* tsbarea = tsb miss area
* tmp1 = tmp reg
* tmp2 = tmp reg
* label = temporary label
* exitlabel = label where to jump to if write perm bit not set.
*/
#define TTE_SET_REFMOD_ML(tte, ttepa, tsbarea, tmp1, tmp2, label, \
exitlabel) \
/* BEGIN CSTYLED */ \
/* check reference bit */ \
andcc tte, TTE_WRPRM_INT, %g0; \
bz,pn %xcc, exitlabel; /* exit if wr_perm not set */ \
nop; \
andcc tte, TTE_HWWR_INT, %g0; \
bnz,pn %xcc, label/**/4; /* nothing to do */ \
nop; \
GET_CPU_IMPL(tmp1); \
cmp tmp1, SPITFIRE_IMPL; \
blt %icc, label/**/2; /* skip flush if FJ-OPL cpus */ \
cmp tmp1, CHEETAH_IMPL; \
bl,a %icc, label/**/1; \
/* update reference bit */ \
lduh [tsbarea + TSBMISS_DMASK], tmp1; \
stxa %g0, [ttepa]ASI_DC_INVAL; /* flush line from dcache */ \
membar #Sync; \
ba label/**/2; \
label/**/1: \
and ttepa, tmp1, tmp1; \
stxa %g0, [tmp1]ASI_DC_TAG; /* flush line1 from dcache */ \
or %g0, 1, tmp2; \
sllx tmp2, MMU_PAGESHIFT, tmp2; \
xor tmp1, tmp2, tmp1; \
stxa %g0, [tmp1]ASI_DC_TAG; /* flush line2 from dcache */ \
membar #Sync; \
label/**/2: \
or tte, TTE_HWWR_INT | TTE_REF_INT, tmp1; \
casxa [ttepa]ASI_MEM, tte, tmp1; /* update ref/mod bit */ \
cmp tte, tmp1; \
bne,a,pn %xcc, label/**/2; \
ldxa [ttepa]ASI_MEM, tte; /* MMU_READTTE through pa */ \
or tte, TTE_HWWR_INT | TTE_REF_INT, tte; \
label/**/4: \
/* END CSTYLED */
#ifndef UTSB_PHYS
/*
* Synthesize TSB base register contents for a process with
* a single TSB.
*
* We patch the virtual address mask in at runtime since the
* number of significant virtual address bits in the TSB VA
* can vary depending upon the TSB slab size being used on the
* machine.
*
* In:
* tsbinfo = TSB info pointer (ro)
* vabase = value of utsb_vabase (ro)
* Out:
* tsbreg = value to program into TSB base register
*/
#define MAKE_TSBREG(tsbreg, tsbinfo, vabase, tmp1, tmp2, label) \
/* BEGIN CSTYLED */ \
ldx [tsbinfo + TSBINFO_VADDR], tmp1; \
.global label/**/_tsbreg_vamask ;\
label/**/_tsbreg_vamask: \
or %g0, RUNTIME_PATCH, tsbreg; \
lduh [tsbinfo + TSBINFO_SZCODE], tmp2; \
sllx tsbreg, TSBREG_VAMASK_SHIFT, tsbreg; \
or vabase, tmp2, tmp2; \
and tmp1, tsbreg, tsbreg; \
or tsbreg, tmp2, tsbreg; \
/* END CSTYLED */
/*
* Synthesize TSB base register contents for a process with
* two TSBs. See hat_sfmmu.h for the layout of the TSB base
* register in this case.
*
* In:
* tsb1 = pointer to first TSB info (ro)
* tsb2 = pointer to second TSB info (ro)
* Out:
* tsbreg = value to program into TSB base register
*/
#define MAKE_TSBREG_SECTSB(tsbreg, tsb1, tsb2, tmp1, tmp2, tmp3, label) \
/* BEGIN CSTYLED */ \
set TSBREG_MSB_CONST, tmp3 ;\
sllx tmp3, TSBREG_MSB_SHIFT, tsbreg ;\
.global label/**/_tsbreg_vamask ;\
label/**/_tsbreg_vamask: ;\
or %g0, RUNTIME_PATCH, tmp3 ;\
sll tmp3, TSBREG_VAMASK_SHIFT, tmp3 ;\
ldx [tsb1 + TSBINFO_VADDR], tmp1 ;\
ldx [tsb2 + TSBINFO_VADDR], tmp2 ;\
and tmp1, tmp3, tmp1 ;\
and tmp2, tmp3, tmp2 ;\
sllx tmp2, TSBREG_SECTSB_MKSHIFT, tmp2 ;\
or tmp1, tmp2, tmp3 ;\
or tsbreg, tmp3, tsbreg ;\
lduh [tsb1 + TSBINFO_SZCODE], tmp1 ;\
lduh [tsb2 + TSBINFO_SZCODE], tmp2 ;\
and tmp1, TSB_SOFTSZ_MASK, tmp1 ;\
and tmp2, TSB_SOFTSZ_MASK, tmp2 ;\
sllx tmp2, TSBREG_SECSZ_SHIFT, tmp2 ;\
or tmp1, tmp2, tmp3 ;\
or tsbreg, tmp3, tsbreg ;\
/* END CSTYLED */
/*
* Load the locked TSB TLB entry.
*
* In:
* tsbinfo = tsb_info pointer as va (ro)
* tteidx = shifted index into TLB to load the locked entry (ro)
* va = virtual address at which to load the locked TSB entry (ro)
* Out:
* Scratch:
* tmp
*/
#define LOAD_TSBTTE(tsbinfo, tteidx, va, tmp) \
mov MMU_TAG_ACCESS, tmp; \
stxa va, [tmp]ASI_DMMU; /* set tag access */ \
membar #Sync; \
ldx [tsbinfo + TSBINFO_TTE], tmp; /* fetch locked tte */ \
stxa tmp, [tteidx]ASI_DTLB_ACCESS; /* load locked tte */ \
membar #Sync
/*
* In the current implementation, TSBs usually come from physically
* contiguous chunks of memory up to 4MB in size, but 8K TSBs may be
* allocated from 8K chunks of memory under certain conditions. To
* prevent aliasing in the virtual address cache when the TSB slab is
* 8K in size we must align the reserved (TL>0) TSB virtual address to
* have the same low-order bits as the kernel (TL=0) TSB virtual address,
* and map 8K TSBs with an 8K TTE. In cases where the TSB reserved VA
* range is smaller than the assumed 4M we will patch the shift at
* runtime; otherwise we leave it alone (which is why RUNTIME_PATCH
* constant doesn't appear below).
*
* In:
* tsbinfo (ro)
* resva: reserved VA base for this TSB
* Out:
* resva: corrected VA for this TSB
*/
#define RESV_OFFSET(tsbinfo, resva, tmp1, label) \
/* BEGIN CSTYLED */ \
lduh [tsbinfo + TSBINFO_SZCODE], tmp1 ;\
brgz,pn tmp1, label/**/9 ;\
nop ;\
ldx [tsbinfo + TSBINFO_VADDR], tmp1 ;\
.global label/**/_resv_offset ;\
label/**/_resv_offset: ;\
sllx tmp1, (64 - MMU_PAGESHIFT4M), tmp1 ;\
srlx tmp1, (64 - MMU_PAGESHIFT4M), tmp1 ;\
or tmp1, resva, resva ;\
label/**/9: \
/* END CSTYLED */
/*
* Determine the pointer of the entry in the first TSB to probe given
* the 8K TSB pointer register contents.
*
* In:
* tsbp8k = 8K TSB pointer register (ro)
* tmp = scratch register
* label = label for hot patching of utsb_vabase
*
* Out: tsbe_ptr = TSB entry address
*
* Note: This function is patched at runtime for performance reasons.
* Any changes here require sfmmu_patch_utsb fixed.
*/
#define GET_1ST_TSBE_PTR(tsbp8k, tsbe_ptr, tmp, label) \
/* BEGIN CSTYLED */ \
label/**/_get_1st_tsbe_ptr: ;\
RUNTIME_PATCH_SETX(tsbe_ptr, tmp) ;\
/* tsbeptr = contents of utsb_vabase */ ;\
/* clear upper bits leaving just bits 21:0 of TSB ptr. */ ;\
sllx tsbp8k, TSBREG_FIRTSB_SHIFT, tmp ;\
/* finish clear */ ;\
srlx tmp, TSBREG_FIRTSB_SHIFT, tmp ;\
/* or-in bits 41:22 of the VA to form the real pointer. */ ;\
or tsbe_ptr, tmp, tsbe_ptr \
/* END CSTYLED */
/*
* Determine the base address of the second TSB given the 8K TSB
* pointer register contents.
*
* In:
* tsbp8k = 8K TSB pointer register (ro)
* tmp = scratch register
* label = label for hot patching of utsb_vabase
*
* Out:
* tsbbase = TSB base address
*
* Note: This function is patched at runtime for performance reasons.
* Any changes here require sfmmu_patch_utsb fixed.
*/
#define GET_2ND_TSB_BASE(tsbp8k, tsbbase, tmp, label) \
/* BEGIN CSTYLED */ \
label/**/_get_2nd_tsb_base: ;\
RUNTIME_PATCH_SETX(tsbbase, tmp) ;\
/* tsbbase = contents of utsb4m_vabase */ ;\
/* clear upper bits leaving just bits 21:xx of TSB addr. */ ;\
sllx tsbp8k, TSBREG_SECTSB_LSHIFT, tmp ;\
/* clear lower bits leaving just 21:13 in 8:0 */ ;\
srlx tmp, (TSBREG_SECTSB_RSHIFT + MMU_PAGESHIFT), tmp ;\
/* adjust TSB offset to bits 21:13 */ ;\
sllx tmp, MMU_PAGESHIFT, tmp ;\
or tsbbase, tmp, tsbbase ;\
/* END CSTYLED */
/*
* Determine the size code of the second TSB given the 8K TSB
* pointer register contents.
*
* In:
* tsbp8k = 8K TSB pointer register (ro)
* Out:
* size = TSB size code
*/
#define GET_2ND_TSB_SIZE(tsbp8k, size) \
srlx tsbp8k, TSBREG_SECSZ_SHIFT, size; \
and size, TSB_SOFTSZ_MASK, size
/*
* Get the location in the 2nd TSB of the tsbe for this fault.
* Assumes that the second TSB only contains 4M mappings.
*
* In:
* tagacc = tag access register (clobbered)
* tsbp8k = contents of TSB8K pointer register (ro)
* tmp1, tmp2 = scratch registers
* label = label at which to patch in reserved TSB 4M VA range
* Out:
* tsbe_ptr = pointer to the tsbe in the 2nd TSB
*/
#define GET_2ND_TSBE_PTR(tagacc, tsbp8k, tsbe_ptr, tmp1, tmp2, label) \
GET_2ND_TSB_BASE(tsbp8k, tsbe_ptr, tmp2, label); \
/* tsbe_ptr = TSB base address, tmp2 = junk */ \
GET_2ND_TSB_SIZE(tsbp8k, tmp1); \
/* tmp1 = TSB size code */ \
GET_TSBE_POINTER(MMU_PAGESHIFT4M, tsbe_ptr, tagacc, tmp1, tmp2)
#else /* !UTSB_PHYS */
/*
* Determine the pointer of the entry in the first TSB to probe given
* the 8K TSB pointer register contents.
*
* In:
* tagacc = tag access register
* tsbe_ptr = 8K TSB pointer register
* tmp = scratch registers
*
* Out: tsbe_ptr = TSB entry address
*
* Note: This macro is a nop since the 8K TSB pointer register
* is the entry pointer and does not need to be decoded.
* It is defined to allow for code sharing with sun4v.
*/
#define GET_1ST_TSBE_PTR(tagacc, tsbe_ptr, tmp1, tmp2)
#endif /* !UTSB_PHYS */
/*
* Load TSB base register. In the single TSB case this register
* contains utsb_vabase, bits 21:13 of tsbinfo->tsb_va, and the
* TSB size code in bits 2:0. See hat_sfmmu.h for the layout in
* the case where we have multiple TSBs per process.
*
* In:
* tsbreg = value to load (ro)
*/
#define LOAD_TSBREG(tsbreg, tmp1, tmp2) \
mov MMU_TSB, tmp1; \
sethi %hi(FLUSH_ADDR), tmp2; \
stxa tsbreg, [tmp1]ASI_DMMU; /* dtsb reg */ \
stxa tsbreg, [tmp1]ASI_IMMU; /* itsb reg */ \
flush tmp2
#ifdef UTSB_PHYS
#define UTSB_PROBE_ASI ASI_QUAD_LDD_PHYS
#else
#define UTSB_PROBE_ASI ASI_NQUAD_LD
#endif
#define PROBE_TSB(tsbe_ptr, tag, tsbtag, label) \
/* BEGIN CSTYLED */ \
ldda [tsbe_ptr]UTSB_PROBE_ASI, tsbtag ;\
cmp tsbtag, tag /* compare tag w/ TSB */ ;\
bne,pn %xcc, label/**/1 /* branch if !match */ ;\
nop \
/* END CSTYLED */
/*
* Probe a TSB. If miss continue from the end of the macro for most probes
* except jump to TSB miss for 3rd ITSB probe. If hit retry faulted
* instruction for DTSB probes. For ITSB probes in case of TSB hit check
* execute bit and branch to exec_fault if the bit is not set otherwise retry
* faulted instruction. Do ITLB synthesis in case of hit in second ITSB if
* synthesis bit is set.
*
* tsbe_ptr = precomputed TSB entry pointer (in, ro)
* vpg_4m = 4M virtual page number for tag matching (in, ro)
* label = where to branch to if this is a miss (text)
*
* For trapstat, we have to explicily use these registers.
* g4 = location tag will be retrieved into from TSB (out)
* g5 = location data(tte) will be retrieved into from TSB (out)
*
* In case of first tsb probe tsbe_ptr is %g1. For other tsb probes
* move tsbe_ptr into %g1 in case of hit for traptrace.
*
* If the probe fails and we continue from call site %g4-%g5 are clobbered.
* 2nd ITSB probe macro will also clobber %g6 in this case.
*/
#define PROBE_1ST_DTSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_TSB(tsbe_ptr, vpg_4m, %g4, label) ;\
TT_TRACE(trace_tsbhit) ;\
DTLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1: \
/* END CSTYLED */
#define PROBE_2ND_DTSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_TSB(tsbe_ptr, vpg_4m, %g4, label) ;\
mov tsbe_ptr, %g1 /* trace_tsbhit wants ptr in %g1 */ ;\
TT_TRACE(trace_tsbhit) ;\
DTLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1: \
/* END CSTYLED */
#define PROBE_1ST_ITSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_TSB(tsbe_ptr, vpg_4m, %g4, label) ;\
andcc %g5, TTE_EXECPRM_INT, %g0 /* check execute bit */ ;\
bz,pn %icc, exec_fault ;\
nop ;\
TT_TRACE(trace_tsbhit) ;\
ITLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1: \
/* END CSTYLED */
#define PROBE_2ND_ITSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
ldda [tsbe_ptr]UTSB_PROBE_ASI, %g4 /* g4 = tag, g5 = data */ ;\
cmp %g4, vpg_4m /* compare tag w/ TSB */ ;\
bne,pn %xcc, label/**/2 /* branch if !match */ ;\
or %g0, TTE4M, %g6 ;\
andcc %g5, TTE_EXECPRM_INT, %g0 /* check execute bit */ ;\
bz,a,pn %icc, label/**/1 ;\
sllx %g6, TTE_SZ_SHFT, %g6 ;\
mov tsbe_ptr, %g1 /* trap trace wants ptr in %g1 */ ;\
TT_TRACE(trace_tsbhit) ;\
ITLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1: ;\
andcc %g5, TTE_E_SYNTH_INT, %g0 ;\
bz,pn %icc, exec_fault ;\
mov tsbe_ptr, %g1 /* trap trace wants ptr in %g1 */ ;\
or %g5, %g6, %g5 ;\
TT_TRACE(trace_tsbhit) ;\
ITLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/2:
/* END CSTYLED */
#ifdef UTSB_PHYS
/*
* Updates the context filed in the tagaccess register with the shared
* context to force the next i/DTLB_STUFF() to load this mapping into
* the TLB with the shared context.
*/
#define SET_SHCTX_TAGACC(tmp1, tmp2, asi) \
/* BEGIN CSTYLED */ \
mov MMU_TAG_ACCESS, tmp2 ;\
ldxa [tmp2]asi, tmp2 /* tmp2 = VA|CTX */ ;\
srlx tmp2, TAGACC_SHIFT, tmp2 ;\
sllx tmp2, TAGACC_SHIFT, tmp2 /* tmp2 = VA */ ;\
mov MMU_SHARED_CONTEXT, tmp1 /* clobber tsbe_ptr */ ;\
ldxa [tmp1]ASI_MMU_CTX, tmp1 /* tmp2 = shctx reg */ ;\
sllx tmp1, SHCTXREG_CTX_LSHIFT, tmp1 ;\
srlx tmp1, SHCTXREG_CTX_LSHIFT, tmp1 /* tmp1 = SHCTX */ ;\
or tmp1, tmp2, tmp1 /* tmp1 = VA|SHCTX */ ;\
mov MMU_TAG_ACCESS, tmp2 ;\
stxa tmp1, [tmp2]asi /* asi = VA|SHCTX */
/* END CSTYLED */
#define PROBE_SHCTX_DTSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_TSB(tsbe_ptr, vpg_4m, %g4, label) ;\
mov tsbe_ptr, %g1 /* trace_tsbhit wants ptr in %g1 */ ;\
TT_TRACE(trace_tsbhit) ;\
SET_SHCTX_TAGACC(%g3, %g4, ASI_DMMU) ;\
DTLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1: \
/* END CSTYLED */
#define PROBE_3RD_DTSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_SHCTX_DTSB(tsbe_ptr, vpg_4m, label) ;\
/* END CSTYLED */
#define PROBE_4TH_DTSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_SHCTX_DTSB(tsbe_ptr, vpg_4m, label) ;\
/* END CSTYLED */
#define PROBE_SHCTX_ITSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_TSB(tsbe_ptr, vpg_4m, %g4, label) ;\
andcc %g5, TTE_EXECPRM_INT, %g0 /* check execute bit */ ;\
bz,pn %icc, exec_fault ;\
mov tsbe_ptr, %g1 /* for traptrace sake */ ;\
TT_TRACE(trace_tsbhit) ;\
SET_SHCTX_TAGACC(%g3, %g4, ASI_IMMU) ;\
ITLB_STUFF(%g5, %g1, %g2, %g3, %g4) ;\
retry /* retry faulted instruction */ ;\
label/**/1:
/* END CSTYLED */
#define PROBE_3RD_ITSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_SHCTX_ITSB(tsbe_ptr, vpg_4m, sfmmu_tsb_miss_tt) ;\
/* END CSTYLED */
#define PROBE_4TH_ITSB(tsbe_ptr, vpg_4m, label) \
/* BEGIN CSTYLED */ \
PROBE_SHCTX_ITSB(tsbe_ptr, vpg_4m, label) ;\
/* END CSTYLED */
/*
* The traptype is supplied by caller.
*
* If iTSB miss, store shctx into IMMU TAG ACCESS REG
* If dTSB miss, store shctx into DMMU TAG ACCESS REG
* Thus the [D|I]TLB_STUFF will work as expected.
*/
#define SAVE_CTX1(traptype, tmp1, tmp2, label) \
/* BEGIN CSTYLED */ \
cmp traptype, FAST_IMMU_MISS_TT ;\
be,pn %icc, label/**/1 ;\
nop ;\
SET_SHCTX_TAGACC(tmp1, tmp2, ASI_DMMU) ;\
membar #Sync ;\
ba,a label/**/2 ;\
label/**/1: ;\
SET_SHCTX_TAGACC(tmp1, tmp2, ASI_IMMU) ;\
sethi %hi(FLUSH_ADDR), tmp1 ;\
flush tmp1 ;\
label/**/2:
/* END CSTYLED */
#endif /* UTSB_PHYS */
#endif /* _ASM */
#ifdef __cplusplus
}
#endif
#endif /* _VM_MACH_SFMMU_H */
|