]> err.no Git - linux-2.6/blobdiff - include/linux/scatterlist.h
hugetlb: follow_hugetlb_page() for write access
[linux-2.6] / include / linux / scatterlist.h
index 809b2ac2e37e04f98103919013c942cc1ff17ee5..25973504414823b7876d2f34256ea1f103018ddb 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _LINUX_SCATTERLIST_H
 #define _LINUX_SCATTERLIST_H
 
+#include <asm/types.h>
 #include <asm/scatterlist.h>
 #include <linux/mm.h>
 #include <linux/string.h>
@@ -149,7 +150,7 @@ static inline struct scatterlist *sg_last(struct scatterlist *sgl,
        struct scatterlist *ret = &sgl[nents - 1];
 #else
        struct scatterlist *sg, *ret = NULL;
-       int i;
+       unsigned int i;
 
        for_each_sg(sgl, sg, nents, i)
                ret = sg;
@@ -178,48 +179,32 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
 #ifndef ARCH_HAS_SG_CHAIN
        BUG();
 #endif
-       prv[prv_nents - 1].page_link = (unsigned long) sgl | 0x01;
+       /*
+        * Set lowest bit to indicate a link pointer, and make sure to clear
+        * the termination bit if it happens to be set.
+        */
+       prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02;
 }
 
 /**
  * sg_mark_end - Mark the end of the scatterlist
- * @sgl:       Scatterlist
- * @nents:     Number of entries in sgl
+ * @sg:                 SG entryScatterlist
  *
  * Description:
- *   Marks the last entry as the termination point for sg_next()
- *
- **/
-static inline void sg_mark_end(struct scatterlist *sgl, unsigned int nents)
-{
-       sgl[nents - 1].page_link = 0x02;
-}
-
-static inline void __sg_mark_end(struct scatterlist *sg)
-{
-       sg->page_link |= 0x02;
-}
-
-/**
- * sg_init_one - Initialize a single entry sg list
- * @sg:                 SG entry
- * @buf:        Virtual address for IO
- * @buflen:     IO length
- *
- * Notes:
- *   This should not be used on a single entry that is part of a larger
- *   table. Use sg_init_table() for that.
+ *   Marks the passed in sg entry as the termination point for the sg
+ *   table. A call to sg_next() on this entry will return NULL.
  *
  **/
-static inline void sg_init_one(struct scatterlist *sg, const void *buf,
-                              unsigned int buflen)
+static inline void sg_mark_end(struct scatterlist *sg)
 {
-       memset(sg, 0, sizeof(*sg));
 #ifdef CONFIG_DEBUG_SG
-       sg->sg_magic = SG_MAGIC;
+       BUG_ON(sg->sg_magic != SG_MAGIC);
 #endif
-       sg_mark_end(sg, 1);
-       sg_set_buf(sg, buf, buflen);
+       /*
+        * Set termination bit, clear potential chain bit
+        */
+       sg->page_link |= 0x02;
+       sg->page_link &= ~0x01;
 }
 
 /**
@@ -235,14 +220,32 @@ static inline void sg_init_one(struct scatterlist *sg, const void *buf,
 static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
 {
        memset(sgl, 0, sizeof(*sgl) * nents);
-       sg_mark_end(sgl, nents);
 #ifdef CONFIG_DEBUG_SG
        {
-               int i;
+               unsigned int i;
                for (i = 0; i < nents; i++)
                        sgl[i].sg_magic = SG_MAGIC;
        }
 #endif
+       sg_mark_end(&sgl[nents - 1]);
+}
+
+/**
+ * sg_init_one - Initialize a single entry sg list
+ * @sg:                 SG entry
+ * @buf:        Virtual address for IO
+ * @buflen:     IO length
+ *
+ * Notes:
+ *   This should not be used on a single entry that is part of a larger
+ *   table. Use sg_init_table() for that.
+ *
+ **/
+static inline void sg_init_one(struct scatterlist *sg, const void *buf,
+                              unsigned int buflen)
+{
+       sg_init_table(sg, 1);
+       sg_set_buf(sg, buf, buflen);
 }
 
 /**
@@ -255,7 +258,7 @@ static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
  *   on the sg page.
  *
  **/
-static inline unsigned long sg_phys(struct scatterlist *sg)
+static inline dma_addr_t sg_phys(struct scatterlist *sg)
 {
        return page_to_phys(sg_page(sg)) + sg->offset;
 }