Skip to content

Commit 2c973ef

Browse files
dczhuralfbaechle
authored andcommitted
MIPS: APRP: Split RTLX support into separate files.
Split the RTLX functionality in preparation for adding support for CMP platforms. Common functions remain in the original file and a new file contains code specific to platforms that do not have a CMP. Signed-off-by: Deng-Cheng Zhu <dengcheng.zhu@imgtec.com> Signed-off-by: Steven J. Hill <Steven.Hill@imgtec.com> Reviewed-by: Qais Yousef <Qais.Yousef@imgtec.com> Patchwork: http://patchwork.linux-mips.org/patch/6093/ Reviewed-by: John Crispin <blogic@openwrt.org>
1 parent 17a1d52 commit 2c973ef

5 files changed

Lines changed: 195 additions & 144 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,11 @@ config MIPS_VPE_APSP_API
19561956
depends on MIPS_VPE_LOADER
19571957
help
19581958

1959+
config MIPS_VPE_APSP_API_MT
1960+
bool
1961+
default "y"
1962+
depends on MIPS_VPE_APSP_API && !MIPS_CMP
1963+
19591964
config MIPS_CMP
19601965
bool "MIPS CMP support"
19611966
depends on SYS_SUPPORTS_MIPS_CMP && MIPS_MT_SMP

‎arch/mips/include/asm/rtlx.h‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
/*
22
* Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
3-
*
3+
* Copyright (C) 2013 Imagination Technologies Ltd.
44
*/
55

66
#ifndef __ASM_RTLX_H_
77
#define __ASM_RTLX_H_
88

99
#include <irq.h>
1010

11+
#define RTLX_MODULE_NAME "rtlx"
12+
1113
#define LX_NODE_BASE 10
1214

1315
#define MIPS_CPU_RTLX_IRQ 0
1416

1517
#define RTLX_VERSION 2
1618
#define RTLX_xID 0x12345600
1719
#define RTLX_ID (RTLX_xID | RTLX_VERSION)
20+
#define RTLX_BUFFER_SIZE 2048
1821
#define RTLX_CHANNELS 8
1922

2023
#define RTLX_CHANNEL_STDIO 0
2124
#define RTLX_CHANNEL_DBG 1
2225
#define RTLX_CHANNEL_SYSIO 2
2326

24-
extern int rtlx_open(int index, int can_sleep);
25-
extern int rtlx_release(int index);
26-
extern ssize_t rtlx_read(int index, void __user *buff, size_t count);
27-
extern ssize_t rtlx_write(int index, const void __user *buffer, size_t count);
28-
extern unsigned int rtlx_read_poll(int index, int can_sleep);
29-
extern unsigned int rtlx_write_poll(int index);
27+
void rtlx_starting(int vpe);
28+
void rtlx_stopping(int vpe);
29+
30+
int rtlx_open(int index, int can_sleep);
31+
int rtlx_release(int index);
32+
ssize_t rtlx_read(int index, void __user *buff, size_t count);
33+
ssize_t rtlx_write(int index, const void __user *buffer, size_t count);
34+
unsigned int rtlx_read_poll(int index, int can_sleep);
35+
unsigned int rtlx_write_poll(int index);
36+
37+
int __init rtlx_module_init(void);
38+
void __exit rtlx_module_exit(void);
39+
40+
void _interrupt_sp(void);
41+
42+
extern struct vpe_notifications rtlx_notify;
43+
extern const struct file_operations rtlx_fops;
44+
extern void (*aprp_hook)(void);
3045

