blob: bed5ab4d756afa3728ee093766e6186287583368 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SCATTERLIST_H
2#define _LINUX_SCATTERLIST_H
3
Herbert Xud32311f2005-09-17 14:41:40 +10004#include <asm/scatterlist.h>
5#include <linux/mm.h>
6#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Herbert Xu03fd9ce2006-08-14 23:11:53 +10008static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
Herbert Xud32311f2005-09-17 14:41:40 +10009 unsigned int buflen)
10{
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 sg->page = virt_to_page(buf);
12 sg->offset = offset_in_page(buf);
13 sg->length = buflen;
14}
15
Herbert Xu03fd9ce2006-08-14 23:11:53 +100016static inline void sg_init_one(struct scatterlist *sg, const void *buf,
Herbert Xud32311f2005-09-17 14:41:40 +100017 unsigned int buflen)
18{
19 memset(sg, 0, sizeof(*sg));
20 sg_set_buf(sg, buf, buflen);
21}
22
Jens Axboe96b418c2007-05-09 09:02:57 +020023#define sg_next(sg) ((sg) + 1)
24#define sg_last(sg, nents) (&(sg[(nents) - 1]))
25
26/*
27 * Loop over each sg element, following the pointer to a new list if necessary
28 */
29#define for_each_sg(sglist, sg, nr, __i) \
30 for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#endif /* _LINUX_SCATTERLIST_H */