Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * misc.c:  Miscellaneous prom functions that don't belong
0004  *          anywhere else.
0005  *
0006  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
0007  */
0008 
0009 #include <linux/types.h>
0010 #include <linux/kernel.h>
0011 #include <linux/sched.h>
0012 #include <linux/module.h>
0013 
0014 #include <asm/openprom.h>
0015 #include <asm/oplib.h>
0016 #include <asm/auxio.h>
0017 
0018 extern void restore_current(void);
0019 
0020 DEFINE_SPINLOCK(prom_lock);
0021 
0022 /* Reset and reboot the machine with the command 'bcommand'. */
0023 void
0024 prom_reboot(char *bcommand)
0025 {
0026     unsigned long flags;
0027     spin_lock_irqsave(&prom_lock, flags);
0028     (*(romvec->pv_reboot))(bcommand);
0029     /* Never get here. */
0030     restore_current();
0031     spin_unlock_irqrestore(&prom_lock, flags);
0032 }
0033 
0034 /* Forth evaluate the expression contained in 'fstring'. */
0035 void
0036 prom_feval(char *fstring)
0037 {
0038     unsigned long flags;
0039     if(!fstring || fstring[0] == 0)
0040         return;
0041     spin_lock_irqsave(&prom_lock, flags);
0042     if(prom_vers == PROM_V0)
0043         (*(romvec->pv_fortheval.v0_eval))(strlen(fstring), fstring);
0044     else
0045         (*(romvec->pv_fortheval.v2_eval))(fstring);
0046     restore_current();
0047     spin_unlock_irqrestore(&prom_lock, flags);
0048 }
0049 EXPORT_SYMBOL(prom_feval);
0050 
0051 /* Drop into the prom, with the chance to continue with the 'go'
0052  * prom command.
0053  */
0054 void
0055 prom_cmdline(void)
0056 {
0057     unsigned long flags;
0058 
0059     spin_lock_irqsave(&prom_lock, flags);
0060     (*(romvec->pv_abort))();
0061     restore_current();
0062     spin_unlock_irqrestore(&prom_lock, flags);
0063     set_auxio(AUXIO_LED, 0);
0064 }
0065 
0066 /* Drop into the prom, but completely terminate the program.
0067  * No chance of continuing.
0068  */
0069 void __noreturn
0070 prom_halt(void)
0071 {
0072     unsigned long flags;
0073 again:
0074     spin_lock_irqsave(&prom_lock, flags);
0075     (*(romvec->pv_halt))();
0076     /* Never get here. */
0077     restore_current();
0078     spin_unlock_irqrestore(&prom_lock, flags);
0079     goto again; /* PROM is out to get me -DaveM */
0080 }
0081 
0082 typedef void (*sfunc_t)(void);
0083 
0084 /* Set prom sync handler to call function 'funcp'. */
0085 void
0086 prom_setsync(sfunc_t funcp)
0087 {
0088     if(!funcp) return;
0089     *romvec->pv_synchook = funcp;
0090 }
0091 
0092 /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
0093  * format type.  'num_bytes' is the number of bytes that your idbuf
0094  * has space for.  Returns 0xff on error.
0095  */
0096 unsigned char
0097 prom_get_idprom(char *idbuf, int num_bytes)
0098 {
0099     int len;
0100 
0101     len = prom_getproplen(prom_root_node, "idprom");
0102     if((len>num_bytes) || (len==-1)) return 0xff;
0103     if(!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
0104         return idbuf[0];
0105 
0106     return 0xff;
0107 }
0108 
0109 /* Get the major prom version number. */
0110 int
0111 prom_version(void)
0112 {
0113     return romvec->pv_romvers;
0114 }
0115 
0116 /* Get the prom plugin-revision. */
0117 int
0118 prom_getrev(void)
0119 {
0120     return prom_rev;
0121 }
0122 
0123 /* Get the prom firmware print revision. */
0124 int
0125 prom_getprev(void)
0126 {
0127     return prom_prev;
0128 }