Subversion Repositories Kolibri OS

Rev

Rev 5270 | Rev 6282 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5270 Rev 6082
1
#ifndef _LINUX_SCATTERLIST_H
1
#ifndef _LINUX_SCATTERLIST_H
2
#define _LINUX_SCATTERLIST_H
2
#define _LINUX_SCATTERLIST_H
3
 
3
 
4
#include 
4
#include 
-
 
5
#include 
5
#include 
6
#include 
6
#include 
7
#include 
7
 
8
 
-
 
9
struct scatterlist {
-
 
10
#ifdef CONFIG_DEBUG_SG
-
 
11
	unsigned long	sg_magic;
8
#include 
12
#endif
-
 
13
	unsigned long	page_link;
9
#include 
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
-
 
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 */
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
/*
43
/*
19
 * Notes on SG table design.
44
 * Notes on SG table design.
20
 *
45
 *
21
 * Architectures must provide an unsigned long page_link field in the
46
 * We use the unsigned long page_link field in the scatterlist struct to place
22
 * scatterlist struct. We use that to place the page pointer AND encode
-
 
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
 *
26
 * If bit 0 is set, then the page_link contains a pointer to the next sg
50
 * If bit 0 is set, then the page_link contains a pointer to the next sg
27
 * table list. Otherwise the next entry is at sg + 1.
51
 * table list. Otherwise the next entry is at sg + 1.
28
 *
52
 *
29
 * If bit 1 is set, then this sg entry is the last element in a list.
53
 * If bit 1 is set, then this sg entry is the last element in a list.
30
 *
54
 *
31
 * See sg_next().
55
 * See sg_next().
32
 *
56
 *
33
 */
57
 */
34
 
58
 
35
#define SG_MAGIC	0x87654321
59
#define SG_MAGIC	0x87654321
36
 
60
 
37
/*
61
/*
38
 * We overload the LSB of the page pointer to indicate whether it's
62
 * We overload the LSB of the page pointer to indicate whether it's
39
 * a valid sg entry, or whether it points to the start of a new scatterlist.
63
 * a valid sg entry, or whether it points to the start of a new scatterlist.
40
 * Those low bits are there for everyone! (thanks mason :-)
64
 * Those low bits are there for everyone! (thanks mason :-)
41
 */
65
 */
42
#define sg_is_chain(sg)		((sg)->page_link & 0x01)
66
#define sg_is_chain(sg)		((sg)->page_link & 0x01)
43
#define sg_is_last(sg)		((sg)->page_link & 0x02)
67
#define sg_is_last(sg)		((sg)->page_link & 0x02)
44
#define sg_chain_ptr(sg)	\
68
#define sg_chain_ptr(sg)	\
45
	((struct scatterlist *) ((sg)->page_link & ~0x03))
69
	((struct scatterlist *) ((sg)->page_link & ~0x03))
46
 
70
 
47
/**
71
/**
48
 * sg_assign_page - Assign a given page to an SG entry
72
 * sg_assign_page - Assign a given page to an SG entry
49
 * @sg:		    SG entry
73
 * @sg:		    SG entry
50
 * @page:	    The page
74
 * @page:	    The page
51
 *
75
 *
52
 * Description:
76
 * Description:
53
 *   Assign page to sg entry. Also see sg_set_page(), the most commonly used
77
 *   Assign page to sg entry. Also see sg_set_page(), the most commonly used
54
 *   variant.
78
 *   variant.
55
 *
79
 *
56
 **/
80
 **/
57
static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
81
static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
58
{
82
{
59
	unsigned long page_link = sg->page_link & 0x3;
83
	unsigned long page_link = sg->page_link & 0x3;
60
 
84
 
61
	/*
85
	/*
62
	 * In order for the low bit stealing approach to work, pages
86
	 * In order for the low bit stealing approach to work, pages
63
	 * must be aligned at a 32-bit boundary as a minimum.
87
	 * must be aligned at a 32-bit boundary as a minimum.
64
	 */
88
	 */
65
	BUG_ON((unsigned long) page & 0x03);
89
	BUG_ON((unsigned long) page & 0x03);
66
#ifdef CONFIG_DEBUG_SG
90
#ifdef CONFIG_DEBUG_SG
67
	BUG_ON(sg->sg_magic != SG_MAGIC);
91
	BUG_ON(sg->sg_magic != SG_MAGIC);
68
	BUG_ON(sg_is_chain(sg));
92
	BUG_ON(sg_is_chain(sg));
69
#endif
93
#endif
70
	sg->page_link = page_link | (unsigned long) page;
94
	sg->page_link = page_link | (unsigned long) page;
71
}
95
}
72
 
96
 
73
/**
97
/**
74
 * sg_set_page - Set sg entry to point at given page
98
 * sg_set_page - Set sg entry to point at given page
75
 * @sg:		 SG entry
99
 * @sg:		 SG entry
76
 * @page:	 The page
100
 * @page:	 The page
77
 * @len:	 Length of data
101
 * @len:	 Length of data
78
 * @offset:	 Offset into page
102
 * @offset:	 Offset into page
79
 *
103
 *
80
 * Description:
104
 * Description:
81
 *   Use this function to set an sg entry pointing at a page, never assign
105
 *   Use this function to set an sg entry pointing at a page, never assign
82
 *   the page directly. We encode sg table information in the lower bits
106
 *   the page directly. We encode sg table information in the lower bits
83
 *   of the page pointer. See sg_page() for looking up the page belonging
107
 *   of the page pointer. See sg_page() for looking up the page belonging
84
 *   to an sg entry.
108
 *   to an sg entry.
85
 *
109
 *
86
 **/
110
 **/
87
static inline void sg_set_page(struct scatterlist *sg, struct page *page,
111
static inline void sg_set_page(struct scatterlist *sg, struct page *page,
88
			       unsigned int len, unsigned int offset)
112
			       unsigned int len, unsigned int offset)
89
{
113
{
90
	sg_assign_page(sg, page);
114
	sg_assign_page(sg, page);
91
	sg->offset = offset;
115
	sg->offset = offset;
92
	sg->length = len;
116
	sg->length = len;
93
}
117
}
94
 
118
 
95
static inline struct page *sg_page(struct scatterlist *sg)
119
static inline struct page *sg_page(struct scatterlist *sg)
96
{
120
{
97
#ifdef CONFIG_DEBUG_SG
121
#ifdef CONFIG_DEBUG_SG
98
	BUG_ON(sg->sg_magic != SG_MAGIC);
122
	BUG_ON(sg->sg_magic != SG_MAGIC);
99
	BUG_ON(sg_is_chain(sg));
123
	BUG_ON(sg_is_chain(sg));
100
#endif
124
#endif
101
	return (struct page *)((sg)->page_link & ~0x3);
125
	return (struct page *)((sg)->page_link & ~0x3);
102
}
126
}
103
 
127
 
104
/**
128
/**
105
 * sg_set_buf - Set sg entry to point at given data
129
 * sg_set_buf - Set sg entry to point at given data
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
}
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
 */
123
#define for_each_sg(sglist, sg, nr, __i)	\
147
#define for_each_sg(sglist, sg, nr, __i)	\
124
	for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
148
	for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
125
 
149
 
126
/**
150
/**
127
 * sg_chain - Chain two sglists together
151
 * sg_chain - Chain two sglists together
128
 * @prv:	First scatterlist
152
 * @prv:	First scatterlist
129
 * @prv_nents:	Number of entries in prv
153
 * @prv_nents:	Number of entries in prv
130
 * @sgl:	Second scatterlist
154
 * @sgl:	Second scatterlist
131
 *
155
 *
132
 * Description:
156
 * Description:
133
 *   Links @prv@ and @sgl@ together, to form a longer scatterlist.
157
 *   Links @prv@ and @sgl@ together, to form a longer scatterlist.
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;
148
 
168
 
149
	/*
169
	/*
150
	 * Set lowest bit to indicate a link pointer, and make sure to clear
170
	 * Set lowest bit to indicate a link pointer, and make sure to clear
151
	 * the termination bit if it happens to be set.
171
	 * the termination bit if it happens to be set.
152
	 */
172
	 */
153
	prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02;
173
	prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02;
154
}
174
}
155
 
