Re: [gentoo-user] Soft scrolling on framebuffer consoles - with GPM handling - version of the patch for kernel 6.6 [was 6.3] onwards.

2024-03-11 Thread Peter Humphrey
On Wednesday, 24 January 2024 12:20:29 GMT Alan Mackenzie wrote:
> Hello, Gentoo.
> 
> On Wed, Jan 24, 2024 at 10:00:37 +, Alan Mackenzie wrote:
> 
> [  ]
> 
> Please note the corrected subject line.  This version of the soft
> scrolling patch is for kernel 6.6.13, or thereabouts.

It works well here, Alan, up to kernel version 6.7.9, but one of the 15 or so 
new kernel parameters (since 6.7.8) seems to cause it to fail.

I've attached the reject file, /usr/src/linux-6.8.0-gentoo/drivers/tty/vt/
vt.c.rej.

-- 
Regards,
Peter.
--- drivers/tty/vt/vt.c
+++ drivers/tty/vt/vt.c
@@ -348,107 +377,111 @@ void schedule_console_callback(void)
  * Code to manage unicode-based screen buffers
  */
 
-/*
- * Our screen buffer is preceded by an array of line pointers so that
- * scrolling only implies some pointer shuffling.
- */
+#define vc_uniscr_buf_end(vc) (vc->vc_uniscr_buf + vc->vc_uniscr_char_size)
 
-static u32 **vc_uniscr_alloc(unsigned int cols, unsigned int rows)
+static int vc_uniscr_alloc(struct vc_data *vc, unsigned int cols, unsigned int rows)
 {
-	u32 **uni_lines;
-	void *p;
-	unsigned int memsize, i, col_size = cols * sizeof(**uni_lines);
-
-	/* allocate everything in one go */
-	memsize = col_size * rows;
-	memsize += rows * sizeof(*uni_lines);
-	uni_lines = vzalloc(memsize);
-	if (!uni_lines)
-		return NULL;
-
-	/* initial line pointers */
-	p = uni_lines + rows;
-	for (i = 0; i < rows; i++) {
-		uni_lines[i] = p;
-		p += col_size;
-	}
+	uint32_t *p;
+	unsigned int new_size;	/* In 32-bit characters */
 
-	return uni_lines;
-}
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_GPM
+	unsigned int num_scrollback_rows;
 
-static void vc_uniscr_free(u32 **uni_lines)
-{
-	vfree(uni_lines);
+	num_scrollback_rows = (console_soft_scrollback_size / 2) / cols;
+	new_size = cols * (num_scrollback_rows + rows + 1);
+#else
+	new_size = cols * (rows + 1); /* 1 row for the circular buffer admin */
+#endif
+	p = (uint32_t *)vzalloc (sizeof (uint32_t) * new_size);
+	if (!p)
+		return -ENOMEM;
+	vc->vc_uniscr_buf = p;
+	vc->vc_uniscr_curr = p;
+	vc->vc_uniscr_char_size = new_size;
+	memset32(p, ' ', new_size); /* Probably redundant. */
+	return 0;
 }
 
-static void vc_uniscr_set(struct vc_data *vc, u32 **new_uni_lines)
+static void vc_uniscr_free(struct vc_data *vc)
 {
-	vc_uniscr_free(vc->vc_uni_lines);
-	vc->vc_uni_lines = new_uni_lines;
+	kvfree(vc->vc_uniscr_buf);
+	vc->vc_uniscr_buf = NULL;
 }
 
 static void vc_uniscr_putc(struct vc_data *vc, u32 uc)
 {
-	if (vc->vc_uni_lines)
-		vc->vc_uni_lines[vc->state.y][vc->state.x] = uc;
+	uint32_t *pos;
+
+	if (vc->vc_uniscr_buf) {
+		pos = vc->vc_uniscr_curr;
+		UNISCR_PLUS(pos, vc->state.y * vc->vc_cols + vc->state.x);
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_GPM
+		UNISCR_MINUS(pos, vc->vc_cols * (vc->vc_softback_lines + vc->vc_top));
+#endif
+		*pos = uc;
+	}
 }
 
 static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
 {
-	if (vc->vc_uni_lines) {
-		u32 *ln = vc->vc_uni_lines[vc->state.y];
-		unsigned int x = vc->state.x, cols = vc->vc_cols;
+	unsigned int x = vc->state.x, y = vc->state.y, cols = vc->vc_cols;
+	uint32_t *ln = vc->vc_uniscr_curr;
 
-		memmove([x + nr], [x], (cols - x - nr) * sizeof(*ln));
+	if (vc->vc_uniscr_buf) {
+		UNISCR_PLUS(ln, y * cols);
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_GPM
+		UNISCR_MINUS(ln, vc->vc_cols * (vc->vc_softback_lines + vc->vc_top));
+#endif
+		memmove([x + nr], [x], (cols - x - nr) * sizeof(uint32_t));
 		memset32([x], ' ', nr);
 	}
 }
 
 static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
 {
-	if (vc->vc_uni_lines) {
-		u32 *ln = vc->vc_uni_lines[vc->state.y];
-		unsigned int x = vc->state.x, cols = vc->vc_cols;
+	unsigned int x = vc->state.x, y = vc->state.y, cols = vc->vc_cols;
+	uint32_t *ln = vc->vc_uniscr_curr;
 
-		memcpy([x], [x + nr], (cols - x - nr) * sizeof(*ln));
+	if (vc->vc_uniscr_buf) {
+		UNISCR_PLUS(ln, y * cols);
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_GPM
+		UNISCR_MINUS(ln, vc->vc_cols * (vc->vc_softback_lines + vc->vc_top));
+#endif
+		memcpy([x], [x + nr], (cols - x - nr) * sizeof(uint32_t));
 		memset32([cols - nr], ' ', nr);
 	}
 }
 
+/* FIXME!!!  We need to check that NR never goes beyond the current line end.  !!! */
 static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x,
  unsigned int nr)
 {
-	if (vc->vc_uni_lines)
-		memset32(>vc_uni_lines[vc->state.y][x], ' ', nr);
+	if (vc->vc_uniscr_buf) {
+		uint32_t *ln = vc->vc_uniscr_curr;
+
+		UNISCR_PLUS(ln, vc->state.y * vc->vc_cols);
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_GPM
+		UNISCR_MINUS(ln, vc->vc_cols * (vc->vc_softback_lines + vc->vc_top));
+#endif
+		memset32([x], ' ', nr);
+	}
 }
 
 static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
   unsigned int nr)
 {
-	if (vc->vc_uni_lines)
-		while (nr--)
-			memset32(vc->vc_uni_lines[y++], ' ', vc->vc_cols);
-}
-
-/* juggling array rotation algorithm (complexity O(N), size complexity O(1)) 

Re: [gentoo-user] Soft scrolling on framebuffer consoles - with GPM handling - version of the patch for kernel 6.6 [was 6.3] onwards.

2024-01-24 Thread Alan Mackenzie
Hello, Gentoo.

On Wed, Jan 24, 2024 at 10:00:37 +, Alan Mackenzie wrote:

[  ]

Please note the corrected subject line.  This version of the soft
scrolling patch is for kernel 6.6.13, or thereabouts.

-- 
Alan Mackenzie (Nuremberg, Germany).