Skip to content

Commit 37b82b5

Browse files
arch/tile: introduce GXIO IORPC framework for tilegx
The GXIO I/O RPC subsystem handles exporting I/O hardware resources to Linux and to applications running under Linux. For instance, memory which is made available for I/O DMA must be mapped by an I/O TLB; that means that such memory must be locked down by Linux, so that it is not swapped or otherwise reused, as long as those I/O TLB entries are active. Similarly, configuring direct hardware access introduces new validation requirements. If a user application registers memory, Linux must ensure that the supplied virtual addresses are valid, and turn them into client physical addresses. Similarly, when Linux then supplies those client physical addresses to the Tilera hypervisor, it must in turn validate those before turning them into the real physical addresses which are required by the hardware. To the extent that these sorts of activities were required on previous TILE architecture processors, they were implemented in a device-specific fashion. This meant that every I/O device had its own Tilera hypervisor driver, its own Linux driver, and in some cases its own user-level library support. There was a large amount of more-or-less functionally identical code in different places, particularly in the different Linux drivers. For TILE-Gx, this support has been generalized into a common framework, known as the I/O RPC framework or just IORPC. The two "gxio" directories (one for headers, one for sources) start with just a few files in each with this infrastructure commit, but after adding support for the on-board I/O shims for networking, PCI, USB, crypto, compression, I2CS, etc., there end up being about 20 files in each directory. More information on the IORPC framework is in the <hv/iorpc.h> header, included in this commit. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent bd0a521 commit 37b82b5

10 files changed

Lines changed: 985 additions & 0 deletions

File tree

‎arch/tile/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ config KERNEL_PL
345345
kernel will be built to run at. Generally you should use
346346
the default value here.
347347

348+
source "arch/tile/gxio/Kconfig"
349+
348350
endmenu # Tilera-specific configuration
349351

350352
menu "Bus options"

‎arch/tile/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ libs-y += $(LIBGCC_PATH)
5959
# See arch/tile/Kbuild for content of core part of the kernel
6060
core-y += arch/tile/
6161

62+
core-$(CONFIG_TILE_GXIO) += arch/tile/gxio/
63+
6264
ifdef TILERA_ROOT
6365
INSTALL_PATH ?= $(TILERA_ROOT)/tile/boot
6466
endif

‎arch/tile/gxio/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Support direct access to TILE-Gx hardware from user space, via the
2+
# gxio library, or from kernel space, via kernel IORPC support.
3+
config TILE_GXIO
4+
bool
5+
depends on TILEGX

‎arch/tile/gxio/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Makefile for the Tile-Gx device access support.
3+
#
4+
5+
obj-$(CONFIG_TILE_GXIO) += iorpc_globals.o kiorpc.o

‎arch/tile/gxio/iorpc_globals.c‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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_globals.h"
17+
18+
struct arm_pollfd_param {
19+
union iorpc_pollfd pollfd;
20+
};
21+
22+
int __iorpc_arm_pollfd(int fd, int pollfd_cookie)
23+
{
24+
struct arm_pollfd_param temp;
25+
struct arm_pollfd_param *params = &temp;
26+
27+
params->pollfd.kernel.cookie = pollfd_cookie;
28+
29+
return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
30+
IORPC_OP_ARM_POLLFD);
31+
}
32+
33+
EXPORT_SYMBOL(__iorpc_arm_pollfd);
34+
35+
struct close_pollfd_param {
36+
union iorpc_pollfd pollfd;
37+
};
38+
39+
int __iorpc_close_pollfd(int fd, int pollfd_cookie)
40+
{
41+
struct close_pollfd_param temp;
42+
struct close_pollfd_param *params = &temp;
43+
44+
params->pollfd.kernel.cookie = pollfd_cookie;
45+
46+
return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
47+
IORPC_OP_CLOSE_POLLFD);
48+
}
49+
50+
EXPORT_SYMBOL(__iorpc_close_pollfd);
51+
52+
struct get_mmio_base_param {
53+
HV_PTE base;
54+
};
55+
56+
int __iorpc_get_mmio_base(int fd, HV_PTE *base)
57+
{
58+
int __result;
59+
struct get_mmio_base_param temp;
60+
struct get_mmio_base_param *params = &temp;
61+
62+
__result =
63+
hv_dev_pread(fd, 0, (HV_VirtAddr) params, sizeof(*params),
64+
IORPC_OP_GET_MMIO_BASE);
65+
*base = params->base;
66+
67+
return __result;
68+
}
69+
70+
EXPORT_SYMBOL(__iorpc_get_mmio_base);
71+
72+
struct check_mmio_offset_param {
73+
unsigned long offset;
74+
unsigned long size;
75+
};
76+
77+
int __iorpc_check_mmio_offset(int fd, unsigned long offset, unsigned long size)
78+
{
79+
struct check_mmio_offset_param temp;
80+
struct check_mmio_offset_param *params = &temp;
81+
82+
params->offset = offset;
83+
params->size = size;
84+
85+
return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
86+
IORPC_OP_CHECK_MMIO_OFFSET);
87+
}
88+
89+
EXPORT_SYMBOL(__iorpc_check_mmio_offset);