3146
enum rtlx_state {
3247
RTLX_STATE_UNUSED = 0,
@@ -35,10 +50,15 @@ enum rtlx_state {
3550
RTLX_STATE_OPENED
3651
};
3752

38-
#define RTLX_BUFFER_SIZE 2048
53+
extern struct chan_waitqueues {
54+
wait_queue_head_t rt_queue;
55+
wait_queue_head_t lx_queue;
56+
atomic_t in_open;
57+
struct mutex mutex;
58+
} channel_wqs[RTLX_CHANNELS];
3959

4060
/* each channel supports read and write.
41-
linux (vpe0) reads lx_buffer and writes rt_buffer
61+
linux (vpe0) reads lx_buffer and writes rt_buffer
4262
SP (vpe1) reads rt_buffer and writes lx_buffer
4363
*/
4464
struct rtlx_channel {
@@ -55,11 +75,10 @@ struct rtlx_channel {
5575
char *lx_buffer;
5676
};
5777

58-
struct rtlx_info {
78+
extern struct rtlx_info {
5979
unsigned long id;
6080
enum rtlx_state state;
6181

6282
struct rtlx_channel channel[RTLX_CHANNELS];
63-
};
64-
83+
} *rtlx;
6584
#endif /* __ASM_RTLX_H_ */

‎arch/mips/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ obj-$(CONFIG_MIPS_VPE_LOADER) += vpe.o
5959
obj-$(CONFIG_MIPS_VPE_LOADER_CMP) += vpe-cmp.o
6060
obj-$(CONFIG_MIPS_VPE_LOADER_MT) += vpe-mt.o
6161
obj-$(CONFIG_MIPS_VPE_APSP_API) += rtlx.o
62+
obj-$(CONFIG_MIPS_VPE_APSP_API_MT) += rtlx-mt.o
6263

6364
obj-$(CONFIG_I8259) += i8259.o
6465
obj-$(CONFIG_IRQ_CPU) += irq_cpu.o

‎arch/mips/kernel/rtlx-mt.c‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* This file is subject to the terms and conditions of the GNU General Public
3+
* License. See the file "COPYING" in the main directory of this archive
4+
* for more details.
5+
*
6+
* Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
7+
* Copyright (C) 2013 Imagination Technologies Ltd.
8+
*/
9+
#include <linux/device.h>
10+
#include <linux/fs.h>
11+
#include <linux/err.h>
12+
#include <linux/wait.h>
13+
#include <linux/sched.h>
14+
#include <linux/interrupt.h>
15+
#include <linux/irq.h>
16+
17+
#include <asm/mips_mt.h>
18+
#include <asm/vpe.h>
19+
#include <asm/rtlx.h>
20+
21+
static int major;
22+
23+
static void rtlx_dispatch(void)
24+
{
25+
if (read_c0_cause() & read_c0_status() & C_SW0)
26+
do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
27+
}
28+
29+
/*
30+
* Interrupt handler may be called before rtlx_init has otherwise had
31+
* a chance to run.
32+
*/
33+
static irqreturn_t rtlx_interrupt(int irq, void *dev_id)
34+
{
35+
unsigned int vpeflags;
36+
unsigned long flags;
37+
int i;
38+
39+
/* Ought not to be strictly necessary for SMTC builds */
40+
local_irq_save(flags);
41+
vpeflags = dvpe();
42+
set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
43+
irq_enable_hazard();
44+
evpe(vpeflags);
45+
local_irq_restore(flags);
46+
47+
for (i = 0; i < RTLX_CHANNELS; i++) {
48+
wake_up(&channel_wqs[i].lx_queue);
49+
wake_up(&channel_wqs[i].rt_queue);
50+
}
51+
52+
return IRQ_HANDLED;
53+
}
54+
55+
static struct irqaction rtlx_irq = {
56+
.handler = rtlx_interrupt,
57+
.name = "RTLX",
58+
};
59+
60+
static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
61+
62+
void _interrupt_sp(void)
63+
{
64+
unsigned long flags;
65+
66+
local_irq_save(flags);
67+
dvpe();
68+
settc(1);
69+
write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0);
70+
evpe(EVPE_ENABLE);
71+
local_irq_restore(flags);
72+
}
73+
74+
int __init rtlx_module_init(void)
75+
{
76+
struct device *dev;
77+
int i, err;
78+
79+
if (!cpu_has_mipsmt) {
80+
pr_warn("VPE loader: not a MIPS MT capable processor\n");
81+
return -ENODEV;
82+
}
83+
84+
if (aprp_cpu_index() == 0) {
85+
pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
86+
"Pass maxtcs=<n> argument as kernel argument\n");
87+
88+
return -ENODEV;
89+
}
90+
91+
major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
92+
if (major < 0) {
93+
pr_err("rtlx_module_init: unable to register device\n");
94+
return major;
95+
}
96+
97+
/* initialise the wait queues */
98+
for (i = 0; i < RTLX_CHANNELS; i++) {
99+
init_waitqueue_head(&channel_wqs[i].rt_queue);
100+
init_waitqueue_head(&channel_wqs[i].lx_queue);
101+
atomic_set(&channel_wqs[i].in_open, 0);
102+
mutex_init(&channel_wqs[i].mutex);
103+
104+
dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
105+
"%s%d", RTLX_MODULE_NAME, i);
106+
if (IS_ERR(dev)) {
107+
err = PTR_ERR(dev);
108+
goto out_chrdev;
109+
}
110+
}
111+
112+
/* set up notifiers */
113+
rtlx_notify.start = rtlx_starting;
114+
rtlx_notify.stop = rtlx_stopping;
115+
vpe_notify(aprp_cpu_index(), &rtlx_notify);
116+
117+
if (cpu_has_vint) {
118+
aprp_hook = rtlx_dispatch;
119+
} else {
120+
pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
121+
err = -ENODEV;
122+
goto out_class;
123+
}
124+
125+
rtlx_irq.dev_id = rtlx;
126+
err = setup_irq(rtlx_irq_num, &rtlx_irq);
127+
if (err)
128+
goto out_class;
129+
130+
return 0;
131+
132+
out_class:
133+
for (i = 0; i < RTLX_CHANNELS; i++)
134+
device_destroy(mt_class, MKDEV(major, i));
135+
out_chrdev:
136+
unregister_chrdev(major, RTLX_MODULE_NAME);
137+
138+
return err;
139+
}
140+
141+
void __exit rtlx_module_exit(void)
142+
{
143+
int i;
144+
145+
for (i = 0; i < RTLX_CHANNELS; i++)
146+
device_destroy(mt_class, MKDEV(major, i));
147+
unregister_chrdev(major, RTLX_MODULE_NAME);
148+
}

0 commit comments

Comments
 (0)