Re: rasops: implement scrollback for inteldrm and efifb

2018-04-27 Thread Jonathan Gray
On Fri, Apr 27, 2018 at 10:22:42PM +0200, Mark Kettenis wrote:
> > Date: Fri, 27 Apr 2018 09:33:31 -0500
> > From: joshua stein 
> > 
> > On Tue, 17 Apr 2018 at 07:52:28 +0200, Mark Kettenis wrote:
> > > > Date: Mon, 16 Apr 2018 10:45:52 -0500
> > > > From: joshua stein 
> > > 
> > > Does this do the right thing for early consoles?  The initial
> > > efifb_bs[] doesn't have space for the scrollback.  At the point where
> > > the scrollback code gets code, we've replaced that with a malloc'ed
> > > buffer?
> > 
> > Here is a new version that puts the scrollback count into each 
> > rasops_screen in case it changes later, which allows it to cope with 
> > the count being 0 if no scrollback has been allocated.
> > 
> > Though the scrollback callback won't be called until wsdisplay 
> > formally attaches later after each rasops_screen is allocated 
> > anyway.
> 
> Two small nits below.  Otherwise this looks fine, so ok kettenis@ if
> you fix those.

I haven't tried this on intel yet but on radeon I often see a thin red
vertical line on the right side of the display with the first screen of
the buffer when scrolling back on rv635.

Index: radeon_kms.c
===
RCS file: /cvs/src/sys/dev/pci/drm/radeon/radeon_kms.c,v
retrieving revision 1.55
diff -u -p -r1.55 radeon_kms.c
--- radeon_kms.c25 Apr 2018 01:27:46 -  1.55
+++ radeon_kms.c28 Apr 2018 01:39:19 -
@@ -202,6 +202,7 @@ struct wsdisplay_accessops radeondrm_acc
.getchar = rasops_getchar,
.load_font = rasops_load_font,
.list_font = rasops_list_font,
+   .scrollback = rasops_scrollback,
.burn_screen = radeondrm_burner
 };
 



Re: rasops: implement scrollback for inteldrm and efifb

2018-04-27 Thread Mark Kettenis
> Date: Fri, 27 Apr 2018 09:33:31 -0500
> From: joshua stein 
> 
> On Tue, 17 Apr 2018 at 07:52:28 +0200, Mark Kettenis wrote:
> > > Date: Mon, 16 Apr 2018 10:45:52 -0500
> > > From: joshua stein 
> > 
> > Does this do the right thing for early consoles?  The initial
> > efifb_bs[] doesn't have space for the scrollback.  At the point where
> > the scrollback code gets code, we've replaced that with a malloc'ed
> > buffer?
> 
> Here is a new version that puts the scrollback count into each 
> rasops_screen in case it changes later, which allows it to cope with 
> the count being 0 if no scrollback has been allocated.
> 
> Though the scrollback callback won't be called until wsdisplay 
> formally attaches later after each rasops_screen is allocated 
> anyway.

Two small nits below.  Otherwise this looks fine, so ok kettenis@ if
you fix those.