‎arch/tile/gxio/kiorpc.c‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
* TILE-Gx IORPC support for kernel I/O drivers.
15+
*/
16+
17+
#include <linux/mmzone.h>
18+
#include <linux/module.h>
19+
#include <linux/io.h>
20+
#include <gxio/iorpc_globals.h>
21+
#include <gxio/kiorpc.h>
22+
23+
#ifdef DEBUG_IORPC
24+
#define TRACE(FMT, ...) pr_info(SIMPLE_MSG_LINE FMT, ## __VA_ARGS__)
25+
#else
26+
#define TRACE(...)
27+
#endif
28+
29+
/* Create kernel-VA-space MMIO mapping for an on-chip IO device. */
30+
void __iomem *iorpc_ioremap(int hv_fd, resource_size_t offset,
31+
unsigned long size)
32+
{
33+
pgprot_t mmio_base, prot = { 0 };
34+
unsigned long pfn;
35+
int err;
36+
37+
/* Look up the shim's lotar and base PA. */
38+
err = __iorpc_get_mmio_base(hv_fd, &mmio_base);
39+
if (err) {
40+
TRACE("get_mmio_base() failure: %d\n", err);
41+
return NULL;
42+
}
43+
44+
/* Make sure the HV driver approves of our offset and size. */
45+
err = __iorpc_check_mmio_offset(hv_fd, offset, size);
46+
if (err) {
47+
TRACE("check_mmio_offset() failure: %d\n", err);
48+
return NULL;
49+
}
50+
51+
/*
52+
* mmio_base contains a base pfn and homing coordinates. Turn
53+
* it into an MMIO pgprot and offset pfn.
54+
*/
55+
prot = hv_pte_set_lotar(prot, hv_pte_get_lotar(mmio_base));
56+
pfn = pte_pfn(mmio_base) + PFN_DOWN(offset);
57+
58+
return ioremap_prot(PFN_PHYS(pfn), size, prot);
59+
}
60+
61+
EXPORT_SYMBOL(iorpc_ioremap);

‎arch/tile/include/gxio/common.h‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
#ifndef _GXIO_COMMON_H_
16+
#define _GXIO_COMMON_H_
17+
18+
/*
19+
* Routines shared between the various GXIO device components.
20+
*/
21+
22+
#include <hv/iorpc.h>
23+
24+
#include <linux/types.h>
25+
#include <linux/compiler.h>
26+
#include <linux/io.h>
27+
28+
/* Define the standard gxio MMIO functions using kernel functions. */
29+
#define __gxio_mmio_read8(addr) readb(addr)
30+
#define __gxio_mmio_read16(addr) readw(addr)
31+
#define __gxio_mmio_read32(addr) readl(addr)
32+
#define __gxio_mmio_read64(addr) readq(addr)
33+
#define __gxio_mmio_write8(addr, val) writeb((val), (addr))
34+
#define __gxio_mmio_write16(addr, val) writew((val), (addr))
35+
#define __gxio_mmio_write32(addr, val) writel((val), (addr))
36+
#define __gxio_mmio_write64(addr, val) writeq((val), (addr))
37+
#define __gxio_mmio_read(addr) __gxio_mmio_read64(addr)
38+
#define __gxio_mmio_write(addr, val) __gxio_mmio_write64((addr), (val))
39+
40+
#endif /* !_GXIO_COMMON_H_ */
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 __IORPC_LINUX_RPC_H__
17+
#define __IORPC_LINUX_RPC_H__
18+
19+
#include <hv/iorpc.h>
20+
21+
#include <linux/string.h>
22+
#include <linux/module.h>
23+
#include <asm/pgtable.h>
24+
25+
#define IORPC_OP_ARM_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9000)
26+
#define IORPC_OP_CLOSE_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9001)
27+
#define IORPC_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
28+
#define IORPC_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
29+
30+
int __iorpc_arm_pollfd(int fd, int pollfd_cookie);
31+
32+
int __iorpc_close_pollfd(int fd, int pollfd_cookie);
33+
34+
int __iorpc_get_mmio_base(int fd, HV_PTE *base);
35+
36+
int __iorpc_check_mmio_offset(int fd, unsigned long offset, unsigned long size);
37+
38+
#endif /* !__IORPC_LINUX_RPC_H__ */

‎arch/tile/include/gxio/kiorpc.h‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
* Support routines for kernel IORPC drivers.
15+
*/
16+
17+
#ifndef _GXIO_KIORPC_H
18+
#define _GXIO_KIORPC_H
19+
20+
#include <linux/types.h>
21+
#include <asm/page.h>
22+
#include <arch/chip.h>
23+
24+
#if CHIP_HAS_MMIO()
25+
void __iomem *iorpc_ioremap(int hv_fd, resource_size_t offset,
26+
unsigned long size);
27+
#endif
28+
29+
#endif /* _GXIO_KIORPC_H */

0 commit comments

Comments
 (0)