shithub: riscv

Download patch

ref: 2d0ede468ddd363243fd31580e3e86c39b51f7be
parent: 9911557e45d5763320eb612aa6c5965f8ff39007
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Dec 10 12:50:06 EST 2022

imx8: cleanup framebuffer code

We can get rid of a bunch of stuff now that we'r using a softscreen.

Get rid of the static Memimage and Memdata for the framebuffer;
just allocate gscreen as a memimage from the image pool.

Avoid exporting fbraw pointer, just have screeninit() return it.

Remove fbmemalloc() function. it used to create a write-thru
mapping but given that we are no more reading the framebuffer,
we can use ucalloc() instead.

--- a/sys/src/9/imx8/fns.h
+++ b/sys/src/9/imx8/fns.h
@@ -80,7 +80,6 @@
 extern void putasid(Proc*);
 
 extern void* ucalloc(usize);
-extern void* fbmemalloc(usize);
 
 /* clock */
 extern void clockinit(void);
--- a/sys/src/9/imx8/lcd.c
+++ b/sys/src/9/imx8/lcd.c
@@ -12,8 +12,6 @@
 #include	<cursor.h>
 #include	"screen.h"
 
-extern u8int *fbraw;
-
 /* system reset controller registers */
 enum {
 	SRC_MIPIPHY_RCR = 0x28/4,
@@ -455,7 +453,7 @@
 }
 
 static void