175
 
156
/**
176
/**
157
 * sg_mark_end - Mark the end of the scatterlist
177
 * sg_mark_end - Mark the end of the scatterlist
158
 * @sg:		 SG entryScatterlist
178
 * @sg:		 SG entryScatterlist
159
 *
179
 *
160
 * Description:
180
 * Description:
161
 *   Marks the passed in sg entry as the termination point for the sg
181
 *   Marks the passed in sg entry as the termination point for the sg
162
 *   table. A call to sg_next() on this entry will return NULL.
182
 *   table. A call to sg_next() on this entry will return NULL.
163
 *
183
 *
164
 **/
184
 **/
165
static inline void sg_mark_end(struct scatterlist *sg)
185
static inline void sg_mark_end(struct scatterlist *sg)
166
{
186
{
167
#ifdef CONFIG_DEBUG_SG
187
#ifdef CONFIG_DEBUG_SG
168
	BUG_ON(sg->sg_magic != SG_MAGIC);
188
	BUG_ON(sg->sg_magic != SG_MAGIC);
169
#endif
189
#endif
170
	/*
190
	/*
171
	 * Set termination bit, clear potential chain bit
191
	 * Set termination bit, clear potential chain bit
172
	 */
192
	 */
173
	sg->page_link |= 0x02;
193
	sg->page_link |= 0x02;
174
	sg->page_link &= ~0x01;
194
	sg->page_link &= ~0x01;
175
}
195
}
176
 
