Skip to contentSkip to conversation

Linux for the PlayStation 2

PATCH In review Fredrik Noring 7 participants 161 messages Sep 1, 2019 – Jan 29, 2022 Page 2 of 2

Subsystems (8)
lore
Share & tools
lore
#127 lore raw

Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2

In reply to Fredrik Noring

Hi Helge,

Thank you for maintaining fbdev! The PlayStation 2 port makes heavy use of it and its acceleration features[1], including tiling operations:

	info->flags = FBINFO_DEFAULT |
		      FBINFO_HWACCEL_COPYAREA |
		      FBINFO_HWACCEL_FILLRECT |
		      FBINFO_HWACCEL_IMAGEBLIT |
		      FBINFO_HWACCEL_XPAN |
		      FBINFO_HWACCEL_YPAN |
		      FBINFO_HWACCEL_YWRAP |
		      FBINFO_PARTIAL_PAN_OK |
		      FBINFO_READS_FAST;

	info->flags |= FBINFO_MISC_TILEBLITTING;
	info->tileops = &tileops;

I attempted a DRM port[2], but my impression is that the DRM subsystem has grave problems in that

- fbset command timing mode settings are ignored;
- attempts to set modes with /sys/class/graphics/fb0/mode are ignored;
- /sys/class/graphics/fb0/modes outputs incorrect refresh rates and types;
- relevant modes are missing in /sys/class/graphics/fb0/modes;
- the standard DRM video modes seem to mix up the sync and front porch timings in struct drm_display_mode but this remains to be confirmed;
- the DRM seems to rely heavily on EDID to negotiate a video resolution, but EDID isn't available with vintage analogue display hardware.

This is only for a (fast and efficient) text console.

My impression is also that the DRM wouldn't do more than displaying a text console, and perhaps an inefficient virtual frame buffer, due to the nature of the Graphics Synthesizer hardware. The complete set of features of the Graphics Synthesizer, and related vector and image processors, seem to go beyond what the DRM subsystem can offer in its current form. I admit that there may possibilities that I haven't seen yet, though. :-)

Some background on the Graphics Synthesizer can be found in [3], as well as in official documentation[4][5]. Many of its command primitives are defined in [6][7], and there is more to it with the data paths from various co-processors, etc.

Note: The fbdev patch below was, at the time, submitted in a series of 18 patches related to fbdev for PlayStation 2. See the complete ps2fb.c[1].

References:

[1] https://github.com/frno7/linux/blob/ps2-main/drivers/video/fbdev/ps2fb.c
[2] https://github.com/frno7/linux/tree/ps2-main/drivers/gpu/drm/gs
[3] https://github.com/frno7/linux/wiki/The-Graphics-Synthesizer
[4] EE User's Manual, version 6.0, Sony Computer Entertainment Inc.
[5] GS User's Manual, version 6.0, Sony Computer Entertainment Inc.
[6] https://github.com/frno7/linux/blob/ps2-main/arch/mips/include/uapi/asm/gs.h
[7] https://github.com/frno7/linux/blob/ps2-main/arch/mips/include/uapi/asm/gif.h

Fredrik

Quoted 632 lines · Fredrik Noring

The main limitation is the lack of mmap, since the Graphics Synthesizer has local frame buffer memory that is not directly accessible from the main bus. The GS has 4 MiB of local memory.

The console drawing primitives are synchronous to allow printk at any time. This is highly useful for debugging but it is not the fastest possible implementation. The console is nevertheless very fast and makes use of several hardware accelerated features of the Graphics Synthesizer.

The maximum practical resolution is 1920x1080p at 16 bits per pixel that requires 4147200 bytes of local memory, leaving 47104 bytes for a tiled font, which at 8x8 pixels and a minimum 4 bits indexed texture palette is at most 1464 characters. The indexed palette makes switching colours easy. &struct fb_tile_ops is accelerated with GS texture sprites that are fast (GS local copy) for the kernel via simple DMA GS commands via the GIF.

---
 drivers/video/fbdev/Kconfig    |  12 +
 drivers/video/fbdev/Makefile   |   1 +
 drivers/video/fbdev/ps2fb.c    | 533 +++++++++++++++++++++++++++++++++
 include/linux/console_struct.h |   2 +
 include/uapi/linux/fb.h        |   1 +
 5 files changed, 549 insertions(+)
 create mode 100644 drivers/video/fbdev/ps2fb.c
drivers/video/fbdev/Kconfig +12 -0
index 6b2de93bd302..cc93cbd67b01 100644
@@ -1999,6 +1999,18 @@ config FB_IBM_GXT4500
 	  doesn't use Geometry Engine GT1000. This driver also supports
 	  AGP Fire GL2/3/4 cards on x86.
 
+# FIXME FB_SYS_*
+config FB_PS2
+	tristate "Frame buffer driver for Sony Playstation 2"
+	depends on FB && SONY_PS2
+	select PS2_GS
+	select FB_TILEBLITTING
+	default y
+	help
+	  Frame buffer driver for the Sony Playstation 2 Graphics Synthesizer.
+	  Memory mapping is not supported since the frame buffer is local to
+	  the GS.
+
 config FB_PS3
 	tristate "PS3 GPU framebuffer driver"
 	depends on FB && PS3_PS3AV
drivers/video/fbdev/Makefile +1 -0
index 7dc4861a93e6..1e55fa8ca4af 100644
@@ -105,6 +105,7 @@ obj-$(CONFIG_FB_S3C2410)	  += s3c2410fb.o
 obj-$(CONFIG_FB_FSL_DIU)	  += fsl-diu-fb.o
 obj-$(CONFIG_FB_COBALT)           += cobalt_lcdfb.o
 obj-$(CONFIG_FB_IBM_GXT4500)	  += gxt4500.o
+obj-$(CONFIG_FB_PS2)		  += ps2fb.o
 obj-$(CONFIG_FB_PS3)		  += ps3fb.o
 obj-$(CONFIG_FB_SM501)            += sm501fb.o
 obj-$(CONFIG_FB_UDL)		  += udlfb.o
drivers/video/fbdev/ps2fb.c new file +533 -0
new file mode 100644
index 000000000000..7bfbc3c2aa4d
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PlayStation 2 frame buffer driver
+ *
+ * Copyright (C) 2019 Fredrik Noring
+ */
+
+/**
+ * DOC: The PlayStation 2 frame buffer console
+ *
+ * The frame buffer supports a tiled frame buffer console. The main limitation
+ * is the lack of memory mapping (mmap), since the Graphics Synthesizer has
+ * local frame buffer memory that is not directly accessible from the main bus.
+ * The GS has 4 MiB of local memory.
+ *
+ * The console drawing primitives are synchronous to allow printk at any time.
+ * This is highly useful for debugging but it is not the fastest possible
+ * implementation. The console is nevertheless very fast and makes use of
+ * several hardware accelerated features of the Graphics Synthesizer.
+ *
+ * The maximum practical resolution is 1920x1080p at 16 bits per pixel that
+ * requires 4147200 bytes of local memory, leaving 47104 bytes for a tiled
+ * font, which at 8x8 pixels and a minimum 4 bits indexed texture palette is
+ * at most 1464 characters. The indexed palette makes switching colours easy.
+ * &struct fb_tile_ops is accelerated with GS texture sprites that are fast
+ * (GS local copy) for the kernel via simple DMA GS commands via the GIF.
+ *
+ * The local memory is organised as follows: first comes the display buffer,
+ * then one block of a palette, and finally the font installed as a texture.
+ *
+ * All frame buffer transmissions are done by DMA via GIF PATH3.
+ */
+
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/fb.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/string.h>
+#include <linux/uaccess.h>
+
+#include <asm/io.h>
+
+#include <asm/mach-ps2/dmac.h>
+#include <asm/mach-ps2/gif.h>
+#include <asm/mach-ps2/gs.h>
+#include <asm/mach-ps2/gs-registers.h>
+
+#include <uapi/asm/gif.h>
+#include <uapi/asm/gs.h>
+
+#define DEVICE_NAME "ps2fb"
+
+#define PALETTE_BLOCK_COUNT 1	/* One block is used for the indexed colors */
+
+/* Module parameters */
+static char *mode_option;
+
+union package {
+	union gif_data gif;
+	struct dma_tag dma;
+};
+
+/**
+ * struct tile_texture - texture representing a tile
+ * @tbp: texture base pointer
+ * @u: texel u coordinate (x coordinate)
+ * @v: texel v coordinate (y coordinate)
+ */
+struct tile_texture {
+	u32 tbp;
+	u32 u;
+	u32 v;
+};
+
+/**
+ * struct console_buffer - console buffer
+ * @block_count: number of frame buffer blocks
+ * @bg: background color index
+ * @fg: foreground color index
+ * @tile: tile dimensions
+ * @tile.width: width in pixels
+ * @tile.height: height in pixels
+ * @tile.width2: least width in pixels, power of 2
+ * @tile.height2: least height in pixels, power of 2
+ * @tile.block: tiles are stored as textures in the PSMT4 pixel storage format
+ * 	with both cols and rows as powers of 2
+ * @tile.block.cols: tile columns per GS block
+ * @tile.block.rows: tile rows per GS block
+ */
+struct console_buffer {
+	u32 block_count;
+
+	u32 bg;
+	u32 fg;
+
+	struct cb_tile {
+		u32 width;
+		u32 height;
+
+		u32 width2;
+		u32 height2;
+
+		struct {
+			u32 cols;
+			u32 rows;
+		} block;
+	} tile;
+};
+
+/**
+ * struct ps2fb_par - driver specific structure
+ * @lock: spin lock to be taken for all structure operations
+ * @cb: console buffer definition
+ * @package: tags and datafor the GIF
+ * @package.capacity: maximum number of GIF packages in 16-byte unit
+ * @package.buffer: DMA buffer for GIF packages
+ */
+struct ps2fb_par {
+	spinlock_t lock;
+
+	struct console_buffer cb;
+
+	struct {
+		size_t capacity;
+		union package *buffer;
+	} package;
+};
+
+/**
+ * texture_least_power_of_2 - round up to a power of 2, not less than 8
+ * @n: integer to round up
+ *
+ * Return: least integer that is a power of 2 and not less than @n or 8
+ */
+static u32 texture_least_power_of_2(u32 n)
+{
+	return max(1 << get_count_order(n), 8);
+}
+
+/**
+ * cb_tile - create a console buffer tile object
+ * @width: width of tile in pixels
+ * @height: height of tile in pixels
+ *
+ * Return: a console buffer tile object with the given width and height
+ */
+static struct cb_tile cb_tile(u32 width, u32 height)
+{
+	const u32 width2 = texture_least_power_of_2(width);
+	const u32 height2 = texture_least_power_of_2(height);
+
+	return (struct cb_tile) {
+		.width = width,
+		.height = height,
+
+		.width2 = width2,
+		.height2 = height2,
+
+		.block = {
+			.cols = GS_PSMT4_BLOCK_WIDTH / width2,
+			.rows = GS_PSMT4_BLOCK_HEIGHT / height2,
+		},
+	};
+}
+
+/**
+ * display_buffer_size - display buffer size for a given video resolution
+ *
+ * This calculation is a lower bound estimate. A precise calculation would have
+ * to take memory pages, blocks and column arrangements into account. To choose
+ * the appropriate standard video mode such details can be disregarded, though.
+ *
+ * Return: the size in bytes of the display buffer
+ */
+static u32 display_buffer_size(const u32 xres_virtual, const u32 yres_virtual,
+      const u32 bits_per_pixel)
+{
+	return (xres_virtual * yres_virtual * bits_per_pixel) / 8;
+}
+
+/**
+ * ps2fb_cb_get_tilemax - maximum number of tiles
+ * @info: frame buffer info object
+ *
+ * Return: the maximum number of tiles
+ */
+static int ps2fb_cb_get_tilemax(struct fb_info *info)
+{
+	const struct ps2fb_par *par = info->par;
+	const u32 block_tile_count =
+		par->cb.tile.block.cols *
+		par->cb.tile.block.rows;
+	const s32 blocks_available =
+		GS_BLOCK_COUNT - par->cb.block_count - PALETTE_BLOCK_COUNT;
+
+	return blocks_available > 0 ? blocks_available * block_tile_count : 0;
+}
+
+/**
+ * bits_per_pixel_fits - does the given resolution fit the given buffer size?
+ * @xres_virtual: virtual x resolution in pixels
+ * @yres_virtual: virtual y resolution in pixels
+ * @bits_per_pixel: number of bits per pixel
+ * @buffer_size: size in bytes of display buffer
+ *
+ * The size calculation is approximate, but accurate enough for the standard
+ * video modes.
+ *
+ * Return: %true if the resolution fits the given buffer size, otherwise %false
+ */
+static bool bits_per_pixel_fits(const u32 xres_virtual, const u32 yres_virtual,
+      const int bits_per_pixel, const size_t buffer_size)
+{
+	return display_buffer_size(xres_virtual, yres_virtual,
+		bits_per_pixel) <= buffer_size;
+}
+
+/**
+ * default_bits_per_pixel - choose either 16 or 32 bits per pixel
+ * @xres_virtual: virtual x resolution in pixels
+ * @yres_virtual: virtual y resolution in pixels
+ * @buffer_size: size in bytes of display buffer
+ *
+ * 32 bits per pixel is returned unless this does not fit the given buffer size.
+ *
+ * The size calculation is approximate, but accurate enough for the standard
+ * video modes.
+ *
+ * Return: 16 or 32 bits per pixel
+ */
+static int default_bits_per_pixel(
+	const u32 xres_virtual, const u32 yres_virtual,
+	const size_t buffer_size)
+{
+	return bits_per_pixel_fits(xres_virtual, yres_virtual,
+		32, buffer_size) ? 32 : 16;
+}
+
+/**
+ * filled_var_videomode - is the screen info video mode filled in?
+ * @var: screen info object to check
+ *
+ * Return: %true if the video mode is filled in, otherwise %false
+ */
+static bool filled_var_videomode(const struct fb_var_screeninfo *var)
+{
+	return var->xres > 0 && var->hsync_len > 0 &&
+	       var->yres > 0 && var->vsync_len > 0 && var->pixclock > 0;
+}
+
+static int ps2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+	/* Check whether video mode defaults are needed. */
+	if (!filled_var_videomode(var)) {
+		const struct fb_videomode *vm =
+			fb_find_best_mode(var, &info->modelist);
+
+		if (!vm)
+			return -EINVAL;
+
+		fb_videomode_to_var(var, vm);
+	}
+
+        /* GS video register resolution is limited to 2048. */
+        if (var->xres < 1 || 2048 < var->xres ||
+	    var->yres < 1 || 2048 < var->yres)
+		return -EINVAL;
+
+	var->xres_virtual = var->xres;
+	var->yres_virtual = var->yres;
+	var->xoffset = 0;
+	var->yoffset = 0;
+
+        /* Check bits per pixel. */
+        if (!var->bits_per_pixel)
+		var->bits_per_pixel = default_bits_per_pixel(
+		     var->xres_virtual, var->yres_virtual, info->fix.smem_len);
+	else if (var->bits_per_pixel != 16 &&
+		 var->bits_per_pixel != 32)
+		return -EINVAL;
+        if (!bits_per_pixel_fits(var->xres_virtual, var->yres_virtual,
+			var->bits_per_pixel, info->fix.smem_len))
+		var->bits_per_pixel = default_bits_per_pixel(
+		     var->xres_virtual, var->yres_virtual, info->fix.smem_len);
+        if (!bits_per_pixel_fits(var->xres_virtual, var->yres_virtual,
+			var->bits_per_pixel, info->fix.smem_len))
+		return -ENOMEM;
+	if (var->bits_per_pixel == 16) {
+		var->red    = (struct fb_bitfield){ .offset =  0, .length = 5 };
+		var->green  = (struct fb_bitfield){ .offset =  5, .length = 5 };
+		var->blue   = (struct fb_bitfield){ .offset = 10, .length = 5 };
+		var->transp = (struct fb_bitfield){ .offset = 15, .length = 1 };
+	} else if (var->bits_per_pixel == 32) {
+		var->red    = (struct fb_bitfield){ .offset =  0, .length = 8 };
+		var->green  = (struct fb_bitfield){ .offset =  8, .length = 8 };
+		var->blue   = (struct fb_bitfield){ .offset = 16, .length = 8 };
+		var->transp = (struct fb_bitfield){ .offset = 24, .length = 8 };
+	} else
+		return -EINVAL;		/* Unsupported bits per pixel. */
+
+        /* Screen rotations are not supported. */
+	if (var->rotate)
+		return -EINVAL;
+
+        return 0;
+}
+
+static int ps2fb_cb_check_var(
+	struct fb_var_screeninfo *var, struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+	int err;
+
+	spin_lock_irqsave(&par->lock, flags);
+	err = ps2fb_check_var(var, info);
+	spin_unlock_irqrestore(&par->lock, flags);
+
+	if (!err && info->tileops)
+		if (info->tileops->fb_get_tilemax(info) < 256)
+			err = -ENOMEM;
+
+	return err;
+}
+
+static u32 block_dimensions(u32 dim, u32 alignment)
+{
+	u32 mask = 0;
+	u32 d;
+
+	for (d = 1; d <= dim; d++)
+		if (d % alignment == 0)
+			mask |= 1 << (d - 1);
+
+	return mask;
+}
+
+static int init_console_buffer(struct platform_device *pdev,
+	struct fb_info *info)
+{
+	static struct fb_ops fbops = {
+		.owner		= THIS_MODULE,
+		.fb_check_var	= ps2fb_cb_check_var,
+	};
+
+	static struct fb_tile_ops tileops = {
+		.fb_get_tilemax = ps2fb_cb_get_tilemax
+	};
+
+	struct ps2fb_par *par = info->par;
+
+	fb_info(info, "Graphics Synthesizer console frame buffer device\n");
+
+	info->screen_size = 0;
+	info->screen_base = NULL;	/* mmap is unsupported by hardware */
+
+	info->fix.smem_start = 0;	/* GS frame buffer is local memory */
+	info->fix.smem_len = GS_MEMORY_SIZE;
+
+	info->fbops = &fbops;
+	info->flags = FBINFO_DEFAULT |
+		      FBINFO_READS_FAST;
+
+	info->flags |= FBINFO_MISC_TILEBLITTING;
+	info->tileops = &tileops;
+
+	/*
+	 * BITBLTBUF for pixel format CT32 requires divisibility by 2,
+	 * and CT16 requires divisibility by 4. So 4 is a safe choice.
+	 */
+	info->pixmap.blit_x = block_dimensions(GS_PSMT4_BLOCK_WIDTH, 4);
+	info->pixmap.blit_y = block_dimensions(GS_PSMT4_BLOCK_HEIGHT, 1);
+
+	/* 8x8 default font tile size for fb_get_tilemax */
+	par->cb.tile = cb_tile(8, 8);
+
+	return 0;
+}
+
+static int ps2fb_probe(struct platform_device *pdev)
+{
+	struct ps2fb_par *par;
+	struct fb_info *info;
+	int err;
+
+	info = framebuffer_alloc(sizeof(*par), &pdev->dev);
+	if (info == NULL) {
+		dev_err(&pdev->dev, "framebuffer_alloc failed\n");
+		err = -ENOMEM;
+		goto err_framebuffer_alloc;
+	}
+
+	par = info->par;
+
+	spin_lock_init(&par->lock);
+
+	par->package.buffer = (union package *)__get_free_page(GFP_DMA);
+	if (!par->package.buffer) {
+		dev_err(&pdev->dev, "Failed to allocate package buffer\n");
+		err = -ENOMEM;
+		goto err_package_buffer;
+	}
+	par->package.capacity = PAGE_SIZE / sizeof(union package);
+
+	strlcpy(info->fix.id, "PS2 GS", ARRAY_SIZE(info->fix.id));
+	info->fix.accel = FB_ACCEL_PLAYSTATION_2;
+
+	err = init_console_buffer(pdev, info);
+	if (err < 0)
+		goto err_init_buffer;
+
+	info->mode = &par->mode;
+
+	if (register_framebuffer(info) < 0) {
+		fb_err(info, "register_framebuffer failed\n");
+		err = -EINVAL;
+		goto err_register_framebuffer;
+	}
+
+	platform_set_drvdata(pdev, info);
+
+	return 0;
+
+err_register_framebuffer:
+err_init_buffer:
+	free_page((unsigned long)par->package.buffer);
+err_package_buffer:
+	framebuffer_release(info);
+err_framebuffer_alloc:
+	return err;
+}
+
+static int ps2fb_remove(struct platform_device *pdev)
+{
+	struct fb_info *info = platform_get_drvdata(pdev);
+	struct ps2fb_par *par = info->par;
+	int err = 0;
+
+	if (info != NULL) {
+		unregister_framebuffer(info);
+		fb_dealloc_cmap(&info->cmap);
+
+		framebuffer_release(info);
+	}
+
+	if (!gif_wait()) {
+		fb_err(info, "Failed to complete GIF DMA transfer\n");
+		err = -EBUSY;
+	}
+	free_page((unsigned long)par->package.buffer);
+
+	return err;
+}
+
+static struct platform_driver ps2fb_driver = {
+	.probe		= ps2fb_probe,
+	.remove		= ps2fb_remove,
+	.driver = {
+		.name	= DEVICE_NAME,
+	},
+};
+
+static struct platform_device *ps2fb_device;
+
+static int __init ps2fb_init(void)
+{
+	int err;
+
+#ifndef MODULE
+	char *options = NULL;
+	char *this_opt;
+
+	if (fb_get_options(DEVICE_NAME, &options))
+		return -ENODEV;
+	if (!options || !*options)
+		goto no_options;
+
+	while ((this_opt = strsep(&options, ",")) != NULL) {
+		if (!*this_opt)
+			continue;
+
+		if (!strncmp(this_opt, "mode_option:", 12))
+			mode_option = &this_opt[12];
+		else if ('0' <= this_opt[0] && this_opt[0] <= '9')
+			mode_option = this_opt;
+		else
+			pr_warn(DEVICE_NAME ": Unrecognized option \"%s\"\n",
+				this_opt);
+	}
+
+no_options:
+#endif /* !MODULE */
+
+	/* Default to a suitable PAL or NTSC broadcast mode. */
+	if (!mode_option)
+		mode_option = gs_region_pal() ? "576x460i@50" : "576x384i@60";
+
+	ps2fb_device = platform_device_alloc("ps2fb", 0);
+	if (!ps2fb_device)
+		return -ENOMEM;
+
+	err = platform_device_add(ps2fb_device);
+	if (err < 0) {
+		platform_device_put(ps2fb_device);
+		return err;
+	}
+
+	return platform_driver_register(&ps2fb_driver);
+}
+
+static void __exit ps2fb_exit(void)
+{
+	platform_driver_unregister(&ps2fb_driver);
+	platform_device_unregister(ps2fb_device);
+}
+
+module_init(ps2fb_init);
+module_exit(ps2fb_exit);
+
+module_param(mode_option, charp, 0);
+MODULE_PARM_DESC(mode_option,
+	"Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
+
+MODULE_DESCRIPTION("PlayStation 2 frame buffer driver");
+MODULE_AUTHOR("Fredrik Noring");
+MODULE_LICENSE("GPL");
include/linux/console_struct.h +2 -0
index 24d4c16e3ae0..cb562672cc3a 100644
@@ -13,9 +13,11 @@
 #ifndef _LINUX_CONSOLE_STRUCT_H
 #define _LINUX_CONSOLE_STRUCT_H
 
+#include <linux/tty.h>
 #include <linux/wait.h>
 #include <linux/vt.h>
 #include <linux/workqueue.h>
+#include <uapi/linux/kd.h>
 
 struct uni_pagedir;
 struct uni_screen;
include/uapi/linux/fb.h +1 -0
index b6aac7ee1f67..38d88eebf651 100644
@@ -149,6 +149,7 @@
 #define FB_ACCEL_SUPERSAVAGE    0x8c    /* S3 Supersavage               */
 #define FB_ACCEL_PROSAVAGE_DDR  0x8d	/* S3 ProSavage DDR             */
 #define FB_ACCEL_PROSAVAGE_DDRK 0x8e	/* S3 ProSavage DDR-K           */
+#define FB_ACCEL_PLAYSTATION_2  0x8f	/* PlayStation 2                */
 
 #define FB_ACCEL_PUV3_UNIGFX	0xa0	/* PKUnity-v3 Unigfx		*/
 
Signature · 1 line
2.21.0
#128 lore raw

PATCH 95/120 MIPS: PS2: FB: fb_set_par() standard-definition television support

In reply to Fredrik Noring

Most of the computations for the video synchronisation registers are based on trial an error, as their bit fields are undocumented. A small set of standard video modes are supplied with the Graphics Synthesizer user manual[1], and for these modes the corresponding register values are known.

This frame buffer driver allows arbitrary top, bottom, left and right video display margin (border) adjustments, hence registers are computed instead of tabulated. This is useful to for example precisely center the image for a given analogue video display.

The SDTV modes are designed to work with S-video, SCART and component video cables, in addition to the PS2 HDMI adapter based on the Macro Silicon MS9282 chip.

The MAGV and MAGH fields for vertical and horizontal magnification in the DISPLAY registers could be used to support lower resolution video modes, for example 320x200 that was popular with many 8-bit and 16-bit computers, but that is left for a future extension.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 84.
---
 drivers/video/fbdev/ps2fb.c | 328 ++++++++++++++++++++++++++++++++++++
 1 file changed, 328 insertions(+)
drivers/video/fbdev/ps2fb.c +328 -0
index 7bfbc3c2aa4d..3fb31719459c 100644
@@ -133,6 +133,97 @@ struct ps2fb_par {
 	} package;
 };
 
