int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
u32 reserved)
{ /* num must be a power of 2 */ if (num != 1 << (ffs(num) - 1)) return -EINVAL;
void *mthca_array_get(struct mthca_array *array, int index)
{ int p = (index * sizeof (void *)) >> PAGE_SHIFT;
if (array->page_list[p].page) return array->page_list[p].page[index & MTHCA_ARRAY_MASK]; else return NULL;
}
int mthca_array_set(struct mthca_array *array, int index, void *value)
{ int p = (index * sizeof (void *)) >> PAGE_SHIFT;
/* Allocate with GFP_ATOMIC because we'll be called with locks held. */ if (!array->page_list[p].page)
array->page_list[p].page = (void **) get_zeroed_page(GFP_ATOMIC);
int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct, union mthca_buf *buf, int *is_direct, struct mthca_pd *pd, int hca_write, struct mthca_mr *mr)
{ int err = -ENOMEM; int npages, shift;
u64 *dma_list = NULL;
dma_addr_t t; int i;
dma_list = kmalloc_array(npages, sizeof(*dma_list),
GFP_KERNEL); if (!dma_list) goto err_free;
for (i = 0; i < npages; ++i)
dma_list[i] = t + i * (1 << shift);
} else {
*is_direct = 0;
npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
shift = PAGE_SHIFT;
dma_list = kmalloc_array(npages, sizeof(*dma_list),
GFP_KERNEL); if (!dma_list) return -ENOMEM;
buf->page_list = kmalloc_array(npages, sizeof(*buf->page_list),
GFP_KERNEL); if (!buf->page_list) goto err_out;
for (i = 0; i < npages; ++i)
buf->page_list[i].buf = NULL;
for (i = 0; i < npages; ++i) {
buf->page_list[i].buf =
dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
&t, GFP_KERNEL); if (!buf->page_list[i].buf) goto err_free;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.