1 #ifndef __NVKM_RUNL_H__ 2 #define __NVKM_RUNL_H__ 3 #include <core/intr.h> 4 struct nvkm_cctx; 5 struct nvkm_cgrp; 6 struct nvkm_chan; 7 struct nvkm_memory; 8 struct nvkm_object; 9 struct nvkm_vctx; 10 enum nvkm_subdev_type; 11 12 struct nvkm_engn { 13 const struct nvkm_engn_func { 14 int (*nonstall)(struct nvkm_engn *); 15 bool (*chsw)(struct nvkm_engn *); 16 int (*cxid)(struct nvkm_engn *, bool *cgid); 17 void (*mmu_fault_trigger)(struct nvkm_engn *); 18 bool (*mmu_fault_triggered)(struct nvkm_engn *); 19 int (*ctor)(struct nvkm_engn *, struct nvkm_vctx *); 20 void (*bind)(struct nvkm_engn *, struct nvkm_cctx *, struct nvkm_chan *); 21 int (*ctor2)(struct nvkm_engn *, struct nvkm_vctx *, struct nvkm_chan *); 22 int (*ramht_add)(struct nvkm_engn *, struct nvkm_object *, struct nvkm_chan *); 23 void (*ramht_del)(struct nvkm_chan *, int hash); 24 } *func; 25 struct nvkm_runl *runl; 26 int id; 27 28 struct nvkm_engine *engine; 29 30 int fault; 31 32 struct { 33 u32 desc; 34 u32 size; 35 } rm; 36 37 struct list_head head; 38 }; 39 40 #define ENGN_PRINT(e,l,p,f,a...) \ 41 RUNL_PRINT((e)->runl, l, p, "%02d[%8s]:"f, (e)->id, (e)->engine->subdev.name, ##a) 42 #define ENGN_DEBUG(e,f,a...) ENGN_PRINT((e), DEBUG, info, " "f"\n", ##a) 43 44 struct nvkm_runl { 45 const struct nvkm_runl_func { 46 void (*init)(struct nvkm_runl *); 47 void (*fini)(struct nvkm_runl *); 48 int runqs; 49 u8 size; 50 int (*update)(struct nvkm_runl *); 51 void (*insert_cgrp)(struct nvkm_cgrp *, struct nvkm_memory *, u64 offset); 52 void (*insert_chan)(struct nvkm_chan *, struct nvkm_memory *, u64 offset); 53 void (*commit)(struct nvkm_runl *, struct nvkm_memory *, u32 start, int count); 54 int (*wait)(struct nvkm_runl *); 55 bool (*pending)(struct nvkm_runl *); 56 void (*block)(struct nvkm_runl *, u32 engm); 57 void (*allow)(struct nvkm_runl *, u32 engm); 58 void (*fault_clear)(struct nvkm_runl *); 59 void (*preempt)(struct nvkm_runl *); 60 bool (*preempt_pending)(struct nvkm_runl *); 61 } *func; 62 struct nvkm_fifo *fifo; 63 int id; 64 u32 addr; 65 u32 chan; 66 u16 doorbell; 67 68 struct nvkm_chid *cgid; 69 #define NVKM_CHAN_EVENT_ERRORED BIT(0) 70 struct nvkm_chid *chid; 71 72 struct list_head engns; 73 74 struct nvkm_runq *runq[2]; 75 int runq_nr; 76 77 struct nvkm_inth inth; 78 79 struct { 80 int vector; 81 struct nvkm_inth inth; 82 } nonstall; 83 84 struct list_head cgrps; 85 int cgrp_nr; 86 int chan_nr; 87 atomic_t changed; 88 struct nvkm_memory *mem; 89 u32 offset; 90 struct mutex mutex; 91 92 int blocked; 93 94 struct work_struct work; 95 atomic_t rc_triggered; 96 atomic_t rc_pending; 97 98 struct list_head head; 99 }; 100 101 struct nvkm_runl *nvkm_runl_new(struct nvkm_fifo *, int runi, u32 addr, int id_nr); 102 struct nvkm_runl *nvkm_runl_get(struct nvkm_fifo *, int runi, u32 addr); 103 struct nvkm_engn *nvkm_runl_add(struct nvkm_runl *, int engi, const struct nvkm_engn_func *, 104 enum nvkm_subdev_type, int inst); 105 void nvkm_runl_del(struct nvkm_runl *); 106 void nvkm_runl_fini(struct nvkm_runl *); 107 void nvkm_runl_block(struct nvkm_runl *); 108 void nvkm_runl_allow(struct nvkm_runl *); 109 void nvkm_runl_update_locked(struct nvkm_runl *, bool wait); 110 bool nvkm_runl_update_pending(struct nvkm_runl *); 111 int nvkm_runl_preempt_wait(struct nvkm_runl *); 112 113 void nvkm_runl_rc_engn(struct nvkm_runl *, struct nvkm_engn *); 114 void nvkm_runl_rc_cgrp(struct nvkm_cgrp *); 115 116 struct nvkm_cgrp *nvkm_runl_cgrp_get_cgid(struct nvkm_runl *, int cgid, unsigned long *irqflags); 117 struct nvkm_chan *nvkm_runl_chan_get_chid(struct nvkm_runl *, int chid, unsigned long *irqflags); 118 struct nvkm_chan *nvkm_runl_chan_get_inst(struct nvkm_runl *, u64 inst, unsigned long *irqflags); 119 120 #define nvkm_runl_find_engn(engn,runl,cond) nvkm_list_find(engn, &(runl)->engns, head, (cond)) 121 122 #define nvkm_runl_first(fifo) list_first_entry(&(fifo)->runls, struct nvkm_runl, head) 123 #define nvkm_runl_foreach(runl,fifo) list_for_each_entry((runl), &(fifo)->runls, head) 124 #define nvkm_runl_foreach_cond(runl,fifo,cond) nvkm_list_foreach(runl, &(fifo)->runls, head, (cond)) 125 #define nvkm_runl_foreach_engn(engn,runl) list_for_each_entry((engn), &(runl)->engns, head) 126 #define nvkm_runl_foreach_engn_cond(engn,runl,cond) \ 127 nvkm_list_foreach(engn, &(runl)->engns, head, (cond)) 128 #define nvkm_runl_foreach_cgrp(cgrp,runl) list_for_each_entry((cgrp), &(runl)->cgrps, head) 129 #define nvkm_runl_foreach_cgrp_safe(cgrp,gtmp,runl) \ 130 list_for_each_entry_safe((cgrp), (gtmp), &(runl)->cgrps, head) 131 132 #define RUNL_PRINT(r,l,p,f,a...) \ 133 nvkm_printk__(&(r)->fifo->engine.subdev, NV_DBG_##l, p, "%06x:"f, (r)->addr, ##a) 134 #define RUNL_ERROR(r,f,a...) RUNL_PRINT((r), ERROR, err, " "f"\n", ##a) 135 #define RUNL_DEBUG(r,f,a...) RUNL_PRINT((r), DEBUG, info, " "f"\n", ##a) 136 #define RUNL_TRACE(r,f,a...) RUNL_PRINT((r), TRACE, info, " "f"\n", ##a) 137 #endif 138