Skip to content

Commit 8a7084d

Browse files
authored
Add host buffer & bug fix (#469)
* support add host buffer message * TDR should not move context out of partition as it doesn't know if update partition is required or not --------- Signed-off-by: Min Ma <[email protected]>
1 parent 7119a69 commit 8a7084d

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

src/driver/amdxdna/aie2_ctx_runqueue.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ static void part_ctx_start(struct aie2_partition *part, struct amdxdna_ctx *ctx)
392392

393393
static void part_ctx_stop_wait(struct amdxdna_ctx *ctx, bool wait)
394394
{
395-
struct aie2_partition *part;
396395
struct amdxdna_dev *xdna;
397396
struct aie2_ctx_rq *rq;
398397

@@ -404,8 +403,21 @@ static void part_ctx_stop_wait(struct amdxdna_ctx *ctx, bool wait)
404403
return;
405404
}
406405
aie2_ctx_disconnect(ctx, wait);
406+
407407
list_move_tail(&ctx->entry, &rq->disconn_list);
408408
ctx->priv->status = CTX_STATE_DISCONNECTED;
409+
}
410+
411+
static void part_ctx_stop(struct amdxdna_ctx *ctx)
412+
{
413+
struct aie2_partition *part;
414+
struct amdxdna_dev *xdna;
415+
struct aie2_ctx_rq *rq;
416+
417+
xdna = ctx->client->xdna;
418+
rq = &xdna->dev_handle->ctx_rq;
419+
part_ctx_stop_wait(ctx, true);
420+
409421
part = ctx->priv->part;
410422
if (part) {
411423
part->hwctx_cnt--;
@@ -418,11 +430,6 @@ static void part_ctx_stop_wait(struct amdxdna_ctx *ctx, bool wait)
418430
XDNA_DBG(xdna, "%s disconnected", ctx->name);
419431
}
420432

421-
static void part_ctx_stop(struct amdxdna_ctx *ctx)
422-
{
423-
part_ctx_stop_wait(ctx, true);
424-
}
425-
426433
static void rq_ctx_cancel(struct aie2_ctx_rq *rq, struct amdxdna_ctx *ctx)
427434
{
428435
struct aie2_partition *part;
@@ -452,8 +459,10 @@ static void part_block_all_ctx(struct aie2_partition *part)
452459
{
453460
struct amdxdna_ctx *ctx;
454461

455-
list_for_each_entry(ctx, &part->conn_list, entry)
462+
list_for_each_entry(ctx, &part->conn_list, entry) {
463+
XDNA_DBG(ctx->client->xdna, "%s set block", ctx->name);
456464
ctx->priv->should_block = true;
465+
}
457466
}
458467

459468
static void part_cleanup(struct aie2_partition *part)
@@ -731,7 +740,6 @@ static bool handle_busy_ctxs(struct aie2_ctx_rq *rq)
731740
bool active = false;
732741
int i;
733742

734-
rq->paused = true;
735743
for (i = 0; i < rq->num_parts; i++) {
736744
part = &rq->parts[i];
737745
if (!part->hwctx_cnt)
@@ -762,6 +770,7 @@ static void rq_parts_work(struct work_struct *work)
762770
goto out;
763771

764772
/* Partition expanding or trimming is needed */
773+
rq->paused = true;
765774
if (handle_busy_ctxs(rq)) {
766775
XDNA_DBG(xdna, "Wait for disconneting active contexts");
767776
goto out;
@@ -873,6 +882,8 @@ void aie2_rq_stop_all(struct aie2_ctx_rq *rq)
873882
down_write(&ctx->priv->io_sem);
874883
XDNA_DBG(xdna, "%s @[%d, %d] stop", ctx->name,
875884
part->start_col, part->end_col);
885+
ctx->priv->should_block = true;
886+
ctx->priv->force_yield = true;
876887
part_ctx_stop_wait(ctx, false);
877888
up_write(&ctx->priv->io_sem);
878889
}
@@ -1101,7 +1112,7 @@ void aie2_rq_del(struct aie2_ctx_rq *rq, struct amdxdna_ctx *ctx)
11011112

11021113
if (wait_update_parts && wait_parts)
11031114
wait_for_completion_killable(&ctx->priv->parts_work_comp);
1104-
cancel_work_sync(&ctx->yield_work);
1115+
flush_work(&ctx->yield_work);
11051116
XDNA_DBG(xdna, "%s deleted, status %d priority %d",
11061117
ctx->name, ctx->priv->status, ctx->priv->priority);
11071118
}

src/driver/amdxdna/aie2_message.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,30 @@ int aie2_destroy_context(struct amdxdna_dev_hdl *ndev, struct amdxdna_ctx *ctx)
360360

361361
int aie2_map_host_buf(struct amdxdna_dev_hdl *ndev, u32 context_id, u64 addr, u64 size)
362362
{
363-
DECLARE_AIE2_MSG(map_host_buffer, MSG_OP_MAP_HOST_BUFFER);
363+
DECLARE_AIE2_MSG(host_buffer, MSG_OP_MAP_HOST_BUFFER);
364364
struct amdxdna_dev *xdna = ndev->xdna;
365+
size_t chunk_size;
365366
int ret;
366367

367-
req.context_id = context_id;
368-
req.buf_addr = addr;
369-
req.buf_size = size;
370-
ret = aie2_send_mgmt_msg_wait(ndev, &msg);
371-
if (ret)
372-
return ret;
368+
chunk_size = xdna->dev_info->dev_mem_size;
369+
WARN_ON(!is_power_of_2(chunk_size));
370+
WARN_ON(!IS_ALIGNED(size, chunk_size));
371+
do {
372+
req.context_id = context_id;
373+
req.buf_addr = addr;
374+
req.buf_size = chunk_size;
375+
ret = aie2_send_mgmt_msg_wait(ndev, &msg);
376+
if (ret)
377+
return ret;
378+
379+
addr += chunk_size;
380+
size -= chunk_size;
381+
XDNA_DBG(xdna, "hwctx %d map host buf addr 0x%llx size 0x%lx",
382+
context_id, addr, chunk_size);
373383

374-
XDNA_DBG(xdna, "hwctx %d map host buf addr 0x%llx size 0x%llx",
375-
context_id, addr, size);
384+
/* Change opcode if there are more than one chunk */
385+
msg.opcode = MSG_OP_ADD_HOST_BUFFER;
386+
} while (size);
376387

377388
return 0;
378389
}

src/driver/amdxdna/aie2_msg_priv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum aie2_msg_opcode {
4545
MSG_OP_START_EVENT_TRACE = 0x10F,
4646
MSG_OP_STOP_EVENT_TRACE = 0x110,
4747
MSG_OP_UPDATE_PROPERTY = 0x113,
48+
MSG_OP_ADD_HOST_BUFFER = 0x114,
4849
MSG_OP_MAX_DRV_OPCODE,
4950
MSG_OP_GET_PROTOCOL_VERSION = 0x301,
5051
MSG_OP_MAX_OPCODE
@@ -105,13 +106,14 @@ struct assign_mgmt_pasid_resp {
105106
enum aie2_msg_status status;
106107
} __packed;
107108

108-
struct map_host_buffer_req {
109+
/* For MSG_OP_MAP_HOST_BUFFER and MSG_OP_ADD_HOST_BUFFER */
110+
struct host_buffer_req {
109111
u32 context_id;
110112
u64 buf_addr;
111113
u64 buf_size;
112114
} __packed;
113115

114-
struct map_host_buffer_resp {
116+
struct host_buffer_resp {
115117
enum aie2_msg_status status;
116118
} __packed;
117119

src/driver/amdxdna/amdxdna_gem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,9 @@ amdxdna_drm_create_dev_heap_bo(struct drm_device *dev,
772772
struct amdxdna_gem_obj *abo;
773773
int ret;
774774

775-
if (args->size > xdna->dev_info->dev_mem_size) {
776-
XDNA_ERR(xdna, "Invalid dev heap size 0x%llx, limit 0x%lx",
775+
WARN_ON(!is_power_of_2(xdna->dev_info->dev_mem_size));
776+
if (!IS_ALIGNED(args->size, xdna->dev_info->dev_mem_size)) {
777+
XDNA_ERR(xdna, "The dev heap size 0x%llx is not multiple of 0x%lx",
777778
args->size, xdna->dev_info->dev_mem_size);
778779
return ERR_PTR(-EINVAL);
779780
}

0 commit comments

Comments
 (0)