aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Metcalf <cmetcalf@tilera.com>2012-05-09 12:25:02 -0400
committerChris Metcalf <cmetcalf@tilera.com>2012-07-18 16:40:24 -0400
commitd1cc1732cc62034542b042a4506d7c5043bc5e5e (patch)
tree85fe94b0e84275d791bd35ab94a6ca2cd4c7c6df
parent41bb38fc5398ae878c799647f3c4b25374029afb (diff)
arch/tile: provide kernel support for the tilegx USB shim
This change adds support for accessing the USB shim from within the kernel. Note that this change by itself does not allow the kernel to act as a host or as a device; it merely exposes the built-in on-chip hardware to the kernel. The <arch/usb_host.h> and <arch/usb_host_def.h> headers are empty at the moment because the kernel does not require any types or definitions specific to the tilegx USB shim; the generic USB core code is all we need. The headers are left in as stubs so that we don't need to modify the hypervisor header (drv_usb_host_intf.h) from upstream. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
-rw-r--r--arch/tile/gxio/Kconfig5
-rw-r--r--arch/tile/gxio/Makefile1
-rw-r--r--arch/tile/gxio/iorpc_usb_host.c99
-rw-r--r--arch/tile/gxio/usb_host.c91
-rw-r--r--arch/tile/include/arch/usb_host.h26
-rw-r--r--arch/tile/include/arch/usb_host_def.h19
-rw-r--r--arch/tile/include/gxio/iorpc_usb_host.h46
-rw-r--r--arch/tile/include/gxio/usb_host.h87
-rw-r--r--arch/tile/include/hv/drv_usb_host_intf.h39
9 files changed, 413 insertions, 0 deletions
diff --git a/arch/tile/gxio/Kconfig b/arch/tile/gxio/Kconfig
index 68e1cca2cce5..d221f8d6de8b 100644
--- a/arch/tile/gxio/Kconfig
+++ b/arch/tile/gxio/Kconfig
@@ -21,3 +21,8 @@ config TILE_GXIO_TRIO
21 bool 21 bool
22 select TILE_GXIO 22 select TILE_GXIO
23 select TILE_GXIO_DMA 23 select TILE_GXIO_DMA
24
25# Support direct access to the TILE-Gx USB hardware from kernel space.
26config TILE_GXIO_USB_HOST
27 bool
28 select TILE_GXIO
diff --git a/arch/tile/gxio/Makefile b/arch/tile/gxio/Makefile
index 2389ef307c73..8684bcaa74ea 100644
--- a/arch/tile/gxio/Makefile
+++ b/arch/tile/gxio/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TILE_GXIO) += iorpc_globals.o kiorpc.o
6obj-$(CONFIG_TILE_GXIO_DMA) += dma_queue.o 6obj-$(CONFIG_TILE_GXIO_DMA) += dma_queue.o
7obj-$(CONFIG_TILE_GXIO_MPIPE) += mpipe.o iorpc_mpipe.o iorpc_mpipe_info.o 7obj-$(CONFIG_TILE_GXIO_MPIPE) += mpipe.o iorpc_mpipe.o iorpc_mpipe_info.o
8obj-$(CONFIG_TILE_GXIO_TRIO) += trio.o iorpc_trio.o 8obj-$(CONFIG_TILE_GXIO_TRIO) += trio.o iorpc_trio.o
9obj-$(CONFIG_TILE_GXIO_USB_HOST) += usb_host.o iorpc_usb_host.o
diff --git a/arch/tile/gxio/iorpc_usb_host.c b/arch/tile/gxio/iorpc_usb_host.c
new file mode 100644
index 000000000000..cf3c3cc12204
--- /dev/null
+++ b/arch/tile/gxio/iorpc_usb_host.c
@@ -0,0 +1,99 @@
1/*
2 * Copyright 2012 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_usb_host.h"
17
18struct cfg_interrupt_param {
19 union iorpc_interrupt interrupt;
20};
21
22int gxio_usb_host_cfg_interrupt(gxio_usb_host_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_USB_HOST_OP_CFG_INTERRUPT);
35}
36
37EXPORT_SYMBOL(gxio_usb_host_cfg_interrupt);
38
39struct register_client_memory_param {
40 HV_PTE pte;
41 unsigned int flags;
42};
43
44int gxio_usb_host_register_client_memory(gxio_usb_host_context_t * context,
45 HV_PTE pte, unsigned int flags)
46{
47 struct register_client_memory_param temp;
48 struct register_client_memory_param *params = &temp;
49
50 params->pte = pte;
51 params->flags = flags;
52
53 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
54 sizeof(*params),
55 GXIO_USB_HOST_OP_REGISTER_CLIENT_MEMORY);
56}
57
58EXPORT_SYMBOL(gxio_usb_host_register_client_memory);
59
60struct get_mmio_base_param {
61 HV_PTE base;
62};
63
64int gxio_usb_host_get_mmio_base(gxio_usb_host_context_t * context, HV_PTE *base)
65{
66 int __result;
67 struct get_mmio_base_param temp;
68 struct get_mmio_base_param *params = &temp;
69
70 __result =
71 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
72 GXIO_USB_HOST_OP_GET_MMIO_BASE);
73 *base = params->base;
74
75 return __result;
76}
77
78EXPORT_SYMBOL(gxio_usb_host_get_mmio_base);
79
80struct check_mmio_offset_param {
81 unsigned long offset;
82 unsigned long size;
83};
84
85int gxio_usb_host_check_mmio_offset(gxio_usb_host_context_t * context,
86 unsigned long offset, unsigned long size)
87{
88 struct check_mmio_offset_param temp;
89 struct check_mmio_offset_param *params = &temp;
90
91 params->offset = offset;
92 params->size = size;
93
94 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
95 sizeof(*params),
96 GXIO_USB_HOST_OP_CHECK_MMIO_OFFSET);
97}
98
99EXPORT_SYMBOL(gxio_usb_host_check_mmio_offset);
diff --git a/arch/tile/gxio/usb_host.c b/arch/tile/gxio/usb_host.c
new file mode 100644
index 000000000000..66b002f54ecc
--- /dev/null
+++ b/arch/tile/gxio/usb_host.c
@@ -0,0 +1,91 @@
1/*
2 * Copyright 2012 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 *
17 * Implementation of USB gxio calls.
18 */
19
20#include <linux/io.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23
24#include <gxio/iorpc_globals.h>
25#include <gxio/iorpc_usb_host.h>
26#include <gxio/kiorpc.h>
27#include <gxio/usb_host.h>
28
29int gxio_usb_host_init(gxio_usb_host_context_t * context, int usb_index,
30 int is_ehci)
31{
32 char file[32];
33 int fd;
34
35 if (is_ehci)
36 snprintf(file, sizeof(file), "usb_host/%d/iorpc/ehci",
37 usb_index);
38 else
39 snprintf(file, sizeof(file), "usb_host/%d/iorpc/ohci",
40 usb_index);
41
42 fd = hv_dev_open((HV_VirtAddr) file, 0);
43 if (fd < 0) {
44 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
45 return fd;
46 else
47 return -ENODEV;
48 }
49
50 context->fd = fd;
51
52 // Map in the MMIO space.
53 context->mmio_base =
54 (void __force *)iorpc_ioremap(fd, 0, HV_USB_HOST_MMIO_SIZE);
55
56 if (context->mmio_base == NULL) {
57 hv_dev_close(context->fd);
58 return -ENODEV;
59 }
60
61 return 0;
62}
63
64EXPORT_SYMBOL_GPL(gxio_usb_host_init);
65
66int gxio_usb_host_destroy(gxio_usb_host_context_t * context)
67{
68 iounmap((void __force __iomem *)(context->mmio_base));
69 hv_dev_close(context->fd);
70
71 context->mmio_base = NULL;
72 context->fd = -1;
73
74 return 0;
75}
76
77EXPORT_SYMBOL_GPL(gxio_usb_host_destroy);
78
79void *gxio_usb_host_get_reg_start(gxio_usb_host_context_t * context)
80{
81 return context->mmio_base;
82}
83
84EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_start);
85
86size_t gxio_usb_host_get_reg_len(gxio_usb_host_context_t * context)
87{
88 return HV_USB_HOST_MMIO_SIZE;
89}
90
91EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_len);
diff --git a/arch/tile/include/arch/usb_host.h b/arch/tile/include/arch/usb_host.h
new file mode 100644
index 000000000000..d09f32683962
--- /dev/null
+++ b/arch/tile/include/arch/usb_host.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright 2012 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/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_USB_HOST_H__
18#define __ARCH_USB_HOST_H__
19
20#include <arch/abi.h>
21#include <arch/usb_host_def.h>
22
23#ifndef __ASSEMBLER__
24#endif /* !defined(__ASSEMBLER__) */
25
26#endif /* !defined(__ARCH_USB_HOST_H__) */
diff --git a/arch/tile/include/arch/usb_host_def.h b/arch/tile/include/arch/usb_host_def.h
new file mode 100644
index 000000000000..aeed7753e8e1
--- /dev/null
+++ b/arch/tile/include/arch/usb_host_def.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright 2012 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/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_USB_HOST_DEF_H__
18#define __ARCH_USB_HOST_DEF_H__
19#endif /* !defined(__ARCH_USB_HOST_DEF_H__) */
diff --git a/arch/tile/include/gxio/iorpc_usb_host.h b/arch/tile/include/gxio/iorpc_usb_host.h
new file mode 100644
index 000000000000..8622e7d126ad
--- /dev/null
+++ b/arch/tile/include/gxio/iorpc_usb_host.h
@@ -0,0 +1,46 @@
1/*
2 * Copyright 2012 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#ifndef __GXIO_USB_HOST_LINUX_RPC_H__
17#define __GXIO_USB_HOST_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_usb_host_intf.h>
22#include <asm/page.h>
23#include <gxio/kiorpc.h>
24#include <gxio/usb_host.h>
25#include <linux/string.h>
26#include <linux/module.h>
27#include <asm/pgtable.h>
28
29#define GXIO_USB_HOST_OP_CFG_INTERRUPT IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1800)
30#define GXIO_USB_HOST_OP_REGISTER_CLIENT_MEMORY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1801)
31#define GXIO_USB_HOST_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
32#define GXIO_USB_HOST_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
33
34int gxio_usb_host_cfg_interrupt(gxio_usb_host_context_t * context, int inter_x,
35 int inter_y, int inter_ipi, int inter_event);
36
37int gxio_usb_host_register_client_memory(gxio_usb_host_context_t * context,
38 HV_PTE pte, unsigned int flags);
39
40int gxio_usb_host_get_mmio_base(gxio_usb_host_context_t * context,
41 HV_PTE *base);
42
43int gxio_usb_host_check_mmio_offset(gxio_usb_host_context_t * context,
44 unsigned long offset, unsigned long size);
45
46#endif /* !__GXIO_USB_HOST_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/usb_host.h b/arch/tile/include/gxio/usb_host.h
new file mode 100644
index 000000000000..a60a126e4565
--- /dev/null
+++ b/arch/tile/include/gxio/usb_host.h
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2012 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#ifndef _GXIO_USB_H_
15#define _GXIO_USB_H_
16
17#include "common.h"
18
19#include <hv/drv_usb_host_intf.h>
20#include <hv/iorpc.h>
21
22/*
23 *
24 * An API for manipulating general-purpose I/O pins.
25 */
26
27/*
28 *
29 * The USB shim allows access to the processor's Universal Serial Bus
30 * connections.
31 */
32
33/* A context object used to manage USB hardware resources. */
34typedef struct {
35
36 /* File descriptor for calling up to the hypervisor. */
37 int fd;
38
39 /* The VA at which our MMIO registers are mapped. */
40 char *mmio_base;
41} gxio_usb_host_context_t;
42
43/* Initialize a USB context.
44 *
45 * A properly initialized context must be obtained before any of the other
46 * gxio_usb_host routines may be used.
47 *
48 * @param context Pointer to a gxio_usb_host_context_t, which will be
49 * initialized by this routine, if it succeeds.
50 * @param usb_index Index of the USB shim to use.
51 * @param is_ehci Nonzero to use the EHCI interface; zero to use the OHCI
52 * intereface.
53 * @return Zero if the context was successfully initialized, else a
54 * GXIO_ERR_xxx error code.
55 */
56extern int gxio_usb_host_init(gxio_usb_host_context_t * context, int usb_index,
57 int is_ehci);
58
59/* Destroy a USB context.
60 *
61 * Once destroyed, a context may not be used with any gxio_usb_host routines
62 * other than gxio_usb_host_init(). After this routine returns, no further
63 * interrupts or signals requested on this context will be delivered. The
64 * state and configuration of the pins which had been attached to this
65 * context are unchanged by this operation.
66 *
67 * @param context Pointer to a gxio_usb_host_context_t.
68 * @return Zero if the context was successfully destroyed, else a
69 * GXIO_ERR_xxx error code.
70 */
71extern int gxio_usb_host_destroy(gxio_usb_host_context_t * context);
72
73/* Retrieve the address of the shim's MMIO registers.
74 *
75 * @param context Pointer to a properly initialized gxio_usb_host_context_t.
76 * @return The address of the shim's MMIO registers.
77 */
78extern void *gxio_usb_host_get_reg_start(gxio_usb_host_context_t * context);
79
80/* Retrieve the length of the shim's MMIO registers.
81 *
82 * @param context Pointer to a properly initialized gxio_usb_host_context_t.
83 * @return The length of the shim's MMIO registers.
84 */
85extern size_t gxio_usb_host_get_reg_len(gxio_usb_host_context_t * context);
86
87#endif /* _GXIO_USB_H_ */
diff --git a/arch/tile/include/hv/drv_usb_host_intf.h b/arch/tile/include/hv/drv_usb_host_intf.h
new file mode 100644
index 000000000000..24ce774a3f1d
--- /dev/null
+++ b/arch/tile/include/hv/drv_usb_host_intf.h
@@ -0,0 +1,39 @@
1/*
2 * Copyright 2012 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 * Interface definitions for the USB host driver.
17 */
18
19#ifndef _SYS_HV_DRV_USB_HOST_INTF_H
20#define _SYS_HV_DRV_USB_HOST_INTF_H
21
22#include <arch/usb_host.h>
23
24
25/** Offset for the EHCI register MMIO region. */
26#define HV_USB_HOST_MMIO_OFFSET_EHCI ((uint64_t) USB_HOST_HCCAPBASE_REG)
27
28/** Offset for the OHCI register MMIO region. */
29#define HV_USB_HOST_MMIO_OFFSET_OHCI ((uint64_t) USB_HOST_OHCD_HC_REVISION_REG)
30
31/** Size of the register MMIO region. This turns out to be the same for
32 * both EHCI and OHCI. */
33#define HV_USB_HOST_MMIO_SIZE ((uint64_t) 0x1000)
34
35/** The number of service domains supported by the USB host shim. */
36#define HV_USB_HOST_NUM_SVC_DOM 1
37
38
39#endif /* _SYS_HV_DRV_USB_HOST_INTF_H */