svn commit: r219358 - projects/ofed/head/sys/ofed/include/linux

Jeff Roberson jeff at FreeBSD.org
Mon Mar 7 02:11:44 UTC 2011


Author: jeff
Date: Mon Mar  7 02:11:44 2011
New Revision: 219358
URL: http://svn.freebsd.org/changeset/base/219358

Log:
   - Implement netdev_priv().
   - Implement timer_pendiong().
   - Implement spin_trylock().
   - Add defines for bools used in Linux code.
   - Redefine dma mapping pci macros to avoid namespace pollution and add
     two missing routines.

Modified:
  projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
  projects/ofed/head/sys/ofed/include/linux/linux_compat.c
  projects/ofed/head/sys/ofed/include/linux/list.h
  projects/ofed/head/sys/ofed/include/linux/netdevice.h
  projects/ofed/head/sys/ofed/include/linux/pci.h
  projects/ofed/head/sys/ofed/include/linux/spinlock.h
  projects/ofed/head/sys/ofed/include/linux/timer.h
  projects/ofed/head/sys/ofed/include/linux/types.h
  projects/ofed/head/sys/ofed/include/linux/vmalloc.h

Modified: projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/dma-mapping.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/dma-mapping.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -226,6 +226,18 @@ dma_sync_sg_for_device(struct device *de
 {
 }
 
+static inline void
+dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
+    unsigned long offset, size_t size, int direction)
+{
+}
+
+static inline void
+dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
+    unsigned long offset, size_t size, int direction)
+{
+}
+
 static inline int
 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {

Modified: projects/ofed/head/sys/ofed/include/linux/linux_compat.c
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/linux_compat.c	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/linux_compat.c	Mon Mar  7 02:11:44 2011	(r219358)
@@ -53,6 +53,7 @@
 #include <linux/sysfs.h>
 #include <linux/mm.h>
 #include <linux/io.h>
+#include <linux/vmalloc.h>
 
 #include <vm/vm_pager.h>
 
@@ -562,38 +563,61 @@ struct fileops linuxfileops = {
 };
 
 /*
- * Hash of iomap addresses.  This is infrequently accessed and does not
+ * Hash of vmmap addresses.  This is infrequently accessed and does not
  * need to be particularly large.  This is done because we must store the
  * caller's idea of the map size to properly unmap.
  */
-struct iomap {
-	LIST_ENTRY(iomap)	im_next;
-	void 			*im_addr;
-	unsigned long		im_size;
+struct vmmap {
+	LIST_ENTRY(vmmap)	vm_next;
+	void 			*vm_addr;
+	unsigned long		vm_size;
 };
 
-LIST_HEAD(iomaphd, iomap);
-#define	IOMAP_HASH_SIZE	64
-#define	IOMAP_HASH_MASK	(IOMAP_HASH_SIZE - 1)
-#define	IO_HASH(addr)	((uintptr_t)(addr) >> PAGE_SHIFT) & IOMAP_HASH_MASK
-static struct iomaphd iomaphead[IOMAP_HASH_SIZE];
-static struct mtx iomaplock;
+LIST_HEAD(vmmaphd, vmmap);
+#define	VMMAP_HASH_SIZE	64
+#define	VMMAP_HASH_MASK	(VMMAP_HASH_SIZE - 1)
+#define	VM_HASH(addr)	((uintptr_t)(addr) >> PAGE_SHIFT) & VMMAP_HASH_MASK
+static struct vmmaphd vmmaphead[VMMAP_HASH_SIZE];
+static struct mtx vmmaplock;
+
+static void
+vmmap_add(void *addr, unsigned long size)
+{
+	struct vmmap *vmmap;
+
+	vmmap = kmalloc(sizeof(*vmmap), GFP_KERNEL);
+	mtx_lock(&vmmaplock);
+	vmmap->vm_size = size;
+	vmmap->vm_addr = addr;
+	LIST_INSERT_HEAD(&vmmaphead[VM_HASH(addr)], vmmap, vm_next);
+	mtx_unlock(&vmmaplock);
+}
+
+static struct vmmap *
+vmmap_remove(void *addr)
+{
+	struct vmmap *vmmap;
+
+	mtx_lock(&vmmaplock);
+	LIST_FOREACH(vmmap, &vmmaphead[VM_HASH(addr)], vm_next)
+		if (vmmap->vm_addr == addr)
+			break;
+	if (vmmap)
+		LIST_REMOVE(vmmap, vm_next);
+	mtx_unlock(&vmmaplock);
+
+	return (vmmap);
+}
 
 void *
 _ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr)
 {
-	struct iomap *iomap;
 	void *addr;
 
 	addr = pmap_mapdev_attr(phys_addr, size, attr);
 	if (addr == NULL)
 		return (NULL);
-	iomap = kmalloc(sizeof(*iomap), GFP_KERNEL);
-	mtx_lock(&iomaplock);
-	iomap->im_size = size;
-	iomap->im_addr = addr;
-	LIST_INSERT_HEAD(&iomaphead[IO_HASH(addr)], iomap, im_next);
-	mtx_unlock(&iomaplock);
+	vmmap_add(addr, size);
 
 	return (addr);
 }
@@ -601,22 +625,45 @@ _ioremap_attr(vm_paddr_t phys_addr, unsi
 void
 iounmap(void *addr)
 {
-	struct iomap *iomap;
+	struct vmmap *vmmap;
 
-	mtx_lock(&iomaplock);
-	LIST_FOREACH(iomap, &iomaphead[IO_HASH(addr)], im_next)
-		if (iomap->im_addr == addr)
-			break;
-	if (iomap)
-		LIST_REMOVE(iomap, im_next);
-	mtx_unlock(&iomaplock);
-	if (iomap == NULL)
+	vmmap = vmmap_remove(addr);
+	if (vmmap == NULL)
 		return;
-	pmap_unmapdev((vm_offset_t)addr, iomap->im_size);
-	kfree(iomap);
+	pmap_unmapdev((vm_offset_t)addr, vmmap->vm_size);
+	kfree(vmmap);
 }
 
 
+void *
+vmap(struct page **pages, unsigned int count, unsigned long flags, int prot)
+{
+	vm_offset_t off;
+	size_t size;
+
+	size = count * PAGE_SIZE;
+	off = kmem_alloc_nofault(kernel_map, size);
+	if (off == 0)
+		return (NULL);
+	vmmap_add((void *)off, size);
+	pmap_qenter(off, pages, count);
+
+	return ((void *)off);
+}
+
+void
+vunmap(void *addr)
+{
+	struct vmmap *vmmap;
+
+	vmmap = vmmap_remove(addr);
+	if (vmmap == NULL)
+		return;
+	pmap_qremove((vm_offset_t)addr, vmmap->vm_size / PAGE_SIZE);
+	kmem_free(kernel_map, (vm_offset_t)addr, vmmap->vm_size);
+	kfree(vmmap);
+}
+
 static void
 linux_compat_init(void)
 {
@@ -640,9 +687,9 @@ linux_compat_init(void)
 	INIT_LIST_HEAD(&pci_drivers);
 	INIT_LIST_HEAD(&pci_devices);
 	spin_lock_init(&pci_lock);
-	mtx_init(&iomaplock, "IO Map lock", NULL, MTX_DEF);
-	for (i = 0; i < IOMAP_HASH_SIZE; i++)
-		LIST_INIT(&iomaphead[i]);
+	mtx_init(&vmmaplock, "IO Map lock", NULL, MTX_DEF);
+	for (i = 0; i < VMMAP_HASH_SIZE; i++)
+		LIST_INIT(&vmmaphead[i]);
 }
 
 SYSINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_init, NULL);

Modified: projects/ofed/head/sys/ofed/include/linux/list.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/list.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/list.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -44,7 +44,9 @@
 #include <sys/vnode.h>
 #include <sys/conf.h>
 #include <sys/socket.h>
+#include <sys/mbuf.h>
 
+#include <net/bpf.h>
 #include <net/if.h>
 #include <net/if_types.h>
 

Modified: projects/ofed/head/sys/ofed/include/linux/netdevice.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/netdevice.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/netdevice.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -61,6 +61,12 @@ extern struct net init_net;
 #define	netif_oper_up(dev)	!!((dev)->if_flags & IFF_UP)
 #define	netif_carrier_ok(dev)	netif_running(dev)
 
+static inline void *
+netdev_priv(const struct net_device *dev)
+{
+	return (dev->if_softc);
+}
+
 static inline void
 _handle_ifnet_link_event(void *arg, struct ifnet *ifp, int linkstate)
 {

Modified: projects/ofed/head/sys/ofed/include/linux/pci.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/pci.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/pci.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -534,28 +534,34 @@ pci_enable_msix(struct pci_dev *pdev, st
 #define pci_pool_destroy	dma_pool_destroy
 #define pci_pool_alloc		dma_pool_alloc
 #define pci_pool_free		dma_pool_free
-#define	pci_pool_create(name, pdev, size, align, allocation)		\
-	    dma_pool_create(name, &(pdev)->dev, size, align, allocation)
-#define	pci_free_consistent(hwdev, size, vaddr, dma_handle)		\
-	    dma_free_coherent((hwdev) == NULL ? NULL : &(hwdev)->dev,	\
-		size, vaddr, dma_handle)
-#define	pci_map_sg(hwdev, sg, nents, direction)				\
-	    dma_map_sg((hwdev) == NULL ? NULL : &(hwdev->dev),		\
-		sg, nents, (enum dma_data_direction)direction)
-#define	pci_unmap_sg(hwdev, sg, nents, direction)			\
-	    dma_unmap_sg((hwdev) == NULL ? NULL : &(hwdev)->dev,	\
-		sg, nents, (enum dma_data_direction)direction)
-#define	pci_map_page(hwdev, page, offset, size, direction)		\
-	    dma_map_page((hwdev) == NULL ? NULL : &(hwdev)->dev, page,	\
-		offset, size, (enum dma_data_direction)direction)
-#define	pci_unmap_page(hwdev, dma_address, size, direction)		\
-	    dma_unmap_page((hwdev) == NULL ? NULL : &(hwdev)->dev,	\
-		dma_address, size, (enum dma_data_direction)direction)
-#define	pci_set_dma_mask(pdev, mask)	dma_set_mask(&(pdev)->dev, (mask))
-#define	pci_dma_mapping_error(pdev, dma_addr)				\
-	    dma_mapping_error(&(pdev)->dev, dma_addr)
-#define	pci_set_consistent_dma_mask(pdev, mask)				\
-	    dma_set_coherent_mask(&(pdev)->dev, (mask))
+#define	pci_pool_create(_name, _pdev, _size, _align, _alloc)		\
+	    dma_pool_create(_name, &(_pdev)->dev, _size, _align, _alloc)
+#define	pci_free_consistent(_hwdev, _size, _vaddr, _dma_handle)		\
+	    dma_free_coherent((_hwdev) == NULL ? NULL : &(_hwdev)->dev,	\
+		_size, _vaddr, _dma_handle)
+#define	pci_map_sg(_hwdev, _sg, _nents, _dir)				\
+	    dma_map_sg((_hwdev) == NULL ? NULL : &(_hwdev->dev),	\
+		_sg, _nents, (enum dma_data_direction)_dir)
+#define	pci_map_single(_hwdev, _ptr, _size, _dir)			\
+	    dma_map_single((_hwdev) == NULL ? NULL : &(_hwdev->dev),	\
+		(_ptr), (_size), (enum dma_data_direction)_dir)
+#define	pci_unmap_single(_hwdev, _addr, _size, _dir)			\
+	    dma_unmap_single((_hwdev) == NULL ? NULL : &(_hwdev)->dev,	\
+		_addr, _size, (enum dma_data_direction)_dir)
+#define	pci_unmap_sg(_hwdev, _sg, _nents, _dir)				\
+	    dma_unmap_sg((_hwdev) == NULL ? NULL : &(_hwdev)->dev,	\
+		_sg, _nents, (enum dma_data_direction)_dir)
+#define	pci_map_page(_hwdev, _page, _offset, _size, _dir)		\
+	    dma_map_page((_hwdev) == NULL ? NULL : &(_hwdev)->dev, _page,\
+		_offset, _size, (enum dma_data_direction)_dir)
+#define	pci_unmap_page(_hwdev, _dma_address, _size, _dir)		\
+	    dma_unmap_page((_hwdev) == NULL ? NULL : &(_hwdev)->dev,	\
+		_dma_address, _size, (enum dma_data_direction)_dir)
+#define	pci_set_dma_mask(_pdev, mask)	dma_set_mask(&(_pdev)->dev, (mask))
+#define	pci_dma_mapping_error(_pdev, _dma_addr)				\
+	    dma_mapping_error(&(_pdev)->dev, _dma_addr)
+#define	pci_set_consistent_dma_mask(_pdev, _mask)			\
+	    dma_set_coherent_mask(&(_pdev)->dev, (_mask))
 #define	DECLARE_PCI_UNMAP_ADDR(x)	DEFINE_DMA_UNMAP_ADDR(x);
 #define	DECLARE_PCI_UNMAP_LEN(x)	DEFINE_DMA_UNMAP_LEN(x);
 #define	pci_unmap_addr		dma_unmap_addr

Modified: projects/ofed/head/sys/ofed/include/linux/spinlock.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/spinlock.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/spinlock.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -44,6 +44,7 @@ typedef struct {
 
 #define	spin_lock(_l)		mtx_lock(&(_l)->m)
 #define	spin_unlock(_l)		mtx_unlock(&(_l)->m)
+#define	spin_trylock(_l)	mtx_trylock(&(_l)->m)
 #define	spin_lock_nested(_l, _n) mtx_lock_flags(&(_l)->m, MTX_DUPOK)
 #define	spin_lock_irq(lock)	spin_lock(lock)
 #define	spin_unlock_irq(lock)	spin_unlock(lock)

Modified: projects/ofed/head/sys/ofed/include/linux/timer.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/timer.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/timer.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -76,6 +76,8 @@ do {									\
 #define	del_timer(timer)	callout_stop(&(timer)->timer_callout)
 #define	del_timer_sync(timer)	callout_drain(&(timer)->timer_callout)
 
+#define	timer_pending(timer)	callout_pending(&(timer)->timer_callout)
+
 static inline unsigned long
 round_jiffies(unsigned long j)
 {

Modified: projects/ofed/head/sys/ofed/include/linux/types.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/types.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/types.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -39,6 +39,9 @@ typedef __u32 __le32;
 typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
+typedef _Bool bool;
+#define	true	TRUE
+#define	false	FALSE
 
 typedef unsigned long kernel_ulong_t;
 typedef unsigned int    uint;

Modified: projects/ofed/head/sys/ofed/include/linux/vmalloc.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/vmalloc.h	Mon Mar  7 00:44:00 2011	(r219357)
+++ projects/ofed/head/sys/ofed/include/linux/vmalloc.h	Mon Mar  7 02:11:44 2011	(r219358)
@@ -29,4 +29,13 @@
 #ifndef _LINUX_VMALLOC_H_
 #define	_LINUX_VMALLOC_H_
 
+#include <asm/page.h>
+
+#define	VM_MAP		0x0000
+#define	PAGE_KERNEL	0x0000
+
+void *vmap(struct page **pages, unsigned int count, unsigned long flags,
+    int prot);
+void vunmap(void *addr);
+
 #endif	/* _LINUX_VMALLOC_H_ */


More information about the svn-src-projects mailing list