KVM: Introduce gfn_to_hva_memslot_prot
[linux/fpc-iii.git] / arch / tile / gxio / uart.c
blobba585175ef883d87cfc147e64ccca0f8f0c71cc6
1 /*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
16 * Implementation of UART gxio calls.
19 #include <linux/io.h>
20 #include <linux/errno.h>
21 #include <linux/module.h>
23 #include <gxio/uart.h>
24 #include <gxio/iorpc_globals.h>
25 #include <gxio/iorpc_uart.h>
26 #include <gxio/kiorpc.h>
28 int gxio_uart_init(gxio_uart_context_t *context, int uart_index)
30 char file[32];
31 int fd;
33 snprintf(file, sizeof(file), "uart/%d/iorpc", uart_index);
34 fd = hv_dev_open((HV_VirtAddr) file, 0);
35 if (fd < 0) {
36 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
37 return fd;
38 else
39 return -ENODEV;
42 context->fd = fd;
44 /* Map in the MMIO space. */
45 context->mmio_base = (void __force *)
46 iorpc_ioremap(fd, HV_UART_MMIO_OFFSET, HV_UART_MMIO_SIZE);
48 if (context->mmio_base == NULL) {
49 hv_dev_close(context->fd);
50 context->fd = -1;
51 return -ENODEV;
54 return 0;
57 EXPORT_SYMBOL_GPL(gxio_uart_init);
59 int gxio_uart_destroy(gxio_uart_context_t *context)
61 iounmap((void __force __iomem *)(context->mmio_base));
62 hv_dev_close(context->fd);
64 context->mmio_base = NULL;
65 context->fd = -1;
67 return 0;
70 EXPORT_SYMBOL_GPL(gxio_uart_destroy);
72 /* UART register write wrapper. */
73 void gxio_uart_write(gxio_uart_context_t *context, uint64_t offset,
74 uint64_t word)
76 __gxio_mmio_write(context->mmio_base + offset, word);
79 EXPORT_SYMBOL_GPL(gxio_uart_write);
81 /* UART register read wrapper. */
82 uint64_t gxio_uart_read(gxio_uart_context_t *context, uint64_t offset)
84 return __gxio_mmio_read(context->mmio_base + offset);
87 EXPORT_SYMBOL_GPL(gxio_uart_read);