| 1 | #ifndef _LINUX_MM_H | 
|---|
| 2 | #define _LINUX_MM_H | 
|---|
| 3 |  | 
|---|
| 4 | #include <linux/sched.h> | 
|---|
| 5 | #include <linux/errno.h> | 
|---|
| 6 | #include <asm/page.h> | 
|---|
| 7 | #include <asm/atomic.h> | 
|---|
| 8 |  | 
|---|
| 9 | /* | 
|---|
| 10 | * GFP bitmasks.. | 
|---|
| 11 | */ | 
|---|
| 12 | #define __GFP_WAIT      0x01 | 
|---|
| 13 | #define __GFP_LOW       0x02 | 
|---|
| 14 | #define __GFP_MED       0x04 | 
|---|
| 15 | #define __GFP_HIGH      0x08 | 
|---|
| 16 | #define __GFP_IO        0x10 | 
|---|
| 17 | #define __GFP_SWAP      0x20 | 
|---|
| 18 | #ifdef CONFIG_HIGHMEM | 
|---|
| 19 | #define __GFP_HIGHMEM   0x40 | 
|---|
| 20 | #else | 
|---|
| 21 | #define __GFP_HIGHMEM   0x0 /* noop */ | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | #define __GFP_DMA       0x80 | 
|---|
| 25 |  | 
|---|
| 26 | #ifdef TARGET_OS2 | 
|---|
| 27 | #define __GFP_DMAHIGHMEM  0x100 | 
|---|
| 28 | #define GFP_DMAHIGHMEM    __GFP_DMAHIGHMEM | 
|---|
| 29 | #endif | 
|---|
| 30 |  | 
|---|
| 31 | #define GFP_BUFFER      (__GFP_LOW | __GFP_WAIT) | 
|---|
| 32 | #define GFP_ATOMIC      (__GFP_HIGH) | 
|---|
| 33 | #define GFP_USER        (__GFP_LOW | __GFP_WAIT | __GFP_IO) | 
|---|
| 34 | #define GFP_HIGHUSER    (GFP_USER | __GFP_HIGHMEM) | 
|---|
| 35 | #define GFP_KERNEL      (__GFP_MED | __GFP_WAIT | __GFP_IO) | 
|---|
| 36 | #define GFP_NFS         (__GFP_HIGH | __GFP_WAIT | __GFP_IO) | 
|---|
| 37 | #define GFP_KSWAPD      (__GFP_IO | __GFP_SWAP) | 
|---|
| 38 |  | 
|---|
| 39 | /* Flag - indicates that the buffer will be suitable for DMA.  Ignored on some | 
|---|
| 40 | platforms, used as appropriate on others */ | 
|---|
| 41 |  | 
|---|
| 42 | #define GFP_DMA         __GFP_DMA | 
|---|
| 43 |  | 
|---|
| 44 | /* Flag - indicates that the buffer can be taken from high memory which is not | 
|---|
| 45 | directly addressable by the kernel */ | 
|---|
| 46 |  | 
|---|
| 47 | #define GFP_HIGHMEM     __GFP_HIGHMEM | 
|---|
| 48 |  | 
|---|
| 49 | /* | 
|---|
| 50 | * This struct defines a memory VMM memory area. There is one of these | 
|---|
| 51 | * per VM-area/task.  A VM area is any part of the process virtual memory | 
|---|
| 52 | * space that has a special rule for the page-fault handlers (ie a shared | 
|---|
| 53 | * library, the executable area etc). | 
|---|
| 54 | */ | 
|---|
| 55 | struct vm_area_struct { | 
|---|
| 56 | struct mm_struct * vm_mm;       /* VM area parameters */ | 
|---|
| 57 | unsigned long vm_start; | 
|---|
| 58 | unsigned long vm_end; | 
|---|
| 59 |  | 
|---|
| 60 | /* linked list of VM areas per task, sorted by address */ | 
|---|
| 61 | struct vm_area_struct *vm_next; | 
|---|
| 62 |  | 
|---|
| 63 | pgprot_t vm_page_prot; | 
|---|
| 64 | unsigned short vm_flags; | 
|---|
| 65 |  | 
|---|
| 66 | /* AVL tree of VM areas per task, sorted by address */ | 
|---|
| 67 | short vm_avl_height; | 
|---|
| 68 | struct vm_area_struct * vm_avl_left; | 
|---|
| 69 | struct vm_area_struct * vm_avl_right; | 
|---|
| 70 |  | 
|---|
| 71 | /* For areas with inode, the list inode->i_mmap, for shm areas, | 
|---|
| 72 | * the list of attaches, otherwise unused. | 
|---|
| 73 | */ | 
|---|
| 74 | struct vm_area_struct *vm_next_share; | 
|---|
| 75 | struct vm_area_struct **vm_pprev_share; | 
|---|
| 76 |  | 
|---|
| 77 | struct vm_operations_struct * vm_ops; | 
|---|
| 78 | unsigned long vm_pgoff;         /* offset in PAGE_SIZE units, *not* PAGE_CACHE_SIZE */ | 
|---|
| 79 | struct file * vm_file; | 
|---|
| 80 | void * vm_private_data;         /* was vm_pte (shared mem) */ | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | /* | 
|---|
| 84 | * vm_flags.. | 
|---|
| 85 | */ | 
|---|
| 86 | #define VM_READ         0x0001  /* currently active flags */ | 
|---|
| 87 | #define VM_WRITE        0x0002 | 
|---|
| 88 | #define VM_EXEC         0x0004 | 
|---|
| 89 | #define VM_SHARED       0x0008 | 
|---|
| 90 |  | 
|---|
| 91 | #define VM_MAYREAD      0x0010  /* limits for mprotect() etc */ | 
|---|
| 92 | #define VM_MAYWRITE     0x0020 | 
|---|
| 93 | #define VM_MAYEXEC      0x0040 | 
|---|
| 94 | #define VM_MAYSHARE     0x0080 | 
|---|
| 95 |  | 
|---|
| 96 | #define VM_GROWSDOWN    0x0100  /* general info on the segment */ | 
|---|
| 97 | #define VM_GROWSUP      0x0200 | 
|---|
| 98 | #define VM_SHM          0x0400  /* shared memory area, don't swap out */ | 
|---|
| 99 | #define VM_DENYWRITE    0x0800  /* ETXTBSY on write attempts.. */ | 
|---|
| 100 |  | 
|---|
| 101 | #define VM_EXECUTABLE   0x1000 | 
|---|
| 102 | #define VM_LOCKED       0x2000 | 
|---|
| 103 | #define VM_IO           0x4000  /* Memory mapped I/O or similar */ | 
|---|
| 104 |  | 
|---|
| 105 | #define VM_STACK_FLAGS  0x0177 | 
|---|
| 106 |  | 
|---|
| 107 | /* Page flag bit values */ | 
|---|
| 108 | #define PG_locked                0 | 
|---|
| 109 | #define PG_error                 1 | 
|---|
| 110 | #define PG_referenced            2 | 
|---|
| 111 | #define PG_uptodate              3 | 
|---|
| 112 | #define PG_decr_after            5 | 
|---|
| 113 | #define PG_DMA                   7 | 
|---|
| 114 | #define PG_slab                  8 | 
|---|
| 115 | #define PG_swap_cache            9 | 
|---|
| 116 | #define PG_skip                 10 | 
|---|
| 117 | #define PG_swap_entry           11 | 
|---|
| 118 | #define PG_highmem              12 | 
|---|
| 119 | /* bits 21-30 unused */ | 
|---|
| 120 | #define PG_reserved             31 | 
|---|
| 121 |  | 
|---|
| 122 | typedef struct page { | 
|---|
| 123 | unsigned long index; | 
|---|
| 124 | atomic_t count; | 
|---|
| 125 | unsigned long flags;    /* atomic flags, some possibly updated asynchronously */ | 
|---|
| 126 | unsigned long virtual; /* nonzero if kmapped */ | 
|---|
| 127 | } mem_map_t; | 
|---|
| 128 |  | 
|---|
| 129 | extern mem_map_t * mem_map; | 
|---|
| 130 |  | 
|---|
| 131 | #define free_page(addr) free_pages((addr),0) | 
|---|
| 132 | extern int free_pages(unsigned long addr, unsigned long order); | 
|---|
| 133 |  | 
|---|
| 134 | #define virt_to_bus virt_to_phys | 
|---|
| 135 | extern unsigned long virt_to_phys(void * address); | 
|---|
| 136 |  | 
|---|
| 137 | extern mem_map_t *virt_to_page(int x); | 
|---|
| 138 |  | 
|---|
| 139 | extern void * phys_to_virt(unsigned long address); | 
|---|
| 140 |  | 
|---|
| 141 | #define __get_free_page(gfp_mask) __get_free_pages((gfp_mask),0) | 
|---|
| 142 | #define __get_dma_pages(gfp_mask, order) __get_free_pages((gfp_mask) | GFP_DMA,(order)) | 
|---|
| 143 |  | 
|---|
| 144 | extern void *__get_free_pages(int gfp_mask, unsigned long order); | 
|---|
| 145 | extern struct page * alloc_pages(int gfp_mask, unsigned long order); | 
|---|
| 146 |  | 
|---|
| 147 | extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, pgprot_t prot); | 
|---|
| 148 |  | 
|---|
| 149 | /* | 
|---|
| 150 | * Error return values for the *_nopage functions | 
|---|
| 151 | */ | 
|---|
| 152 | #define NOPAGE_SIGBUS   (NULL) | 
|---|
| 153 | #define NOPAGE_OOM      -1 | 
|---|
| 154 |  | 
|---|
| 155 | /* | 
|---|
| 156 | * These are the virtual MM functions - opening of an area, closing and | 
|---|
| 157 | * unmapping it (needed to keep files on disk up-to-date etc), pointer | 
|---|
| 158 | * to the functions called when a no-page or a wp-page exception occurs. | 
|---|
| 159 | */ | 
|---|
| 160 | struct vm_operations_struct { | 
|---|
| 161 | void (*open)(struct vm_area_struct * area); | 
|---|
| 162 | void (*close)(struct vm_area_struct * area); | 
|---|
| 163 | void (*unmap)(struct vm_area_struct *area, unsigned long, size_t); | 
|---|
| 164 | void (*protect)(struct vm_area_struct *area, unsigned long, size_t, unsigned int newprot); | 
|---|
| 165 | int (*sync)(struct vm_area_struct *area, unsigned long, size_t, unsigned int flags); | 
|---|
| 166 | void (*advise)(struct vm_area_struct *area, unsigned long, size_t, unsigned int advise); | 
|---|
| 167 | struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int write_access); | 
|---|
| 168 | struct page * (*wppage)(struct vm_area_struct * area, unsigned long address, struct page * page); | 
|---|
| 169 | int (*swapout)(struct page *, struct file *); | 
|---|
| 170 | }; | 
|---|
| 171 |  | 
|---|
| 172 | #endif | 
|---|