> Index: arch/amd64/amd64/efifb.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/efifb.c,v
> retrieving revision 1.15
> diff -u -p -u -p -r1.15 efifb.c
> --- arch/amd64/amd64/efifb.c  25 Apr 2018 00:46:28 -  1.15
> +++ arch/amd64/amd64/efifb.c  27 Apr 2018 14:27:22 -
> @@ -101,6 +101,7 @@ intefifb_show_screen(void *, void *, i
>   void *);
>  int   efifb_list_font(void *, struct wsdisplay_font *);
>  int   efifb_load_font(void *, void *, struct wsdisplay_font *);
> +void  efifb_scrollback(void *, void *, int lines);
>  void  efifb_efiinfo_init(struct efifb *);
>  void  efifb_cnattach_common(void);
>  
> @@ -133,7 +134,8 @@ struct wsdisplay_accessops efifb_accesso
>   .free_screen = efifb_free_screen,
>   .show_screen = efifb_show_screen,
>   .load_font = efifb_load_font,
> - .list_font = efifb_list_font
> + .list_font = efifb_list_font,
> + .scrollback = efifb_scrollback,
>  };
>  
>  struct cfdriver efifb_cd = {
> @@ -397,6 +399,15 @@ efifb_list_font(void *v, struct wsdispla
>   struct rasops_info  *ri = >sc_fb->rinfo;
>  
>   return (rasops_list_font(ri, font));
> +}
> +
> +void
> +efifb_scrollback(void *v, void *cookie, int lines)
> +{
> + struct efifb_softc  *sc = v;
> + struct rasops_info  *ri = >sc_fb->rinfo;
> +
> + rasops_scrollback(ri, cookie, lines);
>  }
>  
>  int
> Index: dev/rasops/rasops.c
> ===
> RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
> retrieving revision 1.52
> diff -u -p -u -p -r1.52 rasops.c
> --- dev/rasops/rasops.c   20 Apr 2018 16:09:37 -  1.52
> +++ dev/rasops/rasops.c   27 Apr 2018 14:27:23 -
> @@ -1373,6 +1373,11 @@ struct rasops_screen {
>   int rs_visible;
>   int rs_crow;
>   int rs_ccol;
> +
> + int rs_sbscreens;
> +#define RS_SCROLLBACK_SCREENS 5
> + int rs_dispoffset;  /* rs_bs index, start of our actual screen */
> + int rs_visibleoffset;   /* rs_bs index, current scrollback screen */
>  };
>  
>  int
> @@ -1387,13 +1392,16 @@ rasops_alloc_screen(void *v, void **cook
>   if (scr == NULL)
>   return (ENOMEM);
>  
> - scr->rs_bs = mallocarray(ri->ri_rows,
> + scr->rs_sbscreens = RS_SCROLLBACK_SCREENS;
> + scr->rs_bs = mallocarray(ri->ri_rows * (scr->rs_sbscreens + 1),
>   ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
>   M_NOWAIT);
>   if (scr->rs_bs == NULL) {
>   free(scr, M_DEVBUF, sizeof(*scr));
>   return (ENOMEM);
>   }
> + scr->rs_visibleoffset = scr->rs_dispoffset = ri->ri_rows *
> + scr->rs_sbscreens * ri->ri_cols;
>  
>   *cookiep = scr;
>   *curxp = 0;
> @@ -1405,13 +1413,19 @@ rasops_alloc_screen(void *v, void **cook
>   scr->rs_crow = -1;
>   scr->rs_ccol = -1;
>  
> + for (i = 0; i < scr->rs_dispoffset; i++) {
> + scr->rs_bs[i].uc = ' ';
> + scr->rs_bs[i].attr = *attrp;
> + }
> +
>   if (ri->ri_bs && scr->rs_visible) {
> - memcpy(scr->rs_bs, ri->ri_bs, ri->ri_rows * ri->ri_cols *
> + memcpy(scr->rs_bs + scr->rs_dispoffset, ri->ri_bs,
> + ri->ri_rows * ri->ri_cols *
>   sizeof(struct wsdisplay_charcell));
>   } else {
>   for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
> - scr->rs_bs[i].uc = ' ';
> - scr->rs_bs[i].attr = *attrp;
> + scr->rs_bs[scr->rs_dispoffset + i].uc = ' ';
> + scr->rs_bs[scr->rs_dispoffset + i].attr = *attrp;
>   }
>   }
>  
> @@ -1431,7 +1445,8 @@ rasops_free_screen(void *v, void *cookie
>   ri->ri_nscreens--;
>  
>   free(scr->rs_bs, M_DEVBUF,
> - ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell));
> + ri->ri_rows * (scr->rs_sbscreens + 1) * ri->ri_cols *
> + sizeof(struct wsdisplay_charcell));
>   free(scr, M_DEVBUF, sizeof(*scr));
>  }
>  

Re: rasops: implement scrollback for inteldrm and efifb

2018-04-16 Thread Mark Kettenis
> Date: Mon, 16 Apr 2018 10:45:52 -0500
> From: joshua stein 

Does this do the right thing for early consoles?  The initial
efifb_bs[] doesn't have space for the scrollback.  At the point where
the scrollback code gets code, we've replaced that with a malloc'ed
buffer?

> Index: arch/amd64/amd64/efifb.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/efifb.c,v
> retrieving revision 1.12
> diff -u -p -u -p -r1.12 efifb.c
> --- arch/amd64/amd64/efifb.c  28 Oct 2017 01:48:03 -  1.12
> +++ arch/amd64/amd64/efifb.c  16 Apr 2018 15:40:22 -
> @@ -101,6 +101,7 @@ intefifb_show_screen(void *, void *, i
>   void *);
>  int   efifb_list_font(void *, struct wsdisplay_font *);
>  int   efifb_load_font(void *, void *, struct wsdisplay_font *);
> +void  efifb_scrollback(void *, void *, int lines);
>  void  efifb_efiinfo_init(struct efifb *);
>  void  efifb_cnattach_common(void);
>  
> @@ -133,7 +134,8 @@ struct wsdisplay_accessops efifb_accesso
>   .free_screen = efifb_free_screen,
>   .show_screen = efifb_show_screen,
>   .load_font = efifb_load_font,
> - .list_font = efifb_list_font
> + .list_font = efifb_list_font,
> + .scrollback = efifb_scrollback,
>  };
>  
>  struct cfdriver efifb_cd = {
> @@ -397,6 +399,15 @@ efifb_list_font(void *v, struct wsdispla
>   struct rasops_info  *ri = >sc_fb->rinfo;
>  
>   return (rasops_list_font(ri, font));
> +}
> +
> +void
> +efifb_scrollback(void *v, void *cookie, int lines)
> +{
> + struct efifb_softc  *sc = v;
> + struct rasops_info  *ri = >sc_fb->rinfo;
> +
> + rasops_scrollback(ri, cookie, lines);
>  }
>  
>  int
> Index: dev/rasops/rasops.c
> ===
> RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
> retrieving revision 1.50
> diff -u -p -u -p -r1.50 rasops.c
> --- dev/rasops/rasops.c   23 Jan 2018 10:10:32 -  1.50
> +++ dev/rasops/rasops.c   16 Apr 2018 15:40:22 -
> @@ -1373,8 +1373,13 @@ struct rasops_screen {
>   int rs_visible;
>   int rs_crow;
>   int rs_ccol;
> +
> + int rs_dispoffset;  /* rs_bs index, start of our actual screen */
> + int rs_visibleoffset;   /* rs_bs index, current scrollback screen */
>  };
>  
> +#define RS_SCROLLBACK_SCREENS 5
> +
>  int
>  rasops_alloc_screen(void *v, void **cookiep,
>  int *curxp, int *curyp, long *attrp)
> @@ -1387,13 +1392,15 @@ rasops_alloc_screen(void *v, void **cook
>   if (scr == NULL)
>   return (ENOMEM);
>  
> - scr->rs_bs = mallocarray(ri->ri_rows,
> + scr->rs_bs = mallocarray(ri->ri_rows * RS_SCROLLBACK_SCREENS,
>   ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
>   M_NOWAIT);
>   if (scr->rs_bs == NULL) {
>   free(scr, M_DEVBUF, sizeof(*scr));
>   return (ENOMEM);
>   }
> + scr->rs_visibleoffset = scr->rs_dispoffset = ri->ri_rows *
> + (RS_SCROLLBACK_SCREENS - 1) * ri->ri_cols;
>  
>   *cookiep = scr;
>   *curxp = 0;
> @@ -1405,13 +1412,19 @@ rasops_alloc_screen(void *v, void **cook
>   scr->rs_crow = -1;
>   scr->rs_ccol = -1;
>  
> + for (i = 0; i < scr->rs_dispoffset; i++) {
> + scr->rs_bs[i].uc = ' ';
> + scr->rs_bs[i].attr = *attrp;
> + }
> +
>   if (ri->ri_bs && scr->rs_visible) {
> - memcpy(scr->rs_bs, ri->ri_bs, ri->ri_rows * ri->ri_cols *
> + memcpy(scr->rs_bs + scr->rs_dispoffset, ri->ri_bs,
> + ri->ri_rows * ri->ri_cols *
>   sizeof(struct wsdisplay_charcell));
>   } else {
>   for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
> - scr->rs_bs[i].uc = ' ';
> - scr->rs_bs[i].attr = *attrp;
> + scr->rs_bs[scr->rs_dispoffset + i].uc = ' ';
> + scr->rs_bs[scr->rs_dispoffset + i].attr = *attrp;
>   }
>   }
>  
> @@ -1431,7 +1444,8 @@ rasops_free_screen(void *v, void *cookie
>   ri->ri_nscreens--;
>  
>   free(scr->rs_bs, M_DEVBUF,
> - ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell));
> + ri->ri_rows * RS_SCROLLBACK_SCREENS * ri->ri_cols *
> + sizeof(struct wsdisplay_charcell));
>   free(scr, M_DEVBUF, sizeof(*scr));
>  }
>  
> @@ -1467,9 +1481,11 @@ rasops_doswitch(void *v)
>   ri->ri_eraserows(ri, 0, ri->ri_rows, attr);
>   ri->ri_active = scr;
>   ri->ri_active->rs_visible = 1;
> + ri->ri_active->rs_visibleoffset = ri->ri_active->rs_dispoffset;
>   for (row = 0; row < ri->ri_rows; row++) {
>   for (col = 0; col < ri->ri_cols; col++) {
> - int off = row * scr->rs_ri->ri_cols + col;
> + int off = row * scr->rs_ri->ri_cols + col +
> + scr->rs_visibleoffset;
>  
>   

rasops: implement scrollback for inteldrm and efifb

2018-04-16 Thread joshua stein
Index: arch/amd64/amd64/efifb.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/efifb.c,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 efifb.c
--- arch/amd64/amd64/efifb.c28 Oct 2017 01:48:03 -  1.12
+++ arch/amd64/amd64/efifb.c16 Apr 2018 15:40:22 -
@@ -101,6 +101,7 @@ int  efifb_show_screen(void *, void *, i
void *);
 int efifb_list_font(void *, struct wsdisplay_font *);
 int efifb_load_font(void *, void *, struct wsdisplay_font *);
+voidefifb_scrollback(void *, void *, int lines);
 voidefifb_efiinfo_init(struct efifb *);
 voidefifb_cnattach_common(void);
 
@@ -133,7 +134,8 @@ struct wsdisplay_accessops efifb_accesso
.free_screen = efifb_free_screen,
.show_screen = efifb_show_screen,
.load_font = efifb_load_font,
-   .list_font = efifb_list_font
+   .list_font = efifb_list_font,
+   .scrollback = efifb_scrollback,
 };
 
 struct cfdriver efifb_cd = {
@@ -397,6 +399,15 @@ efifb_list_font(void *v, struct wsdispla
struct rasops_info  *ri = >sc_fb->rinfo;
 
return (rasops_list_font(ri, font));
+}
+
+void
+efifb_scrollback(void *v, void *cookie, int lines)
+{
+   struct efifb_softc  *sc = v;
+   struct rasops_info  *ri = >sc_fb->rinfo;
+
+   rasops_scrollback(ri, cookie, lines);
 }
 
 int
Index: dev/rasops/rasops.c
===
RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.50
diff -u -p -u -p -r1.50 rasops.c
--- dev/rasops/rasops.c 23 Jan 2018 10:10:32 -  1.50
+++ dev/rasops/rasops.c 16 Apr 2018 15:40:22 -
@@ -1373,8 +1373,13 @@ struct rasops_screen {
int rs_visible;
int rs_crow;
int rs_ccol;
+
+   int rs_dispoffset;  /* rs_bs index, start of our actual screen */
+   int rs_visibleoffset;   /* rs_bs index, current scrollback screen */
 };
 
+#define RS_SCROLLBACK_SCREENS 5
+
 int
 rasops_alloc_screen(void *v, void **cookiep,
 int *curxp, int *curyp, long *attrp)
@@ -1387,13 +1392,15 @@ rasops_alloc_screen(void *v, void **cook
if (scr == NULL)
return (ENOMEM);
 
-   scr->rs_bs = mallocarray(ri->ri_rows,
+   scr->rs_bs = mallocarray(ri->ri_rows * RS_SCROLLBACK_SCREENS,
ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
M_NOWAIT);
if (scr->rs_bs == NULL) {
free(scr, M_DEVBUF, sizeof(*scr));
return (ENOMEM);
}
+   scr->rs_visibleoffset = scr->rs_dispoffset = ri->ri_rows *
+   (RS_SCROLLBACK_SCREENS - 1) * ri->ri_cols;
 
*cookiep = scr;
*curxp = 0;
@@ -1405,13 +1412,19 @@ rasops_alloc_screen(void *v, void **cook
scr->rs_crow = -1;
scr->rs_ccol = -1;
 
+   for (i = 0; i < scr->rs_dispoffset; i++) {
+   scr->rs_bs[i].uc = ' ';
+   scr->rs_bs[i].attr = *attrp;
+   }
+
if (ri->ri_bs && scr->rs_visible) {
-   memcpy(scr->rs_bs, ri->ri_bs, ri->ri_rows * ri->ri_cols *
+   memcpy(scr->rs_bs + scr->rs_dispoffset, ri->ri_bs,
+   ri->ri_rows * ri->ri_cols *
sizeof(struct wsdisplay_charcell));
} else {
for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
-   scr->rs_bs[i].uc = ' ';
-   scr->rs_bs[i].attr = *attrp;
+   scr->rs_bs[scr->rs_dispoffset + i].uc = ' ';
+   scr->rs_bs[scr->rs_dispoffset + i].attr = *attrp;
}
}
 
@@ -1431,7 +1444,8 @@ rasops_free_screen(void *v, void *cookie
ri->ri_nscreens--;
 
free(scr->rs_bs, M_DEVBUF,
-   ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell));
+   ri->ri_rows * RS_SCROLLBACK_SCREENS * ri->ri_cols *
+   sizeof(struct wsdisplay_charcell));
free(scr, M_DEVBUF, sizeof(*scr));
 }
 
@@ -1467,9 +1481,11 @@ rasops_doswitch(void *v)
ri->ri_eraserows(ri, 0, ri->ri_rows, attr);
ri->ri_active = scr;
ri->ri_active->rs_visible = 1;
+   ri->ri_active->rs_visibleoffset = ri->ri_active->rs_dispoffset;
for (row = 0; row < ri->ri_rows; row++) {
for (col = 0; col < ri->ri_cols; col++) {
-   int off = row * scr->rs_ri->ri_cols + col;
+   int off = row * scr->rs_ri->ri_cols + col +
+   scr->rs_visibleoffset;
 
ri->ri_putchar(ri, row, col, scr->rs_bs[off].uc,
scr->rs_bs[off].attr);
@@ -1491,7 +1507,7 @@ rasops_getchar(void *v, int row, int col
if (scr == NULL || scr->rs_bs == NULL)
return (1);
 
-   *cell = scr->rs_bs[row * ri->ri_cols + col];
+   *cell = scr->rs_bs[row * ri->ri_cols + col + scr->rs_dispoffset];
return (0);
 }
 
@@ -1521,7 +1537,10 @@ int