123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- #include "cache.h"
- #include <mips/hal.h>
- #include <mips/m32tlb.h>
- void __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbwi2 (tlbhi_t hi, tlblo_t lo0, tlblo_t lo1, unsigned int mask,
- int index)
- {
- mips32_setentryhi (hi);
- mips32_setentrylo0 (lo0);
- mips32_setentrylo1 (lo1);
- mips32_setpagemask (mask);
- mips32_setindex (index);
- mips_ehb ();
- mips_tlbwi ();
- return;
- }
- void __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbwr2 (tlbhi_t hi, tlblo_t lo0, tlblo_t lo1, unsigned int mask)
- {
- mips32_setentryhi (hi);
- mips32_setentrylo0 (lo0);
- mips32_setentrylo1 (lo1);
- mips32_setpagemask (mask);
- mips_ehb ();
- mips_tlbwr ();
- return;
- }
- int __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbrwr2 (tlbhi_t hi, tlblo_t lo0, tlblo_t lo1, unsigned int mask)
- {
- int index;
- tlbhi_t prev_hi;
- prev_hi = mips32_getentryhi ();
- mips32_setentryhi (hi);
- mips_ehb ();
- mips_tlbp ();
- mips_ehb ();
- index = mips32_getindex ();
- mips32_setentrylo0 (lo0);
- mips32_setentrylo1 (lo1);
- mips32_setpagemask (mask);
- mips_ehb ();
-
- if (index >= 0)
- mips_tlbwi ();
- else
- mips_tlbwr ();
- mips32_setentryhi (prev_hi);
- return index;
- }
- void _MIPS_HAL_NOMIPS16
- mips_tlbri2 (tlbhi_t *phi, tlblo_t *plo0, tlblo_t *plo1,
- unsigned int *pmask, int index)
- {
- mips32_setindex (index);
- mips_ehb ();
- mips_tlbr ();
- mips_ehb ();
- *phi = mips32_getentryhi ();
- *plo0 = mips32_getentrylo0 ();
- *plo1 = mips32_getentrylo1 ();
- *pmask = mips32_getpagemask ();
- return;
- }
- int __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbprobe2 (tlbhi_t hi, tlblo_t *plo0, tlblo_t *plo1,
- unsigned int *pmask)
- {
- int index;
- tlbhi_t prev_hi;
- prev_hi = mips32_getentryhi ();
- mips32_setentryhi (hi);
- mips_ehb ();
- mips_tlbp ();
- mips_ehb ();
- index = mips32_getindex ();
- if (index >= 0)
- {
- mips_tlbr ();
- mips_ehb ();
- *plo0 = mips32_getentrylo0 ();
- *plo1 = mips32_getentrylo1 ();
- *pmask = mips32_getpagemask ();
- }
- else
- index = -1;
- mips32_setentryhi (prev_hi);
- return index;
- }
- void __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbinval (tlbhi_t hi)
- {
- int index, tmp_idx;
- tlbhi_t prev_hi, tmp_hi = 0;
- register const int zero = 0;
- unsigned int cfg;
- prev_hi = mips32_getentryhi ();
- mips32_setentryhi (hi);
- mips_ehb ();
- mips_tlbp ();
- mips_ehb ();
- index = mips32_getindex ();
- if (index < 0)
- goto restore;
- mips32_setentrylo0 (zero);
- mips32_setentrylo1 (zero);
-
- cfg = mips32_getconfig3 ();
- if ((cfg & CFG3_M) != 0)
- {
- cfg = mips32_getconfig4 ();
- if ((cfg & CFG4_IE_MASK) != 0)
- {
- tmp_hi = C0_ENTRYHI_EHINV_MASK;
- goto do_tlbwi;
- }
- }
- tmp_hi = (tlbhi_t) ((unsigned long) KSEG0_BASE - 0x4000);
- do
- {
- tmp_hi = tmp_hi + 0x4000;
- mips32_setentryhi (tmp_hi);
- mips_ehb ();
- mips_tlbp ();
- mips_ehb ();
- tmp_idx = mips32_getindex ();
- }
- while (tmp_idx >= 0);
- mips32_setindex (index);
- do_tlbwi:
- mips32_setentryhi (tmp_hi);
- mips_ehb ();
- mips_tlbwi ();
- mips_ehb ();
- restore:
- mips32_setentryhi (prev_hi);
- return;
- }
- static void _MIPS_HAL_NOMIPS16
- mips_tlb_entries_sets (int *pentries, int *psets)
- {
- int entries = 0, sets = 0, ways = 0;
- unsigned int cfg, cfg1, tcfg, tmp;
- cfg = mips32_getconfig ();
- cfg = (cfg & CFG0_MT_MASK) >> CFG0_MT_SHIFT;
- if ((cfg == 0)
- || (cfg == (CFG0_MT_FIXED >> CFG0_MT_SHIFT))
- || (cfg == (CFG0_MT_BAT >> CFG0_MT_SHIFT))
- || ((cfg & ((CFG0_MT_TLB | CFG0_MT_DUAL) >> CFG0_MT_SHIFT)) == 0))
- {
- *pentries = 0;
- *psets = 0;
- return;
- }
- cfg1 = mips32_getconfig1 ();
-
- entries = ((cfg1 & CFG1_MMUS_MASK) >> CFG1_MMUSSHIFT) + 1;
-
- tcfg = mips32_getconfig3 ();
- if ((tcfg & CFG3_M) == 0)
- goto doReturn;
- tcfg = mips32_getconfig4 ();
- #if (__mips_isa_rev < 6)
- tmp = (tcfg & CFG4_MMUED) >> CFG4_MMUED_SHIFT;
-
- if (tmp == (CFG4_MMUED_FTLBVEXT >> CFG4_MMUED_SHIFT))
- goto doFTLBVTLB;
-
- if (tmp == (CFG4_MMUED_SIZEEXT >> CFG4_MMUED_SHIFT))
- goto doSizeExt;
- if (tmp == 0)
- goto doReturn;
- goto doFTLBSize;
- doSizeExt:
- entries += ((tcfg & CFG4_MMUSE_MASK) >> CFG4_MMUSE_SHIFT)
- << CFG1_MMUS_BITS;
- goto doReturn;
- #endif
- doFTLBVTLB:
- entries += ((tcfg & CFG4_VTLBSEXT_MASK) >> CFG4_VTLBSEXT_SHIFT)
- << CFG1_MMUS_BITS;
- doFTLBSize:
-
- if (cfg != (CFG0_MT_DUAL >> CFG0_MT_SHIFT))
- goto doReturn;
-
- ways = 2 + ((tcfg & CFG4_FTLBW_MASK) >> CFG4_FTLBW_SHIFT);
-
- tmp = ((tcfg & CFG4_FTLBS_MASK) >> CFG4_FTLBS_SHIFT);
- sets = 1 << tmp;
-
- entries += ways << tmp;
- doReturn:
- *pentries = entries;
- *psets = sets;
- return;
- }
- int _MIPS_HAL_NOMIPS16
- mips_tlb_size (void)
- {
- int entries = 0, sets = 0;
- mips_tlb_entries_sets (&entries, &sets);
- (void) sets;
- return entries;
- }
- void __attribute__ ((use_hazard_barrier_return)) _MIPS_HAL_NOMIPS16
- mips_tlbinvalall (void)
- {
- unsigned int cfg0, cfg;
- unsigned long tmp_hi, tmp_hi2;
- int entries = 0, sets = 0, tlb_stride = 0;
- int end_ptr = 0, index = 0;
- register const unsigned long zero = 0;
- extern void *__tlb_stride_length;
- cfg0 = mips32_getconfig ();
- cfg0 = (cfg0 & CFG0_MT_MASK) >> CFG0_MT_SHIFT;
- if ((cfg0 == 0)
- || (cfg0 == (CFG0_MT_FIXED >> CFG0_MT_SHIFT))
- || (cfg0 == (CFG0_MT_BAT >> CFG0_MT_SHIFT)))
- goto doReturn;
- mips_setentrylo0 (zero);
- mips_setentrylo1 (zero);
- mips_setpagemask (zero);
-
- mips_tlb_entries_sets (&entries, &sets);
- cfg = mips32_getconfig3 ();
- if ((cfg & CFG3_M) == 0)
- goto doBasicInval;
- cfg = mips32_getconfig4 ();
- cfg = (cfg & CFG4_IE_MASK) >> CFG4_IE_SHIFT;
-
- if (cfg == 0)
- goto doBasicInval;
-
- if (cfg == (CFG4_IE_EHINV >> CFG4_IE_SHIFT))
- goto doEHINV;
-
- if (cfg0 == (CFG0_MT_TLB >> CFG0_MT_SHIFT)
- || cfg == (CFG4_IE_INVALL >> CFG4_IE_SHIFT))
- {
-
- mips32_setindex (zero);
- mips_ehb ();
- mips_eva_tlbinvf ();
- goto doReturn;
- }
-
-
- mips32_setindex (zero);
- mips_ehb ();
- mips_eva_tlbinvf ();
- tlb_stride = (int) ((unsigned long) &__tlb_stride_length);
- sets = sets * tlb_stride;
- end_ptr = entries - sets;
- do
- {
- entries = entries - tlb_stride;
- mips32_setindex (entries);
- mips_ehb ();
- mips_eva_tlbinvf ();
- }
- while (entries != end_ptr);
- goto doReturn;
- doEHINV:
-
- index = 0;
- tmp_hi = C0_ENTRYHI_EHINV_MASK;
- mips_setentryhi (tmp_hi);
- do
- {
- mips32_setindex (index);
- mips_ehb ();
- mips_tlbwi ();
- index++;
- }
- while (entries != index);
- goto doReturn;
- doBasicInval:
-
- tmp_hi = 0;
- cfg = mips32_getconfig3 ();
-
- if ((cfg & CFG3_LPA) != 0)
- {
- cfg = mips32_getpagegrain ();
- if ((cfg & PAGEGRAIN_ELPA) == 0)
- tmp_hi = 0xFFFFFFFF;
- }
- tmp_hi2 = (unsigned long) KSEG0_BASE - 0x4000;
- index = 0;
- do
- {
- tmp_hi2 += 0x4000;
- mips_setentryhi (tmp_hi2);
- if (tmp_hi != 0)
- mips32_sethientryhi (tmp_hi);
- mips_ehb ();
- mips_tlbp ();
- mips_ehb ();
- if (mips32_getindex () == 0)
- continue;
- mips32_setindex (index);
- mips_ehb ();
- mips_tlbwi ();
- index++;
- }
- while (entries != index);
- doReturn:
-
- mips_setentryhi (zero);
- return;
- }
- _MIPS_HAL_NOMIPS16
- int m64_tlb_size (void) __attribute__ ((alias ("mips_tlb_size")));
- _MIPS_HAL_NOMIPS16
- void m64_tlbinvalall (void) __attribute__ ((alias ("mips_tlbinvalall")));
|