Lines Matching defs:table

222 int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)
224 int i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
227 mutex_lock(&table->mutex);
229 if (table->icm[i]) {
230 ++table->icm[i]->refcount;
234 table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT,
235 (table->lowmem ? GFP_KERNEL : GFP_HIGHUSER) |
236 __GFP_NOWARN, table->coherent);
237 if (!table->icm[i]) {
242 if (mthca_MAP_ICM(dev, table->icm[i],
243 table->virt + i * MTHCA_TABLE_CHUNK_SIZE)) {
244 mthca_free_icm(dev, table->icm[i], table->coherent);
245 table->icm[i] = NULL;
250 ++table->icm[i]->refcount;
253 mutex_unlock(&table->mutex);
257 void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)
264 i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
266 mutex_lock(&table->mutex);
268 if (--table->icm[i]->refcount == 0) {
269 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
271 mthca_free_icm(dev, table->icm[i], table->coherent);
272 table->icm[i] = NULL;
275 mutex_unlock(&table->mutex);
278 void *mthca_table_find(struct mthca_icm_table *table, int obj, dma_addr_t *dma_handle)
285 if (!table->lowmem)
288 mutex_lock(&table->mutex);
290 idx = (obj & (table->num_obj - 1)) * table->obj_size;
291 icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE];
317 mutex_unlock(&table->mutex);
321 int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table,
324 int inc = MTHCA_TABLE_CHUNK_SIZE / table->obj_size;
328 err = mthca_table_get(dev, table, i);
338 mthca_table_put(dev, table, i);
344 void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table,
352 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size)
353 mthca_table_put(dev, table, i);
361 struct mthca_icm_table *table;
370 table = kmalloc(sizeof *table + num_icm * sizeof *table->icm, GFP_KERNEL);
371 if (!table)
374 table->virt = virt;
375 table->num_icm = num_icm;
376 table->num_obj = nobj;
377 table->obj_size = obj_size;
378 table->lowmem = use_lowmem;
379 table->coherent = use_coherent;
380 mutex_init(&table->mutex);
383 table->icm[i] = NULL;
390 table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT,
393 if (!table->icm[i])
395 if (mthca_MAP_ICM(dev, table->icm[i],
397 mthca_free_icm(dev, table->icm[i], table->coherent);
398 table->icm[i] = NULL;
406 ++table->icm[i]->refcount;
409 return table;
413 if (table->icm[i]) {
416 mthca_free_icm(dev, table->icm[i], table->coherent);
419 kfree(table);
424 void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table)
428 for (i = 0; i < table->num_icm; ++i)
429 if (table->icm[i]) {
431 table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
433 mthca_free_icm(dev, table->icm[i], table->coherent);
436 kfree(table);
513 * pages until we clean up the whole db table.