diff mbox series

[072/120] MIPS: PS2: IOP: SIF printk command support

Message ID 53102a0102944d3c118f5cfc8cda3210284f59d6.1567326213.git.noring@nocrew.org (mailing list archive)
State RFC
Headers show
Series Linux for the PlayStation 2 | expand

Commit Message

Fredrik Noring Sept. 1, 2019, 4:12 p.m. UTC
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 <noring@nocrew.org>
---
 drivers/ps2/iop-module.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Sergei Shtylyov Sept. 1, 2019, 5:44 p.m. UTC | #1
On 01.09.2019 19:12, Fredrik Noring wrote:

> 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 <noring@nocrew.org>
> ---
>   drivers/ps2/iop-module.c | 31 +++++++++++++++++++++++++++++++
>   1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/ps2/iop-module.c b/drivers/ps2/iop-module.c
> index bb4814b5d3c4..18020b3673d3 100644
> --- a/drivers/ps2/iop-module.c
> +++ b/drivers/ps2/iop-module.c
> @@ -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?

> + * @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],
> +			'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
Fredrik Noring Sept. 1, 2019, 6:08 p.m. UTC | #2
Hi Sergei,

> > +/**
> > + * cmd_printk - IOP module kernel log printk command
> > + * @header: SIF command header
> > + * @void: message to print
> 
>     @data, maybe?

Indeed, thanks!

Fredrik
diff mbox series

Patch

diff --git a/drivers/ps2/iop-module.c b/drivers/ps2/iop-module.c
index bb4814b5d3c4..18020b3673d3 100644
--- a/drivers/ps2/iop-module.c
+++ b/drivers/ps2/iop-module.c
@@ -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
+ * @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],
+			'i', 'o', 'p', ':', ' ', '%', 's', '\0' };
+
+		printk(fmt, &msg[2]);
+	} else
+		printk("iop: %s", msg);
+}
+
 static int __init iop_module_init(void)
 {
 	int err;
@@ -902,6 +926,12 @@  static int __init iop_module_init(void)
 		return -ENOMEM;
 	}
 
+	err = sif_request_cmd(SIF_CMD_PRINTK, cmd_printk, NULL);
+	if (err < 0) {
+		pr_err("iop-module: Failed request printk cmd with %d\n", err);
+		goto err_printk;
+	}
+
 	err = sif_rpc_bind(&load_file_rpc_client, SIF_SID_LOAD_MODULE);
 	if (err < 0) {
 		pr_err("iop-module: Failed to bind load module with %d\n", err);
@@ -910,6 +940,7 @@  static int __init iop_module_init(void)
 
 	return 0;
 
+err_printk:
 err_bind:
 	root_device_unregister(iop_module_device);