/*
* Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
*
*/
/*
* VPE support module
*
* Provides support for loading a MIPS SP program on VPE1.
* The SP enviroment is rather simple, no tlb's. It needs to be relocatable
* (or partially linked). You should initialise your stack in the startup
* code. This loader looks for the symbol __start and sets up
* execution to resume from there. The MIPS SDE kit contains suitable examples.
*
* To load and run, simply cat a SP 'program file' to /dev/vpe1.
* i.e cat spapp >/dev/vpe1.
*
* You'll need to have the following device files.
* mknod /dev/vpe0 c 63 0
* mknod /dev/vpe1 c 63 1
*/
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/vmalloc.h>
#include <linux/elf.h>
#include <linux/seq_file.h>
#include <linux/syscalls.h>
#include <linux/moduleloader.h>
#include <linux/interrupt.h>
#include <linux/poll.h>
#include <linux/bootmem.h>
#include <asm/mipsregs.h>
#include <asm/mipsmtregs.h>
#include <asm/cacheflush.h>
#include <asm/atomic.h>
#include <asm/cpu.h>
#include <asm/processor.h>
#include <asm/system.h>
typedef void *vpe_handle;
#ifndef ARCH_SHF_SMALL
#define ARCH_SHF_SMALL 0
#endif
/* If this is set, the section belongs in the init part of the module */
#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
static char module_name[] = "vpe";
static int major;
/* grab the likely amount of memory we will need. */
#ifdef CONFIG_MIPS_VPE_LOADER_TOM
#define P_SIZE (2 * 1024 * 1024)
#else
/* add an overhead to the max kmalloc size for non-striped symbols/etc */
#define P_SIZE (256 * 1024)
#endif
#define MAX_VPES 16
enum vpe_state {
VPE_STATE_UNUSED = 0,
VPE_STATE_INUSE,
VPE_STATE_RUNNING
};
enum tc_state {
TC_STATE_UNUSED = 0,
TC_STATE_INUSE,
TC_STATE_RUNNING,
TC_STATE_DYNAMIC
};
struct vpe {
enum vpe_state state;
/* (device) minor associated with this vpe */
int minor;
/* elfloader stuff */
void *load_addr;
unsigned long len;
char *pbuffer;
unsigned long plen;
unsigned long __start;
/* tc's associated with this vpe */
struct list_head tc;
/* The list of vpe's */
struct list_head list;
/* shared symbol address */
void *shared_ptr;
};
struct tc {
enum tc_state state;
int index;
/* parent VPE */
struct vpe *pvpe;
/* The list of TC's with this VPE */
struct list_head tc;
/* The global list of tc's */
struct list_head list;
};
struct vpecontrol_ {
/* Virtual processing elements */
struct list_head vpe_list;
/* Thread contexts */
struct list_head tc_list;
} vpecontrol;
static void release_progmem(void *ptr);
static void dump_vpe(struct vpe * v);
extern void save_gp_address(unsigned int secbase, unsigned int rel);
/* get the vpe associated with this minor */
struct