Skip to content

Commit 2e2ac4a

Browse files
viviergeertu
authored andcommitted
tty: goldfish: Introduce gf_ioread32()/gf_iowrite32()
The goldfish TTY device was clearly defined as having little-endian registers, but the switch to __raw_{read,write}l(() broke its driver when running on big-endian kernels (if anyone ever tried this). The m68k qemu implementation got this wrong, and assumed native-endian registers. While this is a bug in qemu, it is probably impossible to fix that since there is no way of knowing which other operating systems have started relying on that bug over the years. Hence revert commit da31de3 ("tty: goldfish: use __raw_writel()/__raw_readl()", and define gf_ioread32()/gf_iowrite32() to be able to use accessors defined by the architecture. Cc: [email protected] # v5.11+ Fixes: da31de3 ("tty: goldfish: use __raw_writel()/__raw_readl()") Signed-off-by: Laurent Vivier <[email protected]> Link: https://lore.kernel.org/r/[email protected] [geert: Add rationale based on Arnd's comments] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 3123109 commit 2e2ac4a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

drivers/tty/goldfish.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ static void do_rw_io(struct goldfish_tty *qtty,
6161
spin_lock_irqsave(&qtty->lock, irq_flags);
6262
gf_write_ptr((void *)address, base + GOLDFISH_TTY_REG_DATA_PTR,
6363
base + GOLDFISH_TTY_REG_DATA_PTR_HIGH);
64-
__raw_writel(count, base + GOLDFISH_TTY_REG_DATA_LEN);
64+
gf_iowrite32(count, base + GOLDFISH_TTY_REG_DATA_LEN);
6565

6666
if (is_write)
67-
__raw_writel(GOLDFISH_TTY_CMD_WRITE_BUFFER,
67+
gf_iowrite32(GOLDFISH_TTY_CMD_WRITE_BUFFER,
6868
base + GOLDFISH_TTY_REG_CMD);
6969
else
70-
__raw_writel(GOLDFISH_TTY_CMD_READ_BUFFER,
70+
gf_iowrite32(GOLDFISH_TTY_CMD_READ_BUFFER,
7171
base + GOLDFISH_TTY_REG_CMD);
7272

7373
spin_unlock_irqrestore(&qtty->lock, irq_flags);
@@ -142,7 +142,7 @@ static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
142142
unsigned char *buf;
143143
u32 count;
144144

145-
count = __raw_readl(base + GOLDFISH_TTY_REG_BYTES_READY);
145+
count = gf_ioread32(base + GOLDFISH_TTY_REG_BYTES_READY);
146146
if (count == 0)
147147
return IRQ_NONE;
148148

@@ -159,15 +159,15 @@ static int goldfish_tty_activate(struct tty_port *port, struct tty_struct *tty)
159159
{
160160
struct goldfish_tty *qtty = container_of(port, struct goldfish_tty,
161161
port);
162-
__raw_writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
162+
gf_iowrite32(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
163163
return 0;
164164
}
165165

166166
static void goldfish_tty_shutdown(struct tty_port *port)
167167
{
168168
struct goldfish_tty *qtty = container_of(port, struct goldfish_tty,
169169
port);
170-
__raw_writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
170+
gf_iowrite32(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD);
171171
}
172172

173173
static int goldfish_tty_open(struct tty_struct *tty, struct file *filp)
@@ -202,7 +202,7 @@ static unsigned int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
202202
{
203203
struct goldfish_tty *qtty = &goldfish_ttys[tty->index];
204204
void __iomem *base = qtty->base;
205-
return __raw_readl(base + GOLDFISH_TTY_REG_BYTES_READY);
205+
return gf_ioread32(base + GOLDFISH_TTY_REG_BYTES_READY);
206206
}
207207

208208
static void goldfish_tty_console_write(struct console *co, const char *b,
@@ -355,7 +355,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
355355
* on Ranchu emulator (qemu2) returns 1 here and
356356
* driver will use physical addresses.
357357
*/
358-
qtty->version = __raw_readl(base + GOLDFISH_TTY_REG_VERSION);
358+
qtty->version = gf_ioread32(base + GOLDFISH_TTY_REG_VERSION);
359359

360360
/*
361361
* Goldfish TTY device on Ranchu emulator (qemu2)
@@ -374,7 +374,7 @@ static int goldfish_tty_probe(struct platform_device *pdev)
374374
}
375375
}
376376

377-
__raw_writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD);
377+
gf_iowrite32(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD);
378378

379379
ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED,
380380
"goldfish_tty", qtty);
@@ -436,7 +436,7 @@ static int goldfish_tty_remove(struct platform_device *pdev)
436436
#ifdef CONFIG_GOLDFISH_TTY_EARLY_CONSOLE
437437
static void gf_early_console_putchar(struct uart_port *port, unsigned char ch)
438438
{
439-
__raw_writel(ch, port->membase);
439+
gf_iowrite32(ch, port->membase);
440440
}
441441

442442
static void gf_early_write(struct console *con, const char *s, unsigned int n)

include/linux/goldfish.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,31 @@
88

99
/* Helpers for Goldfish virtual platform */
1010

11+
#ifndef gf_ioread32
12+
#define gf_ioread32 ioread32
13+
#endif
14+
#ifndef gf_iowrite32
15+
#define gf_iowrite32 iowrite32
16+
#endif
17+
1118
static inline void gf_write_ptr(const void *ptr, void __iomem *portl,
1219
void __iomem *porth)
1320
{
1421
const unsigned long addr = (unsigned long)ptr;
1522

16-
__raw_writel(lower_32_bits(addr), portl);
23+
gf_iowrite32(lower_32_bits(addr), portl);
1724
#ifdef CONFIG_64BIT
18-
__raw_writel(upper_32_bits(addr), porth);
25+
gf_iowrite32(upper_32_bits(addr), porth);
1926
#endif
2027
}
2128

2229
static inline void gf_write_dma_addr(const dma_addr_t addr,
2330
void __iomem *portl,
2431
void __iomem *porth)
2532
{
26-
__raw_writel(lower_32_bits(addr), portl);
33+
gf_iowrite32(lower_32_bits(addr), portl);
2734
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
28-
__raw_writel(upper_32_bits(addr), porth);
35+
gf_iowrite32(upper_32_bits(addr), porth);
2936
#endif
3037
}
3138

0 commit comments

Comments
 (0)