1 From 8a64687192f4bbe09c9c365fdcff8207fe2004d4 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Tue, 26 Mar 2019 14:43:06 +0000
4 Subject: [PATCH 592/773] gpu: vc4-fkms: Switch to the newer mailbox frame
7 The old mailbox FB API was ideally deprecated but still used by
9 Update to the newer API.
11 NB This needs current firmware that accepts ARM allocated buffers
12 through the newer API.
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
16 drivers/gpu/drm/vc4/vc4_firmware_kms.c | 109 +++++++++++----------
17 include/soc/bcm2835/raspberrypi-firmware.h | 10 ++
18 2 files changed, 67 insertions(+), 52 deletions(-)
20 --- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
21 +++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
24 #include <soc/bcm2835/raspberrypi-firmware.h>
26 +struct fb_alloc_tags {
27 + struct rpi_firmware_property_tag_header tag1;
29 + struct rpi_firmware_property_tag_header tag2;
30 + u32 xres_virtual, yres_virtual;
31 + struct rpi_firmware_property_tag_header tag3;
33 + struct rpi_firmware_property_tag_header tag4;
34 + u32 xoffset, yoffset;
35 + struct rpi_firmware_property_tag_header tag5;
36 + u32 base, screen_size;
37 + struct rpi_firmware_property_tag_header tag6;
39 + struct rpi_firmware_property_tag_header tag7;
41 + struct rpi_firmware_property_tag_header tag8;
45 /* The firmware delivers a vblank interrupt to us through the SMI
46 * hardware, which has only this one register.
48 @@ -121,45 +140,39 @@ static void vc4_primary_plane_atomic_upd
49 struct drm_plane_state *old_state)
51 struct vc4_dev *vc4 = to_vc4_dev(plane->dev);
52 - struct vc4_fkms_plane *vc4_plane = to_vc4_fkms_plane(plane);
53 struct drm_plane_state *state = plane->state;
54 struct drm_framebuffer *fb = state->fb;
55 struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
56 - volatile struct fbinfo_s *fbinfo = vc4_plane->fbinfo;
57 + u32 format = fb->format->format;
58 + struct fb_alloc_tags fbinfo = {
59 + .tag1 = { RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT,
61 + .xres = state->crtc_w,
62 + .yres = state->crtc_h,
63 + .tag2 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT,
65 + .xres_virtual = state->crtc_w,
66 + .yres_virtual = state->crtc_h,
67 + .tag3 = { RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH, 4, 0 },
69 + .tag4 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET, 8, 0 },
72 + .tag5 = { RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE, 8, 0 },
73 + .base = bo->paddr + fb->offsets[0],
74 + .screen_size = state->crtc_w * state->crtc_h * 4,
75 + .tag6 = { RPI_FIRMWARE_FRAMEBUFFER_SET_PITCH, 4, 0 },
76 + .pitch = fb->pitches[0],
77 + .tag7 = { RPI_FIRMWARE_FRAMEBUFFER_SET_ALPHA_MODE, 4, 0 },
78 + .alpha_mode = format == DRM_FORMAT_ARGB8888 ? 0 : 2,
79 + .tag8 = { RPI_FIRMWARE_FRAMEBUFFER_SET_LAYER, 4, 0 },
85 - fbinfo->xres = state->crtc_w;
86 - fbinfo->yres = state->crtc_h;
87 - fbinfo->xres_virtual = state->crtc_w;
88 - fbinfo->yres_virtual = state->crtc_h;
90 - fbinfo->xoffset = state->crtc_x;
91 - fbinfo->yoffset = state->crtc_y;
92 - fbinfo->base = bo->paddr + fb->offsets[0];
93 - fbinfo->pitch = fb->pitches[0];
95 if (fb->modifier == DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED)
96 - fbinfo->bpp |= BIT(31);
98 - /* A bug in the firmware makes it so that if the fb->base is
99 - * set to nonzero, the configured pitch gets overwritten with
100 - * the previous pitch. So, to get the configured pitch
101 - * recomputed, we have to make it allocate itself a new buffer
102 - * in VC memory, first.
104 - if (vc4_plane->pitch != fb->pitches[0]) {
105 - u32 saved_base = fbinfo->base;
108 - ret = rpi_firmware_transaction(vc4->firmware,
109 - RPI_FIRMWARE_CHAN_FB,
110 - vc4_plane->fbinfo_bus_addr);
111 - fbinfo->base = saved_base;
113 - vc4_plane->pitch = fbinfo->pitch;
114 - WARN_ON_ONCE(vc4_plane->pitch != fb->pitches[0]);
116 + fbinfo.bpp |= BIT(31);
118 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] primary update %dx%d@%d +%d,%d 0x%pad/%d\n",
119 plane->base.id, plane->name,
120 @@ -168,14 +181,13 @@ static void vc4_primary_plane_atomic_upd
128 - ret = rpi_firmware_transaction(vc4->firmware,
129 - RPI_FIRMWARE_CHAN_FB,
130 - vc4_plane->fbinfo_bus_addr);
131 - WARN_ON_ONCE(fbinfo->pitch != fb->pitches[0]);
132 - WARN_ON_ONCE(fbinfo->base != bo->paddr + fb->offsets[0]);
133 + ret = rpi_firmware_property_list(vc4->firmware, &fbinfo,
135 + WARN_ON_ONCE(fbinfo.pitch != fb->pitches[0]);
136 + WARN_ON_ONCE(fbinfo.base != bo->paddr + fb->offsets[0]);
138 /* If the CRTC is on (or going to be on) and we're enabled,
139 * then unblank. Otherwise, stay blank until CRTC enable.
140 @@ -332,10 +344,10 @@ static const struct drm_plane_helper_fun
141 static struct drm_plane *vc4_fkms_plane_init(struct drm_device *dev,
142 enum drm_plane_type type)
144 + /* Primary and cursor planes only */
145 struct drm_plane *plane = NULL;
146 struct vc4_fkms_plane *vc4_plane;
147 - u32 xrgb8888 = DRM_FORMAT_XRGB8888;
148 - u32 argb8888 = DRM_FORMAT_ARGB8888;
149 + u32 formats[] = {DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888};
151 bool primary = (type == DRM_PLANE_TYPE_PRIMARY);
152 static const uint64_t modifiers[] = {
153 @@ -357,22 +369,15 @@ static struct drm_plane *vc4_fkms_plane_
154 plane = &vc4_plane->base;
155 ret = drm_universal_plane_init(dev, plane, 0xff,
157 - primary ? &xrgb8888 : &argb8888, 1,
159 + formats, primary ? 2 : 1, modifiers,
160 type, primary ? "primary" : "cursor");
162 - if (type == DRM_PLANE_TYPE_PRIMARY) {
163 - vc4_plane->fbinfo =
164 - dma_alloc_coherent(dev->dev,
165 - sizeof(*vc4_plane->fbinfo),
166 - &vc4_plane->fbinfo_bus_addr,
168 - memset(vc4_plane->fbinfo, 0, sizeof(*vc4_plane->fbinfo));
170 + if (type == DRM_PLANE_TYPE_PRIMARY)
171 drm_plane_helper_add(plane, &vc4_primary_plane_helper_funcs);
174 drm_plane_helper_add(plane, &vc4_cursor_plane_helper_funcs);
177 + drm_plane_create_alpha_property(plane);
181 --- a/include/soc/bcm2835/raspberrypi-firmware.h
182 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
183 @@ -111,9 +111,15 @@ enum rpi_firmware_property_tag {
184 RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_OFFSET = 0x00040009,
185 RPI_FIRMWARE_FRAMEBUFFER_GET_OVERSCAN = 0x0004000a,
186 RPI_FIRMWARE_FRAMEBUFFER_GET_PALETTE = 0x0004000b,
187 + RPI_FIRMWARE_FRAMEBUFFER_GET_LAYER = 0x0004000c,
188 + RPI_FIRMWARE_FRAMEBUFFER_GET_TRANSFORM = 0x0004000d,
189 + RPI_FIRMWARE_FRAMEBUFFER_GET_VSYNC = 0x0004000e,
190 RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF = 0x0004000f,
191 RPI_FIRMWARE_FRAMEBUFFER_GET_GPIOVIRTBUF = 0x00040010,
192 RPI_FIRMWARE_FRAMEBUFFER_RELEASE = 0x00048001,
193 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM = 0x00048013,
194 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS = 0x00040013,
195 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS = 0x00040014,
196 RPI_FIRMWARE_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
197 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
198 RPI_FIRMWARE_FRAMEBUFFER_TEST_DEPTH = 0x00044005,
199 @@ -122,6 +128,8 @@ enum rpi_firmware_property_tag {
200 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_OFFSET = 0x00044009,
201 RPI_FIRMWARE_FRAMEBUFFER_TEST_OVERSCAN = 0x0004400a,
202 RPI_FIRMWARE_FRAMEBUFFER_TEST_PALETTE = 0x0004400b,
203 + RPI_FIRMWARE_FRAMEBUFFER_TEST_LAYER = 0x0004400c,
204 + RPI_FIRMWARE_FRAMEBUFFER_TEST_TRANSFORM = 0x0004400d,
205 RPI_FIRMWARE_FRAMEBUFFER_TEST_VSYNC = 0x0004400e,
206 RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
207 RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
208 @@ -134,6 +142,8 @@ enum rpi_firmware_property_tag {
209 RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF = 0x0004801f,
210 RPI_FIRMWARE_FRAMEBUFFER_SET_GPIOVIRTBUF = 0x00048020,
211 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC = 0x0004800e,
212 + RPI_FIRMWARE_FRAMEBUFFER_SET_LAYER = 0x0004800c,
213 + RPI_FIRMWARE_FRAMEBUFFER_SET_TRANSFORM = 0x0004800d,
214 RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT = 0x0004800f,
216 RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,