Linux for the PlayStation 2
Subsystems (8)
PATCH 111/120 MIPS: PS2: FB: Analogue display mode adjustment module parameter
In reply to Fredrik NoringAnalogue 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
@@ -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
PATCH 112/120 USB: OHCI: Support for the PlayStation 2
In reply to Fredrik NoringSupport 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
@@ -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
@@ -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
PATCH 113/120 USB: OHCI: OHCI_INTR_MIE workaround for freeze on the PlayStation 2
In reply to Fredrik NoringOHCI_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
@@ -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 , ®s->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
PATCH 114/120 MIPS: PS2: Workaround for unexpected uLaunchELF CP0 Status user mode
In reply to Fredrik NoringThe 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
@@ -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
PATCH 115/120 MIPS: PS2: Define initial PlayStation 2 devices
In reply to Fredrik NoringOnly 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
@@ -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
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
@@ -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
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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
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
@@ -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
Re: [PATCH 011/120] MIPS: R5900: Avoid pipeline hazard with the TLBP instruction
In reply to Fredrik NoringHello!
Quoted 18 lines · Fredrik Noring
On the R5900, the TLBP instruction must be immediately followed by an ERET or a SYNC.P instruction[1].
References:
[1] "TX System RISC TX79 Core Architecture" manual, revision 2.0,
Toshiba Corporation, p. C-37, https://wiki.qemu.org/File:C790.pdfSigned-off-by Fredrik Noring <[email protected]>--- arch/mips/mm/tlbex.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)arch/mips/mm/tlbex.c +0
-0
arch/mips/mm/tlbex.c static void __maybe_unused build_tlb_probe_entry(u32 **p) · line 494
Quoted 6 lines
arch/mips/mm/tlbex.c +3
-0@@ -489,6 +489,19 @@ static void __maybe_unused build_tlb_probe_entry(u32 **p)uasm_i_tlbp (p);break ; +case CPU_R5900 : +/* +* On the R5900, the TLBWP instruction must be immediately
So is it TLBP or TLBWP?
arch/mips/mm/tlbex.c static void __maybe_unused build_tlb_probe_entry(u32 **p) · line 507
Quoted 13 lines
arch/mips/mm/tlbex.c +10
-0+* followed by an ERET or a SYNC.P instruction. +*/ +uasm_i_tlbp (p); +uasm_i_syncp (p); +uasm_i_nop (p); +uasm_i_nop (p); +uasm_i_nop (p); +uasm_i_nop (p); +break ; +default :uasm_i_tlbp (p);break ;
MBR, Sergei
Re: [PATCH 011/120] MIPS: R5900: Avoid pipeline hazard with the TLBP instruction
Hi Sergei,
Quoted 5 lines
arch/mips/mm/tlbex.c static void __maybe_unused build_tlb_probe_entry(u32 **p) · line 494
Quoted 3 lines
arch/mips/mm/tlbex.c +3
-0+case CPU_R5900 : +/* +* On the R5900, the TLBWP instruction must be immediately So is it TLBP or TLBWP?
TLBWP does not exist, so it must be TLBP. Thanks! :)
Fredrik
Re: [PATCH 072/120] MIPS: PS2: IOP: SIF printk command support
In reply to Fredrik NoringQuoted 15 lines · Fredrik Noring
Allow IOP modules to print kernel messages, with kernel log levels. This greatly simplifies debugging of subsequent IOP modules.
IOP messages are prefixed with "iop: " in the kernel log.
Signed-off-by Fredrik Noring <[email protected]>--- drivers/ps2/iop-module.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)drivers/ps2/iop-module.c +0
-0
drivers/ps2/iop-module.c int iop_module_request(const char *name, int version, const char *arg) · line 898
Quoted 7 lines
drivers/ps2/iop-module.c +4
-0@@ -892,6 +892,30 @@ int iop_module_request(const char *name, int version, const char *arg) }EXPORT_SYMBOL_GPL (iop_module_request); +/** +* cmd_printk - IOP module kernel log printk command +* @header: SIF command header +* @void: message to print
@data, maybe?
Quoted 13 lines
drivers/ps2/iop-module.c +13
-0+* @arg: optional argument to sif_request_cmd, set to %NULL +* +* The command allows IOP modules to print kernel messages, with kernel log +* levels. This greatly simplifies debugging of subsequent IOP modules. IOP +* messages are prefixed with "iop: " in the kernel log. +*/ +static void cmd_printk (const struct sif_cmd_header *header, +const void *data,void *arg) +{ +const char *msg = data; + +if (msg[0 ] ==KERN_SOH [0 ]) { + const char fmt[] = { msg[0], msg[1],
drivers/ps2/iop-module.c int iop_module_request(const char *name, int version, const char *arg) · line 921
Quoted 10 lines
drivers/ps2/iop-module.c +7
-0+ 'i', 'o', 'p', ':', ' ', '%', 's', '\0' }; + +printk (fmt, &msg[2 ]); + }else +printk ("iop: %s" , msg); +} +static int __init iop_module_init (void ) {int err;
[...]
MBR, Sergei
Re: [PATCH 072/120] MIPS: PS2: IOP: SIF printk command support
Hi Sergei,
Quoted 6 lines
Quoted 4 lines
+/**
+ *cmd_printk- IOP module kernel log printk command
+ * @header: SIF command header
+ * @void: message to print@data, maybe?
Indeed, thanks!
Fredrik
Re: [PATCH 001/120] MIPS: R5900: Initial support for the Emotion Engine in the PlayStation 2
In reply to Fredrik Noringarch/mips/include/asm/cpu.h line 89
Quoted 12 lines · Fredrik Noring
arch/mips/include/asm/cpu.h +1
-0@@ -83,6 +83,7 @@#define PRID_IMP_R4650 0x2200/* Same as R4640 */ #define PRID_IMP_R5000 0x2300#define PRID_IMP_TX49 0x2d00 +#define PRID_IMP_R5900 0x2e00/* PlayStation 2 */ #define PRID_IMP_SONIC 0x2400#define PRID_IMP_MAGIC 0x2500#define PRID_IMP_RM7000 0x2700
Hmm, I don't know why PRID_IMP_TX49 has been misplaced, 18 years ago with
commit b8c80cd25ffe ("Add missing PrId values for TX39 / TX 49 CPUs."), however I suggest that PRID_IMP_R5900 does not make things worse. I.e. please place it between PRID_IMP_NEVADA and PRID_IMP_RM9000.
Maciej
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
In reply to Fredrik NoringQuoted 2 lines · Fredrik Noring
CONFIG_DEFAULT_MMAP_MIN_ADDRmust not be less thanPAGE_SIZEto reliably trap and emulate RDHWR, so this is made aBUILD_BUG_ONfor the R5900.
I think a more complex solution is required as the value can be changed
at run time, via /proc/sys/vm/mmap_min_addr, defeating this protection. E.g. by introducing an ARCH_MIN_MMAP_MIN_ADDR minimum value, by default 0 unless overridden by the architecture selected, and then using it for both the default DEFAULT_MMAP_MIN_ADDR value and the minimum accepted via /proc/sys/vm/mmap_min_addr.
arch/mips/kernel/unaligned.c static void emulate_load_store_insn(struct pt_regs *regs, · line 1381
Quoted 12 lines
arch/mips/kernel/unaligned.c +1
-0@@ -1342,6 +1375,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,cu2_notifier_call_chain (CU2_SDC2_OP , regs);break ;#endif +default :/* * Pheeee... We encountered an yet unknown instruction or
Extraneous change.
Maciej
Re: [PATCH 010/120] MIPS: R5900: Workaround exception NOP execution bug (FLX05)
In reply to Fredrik NoringQuoted 8 lines · Fredrik Noring
For the R5900, there are cases in which the first two instructions in an exception handler are executed as NOP instructions, when certain exceptions occur and then a bus error occurs immediately before jumping to the exception handler (FLX05)[1].
The corrective measure is to place NOP in the first two instruction locations in all exception handlers.
Quoted 6 lines
References:
[1] "TX System RISC TX79 Core Architecture" manual, revision 2.0,
Toshiba Corporation, p. 1-11, https://wiki.qemu.org/File:C790.pdfSigned-off-by Fredrik Noring <[email protected]>
Quoted 57 lines
--- arch/mips/kernel/genex.S | 5 +++++ arch/mips/kernel/traps.c | 6 ++++++ arch/mips/mm/tlbex.c | 6 ++++++ 3 files changed, 17 insertions(+)arch/mips/kernel/genex.S +5
-0@@ -32,6 +32,11 @@ NESTED(except_vec3_generic, 0, sp) .set push .set noat +#ifdef CONFIG_CPU_R5900 + /* Workaround for R5900 exception execution bug (FLX05). */ + nop + nop +#endif #if R5432_CP0_INTERRUPT_WAR #ifdef CONFIG_CPU_R5900 sync.parch/mips/kernel/traps.c +6
-0@@ -1953,6 +1953,12 @@ void __init *set_except_vector(int n, void *addr)#endif u32 *buf = (u32 *)(ebase +0x200 );unsigned int k0 =26 ; + +#ifdef CONFIG_CPU_R5900 +/* Workaround for R5900 exception execution bug (FLX05). */ +uasm_i_nop (&buf); +uasm_i_nop (&buf); +#endif if ((handler & jump_mask) == ((ebase +0x200 ) & jump_mask)) {uasm_i_j (&buf, handler & ~jump_mask);uasm_i_nop (&buf);arch/mips/mm/tlbex.c +6
-0@@ -1313,6 +1313,12 @@ static void build_r4000_tlb_refill_handler(void)memset (relocs,0 ,sizeof (relocs));memset (final_handler,0 ,sizeof (final_handler)); +#ifdef CONFIG_CPU_R5900 +/* Workaround for R5900 exception execution bug (FLX05). */ +uasm_i_nop (&p); +uasm_i_nop (&p); +#endif +if (IS_ENABLED (CONFIG_64BIT ) && (scratch_reg >=0 ||scratchpad_available ()) &&use_bbit_insns ()) { htlb_info =build_fast_tlb_refill_handler (&p, &l, &r,K0 ,K1 , scratch_reg);
Re: [PATCH 020/120] MIPS: R5900: Define CP0.Config register fields
In reply to Fredrik NoringQuoted 32 lines · Fredrik Noring
The following CP0.Config fields are specific to the R5900[1]:
Field | Bit | Type | Description
------+-----+------+-----------------------------
DIE | 18 | RW | Enable double issue
ICE | 17 | RW | Enable the instruction cache
DCE | 16 | RW | Enable the data cache
BE | 15 | RO | Enable big-endian
NBE | 13 | RW | Enable nonblocking load
BPE | 12 | RW | Enable branch prediction
------+-----+------+-----------------------------References:
[1] "TX System RISC TX79 Core Architecture" manual, revision 2.0,
Toshiba Corporation, p. 4-23, https://wiki.qemu.org/File:C790.pdfSigned-off-by Fredrik Noring <[email protected]>--- arch/mips/include/asm/mipsregs.h | 8 ++++++++ 1 file changed, 8 insertions(+)arch/mips/include/asm/mipsregs.h +1
-0@@ -511,6 +511,14 @@#define R5K_CONF_SE (_ULCAST_(1) << 12)#define R5K_CONF_SS (_ULCAST_(3) << 20) +/* Bits specific to the R5900. */
arch/mips/include/asm/mipsregs.h line 524
Quoted 10 lines
arch/mips/include/asm/mipsregs.h +7
-0+#define R5900_CONF_BPE (_ULCAST_(1) << 12)/* Enable branch prediction. */ +#define R5900_CONF_NBE (_ULCAST_(1) << 13)/* Enable non-blocking load. */ +#define R5900_CONF_BE (_ULCAST_(1) << 15)/* Enable big-endian (read-only). */ +#define R5900_CONF_DCE (_ULCAST_(1) << 16)/* Enable the data cache. */ +#define R5900_CONF_ICE (_ULCAST_(1) << 17)/* Enable the instruction cache. */ +#define R5900_CONF_DIE (_ULCAST_(1) << 18)/* Enable double issue. */ +/* Bits specific to the RM7000. */ #define RM7K_CONF_SE (_ULCAST_(1) << 3)#define RM7K_CONF_TE (_ULCAST_(1) << 12)
Re: [PATCH 047/120] MIPS: PS2: Let the system type be Sony PlayStation 2
In reply to Fredrik NoringQuoted 23 lines · Fredrik Noring
The system type is shown in the
/proc/cpuinfofile:# grep system' 'type /proc/cpuinfo system type : Sony PlayStation 2Signed-off-by Fredrik Noring <[email protected]>--- arch/mips/ps2/identify.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/mips/ps2/identify.c +1
-0@@ -9,11 +9,17 @@#include <linux/init.h> #include <linux/printk.h> +#include <asm/bootinfo.h> #include <asm/prom.h> #include <asm/mach-ps2/rom.h>
arch/mips/ps2/identify.c line 25
Quoted 10 lines
arch/mips/ps2/identify.c +5
-0#include <asm/mach-ps2/scmd.h> +const char *get_system_type (void ) +{ +return "Sony PlayStation 2" ; +} +static int __init set_machine_name_by_scmd (void ) {const struct scmd_machine_name machine =scmd_read_machine_name ();
Re: [PATCH 093/120] fbdev: Add fb_warn_once() variant that only prints a warning once
In reply to Fredrik NoringQuoted 13 lines · Fredrik Noring
fb_warn_once()is a variant offb_warn(), to print a warning only once.Signed-off-by Fredrik Noring <[email protected]>--- include/linux/fb.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/fb.h +0
-0
include/linux/fb.h extern int fb_find_mode(struct fb_var_screeninfo *var, · line 825
Quoted 8 lines
include/linux/fb.h +2
-0@@ -818,6 +818,8 @@ extern int fb_find_mode(struct fb_var_screeninfo *var, pr_notice("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)#define fb_warn (fb_info, fmt, ...) \ pr_warn("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) +#define fb_warn_once (fb_info, fmt, ...) \ + pr_warn_once("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)#define fb_info (fb_info, fmt, ...) \ pr_info("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)#define fb_dbg (fb_info, fmt, ...) \
Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA
In reply to Fredrik NoringQuoted 15 lines · Fredrik Noring
Signed-off-by Fredrik Noring <[email protected]>--- arch/mips/kernel/setup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)arch/mips/kernel/setup.c +0
-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" ;
arch/mips/kernel/setup.c static void __init resource_init(void) · line 882
Quoted 10 lines
arch/mips/kernel/setup.c +4
-1res->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);
Jiaxun Yang
maintainerRe: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA
In reply to Fredrik NoringQuoted 10 lines · Fredrik Noring
Signed-off-by Fredrik Noring <[email protected]>--- arch/mips/kernel/setup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)arch/mips/kernel/setup.c +0
-0
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
-1case BOOT_MEM_RESERVED :case BOOT_MEM_NOMAP :default : - res->name ="reserved" ; + res->name ="Reserved" ; }request_resource (&iomem_resource, res);
Jiaxun Yang
maintainerRe: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Fredrik NoringQuoted 10 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.
Quoted 8 lines
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_opsis accelerated with GS texture sprites that are fast (GS local copy) for the kernel via simple DMA GS commands via the GIF.Signed-off-by Fredrik Noring <[email protected]>
Hi Fredik,
According to kernel policy[1] no more new FBDev driver would be accepted.
Please refactor it to DRM.
Thanks.
[1] http://lkml.iu.edu/hypermail/linux/kernel/1509.3/00253.html
--
Jiaxun Yang
Quoted 611 lines
--- 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.cdrivers/video/fbdev/Kconfig +12
-0@@ -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_PS3AVdrivers/video/fbdev/Makefile +1
-0@@ -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.odrivers/video/fbdev/ps2fb.c new file +533
-0@@ -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@@ -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@@ -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 */
Re: [PATCH 038/120] MIPS: PS2: ROM: Read data for a given ROM file name
In reply to Fredrik NoringHello!
Quoted 5 lines · Fredrik Noring
Reading ROM files is trivial since they are permanently available in memory. Having
rom_read_file()is a convenient when for example resolving the machine region in subsequent changes.Signed-off-by Fredrik Noring <[email protected]>
[...]
Quoted 24 lines
index
12a57f24bd63..840d37a199d8100644arch/mips/ps2/rom.c +17
-0@@ -224,6 +224,39 @@ struct rom_file rom_first_file(const struct rom_dir dir) }EXPORT_SYMBOL_GPL (rom_first_file); +/** +* rom_read_file - read ROM file data +* @dir: directory to read the file from +* @name: file name to read +* @buffer: pointer to buffer to store data that is read +* @size: size in bytes to read +* @offset: offset in bytes to start reading +* +* Context: any +* Return: on successful completion, a nonnegative integer indicating the +* number of bytes actually read; otherwise, a negative error number +*/ +ssize_t rom_read_file (const struct rom_dir dir, +const char *name,void *buffer,size_t size,loff_t offset) +{ +struct rom_file file; +
arch/mips/ps2/rom.c struct rom_file rom_first_file(const struct rom_dir dir) · line 253
Quoted 10 lines
arch/mips/ps2/rom.c +10
-0+ rom_find_files(file, dir, name) +if (offset < file.size) { +const u8 *b = file.data; +size_t remaining = file.size - offset; +size_t n =min (size, remaining); + +memcpy (buffer, &b[offset], n); + +return n; + }else
The *else* branch also needs {} if the *if* branch has 'emn, according toDocumentation/process/coding-style.rst.
arch/mips/ps2/rom.c struct rom_file rom_first_file(const struct rom_dir dir) · line 262
Quoted 9 lines
arch/mips/ps2/rom.c +6
-0+return 0 ; + +return -ENOENT ; +} +EXPORT_SYMBOL_GPL (rom_read_file); +/** * find_reset_string - find the offset to the ``"RESET"`` string, if it exists * @rom: ROM to search in
MBR, Sergei
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Jiaxun YangHi Jiaxun Yang,
Quoted 3 lines
According to kernel policy[1] no more new FBDev driver would be accepted.
Please refactor it to DRM.
I had the impression that the DRM does not support a kernel console?
Standard hardware, on its part, does not have a serial port or similar alternatives that could easily function as a console, unfortunately.
Fredrik
Re: [PATCH 001/120] MIPS: R5900: Initial support for the Emotion Engine in the PlayStation 2
In reply to Maciej W. RozyckiQuoted 4 lines
Hmm, I don't know why
PRID_IMP_TX49has been misplaced, 18 years ago with
commitb8c80cd25ffe("Add missing PrId values for TX39 / TX 49 CPUs."), however I suggest thatPRID_IMP_R5900does not make things worse. I.e. please place it betweenPRID_IMP_NEVADAandPRID_IMP_RM9000.
Done, thanks!
Fredrik
Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA
In reply to Jiaxun YangQuoted 2 lines
ROM_DATAmeant 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_maphad 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
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Fredrik NoringHi,
Quoted 7 lines · Fredrik Noring
Hi Jiaxun Yang,
Quoted 3 lines
According to kernel policy[1] no more new FBDev driver would be accepted.
Please refactor it to DRM.
I had the impression that the DRM does not support a kernel console?
DRM drivers do provide FB console.
A.
Jiaxun Yang
maintainerRe: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA
In reply to Fredrik NoringQuoted 4 lines · Fredrik Noring
Quoted 2 lines
ROM_DATAmeant 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_maphad 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
Jiaxun Yang
maintainerRe: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Fredrik NoringQuoted 6 lines · Fredrik Noring
Hi Jiaxun Yang,
Quoted 3 lines
According to kernel policy[1] no more new FBDev driver would be accepted.
Please refactor it to DRM.
I had the impression that the DRM does not support a kernel console?
Hi Fredik,
DRM do have fb_helper providing FB console.
I think refactor your current FB driver with drm gem cma helper won't be very hard.
Quoted 3 lines
Standard hardware, on its part, does not have a serial port or similar alternatives that could easily function as a console, unfortunately.
Ahh, the guy runs Linux on that gaming console is really cool! How do you debug your code?
Thanks.
--
Jiaxun Yang
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Aaro KoskinenHi Aaro,
Quoted 1 line
DRM drivers do provide FB console.
Great, thanks! I will look into that.
Fredrik
Re: [PATCH 120/120] MIPS: Fix name of BOOT_MEM_ROM_DATA
In reply to Jiaxun YangQuoted 4 lines
Then it's not *memory* right?'
And It should not be managed by
boot_mem_map(Or memblock afterboot_mem_mapbeing 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
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Jiaxun YangQuoted 4 lines
DRM do have
fb_helperproviding FB console.I think refactor your current FB driver with drm gem cma helper won't be very hard.
Thanks! I will update that for v2.
Quoted 2 lines
Ahh, the guy runs Linux on that gaming console is really cool! How do you debug your code?
The video screen is used for the earliest stages, even before the kernel is decompressed in arch/mips/boot/compressed/decompress.c. I have a simple patch that sets up the Graphics Synthesizer and uses DMA to render a trivial frame buffer console, displaying
zimage at: 00803BE0 00BDDE8C
Uncompressing Linux at load address 80010000 Now, booting the kernel...
and so on as a video image. This is functionally equivalent to the serial port drivers for prom_putchar() that other MIPS platforms have, and essential to debug early boot and kexec.
[ I assume this code will not be accepted, since the approach is rather nontraditional, which is why I didn't include it in the patch set. ]
Somewhat later the fbcon driver takes over the video screen console. Then USB is configured with a wifi device, an ssh daemon is started etc. for remote login and scripting.
I have QEMU patches for R5900 user mode emulation, that can be used for development and debugging. I mainly use it to compile Gentoo for the PlayStation 2.
Fredrik
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
Quoted 9 lines · Fredrik Noring
The video screen is used for the earliest stages, even before the kernel is decompressed in
arch/mips/boot/compressed/decompress.c. I have a simple patch that sets up the Graphics Synthesizer and uses DMA to render a trivial frame buffer console, displayingzimage at: 00803BE0 00BDDE8C
Uncompressing Linux at load address 80010000 Now, booting the kernel...
Quoted 6 lines
and so on as a video image. This is functionally equivalent to the serial port drivers for
prom_putchar()that other MIPS platforms have, and essential to debug early boot and kexec.[ I assume this code will not be accepted, since the approach is rather nontraditional, which is why I didn't include it in the patch set. ]
Hmm, why do you think this would be unacceptable? Do you expect your
code to cause unjustified maintenance burden once integrated?
Maciej
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
Quoted 2 lines
Hmm, why do you think this would be unacceptable? Do you expect your
code to cause unjustified maintenance burden once integrated?
I suppose it can be implemented quite nicely, with a bit of effort. Steps to be taken:
1. A font needs to be linked with the early boot code. I'm using acorndata_8x8 from lib/fonts/font_acorn_8x8.c, but any font would do.
2. A single, or small set of, video resolutions need to be selected. I chose 1920x1080p and wrote those values to the Graphics Synthesizer video clock registers. A complete video mode line parser seems excessive, unless that code can be shared with the boot code somehow.
3. Implement clear_screen() and plot(x, y) for a single pixel using DMA commands to the Graphics Synthesizer. [ Clearing the screen can be done by plotting the whole screen, but it was somewhat slow. ]
4. Implement prom_putchar() using plot() for the given font.
Steps (1) and (4) could be generic code.
Fredrik
Jiaxun Yang
maintainerRe: [PATCH 022/120] MIPS: R5900: Support 64-bit inq() and outq() macros in 32-bit kernels
In reply to Fredrik NoringQuoted 4 lines · Fredrik Noring
PlayStation 2 hardware such as the Graphics Synthesizer requires 64-bit register reads and writes[1], also in 32-bit kernels. Interrupts must be disabled when manipulating 64-bit registers unless the kernel saves and restores 64-bit registers in the interrupt and context switch handlers.
Hi Fredrik,
Why don't we just build a 64bit kernel rather than do these hacks?
Any hardware/firmware issue blocks 64bit kernel?
--
Jiaxun Yang
Quoted 8 lines
References:
[1] "EE User's Manual", version 6.0, Sony Computer Entertainment Inc., p. 26: GS privileged registers must be accessed using LD/SD instructions.
Signed-off-by Fredrik Noring<[email protected]>---
Re: [PATCH 038/120] MIPS: PS2: ROM: Read data for a given ROM file name
In reply to Sergei ShtylyovHello!
Quoted 33 lines · Sergei Shtylyov
Quoted 5 lines
Reading ROM files is trivial since they are permanently available in memory. Having
rom_read_file()is a convenient when for example resolving the machine region in subsequent changes.Signed-off-by Fredrik Noring <[email protected]>[...]
Quoted 27 lines
index
12a57f24bd63..840d37a199d8100644arch/mips/ps2/rom.c +20
-0@@ -224,6 +224,39 @@ struct rom_file rom_first_file(const struct rom_dir dir) }EXPORT_SYMBOL_GPL (rom_first_file); +/** +* rom_read_file - read ROM file data +* @dir: directory to read the file from +* @name: file name to read +* @buffer: pointer to buffer to store data that is read +* @size: size in bytes to read +* @offset: offset in bytes to start reading +* +* Context: any +* Return: on successful completion, a nonnegative integer indicating the +* number of bytes actually read; otherwise, a negative error number +*/ +ssize_t rom_read_file(const struct rom_dir dir, + const char *name, void *buffer, size_t size, loff_t offset) +{ + struct rom_file file; + + rom_find_files(file, dir, name) +if (offset < file.size) { +const u8 *b = file.data; +size_t remaining = file.size - offset;
Quoted 8 lines
arch/mips/ps2/rom.c struct rom_file rom_first_file(const struct rom_dir dir) · line 253
Quoted 6 lines
arch/mips/ps2/rom.c +6
-0+size_t n =min (size, remaining); + +memcpy (buffer, &b[offset], n); + +return n; + }else The *else* branch also needs {} if the *if* branch has 'emn, according to
Documentation/process/coding-style.rst.
Just realized that we don't need *else* after *return*...
Quoted 9 lines
arch/mips/ps2/rom.c struct rom_file rom_first_file(const struct rom_dir dir) · line 262
Quoted 9 lines
arch/mips/ps2/rom.c +6
-0+return 0 ; + +return -ENOENT ; +} +EXPORT_SYMBOL_GPL (rom_read_file); +/** * find_reset_string - find the offset to the ``"RESET"`` string, if it exists * @rom: ROM to search in
MBR, Sergei
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 inRESTORE_SOME
MIPS: R5900: Reset the funnel shift amount (SA) register inRESTORE_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-bitinq()andoutq()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/memto 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 usecpu_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/memto 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: Definegs_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: ExtendCOUNT_ARGS()from 12 to 32 arguments
MIPS: PS2: GS: Show privileged registers with sysfs
MIPS: PS2: GS: Store privileged registers with sysfs
fbdev: Addfb_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 acceleratedfb_tilecopy()support
MIPS: PS2: FB: Hardware acceleratedfb_tilefill()support
MIPS: PS2: FB: Simplifiedfb_tileblit()support
MIPS: PS2: FB:fb_tilecursor()placeholder
MIPS: PS2: FB: Hardware acceleratedfb_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_MIEworkaround 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 ofBOOT_MEM_ROM_DATAarch/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.cSignature · 1 line
2.21.0
Re: [PATCH 022/120] MIPS: R5900: Support 64-bit inq() and outq() macros in 32-bit kernels
In reply to Jiaxun YangQuoted 10 lines · Jiaxun Yang
Quoted 4 lines
PlayStation 2 hardware such as the Graphics Synthesizer requires 64-bit register reads and writes[1], also in 32-bit kernels. Interrupts must be disabled when manipulating 64-bit registers unless the kernel saves and restores 64-bit registers in the interrupt and context switch handlers.
Hi Fredrik,
Why don't we just build a 64bit kernel rather than do these hacks?
Any hardware/firmware issue blocks 64bit kernel?
One issue I recall with the R5900 is $pc is 32-bit (as if with
CP0.Status.PX=1 on modern hardware) and is zero- rather than sign-extended when copied to a GPR with instructions like JALR, BLTZAL, etc. This is contrary to MIPS architecture requirements and unlike other 64-bit MIPS processors.
This does not cause an issue in the user mode (because USEG addresses
have bit #31 set to 0 anyway) or with the JR and JALR instructions (because these ignore the upper 32 bits in the source GPR). This however breaks in the kernel mode whenever the value retrieved from $pc is used for any kind of calculation, meaning that the kernel will have to be audited for such use before we can run 64-bit kernel code.
This means it's much easier to have a 32-bit kernel running, with a small
and simple sanitanisation change posted as 003/120, and have all the platform and driver infrastructure verified before this processor quirk is addressed.
Maciej
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
Re: [PATCH 038/120] MIPS: PS2: ROM: Read data for a given ROM file name
In reply to Sergei ShtylyovQuoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/mips/ps2/rom.c +6
-0+struct rom_file file; + + rom_find_files(file, dir, name) +if (offset < file.size) { +const u8 *b = file.data; +size_t remaining = file.size - offset;Quoted 8 lines
arch/mips/ps2/rom.c struct rom_file rom_first_file(const struct rom_dir dir) · line 253
Quoted 6 lines
arch/mips/ps2/rom.c +6
-0+size_t n =min (size, remaining); + +memcpy (buffer, &b[offset], n); + +return n; + }else The *else* branch also needs {} if the *if* branch has 'emn, according to
Documentation/process/coding-style.rst.
Quoted 3 lines
Just realized that we don't need *else* after *return*...
Quoted 1 line
Quoted 1 line
+ return 0;
There is a style rule that says "use braces when a loop contains more than a single simple statement", and with those braces we could remove the else:
rom_find_files (file, dir, name) {
if (offset < file.size) {
const u8 *b = file.data;
size_t remaining = file.size - offset;
size_t n = min(size, remaining);
memcpy(buffer, &b[offset], n);
return n;
}
return 0;
}[ rom_find_files() is a cursor based loop macro similar to list_for_each_entry() and others of the same kind. Perhaps the name could be a bit better, for example rom_for_each_file_with_name() or something like that. Patches 036/120 and 037/120 have the details. ]
Fredrik
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
In reply to Fredrik NoringHi Fredrik,
Cc'ing glibc folks in case...
Quoted 3 lines · Fredrik Noring
On the R5900, the RDHWR instruction is interpreted as the R5900 specific SQ instruction[1] that traps into a zero page address exception. Hence RDHWR can be emulated by
emulate_load_store_insn().
Please bare with me because this is not my area, but this does not look the correct way to fix this problem to me.
The R5900 is a MIPS-III, so I don't understand why we have to care about RDHWR.
IIRC MIPS TLS support has been added in glibc with MIPS32 ISA in mind in 2005:
https://sourceware.org/git/?p=glibc.git;a=commit;h=f850220be6
MIPS16 is handled differently:
https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=ports/sysdeps/mips/tls-macros.h;h=3e87e42ea;hp=8fe2e4a150d;hb=43301bd3c2;hpb=85bd816a60
Shouldn't we have a similar set of macros for the R5900?
The problem I have is this break running the binaries built by the Sony Linux Toolkit for Playstation 2 which use the LQ/SQ instruction:
1b00d5c: 0c6c00d4 jal 0x1b00350 1b00d60: 7fa90020 sq t1,32(sp) 1b00d64: a2710000 sb s1,0(s3) 1b00d68: 26730001 addiu s3,s3,1 1b00d6c: 10000004 b 0x1b00d80 1b00d70: 7ba90020 lq t1,32(sp) 1b00d74: 00000000 nop 1b00d78: 2617ffff addiu s7,s0,-1 1b00d7c: 25360001 addiu s6,t1,1 1b00d80: 91220000 lbu v0,0(t1) 1b00d84: 02e0802d move s0,s7 1b00d88: 02c0482d move t1,s6 1b00d8c: a2620000 sb v0,0(s3) 1b00d90: 1600fff9 bnez s0,0x1b00d78 1b00d94: 26730001 addiu s3,s3,1 1b00d98: 10000003 b 0x1b00da8 1b00d9c: 01342026 xor a0,t1,s4 1b00da0: 253e0003 addiu s8,t1,3 1b00da4: 01342026 xor a0,t1,s4 1b00da8: 7fa90020 sq t1,32(sp) 1b00dac: 2c840001 sltiu a0,a0,1 1b00db0: 0c6c00d4 jal 0x1b00350
What do you think?
Regards,
Phil.
Quoted 101 lines
CONFIG_DEFAULT_MMAP_MIN_ADDRmust not be less thanPAGE_SIZEto reliably trap and emulate RDHWR, so this is made aBUILD_BUG_ONfor the R5900.References:
[1] "TX System RISC TX79 Core Architecture" manual, revision 2.0,
Toshiba Corporation, p. B-162, https://wiki.qemu.org/File:C790.pdfSigned-off-by Fredrik Noring <[email protected]>--- arch/mips/include/asm/traps.h | 2 ++ arch/mips/kernel/traps.c | 2 +- arch/mips/kernel/unaligned.c | 36 ++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-)arch/mips/include/asm/traps.h +2
-0@@ -35,4 +35,6 @@ extern int register_nmi_notifier(struct notifier_block *nb); register_nmi_notifier(&fn##_nb); \ }) +int simulate_rdhwr (struct pt_regs *regs,int rd,int rt); +#endif /* _ASM_TRAPS_H */ arch/mips/kernel/traps.c +1
-1@@ -625,7 +625,7 @@ static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)* Simulate trapping 'rdhwr' instructions to provide user accessible * registers not implemented in hardware. */ -static int simulate_rdhwr (struct pt_regs *regs,int rd,int rt) +int simulate_rdhwr (struct pt_regs *regs,int rd,int rt) {struct thread_info *ti =task_thread_info (current);arch/mips/kernel/unaligned.c +35
-1@@ -90,6 +90,7 @@#include <asm/fpu_emulator.h> #include <asm/inst.h> #include <asm/mmu_context.h> +#include <asm/traps.h> #include <linux/uaccess.h> #define STR (x) __STR(x)@@ -934,7 +935,39 @@ static void emulate_load_store_insn(struct pt_regs *regs,* interest. */ case spec3_op: -if (insn.dsp_format.func == lx_op) { +if (IS_ENABLED (CONFIG_CPU_R5900 )) { +/* +* On the R5900, the RDHWR instruction +* +* +--------+-------+----+----+-------+--------+ +* | 011111 | 00000 | rt | rd | 00000 | 111011 | +* +--------+-------+----+----+-------+--------+ +* 6 5 5 5 5 6 +* +* is interpreted as the R5900 specific SQ instruction +* +* +--------+-------+----+---------------------+ +* | 011111 | base | rt | offset | +* +--------+-------+----+---------------------+ +* 6 5 5 16 +* +* that asserts a zero page address exception. Hence +* RDHWR can be trapped and emulated here, provided +* DEFAULT_MMAP_MIN_ADDR isn't zero. +*/ +BUILD_BUG_ON (IS_ENABLED (CONFIG_CPU_R5900 ) && +CONFIG_DEFAULT_MMAP_MIN_ADDR <PAGE_SIZE ); +if (insn.r_format.func == rdhwr_op && + insn.r_format.rs ==0 && + insn.r_format.re ==0 ) { +if (compute_return_epc (regs) <0 || +simulate_rdhwr (regs, insn.r_format.rd, + insn.r_format.rt) <0 ) + goto sigill; +return ; + } + goto sigbus; + }else if (insn.dsp_format.func == lx_op) {switch (insn.dsp_format.op) {case lwx_op:if (!access_ok (addr,4 ))@@ -1342,6 +1375,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,cu2_notifier_call_chain (CU2_SDC2_OP , regs);break ;#endif +default :/* * Pheeee... We encountered an yet unknown instruction or
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
In reply to Maciej W. RozyckiQuoted 3 lines · Maciej W. Rozycki
Consequently an AdES exception is triggered which we can trap and handle,
reinterpreting the encoding according to our needs and return the TLS pointer in $v1 rather than issuing a SIGBUS.
... while keeping regular SQ instruction use intact, I should have added.
Maciej
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
Quoted 3 lines
On the R5900, the RDHWR instruction is interpreted as the R5900 specific SQ instruction[1] that traps into a zero page address exception. Hence RDHWR can be emulated by
emulate_load_store_insn().Please bare with me because this is not my area, but this does not look the correct way to fix this problem to me.
The R5900 is a MIPS-III, so I don't understand why we have to care about RDHWR.
The use of RDHWR, actual or emulated, is a part of the MIPS TLS psABI,
see: <https://www.linux-mips.org/wiki/NPTL>, in particular starting from:
<https://www.linux-mips.org/wiki/NPTL#Design_Choices> and throughout (the expired certificate of the web site is a known issue, but there is currently no way to get it fixed as nobody knows where Ralf Baechle has gone).
Quoted 8 lines
IIRC MIPS TLS support has been added in glibc with MIPS32 ISA in mind in 2005:
https://sourceware.org/git/?p=glibc.git;a=commit;h=f850220be6MIPS16 is handled differently:
https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=ports/sysdeps/mips/tls-macros.h;h=3e87e42ea;hp=8fe2e4a150d;hb=43301bd3c2;hpb=85bd816a60Shouldn't we have a similar set of macros for the R5900?
The macros are there to support different instructions used to access
data within TLS. However the TLS pointer still has to be fetched with RDHWR, and READ_THREAD_POINTER does exactly that, by calling the `__builtin_thread_pointer' intrinsic in the MIPS16 case. How it works is explained in GCC sources, in gcc/config/mips/mips.md:
;; In MIPS16 mode, the TLS base pointer is accessed by a ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not ;; accessible in MIPS16.
;;
;; This is not represented as a call insn, to avoid the ;; unnecesarry clobbering of caller-save registers by a ;; function consisting only of: "rdhwr $3,$29; j $31; nop;" ;;
;; A $25 clobber is added to cater for a $25 load stub added by the ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
-- that is a small piece of regular MIPS code is called, which executes RDHWR.
Quoted 18 lines
The problem I have is this break running the binaries built by the Sony Linux Toolkit for Playstation 2 which use the LQ/SQ instruction:
1b00d5c: 0c6c00d4 jal 0x1b00350 1b00d60: 7fa90020 sq t1,32(sp) 1b00d64: a2710000 sb s1,0(s3) 1b00d68: 26730001 addiu s3,s3,1 1b00d6c: 10000004 b 0x1b00d80 1b00d70: 7ba90020 lq t1,32(sp) 1b00d74: 00000000 nop 1b00d78: 2617ffff addiu s7,s0,-1 1b00d7c: 25360001 addiu s6,t1,1 1b00d80: 91220000 lbu v0,0(t1) 1b00d84: 02e0802d move s0,s7 1b00d88: 02c0482d move t1,s6 1b00d8c: a2620000 sb v0,0(s3) 1b00d90: 1600fff9 bnez s0,0x1b00d78
Quoted 8 lines
1b00d94: 26730001 addiu s3,s3,1 1b00d98: 10000003 b 0x1b00da8 1b00d9c: 01342026 xor a0,t1,s4 1b00da0: 253e0003 addiu s8,t1,3 1b00da4: 01342026 xor a0,t1,s4 1b00da8: 7fa90020 sq t1,32(sp) 1b00dac: 2c840001 sltiu a0,a0,1 1b00db0: 0c6c00d4 jal 0x1b00350
Where exactly do you see a problem, what are the symptoms? A bug in the
emulation cannot be ruled out of course.
While there indeed is an unfortunate opcode overlap between RDHWR and SQ,
the encoding of the specific operands chosen for TLS pointer access is luckily guaranteed to always trap in the user mode, because the address requested when the encoding is interpreted as SQ rather than RDHWR is within the kernel KSEG2 segment:
$ cat rdhwr.s rdhwr $3, $29 $ gcc -march=mips32r2 -c rdhwr.s $ objdump -d rdhwr.o rdhwr.o: file format elf32-tradlittlemips
Disassembly of section .text:
00000000 <.text>:
0: 7c03e83b rdhwr v1,$29
... $ objdump -m mips:5900 -d rdhwr.o
rdhwr.o: file format elf32-tradlittlemips
Disassembly of section .text:
00000000 <.text>:
0: 7c03e83b sq v1,-6085(zero)
...
$
This is because the HWR read is encoded in bits 15:11 of the instruction word and $29 has the highest bit set, which lands in bit 15 of the instruction word, meaning that the offset encoded in bits 15:0 used where the instruction word is interpreted as SQ is negative. And then bits 25:21 are hardwired to 0 in the encoding of RDHWR and they correspond to the base register encoding with SQ, meaning that it will be interpreted as $zero. So the address ultimately requested is -6085 => 0xffffffffffffe83b (the R5900 uses 32-bit addressing and ignores address bits 63:32, but that does not matter here; this is KSEG2 either way).
Consequently an AdES exception is triggered which we can trap and handle,
reinterpreting the encoding according to our needs and return the TLS pointer in $v1 rather than issuing a SIGBUS. So you are not expected to see any issue unless there is a security erratum in the R5900 as well and the encoding does not cause an exception for some reason.
This of course disagrees with what Fredrik wrote in the quotation above,
as it's the last page rather than the zeroth that is accessed, but the net effect is the same, or even better.
Maciej
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
Hi Maciej,
Quoted 6 lines · Maciej W. Rozycki
The use of RDHWR, actual or emulated, is a part of the MIPS TLS psABI,
see: <https://www.linux-mips.org/wiki/NPTL>, in particular starting from:
<https://www.linux-mips.org/wiki/NPTL#Design_Choices> and throughout (the expired certificate of the web site is a known issue, but there is currently no way to get it fixed as nobody knows where Ralf Baechle has gone).
Can the site be wrapped up and published elsewhere?
Quoted 46 lines
While there indeed is an unfortunate opcode overlap between RDHWR and SQ,
the encoding of the specific operands chosen for TLS pointer access is luckily guaranteed to always trap in the user mode, because the address requested when the encoding is interpreted as SQ rather than RDHWR is within the kernel KSEG2 segment:$ cat rdhwr.s rdhwr $3, $29 $ gcc -march=mips32r2 -c rdhwr.s $ objdump -d rdhwr.o rdhwr.o: file format elf32-tradlittlemipsDisassembly of section .text:
00000000 <.text>:
0: 7c03e83b rdhwr v1,$29 ... $ objdump -m mips:5900 -d rdhwr.ordhwr.o: file format elf32-tradlittlemips
Disassembly of section .text:
00000000 <.text>:
0: 7c03e83b sq v1,-6085(zero) ...$
This is because the HWR read is encoded in bits 15:11 of the instruction word and $29 has the highest bit set, which lands in bit 15 of the instruction word, meaning that the offset encoded in bits 15:0 used where the instruction word is interpreted as SQ is negative. And then bits 25:21 are hardwired to 0 in the encoding of RDHWR and they correspond to the base register encoding with SQ, meaning that it will be interpreted as $zero. So the address ultimately requested is -6085 =>
0xffffffffffffe83b(the R5900 uses 32-bit addressing and ignores address bits 63:32, but that does not matter here; this is KSEG2 either way).Consequently an AdES exception is triggered which we can trap and handle,
reinterpreting the encoding according to our needs and return the TLS pointer in $v1 rather than issuing a SIGBUS. So you are not expected to see any issue unless there is a security erratum in the R5900 as well and the encoding does not cause an exception for some reason.
Quoted 3 lines
This of course disagrees with what Fredrik wrote in the quotation above,
as it's the last page rather than the zeroth that is accessed, but the net effect is the same, or even better.
The first page could be mapped by the application itself, but what about RDHWR registers $0-$3 having mnemonics CPUNum, SYNC1_Step, CC and CCRes[1], or in Linux
/* RDHWR register numbers */
#define MIPS_HWR_CPUNUM 0 /* CPU number */
#define MIPS_HWR_SYNCISTEP 1 /* SYNCI step size */
#define MIPS_HWR_CC 2 /* Cycle counter */
#define MIPS_HWR_CCRES 3 /* Cycle counter resolution */
#define MIPS_HWR_ULR 29 /* UserLocal */
#define MIPS_HWR_IMPL1 30 /* Implementation dependent */
#define MIPS_HWR_IMPL2 31 /* Implementation dependent */
in arch/mips/include/asm/mipsregs.h? They land on the first page, no?
Fredrik
References:
[1] "MIPS Architecture for programmers Volume II-A: The MIPS32 Instruction
Set", revision 5.04, 11 December 2013, p. 248.
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
Quoted 8 lines · Fredrik Noring
Quoted 6 lines
The use of RDHWR, actual or emulated, is a part of the MIPS TLS psABI,
see: <https://www.linux-mips.org/wiki/NPTL>, in particular starting from:
<https://www.linux-mips.org/wiki/NPTL#Design_Choices> and throughout (the expired certificate of the web site is a known issue, but there is currently no way to get it fixed as nobody knows where Ralf Baechle has gone).Can the site be wrapped up and published elsewhere?
Well if someone does that, sure! I guess archive.org will have it too.
Quoted 5 lines
Quoted 3 lines
This of course disagrees with what Fredrik wrote in the quotation above,
as it's the last page rather than the zeroth that is accessed, but the net effect is the same, or even better.The first page could be mapped by the application itself, but what about
It doesn't matter given that `rdhwr $3, $29' maps to an R5900 instruction
that does not access it.
Quoted 12 lines
RDHWR registers $0-$3 having mnemonics CPUNum,
SYNC1_Step, CC and CCRes[1], or in Linux/* RDHWR register numbers */
#defineMIPS_HWR_CPUNUM0 /* CPU number */
#defineMIPS_HWR_SYNCISTEP1 /* SYNCI step size */
#defineMIPS_HWR_CC2 /* Cycle counter */
#defineMIPS_HWR_CCRES3 /* Cycle counter resolution */
#defineMIPS_HWR_ULR29 /* UserLocal */
#defineMIPS_HWR_IMPL130 /* Implementation dependent */
#defineMIPS_HWR_IMPL231 /* Implementation dependent */
Quoted 1 line
in
arch/mips/include/asm/mipsregs.h? They land on the first page, no?
Unlike TLS pointer access, specifically using $3 as rt, which has been
made a part of the Linux ABI, they're not supposed to be referred with pre-R2 code. After all RDHWR was only introduced with R2.
Indeed there's emulation code in the kernel for those encodings even with
pre-R2 hardware, but it is not guaranteed to give sensible results, and given the circumstances I'm not sure what it really is for, e.g. what is SYNCI_Step for with processors that do not implement SYNCI? The cycle counter register may be absent too, so even emulated accesses will return rubbish; gettimeofday(2) is the standard interface.
So I think we can safely ignore them, just as we can any ULR access with
rt != $3. Unlike standardised TLS pointer accesses such instructions won't appear in compiler-generated code and whoever uses them in handcoded assembly or otherwise generated machine code will have to make sure they make sense for their application (yes, there's rubbish code out there, e.g. Firefox has a JIT that unconditionally produces MIPS R2 code even if the piece of software has been compiled for an older ISA revision, and having not verified that the CPU it runs on actually supports the R2 ISA, but that's just the usual imperfection of the world; you just can't fix it all).
Maciej
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
Quoted 11 lines · Maciej W. Rozycki
Unlike TLS pointer access, specifically using $3 as rt, which has been
made a part of the Linux ABI, they're not supposed to be referred with pre-R2 code. After all RDHWR was only introduced with R2.Indeed there's emulation code in the kernel for those encodings even with
pre-R2 hardware, but it is not guaranteed to give sensible results, and given the circumstances I'm not sure what it really is for, e.g. what isSYNCI_Stepfor with processors that do not implement SYNCI? The cycle counter register may be absent too, so even emulated accesses will return rubbish; gettimeofday(2) is the standard interface.
Quoted 10 lines
So I think we can safely ignore them, just as we can any ULR access with
rt != $3. Unlike standardised TLS pointer accesses such instructions won't appear in compiler-generated code and whoever uses them in handcoded assembly or otherwise generated machine code will have to make sure they make sense for their application (yes, there's rubbish code out there, e.g. Firefox has a JIT that unconditionally produces MIPS R2 code even if the piece of software has been compiled for an older ISA revision, and having not verified that the CPU it runs on actually supports the R2 ISA, but that's just the usual imperfection of the world; you just can't fix it all).
Many thanks, that resolves it! I'll write it up in the commit message.
Fredrik
Re: [PATCH 002/120] MIPS: R5900: Trap the RDHWR instruction as an SQ address exception
In reply to Maciej W. RozyckiQuoted 2 lines
So I think we can safely ignore them, just as we can any ULR access with
rt != $3.
The comment is corrected and the conditions on rd and rt are now strict, as shown in the patch below.
Fredrik
arch/mips/kernel/unaligned.c +41 -1
@@ -90,6 +90,7 @@#include <asm/fpu_emulator.h> #include <asm/inst.h> #include <asm/mmu_context.h> +#include <asm/traps.h> #include <linux/uaccess.h> #define STR (x) __STR(x)
@@ -934,7 +935,46 @@ static void emulate_load_store_insn(struct pt_regs *regs,* interest. */ case spec3_op: -if (insn.dsp_format.func == lx_op) { +if (IS_ENABLED (CONFIG_CPU_R5900 )) { +/* +* On the R5900, a valid RDHWR instruction +* +* +--------+-------+----+----+-------+--------+ +* | 011111 | 00000 | rt | rd | 00000 | 111011 | +* +--------+-------+----+----+-------+--------+ +* 6 5 5 5 5 6 +* +* having rt $3 (v1) and rd $29 (MIPS_HWR_ULR) is +* interpreted as the R5900 specific SQ instruction +* +* +--------+-------+----+---------------------+ +* | 011111 | base | rt | offset | +* +--------+-------+----+---------------------+ +* 6 5 5 16 +* +* with +* +* sq v1,-6085(zero) +* +* that asserts an address exception since -6085(zero) +* always resolves to 0xffffe83b in 32-bit KSEG2. +* +* Other legacy values of rd, such as MIPS_HWR_CPUNUM, +* are ignored. +*/ +if (insn.r_format.func == rdhwr_op && + insn.r_format.rd ==MIPS_HWR_ULR && + insn.r_format.rt ==3 && + insn.r_format.rs ==0 && + insn.r_format.re ==0 ) { +if (compute_return_epc (regs) <0 || +simulate_rdhwr (regs, insn.r_format.rd, + insn.r_format.rt) <0 ) + goto sigill; +return ; + } + goto sigbus; + }else if (insn.dsp_format.func == lx_op) {switch (insn.dsp_format.op) {case lwx_op:if (!access_ok (addr,4 ))
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Jiaxun YangQuoted 3 lines · Jiaxun Yang
According to kernel policy[1] no more new FBDev driver would be accepted.
Please refactor it to DRM.
I obtained a functional DRM driver a while back, but unfortunately it's a poor fit on the hardware, for the following reasons, in brief:
The DRM subsystem (in general) breaks user-space in significant ways:
- 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;
- 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.
DRM seems to rely heavily on EDID to negotiate a video resolution, but EDID isn't available with vintage analogue display hardware.
The Graphics Synthesizer (GS) hardware is essentially a serial device that accepts sequences of commands with data via DMA. Notably, it cannot be memory mapped.
Can the GS be modelled, in a reasonable way, on existing kernel video interfaces, when taking memory efficiency and performance into account?
For anyone who is interested:
In addition to this patch series and its documentation references, some background information and details on the Graphics Synthesizer are available here:
https://github.com/frno7/linux/issues/10
Fredrik
Re: [PATCH 094/120] MIPS: PS2: FB: Frame buffer driver for the PlayStation 2
In reply to Fredrik NoringHi 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_opsis accelerated with GS texture sprites that are fast (GS local copy) for the kernel via simple DMA GS commands via the GIF.Signed-off-by Fredrik Noring <[email protected]>--- 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.cdrivers/video/fbdev/Kconfig +12
-0@@ -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_PS3AVdrivers/video/fbdev/Makefile +1
-0@@ -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.odrivers/video/fbdev/ps2fb.c new file +533
-0@@ -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@@ -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@@ -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