Changeset fbb8b2b in mainline for arch/ppc32/src/mm/page.c


Ignore:
Timestamp:
2006-06-17T17:26:14Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8e3bf3e2
Parents:
74b22cc5
Message:

ppc32: more generic page hash table handling
(preliminary code, will be fixed properly later)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • arch/ppc32/src/mm/page.c

    r74b22cc5 rfbb8b2b  
    2727 */
    2828
    29  /** @addtogroup ppc32mm       
     29/** @addtogroup ppc32mm
    3030 * @{
    3131 */
     
    4949#include <symtab.h>
    5050
    51 static phte_t *phte;
    52 
    5351
    5452/** Try to find PTE for faulting address
     
    6765 *
    6866 */
    69 static pte_t *find_mapping_and_check(as_t *as, bool lock, __address badvaddr, int access,
    70                                      istate_t *istate, int *pfrc)
     67static pte_t *find_mapping_and_check(as_t *as, bool lock, __address badvaddr, int access, istate_t *istate, int *pfrc)
    7168{
    7269        /*
     
    133130        __u32 page = (vaddr >> 12) & 0xffff;
    134131        __u32 api = (vaddr >> 22) & 0x3f;
     132       
    135133        __u32 vsid;
    136        
    137134        asm volatile (
    138135                "mfsrin %0, %1\n"
     
    140137                : "r" (vaddr)
    141138        );
     139       
     140        __u32 sdr1;
     141        asm volatile (
     142                "mfsdr1 %0\n"
     143                : "=r" (sdr1)
     144        );
     145        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    142146       
    143147        /* Primary hash (xor) */
     
    186190        phte[base + i].c = 0;
    187191        phte[base + i].pp = 2; // FIXME
     192}
     193
     194
     195static void pht_real_insert(const __address vaddr, const pfn_t pfn)
     196{
     197        __u32 page = (vaddr >> 12) & 0xffff;
     198        __u32 api = (vaddr >> 22) & 0x3f;
     199       
     200        __u32 vsid;
     201        asm volatile (
     202                "mfsrin %0, %1\n"
     203                : "=r" (vsid)
     204                : "r" (vaddr)
     205        );
     206       
     207        __u32 sdr1;
     208        asm volatile (
     209                "mfsdr1 %0\n"
     210                : "=r" (sdr1)
     211        );
     212        phte_t *phte_physical = (phte_t *) (sdr1 & 0xffff0000);
     213       
     214        /* Primary hash (xor) */
     215        __u32 h = 0;
     216        __u32 hash = vsid ^ page;
     217        __u32 base = (hash & 0x3ff) << 3;
     218        __u32 i;
     219        bool found = false;
     220       
     221        /* Find unused or colliding
     222           PTE in PTEG */
     223        for (i = 0; i < 8; i++) {
     224                if ((!phte_physical[base + i].v) || ((phte_physical[base + i].vsid == vsid) && (phte_physical[base + i].api == api))) {
     225                        found = true;
     226                        break;
     227                }
     228        }
     229       
     230        if (!found) {
     231                /* Secondary hash (not) */
     232                __u32 base2 = (~hash & 0x3ff) << 3;
     233               
     234                /* Find unused or colliding
     235                   PTE in PTEG */
     236                for (i = 0; i < 8; i++) {
     237                        if ((!phte_physical[base2 + i].v) || ((phte_physical[base2 + i].vsid == vsid) && (phte_physical[base2 + i].api == api))) {
     238                                found = true;
     239                                base = base2;
     240                                h = 1;
     241                                break;
     242                        }
     243                }
     244               
     245                if (!found) {
     246                        // TODO: A/C precedence groups
     247                        i = page % 8;
     248                }
     249        }
     250       
     251        phte_physical[base + i].v = 1;
     252        phte_physical[base + i].vsid = vsid;
     253        phte_physical[base + i].h = h;
     254        phte_physical[base + i].api = api;
     255        phte_physical[base + i].rpn = pfn;
     256        phte_physical[base + i].r = 0;
     257        phte_physical[base + i].c = 0;
     258        phte_physical[base + i].pp = 2; // FIXME
    188259}
    189260
     
    251322
    252323
     324/** Process Instruction/Data Storage Interrupt in Real Mode
     325 *
     326 * @param n Interrupt vector number.
     327 * @param istate Interrupted register context.
     328 *
     329 */
     330bool pht_real_refill(int n, istate_t *istate)
     331{
     332        __address badvaddr;
     333       
     334        if (n == VECTOR_DATA_STORAGE) {
     335                asm volatile (
     336                        "mfdar %0\n"
     337                        : "=r" (badvaddr)
     338                );
     339        } else
     340                badvaddr = istate->pc;
     341       
     342        __u32 physmem;
     343        asm volatile (
     344                "mfsprg3 %0\n"
     345                : "=r" (physmem)
     346        );
     347       
     348        if ((badvaddr >= PA2KA(0)) && (badvaddr <= PA2KA(physmem))) {
     349                pht_real_insert(badvaddr, KA2PA(badvaddr) >> 12);
     350                return true;
     351        }
     352       
     353        return false;
     354}
     355
     356
    253357void pht_init(void)
    254358{
    255         memsetb((__address) phte, 1 << PHT_BITS, 0);
     359        // FIXME
     360       
     361        __u32 sdr1;
     362        asm volatile (
     363                "mfsdr1 %0\n"
     364                : "=r" (sdr1)
     365        );
     366        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
     367       
     368        memsetb((__address) phte, 65536, 0);
    256369}
    257370
     
    259372void page_arch_init(void)
    260373{
    261         if (config.cpu_active == 1) {
     374        if (config.cpu_active == 1)
    262375                page_mapping_operations = &pt_mapping_operations;
    263                
    264                 __address cur;
    265                 int flags;
    266                
    267                 /* Frames below 128 MB are mapped using BAT,
    268                    map rest of the physical memory */
    269                 for (cur = 128 << 20; cur < last_frame; cur += FRAME_SIZE) {
    270                         flags = PAGE_CACHEABLE;
    271                         if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
    272                                 flags |= PAGE_GLOBAL;
    273                         page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    274                 }
    275                
    276                 /* Allocate page hash table */
    277                 phte_t *physical_phte = (phte_t *) PFN2ADDR(frame_alloc(PHT_ORDER, FRAME_KA | FRAME_PANIC));
    278                 phte = (phte_t *) PA2KA((__address) physical_phte);
    279                
    280                 ASSERT((__address) physical_phte % (1 << PHT_BITS) == 0);
    281                 pht_init();
    282                
    283                 asm volatile (
    284                         "mtsdr1 %0\n"
    285                         :
    286                         : "r" ((__address) physical_phte)
    287                 );
    288         }
    289376}
    290377
     
    305392}
    306393
    307  /** @}
    308  */
    309 
     394/** @}
     395 */
Note: See TracChangeset for help on using the changeset viewer.