/*
    Copyright 2001 (c) by Authors,
    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/sa1100/Attic/vm_pmap_hal.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 $
 
*/


#ifndef PMAP_H
#define PMAP_H


/*** architecture dependent pmap structures and constants     ***/
/*** the architecture independent stuff is found in vm_pmap.h ***/

/* memory size constants are in MemoryLayout.h */

/* adresses where we can temporarly map some pages (for copy & zero) */
/* NOTE: address 0x00000000 is reserved for the exception handling */
#define MAP_PAGE_POS1				((address_t)0x00001000)
#define MAP_PAGE_POS2				((address_t)0x00002000)
#define MAP_PAGE_POS3				((address_t)0x00003000)
#define MAP_PAGE_POS4				((address_t)0x00004000)
#define MAP_PAGE_POS5				((address_t)0x00005000)

/* different parts of the virtual address */
// the part of the virtual address that is used as an index into TT1
#define TT1_LEVEL_MASK				0xFFF00000
#define TT1_LEVEL_SHIFT				20
// the part of the virtual address that is used as an index into TT2
#define TT2_LEVEL_MASK				0x000FF000
#define TT2_LEVEL_SHIFT				12
// the part of the virtual address that is used as an index into the phys page
#define PAGE_LEVEL_MASK				0x00000FFF
#define PAGE_LEVEL_SHIFT			0

/* TT1 masks & sizes & bit-offsets */
#define TT1_SIZE					16384
#define TT1_NUM_OF_ENTRIES			4096
#define TT1_COARSE_ADDR_MASK		0xFFFFFC00
#define TT1_FLAGS_MASK				0x000001FC
#define TT1_FLAGS_SHIFT				2
#define TT1_IMPDEF_FLAGS			0						// not documented => set it to zero
#define TT1_DOMAIN_MASK				0x000001E0
#define TT1_DOMAIN_SHIFT			5
#define TT1_FORMAT_MASK				0x00000003
#define TT1_COARSE_FMT				0x1

/* TT2 masks & sizes & bit-offsets */
#define TT2_SIZE					1024
#define TT2_NUM_OF_ENTRIES			256
#define TT2_SP_ADDR_MASK			0xFFFFF000
#define TT2_SP_PROT_MASK			0x00000FF0
#define TT2_CB_MASK					0xC
#define TT2_CB_BUFFERABLE			0x4
#define TT2_CB_CACHABLE				0x8
#define TT2_AC_READ					0xAA0				// sets read only on all subpages
#define TT2_AC_NONE					0x550				// sets no access on all subpages
#define TT2_AC_READWRITE			0xFF0				// sets read/write on all subpages
#define TT2_SP_FLAGS_MASK			0x00000FFC
#define TT2_FLAGS_SHIFT				2
#define TT2_FORMAT_MASK				0x3
#define TT2_SP_FMT					0x2
#define TT2_TABLE_SIZE				1024

/* Domain access permissions (we always use domain 0 for regular    *
 * pages which means the are checked agains page permissions and    *
 * therefor need to be of type client => bit [1:0] of the domain    *
 * register need to be set to 01 the rest is set to zero => no      *
 * access)                                                          */
#define DOMAINACCESS_PERM			0x00000001


/* pmap structure */
typedef struct vm_pmap
{
  // virtual base address of TT1
  address_t		tt1base_v;
  // physical bas address of TT1 (to be saved in CP15)
  address_t		tt1base_p;
}
pmap_entry_t;
typedef pmap_entry_t *pmap_t;


/* architecture dependent function prototypes (independent ones are *
 *   located in vm_pmap.h)                                          */
int vm_pmap_lookup_type(pmap_t pmap, address_t virt);
address_t vm_pmap_lookup_paddr(pmap_t pmap, address_t virt);


#endif
