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 = kzalloc(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 = ioremap(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 iounmap(ctxld->ctxld_reg); in dcss_ctxld_init()
239 dcss_ctxld_free_ctx(ctxld); in dcss_ctxld_init()
240 kfree(ctxld); in dcss_ctxld_init()
245 void dcss_ctxld_exit(struct dcss_ctxld *ctxld) in dcss_ctxld_exit() argument
247 free_irq(ctxld->irq, ctxld); in dcss_ctxld_exit()
249 if (ctxld->ctxld_reg) in dcss_ctxld_exit()
250 iounmap(ctxld->ctxld_reg); in dcss_ctxld_exit()
252 dcss_ctxld_free_ctx(ctxld); in dcss_ctxld_exit()
253 kfree(ctxld); in dcss_ctxld_exit()
256 static int dcss_ctxld_enable_locked(struct dcss_ctxld *ctxld) in dcss_ctxld_enable_locked() argument
258 int curr_ctx = ctxld->current_ctx; in dcss_ctxld_enable_locked()
261 struct dcss_dev *dcss = dcss_drv_dev_to_dcss(ctxld->dev); in dcss_ctxld_enable_locked()
270 sb_hp_cnt = ctxld->ctx_size[curr_ctx][CTX_SB_HP]; in dcss_ctxld_enable_locked()
271 sb_lp_cnt = ctxld->ctx_size[curr_ctx][CTX_SB_LP]; in dcss_ctxld_enable_locked()
272 db_cnt = ctxld->ctx_size[curr_ctx][CTX_DB]; in dcss_ctxld_enable_locked()
276 ctxld->sb_lp[curr_ctx] != ctxld->sb_hp[curr_ctx] + sb_hp_cnt) { in dcss_ctxld_enable_locked()
279 sb_lp_adjusted = ctxld->sb_hp[curr_ctx] + sb_hp_cnt; in dcss_ctxld_enable_locked()
281 memcpy(sb_lp_adjusted, ctxld->sb_lp[curr_ctx], in dcss_ctxld_enable_locked()
285 db_base = db_cnt ? ctxld->db_paddr[curr_ctx] : 0; in dcss_ctxld_enable_locked()
287 dcss_writel(db_base, ctxld->ctxld_reg + DCSS_CTXLD_DB_BASE_ADDR); in dcss_ctxld_enable_locked()
288 dcss_writel(db_cnt, ctxld->ctxld_reg + DCSS_CTXLD_DB_COUNT); in dcss_ctxld_enable_locked()
296 sb_base = sb_count ? ctxld->sb_paddr[curr_ctx] : 0; in dcss_ctxld_enable_locked()
298 dcss_writel(sb_base, ctxld->ctxld_reg + DCSS_CTXLD_SB_BASE_ADDR); in dcss_ctxld_enable_locked()
299 dcss_writel(sb_count, ctxld->ctxld_reg + DCSS_CTXLD_SB_COUNT); in dcss_ctxld_enable_locked()
302 dcss_set(CTXLD_ENABLE, ctxld->ctxld_reg + DCSS_CTXLD_CONTROL_STATUS); in dcss_ctxld_enable_locked()
304 ctxld->in_use = true; in dcss_ctxld_enable_locked()
310 ctxld->current_ctx ^= 1; in dcss_ctxld_enable_locked()
312 ctxld->ctx_size[ctxld->current_ctx][CTX_DB] = 0; in dcss_ctxld_enable_locked()
313 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_HP] = 0; in dcss_ctxld_enable_locked()
314 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_LP] = 0; in dcss_ctxld_enable_locked()
319 int dcss_ctxld_enable(struct dcss_ctxld *ctxld) in dcss_ctxld_enable() argument
321 spin_lock_irq(&ctxld->lock); in dcss_ctxld_enable()
322 ctxld->armed = true; in dcss_ctxld_enable()
323 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_enable()
328 void dcss_ctxld_kick(struct dcss_ctxld *ctxld) in dcss_ctxld_kick() argument
332 spin_lock_irqsave(&ctxld->lock, flags); in dcss_ctxld_kick()
333 if (ctxld->armed && !ctxld->in_use) { in dcss_ctxld_kick()
334 ctxld->armed = false; in dcss_ctxld_kick()
335 dcss_ctxld_enable_locked(ctxld); in dcss_ctxld_kick()
337 spin_unlock_irqrestore(&ctxld->lock, flags); in dcss_ctxld_kick()
340 void dcss_ctxld_write_irqsafe(struct dcss_ctxld *ctxld, u32 ctx_id, u32 val, in dcss_ctxld_write_irqsafe() argument
343 int curr_ctx = ctxld->current_ctx; in dcss_ctxld_write_irqsafe()
345 [CTX_DB] = ctxld->db[curr_ctx], in dcss_ctxld_write_irqsafe()
346 [CTX_SB_HP] = ctxld->sb_hp[curr_ctx], in dcss_ctxld_write_irqsafe()
347 [CTX_SB_LP] = ctxld->sb_lp[curr_ctx] in dcss_ctxld_write_irqsafe()
349 int item_idx = ctxld->ctx_size[curr_ctx][ctx_id]; in dcss_ctxld_write_irqsafe()
358 ctxld->ctx_size[curr_ctx][ctx_id] += 1; in dcss_ctxld_write_irqsafe()
361 void dcss_ctxld_write(struct dcss_ctxld *ctxld, u32 ctx_id, in dcss_ctxld_write() argument
364 spin_lock_irq(&ctxld->lock); in dcss_ctxld_write()
365 dcss_ctxld_write_irqsafe(ctxld, ctx_id, val, reg_ofs); in dcss_ctxld_write()
366 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_write()
369 bool dcss_ctxld_is_flushed(struct dcss_ctxld *ctxld) in dcss_ctxld_is_flushed() argument
371 return ctxld->ctx_size[ctxld->current_ctx][CTX_DB] == 0 && in dcss_ctxld_is_flushed()
372 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_HP] == 0 && in dcss_ctxld_is_flushed()
373 ctxld->ctx_size[ctxld->current_ctx][CTX_SB_LP] == 0; in dcss_ctxld_is_flushed()
376 int dcss_ctxld_resume(struct dcss_ctxld *ctxld) in dcss_ctxld_resume() argument
378 dcss_ctxld_hw_cfg(ctxld); in dcss_ctxld_resume()
380 if (!ctxld->irq_en) { in dcss_ctxld_resume()
381 enable_irq(ctxld->irq); in dcss_ctxld_resume()
382 ctxld->irq_en = true; in dcss_ctxld_resume()
388 int dcss_ctxld_suspend(struct dcss_ctxld *ctxld) in dcss_ctxld_suspend() argument
393 if (!dcss_ctxld_is_flushed(ctxld)) { in dcss_ctxld_suspend()
394 dcss_ctxld_kick(ctxld); in dcss_ctxld_suspend()
396 while (!time_after(jiffies, timeout) && ctxld->in_use) in dcss_ctxld_suspend()
403 spin_lock_irq(&ctxld->lock); in dcss_ctxld_suspend()
405 if (ctxld->irq_en) { in dcss_ctxld_suspend()
406 disable_irq_nosync(ctxld->irq); in dcss_ctxld_suspend()
407 ctxld->irq_en = false; in dcss_ctxld_suspend()
411 ctxld->current_ctx = 0; in dcss_ctxld_suspend()
412 ctxld->ctx_size[0][CTX_DB] = 0; in dcss_ctxld_suspend()
413 ctxld->ctx_size[0][CTX_SB_HP] = 0; in dcss_ctxld_suspend()
414 ctxld->ctx_size[0][CTX_SB_LP] = 0; in dcss_ctxld_suspend()
416 spin_unlock_irq(&ctxld->lock); in dcss_ctxld_suspend()
421 void dcss_ctxld_assert_locked(struct dcss_ctxld *ctxld) in dcss_ctxld_assert_locked() argument
423 lockdep_assert_held(&ctxld->lock); in dcss_ctxld_assert_locked()