18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved. 78c2ecf20Sopenharmony_ci * Copyright (C) 2013 Imagination Technologies Ltd. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef _ASM_VPE_H 108c2ecf20Sopenharmony_ci#define _ASM_VPE_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/init.h> 138c2ecf20Sopenharmony_ci#include <linux/list.h> 148c2ecf20Sopenharmony_ci#include <linux/smp.h> 158c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define VPE_MODULE_NAME "vpe" 188c2ecf20Sopenharmony_ci#define VPE_MODULE_MINOR 1 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* grab the likely amount of memory we will need. */ 218c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_VPE_LOADER_TOM 228c2ecf20Sopenharmony_ci#define P_SIZE (2 * 1024 * 1024) 238c2ecf20Sopenharmony_ci#else 248c2ecf20Sopenharmony_ci/* add an overhead to the max kmalloc size for non-striped symbols/etc */ 258c2ecf20Sopenharmony_ci#define P_SIZE (256 * 1024) 268c2ecf20Sopenharmony_ci#endif 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define MAX_VPES 16 298c2ecf20Sopenharmony_ci#define VPE_PATH_MAX 256 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline int aprp_cpu_index(void) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_CMP 348c2ecf20Sopenharmony_ci return setup_max_cpus; 358c2ecf20Sopenharmony_ci#else 368c2ecf20Sopenharmony_ci extern int tclimit; 378c2ecf20Sopenharmony_ci return tclimit; 388c2ecf20Sopenharmony_ci#endif 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cienum vpe_state { 428c2ecf20Sopenharmony_ci VPE_STATE_UNUSED = 0, 438c2ecf20Sopenharmony_ci VPE_STATE_INUSE, 448c2ecf20Sopenharmony_ci VPE_STATE_RUNNING 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cienum tc_state { 488c2ecf20Sopenharmony_ci TC_STATE_UNUSED = 0, 498c2ecf20Sopenharmony_ci TC_STATE_INUSE, 508c2ecf20Sopenharmony_ci TC_STATE_RUNNING, 518c2ecf20Sopenharmony_ci TC_STATE_DYNAMIC 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct vpe { 558c2ecf20Sopenharmony_ci enum vpe_state state; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /* (device) minor associated with this vpe */ 588c2ecf20Sopenharmony_ci int minor; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* elfloader stuff */ 618c2ecf20Sopenharmony_ci void *load_addr; 628c2ecf20Sopenharmony_ci unsigned long len; 638c2ecf20Sopenharmony_ci char *pbuffer; 648c2ecf20Sopenharmony_ci unsigned long plen; 658c2ecf20Sopenharmony_ci char cwd[VPE_PATH_MAX]; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci unsigned long __start; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci /* tc's associated with this vpe */ 708c2ecf20Sopenharmony_ci struct list_head tc; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* The list of vpe's */ 738c2ecf20Sopenharmony_ci struct list_head list; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci /* shared symbol address */ 768c2ecf20Sopenharmony_ci void *shared_ptr; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci /* the list of who wants to know when something major happens */ 798c2ecf20Sopenharmony_ci struct list_head notify; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci unsigned int ntcs; 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistruct tc { 858c2ecf20Sopenharmony_ci enum tc_state state; 868c2ecf20Sopenharmony_ci int index; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci struct vpe *pvpe; /* parent VPE */ 898c2ecf20Sopenharmony_ci struct list_head tc; /* The list of TC's with this VPE */ 908c2ecf20Sopenharmony_ci struct list_head list; /* The global list of tc's */ 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct vpe_notifications { 948c2ecf20Sopenharmony_ci void (*start)(int vpe); 958c2ecf20Sopenharmony_ci void (*stop)(int vpe); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci struct list_head list; 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct vpe_control { 1018c2ecf20Sopenharmony_ci spinlock_t vpe_list_lock; 1028c2ecf20Sopenharmony_ci struct list_head vpe_list; /* Virtual processing elements */ 1038c2ecf20Sopenharmony_ci spinlock_t tc_list_lock; 1048c2ecf20Sopenharmony_ci struct list_head tc_list; /* Thread contexts */ 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciextern struct vpe_control vpecontrol; 1088c2ecf20Sopenharmony_ciextern const struct file_operations vpe_fops; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciint vpe_notify(int index, struct vpe_notifications *notify); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_civoid *vpe_get_shared(int index); 1138c2ecf20Sopenharmony_cichar *vpe_getcwd(int index); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct vpe *get_vpe(int minor); 1168c2ecf20Sopenharmony_cistruct tc *get_tc(int index); 1178c2ecf20Sopenharmony_cistruct vpe *alloc_vpe(int minor); 1188c2ecf20Sopenharmony_cistruct tc *alloc_tc(int index); 1198c2ecf20Sopenharmony_civoid release_vpe(struct vpe *v); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_civoid *alloc_progmem(unsigned long len); 1228c2ecf20Sopenharmony_civoid release_progmem(void *ptr); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ciint vpe_run(struct vpe *v); 1258c2ecf20Sopenharmony_civoid cleanup_tc(struct tc *tc); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciint __init vpe_module_init(void); 1288c2ecf20Sopenharmony_civoid __exit vpe_module_exit(void); 1298c2ecf20Sopenharmony_ci#endif /* _ASM_VPE_H */ 130