Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: goldfish: use __raw_writel()/__raw_readl()

gf_early_console_putchar() uses __raw_writel() but the standard driver
uses writel()/readl(). This means we can't use both on the same machine
as the device is either big-endian, little-endian or native-endian.

As android implementation defines the endianness of the device is the one
of the architecture replace all writel()/readl() by
__raw_writel()/__raw_readl()

https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/hw/char/goldfish_tty.c#222

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Link: https://lore.kernel.org/r/20201010004749.1201695-1-laurent@vivier.eu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Laurent Vivier and committed by
Greg Kroah-Hartman
da31de35 1a460c36

+13 -13
+9 -9
drivers/tty/goldfish.c
··· 61 61 spin_lock_irqsave(&qtty->lock, irq_flags); 62 62 gf_write_ptr((void *)address, base + GOLDFISH_TTY_REG_DATA_PTR, 63 63 base + GOLDFISH_TTY_REG_DATA_PTR_HIGH); 64 - writel(count, base + GOLDFISH_TTY_REG_DATA_LEN); 64 + __raw_writel(count, base + GOLDFISH_TTY_REG_DATA_LEN); 65 65 66 66 if (is_write) 67 - writel(GOLDFISH_TTY_CMD_WRITE_BUFFER, 67 + __raw_writel(GOLDFISH_TTY_CMD_WRITE_BUFFER, 68 68 base + GOLDFISH_TTY_REG_CMD); 69 69 else 70 - writel(GOLDFISH_TTY_CMD_READ_BUFFER, 70 + __raw_writel(GOLDFISH_TTY_CMD_READ_BUFFER, 71 71 base + GOLDFISH_TTY_REG_CMD); 72 72 73 73 spin_unlock_irqrestore(&qtty->lock, irq_flags); ··· 142 142 unsigned char *buf; 143 143 u32 count; 144 144 145 - count = readl(base + GOLDFISH_TTY_REG_BYTES_READY); 145 + count = __raw_readl(base + GOLDFISH_TTY_REG_BYTES_READY); 146 146 if (count == 0) 147 147 return IRQ_NONE; 148 148 ··· 159 159 { 160 160 struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, 161 161 port); 162 - writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD); 162 + __raw_writel(GOLDFISH_TTY_CMD_INT_ENABLE, qtty->base + GOLDFISH_TTY_REG_CMD); 163 163 return 0; 164 164 } 165 165 ··· 167 167 { 168 168 struct goldfish_tty *qtty = container_of(port, struct goldfish_tty, 169 169 port); 170 - writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD); 170 + __raw_writel(GOLDFISH_TTY_CMD_INT_DISABLE, qtty->base + GOLDFISH_TTY_REG_CMD); 171 171 } 172 172 173 173 static int goldfish_tty_open(struct tty_struct *tty, struct file *filp) ··· 202 202 { 203 203 struct goldfish_tty *qtty = &goldfish_ttys[tty->index]; 204 204 void __iomem *base = qtty->base; 205 - return readl(base + GOLDFISH_TTY_REG_BYTES_READY); 205 + return __raw_readl(base + GOLDFISH_TTY_REG_BYTES_READY); 206 206 } 207 207 208 208 static void goldfish_tty_console_write(struct console *co, const char *b, ··· 357 357 * on Ranchu emulator (qemu2) returns 1 here and 358 358 * driver will use physical addresses. 359 359 */ 360 - qtty->version = readl(base + GOLDFISH_TTY_REG_VERSION); 360 + qtty->version = __raw_readl(base + GOLDFISH_TTY_REG_VERSION); 361 361 362 362 /* 363 363 * Goldfish TTY device on Ranchu emulator (qemu2) ··· 376 376 } 377 377 } 378 378 379 - writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD); 379 + __raw_writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_REG_CMD); 380 380 381 381 ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, 382 382 "goldfish_tty", qtty);
+4 -4
include/linux/goldfish.h
··· 13 13 { 14 14 const unsigned long addr = (unsigned long)ptr; 15 15 16 - writel(lower_32_bits(addr), portl); 16 + __raw_writel(lower_32_bits(addr), portl); 17 17 #ifdef CONFIG_64BIT 18 - writel(upper_32_bits(addr), porth); 18 + __raw_writel(upper_32_bits(addr), porth); 19 19 #endif 20 20 } 21 21 ··· 23 23 void __iomem *portl, 24 24 void __iomem *porth) 25 25 { 26 - writel(lower_32_bits(addr), portl); 26 + __raw_writel(lower_32_bits(addr), portl); 27 27 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 28 - writel(upper_32_bits(addr), porth); 28 + __raw_writel(upper_32_bits(addr), porth); 29 29 #endif 30 30 } 31 31