From aa86476edfdc2a44f5e5d74add7b93a0fbef9dc1 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Sat, 16 Apr 2005 15:26:29 -0700 Subject: [PATCH] --- yaml --- r: 183 b: refs/heads/master c: 0fabd9fb7bdc935f121e6950a2c4eff971dd4c75 h: refs/heads/master i: 181: 6457705c53f9d1a8ae39d6704ef46588007eefe2 179: 02b01cb63b0a94ff1de9d53c7d80d7e37ecd0215 175: 0740954d8eb0a2ff75edecae25efd5f1331a2ce9 v: v3 --- [refs] | 2 +- .../infiniband/hw/mthca/mthca_memfree.c | 34 +++++++++++++++++++ .../infiniband/hw/mthca/mthca_memfree.h | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 1eb6127e7b0d..1419ef637612 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b8ca06f674ab5d7853d7de892c09bdc4c1bfb069 +refs/heads/master: 0fabd9fb7bdc935f121e6950a2c4eff971dd4c75 diff --git a/trunk/drivers/infiniband/hw/mthca/mthca_memfree.c b/trunk/drivers/infiniband/hw/mthca/mthca_memfree.c index 46981d48c232..ea45de8c5b8e 100644 --- a/trunk/drivers/infiniband/hw/mthca/mthca_memfree.c +++ b/trunk/drivers/infiniband/hw/mthca/mthca_memfree.c @@ -192,6 +192,40 @@ void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int o up(&table->mutex); } +void *mthca_table_find(struct mthca_icm_table *table, int obj) +{ + int idx, offset, i; + struct mthca_icm_chunk *chunk; + struct mthca_icm *icm; + struct page *page = NULL; + + if (!table->lowmem) + return NULL; + + down(&table->mutex); + + idx = (obj & (table->num_obj - 1)) * table->obj_size; + icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE]; + offset = idx % MTHCA_TABLE_CHUNK_SIZE; + + if (!icm) + goto out; + + list_for_each_entry(chunk, &icm->chunk_list, list) { + for (i = 0; i < chunk->npages; ++i) { + if (chunk->mem[i].length >= offset) { + page = chunk->mem[i].page; + break; + } + offset -= chunk->mem[i].length; + } + } + +out: + up(&table->mutex); + return page ? lowmem_page_address(page) + offset : NULL; +} + int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table, int start, int end) { diff --git a/trunk/drivers/infiniband/hw/mthca/mthca_memfree.h b/trunk/drivers/infiniband/hw/mthca/mthca_memfree.h index ef72e430250a..fe7be2a6bc4a 100644 --- a/trunk/drivers/infiniband/hw/mthca/mthca_memfree.h +++ b/trunk/drivers/infiniband/hw/mthca/mthca_memfree.h @@ -85,6 +85,7 @@ struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev, void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table); int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int obj); void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj); +void *mthca_table_find(struct mthca_icm_table *table, int obj); int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table, int start, int end); void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table,