Skip to content

Commit 6ec006e

Browse files
tilegx: provide kernel support for the tilegx UART shim
The TILE-Gx chip includes an on-chip UART. This change adds support for using the UART from within the kernel. The UART shim has more functionality than is exposed here, but to keep the kernel code and binary simpler, this is a subset of the full API designed to enable a standard Linux tty serial driver only. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent acbde1d commit 6ec006e

9 files changed

Lines changed: 768 additions & 0 deletions

File tree

‎arch/tile/gxio/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ config TILE_GXIO_TRIO
2626
config TILE_GXIO_USB_HOST
2727
bool
2828
select TILE_GXIO
29+
30+
# Support direct access to the TILE-Gx UART hardware from kernel space.
31+
config TILE_GXIO_UART
32+
bool
33+
select TILE_GXIO

‎arch/tile/gxio/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ obj-$(CONFIG_TILE_GXIO) += iorpc_globals.o kiorpc.o
66
obj-$(CONFIG_TILE_GXIO_DMA) += dma_queue.o
77
obj-$(CONFIG_TILE_GXIO_MPIPE) += mpipe.o iorpc_mpipe.o iorpc_mpipe_info.o
88
obj-$(CONFIG_TILE_GXIO_TRIO) += trio.o iorpc_trio.o
9+
obj-$(CONFIG_TILE_GXIO_UART) += uart.o iorpc_uart.o
910
obj-$(CONFIG_TILE_GXIO_USB_HOST) += usb_host.o iorpc_usb_host.o

‎arch/tile/gxio/iorpc_uart.c‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2013 Tilera Corporation. All Rights Reserved.
3+
*
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.
7+
*
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.
13+
*/
14+
15+
/* This file is machine-generated; DO NOT EDIT! */
16+
#include "gxio/iorpc_uart.h"
17+
18+
struct cfg_interrupt_param {
19+
union iorpc_interrupt interrupt;
20+
};
21+
22+
int gxio_uart_cfg_interrupt(gxio_uart_context_t *context, int inter_x,
23+
int inter_y, int inter_ipi, int inter_event)
24+
{
25+
struct cfg_interrupt_param temp;
26+
struct cfg_interrupt_param *params = &temp;
27+
28+
params->interrupt.kernel.x = inter_x;
29+
params->interrupt.kernel.y = inter_y;
30+
params->interrupt.kernel.ipi = inter_ipi;
31+
params->interrupt.kernel.event = inter_event;
32+
33+
return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
34+
sizeof(*params), GXIO_UART_OP_CFG_INTERRUPT);
35+
}
36+
37+
EXPORT_SYMBOL(gxio_uart_cfg_interrupt);
38+
39+
struct get_mmio_base_param {
40+
HV_PTE base;
41+
};
42+
43+
int gxio_uart_get_mmio_base(gxio_uart_context_t *context, HV_PTE *base)
44+
{
45+
int __result;
46+
struct get_mmio_base_param temp;
47+
struct get_mmio_base_param *params = &temp;
48+
49+
__result =
50+
hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
51+
GXIO_UART_OP_GET_MMIO_BASE);
52+
*base = params->base;
53+
54+
return __result;
55+
}
56+
57+
EXPORT_SYMBOL(gxio_uart_get_mmio_base);
58+
59+
struct check_mmio_offset_param {
60+
unsigned long offset;
61+
unsigned long size;
62+
};
63+
64+
int gxio_uart_check_mmio_offset(gxio_uart_context_t *context,
65+
unsigned long offset, unsigned long size)
66+
{
67+
struct check_mmio_offset_param temp;
68+
struct check_mmio_offset_param *params = &temp;
69+
70+
params->offset = offset;
71+
params->size = size;
72+
73+
return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
74+
sizeof(*params), GXIO_UART_OP_CHECK_MMIO_OFFSET);
75+
}
76+
77+
EXPORT_SYMBOL(gxio_uart_check_mmio_offset);

‎arch/tile/gxio/uart.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2013 Tilera Corporation. All Rights Reserved.
3+
*
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.
7+
*
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.
13+
*/
14+
15+
/*
16+
* Implementation of UART gxio calls.
17+
*/
18+
19+
#include <linux/io.h>
20+
#include <linux/errno.h>
21+
#include <linux/module.h>
22+
23+
#include <gxio/uart.h>
24+
#include <gxio/iorpc_globals.h>
25+
#include <gxio/iorpc_uart.h>
26+
#include <gxio/kiorpc.h>
27+
28+
int gxio_uart_init(gxio_uart_context_t *context, int uart_index)
29+
{
30+
char file[32];
31+
int fd;
32+
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;
40+
}
41+
42+
context->fd = fd;
43+
44+
/* Map in the MMIO space. */
45+
context->mmio_base = (void __force *)
46+
iorpc_ioremap(fd, HV_UART_MMIO_OFFSET, HV_UART_MMIO_SIZE);
47+
48+
if (context->mmio_base == NULL) {
49+
hv_dev_close(context->fd);
50+
context->fd = -1;
51+
return -ENODEV;
52+
}
53+
54+
return 0;
55+
}
56+
57+
EXPORT_SYMBOL_GPL(gxio_uart_init);
58+
59+
int gxio_uart_destroy(gxio_uart_context_t *context)
60+
{
61+
iounmap((void __force __iomem *)(context->mmio_base));
62+
hv_dev_close(context->fd);
63+
64+
context->mmio_base = NULL;
65+
context->fd = -1;
66+
67+
return 0;
68+
}
69+
70+
EXPORT_SYMBOL_GPL(gxio_uart_destroy);
71+
72+
/* UART register write wrapper. */
73+
void gxio_uart_write(gxio_uart_context_t *context, uint64_t offset,
74+
uint64_t word)
75+
{
76+
__gxio_mmio_write(context->mmio_base + offset, word);
77+
}
78+
79+
EXPORT_SYMBOL_GPL(gxio_uart_write);
80+
81+
/* UART register read wrapper. */
82+
uint64_t gxio_uart_read(gxio_uart_context_t *context, uint64_t offset)
83+
{
84+
return __gxio_mmio_read(context->mmio_base + offset);
85+
}
86+
87+
EXPORT_SYMBOL_GPL(gxio_uart_read);

0 commit comments

Comments
 (0)