196
 
177
/**
197
/**
178
 * sg_unmark_end - Undo setting the end of the scatterlist
198
 * sg_unmark_end - Undo setting the end of the scatterlist
179
 * @sg:		 SG entryScatterlist
199
 * @sg:		 SG entryScatterlist
180
 *
200
 *
181
 * Description:
201
 * Description:
182
 *   Removes the termination marker from the given entry of the scatterlist.
202
 *   Removes the termination marker from the given entry of the scatterlist.
183
 *
203
 *
184
 **/
204
 **/
185
static inline void sg_unmark_end(struct scatterlist *sg)
205
static inline void sg_unmark_end(struct scatterlist *sg)
186
{
206
{
187
#ifdef CONFIG_DEBUG_SG
207
#ifdef CONFIG_DEBUG_SG
188
	BUG_ON(sg->sg_magic != SG_MAGIC);
208
	BUG_ON(sg->sg_magic != SG_MAGIC);
189
#endif
209
#endif
190
	sg->page_link &= ~0x02;
210
	sg->page_link &= ~0x02;
191
}
211
}
192
 
212
 
193
/**
213
/**
194
 * sg_phys - Return physical address of an sg entry
214
 * sg_phys - Return physical address of an sg entry
195
 * @sg:	     SG entry
215
 * @sg:	     SG entry
196
 *
216
 *
197
 * Description:
217
 * Description:
198
 *   This calls page_to_phys() on the page in this sg entry, and adds the
218
 *   This calls page_to_phys() on the page in this sg entry, and adds the
199
 *   sg offset. The caller must know that it is legal to call page_to_phys()
219
 *   sg offset. The caller must know that it is legal to call page_to_phys()
200
 *   on the sg page.
220
 *   on the sg page.
201
 *
221
 *
202
 **/
222
 **/
203
static inline dma_addr_t sg_phys(struct scatterlist *sg)
223
static inline dma_addr_t sg_phys(struct scatterlist *sg)
204
{
224
{
205
	return page_to_phys(sg_page(sg)) + sg->offset;
225
	return page_to_phys(sg_page(sg)) + sg->offset;
206
}
226
}
207
 
