mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Magnus Lindholm <linmag7@gmail.com>,
	davem@davemloft.net, andreas@gaisler.com,
	sparclinux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	krzk@kernel.org, oleg@redhat.com
Subject: Re: [PATCH v2 6/6] hvc: add an M3000 firmware console backend
Date: Mon, 12 Oct 2026 08:46:30 +0200	[thread overview]
Message-ID: <1f66c850-faa7-477f-9535-761074ccc077@kernel.org> (raw)
In-Reply-To: <20261011195729.981243-7-linmag7@gmail.com>

On 11. 10. 26, 21:55, Magnus Lindholm wrote:
...
> --- /dev/null
> +++ b/drivers/tty/hvc/hvc_m3000.c
> @@ -0,0 +1,205 @@

> +struct m3000_console {
> +	int stdin;
> +	bool ready;
> +	u8 buffer[256];
> +	raw_spinlock_t buffer_lock;
> +	struct timer_list poll_timer;
> +	struct mutex poll_mutex; /* Serialize open against synchronous close. */
> +	spinlock_t poll_lock; /* Protect active state and timer rearming. */
> +	bool poll_active;

Perhaps group these a bit better, so that there are not such holes?

> +};
...
> +/*
> + * HVC's idle backoff can exceed the firmware input FIFO's capacity.
> + * Wake its worker each tick while open; keep PROM calls out of the timer.
> + */
> +static void m3000_poll_tick(struct timer_list *timer)
> +{
> +	struct m3000_console *con = timer_container_of(con, timer, poll_timer);
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&con->poll_lock, flags);

Any reason not to use guard()s?

> +	if (con->poll_active) {
> +		hvc_kick();
> +		mod_timer(&con->poll_timer, jiffies + 1);
> +	}
> +	spin_unlock_irqrestore(&con->poll_lock, flags);
> +}
> +
> +static int m3000_open(struct hvc_struct *hp, int data)
> +{
> +	struct m3000_console *con = m3000_console(hp->vtermno);
> +	unsigned long flags;
> +
> +	if (!con)
> +		return -ENODEV;
> +	mutex_lock(&con->poll_mutex);
> +	spin_lock_irqsave(&con->poll_lock, flags);

Same here.

> +	con->poll_active = true;
> +	mod_timer(&con->poll_timer, jiffies + 1);
> +	spin_unlock_irqrestore(&con->poll_lock, flags);
> +	mutex_unlock(&con->poll_mutex);
> +	return 0;
> +}
> +
> +static void m3000_close(struct hvc_struct *hp, int data)
> +{
> +	struct m3000_console *con = m3000_console(hp->vtermno);
> +	unsigned long flags;
> +
> +	if (!con)
> +		return;
> +	mutex_lock(&con->poll_mutex);
> +	spin_lock_irqsave(&con->poll_lock, flags);

And here.

> +	con->poll_active = false;
> +	spin_unlock_irqrestore(&con->poll_lock, flags);
> +	/* Block reopen until the callback has finished and cannot rearm. */
> +	timer_delete_sync(&con->poll_timer);
> +	mutex_unlock(&con->poll_mutex);
> +}
> +
> +static ssize_t m3000_io(struct m3000_console *con, u8 *in,
> +			const u8 *out, size_t count)
> +{
> +	unsigned long args[7], flags;
> +	bool input = in;

You can test "in" below directly, right?

> +	int ret;
> +
> +	if (!count)
> +		return 0;
> +	count = min(count, input ? 1 : sizeof(con->buffer));
> +	/* Console writes can run with interrupts disabled; this lock cannot sleep. */
> +	raw_spin_lock_irqsave(&con->buffer_lock, flags);

scoped_guard()

> +	if (!input)
> +		memcpy(con->buffer, out, count);
> +	args[0] = (unsigned long)(input ? "read" : "write");
> +	args[1] = 3;
> +	args[2] = 1;
> +	args[3] = (unsigned int)(input ? con->stdin : prom_stdout);
> +	args[4] = (unsigned long)con->buffer;
> +	args[5] = count;
> +	args[6] = (unsigned long)-1;
> +	p1275_cmd_direct(args);
> +	ret = (int)args[6];
> +	if (ret > 0 && ret <= count && input)
> +		memcpy(in, con->buffer, ret);
> +	raw_spin_unlock_irqrestore(&con->buffer_lock, flags);
> +	if (ret == -2 || ret == 0)

That's full of magic constants. Can we have defines for those?

> +		return 0;
> +	if (ret < 0 || ret > count)
> +		return -EIO;
> +	return ret;
thanks,
-- 
js
suse labs

      reply	other threads:[~2026-10-12  6:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 19:55 [PATCH v2 0/6] sparc64: add Fujitsu M3000 support Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 1/6] sparc64: return from the generic clear_page implementation Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 2/6] sparc64: honor queued spinlock layout in secondary startup Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 3/6] sparc64: avoid huge kernel PUD mappings on sun4u Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 4/6] sparc64: add SPARC64 VII CPU, MMU and SMP support Magnus Lindholm
2026-10-12  7:34   ` kernel test robot
2026-10-11 19:55 ` [PATCH v2 5/6] sparc64: add M3000 Oberon PCIe support Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 6/6] hvc: add an M3000 firmware console backend Magnus Lindholm
2026-10-12  6:46   ` Jiri Slaby [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f66c850-faa7-477f-9535-761074ccc077@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk@kernel.org \
    --cc=linmag7@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=oleg@redhat.com \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®