| Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * misc.c:  Miscellaneous prom functions that don't belong | 
|  | 3 | *          anywhere else. | 
|  | 4 | * | 
|  | 5 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | 
|  | 6 | */ | 
|  | 7 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/types.h> | 
|  | 9 | #include <linux/kernel.h> | 
|  | 10 | #include <linux/sched.h> | 
| Sam Ravnborg | 6943f3d | 2009-01-08 16:58:05 -0800 | [diff] [blame] | 11 | #include <linux/module.h> | 
|  | 12 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/openprom.h> | 
|  | 14 | #include <asm/oplib.h> | 
|  | 15 | #include <asm/auxio.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | extern void restore_current(void); | 
|  | 18 |  | 
|  | 19 | DEFINE_SPINLOCK(prom_lock); | 
|  | 20 |  | 
|  | 21 | /* Reset and reboot the machine with the command 'bcommand'. */ | 
|  | 22 | void | 
|  | 23 | prom_reboot(char *bcommand) | 
|  | 24 | { | 
|  | 25 | unsigned long flags; | 
|  | 26 | spin_lock_irqsave(&prom_lock, flags); | 
|  | 27 | (*(romvec->pv_reboot))(bcommand); | 
|  | 28 | /* Never get here. */ | 
|  | 29 | restore_current(); | 
|  | 30 | spin_unlock_irqrestore(&prom_lock, flags); | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | /* Forth evaluate the expression contained in 'fstring'. */ | 
|  | 34 | void | 
|  | 35 | prom_feval(char *fstring) | 
|  | 36 | { | 
|  | 37 | unsigned long flags; | 
|  | 38 | if(!fstring || fstring[0] == 0) | 
|  | 39 | return; | 
|  | 40 | spin_lock_irqsave(&prom_lock, flags); | 
|  | 41 | if(prom_vers == PROM_V0) | 
|  | 42 | (*(romvec->pv_fortheval.v0_eval))(strlen(fstring), fstring); | 
|  | 43 | else | 
|  | 44 | (*(romvec->pv_fortheval.v2_eval))(fstring); | 
|  | 45 | restore_current(); | 
|  | 46 | spin_unlock_irqrestore(&prom_lock, flags); | 
|  | 47 | } | 
| Sam Ravnborg | 6943f3d | 2009-01-08 16:58:05 -0800 | [diff] [blame] | 48 | EXPORT_SYMBOL(prom_feval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* Drop into the prom, with the chance to continue with the 'go' | 
|  | 51 | * prom command. | 
|  | 52 | */ | 
|  | 53 | void | 
|  | 54 | prom_cmdline(void) | 
|  | 55 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | unsigned long flags; | 
|  | 57 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | spin_lock_irqsave(&prom_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | (*(romvec->pv_abort))(); | 
|  | 60 | restore_current(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | spin_unlock_irqrestore(&prom_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | set_auxio(AUXIO_LED, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
|  | 65 | /* Drop into the prom, but completely terminate the program. | 
|  | 66 | * No chance of continuing. | 
|  | 67 | */ | 
| Sam Ravnborg | 5f66dd3 | 2011-01-03 08:27:55 +0000 | [diff] [blame] | 68 | void __noreturn | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | prom_halt(void) | 
|  | 70 | { | 
|  | 71 | unsigned long flags; | 
|  | 72 | again: | 
|  | 73 | spin_lock_irqsave(&prom_lock, flags); | 
|  | 74 | (*(romvec->pv_halt))(); | 
|  | 75 | /* Never get here. */ | 
|  | 76 | restore_current(); | 
|  | 77 | spin_unlock_irqrestore(&prom_lock, flags); | 
|  | 78 | goto again; /* PROM is out to get me -DaveM */ | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | typedef void (*sfunc_t)(void); | 
|  | 82 |  | 
|  | 83 | /* Set prom sync handler to call function 'funcp'. */ | 
|  | 84 | void | 
|  | 85 | prom_setsync(sfunc_t funcp) | 
|  | 86 | { | 
|  | 87 | if(!funcp) return; | 
|  | 88 | *romvec->pv_synchook = funcp; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the | 
|  | 92 | * format type.  'num_bytes' is the number of bytes that your idbuf | 
|  | 93 | * has space for.  Returns 0xff on error. | 
|  | 94 | */ | 
|  | 95 | unsigned char | 
|  | 96 | prom_get_idprom(char *idbuf, int num_bytes) | 
|  | 97 | { | 
|  | 98 | int len; | 
|  | 99 |  | 
|  | 100 | len = prom_getproplen(prom_root_node, "idprom"); | 
|  | 101 | if((len>num_bytes) || (len==-1)) return 0xff; | 
|  | 102 | if(!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes)) | 
|  | 103 | return idbuf[0]; | 
|  | 104 |  | 
|  | 105 | return 0xff; | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | /* Get the major prom version number. */ | 
|  | 109 | int | 
|  | 110 | prom_version(void) | 
|  | 111 | { | 
|  | 112 | return romvec->pv_romvers; | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | /* Get the prom plugin-revision. */ | 
|  | 116 | int | 
|  | 117 | prom_getrev(void) | 
|  | 118 | { | 
|  | 119 | return prom_rev; | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | /* Get the prom firmware print revision. */ | 
|  | 123 | int | 
|  | 124 | prom_getprev(void) | 
|  | 125 | { | 
|  | 126 | return prom_prev; | 
|  | 127 | } |