Reduce amount of casting in drivers/tty/goldfish.c.

Change-Id: I8be0ff52a4c3a5bfcc72971f79df8d1c0b5a0eec
Signed-off-by: Roman Kiryanov <rkir@google.com>
This commit is contained in:
Roman Kiryanov 2018-04-06 16:51:19 -07:00
parent d6bbe8be6b
commit c758d68c86

View file

@ -87,32 +87,35 @@ static void do_rw_io(struct goldfish_tty *qtty,
} }
static void goldfish_tty_rw(struct goldfish_tty *qtty, static void goldfish_tty_rw(struct goldfish_tty *qtty,
unsigned long addr, const void *address_ptr,
unsigned int count, unsigned int count,
int is_write) int is_write)
{ {
dma_addr_t dma_handle; dma_addr_t dma_handle;
enum dma_data_direction dma_dir; enum dma_data_direction dma_dir;
uintptr_t address;
address = (uintptr_t)address_ptr;
dma_dir = (is_write ? DMA_TO_DEVICE : DMA_FROM_DEVICE); dma_dir = (is_write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
if (qtty->version > 0) { if (qtty->version > 0) {
/* /*
* Goldfish TTY for Ranchu platform uses * Goldfish TTY for Ranchu platform uses
* physical addresses and DMA for read/write operations * physical addresses and DMA for read/write operations
*/ */
unsigned long addr_end = addr + count; uintptr_t address_end = address + count;
while (addr < addr_end) { while (address < address_end) {
unsigned long pg_end = (addr & PAGE_MASK) + PAGE_SIZE; uintptr_t page_end = (address & PAGE_MASK) + PAGE_SIZE;
unsigned long next = uintptr_t next = page_end < address_end ?
pg_end < addr_end ? pg_end : addr_end; page_end : address_end;
unsigned long avail = next - addr; uintptr_t avail = next - address;
/* /*
* Map the buffer's virtual address to the DMA address * Map the buffer's virtual address to the DMA address
* so the buffer can be accessed by the device. * so the buffer can be accessed by the device.
*/ */
dma_handle = dma_map_single(qtty->dev, (void *)addr, dma_handle = dma_map_single(qtty->dev, (void *)address,
avail, dma_dir); avail, dma_dir);
if (dma_mapping_error(qtty->dev, dma_handle)) { if (dma_mapping_error(qtty->dev, dma_handle)) {
@ -127,31 +130,30 @@ static void goldfish_tty_rw(struct goldfish_tty *qtty,
*/ */
dma_unmap_single(qtty->dev, dma_handle, avail, dma_dir); dma_unmap_single(qtty->dev, dma_handle, avail, dma_dir);
addr += avail; address += avail;
} }
} else { } else {
/* /*
* Old style Goldfish TTY used on the Goldfish platform * Old style Goldfish TTY used on the Goldfish platform
* uses virtual addresses. * uses virtual addresses.
*/ */
do_rw_io(qtty, addr, count, is_write); do_rw_io(qtty, address, count, is_write);
} }
} }
static void goldfish_tty_do_write(int line, const char *buf, static void goldfish_tty_do_write(int line, const char *buf,
unsigned int count) unsigned int count)
{ {
struct goldfish_tty *qtty = &goldfish_ttys[line]; struct goldfish_tty *qtty = &goldfish_ttys[line];
unsigned long address = (unsigned long)(void *)buf;
goldfish_tty_rw(qtty, address, count, 1); goldfish_tty_rw(qtty, buf, count, 1);
} }
static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
{ {
struct goldfish_tty *qtty = dev_id; struct goldfish_tty *qtty = dev_id;
void __iomem *base = qtty->base; void __iomem *base = qtty->base;
unsigned long address;
unsigned char *buf; unsigned char *buf;
u32 count; u32 count;
@ -160,9 +162,7 @@ static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id)
return IRQ_NONE; return IRQ_NONE;
count = tty_prepare_flip_string(&qtty->port, &buf, count); count = tty_prepare_flip_string(&qtty->port, &buf, count);
goldfish_tty_rw(qtty, buf, count, 0);
address = (unsigned long)(void *)buf;
goldfish_tty_rw(qtty, address, count, 0);
tty_schedule_flip(&qtty->port); tty_schedule_flip(&qtty->port);
return IRQ_HANDLED; return IRQ_HANDLED;