Skip to content

Commit 2bb9dab

Browse files
6by9popcornmix
authored andcommitted
video: bcm2708_fb: Try allocating on the ARM and passing to VPU
Currently the VPU allocates the contiguous buffer for the framebuffer. Try an alternate path first where we use dma_alloc_coherent and pass the buffer to the VPU. Should the VPU firmware not support that path, then free the buffer and revert to the old behaviour of using the VPU allocation. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent 0e25932 commit 2bb9dab

2 files changed

Lines changed: 91 additions & 12 deletions

File tree

‎drivers/video/fbdev/bcm2708_fb.c‎

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ struct bcm2708_fb {
9898
struct bcm2708_fb_stats stats;
9999
unsigned long fb_bus_address;
100100
struct { u32 base, length; } gpu;
101+
102+
bool disable_arm_alloc;
103+
unsigned int image_size;
104+
dma_addr_t dma_addr;
105+
void *cpuaddr;
101106
};
102107

103108
#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
@@ -283,23 +288,88 @@ static int bcm2708_fb_set_par(struct fb_info *info)
283288
.xoffset = info->var.xoffset,
284289
.yoffset = info->var.yoffset,
285290
.tag5 = { RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE, 8, 0 },
286-
.base = 0,
287-
.screen_size = 0,
288-
.tag6 = { RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH, 4, 0 },
289-
.pitch = 0,
291+
/* base and screen_size will be initialised later */
292+
.tag6 = { RPI_FIRMWARE_FRAMEBUFFER_SET_PITCH, 4, 0 },
293+
/* pitch will be initialised later */
290294
};
291-
int ret;
295+
int ret, image_size;
296+
292297

293298
print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n", __func__, info,
294299
info->var.xres, info->var.yres, info->var.xres_virtual,
295300
info->var.yres_virtual, (int)info->screen_size,
296301
info->var.bits_per_pixel);
297302

298-
ret = rpi_firmware_property_list(fb->fw, &fbinfo, sizeof(fbinfo));
303+
/* Try allocating our own buffer. We can specify all the parameters */
304+
image_size = ((info->var.xres * info->var.yres) *
305+
info->var.bits_per_pixel) >> 3;
306+
307+
if (!fb->disable_arm_alloc &&
308+
(image_size != fb->image_size || !fb->dma_addr)) {
309+
if (fb->dma_addr) {
310+
dma_free_coherent(info->device, fb->image_size,
311+
fb->cpuaddr, fb->dma_addr);
312+
fb->image_size = 0;
313+
fb->cpuaddr = NULL;
314+
fb->dma_addr = 0;
315+
}
316+
317+
fb->cpuaddr = dma_alloc_coherent(info->device, image_size,
318+
&fb->dma_addr, GFP_KERNEL);
319+
320+
if (!fb->cpuaddr) {
321+
fb->dma_addr = 0;
322+
fb->disable_arm_alloc = true;
323+
} else {
324+
fb->image_size = image_size;
325+
}
326+
}
327+
328+
if (fb->cpuaddr) {
329+
fbinfo.base = fb->dma_addr;
330+
fbinfo.screen_size = image_size;
331+
fbinfo.pitch = (info->var.xres * info->var.bits_per_pixel) >> 3;
332+
333+
ret = rpi_firmware_property_list(fb->fw, &fbinfo,
334+
sizeof(fbinfo));
335+
if (ret || fbinfo.base != fb->dma_addr) {
336+
/* Firmware either failed, or assigned a different base
337+
* address (ie it doesn't support being passed an FB
338+
* allocation).
339+
* Destroy the allocation, and don't try again.
340+
*/
341+
dma_free_coherent(info->device, fb->image_size,
342+
fb->cpuaddr, fb->dma_addr);
343+
fb->image_size = 0;
344+
fb->cpuaddr = NULL;
345+
fb->dma_addr = 0;
346+
fb->disable_arm_alloc = true;
347+
}
348+
} else {
349+
/* Our allocation failed - drop into the old scheme of
350+
* allocation by the VPU.
351+
*/
352+
ret = -ENOMEM;
353+
}
354+
299355
if (ret) {
300-
dev_err(info->device,
301-
"Failed to allocate GPU framebuffer (%d)\n", ret);
302-
return ret;
356+
/* Old scheme:
357+
* - FRAMEBUFFER_ALLOCATE passes 0 for base and screen_size.
358+
* - GET_PITCH instead of SET_PITCH.
359+
*/
360+
fbinfo.base = 0;
361+
fbinfo.screen_size = 0;
362+
fbinfo.tag6.tag = RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH;
363+
fbinfo.pitch = 0;
364+
365+
ret = rpi_firmware_property_list(fb->fw, &fbinfo,
366+
sizeof(fbinfo));
367+
if (ret) {
368+
dev_err(info->device,
369+
"Failed to allocate GPU framebuffer (%d)\n",
370+
ret);
371+
return ret;
372+
}
303373
}
304374

305375
if (info->var.bits_per_pixel <= 8)
@@ -314,9 +384,17 @@ static int bcm2708_fb_set_par(struct fb_info *info)
314384
fb->fb.fix.smem_start = fbinfo.base;
315385
fb->fb.fix.smem_len = fbinfo.pitch * fbinfo.yres_virtual;
316386
fb->fb.screen_size = fbinfo.screen_size;
317-
if (fb->fb.screen_base)
318-
iounmap(fb->fb.screen_base);
319-
fb->fb.screen_base = ioremap_wc(fbinfo.base, fb->fb.screen_size);
387+
388+
if (!fb->dma_addr) {
389+
if (fb->fb.screen_base)
390+
iounmap(fb->fb.screen_base);
391+
392+
fb->fb.screen_base = ioremap_wc(fbinfo.base,
393+
fb->fb.screen_size);
394+
} else {
395+
fb->fb.screen_base = fb->cpuaddr;
396+
}
397+
320398
if (!fb->fb.screen_base) {
321399
/* the console may currently be locked */
322400
console_trylock();

‎include/soc/bcm2835/raspberrypi-firmware.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum rpi_firmware_property_tag {
128128
RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH = 0x00048005,
129129
RPI_FIRMWARE_FRAMEBUFFER_SET_PIXEL_ORDER = 0x00048006,
130130
RPI_FIRMWARE_FRAMEBUFFER_SET_ALPHA_MODE = 0x00048007,
131+
RPI_FIRMWARE_FRAMEBUFFER_SET_PITCH = 0x00048008,
131132
RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET = 0x00048009,
132133
RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN = 0x0004800a,
133134
RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE = 0x0004800b,

0 commit comments

Comments
 (0)