1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright 2018 Marty E. Plummer <hanetzer@startmail.com> */ 3 /* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */ 4 5 #include <linux/debugfs.h> 6 #include <linux/clk.h> 7 #include <linux/reset.h> 8 #include <linux/platform_device.h> 9 #include <linux/pm_domain.h> 10 #include <linux/pm_runtime.h> 11 #include <linux/regulator/consumer.h> 12 #include <drm/drm_drv.h> 13 #include <drm/drm_print.h> 14 15 #include "panfrost_device.h" 16 #include "panfrost_devfreq.h" 17 #include "panfrost_gem.h" 18 #include "panfrost_issues.h" 19 #include "panfrost_gpu.h" 20 #include "panfrost_job.h" 21 #include "panfrost_mmu.h" 22 #include "panfrost_perfcnt.h" 23 24 static int panfrost_reset_init(struct panfrost_device *pfdev) 25 { 26 pfdev->rstc = devm_reset_control_array_get_optional_exclusive(pfdev->base.dev); 27 if (IS_ERR(pfdev->rstc)) { 28 dev_err(pfdev->base.dev, "get reset failed %ld\n", PTR_ERR(pfdev->rstc)); 29 return PTR_ERR(pfdev->rstc); 30 } 31 32 return reset_control_deassert(pfdev->rstc); 33 } 34 35 static void panfrost_reset_fini(struct panfrost_device *pfdev) 36 { 37 reset_control_assert(pfdev->rstc); 38 } 39 40 static int panfrost_clks_enable(struct panfrost_device *pfdev, bool on_resume) 41 { 42 int err; 43 44 err = clk_prepare_enable(pfdev->clock); 45 if (err) 46 return err; 47 48 err = clk_prepare_enable(pfdev->bus_clock); 49 if (err) 50 goto disable_clock; 51 52 if (on_resume) { 53 err = clk_prepare_enable(pfdev->bus_ace_clock); 54 if (err) 55 goto disable_bus_clock; 56 } 57 58 return 0; 59 60 disable_bus_clock: 61 clk_disable_unprepare(pfdev->bus_clock); 62 disable_clock: 63 clk_disable_unprepare(pfdev->clock); 64 65 return err; 66 } 67 68 static void panfrost_clks_disable(struct panfrost_device *pfdev, bool on_suspend) 69 { 70 if (on_suspend) 71 clk_disable_unprepare(pfdev->bus_ace_clock); 72 clk_disable_unprepare(pfdev->bus_clock); 73 clk_disable_unprepare(pfdev->clock); 74 } 75 76 static int panfrost_clk_init(struct panfrost_device *pfdev) 77 { 78 unsigned long rate; 79 int err; 80 81 pfdev->clock = devm_clk_get(pfdev->base.dev, NULL); 82 if (IS_ERR(pfdev->clock)) { 83 dev_err(pfdev->base.dev, "get clock failed %ld\n", PTR_ERR(pfdev->clock)); 84 return PTR_ERR(pfdev->clock); 85 } 86 87 rate = clk_get_rate(pfdev->clock); 88 dev_info(pfdev->base.dev, "clock rate = %lu\n", rate); 89 90 err = clk_prepare(pfdev->clock); 91 if (err) 92 return err; 93 94 pfdev->bus_clock = devm_clk_get_optional(pfdev->base.dev, "bus"); 95 if (IS_ERR(pfdev->bus_clock)) { 96 err = PTR_ERR(pfdev->bus_clock); 97 dev_err(pfdev->base.dev, "get bus_clock failed %d\n", err); 98 goto unprepare_clock; 99 } 100 101 if (pfdev->bus_clock) { 102 rate = clk_get_rate(pfdev->bus_clock); 103 dev_info(pfdev->base.dev, "bus_clock rate = %lu\n", rate); 104 105 err = clk_prepare(pfdev->bus_clock); 106 if (err) 107 goto unprepare_clock; 108 } 109 110 pfdev->bus_ace_clock = devm_clk_get_optional(pfdev->base.dev, "bus_ace"); 111 if (IS_ERR(pfdev->bus_ace_clock)) { 112 err = PTR_ERR(pfdev->bus_ace_clock); 113 dev_err(pfdev->base.dev, "get bus_ace_clock failed %d\n", err); 114 goto unprepare_bus_clock; 115 } 116 117 err = clk_prepare(pfdev->bus_ace_clock); 118 if (err) 119 goto unprepare_bus_clock; 120 121 err = panfrost_clks_enable(pfdev, true); 122 if (err) 123 goto unprepare_bus_ace_clock; 124 125 return 0; 126 127 unprepare_bus_ace_clock: 128 clk_unprepare(pfdev->bus_ace_clock); 129 unprepare_bus_clock: 130 clk_unprepare(pfdev->bus_clock); 131 unprepare_clock: 132 clk_unprepare(pfdev->clock); 133 134 return err; 135 } 136 137 static void panfrost_clk_fini(struct panfrost_device *pfdev) 138 { 139 panfrost_clks_disable(pfdev, true); 140 clk_unprepare(pfdev->bus_ace_clock); 141 clk_unprepare(pfdev->bus_clock); 142 clk_unprepare(pfdev->clock); 143 } 144 145 static int panfrost_regulator_init(struct panfrost_device *pfdev) 146 { 147 int ret, i; 148 149 pfdev->regulators = devm_kcalloc(pfdev->base.dev, pfdev->comp->num_supplies, 150 sizeof(*pfdev->regulators), 151 GFP_KERNEL); 152 if (!pfdev->regulators) 153 return -ENOMEM; 154 155 for (i = 0; i < pfdev->comp->num_supplies; i++) 156 pfdev->regulators[i].supply = pfdev->comp->supply_names[i]; 157 158 ret = devm_regulator_bulk_get(pfdev->base.dev, 159 pfdev->comp->num_supplies, 160 pfdev->regulators); 161 if (ret < 0) { 162 if (ret != -EPROBE_DEFER) 163 dev_err(pfdev->base.dev, "failed to get regulators: %d\n", 164 ret); 165 return ret; 166 } 167 168 ret = regulator_bulk_enable(pfdev->comp->num_supplies, 169 pfdev->regulators); 170 if (ret < 0) { 171 dev_err(pfdev->base.dev, "failed to enable regulators: %d\n", ret); 172 return ret; 173 } 174 175 return 0; 176 } 177 178 static void panfrost_regulator_fini(struct panfrost_device *pfdev) 179 { 180 if (!pfdev->regulators) 181 return; 182 183 regulator_bulk_disable(pfdev->comp->num_supplies, pfdev->regulators); 184 } 185 186 static void panfrost_pm_domain_fini(struct panfrost_device *pfdev) 187 { 188 int i; 189 190 for (i = 0; i < ARRAY_SIZE(pfdev->pm_domain_devs); i++) { 191 if (!pfdev->pm_domain_devs[i]) 192 break; 193 194 if (pfdev->pm_domain_links[i]) 195 device_link_del(pfdev->pm_domain_links[i]); 196 197 dev_pm_domain_detach(pfdev->pm_domain_devs[i], true); 198 } 199 } 200 201 static int panfrost_pm_domain_init(struct panfrost_device *pfdev) 202 { 203 int err; 204 int i, num_domains; 205 206 num_domains = of_count_phandle_with_args(pfdev->base.dev->of_node, 207 "power-domains", 208 "#power-domain-cells"); 209 210 /* 211 * Single domain is handled by the core, and, if only a single power 212 * the power domain is requested, the property is optional. 213 */ 214 if (num_domains < 2 && pfdev->comp->num_pm_domains < 2) 215 return 0; 216 217 if (num_domains != pfdev->comp->num_pm_domains) { 218 dev_err(pfdev->base.dev, 219 "Incorrect number of power domains: %d provided, %d needed\n", 220 num_domains, pfdev->comp->num_pm_domains); 221 return -EINVAL; 222 } 223 224 if (WARN(num_domains > ARRAY_SIZE(pfdev->pm_domain_devs), 225 "Too many supplies in compatible structure.\n")) 226 return -EINVAL; 227 228 for (i = 0; i < num_domains; i++) { 229 pfdev->pm_domain_devs[i] = 230 dev_pm_domain_attach_by_name(pfdev->base.dev, 231 pfdev->comp->pm_domain_names[i]); 232 if (IS_ERR_OR_NULL(pfdev->pm_domain_devs[i])) { 233 err = PTR_ERR(pfdev->pm_domain_devs[i]) ? : -ENODATA; 234 pfdev->pm_domain_devs[i] = NULL; 235 dev_err(pfdev->base.dev, 236 "failed to get pm-domain %s(%d): %d\n", 237 pfdev->comp->pm_domain_names[i], i, err); 238 goto err; 239 } 240 241 pfdev->pm_domain_links[i] = 242 device_link_add(pfdev->base.dev, 243 pfdev->pm_domain_devs[i], DL_FLAG_PM_RUNTIME | 244 DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE); 245 if (!pfdev->pm_domain_links[i]) { 246 dev_err(pfdev->pm_domain_devs[i], 247 "adding device link failed!\n"); 248 err = -ENODEV; 249 goto err; 250 } 251 } 252 253 return 0; 254 255 err: 256 panfrost_pm_domain_fini(pfdev); 257 return err; 258 } 259 260 int panfrost_device_init(struct panfrost_device *pfdev) 261 { 262 bool device_initialised = false; 263 int err; 264 265 pfdev->comp = of_device_get_match_data(pfdev->base.dev); 266 if (!pfdev->comp) 267 return -ENODEV; 268 269 pfdev->coherent = device_get_dma_attr(pfdev->base.dev) == DEV_DMA_COHERENT; 270 271 #ifdef CONFIG_DEBUG_FS 272 mutex_init(&pfdev->debugfs.gems_lock); 273 INIT_LIST_HEAD(&pfdev->debugfs.gems_list); 274 #endif 275 276 err = panfrost_pm_domain_init(pfdev); 277 if (err) 278 return err; 279 280 err = panfrost_reset_init(pfdev); 281 if (err) { 282 dev_err(pfdev->base.dev, "reset init failed %d\n", err); 283 goto out_pm_domain; 284 } 285 286 err = panfrost_clk_init(pfdev); 287 if (err) { 288 dev_err(pfdev->base.dev, "clk init failed %d\n", err); 289 goto out_reset; 290 } 291 292 err = panfrost_devfreq_init(pfdev); 293 if (err) { 294 if (err != -EPROBE_DEFER) 295 dev_err(pfdev->base.dev, "devfreq init failed %d\n", err); 296 goto out_clk; 297 } 298 299 /* OPP will handle regulators */ 300 if (!pfdev->pfdevfreq.opp_of_table_added) { 301 err = panfrost_regulator_init(pfdev); 302 if (err) 303 goto out_devfreq; 304 } 305 306 pfdev->iomem = devm_platform_ioremap_resource(to_platform_device(pfdev->base.dev), 0); 307 if (IS_ERR(pfdev->iomem)) { 308 err = PTR_ERR(pfdev->iomem); 309 goto out_regulator; 310 } 311 312 err = panfrost_gpu_init(pfdev); 313 if (err) 314 goto out_regulator; 315 316 err = panfrost_mmu_init(pfdev); 317 if (err) 318 goto out_gpu; 319 320 err = panfrost_jm_init(pfdev); 321 if (err) 322 goto out_mmu; 323 324 err = panfrost_perfcnt_init(pfdev); 325 if (err) 326 goto out_job; 327 328 err = panfrost_gem_init(pfdev); 329 if (err) 330 goto out_perfcnt; 331 332 device_initialised = true; 333 334 /* The reason we must manually set the PM status and usage counter is 335 * we have just powered the device up but did not go through the PM 336 * runtime resume callback, so we need to update these ourselves. 337 */ 338 pm_runtime_get_noresume(pfdev->base.dev); 339 pm_runtime_set_active(pfdev->base.dev); 340 pm_runtime_mark_last_busy(pfdev->base.dev); 341 pm_runtime_enable(pfdev->base.dev); 342 pm_runtime_set_autosuspend_delay(pfdev->base.dev, 50); /* ~3 frames */ 343 pm_runtime_use_autosuspend(pfdev->base.dev); 344 345 /* 346 * Register the DRM device with the core and the connectors with 347 * sysfs 348 */ 349 err = drm_dev_register(&pfdev->base, 0); 350 if (err < 0) 351 goto err_disable_rpm; 352 353 pm_runtime_put_autosuspend(pfdev->base.dev); 354 355 return 0; 356 357 err_disable_rpm: 358 pm_runtime_dont_use_autosuspend(pfdev->base.dev); 359 pm_runtime_disable(pfdev->base.dev); 360 panfrost_gem_fini(pfdev); 361 out_perfcnt: 362 panfrost_perfcnt_fini(pfdev); 363 out_job: 364 panfrost_jm_fini(pfdev); 365 out_mmu: 366 panfrost_mmu_fini(pfdev); 367 out_gpu: 368 panfrost_gpu_fini(pfdev); 369 out_regulator: 370 panfrost_regulator_fini(pfdev); 371 out_devfreq: 372 panfrost_devfreq_fini(pfdev); 373 out_clk: 374 panfrost_clk_fini(pfdev); 375 out_reset: 376 panfrost_reset_fini(pfdev); 377 out_pm_domain: 378 panfrost_pm_domain_fini(pfdev); 379 380 if (device_initialised) { 381 pm_runtime_set_suspended(pfdev->base.dev); 382 pm_runtime_put_noidle(pfdev->base.dev); 383 } 384 385 return err; 386 } 387 388 void panfrost_device_fini(struct panfrost_device *pfdev) 389 { 390 drm_WARN_ON(&pfdev->base, pm_runtime_get_sync(pfdev->base.dev) < 0); 391 392 pm_runtime_dont_use_autosuspend(pfdev->base.dev); 393 pm_runtime_disable(pfdev->base.dev); 394 395 panfrost_gem_fini(pfdev); 396 panfrost_perfcnt_fini(pfdev); 397 panfrost_jm_fini(pfdev); 398 panfrost_mmu_fini(pfdev); 399 panfrost_gpu_fini(pfdev); 400 panfrost_devfreq_fini(pfdev); 401 panfrost_regulator_fini(pfdev); 402 panfrost_clk_fini(pfdev); 403 panfrost_reset_fini(pfdev); 404 panfrost_pm_domain_fini(pfdev); 405 406 pm_runtime_set_suspended(pfdev->base.dev); 407 pm_runtime_put_noidle(pfdev->base.dev); 408 } 409 410 #define PANFROST_EXCEPTION(id) \ 411 [DRM_PANFROST_EXCEPTION_ ## id] = { \ 412 .name = #id, \ 413 } 414 415 struct panfrost_exception_info { 416 const char *name; 417 }; 418 419 static const struct panfrost_exception_info panfrost_exception_infos[] = { 420 PANFROST_EXCEPTION(OK), 421 PANFROST_EXCEPTION(DONE), 422 PANFROST_EXCEPTION(INTERRUPTED), 423 PANFROST_EXCEPTION(STOPPED), 424 PANFROST_EXCEPTION(TERMINATED), 425 PANFROST_EXCEPTION(KABOOM), 426 PANFROST_EXCEPTION(EUREKA), 427 PANFROST_EXCEPTION(ACTIVE), 428 PANFROST_EXCEPTION(JOB_CONFIG_FAULT), 429 PANFROST_EXCEPTION(JOB_POWER_FAULT), 430 PANFROST_EXCEPTION(JOB_READ_FAULT), 431 PANFROST_EXCEPTION(JOB_WRITE_FAULT), 432 PANFROST_EXCEPTION(JOB_AFFINITY_FAULT), 433 PANFROST_EXCEPTION(JOB_BUS_FAULT), 434 PANFROST_EXCEPTION(INSTR_INVALID_PC), 435 PANFROST_EXCEPTION(INSTR_INVALID_ENC), 436 PANFROST_EXCEPTION(INSTR_TYPE_MISMATCH), 437 PANFROST_EXCEPTION(INSTR_OPERAND_FAULT), 438 PANFROST_EXCEPTION(INSTR_TLS_FAULT), 439 PANFROST_EXCEPTION(INSTR_BARRIER_FAULT), 440 PANFROST_EXCEPTION(INSTR_ALIGN_FAULT), 441 PANFROST_EXCEPTION(DATA_INVALID_FAULT), 442 PANFROST_EXCEPTION(TILE_RANGE_FAULT), 443 PANFROST_EXCEPTION(ADDR_RANGE_FAULT), 444 PANFROST_EXCEPTION(IMPRECISE_FAULT), 445 PANFROST_EXCEPTION(OOM), 446 PANFROST_EXCEPTION(OOM_AFBC), 447 PANFROST_EXCEPTION(UNKNOWN), 448 PANFROST_EXCEPTION(DELAYED_BUS_FAULT), 449 PANFROST_EXCEPTION(GPU_SHAREABILITY_FAULT), 450 PANFROST_EXCEPTION(SYS_SHAREABILITY_FAULT), 451 PANFROST_EXCEPTION(GPU_CACHEABILITY_FAULT), 452 PANFROST_EXCEPTION(TRANSLATION_FAULT_0), 453 PANFROST_EXCEPTION(TRANSLATION_FAULT_1), 454 PANFROST_EXCEPTION(TRANSLATION_FAULT_2), 455 PANFROST_EXCEPTION(TRANSLATION_FAULT_3), 456 PANFROST_EXCEPTION(TRANSLATION_FAULT_4), 457 PANFROST_EXCEPTION(TRANSLATION_FAULT_IDENTITY), 458 PANFROST_EXCEPTION(PERM_FAULT_0), 459 PANFROST_EXCEPTION(PERM_FAULT_1), 460 PANFROST_EXCEPTION(PERM_FAULT_2), 461 PANFROST_EXCEPTION(PERM_FAULT_3), 462 PANFROST_EXCEPTION(TRANSTAB_BUS_FAULT_0), 463 PANFROST_EXCEPTION(TRANSTAB_BUS_FAULT_1), 464 PANFROST_EXCEPTION(TRANSTAB_BUS_FAULT_2), 465 PANFROST_EXCEPTION(TRANSTAB_BUS_FAULT_3), 466 PANFROST_EXCEPTION(ACCESS_FLAG_0), 467 PANFROST_EXCEPTION(ACCESS_FLAG_1), 468 PANFROST_EXCEPTION(ACCESS_FLAG_2), 469 PANFROST_EXCEPTION(ACCESS_FLAG_3), 470 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_IN0), 471 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_IN1), 472 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_IN2), 473 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_IN3), 474 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_OUT0), 475 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_OUT1), 476 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_OUT2), 477 PANFROST_EXCEPTION(ADDR_SIZE_FAULT_OUT3), 478 PANFROST_EXCEPTION(MEM_ATTR_FAULT_0), 479 PANFROST_EXCEPTION(MEM_ATTR_FAULT_1), 480 PANFROST_EXCEPTION(MEM_ATTR_FAULT_2), 481 PANFROST_EXCEPTION(MEM_ATTR_FAULT_3), 482 PANFROST_EXCEPTION(MEM_ATTR_NONCACHE_0), 483 PANFROST_EXCEPTION(MEM_ATTR_NONCACHE_1), 484 PANFROST_EXCEPTION(MEM_ATTR_NONCACHE_2), 485 PANFROST_EXCEPTION(MEM_ATTR_NONCACHE_3), 486 }; 487 488 const char *panfrost_exception_name(u32 exception_code) 489 { 490 if (WARN_ON(exception_code >= ARRAY_SIZE(panfrost_exception_infos) || 491 !panfrost_exception_infos[exception_code].name)) 492 return "Unknown exception type"; 493 494 return panfrost_exception_infos[exception_code].name; 495 } 496 497 bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev, 498 u32 exception_code) 499 { 500 /* If an occlusion query write causes a bus fault on affected GPUs, 501 * future fragment jobs may hang. Reset to workaround. 502 */ 503 if (exception_code == DRM_PANFROST_EXCEPTION_JOB_BUS_FAULT) 504 return panfrost_has_hw_issue(pfdev, HW_ISSUE_TTRX_3076); 505 506 /* No other GPUs we support need a reset */ 507 return false; 508 } 509 510 void panfrost_device_reset(struct panfrost_device *pfdev, bool enable_job_int) 511 { 512 guard(rwsem_write)(&pfdev->reset.lock); 513 514 panfrost_gpu_soft_reset(pfdev); 515 516 panfrost_gpu_power_on(pfdev); 517 panfrost_mmu_reset(pfdev); 518 519 panfrost_jm_reset_interrupts(pfdev); 520 if (enable_job_int) 521 panfrost_jm_enable_interrupts(pfdev); 522 523 panfrost_perfcnt_reset(pfdev); 524 } 525 526 static int panfrost_device_runtime_resume(struct device *dev) 527 { 528 struct panfrost_device *pfdev = dev_get_drvdata(dev); 529 int ret; 530 531 if (pfdev->comp->pm_features & BIT(GPU_PM_RT)) { 532 ret = reset_control_deassert(pfdev->rstc); 533 if (ret) 534 return ret; 535 536 ret = panfrost_clks_enable(pfdev, true); 537 if (ret) { 538 reset_control_assert(pfdev->rstc); 539 return ret; 540 } 541 } 542 543 panfrost_device_reset(pfdev, true); 544 panfrost_devfreq_resume(pfdev); 545 546 return 0; 547 } 548 549 static int panfrost_device_runtime_suspend(struct device *dev) 550 { 551 struct panfrost_device *pfdev = dev_get_drvdata(dev); 552 553 if (!panfrost_jm_is_idle(pfdev)) 554 return -EBUSY; 555 556 panfrost_devfreq_suspend(pfdev); 557 panfrost_jm_suspend_irq(pfdev); 558 panfrost_mmu_suspend_irq(pfdev); 559 panfrost_gpu_suspend_irq(pfdev); 560 panfrost_gpu_power_off(pfdev); 561 562 if (pfdev->comp->pm_features & BIT(GPU_PM_RT)) { 563 panfrost_clks_disable(pfdev, true); 564 reset_control_assert(pfdev->rstc); 565 } 566 567 return 0; 568 } 569 570 static int panfrost_device_resume(struct device *dev) 571 { 572 struct panfrost_device *pfdev = dev_get_drvdata(dev); 573 int ret; 574 575 if (pfdev->comp->pm_features & BIT(GPU_PM_VREG_OFF)) { 576 unsigned long freq = pfdev->pfdevfreq.fast_rate; 577 struct dev_pm_opp *opp; 578 579 opp = dev_pm_opp_find_freq_ceil(dev, &freq); 580 if (IS_ERR(opp)) 581 return PTR_ERR(opp); 582 dev_pm_opp_set_opp(dev, opp); 583 dev_pm_opp_put(opp); 584 } 585 586 if (pfdev->comp->pm_features & BIT(GPU_PM_CLK_DIS)) { 587 ret = panfrost_clks_enable(pfdev, false); 588 if (ret) 589 goto err_clk; 590 } 591 592 ret = pm_runtime_force_resume(dev); 593 if (ret) 594 goto err_resume; 595 596 return 0; 597 598 err_resume: 599 if (pfdev->comp->pm_features & BIT(GPU_PM_CLK_DIS)) 600 panfrost_clks_disable(pfdev, false); 601 err_clk: 602 if (pfdev->comp->pm_features & BIT(GPU_PM_VREG_OFF)) 603 dev_pm_opp_set_opp(dev, NULL); 604 return ret; 605 } 606 607 static int panfrost_device_suspend(struct device *dev) 608 { 609 struct panfrost_device *pfdev = dev_get_drvdata(dev); 610 int ret; 611 612 ret = pm_runtime_force_suspend(dev); 613 if (ret) 614 return ret; 615 616 if (pfdev->comp->pm_features & BIT(GPU_PM_CLK_DIS)) 617 panfrost_clks_disable(pfdev, false); 618 619 if (pfdev->comp->pm_features & BIT(GPU_PM_VREG_OFF)) 620 dev_pm_opp_set_opp(dev, NULL); 621 622 return 0; 623 } 624 625 EXPORT_GPL_DEV_PM_OPS(panfrost_pm_ops) = { 626 RUNTIME_PM_OPS(panfrost_device_runtime_suspend, panfrost_device_runtime_resume, NULL) 627 SYSTEM_SLEEP_PM_OPS(panfrost_device_suspend, panfrost_device_resume) 628 }; 629 630 #ifdef CONFIG_DEBUG_FS 631 static int reset_get(void *data, u64 *val) 632 { 633 struct panfrost_device *pfdev = 634 container_of(data, struct panfrost_device, base); 635 636 *val = atomic_read(&pfdev->reset.pending); 637 return 0; 638 } 639 640 static int reset_set(void *data, u64 val) 641 { 642 struct panfrost_device *pfdev = 643 container_of(data, struct panfrost_device, base); 644 int ret; 645 646 if (val != 1) 647 return -EINVAL; 648 649 ret = pm_runtime_get_if_active(pfdev->base.dev); 650 if (!ret) 651 return 0; 652 653 panfrost_device_schedule_reset(pfdev); 654 flush_work(&pfdev->reset.work); 655 656 /* ret < 0 means runtime PM for the device is disabled, so we 657 * only need to return the PM reference in the opposite case 658 */ 659 if (ret > 0) 660 pm_runtime_put(pfdev->base.dev); 661 662 return 0; 663 } 664 665 DEFINE_DEBUGFS_ATTRIBUTE(panfrost_reset_debugfs_fops, 666 reset_get, reset_set, 667 "0x%08llx\n"); 668 669 static void panfrost_reset_debugfs_init(struct drm_minor *minor) 670 { 671 debugfs_create_file("reset", 0600, minor->debugfs_root, 672 minor->dev, &panfrost_reset_debugfs_fops); 673 } 674 675 void panfrost_device_debugfs_init(struct drm_minor *minor) 676 { 677 panfrost_gem_debugfs_init(minor); 678 panfrost_sched_debugfs_init(minor); 679 panfrost_reset_debugfs_init(minor); 680 } 681 #endif // CONFIG_DEBUG_FS 682