svn commit: r210153 - projects/ofed/head/sys/ofed/include/linux
Jeff Roberson
jeff at FreeBSD.org
Fri Jul 16 00:56:18 UTC 2010
Author: jeff
Date: Fri Jul 16 00:56:17 2010
New Revision: 210153
URL: http://svn.freebsd.org/changeset/base/210153
Log:
- Add a scatterlist implementation and make use of it in the dma mapping
code.
Sponsored by: Isilon Systems, iX Systems, and Panasas.
Modified:
projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
projects/ofed/head/sys/ofed/include/linux/scatterlist.h
Modified: projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/dma-mapping.h Thu Jul 15 23:34:58 2010 (r210152)
+++ projects/ofed/head/sys/ofed/include/linux/dma-mapping.h Fri Jul 16 00:56:17 2010 (r210153)
@@ -150,17 +150,22 @@ dma_unmap_single_attrs(struct device *de
}
static inline int
-dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
+dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents,
enum dma_data_direction dir, struct dma_attrs *attrs)
{
- KASSERT(0, ("%s", __FUNCTION__));
+ struct scatterlist *sg;
+ int i;
+
+ for_each_sg(sgl, sg, nents, i)
+ sg_dma_address(sg) = sg_phys(sg);
+
+ return (nents);
}
static inline void
dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir, struct dma_attrs *attrs)
{
- KASSERT(0, ("%s", __FUNCTION__));
}
static inline dma_addr_t
@@ -177,7 +182,6 @@ dma_unmap_page(struct device *dev, dma_a
{
}
-/* XXX This is x86 specific, no syncs required. */
static inline void
dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
enum dma_data_direction direction)
Modified: projects/ofed/head/sys/ofed/include/linux/scatterlist.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/scatterlist.h Thu Jul 15 23:34:58 2010 (r210152)
+++ projects/ofed/head/sys/ofed/include/linux/scatterlist.h Fri Jul 16 00:56:17 2010 (r210153)
@@ -29,11 +29,69 @@
#define _LINUX_SCATTERLIST_H_
#include <linux/string.h>
+#include <linux/page.h>
struct scatterlist {
+ union {
+ struct page *page;
+ struct scatterlist *sg;
+ } sl_un;
+ unsigned long address;
+ unsigned long offset;
+ uint32_t length;
+ uint32_t flags;
};
-#define sg_dma_address(sg) 0
-#define sg_dma_len(sg) 0
+#define sg_dma_address(sg) (sg)->address
+#define sg_dma_len(sg) (sg)->length
+#define sg_page(sg) (sg)->sl_un.page
+#define sg_scatternext(sg) (sg)->sl_un.sg
+
+#define SG_END 0x01
+#define SG_CHAIN 0x02
+
+static inline void
+sg_set_page(struct scatterlist *sg, struct page *page, unsigned int len,
+ unsigned int offset)
+{
+ sg_page(sg) = page;
+ sg_dma_len(sg) = len;
+ sg_dma_address(sg) = 0;
+ sg->offset = offset;
+}
+
+static inline void
+sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int buflen)
+{
+ sg_set_page(sg, PHYS_TO_VM_PAGE(vtophys(buf)), buflen,
+ ((uintptr_t)buf) & PAGE_MASK);
+}
+
+static inline void
+sg_init_table(struct scatterlist *sg, unsigned int nents)
+{
+ bzero(sg, sizeof(*sg) * nents);
+ sg[nents].flags = SG_END;
+}
+
+static inline struct scatterlist *
+sg_next(struct scatterlist *sg)
+{
+ if (sg->flags & SG_END)
+ return (NULL);
+ sg++;
+ if (sg->flags & SG_CHAIN)
+ sg = sg_scatternext(sg);
+ return (sg);
+}
+
+static inline vm_paddr_t
+sg_phys(struct scatterlist *sg)
+{
+ return sg_page(sg)->phys_addr + sg->offset;
+}
+
+#define for_each_sg(sglist, sg, sgmax, _itr) \
+ for (_itr = 0, sg = (sglist); _itr < (sgmax); _itr++, sg = sg_next(sg))
#endif /* _LINUX_SCATTERLIST_H_ */
More information about the svn-src-projects
mailing list