struct scatterlist 使用

来源:互联网 发布:淘宝云客服工资怎么算 编辑:程序博客网 时间:2024/06/18 17:05

转自:http://blog.csdn.net/ganggexiongqi/article/details/7038335

1、结构解析

struct scatterlist {
     ...
     /* User input members */
    unsigned long   page_link;// pointer to a page, but the bit0 and bit1 have special info.[1]
    unsigned int    offset; // Offset of data buffer in page referred by @page_link
    unsigned int    length; //Length of data
    /* Output value */
    dma_addr_t  dma_address; // this address can be used by device to do DMA 
     ...
};

2、使用

static inline void sg_set_page(struct scatterlist *sg, struct page *page,
                   unsigned int len, unsigned int offset)
{
    sg_assign_page(sg, page);
    sg->offset = offset;
    sg->length = len;
}

static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
{
    unsigned long page_link = sg->page_link & 0x3;

    /*
     * In order for the low bit stealing approach to work, pages
     * must be aligned at a 32-bit boundary as a minimum.
     */
    BUG_ON((unsigned long) page & 0x03);
     ...
    sg->page_link = page_link | (unsigned long) page;
}





原创粉丝点击