2 * Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
4 * This program is free software; you can distribute it and/or modify it
5 * under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 * Provides support for loading a MIPS SP program on VPE1.
22 * The SP environment is rather simple, no tlb's. It needs to be relocatable
23 * (or partially linked). You should initialise your stack in the startup
24 * code. This loader looks for the symbol __start and sets up
25 * execution to resume from there. The MIPS SDE kit contains suitable examples.
27 * To load and run, simply cat a SP 'program file' to /dev/vpe1.
28 * i.e cat spapp >/dev/vpe1.
30 #include <linux/kernel.h>
31 #include <linux/device.h>
33 #include <linux/init.h>
34 #include <asm/uaccess.h>
35 #include <linux/slab.h>
36 #include <linux/list.h>
37 #include <linux/vmalloc.h>
38 #include <linux/elf.h>
39 #include <linux/seq_file.h>
40 #include <linux/syscalls.h>
41 #include <linux/moduleloader.h>
42 #include <linux/interrupt.h>
43 #include <linux/poll.h>
44 #include <linux/bootmem.h>
45 #include <asm/mipsregs.h>
46 #include <asm/mipsmtregs.h>
47 #include <asm/cacheflush.h>
48 #include <linux/atomic.h>
50 #include <asm/mips_mt.h>
51 #include <asm/processor.h>
54 #ifndef ARCH_SHF_SMALL
55 #define ARCH_SHF_SMALL 0
58 /* If this is set, the section belongs in the init part of the module */
59 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
61 struct vpe_control vpecontrol
= {
62 .vpe_list_lock
= __SPIN_LOCK_UNLOCKED(vpe_list_lock
),
63 .vpe_list
= LIST_HEAD_INIT(vpecontrol
.vpe_list
),
64 .tc_list_lock
= __SPIN_LOCK_UNLOCKED(tc_list_lock
),
65 .tc_list
= LIST_HEAD_INIT(vpecontrol
.tc_list
)
68 /* get the vpe associated with this minor */
69 struct vpe
*get_vpe(int minor
)
77 spin_lock(&vpecontrol
.vpe_list_lock
);
78 list_for_each_entry(v
, &vpecontrol
.vpe_list
, list
) {
79 if (v
->minor
== VPE_MODULE_MINOR
) {
84 spin_unlock(&vpecontrol
.vpe_list_lock
);
89 /* get the vpe associated with this minor */
90 struct tc
*get_tc(int index
)
95 spin_lock(&vpecontrol
.tc_list_lock
);
96 list_for_each_entry(t
, &vpecontrol
.tc_list
, list
) {
97 if (t
->index
== index
) {
102 spin_unlock(&vpecontrol
.tc_list_lock
);
107 /* allocate a vpe and associate it with this minor (or index) */
108 struct vpe
*alloc_vpe(int minor
)
112 if ((v
= kzalloc(sizeof(struct vpe
), GFP_KERNEL
)) == NULL
)
115 INIT_LIST_HEAD(&v
->tc
);
116 spin_lock(&vpecontrol
.vpe_list_lock
);
117 list_add_tail(&v
->list
, &vpecontrol
.vpe_list
);
118 spin_unlock(&vpecontrol
.vpe_list_lock
);
120 INIT_LIST_HEAD(&v
->notify
);
121 v
->minor
= VPE_MODULE_MINOR
;
126 /* allocate a tc. At startup only tc0 is running, all other can be halted. */
127 struct tc
*alloc_tc(int index
)
131 if ((tc
= kzalloc(sizeof(struct tc
), GFP_KERNEL
)) == NULL
)
134 INIT_LIST_HEAD(&tc
->tc
);
137 spin_lock(&vpecontrol
.tc_list_lock
);
138 list_add_tail(&tc
->list
, &vpecontrol
.tc_list
);
139 spin_unlock(&vpecontrol
.tc_list_lock
);
145 /* clean up and free everything */
146 void release_vpe(struct vpe
*v
)
154 /* Find some VPE program space */
155 void *alloc_progmem(unsigned long len
)
159 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
161 * This means you must tell Linux to use less memory than you
162 * physically have, for example by passing a mem= boot argument.
164 addr
= pfn_to_kaddr(max_low_pfn
);
165 memset(addr
, 0, len
);
167 /* simple grab some mem for now */
168 addr
= kzalloc(len
, GFP_KERNEL
);
174 void release_progmem(void *ptr
)
176 #ifndef CONFIG_MIPS_VPE_LOADER_TOM
181 /* Update size with this section: return offset. */
182 static long get_offset(unsigned long *size
, Elf_Shdr
* sechdr
)
186 ret
= ALIGN(*size
, sechdr
->sh_addralign
? : 1);
187 *size
= ret
+ sechdr
->sh_size
;
191 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
192 might -- code, read-only data, read-write data, small data. Tally
193 sizes, and place the offsets into sh_entsize fields: high bit means it
195 static void layout_sections(struct module
*mod
, const Elf_Ehdr
* hdr
,
196 Elf_Shdr
* sechdrs
, const char *secstrings
)
198 static unsigned long const masks
[][2] = {
199 /* NOTE: all executable code must be the first section
200 * in this array; otherwise modify the text_size
201 * finder in the two loops below */
202 {SHF_EXECINSTR
| SHF_ALLOC
, ARCH_SHF_SMALL
},
203 {SHF_ALLOC
, SHF_WRITE
| ARCH_SHF_SMALL
},
204 {SHF_WRITE
| SHF_ALLOC
, ARCH_SHF_SMALL
},
205 {ARCH_SHF_SMALL
| SHF_ALLOC
, 0}
209 for (i
= 0; i
< hdr
->e_shnum
; i
++)
210 sechdrs
[i
].sh_entsize
= ~0UL;
212 for (m
= 0; m
< ARRAY_SIZE(masks
); ++m
) {
213 for (i
= 0; i
< hdr
->e_shnum
; ++i
) {
214 Elf_Shdr
*s
= &sechdrs
[i
];
216 // || strncmp(secstrings + s->sh_name, ".init", 5) == 0)
217 if ((s
->sh_flags
& masks
[m
][0]) != masks
[m
][0]
218 || (s
->sh_flags
& masks
[m
][1])
219 || s
->sh_entsize
!= ~0UL)
222 get_offset((unsigned long *)&mod
->core_size
, s
);
226 mod
->core_text_size
= mod
->core_size
;
232 /* from module-elf32.c, but subverted a little */
235 struct mips_hi16
*next
;
240 static struct mips_hi16
*mips_hi16_list
;
241 static unsigned int gp_offs
, gp_addr
;
243 static int apply_r_mips_none(struct module
*me
, uint32_t *location
,
249 static int apply_r_mips_gprel16(struct module
*me
, uint32_t *location
,
254 if( !(*location
& 0xffff) ) {
255 rel
= (int)v
- gp_addr
;
258 /* .sbss + gp(relative) + offset */
260 rel
= (int)(short)((int)v
+ gp_offs
+
261 (int)(short)(*location
& 0xffff) - gp_addr
);
264 if( (rel
> 32768) || (rel
< -32768) ) {
265 printk(KERN_DEBUG
"VPE loader: apply_r_mips_gprel16: "
266 "relative address 0x%x out of range of gp register\n",
271 *location
= (*location
& 0xffff0000) | (rel
& 0xffff);
276 static int apply_r_mips_pc16(struct module
*me
, uint32_t *location
,
280 rel
= (((unsigned int)v
- (unsigned int)location
));
281 rel
>>= 2; // because the offset is in _instructions_ not bytes.
282 rel
-= 1; // and one instruction less due to the branch delay slot.
284 if( (rel
> 32768) || (rel
< -32768) ) {
285 printk(KERN_DEBUG
"VPE loader: "
286 "apply_r_mips_pc16: relative address out of range 0x%x\n", rel
);
290 *location
= (*location
& 0xffff0000) | (rel
& 0xffff);
295 static int apply_r_mips_32(struct module
*me
, uint32_t *location
,
303 static int apply_r_mips_26(struct module
*me
, uint32_t *location
,
307 printk(KERN_DEBUG
"VPE loader: apply_r_mips_26 "
308 " unaligned relocation\n");
313 * Not desperately convinced this is a good check of an overflow condition
314 * anyway. But it gets in the way of handling undefined weak symbols which
315 * we want to set to zero.
316 * if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
318 * "module %s: relocation overflow\n",
324 *location
= (*location
& ~0x03ffffff) |
325 ((*location
+ (v
>> 2)) & 0x03ffffff);
329 static int apply_r_mips_hi16(struct module
*me
, uint32_t *location
,
335 * We cannot relocate this one now because we don't know the value of
336 * the carry we need to add. Save the information, and let LO16 do the
339 n
= kmalloc(sizeof *n
, GFP_KERNEL
);
345 n
->next
= mips_hi16_list
;
351 static int apply_r_mips_lo16(struct module
*me
, uint32_t *location
,
354 unsigned long insnlo
= *location
;
355 Elf32_Addr val
, vallo
;
356 struct mips_hi16
*l
, *next
;
358 /* Sign extend the addend we extract from the lo insn. */
359 vallo
= ((insnlo
& 0xffff) ^ 0x8000) - 0x8000;
361 if (mips_hi16_list
!= NULL
) {
368 * The value for the HI16 had best be the same.
371 printk(KERN_DEBUG
"VPE loader: "
372 "apply_r_mips_lo16/hi16: \t"
373 "inconsistent value information\n");
378 * Do the HI16 relocation. Note that we actually don't
379 * need to know anything about the LO16 itself, except
380 * where to find the low 16 bits of the addend needed
384 val
= ((insn
& 0xffff) << 16) + vallo
;
388 * Account for the sign extension that will happen in
391 val
= ((val
>> 16) + ((val
& 0x8000) != 0)) & 0xffff;
393 insn
= (insn
& ~0xffff) | val
;
401 mips_hi16_list
= NULL
;
405 * Ok, we're done with the HI16 relocs. Now deal with the LO16.
408 insnlo
= (insnlo
& ~0xffff) | (val
& 0xffff);
419 mips_hi16_list
= NULL
;
424 static int (*reloc_handlers
[]) (struct module
*me
, uint32_t *location
,
426 [R_MIPS_NONE
] = apply_r_mips_none
,
427 [R_MIPS_32
] = apply_r_mips_32
,
428 [R_MIPS_26
] = apply_r_mips_26
,
429 [R_MIPS_HI16
] = apply_r_mips_hi16
,
430 [R_MIPS_LO16
] = apply_r_mips_lo16
,
431 [R_MIPS_GPREL16
] = apply_r_mips_gprel16
,
432 [R_MIPS_PC16
] = apply_r_mips_pc16
435 static char *rstrs
[] = {
436 [R_MIPS_NONE
] = "MIPS_NONE",
437 [R_MIPS_32
] = "MIPS_32",
438 [R_MIPS_26
] = "MIPS_26",
439 [R_MIPS_HI16
] = "MIPS_HI16",
440 [R_MIPS_LO16
] = "MIPS_LO16",
441 [R_MIPS_GPREL16
] = "MIPS_GPREL16",
442 [R_MIPS_PC16
] = "MIPS_PC16"
445 static int apply_relocations(Elf32_Shdr
*sechdrs
,
447 unsigned int symindex
,
451 Elf32_Rel
*rel
= (void *) sechdrs
[relsec
].sh_addr
;
458 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
459 Elf32_Word r_info
= rel
[i
].r_info
;
461 /* This is where to make the change */
462 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
464 /* This is the symbol it is referring to */
465 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
466 + ELF32_R_SYM(r_info
);
468 if (!sym
->st_value
) {
469 printk(KERN_DEBUG
"%s: undefined weak symbol %s\n",
470 me
->name
, strtab
+ sym
->st_name
);
471 /* just print the warning, dont barf */
476 res
= reloc_handlers
[ELF32_R_TYPE(r_info
)](me
, location
, v
);
478 char *r
= rstrs
[ELF32_R_TYPE(r_info
)];
479 printk(KERN_WARNING
"VPE loader: .text+0x%x "
480 "relocation type %s for symbol \"%s\" failed\n",
481 rel
[i
].r_offset
, r
? r
: "UNKNOWN",
482 strtab
+ sym
->st_name
);
490 static inline void save_gp_address(unsigned int secbase
, unsigned int rel
)
492 gp_addr
= secbase
+ rel
;
493 gp_offs
= gp_addr
- (secbase
& 0xffff0000);
495 /* end module-elf32.c */
499 /* Change all symbols so that sh_value encodes the pointer directly. */
500 static void simplify_symbols(Elf_Shdr
* sechdrs
,
501 unsigned int symindex
,
503 const char *secstrings
,
504 unsigned int nsecs
, struct module
*mod
)
506 Elf_Sym
*sym
= (void *)sechdrs
[symindex
].sh_addr
;
507 unsigned long secbase
, bssbase
= 0;
508 unsigned int i
, n
= sechdrs
[symindex
].sh_size
/ sizeof(Elf_Sym
);
511 /* find the .bss section for COMMON symbols */
512 for (i
= 0; i
< nsecs
; i
++) {
513 if (strncmp(secstrings
+ sechdrs
[i
].sh_name
, ".bss", 4) == 0) {
514 bssbase
= sechdrs
[i
].sh_addr
;
519 for (i
= 1; i
< n
; i
++) {
520 switch (sym
[i
].st_shndx
) {
522 /* Allocate space for the symbol in the .bss section.
523 st_value is currently size.
524 We want it to have the address of the symbol. */
526 size
= sym
[i
].st_value
;
527 sym
[i
].st_value
= bssbase
;
533 /* Don't need to do anything */
540 case SHN_MIPS_SCOMMON
:
541 printk(KERN_DEBUG
"simplify_symbols: ignoring SHN_MIPS_SCOMMON "
542 "symbol <%s> st_shndx %d\n", strtab
+ sym
[i
].st_name
,
548 secbase
= sechdrs
[sym
[i
].st_shndx
].sh_addr
;
550 if (strncmp(strtab
+ sym
[i
].st_name
, "_gp", 3) == 0) {
551 save_gp_address(secbase
, sym
[i
].st_value
);
554 sym
[i
].st_value
+= secbase
;
560 #ifdef DEBUG_ELFLOADER
561 static void dump_elfsymbols(Elf_Shdr
* sechdrs
, unsigned int symindex
,
562 const char *strtab
, struct module
*mod
)
564 Elf_Sym
*sym
= (void *)sechdrs
[symindex
].sh_addr
;
565 unsigned int i
, n
= sechdrs
[symindex
].sh_size
/ sizeof(Elf_Sym
);
567 printk(KERN_DEBUG
"dump_elfsymbols: n %d\n", n
);
568 for (i
= 1; i
< n
; i
++) {
569 printk(KERN_DEBUG
" i %d name <%s> 0x%x\n", i
,
570 strtab
+ sym
[i
].st_name
, sym
[i
].st_value
);
575 static int find_vpe_symbols(struct vpe
* v
, Elf_Shdr
* sechdrs
,
576 unsigned int symindex
, const char *strtab
,
579 Elf_Sym
*sym
= (void *)sechdrs
[symindex
].sh_addr
;
580 unsigned int i
, n
= sechdrs
[symindex
].sh_size
/ sizeof(Elf_Sym
);
582 for (i
= 1; i
< n
; i
++) {
583 if (strcmp(strtab
+ sym
[i
].st_name
, "__start") == 0) {
584 v
->__start
= sym
[i
].st_value
;
587 if (strcmp(strtab
+ sym
[i
].st_name
, "vpe_shared") == 0) {
588 v
->shared_ptr
= (void *)sym
[i
].st_value
;
592 if ( (v
->__start
== 0) || (v
->shared_ptr
== NULL
))
599 * Allocates a VPE with some program code space(the load address), copies the
600 * contents of the program (p)buffer performing relocatations/etc, free's it
603 static int vpe_elfload(struct vpe
* v
)
608 char *secstrings
, *strtab
= NULL
;
609 unsigned int len
, i
, symindex
= 0, strindex
= 0, relocate
= 0;
610 struct module mod
; // so we can re-use the relocations code
612 memset(&mod
, 0, sizeof(struct module
));
613 strcpy(mod
.name
, "VPE loader");
615 hdr
= (Elf_Ehdr
*) v
->pbuffer
;
618 /* Sanity checks against insmoding binaries or wrong arch,
620 if (memcmp(hdr
->e_ident
, ELFMAG
, SELFMAG
) != 0
621 || (hdr
->e_type
!= ET_REL
&& hdr
->e_type
!= ET_EXEC
)
622 || !elf_check_arch(hdr
)
623 || hdr
->e_shentsize
!= sizeof(*sechdrs
)) {
625 "VPE loader: program wrong arch or weird elf version\n");
630 if (hdr
->e_type
== ET_REL
)
633 if (len
< hdr
->e_shoff
+ hdr
->e_shnum
* sizeof(Elf_Shdr
)) {
634 printk(KERN_ERR
"VPE loader: program length %u truncated\n",
640 /* Convenience variables */
641 sechdrs
= (void *)hdr
+ hdr
->e_shoff
;
642 secstrings
= (void *)hdr
+ sechdrs
[hdr
->e_shstrndx
].sh_offset
;
643 sechdrs
[0].sh_addr
= 0;
645 /* And these should exist, but gcc whinges if we don't init them */
646 symindex
= strindex
= 0;
649 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
650 if (sechdrs
[i
].sh_type
!= SHT_NOBITS
651 && len
< sechdrs
[i
].sh_offset
+ sechdrs
[i
].sh_size
) {
652 printk(KERN_ERR
"VPE program length %u truncated\n",
657 /* Mark all sections sh_addr with their address in the
659 sechdrs
[i
].sh_addr
= (size_t) hdr
+ sechdrs
[i
].sh_offset
;
661 /* Internal symbols and strings. */
662 if (sechdrs
[i
].sh_type
== SHT_SYMTAB
) {
664 strindex
= sechdrs
[i
].sh_link
;
665 strtab
= (char *)hdr
+ sechdrs
[strindex
].sh_offset
;
668 layout_sections(&mod
, hdr
, sechdrs
, secstrings
);
671 v
->load_addr
= alloc_progmem(mod
.core_size
);
675 pr_info("VPE loader: loading to %p\n", v
->load_addr
);
678 for (i
= 0; i
< hdr
->e_shnum
; i
++) {
681 if (!(sechdrs
[i
].sh_flags
& SHF_ALLOC
))
684 dest
= v
->load_addr
+ sechdrs
[i
].sh_entsize
;
686 if (sechdrs
[i
].sh_type
!= SHT_NOBITS
)
687 memcpy(dest
, (void *)sechdrs
[i
].sh_addr
,
689 /* Update sh_addr to point to copy in image. */
690 sechdrs
[i
].sh_addr
= (unsigned long)dest
;
692 printk(KERN_DEBUG
" section sh_name %s sh_addr 0x%x\n",
693 secstrings
+ sechdrs
[i
].sh_name
, sechdrs
[i
].sh_addr
);
696 /* Fix up syms, so that st_value is a pointer to location. */
697 simplify_symbols(sechdrs
, symindex
, strtab
, secstrings
,
700 /* Now do relocations. */
701 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
702 const char *strtab
= (char *)sechdrs
[strindex
].sh_addr
;
703 unsigned int info
= sechdrs
[i
].sh_info
;
705 /* Not a valid relocation section? */
706 if (info
>= hdr
->e_shnum
)
709 /* Don't bother with non-allocated sections */
710 if (!(sechdrs
[info
].sh_flags
& SHF_ALLOC
))
713 if (sechdrs
[i
].sh_type
== SHT_REL
)
714 err
= apply_relocations(sechdrs
, strtab
, symindex
, i
,
716 else if (sechdrs
[i
].sh_type
== SHT_RELA
)
717 err
= apply_relocate_add(sechdrs
, strtab
, symindex
, i
,
724 struct elf_phdr
*phdr
= (struct elf_phdr
*) ((char *)hdr
+ hdr
->e_phoff
);
726 for (i
= 0; i
< hdr
->e_phnum
; i
++) {
727 if (phdr
->p_type
== PT_LOAD
) {
728 memcpy((void *)phdr
->p_paddr
,
729 (char *)hdr
+ phdr
->p_offset
,
731 memset((void *)phdr
->p_paddr
+ phdr
->p_filesz
,
732 0, phdr
->p_memsz
- phdr
->p_filesz
);
737 for (i
= 0; i
< hdr
->e_shnum
; i
++) {
738 /* Internal symbols and strings. */
739 if (sechdrs
[i
].sh_type
== SHT_SYMTAB
) {
741 strindex
= sechdrs
[i
].sh_link
;
742 strtab
= (char *)hdr
+ sechdrs
[strindex
].sh_offset
;
744 /* mark the symtab's address for when we try to find the
746 sechdrs
[i
].sh_addr
= (size_t) hdr
+ sechdrs
[i
].sh_offset
;
751 /* make sure it's physically written out */
752 flush_icache_range((unsigned long)v
->load_addr
,
753 (unsigned long)v
->load_addr
+ v
->len
);
755 if ((find_vpe_symbols(v
, sechdrs
, symindex
, strtab
, &mod
)) < 0) {
756 if (v
->__start
== 0) {
757 printk(KERN_WARNING
"VPE loader: program does not contain "
758 "a __start symbol\n");
762 if (v
->shared_ptr
== NULL
)
763 printk(KERN_WARNING
"VPE loader: "
764 "program does not contain vpe_shared symbol.\n"
765 " Unable to use AMVP (AP/SP) facilities.\n");
768 printk(" elf loaded\n");
772 static int getcwd(char *buff
, int size
)
780 ret
= sys_getcwd(buff
, size
);
787 /* checks VPE is unused and gets ready to load program */
788 static int vpe_open(struct inode
*inode
, struct file
*filp
)
790 enum vpe_state state
;
791 struct vpe_notifications
*not;
795 if (VPE_MODULE_MINOR
!= iminor(inode
)) {
796 /* assume only 1 device at the moment. */
797 pr_warning("VPE loader: only vpe1 is supported\n");
802 if ((v
= get_vpe(aprp_cpu_index())) == NULL
) {
803 pr_warning("VPE loader: unable to get vpe\n");
808 state
= xchg(&v
->state
, VPE_STATE_INUSE
);
809 if (state
!= VPE_STATE_UNUSED
) {
810 printk(KERN_DEBUG
"VPE loader: tc in use dumping regs\n");
812 list_for_each_entry(not, &v
->notify
, list
) {
813 not->stop(aprp_cpu_index());
816 release_progmem(v
->load_addr
);
817 cleanup_tc(get_tc(aprp_cpu_index()));
820 /* this of-course trashes what was there before... */
821 v
->pbuffer
= vmalloc(P_SIZE
);
823 pr_warning("VPE loader: unable to allocate memory\n");
830 v
->uid
= filp
->f_cred
->fsuid
;
831 v
->gid
= filp
->f_cred
->fsgid
;
834 ret
= getcwd(v
->cwd
, VPE_PATH_MAX
);
836 printk(KERN_WARNING
"VPE loader: open, getcwd returned %d\n", ret
);
838 v
->shared_ptr
= NULL
;
844 static int vpe_release(struct inode
*inode
, struct file
*filp
)
850 v
= get_vpe(aprp_cpu_index());
854 hdr
= (Elf_Ehdr
*) v
->pbuffer
;
855 if (memcmp(hdr
->e_ident
, ELFMAG
, SELFMAG
) == 0) {
856 if ((vpe_elfload(v
) >= 0) && vpe_run
) {
859 printk(KERN_WARNING
"VPE loader: ELF load failed.\n");
863 printk(KERN_WARNING
"VPE loader: only elf files are supported\n");
867 /* It's good to be able to run the SP and if it chokes have a look at
868 the /dev/rt?. But if we reset the pointer to the shared struct we
869 lose what has happened. So perhaps if garbage is sent to the vpe
870 device, use it as a trigger for the reset. Hopefully a nice
871 executable will be along shortly. */
873 v
->shared_ptr
= NULL
;
881 static ssize_t
vpe_write(struct file
*file
, const char __user
* buffer
,
882 size_t count
, loff_t
* ppos
)
887 if (iminor(file_inode(file
)) != VPE_MODULE_MINOR
)
890 v
= get_vpe(aprp_cpu_index());
894 if ((count
+ v
->len
) > v
->plen
) {
896 "VPE loader: elf size too big. Perhaps strip uneeded symbols\n");
900 count
-= copy_from_user(v
->pbuffer
+ v
->len
, buffer
, count
);
908 const struct file_operations vpe_fops
= {
909 .owner
= THIS_MODULE
,
911 .release
= vpe_release
,
913 .llseek
= noop_llseek
,
916 void *vpe_get_shared(int index
)
920 if ((v
= get_vpe(index
)) == NULL
)
923 return v
->shared_ptr
;
926 EXPORT_SYMBOL(vpe_get_shared
);
928 int vpe_getuid(int index
)
932 if ((v
= get_vpe(index
)) == NULL
)
938 EXPORT_SYMBOL(vpe_getuid
);
940 int vpe_getgid(int index
)
944 if ((v
= get_vpe(index
)) == NULL
)
950 EXPORT_SYMBOL(vpe_getgid
);
952 int vpe_notify(int index
, struct vpe_notifications
*notify
)
956 if ((v
= get_vpe(index
)) == NULL
)
959 list_add(¬ify
->list
, &v
->notify
);
963 EXPORT_SYMBOL(vpe_notify
);
965 char *vpe_getcwd(int index
)
969 if ((v
= get_vpe(index
)) == NULL
)
975 EXPORT_SYMBOL(vpe_getcwd
);
977 module_init(vpe_module_init
);
978 module_exit(vpe_module_exit
);
979 MODULE_DESCRIPTION("MIPS VPE Loader");
980 MODULE_AUTHOR("Elizabeth Oldham, MIPS Technologies, Inc.");
981 MODULE_LICENSE("GPL");
This page took 0.052923 seconds and 5 git commands to generate.