-lcdifinit(struct video_mode *mode)
+lcdifinit(struct video_mode *mode, u32int framebuffer)
 {
 	wr(lcdif, LCDIF_CTRL_CLR, CTRL_SFTRST);
 	while(rr(lcdif, LCDIF_CTRL) & CTRL_SFTRST)
@@ -504,8 +502,8 @@
 	wr(lcdif, LCDIF_VDCTRL4,
 		sm(mode->hactive, VDCTRL4_DOTCLK_H_VALID_DATA_CNT));
 
-	wr(lcdif, LCDIF_CUR_BUF, PADDR(fbraw));
-	wr(lcdif, LCDIF_NEXT_BUF, PADDR(fbraw));
+	wr(lcdif, LCDIF_CUR_BUF, framebuffer);
+	wr(lcdif, LCDIF_NEXT_BUF, framebuffer);
 
 	wr(lcdif, LCDIF_CTRL_SET, CTRL_DOTCLK_MODE);
 
@@ -891,6 +889,7 @@
 	struct dsi_cfg dsi_cfg;
 	struct video_mode mode;
 	char *err;
+	void *fb;
 
 	intrenable(IRQlcdif, blankirq, nil, BUSUNKNOWN, "lcdif");
 
@@ -960,8 +959,8 @@
 	if(err != nil)
 		goto out;
 
-	/* allocates the framebuffer (gscreen->data->bdata) */
-	if(screeninit(mode.hactive, mode.vactive, 32) < 0){
+	/* allocates the framebuffer */
+	if((fb = screeninit(mode.hactive, mode.vactive, 32)) == nil){
 		err = "screeninit failed";
 		goto out;
 	}
@@ -980,7 +979,7 @@
 	bridgeinit(&mode, &dsi_cfg);
 
 	/* send the pixels */
-	lcdifinit(&mode);
+	lcdifinit(&mode, (u32int)PADDR(fb));
 	return;
 
 out:
--- a/sys/src/9/imx8/mmu.c
+++ b/sys/src/9/imx8/mmu.c
@@ -517,9 +517,3 @@
 {
 	return ucramalloc(size, 8, PTEUNCACHED);
 }
-
-void*
-fbmemalloc(usize size)
-{
-	return ucramalloc(PGROUND(size), BY2PG, PTEWT);
-}
--- a/sys/src/9/imx8/screen.c
+++ b/sys/src/9/imx8/screen.c
@@ -16,10 +16,9 @@
 };
 
 Memimage *gscreen;
-u8int *fbraw;
 
-static Memdata xgdata;
-static Memimage xgscreen;
+static ulong *fbraw;
+
 static Memimage *conscol;
 static Memimage *back;
 static Memsubfont *memdefont;
@@ -85,6 +84,7 @@
 hwdraw(Memdrawparam *par)
 {
 	Memimage *dst, *src, *mask;
+	uchar *scrd;
 
 	if((dst = par->dst) == nil || dst->data == nil)
 		return 0;
@@ -93,17 +93,18 @@
 	if((mask = par->mask) && mask->data == nil)
 		mask = nil;
 
-	if(dst->data->bdata == xgdata.bdata)
+	scrd = gscreen->data->bdata;
+	if(dst->data->bdata == scrd)
 		swcursoravoid(par->r);
-	if(src && src->data->bdata == xgdata.bdata)
+	if(src && src->data->bdata == scrd)
 		swcursoravoid(par->sr);
-	if(mask && mask->data->bdata == xgdata.bdata)
+	if(mask && mask->data->bdata == scrd)
 		swcursoravoid(par->mr);
 
 	return 0;
 }
 
-int
+void*
 screeninit(int width, int height, int depth)
 {
 	ulong chan;
@@ -110,7 +111,7 @@
 
 	switch(depth){
 	default:
-		return -1;
+		return nil;
 	case 32:
 		chan = XRGB32;
 		break;
@@ -121,21 +122,15 @@
 		chan = RGB16;
 		break;
 	}
-	memsetchan(&xgscreen, chan);
-	xgscreen.r = Rect(0, 0, width, height);
-	xgscreen.clipr = xgscreen.r;
-	xgscreen.depth = depth;
-	xgscreen.width = wordsperline(xgscreen.r, xgscreen.depth);
-	xgdata.bdata = malloc(xgscreen.width*sizeof(ulong)*height);
-	xgdata.ref = 1;
+	memimageinit();
 
-	xgscreen.data = &xgdata;
-	gscreen = &xgscreen;
+	gscreen = allocmemimage(Rect(0, 0, width, height), chan);
+	if(gscreen == nil)
+		return nil;
+
 	conf.monitor = 1;
+	fbraw = ucalloc(PGROUND(gscreen->width*sizeof(ulong)*height));
 
-	fbraw = fbmemalloc(xgscreen.width*sizeof(ulong)*height);
-
-	memimageinit();
 	memdefont = getmemdefont();
 	screenwin();
 	myscreenputs(kmesg.buf, kmesg.n);
@@ -142,25 +137,26 @@
 	screenputs = myscreenputs;
 	swcursorinit();
 
-	return 0;
+	return fbraw;
 }
 
 void
 flushmemscreen(Rectangle r)
 {
-	int pitch, n, y;
+	int pitch, n;
 	ulong *d, *s;
 
-	if(rectclip(&r, xgscreen.r)){
-		s = wordaddr(&xgscreen, r.min);
-		d = (ulong*)fbraw + (s - wordaddr(&xgscreen, xgscreen.r.min));
-		n = bytesperline(r, xgscreen.depth);
-		pitch = wordsperline(xgscreen.r, xgscreen.depth);
-		for(y = 0; y < Dy(r); y++){
-			memmove(d, s, n);
-			d += pitch;
-			s += pitch;
-		}
+	if(!rectclip(&r, gscreen->r))
+		return;
+
+	s = wordaddr(gscreen, r.min);
+	d = fbraw + (s - wordaddr(gscreen, gscreen->r.min));
+	n = bytesperline(r, gscreen->depth);
+	pitch = wordsperline(gscreen->r, gscreen->depth);
+	while(r.min.y++ < r.max.y){
+		memmove(d, s, n);
+		d += pitch;
+		s += pitch;
 	}
 }
 
--- a/sys/src/9/imx8/screen.h
+++ b/sys/src/9/imx8/screen.h
@@ -7,7 +7,7 @@
 extern void mouseaccelerate(int);
 
 /* screen.c */
-extern int	screeninit(int width, int hight, int depth);
+extern void*	screeninit(int width, int hight, int depth);
 extern void	blankscreen(int);
 extern void	flushmemscreen(Rectangle);
 extern Memdata*	attachscreen(Rectangle*, ulong*, int*, int*, int*);