227
 
208
/**
228
/**
209
 * sg_virt - Return virtual address of an sg entry
229
 * sg_virt - Return virtual address of an sg entry
210
 * @sg:      SG entry
230
 * @sg:      SG entry
211
 *
231
 *
212
 * Description:
232
 * Description:
213
 *   This calls page_address() on the page in this sg entry, and adds the
233
 *   This calls page_address() on the page in this sg entry, and adds the
214
 *   sg offset. The caller must know that the sg page has a valid virtual
234
 *   sg offset. The caller must know that the sg page has a valid virtual
215
 *   mapping.
235
 *   mapping.
216
 *
236
 *
217
 **/
237
 **/
218
//static inline void *sg_virt(struct scatterlist *sg)
238
//static inline void *sg_virt(struct scatterlist *sg)
219
//{
239
//{
220
//   return page_address(sg_page(sg)) + sg->offset;
240
//   return page_address(sg_page(sg)) + sg->offset;
221
//}
241
//}
222
 
242
 
223
int sg_nents(struct scatterlist *sg);
243
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);
227
void sg_init_one(struct scatterlist *, const void *, 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,
-
 
253
	     gfp_t gfp_mask);
228
 
254
 
229
typedef struct scatterlist *(sg_alloc_fn)(unsigned int, gfp_t);
255
typedef struct scatterlist *(sg_alloc_fn)(unsigned int, gfp_t);
230
typedef void (sg_free_fn)(struct scatterlist *, unsigned int);
256
typedef void (sg_free_fn)(struct scatterlist *, unsigned int);
231
 
257
 
232
void __sg_free_table(struct sg_table *, unsigned int, bool, sg_free_fn *);
258
void __sg_free_table(struct sg_table *, unsigned int, bool, sg_free_fn *);
233
void sg_free_table(struct sg_table *);
259
void sg_free_table(struct sg_table *);
234
int __sg_alloc_table(struct sg_table *, unsigned int, unsigned int,
260
int __sg_alloc_table(struct sg_table *, unsigned int, unsigned int,
235
		     struct scatterlist *, gfp_t, sg_alloc_fn *);
261
		     struct scatterlist *, gfp_t, sg_alloc_fn *);
236
int sg_alloc_table(struct sg_table *, unsigned int, gfp_t);
262
int sg_alloc_table(struct sg_table *, unsigned int, gfp_t);
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);
-
 
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,
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);
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);
251
 
280
 
252
/*
281
/*
253
 * Maximum number of entries that will be allocated in one piece, if
282
 * Maximum number of entries that will be allocated in one piece, if
254
 * a list larger than this is required then chaining will be utilized.
283
 * a list larger than this is required then chaining will be utilized.
255
 */
284
 */
256
#define SG_MAX_SINGLE_ALLOC     (4*PAGE_SIZE / sizeof(struct scatterlist))
285
#define SG_MAX_SINGLE_ALLOC     (4*PAGE_SIZE / sizeof(struct scatterlist))
257
 
286
 
258
/*
287
/*
259
 * sg page iterator
288
 * sg page iterator
260
 *
289
 *
261
 * Iterates over sg entries page-by-page.  On each successful iteration,
290
 * Iterates over sg entries page-by-page.  On each successful iteration,
262
 * you can call sg_page_iter_page(@piter) and sg_page_iter_dma_address(@piter)
291
 * you can call sg_page_iter_page(@piter) and sg_page_iter_dma_address(@piter)
263
 * to get the current page and its dma address. @piter->sg will point to the
292
 * to get the current page and its dma address. @piter->sg will point to the
264
 * sg holding this page and @piter->sg_pgoffset to the page's page offset
293
 * sg holding this page and @piter->sg_pgoffset to the page's page offset
265
 * within the sg. The iteration will stop either when a maximum number of sg
294
 * within the sg. The iteration will stop either when a maximum number of sg
266
 * entries was reached or a terminating sg (sg_last(sg) == true) was reached.
295
 * entries was reached or a terminating sg (sg_last(sg) == true) was reached.
267
 */
