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