Add a 00-INDEX file to Documentation/mips/
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / scatterlist.h
blob2dc7464cce5245a0a41e458567372e9401bd58d3
1 #ifndef _LINUX_SCATTERLIST_H
2 #define _LINUX_SCATTERLIST_H
4 #include <asm/scatterlist.h>
5 #include <linux/mm.h>
6 #include <linux/string.h>
8 static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
9 unsigned int buflen)
11 sg->page = virt_to_page(buf);
12 sg->offset = offset_in_page(buf);
13 sg->length = buflen;
16 static inline void sg_init_one(struct scatterlist *sg, const void *buf,
17 unsigned int buflen)
19 memset(sg, 0, sizeof(*sg));
20 sg_set_buf(sg, buf, buflen);
24 * We overload the LSB of the page pointer to indicate whether it's
25 * a valid sg entry, or whether it points to the start of a new scatterlist.
26 * Those low bits are there for everyone! (thanks mason :-)
28 #define sg_is_chain(sg) ((unsigned long) (sg)->page & 0x01)
29 #define sg_chain_ptr(sg) \
30 ((struct scatterlist *) ((unsigned long) (sg)->page & ~0x01))
32 /**
33 * sg_next - return the next scatterlist entry in a list
34 * @sg: The current sg entry
36 * Usually the next entry will be @sg@ + 1, but if this sg element is part
37 * of a chained scatterlist, it could jump to the start of a new
38 * scatterlist array.
40 * Note that the caller must ensure that there are further entries after
41 * the current entry, this function will NOT return NULL for an end-of-list.
44 static inline struct scatterlist *sg_next(struct scatterlist *sg)
46 sg++;
48 if (unlikely(sg_is_chain(sg)))
49 sg = sg_chain_ptr(sg);
51 return sg;
55 * Loop over each sg element, following the pointer to a new list if necessary
57 #define for_each_sg(sglist, sg, nr, __i) \
58 for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
60 /**
61 * sg_last - return the last scatterlist entry in a list
62 * @sgl: First entry in the scatterlist
63 * @nents: Number of entries in the scatterlist
65 * Should only be used casually, it (currently) scan the entire list
66 * to get the last entry.
68 * Note that the @sgl@ pointer passed in need not be the first one,
69 * the important bit is that @nents@ denotes the number of entries that
70 * exist from @sgl@.
73 static inline struct scatterlist *sg_last(struct scatterlist *sgl,
74 unsigned int nents)
76 #ifndef ARCH_HAS_SG_CHAIN
77 struct scatterlist *ret = &sgl[nents - 1];
78 #else
79 struct scatterlist *sg, *ret = NULL;
80 int i;
82 for_each_sg(sgl, sg, nents, i)
83 ret = sg;
85 #endif
86 return ret;
89 /**
90 * sg_chain - Chain two sglists together
91 * @prv: First scatterlist
92 * @prv_nents: Number of entries in prv
93 * @sgl: Second scatterlist
95 * Links @prv@ and @sgl@ together, to form a longer scatterlist.
98 static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
99 struct scatterlist *sgl)
101 #ifndef ARCH_HAS_SG_CHAIN
102 BUG();
103 #endif
104 prv[prv_nents - 1].page = (struct page *) ((unsigned long) sgl | 0x01);
107 #endif /* _LINUX_SCATTERLIST_H */