home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / vm / vm_hat.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  7.0 KB  |  237 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _VM_VM_HAT_H
  11. #define _VM_VM_HAT_H
  12.  
  13. #ident    "@(#)/usr/include/vm/vm_hat.h.sl 1.1 4.0 12/08/90 38742 AT&T-USL"
  14.  
  15. #include "sys/immu.h"
  16.  
  17. /*
  18.  * VM - Hardware Address Translation management.
  19.  *
  20.  * This file describes the contents of the machine specific
  21.  * hat data structures and the machine specific hat procedures.
  22.  * The machine independent interface is described in <vm/hat.h>.
  23.  */
  24.  
  25. /* The 386 HAT design is based on dividing a page table into
  26.  * chunks that are a power of 2 long.
  27.  * These chunks allow the mapping pointer overhead to be
  28.  * reduced for the typical small process.
  29.  * The number of chunks times the number of entries equals 1024.
  30.  * The initial design uses 32 chunks of 32 entries.
  31.  * If translation caching (stealable translation accounting)
  32.  * is implemented, this may change to 16 chunks of 64 entries.
  33.  * This allows four accounting words to be available per chunk
  34.  * (instead of 1 word) in the accounting chunk (chunk 0) of
  35.  * a mapping chunk page.
  36.  * The extra words would be used for a time stamp and pointers
  37.  * for a doubly linked list.
  38.  * To acommodate this possible change, the following defines exist.
  39.  */
  40. #define HAT_MCPP    32    /* number of mapping chunks per page */
  41. #define HAT_EPMC    32    /* number of entries per mapping chunk */
  42. typedef union hatmap {
  43.     uint hat_mapv;
  44.     union hatmap *hat_mnext;
  45. } hatmap_t;
  46.  
  47. typedef struct hatmc {
  48.     hatmap_t hat_map[HAT_EPMC];
  49. } hatmc_t;
  50.  
  51. /* 
  52.  * The hatmcp_t:
  53.  */
  54. typedef struct {
  55.     hatmc_t *hat_mcp;
  56. } hatmcp_t;
  57.  
  58. #define HATMAP_ADDR    0xFFFFFF80
  59.  
  60. /* The hatpt structure is the machine dependent page table accounting
  61.  * structure internal to the 386 HAT layer.
  62.  * It links an address space to a currently resident page table
  63.  * and the currently resident mapping pointer chunks for that
  64.  * page table.
  65.  * It contains an active PTE count and all locking information.
  66.  * It also contains hatpt pointers for a doubly linked, circular
  67.  * linked list of active page tables for an address space.
  68.  */
  69. typedef struct hatpt {
  70.     struct    hatpt *hatpt_forw;    /* forward page table list ptr */
  71.     struct    hatpt *hatpt_back;    /* backward page table list ptr */
  72.     struct    hatpt *hatpt_next;    /* forward activept list ptr */
  73.     struct    hatpt *hatpt_prev;    /* backward activept list ptr */
  74.     pte_t    hatpt_pde;        /* PDE for page table */
  75.     pte_t    *hatpt_pdtep;        /* PDT entry pointer */
  76.     struct    as *hatpt_as;        /* pointer back to containing as */
  77.     cnt_t    hatpt_aec;        /* active entry count */
  78.     cnt_t    hatpt_locks;        /* count of locked PTEs */
  79.     hatmcp_t hatpt_mcp[HAT_MCPP];    /* mapping chunk pointer array */
  80. } hatpt_t;
  81.  
  82. /*
  83.  * The hat structure is the machine dependent hardware address translation
  84.  * structure kept in the address space structure to show the translation.
  85.  */
  86. typedef struct hat {
  87.     struct    hatpt *hat_pts;        /* current page table list */
  88.     struct    hatpt *hat_ptlast;    /* last page table to fault */
  89. } hat_t;
  90.  
  91. typedef struct hatpgtc {
  92.     pte_t    hat_pte[HAT_EPMC];
  93. } hatpgtc_t;
  94.  
  95. /* The mapping chunk page declarations:
  96.  */
  97.  
  98. typedef union {
  99.     struct {
  100.         uint hat_mcaec    :  6,    /* active PTE count for chunk */
  101.                 :  1,    /* spare bit */
  102.              hat_ptcndx    : 25;    /* high order bits of pointer
  103.                      * to page table chunk.  Zeroed
  104.                      * low order bits completes
  105.                      * the pointer.
  106.                      */
  107.     } ptp;
  108.     uint hat_ptpv;
  109.     hatpgtc_t *hat_pgtcp;
  110. } hatptcp_t;
  111.  
  112. #define HATPTC_ADDR    0xFFFFFF80
  113.  
  114.  
  115. typedef union hatmpga {
  116.     uint    hat_mpgabits;        /* mapping chunk page allocation bits.
  117.                      * This may get changed if translation
  118.                      * cache needs it.
  119.                      */
  120.     hatptcp_t hatptcp[HAT_MCPP];    /* pointers to the page table chunks
  121.                      * for the 31 (1-31) mapping chunks
  122.                      * in the page.
  123.                      * Slot 0 corresponds to the hatmpga
  124.                      * data, so it is available for other use.
  125.                      */
  126. } hatmpga_t;
  127.  
  128. #define HATMCFULL    0xFFFFFFFF
  129.  
  130. typedef union hatmcpg {
  131.     hatmpga_t hat_mcpga;
  132.     hatmc_t hat_mc[HAT_MCPP];
  133. } hatmcpg_t;
  134.  
  135.  
  136. typedef struct hatpgt {
  137.     hatpgtc_t hat_pgtc[HAT_MCPP];
  138. } hatpgt_t;
  139.  
  140. /* Hat-specific parts of a page structure:
  141.    struct phat is always valid, struct phat2 is overlaid with p_dblist[]. */
  142.  
  143. struct phat {
  144.     caddr_t mappings;    /* List of mappings (translations) for this
  145.                    page; must be zero if no mappings. */
  146. };
  147.  
  148. struct phat2 {
  149.     union {
  150.         hatpt_t *ptap;
  151.         hatmcpg_t *mcpgp;
  152.     } ph_use;
  153. };
  154.  
  155. #define phat_ptap    p_hat2.ph_use.ptap
  156. #define phat_mcpgp    p_hat2.ph_use.mcpgp
  157.  
  158. /*
  159.  * Flags to pass to hat_ptalloc().
  160.  *
  161.  * NOTE: HAT_NOSLEEP and HAT_CANWAIT must match up with
  162.  *       P_NOSLEEP and P_CANWAIT (respectively) in vm_page.h
  163.  */
  164. #define    HAT_NOSLEEP    0    /* return immediately if no memory */
  165. #define HAT_CANWAIT    1    /* wait if no memory currently available */
  166. #define HAT_NOSTEAL    2    /* don't steal a PT from another process */    
  167.  
  168. /*
  169.  * Flags to pass to hat_ptsteal().
  170.  */
  171. #define HAT_PTUSED    0    /* stolen PT will be reused immediately */
  172.                 /* called from hat_ptalloc() */
  173. #define HAT_PTFREE    1    /* stolen PT will be freed, */
  174.                 /* called from hat_mcalloc() */
  175.  
  176.  
  177. #define HATMCNOSHFT    17    /* PNUMSHFT + LOG2(HAT_EPMC) */
  178. #define HATMCNOMASK    (HAT_MCPP-1)
  179. #define HATMCNDXSHFT    PNUMSHFT
  180. #define HATMCNDXMASK    (HAT_EPMC-1)
  181. #define MAPMCNOSHFT    7    
  182. #define MAPMCNDXSHFT    2
  183. #define HATMCNO(v)    (((uint)(v) >>HATMCNOSHFT) & HATMCNOMASK)
  184. #define HATMCNDX(v)    (((uint)(v) >>HATMCNDXSHFT) & HATMCNDXMASK)
  185. #define HATMAPMCNO(map)    (((uint)(map) >>MAPMCNOSHFT) & HATMCNOMASK)
  186. #define HATMAPMCNDX(map)(((uint)(map) >>MAPMCNDXSHFT) & HATMCNDXMASK)
  187. #define HATMCSIZE    (1 << HATMCNOSHFT)
  188. #define HATVMC_ADDR    0xFFFE0000
  189.  
  190. #ifdef _KERNEL
  191.  
  192. extern void restorepd();
  193.  
  194. #endif /* _KERNEL */
  195.  
  196. /* some HAT-specific macros: */
  197.  
  198. /* obtain the virtual address that maps the page frame number in a pte */
  199. #define ptetokv(pte)    (xphystokv((pte) & PG_ADDR))
  200.  
  201. /* from a mapping chunk pointer to the address of mapping chunk */
  202. #define mcptomapp(mcp)    ((hatmap_t *)((mcp)->hat_mcp))
  203.  
  204. /* from a mapping pointer to the page table chunk pointer */
  205. #define mapptoptcp(mapp) ((hatptcp_t *)((uint)(mapp) & PG_ADDR) \
  206.                 + HATMAPMCNO(mapp))
  207.  
  208. /* from a mapping pointer to the page table entry pointer */
  209. #define mapptoptep(mapp) ((pte_t *)(((hatptcp_t *)((uint)(mapp) & PG_ADDR) \
  210.               + HATMAPMCNO(mapp))->hat_ptpv & HATPTC_ADDR) \
  211.               + HATMAPMCNDX(mapp))
  212.  
  213. /* obtain page table chunk point from ptcp */
  214. #define ptcptoptep(ptcp) (pte_t *)(ptcp->hat_ptpv & HATPTC_ADDR) 
  215.  
  216. #define    APPEND_PT(PT, LIST)    {                    \
  217.                 (LIST).hatpt_prev->hatpt_next = PT;    \
  218.                 (PT)->hatpt_prev = (LIST).hatpt_prev;    \
  219.                 (PT)->hatpt_next = &LIST;            \
  220.                 (LIST).hatpt_prev = PT;            \
  221.             }
  222.  
  223. #define    PREPEND_PT(PT, LIST)    {                    \
  224.                 (LIST).hatpt_next->hatpt_prev = PT;    \
  225.                 (PT)->hatpt_next = (LIST).hatpt_next;    \
  226.                 (PT)->hatpt_prev = &LIST;            \
  227.                 (LIST).hatpt_next = PT;            \
  228.             }
  229.  
  230. #define    REMOVE_PT(PT)    {                        \
  231.             (PT)->hatpt_prev->hatpt_next = (PT)->hatpt_next;    \
  232.             (PT)->hatpt_next->hatpt_prev = (PT)->hatpt_prev;    \
  233.             }
  234.  
  235. #endif    /* _VM_VM_HAT_H */
  236.  
  237.