All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Ashish Kalra <ashish.kalra@amd.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Denis Mukhin <dmukhin@ford.com>
Subject: [PATCH v1 6/6] x86/boot: Introduce MMIO accessors and their support in earlyprintk
Date: Fri,  2 May 2025 15:29:42 +0300	[thread overview]
Message-ID: <20250502123145.4066635-7-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20250502123145.4066635-1-andriy.shevchenko@linux.intel.com>

If user supplied serial base address via kernel command line and
at the same time the word 'mmio' is present, use MMIO accessors.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 arch/x86/boot/early_serial_console.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c
index 6841f14346c2..fa8eb0b4542e 100644
--- a/arch/x86/boot/early_serial_console.c
+++ b/arch/x86/boot/early_serial_console.c
@@ -33,6 +33,20 @@ static void io_serial_out(unsigned long addr, int offset, int value)
 	outb(value, addr + offset);
 }
 
+static void mem8_serial_out(unsigned long addr, int offset, int value)
+{
+	u8 __iomem *vaddr = (u8 __iomem *)addr;
+	/* shift implied by pointer type */
+	writeb(value, vaddr + offset);
+}
+
+static unsigned int mem8_serial_in(unsigned long addr, int offset)
+{
+	u8 __iomem *vaddr = (u8 __iomem *)addr;
+	/* shift implied by pointer type */
+	return readb(vaddr + offset);
+}
+
 static void early_serial_configure(unsigned long port, int baud)
 {
 	unsigned char c;
@@ -59,6 +73,13 @@ static void early_serial_use_io_accessors(void)
 	serial_out = io_serial_out;
 }
 
+static void early_serial_use_mmio_accessors(void)
+{
+	/* It is memory mapped - assume 8-bit alignment */
+	serial_in = mem8_serial_in;
+	serial_out = mem8_serial_out;
+}
+
 static void early_serial_init(unsigned long port, int baud)
 {
 	early_serial_configure(port, baud);
@@ -101,12 +122,16 @@ static void parse_earlyprintk(void)
 		/*
 		 * make sure we have
 		 *	"serial,0x3f8,115200"
+		 *	"serial,mmio,0xff010180,115200"
 		 *	"serial,ttyS0,115200"
 		 *	"ttyS0,115200"
 		 */
 		if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
 			port = parse_serial_port(arg, pos + 0, &pos);
 			early_serial_use_io_accessors();
+		} else if (pos == 7 && !strncmp(arg + pos, "mmio,0x", 7)) {
+			port = parse_serial_port(arg, pos + 5, &pos);
+			early_serial_use_mmio_accessors();
 		} else if (!strncmp(arg + pos, "ttyS", 4)) {
 			static const int bases[] = { 0x3f8, 0x2f8 };
 			int idx = 0;
-- 
2.47.2


  parent reply	other threads:[~2025-05-02 12:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02 12:29 [PATCH v1 0/6] x86/boot: Enable earlyprintk on MMIO (8-bit) Andy Shevchenko
2025-05-02 12:29 ` [PATCH v1 1/6] x86/boot: Convert early_serial_base to unsigned long Andy Shevchenko
2025-05-02 12:29 ` [PATCH v1 2/6] x86/boot: Introduce helpers for serial I/O Andy Shevchenko
2025-05-02 12:29 ` [PATCH v1 3/6] x86/boot: Split out parse_serial_port() helper for earlyprintk Andy Shevchenko
2025-05-02 12:29 ` [PATCH v1 4/6] x86/boot: Allow longer parameter list " Andy Shevchenko
2025-05-02 12:29 ` [PATCH v1 5/6] x86/boot: Also share MMIO accessors Andy Shevchenko
2025-05-02 12:29 ` Andy Shevchenko [this message]
2025-05-02 17:33 ` [PATCH v1 0/6] x86/boot: Enable earlyprintk on MMIO (8-bit) David Woodhouse
2025-05-05 14:05   ` Andy Shevchenko
2025-05-05 14:35     ` David Woodhouse
2025-05-05 14:59       ` Andy Shevchenko
2025-05-05 15:01         ` Andy Shevchenko
2025-05-05 23:32           ` David Woodhouse
2025-05-06  3:19             ` David Woodhouse
2025-05-06 19:38 ` David Woodhouse
2025-05-07 13:54   ` Andy Shevchenko

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=20250502123145.4066635-7-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dmukhin@ford.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.