1384740dcSRalf Baechle /* 2*5792bf64SSteven J. Hill * This file is subject to the terms and conditions of the GNU General Public 3*5792bf64SSteven J. Hill * License. See the file "COPYING" in the main directory of this archive 4384740dcSRalf Baechle * for more details. 5384740dcSRalf Baechle * 6*5792bf64SSteven J. Hill * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved. 7*5792bf64SSteven J. Hill * Copyright (C) 2013 Imagination Technologies Ltd. 8384740dcSRalf Baechle */ 9384740dcSRalf Baechle #ifndef _ASM_VPE_H 10384740dcSRalf Baechle #define _ASM_VPE_H 11384740dcSRalf Baechle 121a2a6d7eSDeng-Cheng Zhu #include <linux/init.h> 131a2a6d7eSDeng-Cheng Zhu #include <linux/list.h> 141a2a6d7eSDeng-Cheng Zhu #include <linux/smp.h> 151a2a6d7eSDeng-Cheng Zhu #include <linux/spinlock.h> 161a2a6d7eSDeng-Cheng Zhu 171a2a6d7eSDeng-Cheng Zhu #define VPE_MODULE_NAME "vpe" 181a2a6d7eSDeng-Cheng Zhu #define VPE_MODULE_MINOR 1 191a2a6d7eSDeng-Cheng Zhu 201a2a6d7eSDeng-Cheng Zhu /* grab the likely amount of memory we will need. */ 211a2a6d7eSDeng-Cheng Zhu #ifdef CONFIG_MIPS_VPE_LOADER_TOM 221a2a6d7eSDeng-Cheng Zhu #define P_SIZE (2 * 1024 * 1024) 231a2a6d7eSDeng-Cheng Zhu #else 241a2a6d7eSDeng-Cheng Zhu /* add an overhead to the max kmalloc size for non-striped symbols/etc */ 251a2a6d7eSDeng-Cheng Zhu #define P_SIZE (256 * 1024) 261a2a6d7eSDeng-Cheng Zhu #endif 271a2a6d7eSDeng-Cheng Zhu 281a2a6d7eSDeng-Cheng Zhu #define MAX_VPES 16 291a2a6d7eSDeng-Cheng Zhu #define VPE_PATH_MAX 256 301a2a6d7eSDeng-Cheng Zhu 311a2a6d7eSDeng-Cheng Zhu static inline int aprp_cpu_index(void) 321a2a6d7eSDeng-Cheng Zhu { 331a2a6d7eSDeng-Cheng Zhu #ifdef CONFIG_MIPS_CMP 341a2a6d7eSDeng-Cheng Zhu return setup_max_cpus; 351a2a6d7eSDeng-Cheng Zhu #else 361a2a6d7eSDeng-Cheng Zhu extern int tclimit; 371a2a6d7eSDeng-Cheng Zhu return tclimit; 381a2a6d7eSDeng-Cheng Zhu #endif 391a2a6d7eSDeng-Cheng Zhu } 401a2a6d7eSDeng-Cheng Zhu 411a2a6d7eSDeng-Cheng Zhu enum vpe_state { 421a2a6d7eSDeng-Cheng Zhu VPE_STATE_UNUSED = 0, 431a2a6d7eSDeng-Cheng Zhu VPE_STATE_INUSE, 441a2a6d7eSDeng-Cheng Zhu VPE_STATE_RUNNING 451a2a6d7eSDeng-Cheng Zhu }; 461a2a6d7eSDeng-Cheng Zhu 471a2a6d7eSDeng-Cheng Zhu enum tc_state { 481a2a6d7eSDeng-Cheng Zhu TC_STATE_UNUSED = 0, 491a2a6d7eSDeng-Cheng Zhu TC_STATE_INUSE, 501a2a6d7eSDeng-Cheng Zhu TC_STATE_RUNNING, 511a2a6d7eSDeng-Cheng Zhu TC_STATE_DYNAMIC 521a2a6d7eSDeng-Cheng Zhu }; 531a2a6d7eSDeng-Cheng Zhu 541a2a6d7eSDeng-Cheng Zhu struct vpe { 551a2a6d7eSDeng-Cheng Zhu enum vpe_state state; 561a2a6d7eSDeng-Cheng Zhu 571a2a6d7eSDeng-Cheng Zhu /* (device) minor associated with this vpe */ 581a2a6d7eSDeng-Cheng Zhu int minor; 591a2a6d7eSDeng-Cheng Zhu 601a2a6d7eSDeng-Cheng Zhu /* elfloader stuff */ 611a2a6d7eSDeng-Cheng Zhu void *load_addr; 621a2a6d7eSDeng-Cheng Zhu unsigned long len; 631a2a6d7eSDeng-Cheng Zhu char *pbuffer; 641a2a6d7eSDeng-Cheng Zhu unsigned long plen; 651a2a6d7eSDeng-Cheng Zhu unsigned int uid, gid; 661a2a6d7eSDeng-Cheng Zhu char cwd[VPE_PATH_MAX]; 671a2a6d7eSDeng-Cheng Zhu 681a2a6d7eSDeng-Cheng Zhu unsigned long __start; 691a2a6d7eSDeng-Cheng Zhu 701a2a6d7eSDeng-Cheng Zhu /* tc's associated with this vpe */ 711a2a6d7eSDeng-Cheng Zhu struct list_head tc; 721a2a6d7eSDeng-Cheng Zhu 731a2a6d7eSDeng-Cheng Zhu /* The list of vpe's */ 741a2a6d7eSDeng-Cheng Zhu struct list_head list; 751a2a6d7eSDeng-Cheng Zhu 761a2a6d7eSDeng-Cheng Zhu /* shared symbol address */ 771a2a6d7eSDeng-Cheng Zhu void *shared_ptr; 781a2a6d7eSDeng-Cheng Zhu 791a2a6d7eSDeng-Cheng Zhu /* the list of who wants to know when something major happens */ 801a2a6d7eSDeng-Cheng Zhu struct list_head notify; 811a2a6d7eSDeng-Cheng Zhu 821a2a6d7eSDeng-Cheng Zhu unsigned int ntcs; 831a2a6d7eSDeng-Cheng Zhu }; 841a2a6d7eSDeng-Cheng Zhu 851a2a6d7eSDeng-Cheng Zhu struct tc { 861a2a6d7eSDeng-Cheng Zhu enum tc_state state; 871a2a6d7eSDeng-Cheng Zhu int index; 881a2a6d7eSDeng-Cheng Zhu 891a2a6d7eSDeng-Cheng Zhu struct vpe *pvpe; /* parent VPE */ 901a2a6d7eSDeng-Cheng Zhu struct list_head tc; /* The list of TC's with this VPE */ 911a2a6d7eSDeng-Cheng Zhu struct list_head list; /* The global list of tc's */ 921a2a6d7eSDeng-Cheng Zhu }; 931a2a6d7eSDeng-Cheng Zhu 94384740dcSRalf Baechle struct vpe_notifications { 95384740dcSRalf Baechle void (*start)(int vpe); 96384740dcSRalf Baechle void (*stop)(int vpe); 97384740dcSRalf Baechle 98384740dcSRalf Baechle struct list_head list; 99384740dcSRalf Baechle }; 100384740dcSRalf Baechle 1011a2a6d7eSDeng-Cheng Zhu struct vpe_control { 1021a2a6d7eSDeng-Cheng Zhu spinlock_t vpe_list_lock; 1031a2a6d7eSDeng-Cheng Zhu struct list_head vpe_list; /* Virtual processing elements */ 1041a2a6d7eSDeng-Cheng Zhu spinlock_t tc_list_lock; 1051a2a6d7eSDeng-Cheng Zhu struct list_head tc_list; /* Thread contexts */ 1061a2a6d7eSDeng-Cheng Zhu }; 107384740dcSRalf Baechle 1081a2a6d7eSDeng-Cheng Zhu extern unsigned long physical_memsize; 1091a2a6d7eSDeng-Cheng Zhu extern struct vpe_control vpecontrol; 1101a2a6d7eSDeng-Cheng Zhu extern const struct file_operations vpe_fops; 111384740dcSRalf Baechle 1121a2a6d7eSDeng-Cheng Zhu int vpe_notify(int index, struct vpe_notifications *notify); 113384740dcSRalf Baechle 1141a2a6d7eSDeng-Cheng Zhu void *vpe_get_shared(int index); 1151a2a6d7eSDeng-Cheng Zhu int vpe_getuid(int index); 1161a2a6d7eSDeng-Cheng Zhu int vpe_getgid(int index); 1171a2a6d7eSDeng-Cheng Zhu char *vpe_getcwd(int index); 1181a2a6d7eSDeng-Cheng Zhu 1191a2a6d7eSDeng-Cheng Zhu struct vpe *get_vpe(int minor); 1201a2a6d7eSDeng-Cheng Zhu struct tc *get_tc(int index); 1211a2a6d7eSDeng-Cheng Zhu struct vpe *alloc_vpe(int minor); 1221a2a6d7eSDeng-Cheng Zhu struct tc *alloc_tc(int index); 1231a2a6d7eSDeng-Cheng Zhu void release_vpe(struct vpe *v); 1241a2a6d7eSDeng-Cheng Zhu 1251a2a6d7eSDeng-Cheng Zhu void *alloc_progmem(unsigned long len); 1261a2a6d7eSDeng-Cheng Zhu void release_progmem(void *ptr); 1271a2a6d7eSDeng-Cheng Zhu 1281a2a6d7eSDeng-Cheng Zhu int __weak vpe_run(struct vpe *v); 1291a2a6d7eSDeng-Cheng Zhu void cleanup_tc(struct tc *tc); 1301a2a6d7eSDeng-Cheng Zhu 1311a2a6d7eSDeng-Cheng Zhu int __init vpe_module_init(void); 1321a2a6d7eSDeng-Cheng Zhu void __exit vpe_module_exit(void); 133384740dcSRalf Baechle #endif /* _ASM_VPE_H */ 134