|  | @@ -573,6 +573,7 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
 | 
		
	
		
			
			| 573 | 573 |   * @v fbcon		Frame buffer console
 | 
		
	
		
			
			| 574 | 574 |   * @v start		Start address
 | 
		
	
		
			
			| 575 | 575 |   * @v pixel		Pixel geometry
 | 
		
	
		
			
			|  | 576 | + * @v margin		Minimum margin
 | 
		
	
		
			
			| 576 | 577 |   * @v map		Colour mapping
 | 
		
	
		
			
			| 577 | 578 |   * @v font		Font definition
 | 
		
	
		
			
			| 578 | 579 |   * @v pixbuf		Background picture (if any)
 | 
		
	
	
		
			
			|  | @@ -580,9 +581,12 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
 | 
		
	
		
			
			| 580 | 581 |   */
 | 
		
	
		
			
			| 581 | 582 |  int fbcon_init ( struct fbcon *fbcon, userptr_t start,
 | 
		
	
		
			
			| 582 | 583 |  		 struct fbcon_geometry *pixel,
 | 
		
	
		
			
			|  | 584 | +		 struct fbcon_margin *margin,
 | 
		
	
		
			
			| 583 | 585 |  		 struct fbcon_colour_map *map,
 | 
		
	
		
			
			| 584 | 586 |  		 struct fbcon_font *font,
 | 
		
	
		
			
			| 585 | 587 |  		 struct pixel_buffer *pixbuf ) {
 | 
		
	
		
			
			|  | 588 | +	int width;
 | 
		
	
		
			
			|  | 589 | +	int height;
 | 
		
	
		
			
			| 586 | 590 |  	unsigned int xgap;
 | 
		
	
		
			
			| 587 | 591 |  	unsigned int ygap;
 | 
		
	
		
			
			| 588 | 592 |  	int rc;
 | 
		
	
	
		
			
			|  | @@ -603,21 +607,31 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
 | 
		
	
		
			
			| 603 | 607 |  	       user_to_phys ( fbcon->start, 0 ),
 | 
		
	
		
			
			| 604 | 608 |  	       user_to_phys ( fbcon->start, fbcon->len ) );
 | 
		
	
		
			
			| 605 | 609 |  
 | 
		
	
		
			
			|  | 610 | +	/* Expand margin to accommodate whole characters */
 | 
		
	
		
			
			|  | 611 | +	width = ( pixel->width - margin->left - margin->right );
 | 
		
	
		
			
			|  | 612 | +	height = ( pixel->height - margin->top - margin->bottom );
 | 
		
	
		
			
			|  | 613 | +	if ( ( width < FBCON_CHAR_WIDTH ) || ( height < FBCON_CHAR_HEIGHT ) ) {
 | 
		
	
		
			
			|  | 614 | +		DBGC ( fbcon, "FBCON %p has unusable character area "
 | 
		
	
		
			
			|  | 615 | +		       "[%d-%d),[%d-%d)\n", fbcon,
 | 
		
	
		
			
			|  | 616 | +		       margin->left, ( pixel->width - margin->right ),
 | 
		
	
		
			
			|  | 617 | +		       margin->top, ( pixel->height - margin->bottom ) );
 | 
		
	
		
			
			|  | 618 | +		rc = -EINVAL;
 | 
		
	
		
			
			|  | 619 | +		goto err_margin;
 | 
		
	
		
			
			|  | 620 | +	}
 | 
		
	
		
			
			|  | 621 | +	xgap = ( width % FBCON_CHAR_WIDTH );
 | 
		
	
		
			
			|  | 622 | +	ygap = ( height % FBCON_CHAR_HEIGHT );
 | 
		
	
		
			
			|  | 623 | +	fbcon->margin.left = ( margin->left + ( xgap / 2 ) );
 | 
		
	
		
			
			|  | 624 | +	fbcon->margin.top = ( margin->top + ( ygap / 2 ) );
 | 
		
	
		
			
			|  | 625 | +	fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) );
 | 
		
	
		
			
			|  | 626 | +	fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) );
 | 
		
	
		
			
			|  | 627 | +	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
 | 
		
	
		
			
			|  | 628 | +			  ( fbcon->margin.left * pixel->len ) );
 | 
		
	
		
			
			|  | 629 | +
 | 
		
	
		
			
			| 606 | 630 |  	/* Derive character geometry from pixel geometry */
 | 
		
	
		
			
			| 607 |  | -	fbcon->character.width = ( pixel->width / FBCON_CHAR_WIDTH );
 | 
		
	
		
			
			| 608 |  | -	fbcon->character.height = ( pixel->height / FBCON_CHAR_HEIGHT );
 | 
		
	
		
			
			|  | 631 | +	fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
 | 
		
	
		
			
			|  | 632 | +	fbcon->character.height = ( height / FBCON_CHAR_HEIGHT );
 | 
		
	
		
			
			| 609 | 633 |  	fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
 | 
		
	
		
			
			| 610 | 634 |  	fbcon->character.stride = ( pixel->stride * FBCON_CHAR_HEIGHT );
 | 
		
	
		
			
			| 611 |  | -
 | 
		
	
		
			
			| 612 |  | -	/* Calculate margin */
 | 
		
	
		
			
			| 613 |  | -	xgap = ( pixel->width % FBCON_CHAR_WIDTH );
 | 
		
	
		
			
			| 614 |  | -	ygap = ( pixel->height % FBCON_CHAR_HEIGHT );
 | 
		
	
		
			
			| 615 |  | -	fbcon->margin.left = ( xgap / 2 );
 | 
		
	
		
			
			| 616 |  | -	fbcon->margin.top = ( ygap / 2 );
 | 
		
	
		
			
			| 617 |  | -	fbcon->margin.right = ( xgap - fbcon->margin.left );
 | 
		
	
		
			
			| 618 |  | -	fbcon->margin.bottom = ( ygap - fbcon->margin.top );
 | 
		
	
		
			
			| 619 |  | -	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
 | 
		
	
		
			
			| 620 |  | -			  ( fbcon->margin.left * pixel->len ) );
 | 
		
	
		
			
			| 621 | 635 |  	DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
 | 
		
	
		
			
			| 622 | 636 |  	       "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
 | 
		
	
		
			
			| 623 | 637 |  	       fbcon->pixel->height, fbcon->character.width,
 | 
		
	
	
		
			
			|  | @@ -662,6 +676,7 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
 | 
		
	
		
			
			| 662 | 676 |   err_picture:
 | 
		
	
		
			
			| 663 | 677 |  	ufree ( fbcon->text.start );
 | 
		
	
		
			
			| 664 | 678 |   err_text:
 | 
		
	
		
			
			|  | 679 | + err_margin:
 | 
		
	
		
			
			| 665 | 680 |  	return rc;
 | 
		
	
		
			
			| 666 | 681 |  }
 | 
		
	
		
			
			| 667 | 682 |  
 |