296
 */
268
struct sg_page_iter {
297
struct sg_page_iter {
269
	struct scatterlist	*sg;		/* sg holding the page */
298
	struct scatterlist	*sg;		/* sg holding the page */
270
	unsigned int		sg_pgoffset;	/* page offset within the sg */
299
	unsigned int		sg_pgoffset;	/* page offset within the sg */
271
 
300
 
272
	/* these are internal states, keep away */
301
	/* these are internal states, keep away */
273
	unsigned int		__nents;	/* remaining sg entries */
302
	unsigned int		__nents;	/* remaining sg entries */
274
	int			__pg_advance;	/* nr pages to advance at the
303
	int			__pg_advance;	/* nr pages to advance at the
275
						 * next step */
304
						 * next step */
276
};
305
};
277
 
306
 
278
bool __sg_page_iter_next(struct sg_page_iter *piter);
307
bool __sg_page_iter_next(struct sg_page_iter *piter);
279
void __sg_page_iter_start(struct sg_page_iter *piter,
308
void __sg_page_iter_start(struct sg_page_iter *piter,
280
			  struct scatterlist *sglist, unsigned int nents,
309
			  struct scatterlist *sglist, unsigned int nents,
281
			  unsigned long pgoffset);
310
			  unsigned long pgoffset);
282
/**
311
/**
283
 * sg_page_iter_page - get the current page held by the page iterator
312
 * sg_page_iter_page - get the current page held by the page iterator
284
 * @piter:	page iterator holding the page
313
 * @piter:	page iterator holding the page
285
 */
314
 */
286
static inline struct page *sg_page_iter_page(struct sg_page_iter *piter)
315
static inline struct page *sg_page_iter_page(struct sg_page_iter *piter)
287
{
316
{
288
	return nth_page(sg_page(piter->sg), piter->sg_pgoffset);
317
	return nth_page(sg_page(piter->sg), piter->sg_pgoffset);
289
}
318
}
290
 
319
 
291
/**
320
/**
292
 * sg_page_iter_dma_address - get the dma address of the current page held by
321
 * sg_page_iter_dma_address - get the dma address of the current page held by
293
 * the page iterator.
322
 * the page iterator.
294
 * @piter:	page iterator holding the page
323
 * @piter:	page iterator holding the page
295
 */
324
 */
296
static inline dma_addr_t sg_page_iter_dma_address(struct sg_page_iter *piter)
325
static inline dma_addr_t sg_page_iter_dma_address(struct sg_page_iter *piter)
297
{
326
{
298
	return sg_dma_address(piter->sg) + (piter->sg_pgoffset << PAGE_SHIFT);
327
	return sg_dma_address(piter->sg) + (piter->sg_pgoffset << PAGE_SHIFT);
299
}
328
}
300
 
329
 
301
/**
330
/**
302
 * for_each_sg_page - iterate over the pages of the given sg list
331
 * for_each_sg_page - iterate over the pages of the given sg list
303
 * @sglist:	sglist to iterate over
332
 * @sglist:	sglist to iterate over
304
 * @piter:	page iterator to hold current page, sg, sg_pgoffset
333
 * @piter:	page iterator to hold current page, sg, sg_pgoffset
305
 * @nents:	maximum number of sg entries to iterate over
334
 * @nents:	maximum number of sg entries to iterate over
306
 * @pgoffset:	starting page offset
335
 * @pgoffset:	starting page offset
307
 */
336
 */
