--- include/linux/xpmem.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) Index: linux-2.6/include/linux/xmem.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6/include/linux/xmem.h 2008-01-07 15:47:30.000000000 -0800 @@ -0,0 +1,122 @@ +#ifndef __LINUX_XMEM +#define __LINUX_XMEM + +/* + * External memory API. + * + * These function allow the importing of memory that is not managed by the + * Linux kernel for things like: + * + * 1. Access to specialized DMA memory + * 2. Virtualization: Access to memory exported from other guests or from + * the host. + * 3. Large coherent memory machines: Access to exported memory from other + * partitions + * 4. RDMA: Access to memory segment via a network (Infiniband) + * + * The functionality here also allows the exporting of memory for + * + * 1. Large Coherence memory machines: Outside access by other partitions. + * 2. DMA access for special DMA engines or coprocessors + * 3. Virtualization: Exporting of memory areas to be used by other guests. + * 4. RDMA: Provide a memory area accessible via a network + * + * In order to support external memory a xmem device driver needs to be + * written that registers itself using register_xmem_device(); + * + * xmem device drivers can allow sharing of memory in two modes: + * + * 1. Coherent: Both exporter and importer map the same memory + * Running xmem_copy on a coherent mapping has no effect. This means + * that it is possible to code xmem handling without regard + * to the memory mode. A coherent device driver does not populate + * the copy method. + * + * 2. Snapshot: Importer/Exporters runs xmem_copy to take a snapshot + * Running xmem_copy will take a fast snapshot from the system + * that exported the memory using a hardware mechanism. + * xmem_import allocates a buffer. + */ + +int xmem_system_id = -1; + +/* + * Xmem handles consist of 32 bits to describe the system that is + * exporting the memory and a 32 bit handle to the exported segment + * from a certain system. Xmem handles must be transferred via some + * other communication medium between the exporter and importer before + * access from both side to memory becomes possible. + */ + +unsigned int xmem_get_sys_id(xmem_t handle) +{ + return handle >> 32; +} + +unsigned int xmem_get_local_id(xmem_t handle) +{ + VM_BUG_ON(xmem_get_sys_id(handle) != xmem_system_id); + return handle & ((1 << 32) - 1); +} + +/* + * Xmem segment descriptor. + * + * Note that an mm_struct may have multiple overlapping exports for the + * same address range. + */ +struct xmem_seg { + xmem_t handle; /* Handle used for this segment */ + struct xmem_device *dev; /* Device handling this segment */ + unsigned long flags; /* Flags */ + unsigned long from; /* Mapped address space */ + unsigned long to; + struct vm_area_struct *vma; /* vma struct we are attached to */ + struct xmem_seg *next; +} + +struct xmem_seg *first_seg; /* Chained list of xpm segments */ + +#define XMEM_SEG_EXPORT 1 /* Exported range */ +#define XMEM_SEG_IMPORT 2 /* Imported range */ +#define XMEM_SEG_COHERENT 4 /* Memory can be shared across systems */ +#define XMEM_SEG_LOCKED 8 /* Handle is locked */ + +struct xmem_driver { + struct xmem_seg *export(struct vm_area_struct *vma, unsigned long offset, unsigned flags); + int free(struct xmem_seg *i, struct vm_area_struct *vma); + /* Also called from the tlb_start/end_vma callout to remove a vma */ + int import(struct xmem_seg *i, struct vm_area_struct *vma); + int copy(struct xmem_seg *i, struct vm_area_struct *vma, unsigned long length, + unsigned long src_offset, unsigned long dst_offset) + int unmap_page(struct xmem_seg *i, struct page *page, + struct vm_area_struct *vma, unsigned long addr); +}; + +struct xmem_device { + int system; /* If -1 then a local device */ + int id; + struct device dev; + struct xmem_driver *driver; +}; + +int register_xmem_device(struct xmem_driver *); +int unregister_xmem_device(struct xmem_driver *); + +xmem_t sys_xmem_export(unsigned long start, unsigned long length, + unsigned long flags) + +int sys_xmem_import(xmem_t handle, unsigned long start, unsigned long length, + unsigned long offset, unsigned long flags); + +#define XMEM_COHERENT 1 /* Require that the import be coherent */ + +int sys_xmem_copy(xmem_t handle, unsigned long start, + unsigned long length, unsigned long offset, unsigned long flags); + +#define XMEM_BATCH 1 /* sys_xpm_copy is nonblocking */ + +int sys_xmem_free(xmem_t handle) + +#endif /* __LINUX_XMEM */ + Index: linux-2.6/include/linux/mm.h =================================================================== --- linux-2.6.orig/include/linux/mm.h 2008-01-07 10:38:11.000000000 -0800 +++ linux-2.6/include/linux/mm.h 2008-01-07 15:18:43.000000000 -0800 @@ -107,6 +107,8 @@ extern unsigned int kobjsize(const void #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */ +#define VM_XMEM_EXPORT 0x10000000 /* Memory is exported via XMEM */ + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */ #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS #endif Index: linux-2.6/include/linux/mm_types.h =================================================================== --- linux-2.6.orig/include/linux/mm_types.h 2008-01-07 10:38:11.000000000 -0800 +++ linux-2.6/include/linux/mm_types.h 2008-01-07 15:18:43.000000000 -0800 @@ -151,6 +151,9 @@ struct vm_area_struct { #ifdef CONFIG_NUMA struct mempolicy *vm_policy; /* NUMA policy for the VMA */ #endif +#ifdef CONFIG_XMEM + struct xmem_seg *xmem_seg; /* first (of possibly many) xmem_segs */ +#endif }; struct mm_struct {