Commit acc466ab authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/flcn/cmdq: explicitly create command queue(s) from subdevs

Code to interface with LS firmwares is being moved to the subdevs where it
belongs, rather than living in the common falcon code.

This is an incremental step towards that goal.
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 8763955b
...@@ -33,4 +33,12 @@ int gp102_sec2_flcn_enable(struct nvkm_falcon *); ...@@ -33,4 +33,12 @@ int gp102_sec2_flcn_enable(struct nvkm_falcon *);
struct nvkm_falcon_qmgr; struct nvkm_falcon_qmgr;
int nvkm_falcon_qmgr_new(struct nvkm_falcon *, struct nvkm_falcon_qmgr **); int nvkm_falcon_qmgr_new(struct nvkm_falcon *, struct nvkm_falcon_qmgr **);
void nvkm_falcon_qmgr_del(struct nvkm_falcon_qmgr **); void nvkm_falcon_qmgr_del(struct nvkm_falcon_qmgr **);
struct nvkm_falcon_cmdq;
int nvkm_falcon_cmdq_new(struct nvkm_falcon_qmgr *, const char *name,
struct nvkm_falcon_cmdq **);
void nvkm_falcon_cmdq_del(struct nvkm_falcon_cmdq **);
void nvkm_falcon_cmdq_init(struct nvkm_falcon_cmdq *,
u32 index, u32 offset, u32 size);
void nvkm_falcon_cmdq_fini(struct nvkm_falcon_cmdq *);
#endif #endif
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#define __NVKM_SUBDEV_H__ #define __NVKM_SUBDEV_H__
#include <core/device.h> #include <core/device.h>
#define nvkm_falcon_cmdq 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;
......
...@@ -11,6 +11,7 @@ struct nvkm_sec2 { ...@@ -11,6 +11,7 @@ struct nvkm_sec2 {
struct nvkm_falcon falcon; struct nvkm_falcon falcon;
struct nvkm_falcon_qmgr *qmgr; struct nvkm_falcon_qmgr *qmgr;
struct nvkm_falcon_cmdq *cmdq;
struct nvkm_msgqueue *queue; struct nvkm_msgqueue *queue;
struct work_struct work; struct work_struct work;
}; };
......
...@@ -10,6 +10,8 @@ struct nvkm_pmu { ...@@ -10,6 +10,8 @@ struct nvkm_pmu {
struct nvkm_falcon falcon; struct nvkm_falcon falcon;
struct nvkm_falcon_qmgr *qmgr; struct nvkm_falcon_qmgr *qmgr;
struct nvkm_falcon_cmdq *hpq;
struct nvkm_falcon_cmdq *lpq;
struct nvkm_msgqueue *queue; struct nvkm_msgqueue *queue;
struct { struct {
......
...@@ -51,6 +51,7 @@ nvkm_sec2_fini(struct nvkm_engine *engine, bool suspend) ...@@ -51,6 +51,7 @@ nvkm_sec2_fini(struct nvkm_engine *engine, bool suspend)
{ {
struct nvkm_sec2 *sec2 = nvkm_sec2(engine); struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
flush_work(&sec2->work); flush_work(&sec2->work);
nvkm_falcon_cmdq_fini(sec2->cmdq);
return 0; return 0;
} }
...@@ -59,6 +60,7 @@ nvkm_sec2_dtor(struct nvkm_engine *engine) ...@@ -59,6 +60,7 @@ nvkm_sec2_dtor(struct nvkm_engine *engine)
{ {
struct nvkm_sec2 *sec2 = nvkm_sec2(engine); struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
nvkm_msgqueue_del(&sec2->queue); nvkm_msgqueue_del(&sec2->queue);
nvkm_falcon_cmdq_del(&sec2->cmdq);
nvkm_falcon_qmgr_del(&sec2->qmgr); nvkm_falcon_qmgr_del(&sec2->qmgr);
nvkm_falcon_dtor(&sec2->falcon); nvkm_falcon_dtor(&sec2->falcon);
return sec2; return sec2;
...@@ -96,7 +98,8 @@ nvkm_sec2_new_(const struct nvkm_sec2_fwif *fwif, struct nvkm_device *device, ...@@ -96,7 +98,8 @@ nvkm_sec2_new_(const struct nvkm_sec2_fwif *fwif, struct nvkm_device *device,
if (ret) if (ret)
return ret; return ret;
if ((ret = nvkm_falcon_qmgr_new(&sec2->falcon, &sec2->qmgr))) if ((ret = nvkm_falcon_qmgr_new(&sec2->falcon, &sec2->qmgr)) ||
(ret = nvkm_falcon_cmdq_new(sec2->qmgr, "cmdq", &sec2->cmdq)))
return ret; return ret;
INIT_WORK(&sec2->work, nvkm_sec2_recv); INIT_WORK(&sec2->work, nvkm_sec2_recv);
......
...@@ -183,3 +183,48 @@ nvkm_msgqueue_post(struct nvkm_msgqueue *priv, enum msgqueue_msg_priority prio, ...@@ -183,3 +183,48 @@ nvkm_msgqueue_post(struct nvkm_msgqueue *priv, enum msgqueue_msg_priority prio,
return ret; return ret;
} }
void
nvkm_falcon_cmdq_fini(struct nvkm_falcon_cmdq *cmdq)
{
}
void
nvkm_falcon_cmdq_init(struct nvkm_falcon_cmdq *cmdq,
u32 index, u32 offset, u32 size)
{
const struct nvkm_falcon_func *func = cmdq->qmgr->falcon->func;
cmdq->head_reg = func->cmdq.head + index * func->cmdq.stride;
cmdq->tail_reg = func->cmdq.tail + index * func->cmdq.stride;
cmdq->offset = offset;
cmdq->size = size;
FLCNQ_DBG(cmdq, "initialised @ index %d offset 0x%08x size 0x%08x",
index, cmdq->offset, cmdq->size);
}
void
nvkm_falcon_cmdq_del(struct nvkm_falcon_cmdq **pcmdq)
{
struct nvkm_falcon_cmdq *cmdq = *pcmdq;
if (cmdq) {
kfree(*pcmdq);
*pcmdq = NULL;
}
}
int
nvkm_falcon_cmdq_new(struct nvkm_falcon_qmgr *qmgr, const char *name,
struct nvkm_falcon_cmdq **pcmdq)
{
struct nvkm_falcon_cmdq *cmdq = *pcmdq;
if (!(cmdq = *pcmdq = kzalloc(sizeof(*cmdq), GFP_KERNEL)))
return -ENOMEM;
cmdq->qmgr = qmgr;
cmdq->name = name;
mutex_init(&cmdq->mutex);
return 0;
}
...@@ -133,6 +133,7 @@ struct nvkm_msgqueue_func { ...@@ -133,6 +133,7 @@ struct nvkm_msgqueue_func {
*/ */
struct nvkm_msgqueue_queue { struct nvkm_msgqueue_queue {
struct nvkm_falcon_qmgr *qmgr; struct nvkm_falcon_qmgr *qmgr;
const char *name;
struct mutex mutex; struct mutex mutex;
u32 index; u32 index;
u32 offset; u32 offset;
......
...@@ -22,14 +22,11 @@ ...@@ -22,14 +22,11 @@
*/ */
#include "msgqueue.h" #include "msgqueue.h"
#include <engine/falcon.h> #include <engine/falcon.h>
#include <subdev/pmu.h>
#include <subdev/secboot.h> #include <subdev/secboot.h>
/* Queues identifiers */ /* Queues identifiers */
enum { enum {
/* High Priority Command Queue for Host -> PMU communication */
MSGQUEUE_0137C63D_COMMAND_QUEUE_HPQ = 0,
/* Low Priority Command Queue for Host -> PMU communication */
MSGQUEUE_0137C63D_COMMAND_QUEUE_LPQ = 1,
/* Message queue for PMU -> Host communication */ /* Message queue for PMU -> Host communication */
MSGQUEUE_0137C63D_MESSAGE_QUEUE = 4, MSGQUEUE_0137C63D_MESSAGE_QUEUE = 4,
MSGQUEUE_0137C63D_NUM_QUEUES = 5, MSGQUEUE_0137C63D_NUM_QUEUES = 5,
...@@ -61,9 +58,9 @@ msgqueue_0137c63d_cmd_queue(struct nvkm_msgqueue *queue, ...@@ -61,9 +58,9 @@ msgqueue_0137c63d_cmd_queue(struct nvkm_msgqueue *queue,
switch (priority) { switch (priority) {
case MSGQUEUE_MSG_PRIORITY_HIGH: case MSGQUEUE_MSG_PRIORITY_HIGH:
return &priv->queue[MSGQUEUE_0137C63D_COMMAND_QUEUE_HPQ]; return subdev->device->pmu->hpq;
case MSGQUEUE_MSG_PRIORITY_LOW: case MSGQUEUE_MSG_PRIORITY_LOW:
return &priv->queue[MSGQUEUE_0137C63D_COMMAND_QUEUE_LPQ]; return subdev->device->pmu->lpq;
default: default:
nvkm_error(subdev, "invalid command queue!\n"); nvkm_error(subdev, "invalid command queue!\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -138,6 +135,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr) ...@@ -138,6 +135,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr)
} *init = (void *)hdr; } *init = (void *)hdr;
const struct nvkm_falcon_func *func = _queue->falcon->func; const struct nvkm_falcon_func *func = _queue->falcon->func;
const struct nvkm_subdev *subdev = _queue->falcon->owner; const struct nvkm_subdev *subdev = _queue->falcon->owner;
struct nvkm_pmu *pmu = subdev->device->pmu;
int i; int i;
if (init->base.hdr.unit_id != MSGQUEUE_0137C63D_UNIT_INIT) { if (init->base.hdr.unit_id != MSGQUEUE_0137C63D_UNIT_INIT) {
...@@ -159,12 +157,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr) ...@@ -159,12 +157,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr)
queue->offset = init->queue_info[i].offset; queue->offset = init->queue_info[i].offset;
queue->size = init->queue_info[i].size; queue->size = init->queue_info[i].size;
if (i != MSGQUEUE_0137C63D_MESSAGE_QUEUE) { if (i == MSGQUEUE_0137C63D_MESSAGE_QUEUE) {
queue->head_reg = func->cmdq.head + queue->index *
func->cmdq.stride;
queue->tail_reg = func->cmdq.tail + queue->index *
func->cmdq.stride;
} else {
queue->head_reg = func->msgq.head; queue->head_reg = func->msgq.head;
queue->tail_reg = func->msgq.tail; queue->tail_reg = func->msgq.tail;
} }
...@@ -174,6 +167,13 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr) ...@@ -174,6 +167,13 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr)
i, queue->index, queue->offset, queue->size); i, queue->index, queue->offset, queue->size);
} }
nvkm_falcon_cmdq_init(pmu->hpq, init->queue_info[0].index,
init->queue_info[0].offset,
init->queue_info[0].size);
nvkm_falcon_cmdq_init(pmu->lpq, init->queue_info[1].index,
init->queue_info[1].offset,
init->queue_info[1].size);
/* Complete initialization by initializing WPR region */ /* Complete initialization by initializing WPR region */
return acr_init_wpr(&priv->base); return acr_init_wpr(&priv->base);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "msgqueue.h" #include "msgqueue.h"
#include <engine/falcon.h> #include <engine/falcon.h>
#include <engine/sec2.h>
#include <subdev/secboot.h> #include <subdev/secboot.h>
/* /*
...@@ -48,9 +49,7 @@ static struct nvkm_msgqueue_queue * ...@@ -48,9 +49,7 @@ static struct nvkm_msgqueue_queue *
msgqueue_0148cdec_cmd_queue(struct nvkm_msgqueue *queue, msgqueue_0148cdec_cmd_queue(struct nvkm_msgqueue *queue,
enum msgqueue_msg_priority priority) enum msgqueue_msg_priority priority)
{ {
struct msgqueue_0148cdec *priv = msgqueue_0148cdec(queue); return queue->falcon->owner->device->sec2->cmdq;
return &priv->queue[MSGQUEUE_0148CDEC_COMMAND_QUEUE];
} }
static void static void
...@@ -107,6 +106,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr) ...@@ -107,6 +106,7 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr)
} *init = (void *)hdr; } *init = (void *)hdr;
const struct nvkm_falcon_func *func = _queue->falcon->func; const struct nvkm_falcon_func *func = _queue->falcon->func;
const struct nvkm_subdev *subdev = _queue->falcon->owner; const struct nvkm_subdev *subdev = _queue->falcon->owner;
struct nvkm_sec2 *sec2 = subdev->device->sec2;
int i; int i;
if (init->base.hdr.unit_id != MSGQUEUE_0148CDEC_UNIT_INIT) { if (init->base.hdr.unit_id != MSGQUEUE_0148CDEC_UNIT_INIT) {
...@@ -135,10 +135,10 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr) ...@@ -135,10 +135,10 @@ init_callback(struct nvkm_msgqueue *_queue, struct nvkm_msgqueue_hdr *hdr)
queue->tail_reg = func->msgq.tail + queue->index * queue->tail_reg = func->msgq.tail + queue->index *
func->msgq.stride; func->msgq.stride;
} else { } else {
queue->head_reg = func->cmdq.head + queue->index * nvkm_falcon_cmdq_init(sec2->cmdq,
func->cmdq.stride; init->queue_info[i].index,
queue->tail_reg = func->cmdq.tail + queue->index * init->queue_info[i].offset,
func->cmdq.stride; init->queue_info[i].size);
} }
nvkm_debug(subdev, nvkm_debug(subdev,
......
...@@ -15,4 +15,9 @@ struct nvkm_falcon_qmgr { ...@@ -15,4 +15,9 @@ struct nvkm_falcon_qmgr {
struct nvkm_msgqueue_seq *msgqueue_seq_acquire(struct nvkm_msgqueue *); struct nvkm_msgqueue_seq *msgqueue_seq_acquire(struct nvkm_msgqueue *);
void msgqueue_seq_release(struct nvkm_msgqueue *, struct nvkm_msgqueue_seq *); void msgqueue_seq_release(struct nvkm_msgqueue *, struct nvkm_msgqueue_seq *);
#define FLCNQ_PRINTK(t,q,f,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_ERR(q,f,a...) FLCNQ_PRINTK(error, (q), f, ##a)
#endif #endif
...@@ -86,6 +86,9 @@ nvkm_pmu_fini(struct nvkm_subdev *subdev, bool suspend) ...@@ -86,6 +86,9 @@ nvkm_pmu_fini(struct nvkm_subdev *subdev, bool suspend)
pmu->func->fini(pmu); pmu->func->fini(pmu);
flush_work(&pmu->recv.work); flush_work(&pmu->recv.work);
nvkm_falcon_cmdq_fini(pmu->lpq);
nvkm_falcon_cmdq_fini(pmu->hpq);
return 0; return 0;
} }
...@@ -139,6 +142,8 @@ nvkm_pmu_dtor(struct nvkm_subdev *subdev) ...@@ -139,6 +142,8 @@ nvkm_pmu_dtor(struct nvkm_subdev *subdev)
{ {
struct nvkm_pmu *pmu = nvkm_pmu(subdev); struct nvkm_pmu *pmu = nvkm_pmu(subdev);
nvkm_msgqueue_del(&pmu->queue); nvkm_msgqueue_del(&pmu->queue);
nvkm_falcon_cmdq_del(&pmu->lpq);
nvkm_falcon_cmdq_del(&pmu->hpq);
nvkm_falcon_qmgr_del(&pmu->qmgr); nvkm_falcon_qmgr_del(&pmu->qmgr);
nvkm_falcon_dtor(&pmu->falcon); nvkm_falcon_dtor(&pmu->falcon);
return nvkm_pmu(subdev); return nvkm_pmu(subdev);
...@@ -176,7 +181,9 @@ nvkm_pmu_ctor(const struct nvkm_pmu_fwif *fwif, struct nvkm_device *device, ...@@ -176,7 +181,9 @@ nvkm_pmu_ctor(const struct nvkm_pmu_fwif *fwif, struct nvkm_device *device,
if (ret) if (ret)
return ret; return ret;
if ((ret = nvkm_falcon_qmgr_new(&pmu->falcon, &pmu->qmgr))) if ((ret = nvkm_falcon_qmgr_new(&pmu->falcon, &pmu->qmgr)) ||
(ret = nvkm_falcon_cmdq_new(pmu->qmgr, "hpq", &pmu->hpq)) ||
(ret = nvkm_falcon_cmdq_new(pmu->qmgr, "lpq", &pmu->lpq)))
return ret; return ret;
return 0; return 0;
......
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