Lines Matching refs:ctxld

90 	struct dcss_ctxld *ctxld = data;  in dcss_ctxld_irq_handler()  local
91 struct dcss_dev *dcss = dcss_drv_dev_to_dcss(ctxld->dev); in dcss_ctxld_irq_handler()
94 irq_status = dcss_readl(ctxld->ctxld_reg + DCSS_CTXLD_CONTROL_STATUS); in dcss_ctxld_irq_handler()
97 !(irq_status & CTXLD_ENABLE) && ctxld->in_use) { in dcss_ctxld_irq_handler()
98 ctxld->in_use = false; in dcss_ctxld_irq_handler()
107 dev_err(ctxld->dev, "ctxld: error encountered: %08x\n", in dcss_ctxld_irq_handler()
109 dev_err(ctxld->dev, "ctxld: db=%d, sb_hp=%d, sb_lp=%d\n", in dcss_ctxld_irq_handler()
110 ctxld->ctx_size[ctxld->current_ctx ^ 1][CTX_DB], in dcss_ctxld_irq_handler()
111 ctxld->ctx_size[ctxld->current_ctx ^ 1][CTX_SB_HP], in dcss_ctxld_irq_handler()
112 ctxld->ctx_size[ctxld->current_ctx ^ 1][CTX_SB_LP]); in dcss_ctxld_irq_handler()
116 ctxld->ctxld_reg + DCSS_CTXLD_CONTROL_STATUS); in dcss_ctxld_irq_handler()
121 static int dcss_ctxld_irq_config(struct dcss_ctxld *ctxld, in dcss_ctxld_irq_config() argument
126 ctxld->irq = platform_get_irq_byname(pdev, "ctxld"); in dcss_ctxld_irq_config()
127 if (ctxld->irq < 0) in dcss_ctxld_irq_config()
128 return ctxld->irq; in dcss_ctxld_irq_config()
130 ret = request_irq(ctxld->irq, dcss_ctxld_irq_handler, in dcss_ctxld_irq_config()
131 0, "dcss_ctxld", ctxld); in dcss_ctxld_irq_config()
133 dev_err(ctxld->dev, "ctxld: irq request failed.\n"); in dcss_ctxld_irq_config()
137 ctxld->irq_en = true; in dcss_ctxld_irq_config()
142 static void dcss_ctxld_hw_cfg(struct dcss_ctxld *ctxld) in dcss_ctxld_hw_cfg() argument
146 ctxld->ctxld_reg + DCSS_CTXLD_CONTROL_STATUS); in dcss_ctxld_hw_cfg()
149 static void dcss_ctxld_free_ctx(struct dcss_ctxld *ctxld) in dcss_ctxld_free_ctx() argument
155 if (ctxld->db[i]) { in dcss_ctxld_free_ctx()
156 dma_free_coherent(ctxld->dev, in dcss_ctxld_free_ctx()
158 ctxld->db[i], ctxld->db_paddr[i]); in dcss_ctxld_free_ctx()
159 ctxld->db[i] = NULL; in dcss_ctxld_free_ctx()
160 ctxld->db_paddr[i] = 0; in dcss_ctxld_free_ctx()
163 if (ctxld->sb_hp[i]) { in dcss_ctxld_free_ctx()
164 dma_free_coherent(ctxld->dev, in dcss_ctxld_free_ctx()
166 ctxld->sb_hp[i], ctxld->sb_paddr[i]); in dcss_ctxld_free_ctx()
167 ctxld->sb_hp[i] = NULL; in dcss_ctxld_free_ctx()
168 ctxld->sb_paddr[i] = 0; in dcss_ctxld_free_ctx()
173 static int dcss_ctxld_alloc_ctx(struct dcss_ctxld *ctxld) in dcss_ctxld_alloc_ctx() argument
179 ctx = dma_alloc_coherent(ctxld->dev, in dcss_ctxld_alloc_ctx()
181 &ctxld->db_paddr[i], GFP_KERNEL); in dcss_ctxld_alloc_ctx()
185 ctxld->db[i] = ctx; in dcss_ctxld_alloc_ctx()
187 ctx = dma_alloc_coherent(ctxld->dev, in dcss_ctxld_alloc_ctx()
189 &ctxld->sb_paddr[i], GFP_KERNEL); in dcss_ctxld_alloc_ctx()
193 ctxld->sb_hp[i] = ctx; in dcss_ctxld_alloc_ctx()
194 ctxld->sb_lp[i] = ctx + CTXLD_SB_HP_CTX_ENTRIES; in dcss_ctxld_alloc_ctx()
202 struct dcss_ctxld *ctxld; in dcss_ctxld_init() local
205 ctxld = devm_kzalloc(dcss->dev, sizeof(*ctxld), GFP_KERNEL); in dcss_ctxld_init()
206 if (!ctxld) in dcss_ctxld_init()
209 dcss->ctxld = ctxld; in dcss_ctxld_init()
210 ctxld->dev = dcss->dev; in dcss_ctxld_init()
212 spin_lock_init(&ctxld->lock); in dcss_ctxld_init()
214 ret = dcss_ctxld_alloc_ctx(ctxld); in dcss_ctxld_init()
220 ctxld->ctxld_reg = devm_ioremap(dcss->dev, ctxld_base, SZ_4K); in dcss_ctxld_init()
221 if (!ctxld->ctxld_reg) { in dcss_ctxld_init()
227 ret = dcss_ctxld_irq_config(ctxld, to_platform_device(dcss->dev)); in dcss_ctxld_init()
231 dcss_ctxld_hw_cfg(ctxld); in dcss_ctxld_init()
236 dcss_ctxld_free_ctx(ctxld); in dcss_ctxld_init()
241 void dcss_ctxld_exit(struct dcss_ctxld *ctxld) in dcss_ctxld_exit() argument
243 free_irq(ctxld->irq, ctxld); in dcss_ctxld_exit()
245 dcss_ctxld_free_ctx(ctxld); in dcss_ctxld_exit()
248 static int dcss_ctxld_enable_locked(struct dcss_ctxld *ctxld) in dcss_ctxld_enable_locked() argument
250 int curr_ctx = ctxld->current_ctx; in dcss_ctxld_enable_locked()
253 struct dcss_dev *dcss = dcss_drv_dev_to_dcss(ctxld->dev); in dcss_ctxld_enable_locked()
262 sb_hp_cnt = ctxld->ctx_size[curr_ctx][CTX_SB_HP]; in dcss_ctxld_enable_locked()
263 sb_lp_cnt = ctxld->ctx_size[curr_ctx][CTX_SB_LP]; in dcss_ctxld_enable_locked()
264 db_cnt = ctxld->ctx_size[curr_ctx][CTX_DB]; in dcss_ctxld_enable_locked()
268 ctxld->sb_lp[curr_ctx] != ctxld->sb_hp[curr_ctx] + sb_hp_cnt) { in dcss_ctxld_enable_locked()
271 sb_lp_adjusted = ctxld->sb_hp[curr_ctx] + sb_hp_cnt; in dcss_ctxld_enable_locked()
273 memcpy(sb_lp_adjusted, ctxld->sb_lp[curr_ctx], in dcss_ctxld_enable_locked()
277 db_base = db_cnt ? ctxld->db_paddr[curr_ctx] : 0; in dcss_ctxld_enable_locked()
279 dcss_writel(db_base, ctxld->ctxld_reg + DCSS_CTXLD_DB_BASE_ADDR); in dcss_ctxld_enable_locked()
280 dcss_writel(db_cnt, ctxld->ctxld_reg + DCSS_CTXLD_DB_COUNT); in dcss_ctxld_enable_locked()
288 sb_base = sb_count ? ctxld->sb_paddr[curr_ctx] : 0; in dcss_ctxld_enable_locked()
290 dcss_writel(sb_base, ctxld->ctxld_reg + DCSS_CTXLD_SB_BASE_ADDR); in dcss_ctxld_enable_locked()
291 dcss_writel(sb_count, ctxld->ctxld_reg + DCSS_CTXLD_SB_COUNT); in dcss_ctxld_enable_locked()
294 dcss_set(CTXLD_ENABLE, ctxld->ctxld_reg + DCSS_CTXLD_CONTROL_STATUS); in dcss_ctxld_enable_locked()
296 ctxld->in_use = true; in dcss_ctxld_enable_locked()
302 ctxld->current_ctx ^= 1; in dcss_ctxld_enable_locked()
304 ctxld->ctx_size[ctxld->current_ctx][CTX_DB] = 0; in dcss_ctxld_enable_locked()
305 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_HP] = 0; in dcss_ctxld_enable_locked()
306 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_LP] = 0; in dcss_ctxld_enable_locked()
311 int dcss_ctxld_enable(struct dcss_ctxld *ctxld) in dcss_ctxld_enable() argument
313 spin_lock_irq(&ctxld->lock); in dcss_ctxld_enable()
314 ctxld->armed = true; in dcss_ctxld_enable()
315 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_enable()
320 void dcss_ctxld_kick(struct dcss_ctxld *ctxld) in dcss_ctxld_kick() argument
324 spin_lock_irqsave(&ctxld->lock, flags); in dcss_ctxld_kick()
325 if (ctxld->armed && !ctxld->in_use) { in dcss_ctxld_kick()
326 ctxld->armed = false; in dcss_ctxld_kick()
327 dcss_ctxld_enable_locked(ctxld); in dcss_ctxld_kick()
329 spin_unlock_irqrestore(&ctxld->lock, flags); in dcss_ctxld_kick()
332 void dcss_ctxld_write_irqsafe(struct dcss_ctxld *ctxld, u32 ctx_id, u32 val, in dcss_ctxld_write_irqsafe() argument
335 int curr_ctx = ctxld->current_ctx; in dcss_ctxld_write_irqsafe()
337 [CTX_DB] = ctxld->db[curr_ctx], in dcss_ctxld_write_irqsafe()
338 [CTX_SB_HP] = ctxld->sb_hp[curr_ctx], in dcss_ctxld_write_irqsafe()
339 [CTX_SB_LP] = ctxld->sb_lp[curr_ctx] in dcss_ctxld_write_irqsafe()
341 int item_idx = ctxld->ctx_size[curr_ctx][ctx_id]; in dcss_ctxld_write_irqsafe()
350 ctxld->ctx_size[curr_ctx][ctx_id] += 1; in dcss_ctxld_write_irqsafe()
353 void dcss_ctxld_write(struct dcss_ctxld *ctxld, u32 ctx_id, in dcss_ctxld_write() argument
356 spin_lock_irq(&ctxld->lock); in dcss_ctxld_write()
357 dcss_ctxld_write_irqsafe(ctxld, ctx_id, val, reg_ofs); in dcss_ctxld_write()
358 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_write()
361 bool dcss_ctxld_is_flushed(struct dcss_ctxld *ctxld) in dcss_ctxld_is_flushed() argument
363 return ctxld->ctx_size[ctxld->current_ctx][CTX_DB] == 0 && in dcss_ctxld_is_flushed()
364 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_HP] == 0 && in dcss_ctxld_is_flushed()
365 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_LP] == 0; in dcss_ctxld_is_flushed()
368 int dcss_ctxld_resume(struct dcss_ctxld *ctxld) in dcss_ctxld_resume() argument
370 dcss_ctxld_hw_cfg(ctxld); in dcss_ctxld_resume()
372 if (!ctxld->irq_en) { in dcss_ctxld_resume()
373 enable_irq(ctxld->irq); in dcss_ctxld_resume()
374 ctxld->irq_en = true; in dcss_ctxld_resume()
380 int dcss_ctxld_suspend(struct dcss_ctxld *ctxld) in dcss_ctxld_suspend() argument
385 if (!dcss_ctxld_is_flushed(ctxld)) { in dcss_ctxld_suspend()
386 dcss_ctxld_kick(ctxld); in dcss_ctxld_suspend()
388 while (!time_after(jiffies, timeout) && ctxld->in_use) in dcss_ctxld_suspend()
395 spin_lock_irq(&ctxld->lock); in dcss_ctxld_suspend()
397 if (ctxld->irq_en) { in dcss_ctxld_suspend()
398 disable_irq_nosync(ctxld->irq); in dcss_ctxld_suspend()
399 ctxld->irq_en = false; in dcss_ctxld_suspend()
403 ctxld->current_ctx = 0; in dcss_ctxld_suspend()
404 ctxld->ctx_size[0][CTX_DB] = 0; in dcss_ctxld_suspend()
405 ctxld->ctx_size[0][CTX_SB_HP] = 0; in dcss_ctxld_suspend()
406 ctxld->ctx_size[0][CTX_SB_LP] = 0; in dcss_ctxld_suspend()
408 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_suspend()
413 void dcss_ctxld_assert_locked(struct dcss_ctxld *ctxld) in dcss_ctxld_assert_locked() argument
415 lockdep_assert_held(&ctxld->lock); in dcss_ctxld_assert_locked()