+/**
+ * struct gs_sync_param - Graphics Synthesizer registers for video modes
+ * @smode1: SMODE1 register
+ * @smode2: SMODE2 register
+ * @srfsh: SRFSH register
+ * @synch1: SYNCH1 register
+ * @synch2: SYNCH2 register
+ * @syncv: SYNCV register
+ * @display: DISPLAY1 or DISPLAY2 register
+ *
+ * These are the essential Graphics Synthesizer video synchronisation register
+ * parameters.
+ */
+struct gs_sync_param {
+	struct gs_smode1 smode1;
+	struct gs_smode2 smode2;
+	struct gs_srfsh srfsh;
+	struct gs_synch1 synch1;
+	struct gs_synch2 synch2;
+	struct gs_syncv syncv;
+	struct gs_display display;
+};
+
+/**
+ * var_to_fbw - frame buffer width for a given virtual x resolution
+ * @var: screen info object to compute FBW for
+ *
+ * Return: frame buffer width (FBW) in 64-pixel unit
+ */
+static u32 var_to_fbw(const struct fb_var_screeninfo *var)
+{
+	/*
+	 * Round up to nearest GS_FB_PAGE_WIDTH (64 px) since there are
+	 * valid resolutions such as 720 px that do not divide 64 properly.
+	 */
+	return (var->xres_virtual + GS_FB_PAGE_WIDTH - 1) / GS_FB_PAGE_WIDTH;
+}
+
+/**
+ * var_to_psm - frame buffer pixel storage mode for a given bits per pixel
+ * @var: screen info object to compute PSM for
+ * @info: frame buffer info object
+ *
+ * Return: frame buffer pixel storage mode
+ */
+static enum gs_psm var_to_psm(const struct fb_var_screeninfo *var,
+	const struct fb_info *info)
+{
+	if (var->bits_per_pixel == 1)
+		return gs_psm_ct16;
+	if (var->bits_per_pixel == 16)
+		return gs_psm_ct16;
+	if (var->bits_per_pixel == 32)
+		return gs_psm_ct32;
+
+	fb_warn_once(info, "%s: Unsupported bits per pixel %u\n",
+		__func__, var->bits_per_pixel);
+	return gs_psm_ct32;
+}
+
+/**
+ * var_to_block_count - number of frame buffer blocks for a given video mode
+ * @var: screen info object to compute the number of blocks for
+ *
+ * The Graphics Synthesizer frame buffer is subdivided into rectangular pages,
+ * from left to right, top to bottom. Pages are further subdivided into blocks,
+ * with different arrangements for PSMCT16 and PSMCT32. Blocks are further
+ * subdivided into columns, which are finally subdivided into pixels.
+ *
+ * The video display buffer, textures and palettes share the same frame buffer.
+ * This function can be used to compute the first free block after the video
+ * display buffer.
+ *
+ * Return: number of blocks, or zero for unsupported pixel storage modes
+ */
+static u32 var_to_block_count(const struct fb_info *info)
+{
+	const struct fb_var_screeninfo *var = &info->var;
+	const enum gs_psm psm = var_to_psm(var, info);
+	const u32 fbw = var_to_fbw(var);
+
+	if (psm == gs_psm_ct16)
+		return gs_psm_ct16_block_count(fbw, var->yres_virtual);
+	if (psm == gs_psm_ct32)
+		return gs_psm_ct32_block_count(fbw, var->yres_virtual);
+
+	fb_warn_once(info, "%s: Unsupported pixel storage mode %u\n",
+		__func__, psm);
+	return 0;
+}
+
 /**
  * texture_least_power_of_2 - round up to a power of 2, not less than 8
  * @n: integer to round up
@@ -330,6 +421,242 @@ static int ps2fb_cb_check_var(
 	return err;
 }
 
+/**
+ * refresh_for_var - display refresh frequency for a given screen info
+ * @var: screen info object to compute the display frequency for
+ *
+ * Return: display refresh frequency in hertz
+ */
+static u32 refresh_for_var(const struct fb_var_screeninfo *var)
+{
+	const u32 htotal = var->hsync_len +
+		var->left_margin + var->xres + var->right_margin;
+	const u32 vtotal = var->vsync_len +
+		var->upper_margin + var->yres + var->lower_margin;
+	const u32 ptotal = htotal * vtotal;
+
+	return DIV_ROUND_CLOSEST_ULL(DIV_ROUND_CLOSEST_ULL(
+		1000000000000ull * ((var->vmode & FB_VMODE_INTERLACED) ? 2 : 1),
+		var->pixclock), ptotal);
+}
+
+/**
+ * vm_to_cmod - determine the CMOD field for the SMODE1 register
+ * @vm: video mode object to compute CMOD for
+ *
+ * Result: PAL, NTSC or VESA
+ */
+static enum gs_smode1_cmod vm_to_cmod(const struct fb_videomode *vm)
+{
+	const u32 htotal = vm->hsync_len +
+		vm->left_margin + vm->xres + vm->right_margin;
+	const u32 vtotal = vm->vsync_len +
+		vm->upper_margin + vm->yres + vm->lower_margin;
+	const u32 ptotal = htotal * vtotal;
+	const u32 refresh = DIV_ROUND_CLOSEST_ULL(DIV_ROUND_CLOSEST_ULL(
+		1000000000000ull * ((vm->vmode & FB_VMODE_INTERLACED) ? 2 : 1),
+		vm->pixclock), ptotal);
+
+	if (vm->sync & FB_SYNC_BROADCAST)
+		return refresh < 55 ? gs_cmod_pal :
+		       refresh < 65 ? gs_cmod_ntsc :
+				      gs_cmod_vesa;
+
+	return gs_cmod_vesa;
+}
+
+/**
+ * vm_to_sp_sdtv - standard-definition television video synch parameters
+ * @vm: video mode object to compute synchronisation parameters for
+ *
+ * The numeric register field constants come from fixed SDTV video modes made
+ * by Sony. The main complication is that these values are the basis to compute
+ * arbitrary top, bottom, left and right display margin (border) settings for
+ * both PAL and NTSC. This is useful to for example precisely center the image
+ * for a given analogue video display.
+ *
+ * The SDTV modes are designed to work with S-video, SCART and component video
+ * cables, in addition to the PS2 HDMI adapter based on the Macro Silicon
+ * MS9282 chip.
+ *
+ * The MAGV and MAGH fields for vertical and horizontal magnification in the
+ * DISPLAY registers could be used to support lower resolution video modes,
+ * for example 320x200 that was popular with many 8-bit and 16-bit computers,
+ * but that is left for a future extension.
+ *
+ * Return: Graphics Synthesizer SDTV video mode synchronisation parameters
+ */
+static struct gs_sync_param vm_to_sp_sdtv(const struct fb_videomode *vm)
+{
+	const u32 cmod = vm_to_cmod(vm);
+	const u32 intm = (vm->vmode & FB_VMODE_INTERLACED) ? 1 : 0;
+	const u32 vs   = cmod == gs_cmod_pal ? 5 : 6;
+	const u32 hb   = cmod == gs_cmod_pal ? 1680 : 1652;
+	const u32 hf   = 2892 - hb;
+	const u32 hs   = 254;
+	const u32 hbp  = cmod == gs_cmod_pal ? 262 : 222;
+	const u32 hfp  = cmod == gs_cmod_pal ? 48 : 64;
+	const u32 vdp  = cmod == gs_cmod_pal ? 576 : 480;
+	const u32 vbpe = vs;
+	const u32 vbp  = cmod == gs_cmod_pal ? 33 : 26;
+	const u32 vfpe = vs;
+	const u32 vfp  = (vm->vmode & FB_VMODE_INTERLACED) ? 1 :
+		cmod == gs_cmod_pal ? 4 : 2;
+	const u32 tw = hb + hf;
+	const u32 th = vdp;
+	const u32 dw = min_t(u32, vm->xres * 4, tw);
+	const u32 dh = min_t(u32, vm->yres * (intm ? 1 : 2), th);
+	const u32 dx = hs + hbp + (tw - dw)/2 - 1;
+	const u32 dy = (vs + vbp + vbpe + (th - dh)/2) / (intm ? 1 : 2) - 1;
+
+	return (struct gs_sync_param) {
+		.smode1 = {
+			.vhp    =    0, .vcksel = 1, .slck2 = 1, .nvck = 1,
+			.clksel =    1, .pevs   = 0, .pehs  = 0, .pvs  = 0,
+			.phs    =    0, .gcont  = 0, .spml  = 4, .pck2 = 0,
+			.xpck   =    0, .sint   = 1, .prst  = 0, .ex   = 0,
+			.cmod   = cmod, .slck   = 0, .t1248 = 1,
+			.lc     =   32, .rc     = 4
+		},
+		.smode2 = {
+			.intm = intm
+		},
+		.srfsh = {
+			.rfsh = 8
+		},
+		.synch1 = {
+			.hs   = hs,
+			.hsvs = cmod == gs_cmod_pal ? 1474 : 1462,
+			.hseq = cmod == gs_cmod_pal ? 127 : 124,
+			.hbp  = hbp,
+			.hfp  = hfp
+		},
+		.synch2 = {
+			.hb = hb,
+			.hf = hf
+		},
+		.syncv = {
+			.vs   = vs,
+			.vdp  = vdp,
+			.vbpe = vbpe,
+			.vbp  = vbp,
+			.vfpe = vfpe,
+			.vfp  = vfp
+		},
+		.display = {
+			.dh   = vm->yres - 1,
+			.dw   = vm->xres * 4 - 1,
+			.magv = 0,
+			.magh = 3,
+			.dy   = dy,
+			.dx   = dx
+		}
+	};
+}
+
+static struct gs_sync_param vm_to_sp_for_synch_gen(
+	const struct fb_videomode *vm, const struct gs_synch_gen sg)
+{
+	struct gs_sync_param sp = vm_to_sp_sdtv(vm);
+
+	sp.smode1.gcont = gs_gcont_ycrcb;
+	sp.smode1.sint = 1;
+	sp.smode1.prst = 0;
+
+	return sp;
+}
+
+static struct gs_sync_param vm_to_sp(const struct fb_videomode *vm)
+{
+	return vm_to_sp_for_synch_gen(vm, gs_synch_gen_for_vck(vm->pixclock));
+}
+
+static int ps2fb_set_par(struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	const struct fb_var_screeninfo *var = &info->var;
+	const struct fb_videomode *mm = fb_match_mode(var, &info->modelist);
+	const struct fb_videomode vm = (struct fb_videomode) {
+		.refresh      = refresh_for_var(var),
+		.xres         = var->xres,
+		.yres         = var->yres,
+		.pixclock     = var->pixclock,
+		.left_margin  = var->left_margin,
+		.right_margin = var->right_margin,
+		.upper_margin = var->upper_margin,
+		.lower_margin = var->lower_margin,
+		.hsync_len    = var->hsync_len,
+		.vsync_len    = var->vsync_len,
+		.sync         = var->sync,
+		.vmode        = var->vmode,
+		.flag         = mm != NULL ? mm->flag : 0
+	};
+	const struct gs_sync_param sp = vm_to_sp(&vm);
+	struct gs_smode1 smode1 = sp.smode1;
+
+	par->mode = vm;
+
+	info->fix.type = FB_TYPE_PACKED_PIXELS;
+	info->fix.visual = FB_VISUAL_TRUECOLOR;
+	info->fix.xpanstep = 0;
+	info->fix.ypanstep = 0;
+	info->fix.ywrapstep = 1;
+	info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
+
+	gs_write_smode1(smode1);
+	gs_write_smode2(sp.smode2);
+	gs_write_srfsh(sp.srfsh);
+	gs_write_synch1(sp.synch1);
+	gs_write_synch2(sp.synch2);
+	gs_write_syncv(sp.syncv);
+	gs_write_display1(sp.display);
+
+	GS_WRITE_DISPFB1(
+		.fbw = var_to_fbw(var),
+		.psm = var_to_psm(var, info),
+		.dbx = var->xoffset,
+		.dby = var->yoffset,
+	);
+
+	GS_WRITE_PMODE(
+		.en1 = 1,
+		.crtmd = 1
+	);
+
+	smode1.prst = 1;
+	gs_write_smode1(smode1);
+
+	udelay(2500);
+
+	smode1.sint = 0;
+	smode1.prst = 0;
+	gs_write_smode1(smode1);
+
+	return 0;
+}
+
+static int ps2fb_cb_set_par(struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+	int err;
+
+	spin_lock_irqsave(&par->lock, flags);
+
+	err = ps2fb_set_par(info);
+	if (!err)
+		par->cb.block_count = var_to_block_count(info);
+
+	spin_unlock_irqrestore(&par->lock, flags);
+
+	if (!err && info->tileops)
+		fb_info(info, "%d tiles maximum for %ux%u font\n",
+			info->tileops->fb_get_tilemax(info),
+			par->cb.tile.width, par->cb.tile.height);
+
+	return err;
+}
+
 static u32 block_dimensions(u32 dim, u32 alignment)
 {
 	u32 mask = 0;
@@ -347,6 +674,7 @@ static int init_console_buffer(struct platform_device *pdev,
 {
 	static struct fb_ops fbops = {
 		.owner		= THIS_MODULE,
+		.fb_set_par	= ps2fb_cb_set_par,
 		.fb_check_var	= ps2fb_cb_check_var,
 	};
 
Signature · 1 line
2.21.0
#129 lore raw

PATCH 96/120 MIPS: PS2: FB: fb_set_par() high-definition television support

In reply to Fredrik Noring

Some of the numeric register field constants come from fixed DTV video modes made by Sony[1]. The main complication is that these values are the basis to compute arbitrary top, bottom, left and right display margin (border) settings. This is useful to for example precisely center the image for a given analogue video display.

The HDTV modes are designed to work with component video cables and the PS2 HDMI adapter based on the Macro Silicon MS9282 chip.

The MAGV and MAGH fields for vertical and horizontal magnification in the DISPLAY registers could be used to emulate SDTV resolution video modes such as 320x200 that was popular with many 8-bit and 16-bit computers, but that is left for a future extension.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 84.
---
 drivers/video/fbdev/ps2fb.c | 86 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 85 insertions(+), 1 deletion(-)
drivers/video/fbdev/ps2fb.c +85 -1
index 3fb31719459c..f9061ccc5755 100644
@@ -554,10 +554,94 @@ static struct gs_sync_param vm_to_sp_sdtv(const struct fb_videomode *vm)
 	};
 }
 
+/**
+ * vm_to_sp_hdtv - high-definition television video synch parameters
+ * @vm: video mode object to compute synchronisation parameters for
+ * @sg: Graphics Synthesizer SMODE1 register video clock fields
+ *
+ * Some of the numeric register field constants come from fixed DTV video
+ * modes made by Sony. The main complication is that these values are the
+ * basis to compute arbitrary top, bottom, left and right display margin
+ * (border) settings. This is useful to for example precisely center the
+ * image for a given analogue video display.
+ *
+ * The HDTV modes are designed to work with component video cables and the
+ * PS2 HDMI adapter based on the Macro Silicon MS9282 chip.
+ *
+ * The MAGV and MAGH fields for vertical and horizontal magnification in the
+ * DISPLAY registers could be used to emulate SDTV resolution video modes such
+ * as 320x200 that was popular with many 8-bit and 16-bit computers, but that
+ * is left for a future extension.
+ *
+ * Return: Graphics Synthesizer HDTV video mode synchronisation parameters
+ */
+static struct gs_sync_param vm_to_sp_hdtv(
+	const struct fb_videomode *vm, const struct gs_synch_gen sg)
+{
+	const u32 spml  = sg.spml;
+	const u32 t1248 = sg.t1248;
+	const u32 lc    = sg.lc;
+	const u32 rc    = sg.rc;
+	const u32 vc    = vm->yres <= 576 ? 1 : 0;
+	const u32 hadj  = spml / 2;
+	const u32 vhp   = (vm->vmode & FB_VMODE_INTERLACED) ? 0 : 1;
+	const u32 hb    = vm->xres * spml * 3 / 5;
+
+	return (struct gs_sync_param) {
+		.smode1 = {
+			.vhp    = vhp, .vcksel = vc, .slck2 =     1, .nvck = 1,
+			.clksel =   1, .pevs   =  0, .pehs  =     0, .pvs  = 0,
+			.phs    =   0, .gcont  =  0, .spml  =  spml, .pck2 = 0,
+			.xpck   =   0, .sint   =  1, .prst  =     0, .ex   = 0,
+			.cmod   =   0, .slck   =  0, .t1248 = t1248,
+			.lc     =  lc, .rc     = rc
+		},
+		.smode2 = {
+			.intm = (vm->vmode & FB_VMODE_INTERLACED) ? 1 : 0
+		},
+		.srfsh = {
+			.rfsh = gs_rfsh_from_synch_gen(sg)
+		},
+		.synch1 = {
+			.hs   = vm->hsync_len * spml,
+			.hsvs = (vm->left_margin + vm->xres +
+				 vm->right_margin - vm->hsync_len) * spml / 2,
+			.hseq = vm->hsync_len * spml,
+			.hbp  = vm->left_margin * spml - hadj,
+			.hfp  = vm->right_margin * spml + hadj
+		},
+		.synch2 = {
+			.hb = hb,
+			.hf = vm->xres * spml - hb
+		},
+		.syncv = {
+			.vs   = vm->vsync_len,
+			.vdp  = vm->yres,
+			.vbpe = 0,
+			.vbp  = vm->upper_margin,
+			.vfpe = 0,
+			.vfp  = vm->lower_margin
+		},
+		.display = {
+			.dh   = vm->yres - 1,
+			.dw   = vm->xres * spml - 1,
+			.magv = 0,
+			.magh = spml - 1,
+			.dy   = vm->vsync_len + vm->upper_margin - 1,
+			.dx   = (vm->hsync_len + vm->left_margin) * spml - 1 - hadj
+		}
+	};
+}
+
 static struct gs_sync_param vm_to_sp_for_synch_gen(
 	const struct fb_videomode *vm, const struct gs_synch_gen sg)
 {
-	struct gs_sync_param sp = vm_to_sp_sdtv(vm);
+	const bool bc = vm->sync & FB_SYNC_BROADCAST;
+	const bool il = vm->vmode & FB_VMODE_INTERLACED;
+	struct gs_sync_param sp =
+		vm->yres <= 288 &&       bc ? vm_to_sp_sdtv(vm) :
+		vm->yres <= 576 && il && bc ? vm_to_sp_sdtv(vm) :
+					      vm_to_sp_hdtv(vm, sg);
 
 	sp.smode1.gcont = gs_gcont_ycrcb;
 	sp.smode1.sint = 1;
Signature · 1 line
2.21.0
#130 lore raw

PATCH 97/120 MIPS: PS2: FB: fb_set_par() VESA computer display mode support

In reply to Fredrik Noring

Some of the numeric register field constants come from fixed VESA video modes made by Sony[1]. The main complication is that these values are the basis to compute arbitrary top, bottom, left and right display margin (border) settings. This is useful to for example precisely center the image for a given analogue video display.

The VESA modes are designed to work with the synch-on-green (SOG) VGA cable that Sony distributed with the Linux kit for the PlayStation 2. Modern computer displays typically do not support synch-on-green, so an adapter is most likely necessary for these modes.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 84.
---
 drivers/video/fbdev/ps2fb.c | 78 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)
drivers/video/fbdev/ps2fb.c +77 -1
index f9061ccc5755..dd8b468ab72b 100644
@@ -633,6 +633,81 @@ static struct gs_sync_param vm_to_sp_hdtv(
 	};
 }
 
