Two cleanups - These patches make Exynos DRM driver to use pm_runtime_resume_and_get() function instead of m_runtime_get_sync() to deal with usage counter. pm_runtime_get_sync() increases the usage counter even when it failed, which could make callers to forget to decrease the usage counter. pm_runtime_resume_and_get() decreases the usage counter regardless of whether it failed or not. Signed-off-by: Dave Airlie <airlied@redhat.com>
Unified · Split
| @@ -513,8 +513,13 @@ static void decon_swreset(struct decon_context *ctx) · 512 unmodified lines | |||
| 513 | static void decon_atomic_enable(struct exynos_drm_crtc *crtc) | 513 | static void decon_atomic_enable(struct exynos_drm_crtc *crtc) |
| 514 | { | 514 | { |
| 515 | struct decon_context *ctx = crtc->ctx; | 515 | struct decon_context *ctx = crtc->ctx; |
| 516 | int ret; | ||
| 516 | 517 | ||
| 517 | pm_runtime_get_sync(ctx->dev); | 518 | ret = pm_runtime_resume_and_get(ctx->dev); |
| 519 | if (ret < 0) { | ||
| 520 | DRM_DEV_ERROR(ctx->dev, "failed to enable DECON device.\n"); | ||
| 521 | return; | ||
| 522 | } | ||
| 518 | 523 | ||
| 519 | exynos_drm_pipe_clk_enable(crtc, true); | 524 | exynos_drm_pipe_clk_enable(crtc, true); |
| 520 | 525 | ||
| @@ -531,11 +531,16 @@ static void decon_init(struct decon_context *ctx) · 530 unmodified lines | |||
| 531 | static void decon_atomic_enable(struct exynos_drm_crtc *crtc) | 531 | static void decon_atomic_enable(struct exynos_drm_crtc *crtc) |
| 532 | { | 532 | { |
| 533 | struct decon_context *ctx = crtc->ctx; | 533 | struct decon_context *ctx = crtc->ctx; |
| 534 | int ret; | ||
| 534 | 535 | ||
| 535 | if (!ctx->suspended) | 536 | if (!ctx->suspended) |
| 536 | return; | 537 | return; |
| 537 | 538 | ||
| 538 | pm_runtime_get_sync(ctx->dev); | 539 | ret = pm_runtime_resume_and_get(ctx->dev); |
| 540 | if (ret < 0) { | ||
| 541 | DRM_DEV_ERROR(ctx->dev, "failed to enable DECON device.\n"); | ||
| 542 | return; | ||
| 543 | } | ||
| 539 | 544 | ||
| 540 | decon_init(ctx); | 545 | decon_init(ctx); |
| 541 | 546 | ||
| @@ -1383,7 +1383,12 @@ static void exynos_dsi_enable(struct drm_encoder *encoder) · 1382 unmodified lines | |||
| 1383 | if (dsi->state & DSIM_STATE_ENABLED) | 1383 | if (dsi->state & DSIM_STATE_ENABLED) |
| 1384 | return; | 1384 | return; |
| 1385 | 1385 | ||
| 1386 | pm_runtime_get_sync(dsi->dev); | 1386 | ret = pm_runtime_resume_and_get(dsi->dev); |
| 1387 | if (ret < 0) { | ||
| 1388 | dev_err(dsi->dev, "failed to enable DSI device.\n"); | ||
| 1389 | return; | ||
| 1390 | } | ||
| 1391 | |||
| 1387 | dsi->state |= DSIM_STATE_ENABLED; | 1392 | dsi->state |= DSIM_STATE_ENABLED; |
| 1388 | 1393 | ||
| 1389 | if (dsi->panel) { | 1394 | if (dsi->panel) { |
| @@ -1085,8 +1085,14 @@ static int fimc_commit(struct exynos_drm_ipp *ipp, · 1084 unmodified lines | |||
| 1085 | { | 1085 | { |
| 1086 | struct fimc_context *ctx = | 1086 | struct fimc_context *ctx = |
| 1087 | container_of(ipp, struct fimc_context, ipp); | 1087 | container_of(ipp, struct fimc_context, ipp); |
| 1088 | int ret; | ||
| 1089 | |||
| 1090 | ret = pm_runtime_resume_and_get(ctx->dev); | ||
| 1091 | if (ret < 0) { | ||
| 1092 | dev_err(ctx->dev, "failed to enable FIMC device.\n"); | ||
| 1093 | return ret; | ||
| 1094 | } | ||
| 1088 | 1095 | ||
| 1089 | pm_runtime_get_sync(ctx->dev); | ||
| 1090 | ctx->task = task; | 1096 | ctx->task = task; |
| 1091 | 1097 | ||
| 1092 | fimc_src_set_fmt(ctx, task->src.buf.fourcc, task->src.buf.modifier); | 1098 | fimc_src_set_fmt(ctx, task->src.buf.fourcc, task->src.buf.modifier); |
| @@ -343,13 +343,18 @@ static void fimd_enable_shadow_channel_path(struct fimd_context *ctx, · 342 unmodified lines | |||
| 343 | writel(val, ctx->regs + SHADOWCON); | 343 | writel(val, ctx->regs + SHADOWCON); |
| 344 | } | 344 | } |
| 345 | 345 | ||
| 346 | static void fimd_clear_channels(struct exynos_drm_crtc *crtc) | 346 | static int fimd_clear_channels(struct exynos_drm_crtc *crtc) |
| 347 | { | 347 | { |
| 348 | struct fimd_context *ctx = crtc->ctx; | 348 | struct fimd_context *ctx = crtc->ctx; |
| 349 | unsigned int win, ch_enabled = 0; | 349 | unsigned int win, ch_enabled = 0; |
| 350 | int ret; | ||
| 350 | 351 | ||
| 351 | /* Hardware is in unknown state, so ensure it gets enabled properly */ | 352 | /* Hardware is in unknown state, so ensure it gets enabled properly */ |
| 352 | pm_runtime_get_sync(ctx->dev); | 353 | ret = pm_runtime_resume_and_get(ctx->dev); |
| 354 | if (ret < 0) { | ||
| 355 | dev_err(ctx->dev, "failed to enable FIMD device.\n"); | ||
| 356 | return ret; | ||
| 357 | } | ||
| 353 | 358 | ||
| 354 | clk_prepare_enable(ctx->bus_clk); | 359 | clk_prepare_enable(ctx->bus_clk); |
| 355 | clk_prepare_enable(ctx->lcd_clk); | 360 | clk_prepare_enable(ctx->lcd_clk); |
| @@ -384,6 +389,8 @@ static void fimd_clear_channels(struct exynos_drm_crtc *crtc) · 28 unmodified lines | |||
| 384 | clk_disable_unprepare(ctx->bus_clk); | 389 | clk_disable_unprepare(ctx->bus_clk); |
| 385 | 390 | ||
| 386 | pm_runtime_put(ctx->dev); | 391 | pm_runtime_put(ctx->dev); |
| 392 | |||
| 393 | return 0; | ||
| 387 | } | 394 | } |
| 388 | 395 | ||
| 389 | 396 | ||
| @@ -905,7 +912,10 @@ static void fimd_atomic_enable(struct exynos_drm_crtc *crtc) · 515 unmodified lines | |||
| 905 | 912 | ||
| 906 | ctx->suspended = false; | 913 | ctx->suspended = false; |
| 907 | 914 | ||
| 908 | pm_runtime_get_sync(ctx->dev); | 915 | if (pm_runtime_resume_and_get(ctx->dev) < 0) { |
| 916 | dev_warn(ctx->dev, "failed to enable FIMD device.\n"); | ||
| 917 | return; | ||
| 918 | } | ||
| 909 | 919 | ||
| 910 | /* if vblank was enabled status, enable it again. */ | 920 | /* if vblank was enabled status, enable it again. */ |
| 911 | if (test_and_clear_bit(0, &ctx->irq_flags)) | 921 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
| @@ -1089,8 +1099,13 @@ static int fimd_bind(struct device *dev, struct device *master, void *data) · 177 unmodified lines | |||
| 1089 | if (ctx->encoder) | 1099 | if (ctx->encoder) |
| 1090 | exynos_dpi_bind(drm_dev, ctx->encoder); | 1100 | exynos_dpi_bind(drm_dev, ctx->encoder); |
| 1091 | 1101 | ||
| 1092 | if (is_drm_iommu_supported(drm_dev)) | 1102 | if (is_drm_iommu_supported(drm_dev)) { |
| 1093 | fimd_clear_channels(ctx->crtc); | 1103 | int ret; |
| 1104 | |||
| 1105 | ret = fimd_clear_channels(ctx->crtc); | ||
| 1106 | if (ret < 0) | ||
| 1107 | return ret; | ||
| 1108 | } | ||
| 1094 | 1109 | ||
| 1095 | return exynos_drm_register_dma(drm_dev, dev, &ctx->dma_priv); | 1110 | return exynos_drm_register_dma(drm_dev, dev, &ctx->dma_priv); |
| 1096 | } | 1111 | } |
| @@ -892,7 +892,14 @@ static void g2d_runqueue_worker(struct work_struct *work) · 891 unmodified lines | |||
| 892 | g2d->runqueue_node = g2d_get_runqueue_node(g2d); | 892 | g2d->runqueue_node = g2d_get_runqueue_node(g2d); |
| 893 | 893 | ||
| 894 | if (g2d->runqueue_node) { | 894 | if (g2d->runqueue_node) { |
| 895 | pm_runtime_get_sync(g2d->dev); | 895 | int ret; |
| 896 | |||
| 897 | ret = pm_runtime_resume_and_get(g2d->dev); | ||
| 898 | if (ret < 0) { | ||
| 899 | dev_err(g2d->dev, "failed to enable G2D device.\n"); | ||
| 900 | return; | ||
| 901 | } | ||
| 902 | |||
| 896 | g2d_dma_start(g2d, g2d->runqueue_node); | 903 | g2d_dma_start(g2d, g2d->runqueue_node); |
| 897 | } | 904 | } |
| 898 | } | 905 | } |
| @@ -1118,7 +1118,12 @@ static int gsc_commit(struct exynos_drm_ipp *ipp, · 1117 unmodified lines | |||
| 1118 | struct gsc_context *ctx = container_of(ipp, struct gsc_context, ipp); | 1118 | struct gsc_context *ctx = container_of(ipp, struct gsc_context, ipp); |
| 1119 | int ret; | 1119 | int ret; |
| 1120 | 1120 | ||
| 1121 | pm_runtime_get_sync(ctx->dev); | 1121 | ret = pm_runtime_resume_and_get(ctx->dev); |
| 1122 | if (ret < 0) { | ||
| 1123 | dev_err(ctx->dev, "failed to enable GScaler device.\n"); | ||
| 1124 | return ret; | ||
| 1125 | } | ||
| 1126 | |||
| 1122 | ctx->task = task; | 1127 | ctx->task = task; |
| 1123 | 1128 | ||
| 1124 | ret = gsc_reset(ctx); | 1129 | ret = gsc_reset(ctx); |
| @@ -268,11 +268,9 @@ static void mic_pre_enable(struct drm_bridge *bridge) · 267 unmodified lines | |||
| 268 | if (mic->enabled) | 268 | if (mic->enabled) |
| 269 | goto unlock; | 269 | goto unlock; |
| 270 | 270 | ||
| 271 | ret = pm_runtime_get_sync(mic->dev); | 271 | ret = pm_runtime_resume_and_get(mic->dev); |
| 272 | if (ret < 0) { | 272 | if (ret < 0) |
| 273 | pm_runtime_put_noidle(mic->dev); | ||
| 274 | goto unlock; | 273 | goto unlock; |
| 275 | } | ||
| 276 | 274 | ||
| 277 | mic_set_path(mic, 1); | 275 | mic_set_path(mic, 1); |
| 278 | 276 | ||
| @@ -219,8 +219,13 @@ static int rotator_commit(struct exynos_drm_ipp *ipp, · 218 unmodified lines | |||
| 219 | { | 219 | { |
| 220 | struct rot_context *rot = | 220 | struct rot_context *rot = |
| 221 | container_of(ipp, struct rot_context, ipp); | 221 | container_of(ipp, struct rot_context, ipp); |
| 222 | int ret; | ||
| 222 | 223 | ||
| 223 | pm_runtime_get_sync(rot->dev); | 224 | ret = pm_runtime_resume_and_get(rot->dev); |
| 225 | if (ret < 0) { | ||
| 226 | dev_err(rot->dev, "failed to enable ROTATOR device.\n"); | ||
| 227 | return ret; | ||
| 228 | } | ||
| 224 | rot->task = task; | 229 | rot->task = task; |
| 225 | 230 | ||
| 226 | rotator_src_set_fmt(rot, task->src.buf.fourcc); | 231 | rotator_src_set_fmt(rot, task->src.buf.fourcc); |
| @@ -362,15 +362,17 @@ static int scaler_commit(struct exynos_drm_ipp *ipp, · 361 unmodified lines | |||
| 362 | struct drm_exynos_ipp_task_rect *src_pos = &task->src.rect; | 362 | struct drm_exynos_ipp_task_rect *src_pos = &task->src.rect; |
| 363 | struct drm_exynos_ipp_task_rect *dst_pos = &task->dst.rect; | 363 | struct drm_exynos_ipp_task_rect *dst_pos = &task->dst.rect; |
| 364 | const struct scaler_format *src_fmt, *dst_fmt; | 364 | const struct scaler_format *src_fmt, *dst_fmt; |
| 365 | int ret = 0; | ||
| 365 | 366 | ||
| 366 | src_fmt = scaler_get_format(task->src.buf.fourcc); | 367 | src_fmt = scaler_get_format(task->src.buf.fourcc); |
| 367 | dst_fmt = scaler_get_format(task->dst.buf.fourcc); | 368 | dst_fmt = scaler_get_format(task->dst.buf.fourcc); |
| 368 | 369 | ||
| 369 | pm_runtime_get_sync(scaler->dev); | 370 | ret = pm_runtime_resume_and_get(scaler->dev); |
| 370 | if (scaler_reset(scaler)) { | 371 | if (ret < 0) |
| 371 | pm_runtime_put(scaler->dev); | 372 | return ret; |
| 373 | |||
| 374 | if (scaler_reset(scaler)) | ||
| 372 | return -EIO; | 375 | return -EIO; |
| 373 | } | ||
| 374 | 376 | ||
| 375 | scaler->task = task; | 377 | scaler->task = task; |
| 376 | 378 | ||
| @@ -1483,10 +1483,16 @@ static void hdmi_set_refclk(struct hdmi_context *hdata, bool on) · 1482 unmodified lines | |||
| 1483 | /* Should be called with hdata->mutex mutex held. */ | 1483 | /* Should be called with hdata->mutex mutex held. */ |
| 1484 | static void hdmiphy_enable(struct hdmi_context *hdata) | 1484 | static void hdmiphy_enable(struct hdmi_context *hdata) |
| 1485 | { | 1485 | { |
| 1486 | int ret; | ||
| 1487 | |||
| 1486 | if (hdata->powered) | 1488 | if (hdata->powered) |
| 1487 | return; | 1489 | return; |
| 1488 | 1490 | ||
| 1489 | pm_runtime_get_sync(hdata->dev); | 1491 | ret = pm_runtime_resume_and_get(hdata->dev); |
| 1492 | if (ret < 0) { | ||
| 1493 | dev_err(hdata->dev, "failed to enable HDMIPHY device.\n"); | ||
| 1494 | return; | ||
| 1495 | } | ||
| 1490 | 1496 | ||
| 1491 | if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk)) | 1497 | if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk)) |
| 1492 | DRM_DEV_DEBUG_KMS(hdata->dev, | 1498 | DRM_DEV_DEBUG_KMS(hdata->dev, |
| @@ -992,11 +992,16 @@ static void mixer_atomic_flush(struct exynos_drm_crtc *crtc) · 991 unmodified lines | |||
| 992 | static void mixer_atomic_enable(struct exynos_drm_crtc *crtc) | 992 | static void mixer_atomic_enable(struct exynos_drm_crtc *crtc) |
| 993 | { | 993 | { |
| 994 | struct mixer_context *ctx = crtc->ctx; | 994 | struct mixer_context *ctx = crtc->ctx; |
| 995 | int ret; | ||
| 995 | 996 | ||
| 996 | if (test_bit(MXR_BIT_POWERED, &ctx->flags)) | 997 | if (test_bit(MXR_BIT_POWERED, &ctx->flags)) |
| 997 | return; | 998 | return; |
| 998 | 999 | ||
| 999 | pm_runtime_get_sync(ctx->dev); | 1000 | ret = pm_runtime_resume_and_get(ctx->dev); |
| 1001 | if (ret < 0) { | ||
| 1002 | dev_err(ctx->dev, "failed to enable MIXER device.\n"); | ||
| 1003 | return; | ||
| 1004 | } | ||
| 1000 | 1005 | ||
| 1001 | exynos_drm_pipe_clk_enable(crtc, true); | 1006 | exynos_drm_pipe_clk_enable(crtc, true); |
| 1002 | 1007 | ||