18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014, Patrik Jakobsson 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Authors: Patrik Jakobsson <patrik.r.jakobsson@gmail.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "psb_drv.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "blitter.h" 128c2ecf20Sopenharmony_ci#include "psb_reg.h" 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* Wait for the blitter to be completely idle */ 158c2ecf20Sopenharmony_ciint gma_blt_wait_idle(struct drm_psb_private *dev_priv) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci unsigned long stop = jiffies + HZ; 188c2ecf20Sopenharmony_ci int busy = 1; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci /* NOP for Cedarview */ 218c2ecf20Sopenharmony_ci if (IS_CDV(dev_priv->dev)) 228c2ecf20Sopenharmony_ci return 0; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci /* First do a quick check */ 258c2ecf20Sopenharmony_ci if ((PSB_RSGX32(PSB_CR_2D_SOCIF) == _PSB_C2_SOCIF_EMPTY) && 268c2ecf20Sopenharmony_ci ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & _PSB_C2B_STATUS_BUSY) == 0)) 278c2ecf20Sopenharmony_ci return 0; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci do { 308c2ecf20Sopenharmony_ci busy = (PSB_RSGX32(PSB_CR_2D_SOCIF) != _PSB_C2_SOCIF_EMPTY); 318c2ecf20Sopenharmony_ci } while (busy && !time_after_eq(jiffies, stop)); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci if (busy) 348c2ecf20Sopenharmony_ci return -EBUSY; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci do { 378c2ecf20Sopenharmony_ci busy = ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & 388c2ecf20Sopenharmony_ci _PSB_C2B_STATUS_BUSY) != 0); 398c2ecf20Sopenharmony_ci } while (busy && !time_after_eq(jiffies, stop)); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci /* If still busy, we probably have a hang */ 428c2ecf20Sopenharmony_ci return (busy) ? -EBUSY : 0; 438c2ecf20Sopenharmony_ci} 44