308
#define for_each_sg_page(sglist, piter, nents, pgoffset)		   \
337
#define for_each_sg_page(sglist, piter, nents, pgoffset)		   \
309
	for (__sg_page_iter_start((piter), (sglist), (nents), (pgoffset)); \
338
	for (__sg_page_iter_start((piter), (sglist), (nents), (pgoffset)); \
310
	     __sg_page_iter_next(piter);)
339
	     __sg_page_iter_next(piter);)
311
 
340
 
312
/*
341
/*
313
 * Mapping sg iterator
342
 * Mapping sg iterator
314
 *
343
 *
315
 * Iterates over sg entries mapping page-by-page.  On each successful
344
 * Iterates over sg entries mapping page-by-page.  On each successful
316
 * iteration, @miter->page points to the mapped page and
345
 * iteration, @miter->page points to the mapped page and
317
 * @miter->length bytes of data can be accessed at @miter->addr.  As
346
 * @miter->length bytes of data can be accessed at @miter->addr.  As
318
 * long as an interation is enclosed between start and stop, the user
347
 * long as an interation is enclosed between start and stop, the user
319
 * is free to choose control structure and when to stop.
348
 * is free to choose control structure and when to stop.
320
 *
349
 *
321
 * @miter->consumed is set to @miter->length on each iteration.  It
350
 * @miter->consumed is set to @miter->length on each iteration.  It
322
 * can be adjusted if the user can't consume all the bytes in one go.
351
 * can be adjusted if the user can't consume all the bytes in one go.
323
 * Also, a stopped iteration can be resumed by calling next on it.
352
 * Also, a stopped iteration can be resumed by calling next on it.
324
 * This is useful when iteration needs to release all resources and
353
 * This is useful when iteration needs to release all resources and
325
 * continue later (e.g. at the next interrupt).
354
 * continue later (e.g. at the next interrupt).
326
 */
355
 */
327
 
356
 
328
#define SG_MITER_ATOMIC		(1 << 0)	 /* use kmap_atomic */
357
#define SG_MITER_ATOMIC		(1 << 0)	 /* use kmap_atomic */
329
#define SG_MITER_TO_SG		(1 << 1)	/* flush back to phys on unmap */
358
#define SG_MITER_TO_SG		(1 << 1)	/* flush back to phys on unmap */
330
#define SG_MITER_FROM_SG	(1 << 2)	/* nop */
359
#define SG_MITER_FROM_SG	(1 << 2)	/* nop */
331
 
360
 
332
struct sg_mapping_iter {
361
struct sg_mapping_iter {
333
	/* the following three fields can be accessed directly */
362
	/* the following three fields can be accessed directly */
334
	struct page		*page;		/* currently mapped page */
363
	struct page		*page;		/* currently mapped page */
335
	void			*addr;		/* pointer to the mapped area */
364
	void			*addr;		/* pointer to the mapped area */
336
	size_t			length;		/* length of the mapped area */
365
	size_t			length;		/* length of the mapped area */
337
	size_t			consumed;	/* number of consumed bytes */
366
	size_t			consumed;	/* number of consumed bytes */
338
	struct sg_page_iter	piter;		/* page iterator */
367
	struct sg_page_iter	piter;		/* page iterator */
339
 
368
 
340
	/* these are internal states, keep away */
369
	/* these are internal states, keep away */
341
	unsigned int		__offset;	/* offset within page */
370
	unsigned int		__offset;	/* offset within page */
342
	unsigned int		__remaining;	/* remaining bytes on page */
371
	unsigned int		__remaining;	/* remaining bytes on page */
343
	unsigned int		__flags;
372
	unsigned int		__flags;
344
};
373
};
345
 
374
 
346
void sg_miter_start(struct sg_mapping_iter *miter, struct scatterlist *sgl,
375
void sg_miter_start(struct sg_mapping_iter *miter, struct scatterlist *sgl,
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);
-
 
380
 
-
 
381
#define dma_unmap_sg(d, s, n, r)
351
 
382
 
352
#endif /* _LINUX_SCATTERLIST_H */
383
#endif /* _LINUX_SCATTERLIST_H */