Rev 5270 | Rev 6282 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5270 | Rev 6082 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef _LINUX_SCATTERLIST_H |
1 | #ifndef _LINUX_SCATTERLIST_H |
2 | #define _LINUX_SCATTERLIST_H |
2 | #define _LINUX_SCATTERLIST_H |
Line 3... | Line 3... | ||
3 | 3 | ||
- | 4 | #include |
|
4 | #include |
5 | #include |
5 | #include |
6 | #include |
Line 6... | Line 7... | ||
6 | #include |
7 | #include |
- | 8 | ||
- | 9 | struct scatterlist { |
|
- | 10 | #ifdef CONFIG_DEBUG_SG |
|
7 | 11 | unsigned long sg_magic; |
|
- | 12 | #endif |
|
8 | #include |
13 | unsigned long page_link; |
- | 14 | unsigned int offset; |
|
- | 15 | unsigned int length; |
|
- | 16 | dma_addr_t dma_address; |
|
- | 17 | #ifdef CONFIG_NEED_SG_DMA_LENGTH |
|
- | 18 | unsigned int dma_length; |
|
- | 19 | #endif |
|
- | 20 | }; |
|
- | 21 | ||
- | 22 | /* |
|
- | 23 | * These macros should be used after a dma_map_sg call has been done |
|
- | 24 | * to get bus addresses of each of the SG entries and their lengths. |
|
- | 25 | * You should only work with the number of sg entries dma_map_sg |
|
- | 26 | * returns, or alternatively stop on the first sg_dma_len(sg) which |
|
- | 27 | * is 0. |
|
- | 28 | */ |
|
- | 29 | #define sg_dma_address(sg) ((sg)->dma_address) |
|
- | 30 | ||
- | 31 | #ifdef CONFIG_NEED_SG_DMA_LENGTH |
|
- | 32 | #define sg_dma_len(sg) ((sg)->dma_length) |
|
- | 33 | #else |
|
Line 9... | Line 34... | ||
9 | #include |
34 | #define sg_dma_len(sg) ((sg)->length) |
10 | //#include |
35 | #endif |
11 | 36 | ||
12 | struct sg_table { |
37 | struct sg_table { |
13 | struct scatterlist *sgl; /* the list */ |
38 | struct scatterlist *sgl; /* the list */ |
Line 14... | Line 39... | ||
14 | unsigned int nents; /* number of mapped entries */ |
39 | unsigned int nents; /* number of mapped entries */ |
15 | unsigned int orig_nents; /* original size of list */ |
40 | unsigned int orig_nents; /* original size of list */ |
16 | }; |
41 | }; |
17 | 42 | ||
18 | /* |
- | |
19 | * Notes on SG table design. |
43 | /* |
20 | * |
44 | * Notes on SG table design. |
21 | * Architectures must provide an unsigned long page_link field in the |
45 | * |
22 | * scatterlist struct. We use that to place the page pointer AND encode |
46 | * We use the unsigned long page_link field in the scatterlist struct to place |
23 | * information about the sg table as well. The two lower bits are reserved |
47 | * the page pointer AND encode information about the sg table as well. The two |
24 | * for this information. |
48 | * lower bits are reserved for this information. |
25 | * |
49 | * |
Line 106... | Line 130... | ||
106 | * @sg: SG entry |
130 | * @sg: SG entry |
107 | * @buf: Data |
131 | * @buf: Data |
108 | * @buflen: Data length |
132 | * @buflen: Data length |
109 | * |
133 | * |
110 | **/ |
134 | **/ |
111 | //static inline void sg_set_buf(struct scatterlist *sg, const void *buf, |
135 | static inline void sg_set_buf(struct scatterlist *sg, const void *buf, |
112 | // unsigned int buflen) |
136 | unsigned int buflen) |
113 | //{ |
137 | { |
114 | //#ifdef CONFIG_DEBUG_SG |
138 | #ifdef CONFIG_DEBUG_SG |
115 | // BUG_ON(!virt_addr_valid(buf)); |
139 | BUG_ON(!virt_addr_valid(buf)); |
116 | //#endif |
140 | #endif |
117 | // sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); |
141 | sg_set_page(sg, (struct page*)((unsigned)buf&0xFFFFF000), buflen, offset_in_page(buf)); |
118 | //} |
142 | } |
Line 119... | Line 143... | ||
119 | 143 | ||
120 | /* |
144 | /* |
121 | * Loop over each sg element, following the pointer to a new list if necessary |
145 | * Loop over each sg element, following the pointer to a new list if necessary |
122 | */ |
146 | */ |
Line 134... | Line 158... | ||
134 | * |
158 | * |
135 | **/ |
159 | **/ |
136 | static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, |
160 | static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, |
137 | struct scatterlist *sgl) |
161 | struct scatterlist *sgl) |
138 | { |
162 | { |
139 | #ifndef CONFIG_ARCH_HAS_SG_CHAIN |
- | |
140 | BUG(); |
- | |
141 | #endif |
- | |
142 | - | ||
143 | /* |
163 | /* |
144 | * offset and length are unused for chain entry. Clear them. |
164 | * offset and length are unused for chain entry. Clear them. |
145 | */ |
165 | */ |
146 | prv[prv_nents - 1].offset = 0; |
166 | prv[prv_nents - 1].offset = 0; |
147 | prv[prv_nents - 1].length = 0; |
167 | prv[prv_nents - 1].length = 0; |
Line 219... | Line 239... | ||
219 | //{ |
239 | //{ |
220 | // return page_address(sg_page(sg)) + sg->offset; |
240 | // return page_address(sg_page(sg)) + sg->offset; |
221 | //} |
241 | //} |
Line 222... | Line 242... | ||
222 | 242 | ||
- | 243 | int sg_nents(struct scatterlist *sg); |
|
223 | int sg_nents(struct scatterlist *sg); |
244 | int sg_nents_for_len(struct scatterlist *sg, u64 len); |
224 | struct scatterlist *sg_next(struct scatterlist *); |
245 | struct scatterlist *sg_next(struct scatterlist *); |
225 | struct scatterlist *sg_last(struct scatterlist *s, unsigned int); |
246 | struct scatterlist *sg_last(struct scatterlist *s, unsigned int); |
226 | void sg_init_table(struct scatterlist *, unsigned int); |
247 | void sg_init_table(struct scatterlist *, unsigned int); |
- | 248 | void sg_init_one(struct scatterlist *, const void *, unsigned int); |
|
- | 249 | int sg_split(struct scatterlist *in, const int in_mapped_nents, |
|
- | 250 | const off_t skip, const int nb_splits, |
|
- | 251 | const size_t *split_sizes, |
|
- | 252 | struct scatterlist **out, int *out_mapped_nents, |
|
Line 227... | Line 253... | ||
227 | void sg_init_one(struct scatterlist *, const void *, unsigned int); |
253 | gfp_t gfp_mask); |
228 | 254 | ||
Line 229... | Line 255... | ||
229 | typedef struct scatterlist *(sg_alloc_fn)(unsigned int, gfp_t); |
255 | typedef struct scatterlist *(sg_alloc_fn)(unsigned int, gfp_t); |
Line 237... | Line 263... | ||
237 | int sg_alloc_table_from_pages(struct sg_table *sgt, |
263 | int sg_alloc_table_from_pages(struct sg_table *sgt, |
238 | struct page **pages, unsigned int n_pages, |
264 | struct page **pages, unsigned int n_pages, |
239 | unsigned long offset, unsigned long size, |
265 | unsigned long offset, unsigned long size, |
240 | gfp_t gfp_mask); |
266 | gfp_t gfp_mask); |
Line -... | Line 267... | ||
- | 267 | ||
- | 268 | size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf, |
|
- | 269 | size_t buflen, off_t skip, bool to_buffer); |
|
241 | 270 | ||
242 | size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents, |
271 | size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents, |
243 | void *buf, size_t buflen); |
272 | const void *buf, size_t buflen); |
244 | size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, |
273 | size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, |
Line 245... | Line 274... | ||
245 | void *buf, size_t buflen); |
274 | void *buf, size_t buflen); |
246 | 275 | ||
247 | size_t sg_pcopy_from_buffer(struct scatterlist *sgl, unsigned int nents, |
276 | size_t sg_pcopy_from_buffer(struct scatterlist *sgl, unsigned int nents, |
248 | void *buf, size_t buflen, off_t skip); |
277 | const void *buf, size_t buflen, off_t skip); |
Line 249... | Line 278... | ||
249 | size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents, |
278 | size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents, |
250 | void *buf, size_t buflen, off_t skip); |
279 | void *buf, size_t buflen, off_t skip); |
Line 347... | Line 376... | ||
347 | unsigned int nents, unsigned int flags); |
376 | unsigned int nents, unsigned int flags); |
348 | bool sg_miter_skip(struct sg_mapping_iter *miter, off_t offset); |
377 | bool sg_miter_skip(struct sg_mapping_iter *miter, off_t offset); |
349 | bool sg_miter_next(struct sg_mapping_iter *miter); |
378 | bool sg_miter_next(struct sg_mapping_iter *miter); |
350 | void sg_miter_stop(struct sg_mapping_iter *miter); |
379 | void sg_miter_stop(struct sg_mapping_iter *miter); |
Line -... | Line 380... | ||
- | 380 | ||
- | 381 | #define dma_unmap_sg(d, s, n, r) |
|
351 | 382 |