1 #ifndef __LIBCFS_DARWIN_CFS_MEM_H__
2 #define __LIBCFS_DARWIN_CFS_MEM_H__
4 #ifndef __LIBCFS_LIBCFS_H__
5 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
10 #include <sys/types.h>
11 #include <sys/systm.h>
14 #include <sys/kernel.h>
17 #include <sys/malloc.h>
19 #include <sys/lockf.h>
21 #include <mach/mach_types.h>
22 #include <mach/vm_types.h>
24 #include <vm/vm_kern.h>
25 #include <mach/machine/vm_param.h>
26 #include <kern/thread_call.h>
27 #include <sys/param.h>
30 #include <libcfs/darwin/darwin-types.h>
31 #include <libcfs/darwin/darwin-sync.h>
32 #include <libcfs/darwin/darwin-lock.h>
33 #include <libcfs/list.h>
38 * There is no page in OSX, however, we need page in lustre.
40 #define PAGE_MASK (~(PAGE_SIZE-1))
41 #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
42 #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
43 #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
46 * Basic xnu_page struct, should be binary compatibility with
47 * all page types in xnu (we have only xnu_raw_page, xll_page now)
50 /* Variable sized pages are not supported */
52 #define CFS_PAGE_SHIFT 12
53 #define CFS_PAGE_SIZE (1 << CFS_PAGE_SHIFT)
54 #define PAGE_CACHE_SIZE CFS_PAGE_SIZE
55 #define CFS_PAGE_MASK (~(CFS_PAGE_SIZE - 1))
63 typedef __u32 page_off_t;
66 * For XNU we have our own page cache built on top of underlying BSD/MACH
67 * infrastructure. In particular, we have two disjoint types of pages:
69 * - "raw" pages (XNU_PAGE_RAW): these are just buffers mapped into KVM,
72 * - "xll" pages (XNU_PAGE_XLL): these are used by file system to cache
73 * file data, owned by file system objects, hashed, lrued, etc.
75 * cfs_page_t has to cover both of them, because core Lustre code is based on
76 * the Linux assumption that page is _both_ memory buffer and file system
79 * To achieve this, all types of pages supported on XNU has to start from
80 * common header that contains only "page type". Common cfs_page_t operations
81 * dispatch through operation vector based on page type.
84 typedef struct xnu_page {
89 void *(*page_map) (cfs_page_t *);
90 void (*page_unmap) (cfs_page_t *);
91 void *(*page_address) (cfs_page_t *);
94 void xnu_page_ops_register(int type, struct xnu_page_ops *ops);
95 void xnu_page_ops_unregister(int type);
98 * raw page, no cache object, just like buffer
100 struct xnu_raw_page {
101 struct xnu_page header;
102 vm_address_t virtual;
110 * Public interface to lustre
112 * - cfs_alloc_pages(f, o)
113 * - cfs_alloc_page(f)
114 * - cfs_free_pages(p, o)
118 * - cfs_page_address(p)
122 * Of all functions above only cfs_kmap(), cfs_kunmap(), and
123 * cfs_page_address() can be called on file system pages. The rest is for raw
127 cfs_page_t *cfs_alloc_pages(u_int32_t flags, u_int32_t order);
128 cfs_page_t *cfs_alloc_page(u_int32_t flags);
129 void cfs_free_pages(cfs_page_t *pages, int order);
130 void cfs_free_page(cfs_page_t *page);
131 void cfs_get_page(cfs_page_t *page);
132 int cfs_put_page_testzero(cfs_page_t *page);
133 int cfs_page_count(cfs_page_t *page);
134 void cfs_set_page_count(cfs_page_t *page, int v);
136 void *cfs_page_address(cfs_page_t *pg);
137 void *cfs_kmap(cfs_page_t *pg);
138 void cfs_kunmap(cfs_page_t *pg);
144 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
145 extern void cfs_free(void *addr);
147 extern void *cfs_alloc_large(size_t nr_bytes);
148 extern void cfs_free_large(void *addr);
153 * No slab in OSX, use zone allocator to fake slab
155 #define SLAB_HWCACHE_ALIGN 0
157 typedef struct cfs_mem_cache {
158 struct list_head link;
161 char name [ZONE_NAME_MAX_LEN];
164 #define KMEM_CACHE_MAX_COUNT 64
165 #define KMEM_MAX_ZONE 8192
167 extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long,
168 void (*)(void *, cfs_mem_cache_t *, unsigned long),
169 void (*)(void *, cfs_mem_cache_t *, unsigned long));
170 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
171 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
172 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
178 #define num_physpages (64 * 1024)
180 #define CFS_DECL_MMSPACE
181 #define CFS_MMSPACE_OPEN do {} while(0)
182 #define CFS_MMSPACE_CLOSE do {} while(0)
184 #define copy_from_user(kaddr, uaddr, size) copyin((caddr_t)uaddr, (caddr_t)kaddr, size)
185 #define copy_to_user(uaddr, kaddr, size) copyout((caddr_t)kaddr, (caddr_t)uaddr, size)
187 #if defined (__ppc__)
188 #define mb() __asm__ __volatile__ ("sync" : : : "memory")
189 #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
190 #define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
191 #elif defined (__i386__)
192 #define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
194 #define wmb() __asm__ __volatile__ ("": : :"memory")
196 #error architecture not supported
199 #else /* !__KERNEL__ */
201 typedef struct cfs_page{
204 #endif /* __KERNEL__ */
206 #endif /* __XNU_CFS_MEM_H__ */