/*
    Copyright 2001 (c) by Claudio Jeker,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public 
    Licence. A full copy of the GNU GPL is provided in the file COPYING 
    found in the development root of Topsy.
*/
/*
	
    File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/VMemory/Attic/vm_pmap.h,v $
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 2922 $
    Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $  by: $Author: baderma $
 
*/

/*
	 vm_pmap: machine dependent part of the page handling stuff
 
	 Here we define the vm_pmap API to access and modify the page tables.
	 It is important that this API is used so the code can be more modular and
	 object oriented. In other words, don't touch the vm_pmap structure directly!
 
 */
#ifndef __VM_PMAP_H__
#define __VM_PMAP_H__

#include "vm.h"
#include "vm_page.h"
#include "vm_bootup.h"
#include "vm_pmap_hal.h"

/* well known flags */
/* 1. the protection flags */
#define PMAP_READ VM_ACCESS_READ
#define PMAP_WRITE VM_ACCESS_WRITE
#define PMAP_EXEC VM_ACCESS_EXEC

/* 2. cache steering flags */
#define PMAP_CACHABLE 0x10
#define PMAP_BUFFERABLE 0x20

struct protection_domain;

/* functions prototypes */
/* Boris will hate me, because I rename all his functions (:
	 But so we have a nice name convetion over the complete memory management.
*/

/* This function allocates the needed Memory for the pmap forward or reverse table.
	 The mappings for the Kernel Protection Domain are added later via normal enter calls.
 */
void vm_pmap_init(struct vm_segmap* segmap);

/* create is called when the a new protection domain is created (was fuer'n Zufall) */
int vm_pmap_create(pmap_t pmap, struct protection_domain *d);

/* called when protection domain exits */
int vm_pmap_destroy(pmap_t pmap);

/* enter one virtual to physical mapping */
int vm_pmap_enter(pmap_t pmap, address_t virt, address_t phys, int flags);

/* enter linera mappings for a region (only used on bootup, please) */
int vm_pmap_region_enter(struct vm_pmap* vm_pmap,
                         address_t phys, address_t virt, size_t size, int flags);

/* remove one virtual to physical mapping */
int vm_pmap_page_remove(pmap_t pmap, address_t virt);

/* remove all mappings of a region */
int vm_pmap_region_remove(pmap_t pmap, address_t virt_start, address_t virt_end);

/* modify the flags of a virtual to physical mapping */
int vm_pmap_change_page_flags(pmap_t pmap, address_t virt, int flags);

/* the same as befor but this time the complete region is changed */
int vm_pmap_change_region_flags(pmap_t pmap, address_t virt_start, address_t virt_end, int flags);

/* copy a page, this is should be the fastest possible function
	 NOTE: we are using vm_page struct because on the IXP the pmap layer needs
	 to map both pages into his protection domain before the copy can start and
	 afterwards the pages have to be removed again.
	 On the mips we reserve the first 0x10000 bytes for this pmap handling.
 */
int vm_pmap_page_copy(pmap_t pmap, struct vm_page* src, struct vm_page* dest);

/* zero-out a page, again this should be the fastest possible function */
/* saame NOTE as above XXX */
int vm_pmap_page_zero(pmap_t pmap, struct vm_page* src);

void vm_pmap_print(pmap_t pmap);
void vm_pmap_print_all(void);

#endif
