033fd9843a6bc5ffeb4f6bb3f520c9037d734219
[openwrt/staging/pepe2k.git] /
1 From e75de2a5fd951a0244b2000dc2ad3922b0ab0f5e Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 23 Nov 2022 16:00:53 +0100
4 Subject: [PATCH] drm/vc4: hvs: Provide a function to initialize the
5 HVS structure
6
7 We'll need to initialize the HVS structure without a backing device to
8 create a mock we'll use for testing.
9
10 Split the structure initialization part into a separate function.
11
12 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
13 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
14 ---
15 drivers/gpu/drm/vc4/vc4_drv.h | 1 +
16 drivers/gpu/drm/vc4/vc4_hvs.c | 73 +++++++++++++++++++++--------------
17 2 files changed, 44 insertions(+), 30 deletions(-)
18
19 --- a/drivers/gpu/drm/vc4/vc4_drv.h
20 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
21 @@ -1036,6 +1036,7 @@ void vc4_irq_reset(struct drm_device *de
22
23 /* vc4_hvs.c */
24 extern struct platform_driver vc4_hvs_driver;
25 +struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4, struct platform_device *pdev);
26 void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output);
27 int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output);
28 u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo);
29 --- a/drivers/gpu/drm/vc4/vc4_hvs.c
30 +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
31 @@ -1010,6 +1010,46 @@ int vc4_hvs_debugfs_init(struct drm_mino
32 return 0;
33 }
34
35 +struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4, struct platform_device *pdev)
36 +{
37 + struct drm_device *drm = &vc4->base;
38 + struct vc4_hvs *hvs;
39 +
40 + hvs = drmm_kzalloc(drm, sizeof(*hvs), GFP_KERNEL);
41 + if (!hvs)
42 + return ERR_PTR(-ENOMEM);
43 +
44 + hvs->vc4 = vc4;
45 + hvs->pdev = pdev;
46 +
47 + spin_lock_init(&hvs->mm_lock);
48 +
49 + /* Set up the HVS display list memory manager. We never
50 + * overwrite the setup from the bootloader (just 128b out of
51 + * our 16K), since we don't want to scramble the screen when
52 + * transitioning from the firmware's boot setup to runtime.
53 + */
54 + drm_mm_init(&hvs->dlist_mm,
55 + HVS_BOOTLOADER_DLIST_END,
56 + (SCALER_DLIST_SIZE >> 2) - HVS_BOOTLOADER_DLIST_END);
57 +
58 + /* Set up the HVS LBM memory manager. We could have some more
59 + * complicated data structure that allowed reuse of LBM areas
60 + * between planes when they don't overlap on the screen, but
61 + * for now we just allocate globally.
62 + */
63 + if (!vc4->is_vc5)
64 + /* 48k words of 2x12-bit pixels */
65 + drm_mm_init(&hvs->lbm_mm, 0, 48 * 1024);
66 + else
67 + /* 60k words of 4x12-bit pixels */
68 + drm_mm_init(&hvs->lbm_mm, 0, 60 * 1024);
69 +
70 + vc4->hvs = hvs;
71 +
72 + return hvs;
73 +}
74 +
75 static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
76 {
77 struct platform_device *pdev = to_platform_device(dev);
78 @@ -1020,11 +1060,9 @@ static int vc4_hvs_bind(struct device *d
79 u32 dispctrl;
80 u32 reg, top;
81
82 - hvs = drmm_kzalloc(drm, sizeof(*hvs), GFP_KERNEL);
83 - if (!hvs)
84 - return -ENOMEM;
85 - hvs->vc4 = vc4;
86 - hvs->pdev = pdev;
87 + hvs = __vc4_hvs_alloc(vc4, NULL);
88 + if (IS_ERR(hvs))
89 + return PTR_ERR(hvs);
90
91 hvs->regs = vc4_ioremap_regs(pdev, 0);
92 if (IS_ERR(hvs->regs))
93 @@ -1077,29 +1115,6 @@ static int vc4_hvs_bind(struct device *d
94 else
95 hvs->dlist = hvs->regs + SCALER5_DLIST_START;
96
97 - spin_lock_init(&hvs->mm_lock);
98 -
99 - /* Set up the HVS display list memory manager. We never
100 - * overwrite the setup from the bootloader (just 128b out of
101 - * our 16K), since we don't want to scramble the screen when
102 - * transitioning from the firmware's boot setup to runtime.
103 - */
104 - drm_mm_init(&hvs->dlist_mm,
105 - HVS_BOOTLOADER_DLIST_END,
106 - (SCALER_DLIST_SIZE >> 2) - HVS_BOOTLOADER_DLIST_END);
107 -
108 - /* Set up the HVS LBM memory manager. We could have some more
109 - * complicated data structure that allowed reuse of LBM areas
110 - * between planes when they don't overlap on the screen, but
111 - * for now we just allocate globally.
112 - */
113 - if (!vc4->is_vc5)
114 - /* 48k words of 2x12-bit pixels */
115 - drm_mm_init(&hvs->lbm_mm, 0, 48 * 1024);
116 - else
117 - /* 60k words of 4x12-bit pixels */
118 - drm_mm_init(&hvs->lbm_mm, 0, 60 * 1024);
119 -
120 /* Upload filter kernels. We only have the one for now, so we
121 * keep it around for the lifetime of the driver.
122 */
123 @@ -1109,8 +1124,6 @@ static int vc4_hvs_bind(struct device *d
124 if (ret)
125 return ret;
126
127 - vc4->hvs = hvs;
128 -
129 reg = HVS_READ(SCALER_DISPECTRL);
130 reg &= ~SCALER_DISPECTRL_DSP2_MUX_MASK;
131 HVS_WRITE(SCALER_DISPECTRL,