+/**
+ * vm_to_sp_vesa - VESA computer display mode synch parameters
+ * @vm: video mode object to compute synchronisation parameters for
+ * @sg: Graphics Synthesizer SMODE1 register video clock fields
+ *
+ * Some of the numeric register field constants come from fixed VESA video
+ * modes made by Sony. The main complication is that these values are the
+ * basis to compute arbitrary top, bottom, left and right display margin
+ * (border) settings. This is useful to for example precisely center the
+ * image for a given analogue video display.
+ *
+ * The VESA modes are designed to work with the synch-on-green (SOG) VGA cable
+ * that Sony distributed with the Linux kit for the PlayStation 2. Modern
+ * computer displays typically do not support synch-on-green, so an adapter
+ * is most likely necessary for these modes.
+ *
+ * Return: Graphics Synthesizer VESA display mode synchronisation parameters
+ */
+static struct gs_sync_param vm_to_sp_vesa(
+	const struct fb_videomode *vm, const struct gs_synch_gen sg)
+{
+	const u32 spml  = sg.spml;
+	const u32 t1248 = sg.t1248;
+	const u32 lc    = sg.lc;
+	const u32 rc    = sg.rc;
+	const u32 hadj  = spml / 2;
+	const u32 vhp   = (vm->vmode & FB_VMODE_INTERLACED) ? 0 : 1;
+	const u32 hb    = vm->xres * spml * 3 / 5;
+
+	return (struct gs_sync_param) {
+		.smode1 = {
+			.vhp    = vhp, .vcksel =  0, .slck2 =     1, .nvck = 1,
+			.clksel =   1, .pevs   =  0, .pehs  =     0, .pvs  = 0,
+			.phs    =   0, .gcont  =  0, .spml  =  spml, .pck2 = 0,
+			.xpck   =   0, .sint   =  1, .prst  =     0, .ex   = 0,
+			.cmod   =   0, .slck   =  0, .t1248 = t1248,
+			.lc     =  lc, .rc     = rc
+		},
+		.smode2 = {
+			.intm = (vm->vmode & FB_VMODE_INTERLACED) ? 1 : 0
+		},
+		.srfsh = {
+			.rfsh = gs_rfsh_from_synch_gen(sg)
+		},
+		.synch1 = {
+			.hs   = vm->hsync_len * spml,
+			.hsvs = (vm->left_margin + vm->xres +
+				 vm->right_margin - vm->hsync_len) * spml / 2,
+			.hseq = vm->hsync_len * spml,
+			.hbp  = vm->left_margin * spml - hadj,
+			.hfp  = vm->right_margin * spml + hadj
+		},
+		.synch2 = {
+			.hb = hb,
+			.hf = vm->xres * spml - hb
+		},
+		.syncv = {
+			.vs   = vm->vsync_len,
+			.vdp  = vm->yres,
+			.vbpe = 0,
+			.vbp  = vm->upper_margin,
+			.vfpe = 0,
+			.vfp  = vm->lower_margin
+		},
+		.display = {
+			.dh   = vm->yres - 1,
+			.dw   = vm->xres * spml - 1,
+			.magv = 0,
+			.magh = spml - 1,
+			.dy   = vm->vsync_len + vm->upper_margin - 1,
+			.dx   = (vm->hsync_len + vm->left_margin) * spml - 1 - hadj
+		}
+	};
+}
+
 static struct gs_sync_param vm_to_sp_for_synch_gen(
 	const struct fb_videomode *vm, const struct gs_synch_gen sg)
 {
@@ -641,7 +716,8 @@ static struct gs_sync_param vm_to_sp_for_synch_gen(
 	struct gs_sync_param sp =
 		vm->yres <= 288 &&       bc ? vm_to_sp_sdtv(vm) :
 		vm->yres <= 576 && il && bc ? vm_to_sp_sdtv(vm) :
-					      vm_to_sp_hdtv(vm, sg);
+					 bc ? vm_to_sp_hdtv(vm, sg) :
+					      vm_to_sp_vesa(vm, sg);
 
 	sp.smode1.gcont = gs_gcont_ycrcb;
 	sp.smode1.sint = 1;
Signature · 1 line
2.21.0
#131 lore raw

PATCH 98/120 MIPS: PS2: FB: Preconfigure standard PAL, NTSC and VESA display modes

In reply to Fredrik Noring

These display mode configurations are a combination of modes made by Sony[1] and modes from the PlayStation 3 frame buffer driver (ps3fb.c).

The VESA modes are designed to work with the synch-on-green (SOG) VGA cable that Sony distributed with the Linux kit for the PlayStation 2. Modern computer displays typically do not support synch-on-green, so an adapter is most likely necessary for these modes.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 84.
---
 drivers/video/fbdev/ps2fb.c | 110 ++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
drivers/video/fbdev/ps2fb.c +110 -0
index dd8b468ab72b..a28263474665 100644
@@ -156,6 +156,91 @@ struct gs_sync_param {
 	struct gs_display display;
 };
 
+static const struct fb_videomode standard_modes[] = {
+	/* PAL */
+	{ "256p", 50, 640, 256, 74074, 100, 61, 34, 22, 63, 2,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "288p", 50, 720, 288, 74074, 70, 11, 19, 3, 63, 3,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "512i", 50, 640, 512, 74074, 100, 61, 67, 41, 63, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "576i", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "576p", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "720p", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "1080i", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "1080p", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+
+	/* PAL with borders to ensure that the whole screen is visible */
+	{ "460i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED },
+	{ "460p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+	{ "644p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+	{ "964i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED },
+	{ "964p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+
+	/* NTSC */
+	{ "224p", 60, 640, 224, 74074, 95, 60, 22, 14, 63, 3,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "240p", 60, 720, 240, 74074, 58, 17, 15, 5, 63, 3,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "448i", 60, 640, 448, 74074, 95, 60, 44, 27, 63, 6,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "480i", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "480p", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "720p", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+	{ "1080i", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED, FB_MODE_IS_STANDARD },
+	{ "1080p", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED, FB_MODE_IS_STANDARD },
+
+	/* NTSC with borders to ensure that the whole screen is visible */
+	{ "384i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED },
+	{ "384p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+	{ "644p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+	{ "964i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_INTERLACED },
+	{ "964p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
+	  FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED },
+
+	/* VESA */
+	{ "vesa-1a", 60, 640, 480, 39682,  48, 16, 33, 10, 96, 2,
+	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-1c", 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
+	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-2b", 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
+	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-2d", 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
+	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-3b", 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
+	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-3d", 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
+	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-4a", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
+	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
+	{ "vesa-4b", 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
+	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }
+};
+
 /**
  * var_to_fbw - frame buffer width for a given virtual x resolution
  * @var: screen info object to compute FBW for
@@ -829,6 +914,17 @@ static u32 block_dimensions(u32 dim, u32 alignment)
 	return mask;
 }
 
+static void fill_modes(struct device *dev, struct list_head *head)
+{
+	int i;
+
+	INIT_LIST_HEAD(head);
+
+	for (i = 0; i < ARRAY_SIZE(standard_modes); i++)
+		if (fb_add_videomode(&standard_modes[i], head) < 0)
+			dev_err(dev, "fb_add_videomode failed\n");
+}
+
 static int init_console_buffer(struct platform_device *pdev,
 	struct fb_info *info)
 {
@@ -897,6 +993,8 @@ static int ps2fb_probe(struct platform_device *pdev)
 	}
 	par->package.capacity = PAGE_SIZE / sizeof(union package);
 
+	fill_modes(&pdev->dev, &info->modelist);
+
 	strlcpy(info->fix.id, "PS2 GS", ARRAY_SIZE(info->fix.id));
 	info->fix.accel = FB_ACCEL_PLAYSTATION_2;
 
@@ -904,6 +1002,17 @@ static int ps2fb_probe(struct platform_device *pdev)
 	if (err < 0)
 		goto err_init_buffer;
 
+	fb_info(info, "Mode option is \"%s\"\n", mode_option);
+
+	info->var = (struct fb_var_screeninfo) { };
+	if (!fb_find_mode(&info->var, info, mode_option,
+			standard_modes, ARRAY_SIZE(standard_modes), NULL, 32)) {
+		fb_err(info, "Failed to find video mode \"%s\"\n",
+			mode_option);
+		err = -EINVAL;
+		goto err_find_mode;
+	}
+
 	info->mode = &par->mode;
 
 	if (register_framebuffer(info) < 0) {
@@ -917,6 +1026,7 @@ static int ps2fb_probe(struct platform_device *pdev)
 	return 0;
 
 err_register_framebuffer:
+err_find_mode:
 err_init_buffer:
 	free_page((unsigned long)par->package.buffer);
 err_package_buffer:
Signature · 1 line
2.21.0
#132 lore raw

PATCH 99/120 MIPS: PS2: FB: Reset the Graphics Synthesizer drawing environment

In reply to Fredrik Noring

Various parameters are used to draw Graphics Synthesizer primitives, for example texture information and drawing attributes set by the PRIM register[1]. These parameters are called the drawing environment. The environment remains in effect for multiple primitives until it is reset.

Some environment registers such as XYOFFSET_1 and XYOFFSET_2 represent the same function and can be chosen with the CTXT primitive attribute.

This driver is currently only using the first drawing environment.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    pp. 47-49.
---
 drivers/video/fbdev/ps2fb.c | 198 +++++++++++++++++++++++++++++++++++-
 1 file changed, 197 insertions(+), 1 deletion(-)
drivers/video/fbdev/ps2fb.c +197 -1
index a28263474665..90ddcbe27d43 100644
@@ -59,6 +59,11 @@
 
 #define PALETTE_BLOCK_COUNT 1	/* One block is used for the indexed colors */
 
+#define GIF_PACKAGE_TAG(package) ((package)++)->gif.tag = (struct gif_tag)
+#define GIF_PACKAGE_REG(package) ((package)++)->gif.reg = (struct gif_data_reg)
+#define GIF_PACKAGE_AD(package)  ((package)++)->gif.packed.ad = (struct gif_packed_ad)
+#define DMA_PACKAGE_TAG(package) ((package)++)->dma = (struct dma_tag)
+
 /* Module parameters */
 static char *mode_option;
 
@@ -361,6 +366,194 @@ static u32 display_buffer_size(const u32 xres_virtual, const u32 yres_virtual,
 	return (xres_virtual * yres_virtual * bits_per_pixel) / 8;
 }
 
+/**
+ * struct environment - Graphics Synthesizer drawing environment context
+ * @xres: x resolution in pixels
+ * @yres: y resolution in pixels
+ * @fbw: frame buffer width in 64-pixel unit
+ * @psm: pixel storage mode
+ * @fbp: frame buffer base pointer in 2048-pixel unit
+ */
+struct environment {
+	u32 xres;
+	u32 yres;
+	u32 fbw;
+	enum gs_psm psm;
+	u32 fbp;
+};
+
+/**
+ * var_to_env - Graphics Synthesizer drawing environment for a given video mode
+ * @var: screen info object
+ * @info: frame buffer info object
+ *
+ * Return: Graphics Synthesizer drawing environment parameters
+ */
+static struct environment var_to_env(const struct fb_var_screeninfo *var,
+	const struct fb_info *info)
+{
+	return (struct environment) {
+		.xres = var->xres,
+		.yres = var->yres,
+		.fbw  = var_to_fbw(var),
+		.psm  = var_to_psm(var, info)
+	};
+}
+
+/**
+ * package_environment - package drawing environment tags and data for the GIF
+ * @package: DMA buffer to put packages in
+ * @env: drawing environment to package
+ *
+ * Various parameters are used to draw Graphics Synthesizer primitives, for
+ * example texture information and drawing attributes set by the PRIM register.
+ * These parameters are called the drawing environment. The environment remains
+ * in effect for multiple primitives until it is reset.
+ *
+ * Some environment registers such as XYOFFSET_1 and XYOFFSET_2 represent the
+ * same function and can be chosen with the CTXT primitive attribute.
+ *
+ * The following registers are available:
+ *
+ * ============ =============================================================
+ * XYOFFSET_1/2 offset value of vertex coordinates
+ * PRMODECONT   PRIM attributes enabled/disabled
+ * TEX0_1/2     attributes of texture buffer and texture mapping
+ * TEX1_1/2     attributes of texture mapping
+ * TEX2_1/2     colour lookup table entry
+ * CLAMP_1/2    wrap mode of texture mapping
+ * TEXCLUT      colour lookup table setting
+ * SCANMSK      drawing control with y coordinate of pixel
+ * MIPTBP1_1/2  base pointer for MIPMAP on each level
+ * MIPTBP2_1/2  base pointer for MIPMAP on each level
+ * TEXA         reference value when expanding alpha value of TEX16 and TEX24
+ * FOGCOL       fogging distant color
+ * SCISSOR_1/2  scissoring area
+ * ALPHA_1/2    alpha-blending attributes
+ * DIMX         dither matrix
+ * DTHE         dithering enabled/disabled
+ * COLCLAMP     color clamp/mask
+ * TEST_1/2     pixel operation
+ * PABE         alpha-blending in pixel units enabled/disabled
+ * FBA_1/2      alpha correction value
+ * FRAME_1/2    frame buffer setting
+ * ZBUF_1/2     z buffer setting
+ * ============ =============================================================
+ *
+ * Return: number of generated GIF packages in 16-byte unit
+ */
+static size_t package_environment(union package *package,
+	const struct environment env)
+{
+	union package * const base_package = package;
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 11
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_frame_1,
+		.data.frame_1 = {
+			.fbw = env.fbw,
+			.fbp = env.fbp,
+			.psm = env.psm
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_xyoffset_1,
+		.data.xyoffset_1 = {
+			.ofx = 0,
+			.ofy = 0,
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_scissor_1,
+		.data.scissor_1 = {
+			.scax0 = 0, .scax1 = env.xres,
+			.scay0 = 0, .scay1 = env.yres
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_scanmsk,
+		.data.scanmsk = {
+			.msk = gs_scanmsk_normal
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_prmode,
+		.data.prmode = { }	/* Reset PRMODE to a known value */
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_prmodecont,
+		.data.prmodecont = {
+			.ac = 1
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_test_1,
+		.data.test_1 = {
+			.zte  = gs_depth_test_on,	/* Must always be ON */
+			.ztst = gs_depth_pass		/* Emulate OFF */
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_texa,
+		.data.texa = {
+			.ta0 = GS_ALPHA_ONE,
+			.aem = gs_aem_normal,
+			.ta1 = GS_ALPHA_ONE
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_tex1_1,
+		.data.tex1 = {
+			.lcm = gs_lcm_fixed,
+			.mmag = gs_lod_nearest,
+			.mmin = gs_lod_nearest,
+			.k = 0
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_zbuf_1,
+		.data.zbuf = {
+			.zmsk = gs_zbuf_off
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_dthe,
+		.data.dthe = {
+			.dthe = gs_dthe_off
+		}
+	};
+
+	return package - base_package;
+}
+
+/**
+ * write_cb_environment - write console buffer GS drawing environment to the GIF
+ * @info: frame buffer info object
+ *
+ * Write various parameters used to draw Graphics Synthesizer primitives, for
+ * example texture information and drawing attributes set by the PRIM register.
+ * The environment remains in effect for multiple primitives until it is reset.
+ */
+void write_cb_environment(struct fb_info *info)
+{
+        if (gif_wait()) {
+		struct ps2fb_par *par = info->par;
+		union package * const base_package = par->package.buffer;
+		union package *package = base_package;
+
+		package += package_environment(package,
+			var_to_env(&info->var, info));
+
+		gif_write(&base_package->gif, package - base_package);
+	} else
+		fb_err(info, "Failed to write GS environment, GIF is busy\n");
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -889,9 +1082,12 @@ static int ps2fb_cb_set_par(struct fb_info *info)
 	spin_lock_irqsave(&par->lock, flags);
 
 	err = ps2fb_set_par(info);
-	if (!err)
+	if (!err) {
 		par->cb.block_count = var_to_block_count(info);
 
+		write_cb_environment(info);
+	}
+
 	spin_unlock_irqrestore(&par->lock, flags);
 
 	if (!err && info->tileops)
Signature · 1 line
2.21.0
#133 lore raw

PATCH 100/120 MIPS: PS2: FB: Clear the display buffer when changing video modes

In reply to Fredrik Noring

This avoids displaying leftover graphics that appear as garbage from a previous mode.

---
 drivers/video/fbdev/ps2fb.c | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/video/fbdev/ps2fb.c +45 -0
index 90ddcbe27d43..e5e603db7671 100644
@@ -572,6 +572,49 @@ static int ps2fb_cb_get_tilemax(struct fb_info *info)
 	return blocks_available > 0 ? blocks_available * block_tile_count : 0;
 }
 
+/**
+ * clear_screen - clear the displayed buffer screen
+ * @info: frame buffer info object
+ */
+static void clear_screen(struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	union package * const base_package = par->package.buffer;
+	union package *package = base_package;
+
+	if (!gif_wait()) {
+		fb_err(info, "Failed to clear the screen, GIF is busy\n");
+		return;
+	}
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_reglist_mode,
+		.reg0 = gif_reg_prim,
+		.reg1 = gif_reg_rgbaq,
+		.reg2 = gif_reg_xyz2,
+		.reg3 = gif_reg_xyz2,
+		.nreg = 4,
+		.nloop = 1,
+		.eop = 1
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.prim = { .prim = gs_sprite },
+		.hi.rgbaq = { .a = GS_ALPHA_ONE }
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.xyz2 = {
+			.x = gs_fbcs_to_pcs(0),
+			.y = gs_fbcs_to_pcs(0)
+		},
+		.hi.xyz2 = {
+			.x = gs_fbcs_to_pcs(info->var.xres_virtual),
+			.y = gs_fbcs_to_pcs(info->var.yres_virtual)
+		}
+	};
+
+	gif_write(&base_package->gif, package - base_package);
+}
+
 /**
  * bits_per_pixel_fits - does the given resolution fit the given buffer size?
  * @xres_virtual: virtual x resolution in pixels
@@ -1086,6 +1129,8 @@ static int ps2fb_cb_set_par(struct fb_info *info)
 		par->cb.block_count = var_to_block_count(info);
 
 		write_cb_environment(info);
+
+		clear_screen(info);
 	}
 
 	spin_unlock_irqrestore(&par->lock, flags);
Signature · 1 line
2.21.0
#134 lore raw

PATCH 101/120 MIPS: PS2: FB: fb_setcolreg() 256 colour pseudo palette support

In reply to Fredrik Noring

The Graphics Synthesizer display buffer is either 16-bit or 32-bit true colour. The font will be represented by 4-bit palette indexed texture tiles in a forthcoming change.

---
 drivers/video/fbdev/ps2fb.c | 57 +++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
drivers/video/fbdev/ps2fb.c +57 -0
index e5e603db7671..c852341ec19a 100644
@@ -57,6 +57,7 @@
 
 #define DEVICE_NAME "ps2fb"
 
+#define PALETTE_SIZE 256
 #define PALETTE_BLOCK_COUNT 1	/* One block is used for the indexed colors */
 
 #define GIF_PACKAGE_TAG(package) ((package)++)->gif.tag = (struct gif_tag)
@@ -122,6 +123,8 @@ struct console_buffer {
 /**
  * struct ps2fb_par - driver specific structure
  * @lock: spin lock to be taken for all structure operations
+ * @mode: frame buffer video mode
+ * @pseudo_palette: pseudo palette, used for texture colouring
  * @cb: console buffer definition
  * @package: tags and datafor the GIF
  * @package.capacity: maximum number of GIF packages in 16-byte unit
@@ -130,6 +133,9 @@ struct console_buffer {
 struct ps2fb_par {
 	spinlock_t lock;
 
+	struct fb_videomode mode;
+	struct gs_rgba32 pseudo_palette[PALETTE_SIZE];
+
 	struct console_buffer cb;
 
 	struct {
@@ -572,6 +578,44 @@ static int ps2fb_cb_get_tilemax(struct fb_info *info)
 	return blocks_available > 0 ? blocks_available * block_tile_count : 0;
 }
 
+/**
+ * invalidate_palette - set invalid palette indices to force update
+ * @par: driver specific object
+ *
+ * The background and foreground palette indices will mismatch in the next
+ * tile file, and thereby force a palette update.
+ */
+static void invalidate_palette(struct ps2fb_par *par)
+{
+	par->cb.bg = ~0;
+	par->cb.fg = ~0;
+}
+
+static int ps2fb_setcolreg(unsigned regno, unsigned red, unsigned green,
+	unsigned blue, unsigned transp, struct fb_info *info)
+{
+	const struct gs_rgba32 color = {
+		.r = red    >> 8,
+		.g = green  >> 8,
+		.b = blue   >> 8,
+		.a = transp >> 8
+	};
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+
+	if (regno >= PALETTE_SIZE)
+		return -EINVAL;
+
+	spin_lock_irqsave(&par->lock, flags);
+
+	par->pseudo_palette[regno] = color;
+	invalidate_palette(par);
+
+	spin_unlock_irqrestore(&par->lock, flags);
+
+	return 0;
+}
+
 /**
  * clear_screen - clear the displayed buffer screen
  * @info: frame buffer info object
@@ -1076,6 +1120,7 @@ static int ps2fb_set_par(struct fb_info *info)
 	struct gs_smode1 smode1 = sp.smode1;
 
 	par->mode = vm;
+	invalidate_palette(par);
 
 	info->fix.type = FB_TYPE_PACKED_PIXELS;
 	info->fix.visual = FB_VISUAL_TRUECOLOR;
@@ -1171,6 +1216,7 @@ static int init_console_buffer(struct platform_device *pdev,
 {
 	static struct fb_ops fbops = {
 		.owner		= THIS_MODULE,
+		.fb_setcolreg	= ps2fb_setcolreg,
 		.fb_set_par	= ps2fb_cb_set_par,
 		.fb_check_var	= ps2fb_cb_check_var,
 	};
@@ -1203,6 +1249,8 @@ static int init_console_buffer(struct platform_device *pdev,
 	info->pixmap.blit_x = block_dimensions(GS_PSMT4_BLOCK_WIDTH, 4);
 	info->pixmap.blit_y = block_dimensions(GS_PSMT4_BLOCK_HEIGHT, 1);
 
+	info->pseudo_palette = par->pseudo_palette;
+
 	/* 8x8 default font tile size for fb_get_tilemax */
 	par->cb.tile = cb_tile(8, 8);
 
@@ -1256,6 +1304,13 @@ static int ps2fb_probe(struct platform_device *pdev)
 
 	info->mode = &par->mode;
 
+	if (fb_alloc_cmap(&info->cmap, PALETTE_SIZE, 0) < 0) {
+		fb_err(info, "fb_alloc_cmap failed\n");
+		err = -ENOMEM;
+		goto err_alloc_cmap;
+	}
+	fb_set_cmap(&info->cmap, info);
+
 	if (register_framebuffer(info) < 0) {
 		fb_err(info, "register_framebuffer failed\n");
 		err = -EINVAL;
@@ -1267,6 +1322,8 @@ static int ps2fb_probe(struct platform_device *pdev)
 	return 0;
 
 err_register_framebuffer:
+	fb_dealloc_cmap(&info->cmap);
+err_alloc_cmap:
 err_find_mode:
 err_init_buffer:
 	free_page((unsigned long)par->package.buffer);
Signature · 1 line
2.21.0
#135 lore raw

PATCH 102/120 MIPS: PS2: FB: fb_settile() with font stored as palette indexed textures

In reply to Fredrik Noring

Storing the font map locally in Graphics Synthesizer memory is very efficient when drawing. A 4-bit palette indexed texture is used so that both the background and foreground colours can be updated without reinstalling the font map.

Before using converted data from host-to-local or local-to-local transmissions as texture or colour lookup tables for the first time, the texture buffer must be disabled with the TEXFLUSH register.

The register write waits for the completion of the current drawing process, and then disables the texture data read to the texture page buffer. Any data can be written to it. A drawing process succeeding the write to the register is started after the texture page buffer is disabled[1].

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    pp. 43, 51, 55, 63, 77, 131.
---
 drivers/video/fbdev/ps2fb.c | 285 ++++++++++++++++++++++++++++++++++++
 1 file changed, 285 insertions(+)
drivers/video/fbdev/ps2fb.c +285 -0
index c852341ec19a..2f7477dc69c1 100644
@@ -320,6 +320,47 @@ static u32 var_to_block_count(const struct fb_info *info)
 	return 0;
 }
 
+/**
+ * block_address_for_index - frame buffer block address for given block index
+ * @block_index: index of block to compute the address of
+ * @info: frame buffer info object
+ *
+ * Return: block address, or zero for unsupported pixel storage modes
+ */
+static u32 block_address_for_index(const u32 block_index,
+	const struct fb_info *info)
+{
+	const struct fb_var_screeninfo *var = &info->var;
+	const enum gs_psm psm = var_to_psm(var, info);
+	const u32 fbw = var_to_fbw(var);
+
+	if (psm == gs_psm_ct16)
+		return gs_psm_ct16_block_address(fbw, block_index);
+	if (psm == gs_psm_ct32)
+		return gs_psm_ct32_block_address(fbw, block_index);
+
+	fb_warn_once(info, "%s: Unsupported pixel storage format %u\n",
+		__func__, psm);
+	return 0;
+}
+
+/**
+ * texture_address_for_index - frame buffer texture address for given index
+ * @block_index: index of block to compute the address of
+ * @info: frame buffer info object
+ *
+ * Return: texture address, or zero for unsupported pixel storage modes
+ */
+static u32 texture_address_for_index(const u32 block_index,
+	const struct fb_info *info)
+{
+	const struct ps2fb_par *par = info->par;
+
+	return block_address_for_index(
+		par->cb.block_count + PALETTE_BLOCK_COUNT + block_index,
+		info);
+}
+
 /**
  * texture_least_power_of_2 - round up to a power of 2, not less than 8
  * @n: integer to round up
@@ -357,6 +398,34 @@ static struct cb_tile cb_tile(u32 width, u32 height)
 	};
 }
 
+/**
+ * texture_for_tile - texture base pointer and texel coordinates for tile index
+ * @tile_index: index of tile to compute the texture for
+ * @info: frame buffer info object
+ *
+ * Returns texture base pointer and texel coordinates
+ */
+static struct tile_texture texture_for_tile(const u32 tile_index,
+	const struct fb_info *info)
+{
+	const struct ps2fb_par *par = info->par;
+
+	const u32 texture_tile_count =
+		par->cb.tile.block.cols * par->cb.tile.block.rows;
+	const u32 block_tile = tile_index / texture_tile_count;
+	const u32 texture_tile = tile_index % texture_tile_count;
+	const u32 block_address = texture_address_for_index(block_tile, info);
+
+	const u32 row = texture_tile / par->cb.tile.block.cols;
+	const u32 col = texture_tile % par->cb.tile.block.cols;
+
+	return (struct tile_texture) {
+		.tbp	= block_address,
+		.u	= col * par->cb.tile.width2,
+		.v	= row * par->cb.tile.height2
+	};
+}
+
 /**
  * display_buffer_size - display buffer size for a given video resolution
  *
@@ -560,6 +629,221 @@ void write_cb_environment(struct fb_info *info)
 		fb_err(info, "Failed to write GS environment, GIF is busy\n");
 }
 
+/**
+ * pixel - background or foreground pixel palette index for given coordinates
+ * @image: image to sample pixel from
+ * @x: x coordinate, relative to the top left corner
+ * @y: y coordinate, relative to the top left corner
+ * @info: frame buffer info object
+ *
+ * The background palette index is given for coordinates outside of the image.
+ *
+ * Return: background or foreground palette index
+ */
+static u32 pixel(const struct fb_image * const image,
+	const int x, const int y, struct fb_info *info)
+{
+	if (x < 0 || x >= image->width ||
+	    y < 0 || y >= image->height)
+		return image->bg_color;
+
+	if (image->depth == 1)
+		return (image->data[y*((image->width + 7) >> 3) + (x >> 3)] &
+			(0x80 >> (x & 0x7))) ?
+			image->fg_color : image->bg_color;
+
+	fb_warn_once(info, "%s: Unsupported image depth %u\n",
+		__func__, image->depth);
+	return 0;
+}
+
+/**
+ * ps2fb_cb_texflush - flush texture buffer after palette or texture updates
+ * @info: frame buffer info object
+ *
+ * Before using converted data from host-to-local or local-to-local
+ * transmissions as texture or colour lookup tables for the first time, the
+ * texture buffer must be disabled with the TEXFLUSH register.
+ *
+ * The register write waits for the completion of the current drawing process,
+ * and then disables the texture data read to the texture page buffer. Any
+ * data can be written to it. A drawing process succeeding the write to the
+ * register is started after the texture page buffer is disabled.
+ */
+static void ps2fb_cb_texflush(struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	union package * const base_package = par->package.buffer;
+	union package *package = base_package;
+	unsigned long flags;
+
+	if (info->state != FBINFO_STATE_RUNNING)
+		return;
+
+	spin_lock_irqsave(&par->lock, flags);
+
+        if (!gif_wait())
+		goto timeout;
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 1
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_texflush
+	};
+
+	gif_write(&base_package->gif, package - base_package);
+
+timeout:
+	spin_unlock_irqrestore(&par->lock, flags);
+}
+
+/**
+ * package_psmt4_texture - package PSMT4 texture tags and data for the GIF
+ * @package: DMA buffer to put packages in
+ * @image: image to copy
+ * @info: frame buffer info object
+ *
+ * Return: number of generated GIF packages in 16-byte unit
+ */
+static size_t package_psmt4_texture(union package *package,
+	const struct fb_image *image, struct fb_info *info)
+{
+	union package * const base_package = package;
+	const u32 width2 = texture_least_power_of_2(image->width);
+	const u32 height2 = texture_least_power_of_2(image->height);
+	const u32 texels_per_quadword = 32;	/* PSMT4 are 4 bit texels */
+	const u32 nloop = (width2 * height2 + texels_per_quadword - 1) /
+		texels_per_quadword;
+	u32 x, y;
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_image_mode,
+		.nloop = nloop,
+		.eop = 1
+	};
+
+	for (y = 0; y < height2; y++)
+	for (x = 0; x < width2; x += 2) {
+		const int p0 = pixel(image, x + 0, y, info);
+		const int p1 = pixel(image, x + 1, y, info);
+		const int i = 4*y + x/2;
+
+		package[i/16].gif.image[i%16] =
+			(p1 ? 0x10 : 0) | (p0 ? 0x01 : 0);
+	}
+
+	package += nloop;
+
+	return package - base_package;
+}
+
+/**
+ * write_cb_tile - write console buffer tile to the GIF
+ * @tile_index: index of the tile, starting from zero for the first glyph
+ * @image: the image of the tile to write
+ * @info: frame buffer info object
+ */
+static void write_cb_tile(const int tile_index,
+	const struct fb_image *image, struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	const struct tile_texture tt = texture_for_tile(tile_index, info);
+	union package * const base_package = par->package.buffer;
+	union package *package = base_package;
+
+        if (!gif_wait())
+		return;
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 4
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_bitbltbuf,
+		.data.bitbltbuf = {
+			.dpsm = gs_psm_t4,
+			.dbw = GS_PSMT4_BLOCK_WIDTH / 64,
+			.dbp = tt.tbp
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxpos,
+		.data.trxpos = {
+			.dsax = tt.u,
+			.dsay = tt.v
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxreg,
+		.data.trxreg = {
+			.rrw = texture_least_power_of_2(image->width),
+			.rrh = texture_least_power_of_2(image->height)
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxdir,
+		.data.trxdir = { .xdir = gs_trxdir_host_to_local }
+	};
+
+	package += package_psmt4_texture(package, image, info);
+
+	gif_write(&base_package->gif, package - base_package);
+}
+
+/**
+ * ps2fb_cb_settile - set console buffer font tiles
+ * @info: frame buffer info object
+ * @map: font map use as tiles
+*/
+static void ps2fb_cb_settile(struct fb_info *info, struct fb_tilemap *map)
+{
+	const u32 glyph_size = ALIGN(map->width, 8) * map->height / 8;
+	struct ps2fb_par *par = info->par;
+	const u8 *font = map->data;
+	int i;
+
+	if (!font)
+		return;	/* FIXME: Why is fb_settile called with a NULL font? */
+
+	if (info->state != FBINFO_STATE_RUNNING)
+		return;
+
+	if (map->width > GS_PSMT4_BLOCK_WIDTH ||
+	    map->height > GS_PSMT4_BLOCK_HEIGHT ||
+	    map->depth != 1) {
+		fb_err(info, "Unsupported font parameters: "
+			"width %d height %d depth %d length %d\n",
+			map->width, map->height, map->depth, map->length);
+		return;
+	}
+
+	par->cb.tile = cb_tile(map->width, map->height);
+
+	for (i = 0; i < map->length; i++) {
+		const struct fb_image image = {
+			.width = map->width,
+			.height = map->height,
+			.fg_color = 1,
+			.bg_color = 0,
+			.depth = 1,
+			.data = &font[i * glyph_size],
+		};
+		unsigned long flags;
+
+		spin_lock_irqsave(&par->lock, flags);
+		write_cb_tile(i, &image, info);
+		spin_unlock_irqrestore(&par->lock, flags);
+	}
+
+	ps2fb_cb_texflush(info);
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -1222,6 +1506,7 @@ static int init_console_buffer(struct platform_device *pdev,
 	};
 
 	static struct fb_tile_ops tileops = {
+		.fb_settile	= ps2fb_cb_settile,
 		.fb_get_tilemax = ps2fb_cb_get_tilemax
 	};
 
Signature · 1 line
2.21.0
#136 lore raw

PATCH 103/120 MIPS: PS2: FB: Hardware accelerated fb_tilecopy() support

In reply to Fredrik Noring

In local-to-local BITBLTBUF transmissions, the following restrictions to the TRXREG register width field apply depending on the pixel storage mode[1]:

- multiple of 2: PSMCT32, PSMZ32
- multiple of 4: PSMCT16, PSMCT16S, PSMZ16, PSMZ16S
- multiple of 8: PSMCT24, PSMZ24, PSMT8, PSMT8H, PSMT4, PSMT4HL, PSMT4HH

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 76.
---
 drivers/video/fbdev/ps2fb.c | 148 ++++++++++++++++++++++++++++++++++++
 1 file changed, 148 insertions(+)
drivers/video/fbdev/ps2fb.c +148 -0
index 2f7477dc69c1..2123686af013 100644
@@ -426,6 +426,33 @@ static struct tile_texture texture_for_tile(const u32 tile_index,
 	};
 }
 
+/**
+  * valid_bitbltbuf_width - is the BITBLTBUF width valid?
+  * @width: width in pixels to check
+  * @psm: pixel storage mode
+  *
+  * In local-to-local BITBLTBUF transmissions, the following restrictions
+  * to the TRXREG register width field apply depending on the pixel storage
+  * mode[1]:
+  *
+  * - multiple of 2: PSMCT32, PSMZ32
+  * - multiple of 4: PSMCT16, PSMCT16S, PSMZ16, PSMZ16S
+  * - multiple of 8: PSMCT24, PSMZ24, PSMT8, PSMT8H, PSMT4, PSMT4HL, PSMT4HH
+  *
+  * Return: %true if the given width is valid, otherwise %false
+  */
+static bool valid_bitbltbuf_width(int width, enum gs_psm psm)
+{
+	if (width < 1)
+		return false;
+	if (psm == gs_psm_ct32 && (width & 1) != 0)
+		return false;
+	if (psm == gs_psm_ct16 && (width & 3) != 0)
+		return false;
+
+	return true;
+}
+
 /**
  * display_buffer_size - display buffer size for a given video resolution
  *
@@ -629,6 +656,103 @@ void write_cb_environment(struct fb_info *info)
 		fb_err(info, "Failed to write GS environment, GIF is busy\n");
 }
 
+/**
+ * package_copyarea - package copy area tags and data for the GIF
+ * @package: DMA buffer to put packages in
+ * @area: area to copy
+ * @info: frame buffer info object
+ *
+ * Return: number of generated GIF packages in 16-byte unit
+ */
+static size_t package_copyarea(union package *package,
+	const struct fb_copyarea *area, const struct fb_info *info)
+{
+	const struct fb_var_screeninfo *var = &info->var;
+	union package * const base_package = package;
+	const int psm = var_to_psm(var, info);
+	const int fbw = var_to_fbw(var);
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 4
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_bitbltbuf,
+		.data.bitbltbuf = {
+			.spsm = psm, .sbw = fbw,
+			.dpsm = psm, .dbw = fbw
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxpos,
+		.data.trxpos = {
+			.ssax = area->sx, .ssay = area->sy,
+			.dsax = area->dx, .dsay = area->dy,
+			.dir  = area->dy < area->sy ||
+				(area->dy == area->sy && area->dx < area->sx) ?
+				gs_trxpos_dir_ul_lr : gs_trxpos_dir_lr_ul
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxreg,
+		.data.trxreg = {
+			.rrw = area->width,
+			.rrh = area->height
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxdir,
+		.data.trxdir = { .xdir = gs_trxdir_local_to_local }
+	};
+
+	return package - base_package;
+}
+
+/**
+ * ps2fb_cb_copyarea - copy console buffer area
+ * @area: area to copy
+ * @info: frame buffer info object
+ */
+void ps2fb_cb_copyarea(const struct fb_copyarea *area, struct fb_info *info)
+{
+	const enum gs_psm psm = var_to_psm(&info->var, info);
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+
+	if (info->state != FBINFO_STATE_RUNNING)
+		return;
+	if (area->width < 1 || area->height < 1)
+		return;
+	if (!valid_bitbltbuf_width(area->width, psm)) {
+		/*
+		 * Some widths are not entirely supported with BITBLTBUF,
+		 * but there will be more graphical glitches by refusing
+		 * to proceed. Besides, info->pixmap.blit_x says that
+		 * they are unsupported so unless someone wants to have
+		 * odd fonts we will not end up here anyway. Warn once
+		 * here for the protocol.
+		 */
+		fb_warn_once(info, "%s: "
+			"Unsupported width %u for pixel storage format %u\n",
+			__func__, area->width, psm);
+	}
+
+	spin_lock_irqsave(&par->lock, flags);
+
+        if (gif_wait()) {
+		union package * const base_package = par->package.buffer;
+		union package *package = base_package;
+
+		package += package_copyarea(package, area, info);
+
+		gif_write(&base_package->gif, package - base_package);
+	}
+
+	spin_unlock_irqrestore(&par->lock, flags);
+}
+
 /**
  * pixel - background or foreground pixel palette index for given coordinates
  * @image: image to sample pixel from
@@ -844,6 +968,28 @@ static void ps2fb_cb_settile(struct fb_info *info, struct fb_tilemap *map)
 	ps2fb_cb_texflush(info);
 }
 
+/**
+ * ps2fb_cb_tilecopy - copy console buffer tiles
+ * @info: frame buffer info object
+ * @area: tile area to copy
+ */
+static void ps2fb_cb_tilecopy(struct fb_info *info, struct fb_tilearea *area)
+{
+	const struct ps2fb_par *par = info->par;
+	const u32 tw = par->cb.tile.width;
+	const u32 th = par->cb.tile.height;
+	const struct fb_copyarea a = {
+		.dx	= tw * area->dx,
+		.dy	= th * area->dy,
+		.width	= tw * area->width,
+		.height	= th * area->height,
+		.sx	= tw * area->sx,
+		.sy	= th * area->sy
+	};
+
+	ps2fb_cb_copyarea(&a, info);
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -1507,6 +1653,7 @@ static int init_console_buffer(struct platform_device *pdev,
 
 	static struct fb_tile_ops tileops = {
 		.fb_settile	= ps2fb_cb_settile,
+		.fb_tilecopy	= ps2fb_cb_tilecopy,
 		.fb_get_tilemax = ps2fb_cb_get_tilemax
 	};
 
@@ -1522,6 +1669,7 @@ static int init_console_buffer(struct platform_device *pdev,
 
 	info->fbops = &fbops;
 	info->flags = FBINFO_DEFAULT |
+		      FBINFO_HWACCEL_COPYAREA |
 		      FBINFO_READS_FAST;
 
 	info->flags |= FBINFO_MISC_TILEBLITTING;
Signature · 1 line
2.21.0
#137 lore raw

PATCH 104/120 MIPS: PS2: FB: Hardware accelerated fb_tilefill() support

In reply to Fredrik Noring

The local Graphics Synthesizer palette is updated if either the background or the foreground colour index have changed. A single BITBLTBUF operation performs the tile fill.

---
 drivers/video/fbdev/ps2fb.c | 233 ++++++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)
drivers/video/fbdev/ps2fb.c +233 -0
index 2123686af013..c00c0f6a4a49 100644
@@ -252,6 +252,23 @@ static const struct fb_videomode standard_modes[] = {
 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }
 };
 
+/**
+ * console_pseudo_palette - Graphics Synthesizer RGBA for a palette index
+ * @regno: pseudo palette index number
+ * @par: driver specific object
+ *
+ * Return: RGBA colour object for the Graphics Synthesizer
+ */
+static struct gs_rgbaq console_pseudo_palette(const u32 regno,
+	const struct ps2fb_par *par)
+{
+	const struct gs_rgba32 c = regno < PALETTE_SIZE ?
+		par->pseudo_palette[regno] : (struct gs_rgba32) { };
+	const u32 a = (c.a + 1) / 2;	/* 0x80 = GS_ALPHA_ONE = 1.0 */
+
+	return (struct gs_rgbaq) { .r = c.r, .g = c.g, .b = c.b, .a = a };
+}
+
 /**
  * var_to_fbw - frame buffer width for a given virtual x resolution
  * @var: screen info object to compute FBW for
@@ -344,6 +361,19 @@ static u32 block_address_for_index(const u32 block_index,
 	return 0;
 }
 
+/**
+ * color_base_pointer - colour base pointer
+ * @info: frame buffer info object
+ *
+ * Return: block index of the colour palette, that follows the display buffer
+ */
+static u32 color_base_pointer(const struct fb_info *info)
+{
+	const struct ps2fb_par *par = info->par;
+
+	return par->cb.block_count;
+}
+
 /**
  * texture_address_for_index - frame buffer texture address for given index
  * @block_index: index of block to compute the address of
@@ -968,6 +998,187 @@ static void ps2fb_cb_settile(struct fb_info *info, struct fb_tilemap *map)
 	ps2fb_cb_texflush(info);
 }
 
+/**
+ * package_palette - package palette tags and data for the GIF
+ * @package: DMA buffer to put packages in
+ * @bg: background colour palette index
+ * @fg: foreground colour palette index
+ * @info: frame buffer info object
+ *
+ * Return: number of generated GIF packages in 16-byte unit
+ */
+static size_t package_palette(union package *package,
+	const int bg, const int fg, struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	union package * const base_package = par->package.buffer;
+	const struct gs_rgbaq bg_rgbaq = console_pseudo_palette(bg, par);
+	const struct gs_rgbaq fg_rgbaq = console_pseudo_palette(fg, par);
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 4
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_bitbltbuf,
+		.data.bitbltbuf = {
+			.dpsm = gs_psm_ct32,
+			.dbw = 1,	/* Palette is one block wide */
+			.dbp = color_base_pointer(info)
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxpos,
+		.data.trxpos = {
+			.dsax = 0,
+			.dsay = 0
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxreg,
+		.data.trxreg = {
+			.rrw = 2,	/* Background and foreground color */
+			.rrh = 1
+		}
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_trxdir,
+		.data.trxdir = { .xdir = gs_trxdir_host_to_local }
+	};
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_image_mode,
+		.nloop = 1,
+		.eop = 1
+	};
+	package->gif.rgba32[0] = (struct gs_rgba32) {
+		.r = bg_rgbaq.r,
+		.g = bg_rgbaq.g,
+		.b = bg_rgbaq.b,
+		.a = bg_rgbaq.a
+	};
+	package->gif.rgba32[1] = (struct gs_rgba32) {
+		.r = fg_rgbaq.r,
+		.g = fg_rgbaq.g,
+		.b = fg_rgbaq.b,
+		.a = fg_rgbaq.a
+	};
+	package++;
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_packed_mode,
+		.reg0 = gif_reg_ad,
+		.nreg = 1,
+		.nloop = 1
+	};
+	GIF_PACKAGE_AD(package) {
+		.addr = gs_addr_texflush
+	};
+
+	return package - base_package;
+}
+
+/**
+ * write_tilefill - write console buffer tile fill operation to the GIF
+ * @info: frame buffer info object
+ * @rect: rectangle to fill with tiles
+ */
+static void write_tilefill(struct fb_info *info, const struct fb_tilerect rect)
+{
+	const struct tile_texture tt = texture_for_tile(rect.index, info);
+	struct ps2fb_par *par = info->par;
+	union package * const base_package = par->package.buffer;
+	union package *package = base_package;
+	const u32 cbp = color_base_pointer(info);
+	const u32 dsax = par->cb.tile.width * rect.sx;
+	const u32 dsay = par->cb.tile.height * rect.sy;
+	const u32 rrw = par->cb.tile.width * rect.width;
+	const u32 rrh = par->cb.tile.height * rect.height;
+	const u32 tw2 = par->cb.tile.width2;
+	const u32 th2 = par->cb.tile.height2;
+
+	/* Determine whether background or foreground color needs update. */
+	const bool cld = (par->cb.bg != rect.bg || par->cb.fg != rect.fg);
+
+        if (!gif_wait())
+		return;
+
+	if (cld) {
+		package += package_palette(package, rect.bg, rect.fg, info);
+		par->cb.bg = rect.bg;
+		par->cb.fg = rect.fg;
+	}
+
+	GIF_PACKAGE_TAG(package) {
+		.flg = gif_reglist_mode,
+		.reg0 = gif_reg_prim,
+		.reg1 = gif_reg_nop,
+		.reg2 = gif_reg_tex0_1,
+		.reg3 = gif_reg_clamp_1,
+		.reg4 = gif_reg_uv,
+		.reg5 = gif_reg_xyz2,
+		.reg6 = gif_reg_uv,
+		.reg7 = gif_reg_xyz2,
+		.nreg = 8,
+		.nloop = 1,
+		.eop = 1
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.prim = {
+			.prim = gs_sprite,
+			.tme = gs_texturing_on,
+			.fst = gs_texturing_uv
+		}
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.tex0 = {
+			.tbp0 = tt.tbp,
+			.tbw = GS_PSMT4_BLOCK_WIDTH / 64,
+			.psm = gs_psm_t4,
+			.tw = 5,	/* 2^5 = 32 texels wide PSMT4 block */
+			.th = 4,	/* 2^4 = 16 texels high PSMT4 block */
+			.tcc = gs_tcc_rgba,
+			.tfx = gs_tfx_decal,
+			.cbp = cbp,
+			.cpsm = gs_psm_ct32,
+			.csm = gs_csm1,
+			.cld = cld ? 1 : 0
+		},
+		.hi.clamp_1 = {
+			.wms = gs_clamp_region_repeat,
+			.wmt = gs_clamp_region_repeat,
+			.minu = tw2 - 1,  /* Mask, tw is always a power of 2 */
+			.maxu = tt.u,
+			.minv = th2 - 1,  /* Mask, th is always a power of 2 */
+			.maxv = tt.v
+		}
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.uv = {
+			.u = gs_pxcs_to_tcs(tt.u),
+			.v = gs_pxcs_to_tcs(tt.v)
+		},
+		.hi.xyz2 = {
+			.x = gs_fbcs_to_pcs(dsax),
+			.y = gs_fbcs_to_pcs(dsay)
+		}
+	};
+	GIF_PACKAGE_REG(package) {
+		.lo.uv = {
+			.u = gs_pxcs_to_tcs(tt.u + rrw),
+			.v = gs_pxcs_to_tcs(tt.v + rrh)
+		},
+		.hi.xyz2 = {
+			.x = gs_fbcs_to_pcs(dsax + rrw),
+			.y = gs_fbcs_to_pcs(dsay + rrh)
+		}
+	};
+
+	gif_write(&base_package->gif, package - base_package);
+}
+
 /**
  * ps2fb_cb_tilecopy - copy console buffer tiles
  * @info: frame buffer info object
@@ -990,6 +1201,26 @@ static void ps2fb_cb_tilecopy(struct fb_info *info, struct fb_tilearea *area)
 	ps2fb_cb_copyarea(&a, info);
 }
 
+/**
+ * ps2fb_cb_tilefill - tile fill operation
+ * @info: frame buffer info object
+ * @rect: rectangle to fill with tiles
+ */
+static void ps2fb_cb_tilefill(struct fb_info *info, struct fb_tilerect *rect)
+{
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+
+	if (info->state != FBINFO_STATE_RUNNING)
+		return;
+
+	spin_lock_irqsave(&par->lock, flags);
+
+	write_tilefill(info, *rect);
+
+	spin_unlock_irqrestore(&par->lock, flags);
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -1654,6 +1885,7 @@ static int init_console_buffer(struct platform_device *pdev,
 	static struct fb_tile_ops tileops = {
 		.fb_settile	= ps2fb_cb_settile,
 		.fb_tilecopy	= ps2fb_cb_tilecopy,
+		.fb_tilefill    = ps2fb_cb_tilefill,
 		.fb_get_tilemax = ps2fb_cb_get_tilemax
 	};
 
@@ -1670,6 +1902,7 @@ static int init_console_buffer(struct platform_device *pdev,
 	info->fbops = &fbops;
 	info->flags = FBINFO_DEFAULT |
 		      FBINFO_HWACCEL_COPYAREA |
+		      FBINFO_HWACCEL_FILLRECT |
 		      FBINFO_READS_FAST;
 
 	info->flags |= FBINFO_MISC_TILEBLITTING;
Signature · 1 line
2.21.0
#138 lore raw

PATCH 105/120 MIPS: PS2: FB: Simplified fb_tileblit() support

In reply to Fredrik Noring

The tile blit operation is implemented as a series of tile fill operations. This is very simple but not particularly efficient.

---
 drivers/video/fbdev/ps2fb.c | 39 +++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/video/fbdev/ps2fb.c +39 -0
index c00c0f6a4a49..c63215efd07d 100644
@@ -1221,6 +1221,43 @@ static void ps2fb_cb_tilefill(struct fb_info *info, struct fb_tilerect *rect)
 	spin_unlock_irqrestore(&par->lock, flags);
 }
 
+/**
+ * ps2fb_cb_tileblit - tile bit block transfer operation
+ * @info: frame buffer info object
+ * @blit: tile bit block to transfer
+ */
+static void ps2fb_cb_tileblit(struct fb_info *info, struct fb_tileblit *blit)
+{
+	struct ps2fb_par *par = info->par;
+	int i = 0, dx, dy;
+
+	if (info->state != FBINFO_STATE_RUNNING)
+		return;
+
+	/*
+	 * Note: This could be done faster, possibly often as a single
+	 * set of GIF packages.
+	 */
+	for (dy = 0; i < blit->length && dy < blit->height; dy++)
+	for (dx = 0; i < blit->length && dx < blit->width; dx++, i++) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&par->lock, flags);
+
+		write_tilefill(info, (struct fb_tilerect) {
+			.sx = blit->sx + dx,
+			.sy = blit->sy + dy,
+			.width = 1,
+			.height = 1,
+			.index = blit->indices[i],
+			.fg = blit->fg,
+			.bg = blit->bg
+		});
+
+		spin_unlock_irqrestore(&par->lock, flags);
+	}
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -1886,6 +1923,7 @@ static int init_console_buffer(struct platform_device *pdev,
 		.fb_settile	= ps2fb_cb_settile,
 		.fb_tilecopy	= ps2fb_cb_tilecopy,
 		.fb_tilefill    = ps2fb_cb_tilefill,
+		.fb_tileblit    = ps2fb_cb_tileblit,
 		.fb_get_tilemax = ps2fb_cb_get_tilemax
 	};
 
@@ -1903,6 +1941,7 @@ static int init_console_buffer(struct platform_device *pdev,
 	info->flags = FBINFO_DEFAULT |
 		      FBINFO_HWACCEL_COPYAREA |
 		      FBINFO_HWACCEL_FILLRECT |
+		      FBINFO_HWACCEL_IMAGEBLIT |
 		      FBINFO_READS_FAST;
 
 	info->flags |= FBINFO_MISC_TILEBLITTING;
Signature · 1 line
2.21.0
#139 lore raw

PATCH 106/120 MIPS: PS2: FB: fb_tilecursor() placeholder

In reply to Fredrik Noring

Drawing the cursor seems to require composition such as xor, which is not possible here. If the character under the cursor was known, a simple change of foreground and background colours could be implemented to achieve the same effect.

---
 drivers/video/fbdev/ps2fb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/video/fbdev/ps2fb.c +12 -0
index c63215efd07d..bbf9e1d9e3c1 100644
@@ -1258,6 +1258,17 @@ static void ps2fb_cb_tileblit(struct fb_info *info, struct fb_tileblit *blit)
 	}
 }
 
+static void ps2fb_cb_tilecursor(struct fb_info *info,
+	struct fb_tilecursor *cursor)
+{
+	/*
+	 * FIXME: Drawing the cursor seems to require composition such as
+	 * xor, which is not possible here. If the character under the
+	 * cursor was known, a simple change of foreground and background
+	 * colors could be implemented to achieve the same effect.
+	 */
+}
+
 /**
  * ps2fb_cb_get_tilemax - maximum number of tiles
  * @info: frame buffer info object
@@ -1924,6 +1935,7 @@ static int init_console_buffer(struct platform_device *pdev,
 		.fb_tilecopy	= ps2fb_cb_tilecopy,
 		.fb_tilefill    = ps2fb_cb_tilefill,
 		.fb_tileblit    = ps2fb_cb_tileblit,
+		.fb_tilecursor  = ps2fb_cb_tilecursor,
 		.fb_get_tilemax = ps2fb_cb_get_tilemax
 	};
 
Signature · 1 line
2.21.0
#140 lore raw

PATCH 107/120 MIPS: PS2: FB: Hardware accelerated fb_pan_display() support

In reply to Fredrik Noring

XPAN, YPAN and YWRAP are hardware accelerated. YWRAP is implemented using the two independent rectangular area read output circuits of the Graphics Synthesizer[1]. The DISPLAY1 register outputs the upper part and the DISPLAY2 register outputs the lower part.

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 82.
---
 drivers/video/fbdev/ps2fb.c | 120 ++++++++++++++++++++++++++++++++++--
 1 file changed, 116 insertions(+), 4 deletions(-)
drivers/video/fbdev/ps2fb.c +116 -4
index bbf9e1d9e3c1..73fc1fd3f4eb 100644
@@ -1368,6 +1368,109 @@ static void clear_screen(struct fb_info *info)
 	gif_write(&base_package->gif, package - base_package);
 }
 
+/**
+ * write_cb_pan_display - write console buffer pan operation to the GIF
+ * @var: screen info object
+ * @info: frame buffer info object
+ *
+ * XPAN, YPAN and YWRAP are hardware accelerated. YWRAP is implemented using
+ * the two independent rectangular area read output circuits of the Graphics
+ * Synthesizer. The DISPLAY1 register outputs the upper part and the DISPLAY2
+ * register outputs the lower part.
+ */
+static void write_cb_pan_display(const struct fb_var_screeninfo *var,
+	const struct fb_info *info)
+{
+	const struct gs_display display = gs_read_display1();
+	const int psm = var_to_psm(var, info);
+	const int fbw = var_to_fbw(var);
+	const int yo = var->yoffset % var->yres_virtual;
+	const int dh1 = min_t(int, var->yres_virtual - yo, var->yres);
+	const int dh2 = var->yres - dh1;
+
+	GS_WRITE_DISPLAY1(
+		.dh = dh1 - 1,
+		.dw = display.dw,
+		.magv = display.magv,
+		.magh = display.magh,
+		.dy = display.dy,
+		.dx = display.dx,
+	);
+
+	GS_WRITE_DISPLAY2(
+		.dh = dh2 - 1,
+		.dw = display.dw,
+		.magv = display.magv,
+		.magh = display.magh,
+		.dy = display.dy + dh1,
+		.dx = display.dx,
+	);
+
+	GS_WRITE_DISPFB1(
+		.fbw = fbw,
+		.psm = psm,
+		.dbx = var->xoffset,
+		.dby = yo
+	);
+
+	GS_WRITE_DISPFB2(
+		.fbw = fbw,
+		.psm = psm,
+		.dbx = var->xoffset,
+		.dby = 0,
+	);
+
+	GS_WRITE_PMODE(
+		.en1 = 1,
+		.en2 = dh2 ? 1 : 0,
+		.crtmd = 1
+	);
+}
+
+/**
+ * changed_cb_pan_display - is display panning needed?
+ * @var: screen info object
+ *
+ * Panning is undefined until the DISPFB1 register has been set.
+ *
+ * Return: %true if the horizontal or vertical panning is needed, otherwise
+ *	%false
+ */
+static bool changed_cb_pan_display(const struct fb_var_screeninfo *var)
+{
+	if (gs_valid_dispfb1()) {
+		const struct gs_dispfb dspfb12 = gs_read_dispfb1();
+		const int yo = var->yoffset % var->yres_virtual;
+
+		return dspfb12.dbx != var->xoffset || dspfb12.dby != yo;
+	}
+
+	return false;	/* DISPFB1 is incomparable before video mode is set. */
+}
+
+/**
+ * ps2fb_cb_pan_display - pan the display
+ * @var: screen info object
+ * @info: frame buffer info object
+ *
+ * Return: 0 on success, otherwise a negative error number
+ */
+static int ps2fb_cb_pan_display(struct fb_var_screeninfo *var,
+	struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	unsigned long flags;
+
+	spin_lock_irqsave(&par->lock, flags);
+
+	if (changed_cb_pan_display(var))
+		write_cb_pan_display(var, info);
+
+	spin_unlock_irqrestore(&par->lock, flags);
+
+	return 0;
+}
+
 /**
  * bits_per_pixel_fits - does the given resolution fit the given buffer size?
  * @xres_virtual: virtual x resolution in pixels
@@ -1438,8 +1541,11 @@ static int ps2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 	    var->yres < 1 || 2048 < var->yres)
 		return -EINVAL;
 
-	var->xres_virtual = var->xres;
-	var->yres_virtual = var->yres;
+        /* Check virtual resolution. */
+        if (var->xres_virtual < var->xres)
+           var->xres_virtual = var->xres;
+        if (var->yres_virtual < var->yres)
+           var->yres_virtual = var->yres;
 	var->xoffset = 0;
 	var->yoffset = 0;
 
@@ -1833,8 +1939,8 @@ static int ps2fb_set_par(struct fb_info *info)
 
 	info->fix.type = FB_TYPE_PACKED_PIXELS;
 	info->fix.visual = FB_VISUAL_TRUECOLOR;
-	info->fix.xpanstep = 0;
-	info->fix.ypanstep = 0;
+	info->fix.xpanstep = var->xres_virtual > var->xres ? 1 : 0;
+	info->fix.ypanstep = var->yres_virtual > var->yres ? 1 : 0;
 	info->fix.ywrapstep = 1;
 	info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
 
@@ -1883,6 +1989,7 @@ static int ps2fb_cb_set_par(struct fb_info *info)
 		par->cb.block_count = var_to_block_count(info);
 
 		write_cb_environment(info);
+		write_cb_pan_display(&info->var, info);
 
 		clear_screen(info);
 	}
@@ -1928,6 +2035,7 @@ static int init_console_buffer(struct platform_device *pdev,
 		.fb_setcolreg	= ps2fb_setcolreg,
 		.fb_set_par	= ps2fb_cb_set_par,
 		.fb_check_var	= ps2fb_cb_check_var,
+		.fb_pan_display	= ps2fb_cb_pan_display,
 	};
 
 	static struct fb_tile_ops tileops = {
@@ -1954,6 +2062,10 @@ static int init_console_buffer(struct platform_device *pdev,
 		      FBINFO_HWACCEL_COPYAREA |
 		      FBINFO_HWACCEL_FILLRECT |
 		      FBINFO_HWACCEL_IMAGEBLIT |
+		      FBINFO_HWACCEL_XPAN |
+		      FBINFO_HWACCEL_YPAN |
+		      FBINFO_HWACCEL_YWRAP |
+		      FBINFO_PARTIAL_PAN_OK |
 		      FBINFO_READS_FAST;
 
 	info->flags |= FBINFO_MISC_TILEBLITTING;
Signature · 1 line
2.21.0
#141 lore raw

PATCH 108/120 MIPS: PS2: FB: fb_blank() display power management signaling (DPMS)

In reply to Fredrik Noring

The Graphics Synthesizer implements four DPMS levels: on, standby, suspend and off. The level is set with the SMODE2 register DPMS field[1].

References:

[1] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.,

    p. 157.
---
 drivers/video/fbdev/ps2fb.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/video/fbdev/ps2fb.c +33 -0
index 73fc1fd3f4eb..92957797045f 100644
@@ -2004,6 +2004,38 @@ static int ps2fb_cb_set_par(struct fb_info *info)
 	return err;
 }
 
+/**
+ * ps2fb_blank - VESA display power management signaling (DPMS)
+ * @blank: frame buffer blanking level
+ * @info: frame buffer info object
+ *
+ * Return: 0 on success, otherwise a negative error number
+ */
+static int ps2fb_blank(int blank, struct fb_info *info)
+{
+	struct ps2fb_par *par = info->par;
+	struct gs_smode2 smode2;
+	unsigned long flags;
+
+	if (!gs_valid_smode2())
+		return -EIO;	/* Blanking before video mode is set. */
+
+	spin_lock_irqsave(&par->lock, flags);
+
+	smode2 = gs_read_smode2();
+
+	smode2.dpms = blank == FB_BLANK_POWERDOWN     ? gs_dpms_off :
+		      blank == FB_BLANK_NORMAL        ? gs_dpms_standby :
+		      blank == FB_BLANK_VSYNC_SUSPEND ? gs_dpms_suspend :
+		      blank == FB_BLANK_HSYNC_SUSPEND ? gs_dpms_suspend :
+							gs_dpms_on;
+	gs_write_smode2(smode2);
+
+	spin_unlock_irqrestore(&par->lock, flags);
+
+	return 0;
+}
+
 static u32 block_dimensions(u32 dim, u32 alignment)
 {
 	u32 mask = 0;
@@ -2032,6 +2064,7 @@ static int init_console_buffer(struct platform_device *pdev,
 {
 	static struct fb_ops fbops = {
 		.owner		= THIS_MODULE,
+		.fb_blank	= ps2fb_blank,
 		.fb_setcolreg	= ps2fb_setcolreg,
 		.fb_set_par	= ps2fb_cb_set_par,
 		.fb_check_var	= ps2fb_cb_check_var,
Signature · 1 line
2.21.0
#142 lore raw

PATCH 109/120 MIPS: PS2: FB: Disable GIF DMA completion interrupts

In reply to Fredrik Noring

The GIF asserts DMA completion interrupts that are uninteresting because DMA operations are fast enough to busy-wait for.

---
 drivers/video/fbdev/ps2fb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/video/fbdev/ps2fb.c +8 -0
index 92957797045f..d7a54108f37e 100644
@@ -2173,6 +2173,12 @@ static int ps2fb_probe(struct platform_device *pdev)
 	}
 	fb_set_cmap(&info->cmap, info);
 
+	/*
+	 * The GIF asserts DMA completion interrupts that are uninteresting
+	 * because DMA operations are fast enough to busy-wait for.
+	 */
+	disable_irq(IRQ_DMAC_GIF);
+
 	if (register_framebuffer(info) < 0) {
 		fb_err(info, "register_framebuffer failed\n");
 		err = -EINVAL;
@@ -2184,6 +2190,7 @@ static int ps2fb_probe(struct platform_device *pdev)
 	return 0;
 
 err_register_framebuffer:
+	enable_irq(IRQ_DMAC_GIF);
 	fb_dealloc_cmap(&info->cmap);
 err_alloc_cmap:
 err_find_mode:
@@ -2212,6 +2219,7 @@ static int ps2fb_remove(struct platform_device *pdev)
 		fb_err(info, "Failed to complete GIF DMA transfer\n");
 		err = -EBUSY;
 	}
+	enable_irq(IRQ_DMAC_GIF);
 	free_page((unsigned long)par->package.buffer);
 
 	return err;
Signature · 1 line
2.21.0
#143 lore raw

PATCH 110/120 MIPS: PS2: FB: PAL and NTSC grayscale support

In reply to Fredrik Noring

Construct luminance[1] Y' = 0.299R' + 0.587G' + 0.114B' with fixed-point integer arithmetic, where 77 + 150 + 29 = 256.

References:

[1] "Studio encoding parameters of digital television for standard 4:3 and wide-screen 16:9 aspect ratios", recommendation ITU-R BT.601-7, International Telecommunication Union - Radiocommunication sector, p. 2.

---
 drivers/video/fbdev/ps2fb.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/video/fbdev/ps2fb.c +13 -0
index d7a54108f37e..4975f9adb5d0 100644
@@ -125,6 +125,7 @@ struct console_buffer {
  * @lock: spin lock to be taken for all structure operations
  * @mode: frame buffer video mode
  * @pseudo_palette: pseudo palette, used for texture colouring
+ * @grayscale: perform grayscale colour conversion if %true
  * @cb: console buffer definition
  * @package: tags and datafor the GIF
  * @package.capacity: maximum number of GIF packages in 16-byte unit
@@ -135,6 +136,7 @@ struct ps2fb_par {
 
 	struct fb_videomode mode;
 	struct gs_rgba32 pseudo_palette[PALETTE_SIZE];
+	bool grayscale;
 
 	struct console_buffer cb;
 
@@ -266,6 +268,16 @@ static struct gs_rgbaq console_pseudo_palette(const u32 regno,
 		par->pseudo_palette[regno] : (struct gs_rgba32) { };
 	const u32 a = (c.a + 1) / 2;	/* 0x80 = GS_ALPHA_ONE = 1.0 */
 
+	if (par->grayscale) {
+		/*
+		 * Construct luminance Y' = 0.299R' + 0.587G' + 0.114B' with
+		 * fixed-point integer arithmetic, where 77 + 150 + 29 = 256.
+		 */
+		const u32 y = (c.r*77 + c.g*150 + c.b*29) >> 8;
+
+		return (struct gs_rgbaq) { .r = y, .g = y, .b = y, .a = a };
+	}
+
 	return (struct gs_rgbaq) { .r = c.r, .g = c.g, .b = c.b, .a = a };
 }
 
@@ -1935,6 +1947,7 @@ static int ps2fb_set_par(struct fb_info *info)
 	struct gs_smode1 smode1 = sp.smode1;
 
 	par->mode = vm;
+	par->grayscale = (var->grayscale == 1);
 	invalidate_palette(par);
 
 	info->fix.type = FB_TYPE_PACKED_PIXELS;
Signature · 1 line
2.21.0
#144 lore raw

PATCH 111/120 MIPS: PS2: FB: Analogue display mode adjustment module parameter

In reply to Fredrik Noring

Analogue devices are frequently a few pixels off. Use this mode_margin option to make necessary device dependent adjustments to the built-in modes.

---
 drivers/video/fbdev/ps2fb.c | 58 ++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 4 deletions(-)
drivers/video/fbdev/ps2fb.c +54 -4
index 4975f9adb5d0..121c271aa826 100644
@@ -67,6 +67,7 @@
 
 /* Module parameters */
 static char *mode_option;
+static char *mode_margin = "";
 
 union package {
 	union gif_data gif;
@@ -1923,9 +1924,45 @@ static struct gs_sync_param vm_to_sp(const struct fb_videomode *vm)
 	return vm_to_sp_for_synch_gen(vm, gs_synch_gen_for_vck(vm->pixclock));
 }
 
+/**
+ * struct margin_adjustment - move display screen relative given display mode
+ * @dx: positive, negative or zero horizontal x adjustment in pixels
+ * @dy: positive, negative or zero vertical y adjustment in pixels
+ */
+struct margin_adjustment {
+	int dx;
+	int dy;
+};
+
+static struct margin_adjustment margin_adjustment(struct fb_info *info)
+{
+	char sx = '+', sy = '+';
+	int dx = 0, dy = 0;
+
+	bool valid =
+		sscanf(mode_margin, "%c%d%c%d", &sx, &dx, &sy, &dy) == 4 &&
+		(sx == '-' || sx == '+') &&
+		(sy == '-' || sy == '+');
+
+	if (sx == '-')
+		dx = -dx;
+	if (sy == '-')
+		dy = -dy;
+
+	if (mode_margin[0] != '\0')
+		fb_info(info, "Mode margin \"%s\" with %d dx %d dy is %s\n",
+			mode_margin, dx, dy, valid ? "valid" : "invalid");
+
+	if (!valid)
+		return (struct margin_adjustment) { };
+
+	return (struct margin_adjustment) { .dx = dx, .dy = dy };
+}
+
 static int ps2fb_set_par(struct fb_info *info)
 {
 	struct ps2fb_par *par = info->par;
+	const struct margin_adjustment margin_adjust = margin_adjustment(info);
 	const struct fb_var_screeninfo *var = &info->var;
 	const struct fb_videomode *mm = fb_match_mode(var, &info->modelist);
 	const struct fb_videomode vm = (struct fb_videomode) {
@@ -1933,10 +1970,10 @@ static int ps2fb_set_par(struct fb_info *info)
 		.xres         = var->xres,
 		.yres         = var->yres,
 		.pixclock     = var->pixclock,
-		.left_margin  = var->left_margin,
-		.right_margin = var->right_margin,
-		.upper_margin = var->upper_margin,
-		.lower_margin = var->lower_margin,
+		.left_margin  = var->left_margin  + margin_adjust.dx,
+		.right_margin = var->right_margin - margin_adjust.dx,
+		.upper_margin = var->upper_margin + margin_adjust.dy,
+		.lower_margin = var->lower_margin - margin_adjust.dy,
 		.hsync_len    = var->hsync_len,
 		.vsync_len    = var->vsync_len,
 		.sync         = var->sync,
@@ -2198,6 +2235,9 @@ static int ps2fb_probe(struct platform_device *pdev)
 		goto err_register_framebuffer;
 	}
 
+	/* Clear the mode adjustment after setting the initial mode. */
+	mode_margin = "";
+
 	platform_set_drvdata(pdev, info);
 
 	return 0;
@@ -2269,6 +2309,8 @@ static int __init ps2fb_init(void)
 			mode_option = &this_opt[12];
 		else if ('0' <= this_opt[0] && this_opt[0] <= '9')
 			mode_option = this_opt;
+		else if (!strncmp(this_opt, "mode_margin:", 12))
+			mode_margin = &this_opt[12];
 		else
 			pr_warn(DEVICE_NAME ": Unrecognized option \"%s\"\n",
 				this_opt);
@@ -2307,6 +2349,14 @@ module_param(mode_option, charp, 0);
 MODULE_PARM_DESC(mode_option,
 	"Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
 
+/*
+ * Analogue devices are frequently a few pixels off. Use this mode_margin
+ * option to make necessary device dependent adjustments to the built-in modes.
+ */
+module_param(mode_margin, charp, 0);
+MODULE_PARM_DESC(mode_margin,
+	"Adjust initial video mode margin as \"<-|+><dx><-|+><dy>\"");
+
 MODULE_DESCRIPTION("PlayStation 2 frame buffer driver");
 MODULE_AUTHOR("Fredrik Noring");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.21.0
#145 lore raw

PATCH 112/120 USB: OHCI: Support for the PlayStation 2

In reply to Fredrik Noring

Support the USB 1.1 OHCI for the PlayStation 2. The controller is connected to the input/output processor (IOP) which is separate from the main (R5900) processor that runs the kernel.

IOP DMA memory and OHCI registers are mapped into kernel address space. OHCI interrupts are asserted on the IOP and forwarded to the kernel by an IOP IRQ relay module.

---
 drivers/usb/host/Kconfig    |   8 ++
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/ohci-ps2.c | 245 ++++++++++++++++++++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/usb/host/ohci-ps2.c
drivers/usb/host/Kconfig +8 -0
index 40b5de597112..5b3b138006cd 100644
@@ -552,6 +552,14 @@ config USB_OHCI_EXYNOS
 	help
 	 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
 
+config USB_OHCI_HCD_PS2
+	tristate "OHCI support for the Sony PlayStation 2"
+	depends on SONY_PS2
+	select GENERIC_ALLOCATOR
+	default y
+	help
+	 Enable support for the Sony PlayStation 2 OHCI controller.
+
 config USB_CNS3XXX_OHCI
 	bool "Cavium CNS3XXX OHCI Module (DEPRECATED)"
 	depends on ARCH_CNS3XXX
drivers/usb/host/Makefile +1 -0
index 84514f71ae44..9ed4e0fa6657 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_USB_OHCI_HCD_S3C2410)	+= ohci-s3c2410.o
 obj-$(CONFIG_USB_OHCI_HCD_LPC32XX)	+= ohci-nxp.o
 obj-$(CONFIG_USB_OHCI_HCD_PXA27X)	+= ohci-pxa27x.o
 obj-$(CONFIG_USB_OHCI_HCD_DAVINCI)	+= ohci-da8xx.o
+obj-$(CONFIG_USB_OHCI_HCD_PS2)	+= ohci-ps2.o
 
 obj-$(CONFIG_USB_UHCI_HCD)	+= uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD)	+= fhci.o
drivers/usb/host/ohci-ps2.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
2.21.0
#146 lore raw

PATCH 113/120 USB: OHCI: OHCI_INTR_MIE workaround for freeze on the PlayStation 2

In reply to Fredrik Noring

OHCI_INTR_MIE needs to be disabled, most likely due to a hardware bug. Without it, reading a large amount of data (> 1 GB) from a mass storage device results in a freeze.

---
 drivers/usb/host/ohci-ps2.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/usb/host/ohci-ps2.c +19 -0
index a1d446313c13..cdbcbe5ff34e 100644
@@ -35,6 +35,7 @@ struct ps2_hcd {
 };
 
 static struct hc_driver __read_mostly ohci_ps2_hc_driver;
+static irqreturn_t (*ohci_irq)(struct usb_hcd *hcd);
 
 static void ohci_ps2_enable(struct usb_hcd *hcd)
 {
@@ -79,6 +80,21 @@ static int ohci_ps2_reset(struct usb_hcd *hcd)
 	return 0;
 }
 
+static irqreturn_t ohci_ps2_irq(struct usb_hcd *hcd)
+{
+	struct ohci_hcd	*ohci = hcd_to_ohci(hcd);
+	struct ohci_regs __iomem *regs = ohci->regs;
+
+	/*
+	 * OHCI_INTR_MIE needs to be disabled, most likely due to a
+	 * hardware bug. Without it, reading a large amount of data
+	 * (> 1 GB) from a mass storage device results in a freeze.
+	 */
+	ohci_writel(ohci, OHCI_INTR_MIE, &regs->intrdisable);
+
+	return ohci_irq(hcd);	/* Call normal IRQ handler. */
+}
+
 static int iopheap_alloc_dma_buffer(struct platform_device *pdev, size_t size)
 {
 	struct device *dev = &pdev->dev;
@@ -228,6 +244,9 @@ static int __init ohci_ps2_init(void)
 
 	ohci_init_driver(&ohci_ps2_hc_driver, &ps2_overrides);
 
+	ohci_irq = ohci_ps2_hc_driver.irq;	/* Save normal IRQ handler. */
+	ohci_ps2_hc_driver.irq = ohci_ps2_irq;	/* Install IRQ workaround. */
+
 	return platform_driver_register(&ohci_hcd_ps2_driver);
 }
 module_init(ohci_ps2_init);
Signature · 1 line
2.21.0
#147 lore raw

PATCH 114/120 MIPS: PS2: Workaround for unexpected uLaunchELF CP0 Status user mode

In reply to Fredrik Noring

The PlayStation 2 uLaunchELF program, used as a kernel boot loader, starts in user mode with CP0 access enabled (CP0 Status 0x70030c11). This is unexpected and causes a boot freeze.

---
 arch/mips/boot/compressed/head.S | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/mips/boot/compressed/head.S +9 -0
index e3dc831e2616..6dc728d6ebea 100644
@@ -24,6 +24,15 @@ start:
 	move	s2, a2
 	move	s3, a3
 
+#ifdef CONFIG_CPU_R5900
+	# The PlayStation 2 uLaunchELF starts in user mode with
+	# CP0 access enabled (CP0 Status 0x70030c11), which is
+	# unexpected. This is corrected here:
+	li	k0, 0x30010000
+	mtc0	k0, $12
+	sync.p
+#endif /* CONFIG_CPU_R5900 */
+
 	/* Clear BSS */
 	PTR_LA	a0, _edata - 4
 	PTR_LA	a2, _end
Signature · 1 line
2.21.0
#148 lore raw

PATCH 115/120 MIPS: PS2: Define initial PlayStation 2 devices

In reply to Fredrik Noring

Only the real-time clock (RTC), the input/output processor (IOP), USB OHCI and the Graphics Synthesizer are supported at the moment.

---
 arch/mips/ps2/Makefile  |  1 +
 arch/mips/ps2/devices.c | 98 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 arch/mips/ps2/devices.c
arch/mips/ps2/Makefile +1 -0
index 6f671112fbcb..925952a83625 100644
@@ -1,3 +1,4 @@
+obj-y		+= devices.o
 obj-y		+= dmac-irq.o
 obj-y		+= identify.o
 obj-y		+= intc-irq.o
arch/mips/ps2/devices.c new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
2.21.0
#149 lore raw

PATCH 116/120 MIPS: PS2: Define workarounds related to the PlayStation 2

In reply to Fredrik Noring
---
 arch/mips/include/asm/mach-ps2/war.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 arch/mips/include/asm/mach-ps2/war.h
arch/mips/include/asm/mach-ps2/war.h new file +24 -0
new file mode 100644
index 000000000000..f2ebbd31e9ee
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PlayStation 2 workarounds
+ *
+ * Copyright (C) 2010-2013 Jürgen Urban
+ */
+
+#ifndef __ASM_MIPS_MACH_PS2_WAR_H
+#define __ASM_MIPS_MACH_PS2_WAR_H
+
+#define R4600_V1_INDEX_ICACHEOP_WAR	0
+#define R4600_V1_HIT_CACHEOP_WAR	0
+#define R4600_V2_HIT_CACHEOP_WAR	0
+#define R5432_CP0_INTERRUPT_WAR		0
+#define BCM1250_M3_WAR			0
+#define SIBYTE_1956_WAR			0
+#define MIPS4K_ICACHE_REFILL_WAR	0
+#define MIPS_CACHE_SYNC_WAR		0
+#define TX49XX_ICACHE_INDEX_INV_WAR	0
+#define ICACHE_REFILLS_WORKAROUND_WAR	0
+#define R10000_LLSC_WAR			0
+#define MIPS34K_MISSED_ITLB_WAR		0
+
+#endif /* __ASM_MIPS_MACH_PS2_WAR_H */
Signature · 1 line
2.21.0
#150 lore raw

PATCH 117/120 MIPS: PS2: Define R5900 feature overrides

In reply to Fredrik Noring
---
 .../asm/mach-ps2/cpu-feature-overrides.h      | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 arch/mips/include/asm/mach-ps2/cpu-feature-overrides.h
arch/mips/include/asm/mach-ps2/cpu-feature-overrides.h new file +35 -0
new file mode 100644
index 000000000000..e9b218e657f7
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PlayStation 2 CPU features
+ *
+ * Copyright (C) 2010-2013 Jürgen Urban
+ */
+
+#ifndef __ASM_MACH_PS2_CPU_FEATURE_OVERRIDES_H
+#define __ASM_MACH_PS2_CPU_FEATURE_OVERRIDES_H
+
+#define cpu_has_llsc			0
+#define cpu_has_4k_cache		1
+#define cpu_has_divec			1
+#define cpu_has_4kex			1
+#define cpu_has_counter			1
+#define cpu_has_cache_cdex_p		0
+#define cpu_has_cache_cdex_s		0
+#define cpu_has_mcheck			0
+#define cpu_has_nofpuex			1
+#define cpu_has_mipsmt			0
+#define cpu_has_vce			0
+#define cpu_has_dsp			0
+#define cpu_has_userlocal		0
+#define cpu_has_64bit_addresses		0
+#define cpu_has_64bit   		1	/* FIXME */
+#define cpu_has_64bit_gp_regs		0	/* FIXME */
+#define cpu_has_64bit_zero_reg		0	/* FIXME */
+#define cpu_vmbits			31
+#define cpu_has_clo_clz			0
+#define cpu_has_ejtag			0
+#define cpu_has_ic_fills_f_dc		0
+#define cpu_has_inclusive_pcaches	0
+#define cpu_has_fpu 			0	/* FIXME */
+
+#endif /* __ASM_MACH_PS2_CPU_FEATURE_OVERRIDES_H */
Signature · 1 line
2.21.0
#151 lore raw

PATCH 118/120 MIPS: PS2: Define the PlayStation 2 platform

In reply to Fredrik Noring
---
 arch/mips/Kbuild.platforms |  1 +
 arch/mips/ps2/Makefile     |  1 +
 arch/mips/ps2/Platform     |  7 +++++++
 arch/mips/ps2/prom.c       | 18 ++++++++++++++++++
 4 files changed, 27 insertions(+)
 create mode 100644 arch/mips/ps2/Platform
 create mode 100644 arch/mips/ps2/prom.c
arch/mips/Kbuild.platforms +1 -0
index 0de839882106..84be263f44d2 100644
@@ -24,6 +24,7 @@ platforms += netlogic
 platforms += paravirt
 platforms += pic32
 platforms += pistachio
+platforms += ps2
 platforms += pmcs-msp71xx
 platforms += pnx833x
 platforms += ralink
arch/mips/ps2/Makefile +1 -0
index 925952a83625..dbc1bdbac2a8 100644
@@ -4,6 +4,7 @@ obj-y		+= identify.o
 obj-y		+= intc-irq.o
 obj-y		+= irq.o
 obj-y		+= memory.o
+obj-y		+= prom.o
 obj-y		+= reboot.o
 obj-y		+= rom.o
 obj-m		+= rom-sysfs.o
arch/mips/ps2/Platform new file +7 -0
new file mode 100644
index 000000000000..5e9695f86b99
@@ -0,0 +1,7 @@
+#
+# PlayStation 2
+#
+platform-$(CONFIG_SONY_PS2)	+= ps2/
+cflags-$(CONFIG_SONY_PS2)	+= -I$(srctree)/arch/mips/include/asm/mach-ps2
+load-$(CONFIG_SONY_PS2)		+= 0x80010000
+zload-$(CONFIG_SONY_PS2)	+= 0x00800000
arch/mips/ps2/prom.c new file +18 -0
new file mode 100644
index 000000000000..f4d594c4457e
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PlayStation 2 PROM handling
+ */
+
+#include <linux/module.h>
+
+void prom_putchar(char c)
+{
+}
+
+void __init prom_init(void)
+{
+}
+
+void __init prom_free_prom_memory(void)
+{
+}
Signature · 1 line
2.21.0
#152 lore raw

PATCH 119/120 MIPS: PS2: Initial support for the Sony PlayStation 2

In reply to Fredrik Noring
---
 arch/mips/Kconfig | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/mips/Kconfig +22 -0
index 88d6c13260e1..f90af3fd31d3 100644
@@ -1011,6 +1011,27 @@ config MIPS_PARAVIRT
 	help
 	  This option supports guest running under ????
 
+config SONY_PS2
+	bool "Sony PlayStation 2"
+	select BOOT_ELF32
+	select CEVT_R4K
+	select CSRC_R4K
+	select DMA_NONCOHERENT
+	select HARDIRQS_SW_RESEND
+	select HAVE_PATA_PLATFORM
+	select IRQ_MIPS_CPU
+	select MIPS_L1_CACHE_SHIFT_6
+	select NO_IOPORT
+	select SYS_HAS_CPU_R5900
+	select SYS_HAS_EARLY_PRINTK
+	select SYS_SUPPORTS_32BIT_KERNEL
+	select SYS_SUPPORTS_LITTLE_ENDIAN
+	select SYS_SUPPORTS_ZBOOT
+	select USB_ARCH_HAS_OHCI
+	select USB_OHCI_LITTLE_ENDIAN
+	help
+	  This enables support for the Sony PlayStation 2.
+
 endchoice
 
 source "arch/mips/alchemy/Kconfig"
@@ -1037,6 +1058,7 @@ source "arch/mips/loongson32/Kconfig"
 source "arch/mips/loongson64/Kconfig"
 source "arch/mips/netlogic/Kconfig"
 source "arch/mips/paravirt/Kconfig"
+source "arch/mips/ps2/Kconfig"
 
 endmenu
 
Signature · 1 line
2.21.0
#153 lore raw

PATCH 120/120 MIPS: Fix name of BOOT_MEM_ROM_DATA

In reply to Fredrik Noring
---
 arch/mips/kernel/setup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/mips/kernel/setup.c +4 -2
index ab349d2381c3..7d5bf8cb513b 100644
@@ -870,14 +870,16 @@ static void __init resource_init(void)
 		switch (boot_mem_map.map[i].type) {
 		case BOOT_MEM_RAM:
 		case BOOT_MEM_INIT_RAM:
-		case BOOT_MEM_ROM_DATA:
 			res->name = "System RAM";
 			res->flags |= IORESOURCE_SYSRAM;
 			break;
+		case BOOT_MEM_ROM_DATA:
+			res->name = "System ROM";
+			break;
 		case BOOT_MEM_RESERVED:
 		case BOOT_MEM_NOMAP:
 		default:
-			res->name = "reserved";
+			res->name = "Reserved";
 		}
 
 		request_resource(&iomem_resource, res);
Signature · 1 line
2.21.0
Reviewed-by on v1 120/120
#154 lore raw

Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA

Quoted 15 lines · Fredrik Noring
---
 arch/mips/kernel/setup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/mips/kernel/setup.c +0 -1
index ab349d2381c3..7d5bf8cb513b 100644
@@ -870,14 +870,16 @@ static void __init resource_init(void)
 		switch (boot_mem_map.map[i].type) {
 		case BOOT_MEM_RAM:
 		case BOOT_MEM_INIT_RAM:
-		case BOOT_MEM_ROM_DATA:
 			res->name = "System RAM";

arch/mips/kernel/setup.c static void __init resource_init(void) · line 882

Quoted 10 lines
arch/mips/kernel/setup.c +4 -1
 			res->flags |= IORESOURCE_SYSRAM;
 			break;
+		case BOOT_MEM_ROM_DATA:
+			res->name = "System ROM";
+			break;
 		case BOOT_MEM_RESERVED:
 		case BOOT_MEM_NOMAP:
 		default:
-			res->name = "reserved";
+			res->name = "Reserved";
Quoted 4 lines
arch/mips/kernel/setup.c +0 -0
 		}
 
 		request_resource(&iomem_resource, res);
maintainer
#155 lore raw

Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA

In reply to Fredrik Noring
Quoted 10 lines · Fredrik Noring
---
  arch/mips/kernel/setup.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
arch/mips/kernel/setup.c +0 -0
index ab349d2381c3..7d5bf8cb513b 100644

arch/mips/kernel/setup.c static void __init resource_init(void) · line 878

Quoted 10 lines
arch/mips/kernel/setup.c +3 -1
@@ -870,14 +870,16 @@ static void __init resource_init(void)
  		switch (boot_mem_map.map[i].type) {
  		case BOOT_MEM_RAM:
  		case BOOT_MEM_INIT_RAM:
-		case BOOT_MEM_ROM_DATA:
  			res->name = "System RAM";
  			res->flags |= IORESOURCE_SYSRAM;
  			break;
+		case BOOT_MEM_ROM_DATA:
+			res->name = "System ROM";
+			break;

Hi Fredik,

ROM_DATA meant memory used by ROM(Bootloader) to store data in some machines, is that name right?

Btw, boot_mem_map had been droped recently, see mips-next tree, please rebase.

Thanks

--

Jiaxun Yang

Quoted 8 lines
arch/mips/kernel/setup.c +1 -1
  		case BOOT_MEM_RESERVED:
  		case BOOT_MEM_NOMAP:
  		default:
-			res->name = "reserved";
+			res->name = "Reserved";
  		}
 
  		request_resource(&iomem_resource, res);
#156 lore raw

Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA

Quoted 2 lines

ROM_DATA meant memory used by ROM(Bootloader) to store data in some machines, is that name right?

That's the machine reset code, and other things such as the BIOS, drivers, firmware, splash screen animations, a DVD player, etc.

Quoted 2 lines

Btw, boot_mem_map had been droped recently, see mips-next tree, please rebase.

OK, then I think we can drop this patch since it was meant as a starting point to mapping all addresses in /proc/iomem. I have patches that make it look like this:

# cat /proc/iomem 
00000000-01ffffff : System RAM
  00010000-00431c4b : Kernel code
  00431c4c-00584fff : Kernel data
  007c0000-007e695f : Kernel bss
12000000-13ffffff : Graphics Synthesizer
1c000000-1c1fffff : IOP RAM
1e000000-1e0fffff : System ROM
1f801600-1f8016ff : USB OHCI
1fc00000-1fffffff : System ROM

There are many other regions, and it would be useful to have them all included eventually, but they are not essential for the initial system.

Fredrik

maintainer
#157 lore raw

Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA

Quoted 4 lines · Fredrik Noring
Quoted 2 lines

ROM_DATA meant memory used by ROM(Bootloader) to store data in some machines, is that name right?

That's the machine reset code, and other things such as the BIOS, drivers, firmware, splash screen animations, a DVD player, etc.

Hi Fredik,

Then it's not *memory* right?'

And It should not be managed by boot_mem_map (Or memblock after boot_mem_map being dropped).

Quoted 5 lines
Quoted 2 lines

Btw, boot_mem_map had been droped recently, see mips-next tree, please rebase.

OK, then I think we can drop this patch since it was meant as a starting point to mapping all addresses in /proc/iomem. I have patches that make it look like this:

Add these stuff to resource system by platform code is better than hijack memory map of all other machines.

Quoted 12 lines
# cat /proc/iomem
00000000-01ffffff : System RAM
   00010000-00431c4b : Kernel code
   00431c4c-00584fff : Kernel data
   007c0000-007e695f : Kernel bss
12000000-13ffffff : Graphics Synthesizer
1c000000-1c1fffff : IOP RAM
1e000000-1e0fffff : System ROM
1f801600-1f8016ff : USB OHCI
1fc00000-1fffffff : System ROM
Quoted 4 lines

There are many other regions, and it would be useful to have them all included eventually, but they are not essential for the initial system.

Fredrik

Thanks.

--

Jiaxun Yang

#158 lore raw

Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA

Quoted 4 lines

Then it's not *memory* right?'

And It should not be managed by boot_mem_map (Or memblock after boot_mem_map being dropped).

ROM0 corresponds to IC503 (BOOT) and ROM1 to IC506 (DVD) in the SCPH-30000 series edition 6 service manual. Both 4 MiB 44 pin chips. IC506 is faintly marked with SCEI at the bottom of this image of the A side of the mainboard:

https://commons.wikimedia.org/wiki/File:PS2-SCPH-30001-Motherboard.jpg

IC503 is on the B side. What would they be if not read-only memory?

Sony made numerous revisions of their mainboards, so earlier and later designs were different.

Quoted 2 lines

Add these stuff to resource system by platform code is better than hijack memory map of all other machines.

Sorry, I was unclear. The other ones are platform resources, although incomplete.

Fredrik

#159 lore raw
In reply to Fredrik Noring

Hi Fredrik,

Quoted 6 lines · Fredrik Noring

Hi Paul,

This is the initial patch submission for the PlayStation 2. The series implements support for USB devices and a frame buffer console, making Linux usable with unmodified hardware having a working boot loader installed on a memory card.

Wow - you've been busy, this patchset is huge!

Quoted 1 line

There are eight major parts:

I think we may be best to split this up into 8 (or more) different patchsets along these lines. In my experience large patchsets that touch lots of different subsystems are very difficult to get merged, so I'd suggest maybe we start with just the CPU support for arch/mips/ & if you have the bandwidth you could submit drivers to other subsystem maintainers in parallel.

Quoted 6 lines

1. The R5900 is the main processor that runs the kernel[1]. It implements the 64-bit MIPS III instruction set except LL, SC, LLD and SCD, with additional PREFETCH and conditional move instructions from MIPS IV as well as three-operand multiply and multiply-accumulate instructions. It has a set of R5900 specific 128-bit multimedia instructions (MMIs).

Quoted 8 lines

The FPU implements single-precision floating-point operations but it is not entirely IEEE 754 compatible. The FPU is therefore emulated in software for normal ELF executables. The R5900 has several significant hardware bugs. Perhaps the most important bug affecting applications is the short loop bug that under certain conditions causes loops to execute only once or twice.

R5900 specific handling of SYNC.P, SYNC.L, ERET, etc. are implemented.

I see you already got a few comments including on some of the early CPU-related patches. I'll start looking through them in detail soon.

Thanks,
Paul

Quoted 356 lines

2. Interrupts, a timer and minimal DMA support are implemented.

3. System commands (SCMDs) are implemented to identify the hardware model, read and set the real-time clock (RTC), and power off the machine.

4. Read-only memory (ROM) operations are implemented. These are used to identify the hardware. ROM operations are also used to resolve IOP libraries linked as firmware, as explained below.

6. The input/output processor (IOP) and its sub-system interface (SIF) are supported[2]. The IOP is a MIPS R3000A, or in later models a PowerPC 405GP emulating a MIPS R3000A, sometimes referred to as the sub processor. It runs a separate minikernel implemented in ROM. Most peripherals require, in whole or in part, handling by the IOP.

Two IOP services are required to support USB devices: IOP memory allocation and IOP interrupt relay. The latter requires linking a custom IOP module, handled as firmware by the kernel, with library dependency resolution. Remote procedure calls (RPCs) are used to issue bidirectional commands over the SIF, via DMA.

7. The Graphics Synthesizer (GS) is the video hardware that displays the frame buffer console. The GS is highly configurable with a substantial set of hardware accelerated features. Its local memory is not directly accessible from the main bus. All drawing primitives are transmitted via DMA[3].

8. The frame buffer driver implements console support. The font is stored as textures in local GS memory and several hardware accelerated operations are implemented, for example XPAN, YPAN and YWRAP.

The o32 ABI is supported, but not yet n32 as it involves some additional complications. I would very much like to add support for the 128-bit R5900 GPRs, for two primary reasons:

- The 128-bit multimedia instruction set is one of the defining features of the R5900. A respectable PlayStation 2 application ought to use them.

- The MMIs cannot be disabled by the kernel. MMIs will therefore appear to mostly work, with some occasional register corruption due to context switches, unless the kernel properly saves and restores the 128-bit registers.

This patch series has been tested with the PlayStation 2 models SCPH-30004, SCPH-30004 R, SCPH-37000 L, SCPH-39004, SCPH-50004, SCPH-70004, SCPH-75004 and SCPH-77004.

Please consider it for inclusion.

Fredrik

References:

[1] "TX System RISC TX79 Core Architecture" manual, revision 2.0, Toshiba Corporation, https://wiki.qemu.org/File:C790.pdf

[2] "EE Overview", version 6.0, Sony Computer Entertainment Inc.

[3] "GS User's Manual", version 6.0, Sony Computer Entertainment Inc.

Fredrik Noring (120):
MIPS: R5900: Initial support for the Emotion Engine in the PlayStation 2
MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
MIPS: R5900: Sign-extend o32 system call registers
MIPS: R5900: Reset bits 127..64 of GPRs in RESTORE_SOME
MIPS: R5900: Reset the funnel shift amount (SA) register in RESTORE_SOME
MIPS: R5900: Workaround for the short loop bug
MIPS: R5900: Add the SYNC.P instruction
MIPS: R5900: Add implicit SYNC.P to the UASM_i_M[FT]C0 macros
MIPS: R5900: Add mandatory SYNC.P to all M[FT]C0 instructions
MIPS: R5900: Workaround exception NOP execution bug (FLX05)
MIPS: R5900: Avoid pipeline hazard with the TLBP instruction
MIPS: R5900: Avoid pipeline hazards with the TLBW[IR] instructions
MIPS: R5900: Avoid pipeline hazard with the TLBR instruction
MIPS: R5900: Install final length of TLB refill handler rather than 256 bytes
MIPS: R5900: Verify that the TLB refill handler does not overflow
MIPS: R5900: The ERET instruction has issues with delay slot and CACHE
MIPS: R5900: Define CACHE instruction operation field encodings
MIPS: R5900: Workaround where MSB must be 0 for the instruction cache
MIPS: R5900: Use SYNC.L for data cache and SYNC.P for instruction cache
MIPS: R5900: Define CP0.Config register fields
MIPS: R5900: Workaround for CACHE instruction near branch delay slot
MIPS: R5900: Support 64-bit inq() and outq() macros in 32-bit kernels
MIPS: R5900: Add MFSA and MTSA instructions for the special SA register
MIPS: PS2: Define PlayStation 2 I/O port, ROM and RAM address spaces
MIPS: PS2: Define interrupt controller, DMA and timer IRQs
MIPS: PS2: Interrupt controller (INTC) IRQ support
MIPS: PS2: DMAC: Define DMA controller registers
MIPS: PS2: DMAC: Define tag structures
MIPS: PS2: DMAC: IRQ support
MIPS: PS2: Timer support
MIPS: PS2: SCMD: System command support
MIPS: PS2: SCMD: System power off command
MIPS: PS2: SCMD: Read system machine name command
MIPS: PS2: SCMD: Read system command for the real-time clock (RTC)
MIPS: PS2: SCMD: Set system command for the real-time clock (RTC)
MIPS: PS2: ROM: Iterate over the files in a given ROM directory
MIPS: PS2: ROM: Find ROM files with a given name, if they exist
MIPS: PS2: ROM: Read data for a given ROM file name
MIPS: PS2: ROM: Read extended information for a given ROM file
MIPS: PS2: ROM: Read and decode the ROMVER file
MIPS: PS2: ROM: Resolve the name for the type in the ROMVER file
MIPS: PS2: ROM: Resolve the name for the region in the ROMVER file
MIPS: PS2: ROM: Permit /dev/mem to access read-only memory
MIPS: PS2: ROM: Sysfs module to inspect ROM files
MIPS: PS2: ROM: Provide extended file information via sysfs
MIPS: PS2: Identify the machine by model name
MIPS: PS2: Let the system type be Sony PlayStation 2
MIPS: Define and use cpu_relax_forever() for various halting loops
MIPS: PS2: Power off support
MIPS: PS2: Real-time clock (RTC) driver
MIPS: PS2: IOP: I/O processor DMA register PCR2 set and clear
MIPS: PS2: SIF: Sub-system interface reset of the I/O processor (IOP)
MIPS: PS2: IOP: Define error numbers, descriptions and errno mapping
MIPS: PS2: SIF: SIF register write command support
MIPS: PS2: SIF: Respond to remote procedure call (RPC) bind command
MIPS: PS2: SIF: Respond to RPC bind end command
MIPS: PS2: SIF: Reset the SIF0 (sub-to-main) DMA controller
MIPS: PS2: SIF: Handle SIF0 (sub-to-main) RPCs via interrupts
MIPS: PS2: SIF: Enable the IOP to issue SIF commands
MIPS: PS2: SIF: Enable the IOP to issue SIF RPCs
MIPS: PS2: SIF: sif_rpc_bind() to request an RPC server connection
MIPS: PS2: SIF: sif_rpc_unbind() to release an RPC server connection
MIPS: PS2: SIF: sif_rpc() to issue a remote procedure call
MIPS: PS2: IOP: Permit /dev/mem to access IOP memory
MIPS: PS2: IOP: I/O processor memory support
FIXME: Export _dma_cache_{wback,wback_inv,inv}
MIPS: PS2: IOP: Module linking support
MIPS: PS2: IOP: Verify that modules are IRX objects
MIPS: PS2: IOP: Module version compatibility verification
MIPS: PS2: IOP: Avoid linking already linked library modules
MIPS: PS2: IOP: Resolve module dependencies
MIPS: PS2: IOP: SIF printk command support
MIPS: PS2: IOP: Heap memory allocate and free
MIPS: PS2: SIF: Request RPC IRQ command
MIPS: PS2: IOP: IRQ support
MIPS: PS2: GS: Define privileged Graphics Synthesizer registers
MIPS: PS2: GS: Write privileged registers
MIPS: PS2: GS: Read privileged registers
MIPS: PS2: GS: Define privileged register structures
MIPS: PS2: GS: Define gs_xorq_imr()
MIPS: PS2: GS: Privileged register write macros with named fields
MIPS: PS2: GS: IRQ support
MIPS: PS2: GS: Define Graphics Synthesizer primitive structures
MIPS: PS2: GIF: Define Graphics Synthesizer interface structures
MIPS: PS2: GIF: Graphics Synthesizer interface support
MIPS: PS2: GS: Graphics Synthesizer device init and video clock
MIPS: PS2: GS: Compute block count and indices
MIPS: PS2: GS: Primitive and texel coordinate transformations
MIPS: PS2: GS: Approximate video region with ROM region
macro: Extend COUNT_ARGS() from 12 to 32 arguments
MIPS: PS2: GS: Show privileged registers with sysfs
MIPS: PS2: GS: Store privileged registers with sysfs
fbdev: Add fb_warn_once() variant that only prints a warning once
MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
MIPS: PS2: FB: fb_set_par() standard-definition television support
MIPS: PS2: FB: fb_set_par() high-definition television support
MIPS: PS2: FB: fb_set_par() VESA computer display mode support
MIPS: PS2: FB: Preconfigure standard PAL, NTSC and VESA display modes
MIPS: PS2: FB: Reset the Graphics Synthesizer drawing environment
MIPS: PS2: FB: Clear the display buffer when changing video modes
MIPS: PS2: FB: fb_setcolreg() 256 colour pseudo palette support
MIPS: PS2: FB: fb_settile() with font stored as palette indexed textures
MIPS: PS2: FB: Hardware accelerated fb_tilecopy() support
MIPS: PS2: FB: Hardware accelerated fb_tilefill() support
MIPS: PS2: FB: Simplified fb_tileblit() support
MIPS: PS2: FB: fb_tilecursor() placeholder
MIPS: PS2: FB: Hardware accelerated fb_pan_display() support
MIPS: PS2: FB: fb_blank() display power management signaling (DPMS)
MIPS: PS2: FB: Disable GIF DMA completion interrupts
MIPS: PS2: FB: PAL and NTSC grayscale support
MIPS: PS2: FB: Analogue display mode adjustment module parameter
USB: OHCI: Support for the PlayStation 2
USB: OHCI: OHCI_INTR_MIE workaround for freeze on the PlayStation 2
MIPS: PS2: Workaround for unexpected uLaunchELF CP0 Status user mode
MIPS: PS2: Define initial PlayStation 2 devices
MIPS: PS2: Define workarounds related to the PlayStation 2
MIPS: PS2: Define R5900 feature overrides
MIPS: PS2: Define the PlayStation 2 platform
MIPS: PS2: Initial support for the Sony PlayStation 2
MIPS: Fix name of BOOT_MEM_ROM_DATA

 arch/mips/Kbuild.platforms                    |    1 +
 arch/mips/Kconfig                             |   35 +-
 arch/mips/Makefile                            |    1 +
 arch/mips/alchemy/board-gpr.c                 |    7 +-
 arch/mips/alchemy/board-mtx1.c                |    7 +-
 arch/mips/alchemy/board-xxs1500.c             |    7 +-
 arch/mips/alchemy/devboards/platform.c        |    4 +-
 arch/mips/ar7/setup.c                         |    4 +-
 arch/mips/ath79/setup.c                       |    8 +-
 arch/mips/bcm47xx/setup.c                     |    9 +-
 arch/mips/bcm63xx/setup.c                     |   12 +-
 arch/mips/boot/compressed/decompress.c        |    4 +-
 arch/mips/boot/compressed/head.S              |   16 +-
 arch/mips/cavium-octeon/smp.c                 |    4 +-
 arch/mips/cobalt/reset.c                      |    5 +-
 arch/mips/emma/markeins/setup.c               |    5 +-
 arch/mips/fw/arc/init.c                       |    4 +-
 arch/mips/include/asm/asmmacro.h              |   53 +
 arch/mips/include/asm/cacheops.h              |   17 +
 arch/mips/include/asm/cpu-type.h              |    4 +
 arch/mips/include/asm/cpu.h                   |    3 +-
 arch/mips/include/asm/io.h                    |   60 +-
 arch/mips/include/asm/irqflags.h              |   15 +
 .../asm/mach-ps2/cpu-feature-overrides.h      |   35 +
 arch/mips/include/asm/mach-ps2/dmac.h         |  254 ++
 arch/mips/include/asm/mach-ps2/gif.h          |   77 +
 arch/mips/include/asm/mach-ps2/gs-registers.h |  646 +++++
 arch/mips/include/asm/mach-ps2/gs.h           |   81 +
 arch/mips/include/asm/mach-ps2/iop-error.h    |   76 +
 arch/mips/include/asm/mach-ps2/iop-heap.h     |   19 +
 arch/mips/include/asm/mach-ps2/iop-memory.h   |   21 +
 arch/mips/include/asm/mach-ps2/iop-module.h   |   13 +
 .../mips/include/asm/mach-ps2/iop-registers.h |   19 +
 arch/mips/include/asm/mach-ps2/iop.h          |   21 +
 arch/mips/include/asm/mach-ps2/irq.h          |  130 +
 arch/mips/include/asm/mach-ps2/rom.h          |  171 ++
 arch/mips/include/asm/mach-ps2/scmd.h         |   56 +
 arch/mips/include/asm/mach-ps2/sif.h          |   94 +
 arch/mips/include/asm/mach-ps2/war.h          |   24 +
 arch/mips/include/asm/mipsregs.h              |  103 +
 arch/mips/include/asm/module.h                |    2 +
 arch/mips/include/asm/processor.h             |    6 +
 arch/mips/include/asm/r4kcache.h              |  244 +-
 arch/mips/include/asm/stackframe.h            |  108 +
 arch/mips/include/asm/string.h                |    3 +
 arch/mips/include/asm/traps.h                 |    2 +
 arch/mips/include/asm/uasm.h                  |   23 +
 arch/mips/include/uapi/asm/gif.h              |  164 ++
 arch/mips/include/uapi/asm/gs.h               |  723 +++++
 arch/mips/jz4740/reset.c                      |    9 +-
 arch/mips/kernel/cpu-probe.c                  |    8 +
 arch/mips/kernel/genex.S                      |   65 +
 arch/mips/kernel/head.S                       |    9 +
 arch/mips/kernel/r4k_switch.S                 |    9 +
 arch/mips/kernel/scall32-o32.S                |   12 +
 arch/mips/kernel/setup.c                      |    6 +-
 arch/mips/kernel/traps.c                      |   19 +-
 arch/mips/kernel/unaligned.c                  |   36 +-
 arch/mips/lib/delay.c                         |    7 +-
 arch/mips/lib/memset.S                        |    2 +
 arch/mips/loongson64/common/reset.c           |   16 +-
 arch/mips/mm/Makefile                         |    1 +
 arch/mips/mm/c-r4k.c                          |   27 +-
 arch/mips/mm/cache.c                          |    4 +
 arch/mips/mm/cerr-sb1.c                       |    4 +-
 arch/mips/mm/cex-gen.S                        |    6 +
 arch/mips/mm/tlbex-fault.S                    |    3 +
 arch/mips/mm/tlbex.c                          |   94 +-
 arch/mips/mm/uasm-mips.c                      |    1 +
 arch/mips/mm/uasm.c                           |    5 +-
 arch/mips/pic32/common/reset.c                |    9 +-
 arch/mips/pnx833x/common/reset.c              |    5 +-
 arch/mips/ps2/Kconfig                         |   16 +
 arch/mips/ps2/Makefile                        |   12 +
 arch/mips/ps2/Platform                        |    7 +
 arch/mips/ps2/devices.c                       |   98 +
 arch/mips/ps2/dmac-irq.c                      |  102 +
 arch/mips/ps2/identify.c                      |   86 +
 arch/mips/ps2/intc-irq.c                      |  118 +
 arch/mips/ps2/irq.c                           |   38 +
 arch/mips/ps2/memory.c                        |   45 +
 arch/mips/ps2/prom.c                          |   18 +
 arch/mips/ps2/reboot.c                        |   29 +
 arch/mips/ps2/rom-sysfs.c                     |  392 +++
 arch/mips/ps2/rom.c                           |  702 +++++
 arch/mips/ps2/scmd.c                          |  379 +++
 arch/mips/ps2/time.c                          |  153 ++
 arch/mips/sgi-ip22/ip22-reset.c               |    3 +-
 arch/mips/sgi-ip27/ip27-berr.c                |    4 +-
 arch/mips/sgi-ip27/ip27-reset.c               |   13 +-
 arch/mips/sgi-ip32/ip32-berr.c                |    4 +-
 arch/mips/sgi-ip32/ip32-irq.c                 |    3 +-
 arch/mips/sibyte/common/cfe.c                 |    3 +-
 arch/mips/txx9/rbtx4939/setup.c               |    4 +-
 arch/mips/vr41xx/common/pmu.c                 |    2 +-
 drivers/Makefile                              |    1 +
 drivers/ps2/Makefile                          |   12 +
 drivers/ps2/gif.c                             |  106 +
 drivers/ps2/gs-irq.c                          |   93 +
 drivers/ps2/gs-registers.c                    |  189 ++
 drivers/ps2/gs-sysfs.c                        |  592 +++++
 drivers/ps2/gs.c                              |  319 +++
 drivers/ps2/iop-heap.c                        |   90 +
 drivers/ps2/iop-irq.c                         |  186 ++
 drivers/ps2/iop-memory.c                      |   56 +
 drivers/ps2/iop-module.c                      |  954 +++++++
 drivers/ps2/iop-registers.c                   |   39 +
 drivers/ps2/sif.c                             |  888 +++++++
 drivers/rtc/Kconfig                           |   10 +
 drivers/rtc/Makefile                          |    1 +
 drivers/rtc/rtc-ps2.c                         |   74 +
 drivers/usb/host/Kconfig                      |    8 +
 drivers/usb/host/Makefile                     |    1 +
 drivers/usb/host/ohci-ps2.c                   |  264 ++
 drivers/video/fbdev/Kconfig                   |   12 +
 drivers/video/fbdev/Makefile                  |    1 +
 drivers/video/fbdev/ps2fb.c                   | 2362 +++++++++++++++++
 include/linux/console_struct.h                |    2 +
 include/linux/fb.h                            |    2 +
 include/linux/kernel.h                        |   12 +-
 include/uapi/linux/fb.h                       |    1 +
 121 files changed, 12077 insertions(+), 186 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-ps2/cpu-feature-overrides.h
 create mode 100644 arch/mips/include/asm/mach-ps2/dmac.h
 create mode 100644 arch/mips/include/asm/mach-ps2/gif.h
 create mode 100644 arch/mips/include/asm/mach-ps2/gs-registers.h
 create mode 100644 arch/mips/include/asm/mach-ps2/gs.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop-error.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop-heap.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop-memory.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop-module.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop-registers.h
 create mode 100644 arch/mips/include/asm/mach-ps2/iop.h
 create mode 100644 arch/mips/include/asm/mach-ps2/irq.h
 create mode 100644 arch/mips/include/asm/mach-ps2/rom.h
 create mode 100644 arch/mips/include/asm/mach-ps2/scmd.h
 create mode 100644 arch/mips/include/asm/mach-ps2/sif.h
 create mode 100644 arch/mips/include/asm/mach-ps2/war.h
 create mode 100644 arch/mips/include/uapi/asm/gif.h
 create mode 100644 arch/mips/include/uapi/asm/gs.h
 create mode 100644 arch/mips/ps2/Kconfig
 create mode 100644 arch/mips/ps2/Makefile
 create mode 100644 arch/mips/ps2/Platform
 create mode 100644 arch/mips/ps2/devices.c
 create mode 100644 arch/mips/ps2/dmac-irq.c
 create mode 100644 arch/mips/ps2/identify.c
 create mode 100644 arch/mips/ps2/intc-irq.c
 create mode 100644 arch/mips/ps2/irq.c
 create mode 100644 arch/mips/ps2/memory.c
 create mode 100644 arch/mips/ps2/prom.c
 create mode 100644 arch/mips/ps2/reboot.c
 create mode 100644 arch/mips/ps2/rom-sysfs.c
 create mode 100644 arch/mips/ps2/rom.c
 create mode 100644 arch/mips/ps2/scmd.c
 create mode 100644 arch/mips/ps2/time.c
 create mode 100644 drivers/ps2/Makefile
 create mode 100644 drivers/ps2/gif.c
 create mode 100644 drivers/ps2/gs-irq.c
 create mode 100644 drivers/ps2/gs-registers.c
 create mode 100644 drivers/ps2/gs-sysfs.c
 create mode 100644 drivers/ps2/gs.c
 create mode 100644 drivers/ps2/iop-heap.c
 create mode 100644 drivers/ps2/iop-irq.c
 create mode 100644 drivers/ps2/iop-memory.c
 create mode 100644 drivers/ps2/iop-module.c
 create mode 100644 drivers/ps2/iop-registers.c
 create mode 100644 drivers/ps2/sif.c
 create mode 100644 drivers/rtc/rtc-ps2.c
 create mode 100644 drivers/usb/host/ohci-ps2.c
 create mode 100644 drivers/video/fbdev/ps2fb.c
Signature · 1 line
2.21.0
#160 lore raw
Quoted 1 line

Wow - you've been busy, this patchset is huge!

I started in 2017 with a 2.6.35.14 patchset[1] maintained by Jürgen Urban, and ported it through 3.x, 4.x and 5.x to present day. The history goes back to 2.2.1[2] when Sony released a Linux kit.

Maciej W. Rozycki and Jürgen Urban have been very helpful along the way.

Most of the drivers in the 2.6 series are not present in this initial patchset. It is supposed to be fairly small, after all. Most of the other parts from 2.6 were eventually removed, reworked or expanded.

For example, the 2.6 kernel uses BIOS routines for certain services. The BIOS is discarded and the kernel handles the hardware directly in this patchset. Arbitrary video mode lines are now supported. The 2.6 kernel supported n32, and 128-bit GPRs, but this patchset supports only o32, and only 32-bit GPRs although I very much hope we can retain the support for 128-bit GPRs, as suggested in the patchset cover letter, as that is a defining feature of the R5900.

The input/output processor (IOP) modules, handled as firmware by the kernel, have also been reworked and updated for a modern compiler[3].

Some ideas and discussions on further development etc. can be found here:

https://github.com/frno7/linux/issues

Quoted 6 lines

I think we may be best to split this up into 8 (or more) different patchsets along these lines. In my experience large patchsets that touch lots of different subsystems are very difficult to get merged, so I'd suggest maybe we start with just the CPU support for arch/mips/ & if you have the bandwidth you could submit drivers to other subsystem maintainers in parallel.

Sure!

Quoted 2 lines

I see you already got a few comments including on some of the early CPU-related patches. I'll start looking through them in detail soon.

Great, thanks!

Fredrik

References:

[1] https://github.com/frno7/linux/tree/ps2-v2.6.35.14

[2] https://github.com/frno7/linux/tree/ps2-v2.2.1

[3] https://github.com/frno7/iopmod