/*
 * mmu_context.h: Switch MMU context
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) Equator Technologies
 */

#ifndef _ASM_BSP_MMU_CONTEXT_H_
#define _ASM_BSP_MMU_CONTEXT_H_

#include <linux/slab.h>
#include <asm/assert.h>
#include <etilib/etiTypes.h>

#include <asm/mmu.h>

#define NO_ASID  0xffffffff

extern void TLB_get_context( struct mm_struct *mm );
extern void TLB_destroy_context( struct mm_struct *mm );

extern int        dataBrkGlobal;
extern inline void get_mmu_context(struct task_struct *tsk)
{
    struct  mm_struct   *mm= tsk->mm;
    mm_context_t        *mm_ctx = &mm->context;

    if (mm_ctx->asid == NO_ASID) {
        TLB_get_context(mm);
    }

    //mm_ctx = (struct eti_mm_ctx *)mm->context;
    //ASSERT(mm_ctx, ("get_mmu_context(): no ETI mm context!"));

    hmpv_write_asid_cl0    (mm_ctx->asid   );
    hmpv_write_eer_cl0     (mm_ctx->eer    );
    hmpv_write_ibrka_cl0   (mm_ctx->ibrka  );
    hmpv_write_ibrkmsk_cl0 (mm_ctx->ibrkmsk);
    /* If a global data breakpoint has been set, do not
       overwrite them 
    */
    if ( !dataBrkGlobal ) {        
        hmpv_write_dbrka_cl0   (mm_ctx->dbrka  );
        hmpv_write_dbrkmsk_cl0 (mm_ctx->dbrkmsk);
        hmpv_write_ceer_cl0    (mm_ctx->ceer[0]);
        hmpv_write_ceer_cl1    (mm_ctx->ceer[1]);
    }
}


extern inline void init_new_context(struct mm_struct *mm)
{
    mm_context_t *mm_ctx = &mm->context;

    mm_ctx->asid = NO_ASID;
    TLB_get_context(mm);

    mm_ctx->eer      = hmpv_read_eer_cl0();
    mm_ctx->ibrka    = ~0;
    mm_ctx->ibrkmsk  = ~0;
    mm_ctx->dbrka    = ~0;
    mm_ctx->dbrkmsk  = ~0;
    mm_ctx->ceer[0]  = hmpv_read_ceer_cl0();
    mm_ctx->ceer[1]  = hmpv_read_ceer_cl1();
}


extern inline void destroy_context(struct mm_struct *mm)
{
    TLB_destroy_context(mm);
}


extern inline void activate_context(struct task_struct *tsk)
{
    get_mmu_context(tsk);
}



#endif	/* _ASM_BSP_MMU_CONTEXT_H_ */
