Changeset da1bafb in mainline for kernel/arch/ppc32/src/mm/tlb.c


Ignore:
Timestamp:
2010-05-24T18:57:31Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ppc32/src/mm/tlb.c

    r666f492 rda1bafb  
    4545
    4646static unsigned int seed = 10;
    47 static unsigned int seed_real __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    48 
     47static unsigned int seed_real
     48    __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    4949
    5050/** Try to find PTE for faulting address
     
    5454 * if lock is true.
    5555 *
    56  * @param as            Address space.
    57  * @param lock          Lock/unlock the address space.
    58  * @param badvaddr      Faulting virtual address.
    59  * @param access        Access mode that caused the fault.
    60  * @param istate        Pointer to interrupted state.
    61  * @param pfrc          Pointer to variable where as_page_fault() return code
    62  *                      will be stored.
    63  * @return              PTE on success, NULL otherwise.
    64  *
    65  */
    66 static pte_t *
    67 find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr, int access,
    68     istate_t *istate, int *pfrc)
     56 * @param as       Address space.
     57 * @param lock     Lock/unlock the address space.
     58 * @param badvaddr Faulting virtual address.
     59 * @param access   Access mode that caused the fault.
     60 * @param istate   Pointer to interrupted state.
     61 * @param pfrc     Pointer to variable where as_page_fault() return code
     62 *                 will be stored.
     63 *
     64 * @return PTE on success, NULL otherwise.
     65 *
     66 */
     67static pte_t *find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr,
     68    int access, istate_t *istate, int *pfrc)
    6969{
    7070        /*
    7171         * Check if the mapping exists in page tables.
    72          */     
     72         */
    7373        pte_t *pte = page_mapping_find(as, badvaddr);
    7474        if ((pte) && (pte->present)) {
     
    7979                return pte;
    8080        } else {
    81                 int rc;
    82        
    8381                /*
    8482                 * Mapping not found in page tables.
     
    8684                 */
    8785                page_table_unlock(as, lock);
    88                 switch (rc = as_page_fault(badvaddr, access, istate)) {
     86               
     87                int rc = as_page_fault(badvaddr, access, istate);
     88                switch (rc) {
    8989                case AS_PF_OK:
    9090                        /*
     
    107107                default:
    108108                        panic("Unexpected rc (%d).", rc);
    109                 }       
    110         }
    111 }
    112 
     109                }
     110        }
     111}
    113112
    114113static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
     
    123122}
    124123
    125 
    126124static void pht_insert(const uintptr_t vaddr, const pte_t *pte)
    127125{
     
    129127        uint32_t api = (vaddr >> 22) & 0x3f;
    130128       
    131         uint32_t vsid;
    132         asm volatile (
    133                 "mfsrin %0, %1\n"
    134                 : "=r" (vsid)
    135                 : "r" (vaddr)
    136         );
    137        
    138         uint32_t sdr1;
    139         asm volatile (
    140                 "mfsdr1 %0\n"
    141                 : "=r" (sdr1)
    142         );
     129        uint32_t vsid = sr_get(vaddr);
     130        uint32_t sdr1 = sdr1_get();
     131       
     132        // FIXME: compute size of PHT exactly
    143133        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    144134       
     
    215205}
    216206
    217 
    218207/** Process Instruction/Data Storage Exception
    219208 *
     
    224213void pht_refill(int n, istate_t *istate)
    225214{
    226         uintptr_t badvaddr;
    227         pte_t *pte;
    228         int pfrc;
    229215        as_t *as;
    230216        bool lock;
     
    238224        }
    239225       
     226        uintptr_t badvaddr;
     227       
    240228        if (n == VECTOR_DATA_STORAGE)
    241229                badvaddr = istate->dar;
    242230        else
    243231                badvaddr = istate->pc;
    244                
     232       
    245233        page_table_lock(as, lock);
    246234       
    247         pte = find_mapping_and_check(as, lock, badvaddr,
     235        int pfrc;
     236        pte_t *pte = find_mapping_and_check(as, lock, badvaddr,
    248237            PF_ACCESS_READ /* FIXME */, istate, &pfrc);
     238       
    249239        if (!pte) {
    250240                switch (pfrc) {
     
    264254        }
    265255       
    266         pte->accessed = 1; /* Record access to PTE */
     256        /* Record access to PTE */
     257        pte->accessed = 1;
    267258        pht_insert(badvaddr, pte);
    268259       
     
    274265        pht_refill_fail(badvaddr, istate);
    275266}
    276 
    277267
    278268/** Process Instruction/Data Storage Exception in Real Mode
     
    291281                badvaddr = istate->pc;
    292282       
    293         uint32_t physmem;
    294         asm volatile (
    295                 "mfsprg3 %0\n"
    296                 : "=r" (physmem)
    297         );
     283        uint32_t physmem = physmem_top();
    298284       
    299285        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    303289        uint32_t api = (badvaddr >> 22) & 0x3f;
    304290       
    305         uint32_t vsid;
    306         asm volatile (
    307                 "mfsrin %0, %1\n"
    308                 : "=r" (vsid)
    309                 : "r" (badvaddr)
    310         );
    311        
    312         uint32_t sdr1;
    313         asm volatile (
    314                 "mfsdr1 %0\n"
    315                 : "=r" (sdr1)
    316         );
     291        uint32_t vsid = sr_get(badvaddr);
     292        uint32_t sdr1 = sdr1_get();
     293       
     294        // FIXME: compute size of PHT exactly
    317295        phte_t *phte_real = (phte_t *) (sdr1 & 0xffff0000);
    318296       
     
    396374}
    397375
    398 
    399376/** Process ITLB/DTLB Miss Exception in Real Mode
    400377 *
     
    404381{
    405382        uint32_t badvaddr = tlbmiss & 0xfffffffc;
    406        
    407         uint32_t physmem;
    408         asm volatile (
    409                 "mfsprg3 %0\n"
    410                 : "=r" (physmem)
    411         );
     383        uint32_t physmem = physmem_top();
    412384       
    413385        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    420392        uint32_t index = 0;
    421393        asm volatile (
    422                 "mtspr 981, %0\n"
    423                 "mtspr 982, %1\n"
    424                 "tlbld %2\n"
    425                 "tlbli %2\n"
    426                 : "=r" (index)
    427                 : "r" (ptehi),
    428                   "r" (ptelo)
     394                "mtspr 981, %[ptehi]\n"
     395                "mtspr 982, %[ptelo]\n"
     396                "tlbld %[index]\n"
     397                "tlbli %[index]\n"
     398                : [index] "=r" (index)
     399                : [ptehi] "r" (ptehi),
     400                  [ptelo] "r" (ptelo)
    429401        );
    430402}
    431403
    432 
    433404void tlb_arch_init(void)
    434405{
     
    436407}
    437408
    438 
    439409void tlb_invalidate_all(void)
    440410{
    441411        uint32_t index;
     412       
    442413        asm volatile (
    443                 "li %0, 0\n"
     414                "li %[index], 0\n"
    444415                "sync\n"
    445416               
    446417                ".rept 64\n"
    447                 "tlbie %0\n"
    448                 "addi %0, %0, 0x1000\n"
     418                "       tlbie %[index]\n"
     419                "       addi %[index], %[index], 0x1000\n"
    449420                ".endr\n"
    450421               
     
    452423                "tlbsync\n"
    453424                "sync\n"
    454                 : "=r" (index)
     425                : [index] "=r" (index)
    455426        );
    456427}
    457428
    458 
    459429void tlb_invalidate_asid(asid_t asid)
    460430{
    461         uint32_t sdr1;
    462         asm volatile (
    463                 "mfsdr1 %0\n"
    464                 : "=r" (sdr1)
    465         );
     431        uint32_t sdr1 = sdr1_get();
     432       
     433        // FIXME: compute size of PHT exactly
    466434        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    467435       
    468         uint32_t i;
     436        size_t i;
    469437        for (i = 0; i < 8192; i++) {
    470438                if ((phte[i].v) && (phte[i].vsid >= (asid << 4)) &&
     
    472440                        phte[i].v = 0;
    473441        }
     442       
    474443        tlb_invalidate_all();
    475444}
    476 
    477445
    478446void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
     
    482450}
    483451
    484 
    485452#define PRINT_BAT(name, ureg, lreg) \
    486453        asm volatile ( \
    487                 "mfspr %0," #ureg "\n" \
    488                 "mfspr %1," #lreg "\n" \
    489                 : "=r" (upper), "=r" (lower) \
     454                "mfspr %[upper], " #ureg "\n" \
     455                "mfspr %[lower], " #lreg "\n" \
     456                : [upper] "=r" (upper), \
     457                  [lower] "=r" (lower) \
    490458        ); \
     459        \
    491460        mask = (upper & 0x1ffc) >> 2; \
    492461        if (upper & 3) { \
    493462                uint32_t tmp = mask; \
    494463                length = 128; \
     464                \
    495465                while (tmp) { \
    496466                        if ((tmp & 1) == 0) { \
     
    503473        } else \
    504474                length = 0; \
     475        \
    505476        printf(name ": page=%.*p frame=%.*p length=%d KB (mask=%#x)%s%s\n", \
    506477            sizeof(upper) * 2, upper & 0xffff0000, sizeof(lower) * 2, \
     
    515486       
    516487        for (sr = 0; sr < 16; sr++) {
    517                 uint32_t vsid;
    518                 asm volatile (
    519                         "mfsrin %0, %1\n"
    520                         : "=r" (vsid)
    521                         : "r" (sr << 28)
    522                 );
     488                uint32_t vsid = sr_get(sr << 28);
     489               
    523490                printf("sr[%02u]: vsid=%.*p (asid=%u)%s%s\n", sr,
    524491                    sizeof(vsid) * 2, vsid & 0xffffff, (vsid & 0xffffff) >> 4,
Note: See TracChangeset for help on using the changeset viewer.