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
7 We'll need to initialize the HVS structure without a backing device to
8 create a mock we'll use for testing.
10 Split the structure initialization part into a separate function.
12 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
13 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
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(-)
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
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
35 +struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4, struct platform_device *pdev)
37 + struct drm_device *drm = &vc4->base;
38 + struct vc4_hvs *hvs;
40 + hvs = drmm_kzalloc(drm, sizeof(*hvs), GFP_KERNEL);
42 + return ERR_PTR(-ENOMEM);
47 + spin_lock_init(&hvs->mm_lock);
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.
54 + drm_mm_init(&hvs->dlist_mm,
55 + HVS_BOOTLOADER_DLIST_END,
56 + (SCALER_DLIST_SIZE >> 2) - HVS_BOOTLOADER_DLIST_END);
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.
64 + /* 48k words of 2x12-bit pixels */
65 + drm_mm_init(&hvs->lbm_mm, 0, 48 * 1024);
67 + /* 60k words of 4x12-bit pixels */
68 + drm_mm_init(&hvs->lbm_mm, 0, 60 * 1024);
75 static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
77 struct platform_device *pdev = to_platform_device(dev);
78 @@ -1020,11 +1060,9 @@ static int vc4_hvs_bind(struct device *d
82 - hvs = drmm_kzalloc(drm, sizeof(*hvs), GFP_KERNEL);
87 + hvs = __vc4_hvs_alloc(vc4, NULL);
89 + return PTR_ERR(hvs);
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
95 hvs->dlist = hvs->regs + SCALER5_DLIST_START;
97 - spin_lock_init(&hvs->mm_lock);
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.
104 - drm_mm_init(&hvs->dlist_mm,
105 - HVS_BOOTLOADER_DLIST_END,
106 - (SCALER_DLIST_SIZE >> 2) - HVS_BOOTLOADER_DLIST_END);
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.
114 - /* 48k words of 2x12-bit pixels */
115 - drm_mm_init(&hvs->lbm_mm, 0, 48 * 1024);
117 - /* 60k words of 4x12-bit pixels */
118 - drm_mm_init(&hvs->lbm_mm, 0, 60 * 1024);
120 /* Upload filter kernels. We only have the one for now, so we
121 * keep it around for the lifetime of the driver.
123 @@ -1109,8 +1124,6 @@ static int vc4_hvs_bind(struct device *d
129 reg = HVS_READ(SCALER_DISPECTRL);
130 reg &= ~SCALER_DISPECTRL_DSP2_MUX_MASK;
131 HVS_WRITE(SCALER_DISPECTRL,