Commit 91a4e83a authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/flcn/msgq: rename msgq-related nvkm_msgqueue_queue to nvkm_falcon_msgq

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent e1cc5798
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
#define __NVKM_SUBDEV_H__ #define __NVKM_SUBDEV_H__
#include <core/device.h> #include <core/device.h>
#define nvkm_falcon_cmdq nvkm_msgqueue_queue
#define nvkm_falcon_msgq nvkm_msgqueue_queue
struct nvkm_subdev { struct nvkm_subdev {
const struct nvkm_subdev_func *func; const struct nvkm_subdev_func *func;
struct nvkm_device *device; struct nvkm_device *device;
......
...@@ -23,74 +23,74 @@ ...@@ -23,74 +23,74 @@
#include "qmgr.h" #include "qmgr.h"
static void static void
msg_queue_open(struct nvkm_msgqueue_queue *queue) nvkm_falcon_msgq_open(struct nvkm_falcon_msgq *msgq)
{ {
mutex_lock(&queue->mutex); mutex_lock(&msgq->mutex);
queue->position = nvkm_falcon_rd32(queue->qmgr->falcon, queue->tail_reg); msgq->position = nvkm_falcon_rd32(msgq->qmgr->falcon, msgq->tail_reg);
} }
static void static void
msg_queue_close(struct nvkm_msgqueue_queue *queue, bool commit) nvkm_falcon_msgq_close(struct nvkm_falcon_msgq *msgq, bool commit)
{ {
struct nvkm_falcon *falcon = queue->qmgr->falcon; struct nvkm_falcon *falcon = msgq->qmgr->falcon;
if (commit) if (commit)
nvkm_falcon_wr32(falcon, queue->tail_reg, queue->position); nvkm_falcon_wr32(falcon, msgq->tail_reg, msgq->position);
mutex_unlock(&queue->mutex); mutex_unlock(&msgq->mutex);
} }
static bool static bool
msg_queue_empty(struct nvkm_msgqueue_queue *queue) nvkm_falcon_msgq_empty(struct nvkm_falcon_msgq *msgq)
{ {
u32 head = nvkm_falcon_rd32(queue->qmgr->falcon, queue->head_reg); u32 head = nvkm_falcon_rd32(msgq->qmgr->falcon, msgq->head_reg);
u32 tail = nvkm_falcon_rd32(queue->qmgr->falcon, queue->tail_reg); u32 tail = nvkm_falcon_rd32(msgq->qmgr->falcon, msgq->tail_reg);
return head == tail; return head == tail;
} }
static int static int
msg_queue_pop(struct nvkm_msgqueue_queue *queue, void *data, u32 size) nvkm_falcon_msgq_pop(struct nvkm_falcon_msgq *msgq, void *data, u32 size)
{ {
struct nvkm_falcon *falcon = queue->qmgr->falcon; struct nvkm_falcon *falcon = msgq->qmgr->falcon;
u32 head, tail, available; u32 head, tail, available;
head = nvkm_falcon_rd32(falcon, queue->head_reg); head = nvkm_falcon_rd32(falcon, msgq->head_reg);
/* has the buffer looped? */ /* has the buffer looped? */
if (head < queue->position) if (head < msgq->position)
queue->position = queue->offset; msgq->position = msgq->offset;
tail = queue->position; tail = msgq->position;
available = head - tail; available = head - tail;
if (size > available) { if (size > available) {
FLCNQ_ERR(queue, "requested %d bytes, but only %d available", FLCNQ_ERR(msgq, "requested %d bytes, but only %d available",
size, available); size, available);
return -EINVAL; return -EINVAL;
} }
nvkm_falcon_read_dmem(falcon, tail, size, 0, data); nvkm_falcon_read_dmem(falcon, tail, size, 0, data);
queue->position += ALIGN(size, QUEUE_ALIGNMENT); msgq->position += ALIGN(size, QUEUE_ALIGNMENT);
return 0; return 0;
} }
static int static int
msg_queue_read(struct nvkm_msgqueue_queue *queue, struct nv_falcon_msg *hdr) nvkm_falcon_msgq_read(struct nvkm_falcon_msgq *msgq, struct nv_falcon_msg *hdr)
{ {
int ret = 0; int ret = 0;
msg_queue_open(queue); nvkm_falcon_msgq_open(msgq);
if (msg_queue_empty(queue)) if (nvkm_falcon_msgq_empty(msgq))
goto close; goto close;
ret = msg_queue_pop(queue, hdr, HDR_SIZE); ret = nvkm_falcon_msgq_pop(msgq, hdr, HDR_SIZE);
if (ret) { if (ret) {
FLCNQ_ERR(queue, "failed to read message header"); FLCNQ_ERR(msgq, "failed to read message header");
goto close; goto close;
} }
if (hdr->size > MSG_BUF_SIZE) { if (hdr->size > MSG_BUF_SIZE) {
FLCNQ_ERR(queue, "message too big, %d bytes", hdr->size); FLCNQ_ERR(msgq, "message too big, %d bytes", hdr->size);
ret = -ENOSPC; ret = -ENOSPC;
goto close; goto close;
} }
...@@ -98,21 +98,21 @@ msg_queue_read(struct nvkm_msgqueue_queue *queue, struct nv_falcon_msg *hdr) ...@@ -98,21 +98,21 @@ msg_queue_read(struct nvkm_msgqueue_queue *queue, struct nv_falcon_msg *hdr)
if (hdr->size > HDR_SIZE) { if (hdr->size > HDR_SIZE) {
u32 read_size = hdr->size - HDR_SIZE; u32 read_size = hdr->size - HDR_SIZE;
ret = msg_queue_pop(queue, (hdr + 1), read_size); ret = nvkm_falcon_msgq_pop(msgq, (hdr + 1), read_size);
if (ret) { if (ret) {
FLCNQ_ERR(queue, "failed to read message data"); FLCNQ_ERR(msgq, "failed to read message data");
goto close; goto close;
} }
} }
ret = 1; ret = 1;
close: close:
msg_queue_close(queue, (ret >= 0)); nvkm_falcon_msgq_close(msgq, (ret >= 0));
return ret; return ret;
} }
static int static int
msgqueue_msg_handle(struct nvkm_falcon_msgq *msgq, struct nv_falcon_msg *hdr) nvkm_falcon_msgq_exec(struct nvkm_falcon_msgq *msgq, struct nv_falcon_msg *hdr)
{ {
struct nvkm_falcon_qmgr_seq *seq; struct nvkm_falcon_qmgr_seq *seq;
...@@ -136,6 +136,20 @@ msgqueue_msg_handle(struct nvkm_falcon_msgq *msgq, struct nv_falcon_msg *hdr) ...@@ -136,6 +136,20 @@ msgqueue_msg_handle(struct nvkm_falcon_msgq *msgq, struct nv_falcon_msg *hdr)
return 0; return 0;
} }
void
nvkm_falcon_msgq_recv(struct nvkm_falcon_msgq *msgq)
{
/*
* We are invoked from a worker thread, so normally we have plenty of
* stack space to work with.
*/
u8 msg_buffer[MSG_BUF_SIZE];
struct nv_falcon_msg *hdr = (void *)msg_buffer;
while (nvkm_falcon_msgq_read(msgq, hdr) > 0)
nvkm_falcon_msgq_exec(msgq, hdr);
}
int int
nvkm_falcon_msgq_recv_initmsg(struct nvkm_falcon_msgq *msgq, nvkm_falcon_msgq_recv_initmsg(struct nvkm_falcon_msgq *msgq,
void *data, u32 size) void *data, u32 size)
...@@ -148,31 +162,17 @@ nvkm_falcon_msgq_recv_initmsg(struct nvkm_falcon_msgq *msgq, ...@@ -148,31 +162,17 @@ nvkm_falcon_msgq_recv_initmsg(struct nvkm_falcon_msgq *msgq,
msgq->tail_reg = falcon->func->msgq.tail; msgq->tail_reg = falcon->func->msgq.tail;
msgq->offset = nvkm_falcon_rd32(falcon, falcon->func->msgq.tail); msgq->offset = nvkm_falcon_rd32(falcon, falcon->func->msgq.tail);
msg_queue_open(msgq); nvkm_falcon_msgq_open(msgq);
ret = msg_queue_pop(msgq, data, size); ret = nvkm_falcon_msgq_pop(msgq, data, size);
if (ret == 0 && hdr->size != size) { if (ret == 0 && hdr->size != size) {
FLCN_ERR(falcon, "unexpected init message size %d vs %d", FLCN_ERR(falcon, "unexpected init message size %d vs %d",
hdr->size, size); hdr->size, size);
ret = -EINVAL; ret = -EINVAL;
} }
msg_queue_close(msgq, ret == 0); nvkm_falcon_msgq_close(msgq, ret == 0);
return ret; return ret;
} }
void
nvkm_falcon_msgq_recv(struct nvkm_falcon_msgq *queue)
{
/*
* We are invoked from a worker thread, so normally we have plenty of
* stack space to work with.
*/
u8 msg_buffer[MSG_BUF_SIZE];
struct nv_falcon_msg *hdr = (void *)msg_buffer;
while (msg_queue_read(queue, hdr) > 0)
msgqueue_msg_handle(queue, hdr);
}
void void
nvkm_falcon_msgq_init(struct nvkm_falcon_msgq *msgq, nvkm_falcon_msgq_init(struct nvkm_falcon_msgq *msgq,
u32 index, u32 offset, u32 size) u32 index, u32 offset, u32 size)
......
...@@ -69,35 +69,6 @@ struct nvkm_msgqueue_func { ...@@ -69,35 +69,6 @@ struct nvkm_msgqueue_func {
void (*dtor)(struct nvkm_msgqueue *); void (*dtor)(struct nvkm_msgqueue *);
}; };
/**
* struct nvkm_msgqueue_queue - information about a command or message queue
*
* The number of queues is firmware-dependent. All queues must have their
* information filled by the init message handler.
*
* @mutex_lock: to be acquired when the queue is being used
* @index: physical queue index
* @offset: DMEM offset where this queue begins
* @size: size allocated to this queue in DMEM (in bytes)
* @position: current write position
* @head_reg: address of the HEAD register for this queue
* @tail_reg: address of the TAIL register for this queue
*/
struct nvkm_msgqueue_queue {
struct nvkm_falcon_qmgr *qmgr;
const char *name;
struct mutex mutex;
u32 index;
u32 offset;
u32 size;
u32 position;
u32 head_reg;
u32 tail_reg;
struct completion ready;
};
/** /**
* struct nvkm_msgqueue - manage a command/message based FW on a falcon * struct nvkm_msgqueue - manage a command/message based FW on a falcon
* *
......
...@@ -57,6 +57,32 @@ nvkm_falcon_qmgr_seq_acquire(struct nvkm_falcon_qmgr *); ...@@ -57,6 +57,32 @@ nvkm_falcon_qmgr_seq_acquire(struct nvkm_falcon_qmgr *);
void nvkm_falcon_qmgr_seq_release(struct nvkm_falcon_qmgr *, void nvkm_falcon_qmgr_seq_release(struct nvkm_falcon_qmgr *,
struct nvkm_falcon_qmgr_seq *); struct nvkm_falcon_qmgr_seq *);
struct nvkm_falcon_cmdq {
struct nvkm_falcon_qmgr *qmgr;
const char *name;
struct mutex mutex;
struct completion ready;
u32 head_reg;
u32 tail_reg;
u32 offset;
u32 size;
u32 position;
};
struct nvkm_falcon_msgq {
struct nvkm_falcon_qmgr *qmgr;
const char *name;
struct mutex mutex;
u32 head_reg;
u32 tail_reg;
u32 offset;
u32 position;
};
#define FLCNQ_PRINTK(t,q,f,a...) \ #define FLCNQ_PRINTK(t,q,f,a...) \
FLCN_PRINTK(t, (q)->qmgr->falcon, "%s: "f, (q)->name, ##a) FLCN_PRINTK(t, (q)->qmgr->falcon, "%s: "f, (q)->name, ##a)
#define FLCNQ_DBG(q,f,a...) FLCNQ_PRINTK(debug, (q), f, ##a) #define FLCNQ_DBG(q,f,a...) FLCNQ_PRINTK(debug, (q), f, ##a)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment