aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/scatterlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/scatterlist.h')
-rw-r--r--include/linux/scatterlist.h78
1 files changed, 54 insertions, 24 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 1645795cbb13..c6136e8a7f58 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -2,9 +2,26 @@
2#define _LINUX_SCATTERLIST_H 2#define _LINUX_SCATTERLIST_H
3 3
4#include <asm/scatterlist.h> 4#include <asm/scatterlist.h>
5#include <asm/io.h>
6#include <linux/mm.h> 5#include <linux/mm.h>
7#include <linux/string.h> 6#include <linux/string.h>
7#include <asm/io.h>
8
9/*
10 * Notes on SG table design.
11 *
12 * Architectures must provide an unsigned long page_link field in the
13 * scatterlist struct. We use that to place the page pointer AND encode
14 * information about the sg table as well. The two lower bits are reserved
15 * for this information.
16 *
17 * If bit 0 is set, then the page_link contains a pointer to the next sg
18 * table list. Otherwise the next entry is at sg + 1.
19 *
20 * If bit 1 is set, then this sg entry is the last element in a list.
21 *
22 * See sg_next().
23 *
24 */
8 25
9/** 26/**
10 * sg_set_page - Set sg entry to point at given page 27 * sg_set_page - Set sg entry to point at given page
@@ -20,11 +37,20 @@
20 **/ 37 **/
21static inline void sg_set_page(struct scatterlist *sg, struct page *page) 38static inline void sg_set_page(struct scatterlist *sg, struct page *page)
22{ 39{
23 sg->page = page; 40 unsigned long page_link = sg->page_link & 0x3;
41
42 sg->page_link = page_link | (unsigned long) page;
24} 43}
25 44
26#define sg_page(sg) ((sg)->page) 45#define sg_page(sg) ((struct page *) ((sg)->page_link & ~0x3))
27 46
47/**
48 * sg_set_buf - Set sg entry to point at given data
49 * @sg: SG entry
50 * @buf: Data
51 * @buflen: Data length
52 *
53 **/
28static inline void sg_set_buf(struct scatterlist *sg, const void *buf, 54static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
29 unsigned int buflen) 55 unsigned int buflen)
30{ 56{
@@ -38,26 +64,27 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
38 * a valid sg entry, or whether it points to the start of a new scatterlist. 64 * a valid sg entry, or whether it points to the start of a new scatterlist.
39 * Those low bits are there for everyone! (thanks mason :-) 65 * Those low bits are there for everyone! (thanks mason :-)
40 */ 66 */
41#define sg_is_chain(sg) ((unsigned long) (sg)->page & 0x01) 67#define sg_is_chain(sg) ((sg)->page_link & 0x01)
68#define sg_is_last(sg) ((sg)->page_link & 0x02)
42#define sg_chain_ptr(sg) \ 69#define sg_chain_ptr(sg) \
43 ((struct scatterlist *) ((unsigned long) (sg)->page & ~0x01)) 70 ((struct scatterlist *) ((sg)->page_link & ~0x03))
44 71
45/** 72/**
46 * sg_next - return the next scatterlist entry in a list 73 * sg_next - return the next scatterlist entry in a list
47 * @sg: The current sg entry 74 * @sg: The current sg entry
48 * 75 *
49 * Usually the next entry will be @sg@ + 1, but if this sg element is part 76 * Description:
50 * of a chained scatterlist, it could jump to the start of a new 77 * Usually the next entry will be @sg@ + 1, but if this sg element is part
51 * scatterlist array. 78 * of a chained scatterlist, it could jump to the start of a new
52 * 79 * scatterlist array.
53 * Note that the caller must ensure that there are further entries after
54 * the current entry, this function will NOT return NULL for an end-of-list.
55 * 80 *
56 */ 81 **/
57static inline struct scatterlist *sg_next(struct scatterlist *sg) 82static inline struct scatterlist *sg_next(struct scatterlist *sg)
58{ 83{
59 sg++; 84 if (sg_is_last(sg))
85 return NULL;
60 86
87 sg++;
61 if (unlikely(sg_is_chain(sg))) 88 if (unlikely(sg_is_chain(sg)))
62 sg = sg_chain_ptr(sg); 89 sg = sg_chain_ptr(sg);
63 90
@@ -75,14 +102,15 @@ static inline struct scatterlist *sg_next(struct scatterlist *sg)
75 * @sgl: First entry in the scatterlist 102 * @sgl: First entry in the scatterlist
76 * @nents: Number of entries in the scatterlist 103 * @nents: Number of entries in the scatterlist
77 * 104 *
78 * Should only be used casually, it (currently) scan the entire list 105 * Description:
79 * to get the last entry. 106 * Should only be used casually, it (currently) scan the entire list
107 * to get the last entry.
80 * 108 *
81 * Note that the @sgl@ pointer passed in need not be the first one, 109 * Note that the @sgl@ pointer passed in need not be the first one,
82 * the important bit is that @nents@ denotes the number of entries that 110 * the important bit is that @nents@ denotes the number of entries that
83 * exist from @sgl@. 111 * exist from @sgl@.
84 * 112 *
85 */ 113 **/
86static inline struct scatterlist *sg_last(struct scatterlist *sgl, 114static inline struct scatterlist *sg_last(struct scatterlist *sgl,
87 unsigned int nents) 115 unsigned int nents)
88{ 116{
@@ -105,16 +133,17 @@ static inline struct scatterlist *sg_last(struct scatterlist *sgl,
105 * @prv_nents: Number of entries in prv 133 * @prv_nents: Number of entries in prv
106 * @sgl: Second scatterlist 134 * @sgl: Second scatterlist
107 * 135 *
108 * Links @prv@ and @sgl@ together, to form a longer scatterlist. 136 * Description:
137 * Links @prv@ and @sgl@ together, to form a longer scatterlist.
109 * 138 *
110 */ 139 **/
111static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, 140static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
112 struct scatterlist *sgl) 141 struct scatterlist *sgl)
113{ 142{
114#ifndef ARCH_HAS_SG_CHAIN 143#ifndef ARCH_HAS_SG_CHAIN
115 BUG(); 144 BUG();
116#endif 145#endif
117 prv[prv_nents - 1].page = (struct page *) ((unsigned long) sgl | 0x01); 146 prv[prv_nents - 1].page_link = (unsigned long) sgl | 0x01;
118} 147}
119 148
120/** 149/**
@@ -128,13 +157,14 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
128 **/ 157 **/
129static inline void sg_mark_end(struct scatterlist *sgl, unsigned int nents) 158static inline void sg_mark_end(struct scatterlist *sgl, unsigned int nents)
130{ 159{
160 sgl[nents - 1].page_link = 0x02;
131} 161}
132 162
133static inline void __sg_mark_end(struct scatterlist *sg) 163static inline void __sg_mark_end(struct scatterlist *sg)
134{ 164{
165 sg->page_link |= 0x02;
135} 166}
136 167
137
138/** 168/**
139 * sg_init_one - Initialize a single entry sg list 169 * sg_init_one - Initialize a single entry sg list
140 * @sg: SG entry 170 * @sg: SG entry
@@ -187,7 +217,7 @@ static inline unsigned long sg_phys(struct scatterlist *sg)
187 217
188/** 218/**
189 * sg_virt - Return virtual address of an sg entry 219 * sg_virt - Return virtual address of an sg entry
190 * @sg: SG entry 220 * @sg: SG entry
191 * 221 *
192 * Description: 222 * Description:
193 * This calls page_address() on the page in this sg entry, and adds the 223 * This calls page_address() on the page in this sg entry, and adds the