hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
....@@ -3,10 +3,16 @@
33 * Copyright (C) 2015-2018 Etnaviv Project
44 */
55
6
+#include <linux/clk.h>
67 #include <linux/component.h>
8
+#include <linux/delay.h>
79 #include <linux/dma-fence.h>
8
-#include <linux/moduleparam.h>
10
+#include <linux/dma-mapping.h>
11
+#include <linux/module.h>
912 #include <linux/of_device.h>
13
+#include <linux/platform_device.h>
14
+#include <linux/pm_runtime.h>
15
+#include <linux/regulator/consumer.h>
1016 #include <linux/thermal.h>
1117
1218 #include "etnaviv_cmdbuf.h"
....@@ -36,6 +42,8 @@
3642
3743 int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
3844 {
45
+ struct etnaviv_drm_private *priv = gpu->drm->dev_private;
46
+
3947 switch (param) {
4048 case ETNAVIV_PARAM_GPU_MODEL:
4149 *value = gpu->identity.model;
....@@ -139,6 +147,13 @@
139147
140148 case ETNAVIV_PARAM_GPU_NUM_VARYINGS:
141149 *value = gpu->identity.varyings_count;
150
+ break;
151
+
152
+ case ETNAVIV_PARAM_SOFTPIN_START_ADDR:
153
+ if (priv->mmu_global->version == ETNAVIV_IOMMU_V2)
154
+ *value = ETNAVIV_SOFTPIN_START_ADDRESS;
155
+ else
156
+ *value = ~0ULL;
142157 break;
143158
144159 default:
....@@ -318,9 +333,20 @@
318333 gpu->identity.revision = etnaviv_field(chipIdentity,
319334 VIVS_HI_CHIP_IDENTITY_REVISION);
320335 } else {
336
+ u32 chipDate = gpu_read(gpu, VIVS_HI_CHIP_DATE);
321337
322338 gpu->identity.model = gpu_read(gpu, VIVS_HI_CHIP_MODEL);
323339 gpu->identity.revision = gpu_read(gpu, VIVS_HI_CHIP_REV);
340
+ gpu->identity.customer_id = gpu_read(gpu, VIVS_HI_CHIP_CUSTOMER_ID);
341
+
342
+ /*
343
+ * Reading these two registers on GC600 rev 0x19 result in a
344
+ * unhandled fault: external abort on non-linefetch
345
+ */
346
+ if (!etnaviv_is_model_rev(gpu, GC600, 0x19)) {
347
+ gpu->identity.product_id = gpu_read(gpu, VIVS_HI_CHIP_PRODUCT_ID);
348
+ gpu->identity.eco_id = gpu_read(gpu, VIVS_HI_CHIP_ECO_ID);
349
+ }
324350
325351 /*
326352 * !!!! HACK ALERT !!!!
....@@ -335,7 +361,6 @@
335361
336362 /* Another special case */
337363 if (etnaviv_is_model_rev(gpu, GC300, 0x2201)) {
338
- u32 chipDate = gpu_read(gpu, VIVS_HI_CHIP_DATE);
339364 u32 chipTime = gpu_read(gpu, VIVS_HI_CHIP_TIME);
340365
341366 if (chipDate == 0x20080814 && chipTime == 0x12051100) {
....@@ -358,11 +383,18 @@
358383 gpu->identity.model = chipModel_GC3000;
359384 gpu->identity.revision &= 0xffff;
360385 }
386
+
387
+ if (etnaviv_is_model_rev(gpu, GC1000, 0x5037) && (chipDate == 0x20120617))
388
+ gpu->identity.eco_id = 1;
389
+
390
+ if (etnaviv_is_model_rev(gpu, GC320, 0x5303) && (chipDate == 0x20140511))
391
+ gpu->identity.eco_id = 1;
361392 }
362393
363394 dev_info(gpu->dev, "model: GC%x, revision: %x\n",
364395 gpu->identity.model, gpu->identity.revision);
365396
397
+ gpu->idle_mask = ~VIVS_HI_IDLE_STATE_AXI_LP;
366398 /*
367399 * If there is a match in the HWDB, we aren't interested in the
368400 * remaining register values, as they might be wrong.
....@@ -375,6 +407,12 @@
375407 /* Disable fast clear on GC700. */
376408 if (gpu->identity.model == chipModel_GC700)
377409 gpu->identity.features &= ~chipFeatures_FAST_CLEAR;
410
+
411
+ /* These models/revisions don't have the 2D pipe bit */
412
+ if ((gpu->identity.model == chipModel_GC500 &&
413
+ gpu->identity.revision <= 2) ||
414
+ gpu->identity.model == chipModel_GC300)
415
+ gpu->identity.features |= chipFeatures_PIPE_2D;
378416
379417 if ((gpu->identity.model == chipModel_GC500 &&
380418 gpu->identity.revision < 2) ||
....@@ -409,8 +447,9 @@
409447 gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_5);
410448 }
411449
412
- /* GC600 idle register reports zero bits where modules aren't present */
413
- if (gpu->identity.model == chipModel_GC600) {
450
+ /* GC600/300 idle register reports zero bits where modules aren't present */
451
+ if (gpu->identity.model == chipModel_GC600 ||
452
+ gpu->identity.model == chipModel_GC300)
414453 gpu->idle_mask = VIVS_HI_IDLE_STATE_TX |
415454 VIVS_HI_IDLE_STATE_RA |
416455 VIVS_HI_IDLE_STATE_SE |
....@@ -419,9 +458,6 @@
419458 VIVS_HI_IDLE_STATE_PE |
420459 VIVS_HI_IDLE_STATE_DE |
421460 VIVS_HI_IDLE_STATE_FE;
422
- } else {
423
- gpu->idle_mask = ~VIVS_HI_IDLE_STATE_AXI_LP;
424
- }
425461
426462 etnaviv_hw_specs(gpu);
427463 }
....@@ -493,7 +529,7 @@
493529 /* read idle register. */
494530 idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
495531
496
- /* try reseting again if FE it not idle */
532
+ /* try resetting again if FE is not idle */
497533 if ((idle & VIVS_HI_IDLE_STATE_FE) == 0) {
498534 dev_dbg(gpu->dev, "FE is not idle\n");
499535 continue;
....@@ -531,6 +567,12 @@
531567
532568 /* We rely on the GPU running, so program the clock */
533569 etnaviv_gpu_update_clock(gpu);
570
+
571
+ gpu->fe_running = false;
572
+ gpu->exec_state = -1;
573
+ if (gpu->mmu_context)
574
+ etnaviv_iommu_context_put(gpu->mmu_context);
575
+ gpu->mmu_context = NULL;
534576
535577 return 0;
536578 }
....@@ -594,6 +636,25 @@
594636 VIVS_MMUv2_SEC_COMMAND_CONTROL_ENABLE |
595637 VIVS_MMUv2_SEC_COMMAND_CONTROL_PREFETCH(prefetch));
596638 }
639
+
640
+ gpu->fe_running = true;
641
+}
642
+
643
+static void etnaviv_gpu_start_fe_idleloop(struct etnaviv_gpu *gpu,
644
+ struct etnaviv_iommu_context *context)
645
+{
646
+ u16 prefetch;
647
+ u32 address;
648
+
649
+ /* setup the MMU */
650
+ etnaviv_iommu_restore(gpu, context);
651
+
652
+ /* Start command processor */
653
+ prefetch = etnaviv_buffer_init(gpu);
654
+ address = etnaviv_cmdbuf_get_va(&gpu->buffer,
655
+ &gpu->mmu_context->cmdbuf_mapping);
656
+
657
+ etnaviv_gpu_start_fe(gpu, address, prefetch);
597658 }
598659
599660 static void etnaviv_gpu_setup_pulse_eater(struct etnaviv_gpu *gpu)
....@@ -629,8 +690,6 @@
629690
630691 static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu)
631692 {
632
- u16 prefetch;
633
-
634693 if ((etnaviv_is_model_rev(gpu, GC320, 0x5007) ||
635694 etnaviv_is_model_rev(gpu, GC320, 0x5220)) &&
636695 gpu_read(gpu, VIVS_HI_CHIP_TIME) != 0x2062400) {
....@@ -676,19 +735,12 @@
676735 /* setup the pulse eater */
677736 etnaviv_gpu_setup_pulse_eater(gpu);
678737
679
- /* setup the MMU */
680
- etnaviv_iommu_restore(gpu);
681
-
682
- /* Start command processor */
683
- prefetch = etnaviv_buffer_init(gpu);
684
-
685738 gpu_write(gpu, VIVS_HI_INTR_ENBL, ~0U);
686
- etnaviv_gpu_start_fe(gpu, etnaviv_cmdbuf_get_va(&gpu->buffer),
687
- prefetch);
688739 }
689740
690741 int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
691742 {
743
+ struct etnaviv_drm_private *priv = gpu->drm->dev_private;
692744 int ret, i;
693745
694746 ret = pm_runtime_get_sync(gpu->dev);
....@@ -714,28 +766,6 @@
714766 }
715767
716768 /*
717
- * Set the GPU linear window to be at the end of the DMA window, where
718
- * the CMA area is likely to reside. This ensures that we are able to
719
- * map the command buffers while having the linear window overlap as
720
- * much RAM as possible, so we can optimize mappings for other buffers.
721
- *
722
- * For 3D cores only do this if MC2.0 is present, as with MC1.0 it leads
723
- * to different views of the memory on the individual engines.
724
- */
725
- if (!(gpu->identity.features & chipFeatures_PIPE_3D) ||
726
- (gpu->identity.minor_features0 & chipMinorFeatures0_MC20)) {
727
- u32 dma_mask = (u32)dma_get_required_mask(gpu->dev);
728
- if (dma_mask < PHYS_OFFSET + SZ_2G)
729
- gpu->memory_base = PHYS_OFFSET;
730
- else
731
- gpu->memory_base = dma_mask - SZ_2G + 1;
732
- } else if (PHYS_OFFSET >= SZ_2G) {
733
- dev_info(gpu->dev, "Need to move linear window on MC1.0, disabling TS\n");
734
- gpu->memory_base = PHYS_OFFSET;
735
- gpu->identity.features &= ~chipFeatures_FAST_CLEAR;
736
- }
737
-
738
- /*
739769 * On cores with security features supported, we claim control over the
740770 * security states.
741771 */
....@@ -749,34 +779,46 @@
749779 goto fail;
750780 }
751781
752
- gpu->mmu = etnaviv_iommu_new(gpu);
753
- if (IS_ERR(gpu->mmu)) {
754
- dev_err(gpu->dev, "Failed to instantiate GPU IOMMU\n");
755
- ret = PTR_ERR(gpu->mmu);
782
+ ret = etnaviv_iommu_global_init(gpu);
783
+ if (ret)
756784 goto fail;
785
+
786
+ /*
787
+ * Set the GPU linear window to be at the end of the DMA window, where
788
+ * the CMA area is likely to reside. This ensures that we are able to
789
+ * map the command buffers while having the linear window overlap as
790
+ * much RAM as possible, so we can optimize mappings for other buffers.
791
+ *
792
+ * For 3D cores only do this if MC2.0 is present, as with MC1.0 it leads
793
+ * to different views of the memory on the individual engines.
794
+ */
795
+ if (!(gpu->identity.features & chipFeatures_PIPE_3D) ||
796
+ (gpu->identity.minor_features0 & chipMinorFeatures0_MC20)) {
797
+ u32 dma_mask = (u32)dma_get_required_mask(gpu->dev);
798
+ if (dma_mask < PHYS_OFFSET + SZ_2G)
799
+ priv->mmu_global->memory_base = PHYS_OFFSET;
800
+ else
801
+ priv->mmu_global->memory_base = dma_mask - SZ_2G + 1;
802
+ } else if (PHYS_OFFSET >= SZ_2G) {
803
+ dev_info(gpu->dev, "Need to move linear window on MC1.0, disabling TS\n");
804
+ priv->mmu_global->memory_base = PHYS_OFFSET;
805
+ gpu->identity.features &= ~chipFeatures_FAST_CLEAR;
757806 }
758807
759
- gpu->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(gpu);
760
- if (IS_ERR(gpu->cmdbuf_suballoc)) {
761
- dev_err(gpu->dev, "Failed to create cmdbuf suballocator\n");
762
- ret = PTR_ERR(gpu->cmdbuf_suballoc);
763
- goto destroy_iommu;
764
- }
808
+ /*
809
+ * If the GPU is part of a system with DMA addressing limitations,
810
+ * request pages for our SHM backend buffers from the DMA32 zone to
811
+ * hopefully avoid performance killing SWIOTLB bounce buffering.
812
+ */
813
+ if (dma_addressing_limited(gpu->dev))
814
+ priv->shm_gfp_mask |= GFP_DMA32;
765815
766816 /* Create buffer: */
767
- ret = etnaviv_cmdbuf_init(gpu->cmdbuf_suballoc, &gpu->buffer,
817
+ ret = etnaviv_cmdbuf_init(priv->cmdbuf_suballoc, &gpu->buffer,
768818 PAGE_SIZE);
769819 if (ret) {
770820 dev_err(gpu->dev, "could not create command buffer\n");
771
- goto destroy_suballoc;
772
- }
773
-
774
- if (gpu->mmu->version == ETNAVIV_IOMMU_V1 &&
775
- etnaviv_cmdbuf_get_va(&gpu->buffer) > 0x80000000) {
776
- ret = -EINVAL;
777
- dev_err(gpu->dev,
778
- "command buffer outside valid memory window\n");
779
- goto free_buffer;
821
+ goto fail;
780822 }
781823
782824 /* Setup event management */
....@@ -789,23 +831,15 @@
789831 /* Now program the hardware */
790832 mutex_lock(&gpu->lock);
791833 etnaviv_gpu_hw_init(gpu);
792
- gpu->exec_state = -1;
793834 mutex_unlock(&gpu->lock);
794835
795836 pm_runtime_mark_last_busy(gpu->dev);
796837 pm_runtime_put_autosuspend(gpu->dev);
797838
839
+ gpu->initialized = true;
840
+
798841 return 0;
799842
800
-free_buffer:
801
- etnaviv_cmdbuf_free(&gpu->buffer);
802
- gpu->buffer.suballoc = NULL;
803
-destroy_suballoc:
804
- etnaviv_cmdbuf_suballoc_destroy(gpu->cmdbuf_suballoc);
805
- gpu->cmdbuf_suballoc = NULL;
806
-destroy_iommu:
807
- etnaviv_iommu_destroy(gpu->mmu);
808
- gpu->mmu = NULL;
809843 fail:
810844 pm_runtime_mark_last_busy(gpu->dev);
811845 pm_put:
....@@ -857,6 +891,13 @@
857891 idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
858892
859893 verify_dma(gpu, &debug);
894
+
895
+ seq_puts(m, "\tidentity\n");
896
+ seq_printf(m, "\t model: 0x%x\n", gpu->identity.model);
897
+ seq_printf(m, "\t revision: 0x%x\n", gpu->identity.revision);
898
+ seq_printf(m, "\t product_id: 0x%x\n", gpu->identity.product_id);
899
+ seq_printf(m, "\t customer_id: 0x%x\n", gpu->identity.customer_id);
900
+ seq_printf(m, "\t eco_id: 0x%x\n", gpu->identity.eco_id);
860901
861902 seq_puts(m, "\tfeatures\n");
862903 seq_printf(m, "\t major_features: 0x%08x\n",
....@@ -937,6 +978,20 @@
937978 seq_puts(m, "\t FP is not idle\n");
938979 if ((idle & VIVS_HI_IDLE_STATE_TS) == 0)
939980 seq_puts(m, "\t TS is not idle\n");
981
+ if ((idle & VIVS_HI_IDLE_STATE_BL) == 0)
982
+ seq_puts(m, "\t BL is not idle\n");
983
+ if ((idle & VIVS_HI_IDLE_STATE_ASYNCFE) == 0)
984
+ seq_puts(m, "\t ASYNCFE is not idle\n");
985
+ if ((idle & VIVS_HI_IDLE_STATE_MC) == 0)
986
+ seq_puts(m, "\t MC is not idle\n");
987
+ if ((idle & VIVS_HI_IDLE_STATE_PPA) == 0)
988
+ seq_puts(m, "\t PPA is not idle\n");
989
+ if ((idle & VIVS_HI_IDLE_STATE_WD) == 0)
990
+ seq_puts(m, "\t WD is not idle\n");
991
+ if ((idle & VIVS_HI_IDLE_STATE_NN) == 0)
992
+ seq_puts(m, "\t NN is not idle\n");
993
+ if ((idle & VIVS_HI_IDLE_STATE_TP) == 0)
994
+ seq_puts(m, "\t TP is not idle\n");
940995 if (idle & VIVS_HI_IDLE_STATE_AXI_LP)
941996 seq_puts(m, "\t AXI low power mode\n");
942997
....@@ -981,7 +1036,6 @@
9811036
9821037 void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
9831038 {
984
- unsigned long flags;
9851039 unsigned int i = 0;
9861040
9871041 dev_err(gpu->dev, "recover hung GPU!\n");
....@@ -994,16 +1048,13 @@
9941048 etnaviv_hw_reset(gpu);
9951049
9961050 /* complete all events, the GPU won't do it after the reset */
997
- spin_lock_irqsave(&gpu->event_spinlock, flags);
1051
+ spin_lock(&gpu->event_spinlock);
9981052 for_each_set_bit_from(i, gpu->event_bitmap, ETNA_NR_EVENTS)
9991053 complete(&gpu->event_free);
10001054 bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS);
1001
- spin_unlock_irqrestore(&gpu->event_spinlock, flags);
1002
- gpu->completed_fence = gpu->active_fence;
1055
+ spin_unlock(&gpu->event_spinlock);
10031056
10041057 etnaviv_gpu_hw_init(gpu);
1005
- gpu->lastctx = NULL;
1006
- gpu->exec_state = -1;
10071058
10081059 mutex_unlock(&gpu->lock);
10091060 pm_runtime_mark_last_busy(gpu->dev);
....@@ -1038,7 +1089,7 @@
10381089 {
10391090 struct etnaviv_fence *f = to_etnaviv_fence(fence);
10401091
1041
- return fence_completed(f->gpu, f->base.seqno);
1092
+ return (s32)(f->gpu->completed_fence - f->base.seqno) >= 0;
10421093 }
10431094
10441095 static void etnaviv_fence_release(struct dma_fence *fence)
....@@ -1077,6 +1128,12 @@
10771128 return &f->base;
10781129 }
10791130
1131
+/* returns true if fence a comes after fence b */
1132
+static inline bool fence_after(u32 a, u32 b)
1133
+{
1134
+ return (s32)(a - b) > 0;
1135
+}
1136
+
10801137 /*
10811138 * event management:
10821139 */
....@@ -1084,7 +1141,7 @@
10841141 static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
10851142 unsigned int *events)
10861143 {
1087
- unsigned long flags, timeout = msecs_to_jiffies(10 * 10000);
1144
+ unsigned long timeout = msecs_to_jiffies(10 * 10000);
10881145 unsigned i, acquired = 0;
10891146
10901147 for (i = 0; i < nr_events; i++) {
....@@ -1101,7 +1158,7 @@
11011158 timeout = ret;
11021159 }
11031160
1104
- spin_lock_irqsave(&gpu->event_spinlock, flags);
1161
+ spin_lock(&gpu->event_spinlock);
11051162
11061163 for (i = 0; i < nr_events; i++) {
11071164 int event = find_first_zero_bit(gpu->event_bitmap, ETNA_NR_EVENTS);
....@@ -1111,7 +1168,7 @@
11111168 set_bit(event, gpu->event_bitmap);
11121169 }
11131170
1114
- spin_unlock_irqrestore(&gpu->event_spinlock, flags);
1171
+ spin_unlock(&gpu->event_spinlock);
11151172
11161173 return 0;
11171174
....@@ -1124,18 +1181,11 @@
11241181
11251182 static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
11261183 {
1127
- unsigned long flags;
1128
-
1129
- spin_lock_irqsave(&gpu->event_spinlock, flags);
1130
-
11311184 if (!test_bit(event, gpu->event_bitmap)) {
11321185 dev_warn(gpu->dev, "event %u is already marked as free",
11331186 event);
1134
- spin_unlock_irqrestore(&gpu->event_spinlock, flags);
11351187 } else {
11361188 clear_bit(event, gpu->event_bitmap);
1137
- spin_unlock_irqrestore(&gpu->event_spinlock, flags);
1138
-
11391189 complete(&gpu->event_free);
11401190 }
11411191 }
....@@ -1144,7 +1194,7 @@
11441194 * Cmdstream submission/retirement:
11451195 */
11461196 int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
1147
- u32 id, struct timespec *timeout)
1197
+ u32 id, struct drm_etnaviv_timespec *timeout)
11481198 {
11491199 struct dma_fence *fence;
11501200 int ret;
....@@ -1191,7 +1241,8 @@
11911241 * that lock in this function while waiting.
11921242 */
11931243 int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
1194
- struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout)
1244
+ struct etnaviv_gem_object *etnaviv_obj,
1245
+ struct drm_etnaviv_timespec *timeout)
11951246 {
11961247 unsigned long remaining;
11971248 long ret;
....@@ -1315,7 +1366,12 @@
13151366 goto out_unlock;
13161367 }
13171368
1318
- gpu->active_fence = gpu_fence->seqno;
1369
+ if (!gpu->fe_running)
1370
+ etnaviv_gpu_start_fe_idleloop(gpu, submit->mmu_context);
1371
+
1372
+ if (submit->prev_mmu_context)
1373
+ etnaviv_iommu_context_put(submit->prev_mmu_context);
1374
+ submit->prev_mmu_context = etnaviv_iommu_context_get(gpu->mmu_context);
13191375
13201376 if (submit->nr_pmrs) {
13211377 gpu->event[event[1]].sync_point = &sync_point_perfmon_sample_pre;
....@@ -1326,8 +1382,8 @@
13261382
13271383 gpu->event[event[0]].fence = gpu_fence;
13281384 submit->cmdbuf.user_size = submit->cmdbuf.size - 8;
1329
- etnaviv_buffer_queue(gpu, submit->exec_state, event[0],
1330
- &submit->cmdbuf);
1385
+ etnaviv_buffer_queue(gpu, submit->exec_state, submit->mmu_context,
1386
+ event[0], &submit->cmdbuf);
13311387
13321388 if (submit->nr_pmrs) {
13331389 gpu->event[event[2]].sync_point = &sync_point_perfmon_sample_post;
....@@ -1456,55 +1512,40 @@
14561512 {
14571513 int ret;
14581514
1459
- if (gpu->clk_reg) {
1460
- ret = clk_prepare_enable(gpu->clk_reg);
1461
- if (ret)
1462
- return ret;
1463
- }
1515
+ ret = clk_prepare_enable(gpu->clk_reg);
1516
+ if (ret)
1517
+ return ret;
14641518
1465
- if (gpu->clk_bus) {
1466
- ret = clk_prepare_enable(gpu->clk_bus);
1467
- if (ret)
1468
- goto disable_clk_reg;
1469
- }
1519
+ ret = clk_prepare_enable(gpu->clk_bus);
1520
+ if (ret)
1521
+ goto disable_clk_reg;
14701522
1471
- if (gpu->clk_core) {
1472
- ret = clk_prepare_enable(gpu->clk_core);
1473
- if (ret)
1474
- goto disable_clk_bus;
1475
- }
1523
+ ret = clk_prepare_enable(gpu->clk_core);
1524
+ if (ret)
1525
+ goto disable_clk_bus;
14761526
1477
- if (gpu->clk_shader) {
1478
- ret = clk_prepare_enable(gpu->clk_shader);
1479
- if (ret)
1480
- goto disable_clk_core;
1481
- }
1527
+ ret = clk_prepare_enable(gpu->clk_shader);
1528
+ if (ret)
1529
+ goto disable_clk_core;
14821530
14831531 return 0;
14841532
14851533 disable_clk_core:
1486
- if (gpu->clk_core)
1487
- clk_disable_unprepare(gpu->clk_core);
1534
+ clk_disable_unprepare(gpu->clk_core);
14881535 disable_clk_bus:
1489
- if (gpu->clk_bus)
1490
- clk_disable_unprepare(gpu->clk_bus);
1536
+ clk_disable_unprepare(gpu->clk_bus);
14911537 disable_clk_reg:
1492
- if (gpu->clk_reg)
1493
- clk_disable_unprepare(gpu->clk_reg);
1538
+ clk_disable_unprepare(gpu->clk_reg);
14941539
14951540 return ret;
14961541 }
14971542
14981543 static int etnaviv_gpu_clk_disable(struct etnaviv_gpu *gpu)
14991544 {
1500
- if (gpu->clk_shader)
1501
- clk_disable_unprepare(gpu->clk_shader);
1502
- if (gpu->clk_core)
1503
- clk_disable_unprepare(gpu->clk_core);
1504
- if (gpu->clk_bus)
1505
- clk_disable_unprepare(gpu->clk_bus);
1506
- if (gpu->clk_reg)
1507
- clk_disable_unprepare(gpu->clk_reg);
1545
+ clk_disable_unprepare(gpu->clk_shader);
1546
+ clk_disable_unprepare(gpu->clk_core);
1547
+ clk_disable_unprepare(gpu->clk_bus);
1548
+ clk_disable_unprepare(gpu->clk_reg);
15081549
15091550 return 0;
15101551 }
....@@ -1532,7 +1573,7 @@
15321573
15331574 static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu)
15341575 {
1535
- if (gpu->buffer.suballoc) {
1576
+ if (gpu->initialized && gpu->fe_running) {
15361577 /* Replace the last WAIT with END */
15371578 mutex_lock(&gpu->lock);
15381579 etnaviv_buffer_end(gpu);
....@@ -1544,7 +1585,11 @@
15441585 * we fail, just warn and continue.
15451586 */
15461587 etnaviv_gpu_wait_idle(gpu, 100);
1588
+
1589
+ gpu->fe_running = false;
15471590 }
1591
+
1592
+ gpu->exec_state = -1;
15481593
15491594 return etnaviv_gpu_clk_disable(gpu);
15501595 }
....@@ -1560,9 +1605,6 @@
15601605
15611606 etnaviv_gpu_update_clock(gpu);
15621607 etnaviv_gpu_hw_init(gpu);
1563
-
1564
- gpu->lastctx = NULL;
1565
- gpu->exec_state = -1;
15661608
15671609 mutex_unlock(&gpu->lock);
15681610
....@@ -1692,17 +1734,13 @@
16921734 etnaviv_gpu_hw_suspend(gpu);
16931735 #endif
16941736
1695
- if (gpu->buffer.suballoc)
1737
+ if (gpu->mmu_context)
1738
+ etnaviv_iommu_context_put(gpu->mmu_context);
1739
+
1740
+ if (gpu->initialized) {
16961741 etnaviv_cmdbuf_free(&gpu->buffer);
1697
-
1698
- if (gpu->cmdbuf_suballoc) {
1699
- etnaviv_cmdbuf_suballoc_destroy(gpu->cmdbuf_suballoc);
1700
- gpu->cmdbuf_suballoc = NULL;
1701
- }
1702
-
1703
- if (gpu->mmu) {
1704
- etnaviv_iommu_destroy(gpu->mmu);
1705
- gpu->mmu = NULL;
1742
+ etnaviv_iommu_global_fini(gpu);
1743
+ gpu->initialized = false;
17061744 }
17071745
17081746 gpu->drm = NULL;
....@@ -1730,7 +1768,6 @@
17301768 {
17311769 struct device *dev = &pdev->dev;
17321770 struct etnaviv_gpu *gpu;
1733
- struct resource *res;
17341771 int err;
17351772
17361773 gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL);
....@@ -1742,8 +1779,7 @@
17421779 mutex_init(&gpu->fence_lock);
17431780
17441781 /* Map registers: */
1745
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1746
- gpu->mmio = devm_ioremap_resource(&pdev->dev, res);
1782
+ gpu->mmio = devm_platform_ioremap_resource(pdev, 0);
17471783 if (IS_ERR(gpu->mmio))
17481784 return PTR_ERR(gpu->mmio);
17491785
....@@ -1762,26 +1798,26 @@
17621798 }
17631799
17641800 /* Get Clocks: */
1765
- gpu->clk_reg = devm_clk_get(&pdev->dev, "reg");
1801
+ gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg");
17661802 DBG("clk_reg: %p", gpu->clk_reg);
17671803 if (IS_ERR(gpu->clk_reg))
1768
- gpu->clk_reg = NULL;
1804
+ return PTR_ERR(gpu->clk_reg);
17691805
1770
- gpu->clk_bus = devm_clk_get(&pdev->dev, "bus");
1806
+ gpu->clk_bus = devm_clk_get_optional(&pdev->dev, "bus");
17711807 DBG("clk_bus: %p", gpu->clk_bus);
17721808 if (IS_ERR(gpu->clk_bus))
1773
- gpu->clk_bus = NULL;
1809
+ return PTR_ERR(gpu->clk_bus);
17741810
17751811 gpu->clk_core = devm_clk_get(&pdev->dev, "core");
17761812 DBG("clk_core: %p", gpu->clk_core);
17771813 if (IS_ERR(gpu->clk_core))
1778
- gpu->clk_core = NULL;
1814
+ return PTR_ERR(gpu->clk_core);
17791815 gpu->base_rate_core = clk_get_rate(gpu->clk_core);
17801816
1781
- gpu->clk_shader = devm_clk_get(&pdev->dev, "shader");
1817
+ gpu->clk_shader = devm_clk_get_optional(&pdev->dev, "shader");
17821818 DBG("clk_shader: %p", gpu->clk_shader);
17831819 if (IS_ERR(gpu->clk_shader))
1784
- gpu->clk_shader = NULL;
1820
+ return PTR_ERR(gpu->clk_shader);
17851821 gpu->base_rate_shader = clk_get_rate(gpu->clk_shader);
17861822
17871823 /* TODO: figure out max mapped size */
....@@ -1818,15 +1854,19 @@
18181854 struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
18191855 u32 idle, mask;
18201856
1821
- /* If we have outstanding fences, we're not idle */
1822
- if (gpu->completed_fence != gpu->active_fence)
1857
+ /* If there are any jobs in the HW queue, we're not idle */
1858
+ if (atomic_read(&gpu->sched.hw_rq_count))
18231859 return -EBUSY;
18241860
1825
- /* Check whether the hardware (except FE) is idle */
1826
- mask = gpu->idle_mask & ~VIVS_HI_IDLE_STATE_FE;
1861
+ /* Check whether the hardware (except FE and MC) is idle */
1862
+ mask = gpu->idle_mask & ~(VIVS_HI_IDLE_STATE_FE |
1863
+ VIVS_HI_IDLE_STATE_MC);
18271864 idle = gpu_read(gpu, VIVS_HI_IDLE_STATE) & mask;
1828
- if (idle != mask)
1865
+ if (idle != mask) {
1866
+ dev_warn_ratelimited(dev, "GPU not yet idle, mask: 0x%08x\n",
1867
+ idle);
18291868 return -EBUSY;
1869
+ }
18301870
18311871 return etnaviv_gpu_hw_suspend(gpu);
18321872 }
....@@ -1841,7 +1881,7 @@
18411881 return ret;
18421882
18431883 /* Re-initialise the basic hardware state */
1844
- if (gpu->drm && gpu->buffer.suballoc) {
1884
+ if (gpu->drm && gpu->initialized) {
18451885 ret = etnaviv_gpu_hw_resume(gpu);
18461886 if (ret) {
18471887 etnaviv_gpu_clk_disable(gpu);