1384740dcSRalf Baechle /* 25792bf64SSteven J. Hill * This file is subject to the terms and conditions of the GNU General Public 35792bf64SSteven J. Hill * License. See the file "COPYING" in the main directory of this archive 4384740dcSRalf Baechle * for more details. 5384740dcSRalf Baechle * 65792bf64SSteven J. Hill * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved. 75792bf64SSteven 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 char cwd[VPE_PATH_MAX]; 661a2a6d7eSDeng-Cheng Zhu 671a2a6d7eSDeng-Cheng Zhu unsigned long __start; 681a2a6d7eSDeng-Cheng Zhu 691a2a6d7eSDeng-Cheng Zhu /* tc's associated with this vpe */ 701a2a6d7eSDeng-Cheng Zhu struct list_head tc; 711a2a6d7eSDeng-Cheng Zhu 721a2a6d7eSDeng-Cheng Zhu /* The list of vpe's */ 731a2a6d7eSDeng-Cheng Zhu struct list_head list; 741a2a6d7eSDeng-Cheng Zhu 751a2a6d7eSDeng-Cheng Zhu /* shared symbol address */ 761a2a6d7eSDeng-Cheng Zhu void *shared_ptr; 771a2a6d7eSDeng-Cheng Zhu 781a2a6d7eSDeng-Cheng Zhu /* the list of who wants to know when something major happens */ 791a2a6d7eSDeng-Cheng Zhu struct list_head notify; 801a2a6d7eSDeng-Cheng Zhu 811a2a6d7eSDeng-Cheng Zhu unsigned int ntcs; 821a2a6d7eSDeng-Cheng Zhu }; 831a2a6d7eSDeng-Cheng Zhu 841a2a6d7eSDeng-Cheng Zhu struct tc { 851a2a6d7eSDeng-Cheng Zhu enum tc_state state; 861a2a6d7eSDeng-Cheng Zhu int index; 871a2a6d7eSDeng-Cheng Zhu 881a2a6d7eSDeng-Cheng Zhu struct vpe *pvpe; /* parent VPE */ 891a2a6d7eSDeng-Cheng Zhu struct list_head tc; /* The list of TC's with this VPE */ 901a2a6d7eSDeng-Cheng Zhu struct list_head list; /* The global list of tc's */ 911a2a6d7eSDeng-Cheng Zhu }; 921a2a6d7eSDeng-Cheng Zhu 93384740dcSRalf Baechle struct vpe_notifications { 94384740dcSRalf Baechle void (*start)(int vpe); 95384740dcSRalf Baechle void (*stop)(int vpe); 96384740dcSRalf Baechle 97384740dcSRalf Baechle struct list_head list; 98384740dcSRalf Baechle }; 99384740dcSRalf Baechle 1001a2a6d7eSDeng-Cheng Zhu struct vpe_control { 1011a2a6d7eSDeng-Cheng Zhu spinlock_t vpe_list_lock; 1021a2a6d7eSDeng-Cheng Zhu struct list_head vpe_list; /* Virtual processing elements */ 1031a2a6d7eSDeng-Cheng Zhu spinlock_t tc_list_lock; 1041a2a6d7eSDeng-Cheng Zhu struct list_head tc_list; /* Thread contexts */ 1051a2a6d7eSDeng-Cheng Zhu }; 106384740dcSRalf Baechle 1071a2a6d7eSDeng-Cheng Zhu extern unsigned long physical_memsize; 1081a2a6d7eSDeng-Cheng Zhu extern struct vpe_control vpecontrol; 1091a2a6d7eSDeng-Cheng Zhu extern const struct file_operations vpe_fops; 110384740dcSRalf Baechle 1111a2a6d7eSDeng-Cheng Zhu int vpe_notify(int index, struct vpe_notifications *notify); 112384740dcSRalf Baechle 1131a2a6d7eSDeng-Cheng Zhu void *vpe_get_shared(int index); 1141a2a6d7eSDeng-Cheng Zhu char *vpe_getcwd(int index); 1151a2a6d7eSDeng-Cheng Zhu 1161a2a6d7eSDeng-Cheng Zhu struct vpe *get_vpe(int minor); 1171a2a6d7eSDeng-Cheng Zhu struct tc *get_tc(int index); 1181a2a6d7eSDeng-Cheng Zhu struct vpe *alloc_vpe(int minor); 1191a2a6d7eSDeng-Cheng Zhu struct tc *alloc_tc(int index); 1201a2a6d7eSDeng-Cheng Zhu void release_vpe(struct vpe *v); 1211a2a6d7eSDeng-Cheng Zhu 1221a2a6d7eSDeng-Cheng Zhu void *alloc_progmem(unsigned long len); 1231a2a6d7eSDeng-Cheng Zhu void release_progmem(void *ptr); 1241a2a6d7eSDeng-Cheng Zhu 125*c60f9944SBjorn Helgaas int vpe_run(struct vpe *v); 1261a2a6d7eSDeng-Cheng Zhu void cleanup_tc(struct tc *tc); 1271a2a6d7eSDeng-Cheng Zhu 1281a2a6d7eSDeng-Cheng Zhu int __init vpe_module_init(void); 1291a2a6d7eSDeng-Cheng Zhu void __exit vpe_module_exit(void); 130384740dcSRalf Baechle #endif /* _ASM_VPE_H */ 131