xref: /openbmc/linux/arch/mips/include/asm/vpe.h (revision 1a2a6d7e8816ed2b2679a0c4f7ba4019cd31dd62)
1384740dcSRalf Baechle /*
2384740dcSRalf Baechle  * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved.
3*1a2a6d7eSDeng-Cheng Zhu  * Copyright (C) 2013 Imagination Technologies Ltd.
4384740dcSRalf Baechle  *
5384740dcSRalf Baechle  *  This program is free software; you can distribute it and/or modify it
6384740dcSRalf Baechle  *  under the terms of the GNU General Public License (Version 2) as
7384740dcSRalf Baechle  *  published by the Free Software Foundation.
8384740dcSRalf Baechle  *
9384740dcSRalf Baechle  *  This program is distributed in the hope it will be useful, but WITHOUT
10384740dcSRalf Baechle  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11384740dcSRalf Baechle  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12384740dcSRalf Baechle  *  for more details.
13384740dcSRalf Baechle  *
14384740dcSRalf Baechle  *  You should have received a copy of the GNU General Public License along
15384740dcSRalf Baechle  *  with this program; if not, write to the Free Software Foundation, Inc.,
16384740dcSRalf Baechle  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17384740dcSRalf Baechle  *
18384740dcSRalf Baechle  */
19384740dcSRalf Baechle 
20384740dcSRalf Baechle #ifndef _ASM_VPE_H
21384740dcSRalf Baechle #define _ASM_VPE_H
22384740dcSRalf Baechle 
23*1a2a6d7eSDeng-Cheng Zhu #include <linux/init.h>
24*1a2a6d7eSDeng-Cheng Zhu #include <linux/list.h>
25*1a2a6d7eSDeng-Cheng Zhu #include <linux/smp.h>
26*1a2a6d7eSDeng-Cheng Zhu #include <linux/spinlock.h>
27*1a2a6d7eSDeng-Cheng Zhu 
28*1a2a6d7eSDeng-Cheng Zhu #define VPE_MODULE_NAME "vpe"
29*1a2a6d7eSDeng-Cheng Zhu #define VPE_MODULE_MINOR 1
30*1a2a6d7eSDeng-Cheng Zhu 
31*1a2a6d7eSDeng-Cheng Zhu /* grab the likely amount of memory we will need. */
32*1a2a6d7eSDeng-Cheng Zhu #ifdef CONFIG_MIPS_VPE_LOADER_TOM
33*1a2a6d7eSDeng-Cheng Zhu #define P_SIZE (2 * 1024 * 1024)
34*1a2a6d7eSDeng-Cheng Zhu #else
35*1a2a6d7eSDeng-Cheng Zhu /* add an overhead to the max kmalloc size for non-striped symbols/etc */
36*1a2a6d7eSDeng-Cheng Zhu #define P_SIZE (256 * 1024)
37*1a2a6d7eSDeng-Cheng Zhu #endif
38*1a2a6d7eSDeng-Cheng Zhu 
39*1a2a6d7eSDeng-Cheng Zhu #define MAX_VPES 16
40*1a2a6d7eSDeng-Cheng Zhu #define VPE_PATH_MAX 256
41*1a2a6d7eSDeng-Cheng Zhu 
42*1a2a6d7eSDeng-Cheng Zhu static inline int aprp_cpu_index(void)
43*1a2a6d7eSDeng-Cheng Zhu {
44*1a2a6d7eSDeng-Cheng Zhu #ifdef CONFIG_MIPS_CMP
45*1a2a6d7eSDeng-Cheng Zhu 	return setup_max_cpus;
46*1a2a6d7eSDeng-Cheng Zhu #else
47*1a2a6d7eSDeng-Cheng Zhu 	extern int tclimit;
48*1a2a6d7eSDeng-Cheng Zhu 	return tclimit;
49*1a2a6d7eSDeng-Cheng Zhu #endif
50*1a2a6d7eSDeng-Cheng Zhu }
51*1a2a6d7eSDeng-Cheng Zhu 
52*1a2a6d7eSDeng-Cheng Zhu enum vpe_state {
53*1a2a6d7eSDeng-Cheng Zhu 	VPE_STATE_UNUSED = 0,
54*1a2a6d7eSDeng-Cheng Zhu 	VPE_STATE_INUSE,
55*1a2a6d7eSDeng-Cheng Zhu 	VPE_STATE_RUNNING
56*1a2a6d7eSDeng-Cheng Zhu };
57*1a2a6d7eSDeng-Cheng Zhu 
58*1a2a6d7eSDeng-Cheng Zhu enum tc_state {
59*1a2a6d7eSDeng-Cheng Zhu 	TC_STATE_UNUSED = 0,
60*1a2a6d7eSDeng-Cheng Zhu 	TC_STATE_INUSE,
61*1a2a6d7eSDeng-Cheng Zhu 	TC_STATE_RUNNING,
62*1a2a6d7eSDeng-Cheng Zhu 	TC_STATE_DYNAMIC
63*1a2a6d7eSDeng-Cheng Zhu };
64*1a2a6d7eSDeng-Cheng Zhu 
65*1a2a6d7eSDeng-Cheng Zhu struct vpe {
66*1a2a6d7eSDeng-Cheng Zhu 	enum vpe_state state;
67*1a2a6d7eSDeng-Cheng Zhu 
68*1a2a6d7eSDeng-Cheng Zhu 	/* (device) minor associated with this vpe */
69*1a2a6d7eSDeng-Cheng Zhu 	int minor;
70*1a2a6d7eSDeng-Cheng Zhu 
71*1a2a6d7eSDeng-Cheng Zhu 	/* elfloader stuff */
72*1a2a6d7eSDeng-Cheng Zhu 	void *load_addr;
73*1a2a6d7eSDeng-Cheng Zhu 	unsigned long len;
74*1a2a6d7eSDeng-Cheng Zhu 	char *pbuffer;
75*1a2a6d7eSDeng-Cheng Zhu 	unsigned long plen;
76*1a2a6d7eSDeng-Cheng Zhu 	unsigned int uid, gid;
77*1a2a6d7eSDeng-Cheng Zhu 	char cwd[VPE_PATH_MAX];
78*1a2a6d7eSDeng-Cheng Zhu 
79*1a2a6d7eSDeng-Cheng Zhu 	unsigned long __start;
80*1a2a6d7eSDeng-Cheng Zhu 
81*1a2a6d7eSDeng-Cheng Zhu 	/* tc's associated with this vpe */
82*1a2a6d7eSDeng-Cheng Zhu 	struct list_head tc;
83*1a2a6d7eSDeng-Cheng Zhu 
84*1a2a6d7eSDeng-Cheng Zhu 	/* The list of vpe's */
85*1a2a6d7eSDeng-Cheng Zhu 	struct list_head list;
86*1a2a6d7eSDeng-Cheng Zhu 
87*1a2a6d7eSDeng-Cheng Zhu 	/* shared symbol address */
88*1a2a6d7eSDeng-Cheng Zhu 	void *shared_ptr;
89*1a2a6d7eSDeng-Cheng Zhu 
90*1a2a6d7eSDeng-Cheng Zhu 	/* the list of who wants to know when something major happens */
91*1a2a6d7eSDeng-Cheng Zhu 	struct list_head notify;
92*1a2a6d7eSDeng-Cheng Zhu 
93*1a2a6d7eSDeng-Cheng Zhu 	unsigned int ntcs;
94*1a2a6d7eSDeng-Cheng Zhu };
95*1a2a6d7eSDeng-Cheng Zhu 
96*1a2a6d7eSDeng-Cheng Zhu struct tc {
97*1a2a6d7eSDeng-Cheng Zhu 	enum tc_state state;
98*1a2a6d7eSDeng-Cheng Zhu 	int index;
99*1a2a6d7eSDeng-Cheng Zhu 
100*1a2a6d7eSDeng-Cheng Zhu 	struct vpe *pvpe;	/* parent VPE */
101*1a2a6d7eSDeng-Cheng Zhu 	struct list_head tc;	/* The list of TC's with this VPE */
102*1a2a6d7eSDeng-Cheng Zhu 	struct list_head list;	/* The global list of tc's */
103*1a2a6d7eSDeng-Cheng Zhu };
104*1a2a6d7eSDeng-Cheng Zhu 
105384740dcSRalf Baechle struct vpe_notifications {
106384740dcSRalf Baechle 	void (*start)(int vpe);
107384740dcSRalf Baechle 	void (*stop)(int vpe);
108384740dcSRalf Baechle 
109384740dcSRalf Baechle 	struct list_head list;
110384740dcSRalf Baechle };
111384740dcSRalf Baechle 
112*1a2a6d7eSDeng-Cheng Zhu struct vpe_control {
113*1a2a6d7eSDeng-Cheng Zhu 	spinlock_t vpe_list_lock;
114*1a2a6d7eSDeng-Cheng Zhu 	struct list_head vpe_list;      /* Virtual processing elements */
115*1a2a6d7eSDeng-Cheng Zhu 	spinlock_t tc_list_lock;
116*1a2a6d7eSDeng-Cheng Zhu 	struct list_head tc_list;       /* Thread contexts */
117*1a2a6d7eSDeng-Cheng Zhu };
118384740dcSRalf Baechle 
119*1a2a6d7eSDeng-Cheng Zhu extern unsigned long physical_memsize;
120*1a2a6d7eSDeng-Cheng Zhu extern struct vpe_control vpecontrol;
121*1a2a6d7eSDeng-Cheng Zhu extern const struct file_operations vpe_fops;
122384740dcSRalf Baechle 
123*1a2a6d7eSDeng-Cheng Zhu int vpe_notify(int index, struct vpe_notifications *notify);
124384740dcSRalf Baechle 
125*1a2a6d7eSDeng-Cheng Zhu void *vpe_get_shared(int index);
126*1a2a6d7eSDeng-Cheng Zhu int vpe_getuid(int index);
127*1a2a6d7eSDeng-Cheng Zhu int vpe_getgid(int index);
128*1a2a6d7eSDeng-Cheng Zhu char *vpe_getcwd(int index);
129*1a2a6d7eSDeng-Cheng Zhu 
130*1a2a6d7eSDeng-Cheng Zhu struct vpe *get_vpe(int minor);
131*1a2a6d7eSDeng-Cheng Zhu struct tc *get_tc(int index);
132*1a2a6d7eSDeng-Cheng Zhu struct vpe *alloc_vpe(int minor);
133*1a2a6d7eSDeng-Cheng Zhu struct tc *alloc_tc(int index);
134*1a2a6d7eSDeng-Cheng Zhu void release_vpe(struct vpe *v);
135*1a2a6d7eSDeng-Cheng Zhu 
136*1a2a6d7eSDeng-Cheng Zhu void *alloc_progmem(unsigned long len);
137*1a2a6d7eSDeng-Cheng Zhu void release_progmem(void *ptr);
138*1a2a6d7eSDeng-Cheng Zhu 
139*1a2a6d7eSDeng-Cheng Zhu int __weak vpe_run(struct vpe *v);
140*1a2a6d7eSDeng-Cheng Zhu void cleanup_tc(struct tc *tc);
141*1a2a6d7eSDeng-Cheng Zhu 
142*1a2a6d7eSDeng-Cheng Zhu int __init vpe_module_init(void);
143*1a2a6d7eSDeng-Cheng Zhu void __exit vpe_module_exit(void);
144384740dcSRalf Baechle #endif /* _ASM_VPE_H */
145