diff options
-rw-r--r-- | include/linux/scatterlist.h | 112 |
1 files changed, 104 insertions, 8 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 2dc7464cce52..1645795cbb13 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h | |||
@@ -2,24 +2,37 @@ | |||
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> | ||
5 | #include <linux/mm.h> | 6 | #include <linux/mm.h> |
6 | #include <linux/string.h> | 7 | #include <linux/string.h> |
7 | 8 | ||
9 | /** | ||
10 | * sg_set_page - Set sg entry to point at given page | ||
11 | * @sg: SG entry | ||
12 | * @page: The page | ||
13 | * | ||
14 | * Description: | ||
15 | * Use this function to set an sg entry pointing at a page, never assign | ||
16 | * the page directly. We encode sg table information in the lower bits | ||
17 | * of the page pointer. See sg_page() for looking up the page belonging | ||
18 | * to an sg entry. | ||
19 | * | ||
20 | **/ | ||
21 | static inline void sg_set_page(struct scatterlist *sg, struct page *page) | ||
22 | { | ||
23 | sg->page = page; | ||
24 | } | ||
25 | |||
26 | #define sg_page(sg) ((sg)->page) | ||
27 | |||
8 | static inline void sg_set_buf(struct scatterlist *sg, const void *buf, | 28 | static inline void sg_set_buf(struct scatterlist *sg, const void *buf, |
9 | unsigned int buflen) | 29 | unsigned int buflen) |
10 | { | 30 | { |
11 | sg->page = virt_to_page(buf); | 31 | sg_set_page(sg, virt_to_page(buf)); |
12 | sg->offset = offset_in_page(buf); | 32 | sg->offset = offset_in_page(buf); |
13 | sg->length = buflen; | 33 | sg->length = buflen; |
14 | } | 34 | } |
15 | 35 | ||
16 | static inline void sg_init_one(struct scatterlist *sg, const void *buf, | ||
17 | unsigned int buflen) | ||
18 | { | ||
19 | memset(sg, 0, sizeof(*sg)); | ||
20 | sg_set_buf(sg, buf, buflen); | ||
21 | } | ||
22 | |||
23 | /* | 36 | /* |
24 | * We overload the LSB of the page pointer to indicate whether it's | 37 | * 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. | 38 | * a valid sg entry, or whether it points to the start of a new scatterlist. |
@@ -104,4 +117,87 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, | |||
104 | prv[prv_nents - 1].page = (struct page *) ((unsigned long) sgl | 0x01); | 117 | prv[prv_nents - 1].page = (struct page *) ((unsigned long) sgl | 0x01); |
105 | } | 118 | } |
106 | 119 | ||
120 | /** | ||
121 | * sg_mark_end - Mark the end of the scatterlist | ||
122 | * @sgl: Scatterlist | ||
123 | * @nents: Number of entries in sgl | ||
124 | * | ||
125 | * Description: | ||
126 | * Marks the last entry as the termination point for sg_next() | ||
127 | * | ||
128 | **/ | ||
129 | static inline void sg_mark_end(struct scatterlist *sgl, unsigned int nents) | ||
130 | { | ||
131 | } | ||
132 | |||
133 | static inline void __sg_mark_end(struct scatterlist *sg) | ||
134 | { | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * sg_init_one - Initialize a single entry sg list | ||
140 | * @sg: SG entry | ||
141 | * @buf: Virtual address for IO | ||
142 | * @buflen: IO length | ||
143 | * | ||
144 | * Notes: | ||
145 | * This should not be used on a single entry that is part of a larger | ||
146 | * table. Use sg_init_table() for that. | ||
147 | * | ||
148 | **/ | ||
149 | static inline void sg_init_one(struct scatterlist *sg, const void *buf, | ||
150 | unsigned int buflen) | ||
151 | { | ||
152 | memset(sg, 0, sizeof(*sg)); | ||
153 | sg_mark_end(sg, 1); | ||
154 | sg_set_buf(sg, buf, buflen); | ||
155 | } | ||
156 | |||
157 | /** | ||
158 | * sg_init_table - Initialize SG table | ||
159 | * @sgl: The SG table | ||
160 | * @nents: Number of entries in table | ||
161 | * | ||
162 | * Notes: | ||
163 | * If this is part of a chained sg table, sg_mark_end() should be | ||
164 | * used only on the last table part. | ||
165 | * | ||
166 | **/ | ||
167 | static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents) | ||
168 | { | ||
169 | memset(sgl, 0, sizeof(*sgl) * nents); | ||
170 | sg_mark_end(sgl, nents); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * sg_phys - Return physical address of an sg entry | ||
175 | * @sg: SG entry | ||
176 | * | ||
177 | * Description: | ||
178 | * This calls page_to_phys() on the page in this sg entry, and adds the | ||
179 | * sg offset. The caller must know that it is legal to call page_to_phys() | ||
180 | * on the sg page. | ||
181 | * | ||
182 | **/ | ||
183 | static inline unsigned long sg_phys(struct scatterlist *sg) | ||
184 | { | ||
185 | return page_to_phys(sg_page(sg)) + sg->offset; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * sg_virt - Return virtual address of an sg entry | ||
190 | * @sg: SG entry | ||
191 | * | ||
192 | * Description: | ||
193 | * This calls page_address() on the page in this sg entry, and adds the | ||
194 | * sg offset. The caller must know that the sg page has a valid virtual | ||
195 | * mapping. | ||
196 | * | ||
197 | **/ | ||
198 | static inline void *sg_virt(struct scatterlist *sg) | ||
199 | { | ||
200 | return page_address(sg_page(sg)) + sg->offset; | ||
201 | } | ||
202 | |||
107 | #endif /* _LINUX_SCATTERLIST_H */ | 203 | #endif /* _LINUX_SCATTERLIST_H */ |