@@ -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 ();
0 commit comments