/*
    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.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 $
 
*/

/* Topsy VM is a virtual memory implementation with these goals:
   * protection domains for kernel and user
   * hierarchical structure of protection domains
   * sharing of regions (map entry passing) and loose pages (page loan out)
   * transfering of regions and loose pages (page transfer)
   * non complex region splitting and partial freeing
   * possibility of copy-on-write and snapshot
   
   Topsy VM is not designed for demand paging and swapping!
*/

/* Architecture:
   the vm space of a protection domain is hierarchicaly built out of following 
   structures:
     - vm_domain:  root of the vm tree.
     - vm_map:     the high-level address map data structure.
     - vm_pmap:    the physical address map data structure.
     - vm_region:  an entry in a address map.
     - vm_oref:    reference to a vm_object and its handler.
     - vm_object:  abstract object that describes the memory mapped by a region.
		 - vm_manager: handler for a specified object type.
     - vm_pref:    reference to a vm_page.
     - vm_page:    represents a page of physical memory.
 
   See the coresponding include file for the usage of those structures.
*/
#ifndef __VM_H__
#define __VM_H__

#include "Topsy.h"
#include "types.h"

#include "vm_extern.h"
#include "vm_map.h"
#include "vm_pmap.h"

/* statistics */
struct vm_stat
{
  /* vm_page constatants */
  unsigned long pagesize;		/* size of a page (power of 2) */
  unsigned long pagemask;		/* binary page mask */
  unsigned long pageshift;	/* page shift (# '0' in page mask) */

  /* vm_page counters */
  unsigned long npages;			/* total number of pages in the system */
  unsigned long free;				/* number of free pages */
  unsigned long active;			/* number of active (used) pages */
  unsigned long wired;			/* number of wired pages */
  unsigned long reserved;		/* number of pages reserved for kernel */

  /* stat counter */
  unsigned long faults;			/* page fault count */
  unsigned long pmapfaults;	/* page fault count on pmap layer */

#if 0 /* these counters should be in the manager part */

  unsigned long faultnoram;	/* number of times fault was out of ram */
  unsigned long faultanon;	/* number of times fault anon */
  unsigned long faultacow;	/* number of times fault anon cow */
  unsigned long faultobj;		/* number of times fault is on object page */
#endif
  /* XXX */
};

struct vm_physmap
{
  size_t start;
  size_t end;
};
struct vm_page_state;
struct vm_manager_state;
struct vm_pmap_state;

struct vm
{
  struct vm_physmap* physmap;
  int physcnt;
  struct vm_page_state* page;
  struct vm_manager_state* manager;
  struct vm_pmap_state* pmap;
  struct vm_stat stat;
  struct vm_domain* kernel;
};
extern struct vm* vm;

struct vm_domain_stat
{
  size_t size;		/* virtual size of this protection domain */
  size_t rsize;		/* virtual size of all regions in PD */
  int npages;			/* number of used pages */

  int loanout;		/* number of loaned out pages */
  int shared;			/* number of shared pages */
  int freed;			/* number of freed pages XXX ??? */
  int allocated;	/* number of allocated pages */
  /* XXX */
};

/*
 * vm_domain: Describes the complete virtual address space of a protection 
 *            domain. The vm_domain structure contains a process' vm_map 
 *            and vm_pmap structures, and contains statistics on the 
 *            process' memory usage.
 */
struct vm_domain
{
  struct vm_map		vm_map;			/* VM address map */
  struct vm_pmap	vm_pmap;		/* physical address map */
  struct vm_domain_stat statistics;
};


#endif
