/* * misc.c: Miscellaneous prom functions that don't belong * anywhere else. * * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ #include #include #include #include #include #include #include #include #include static int prom_service_exists(const char *service_name) { unsigned long args[5]; args[0] = (unsigned long) "test"; args[1] = 1; args[2] = 1; args[3] = (unsigned long) service_name; args[4] = (unsigned long) -1; p1275_cmd_direct(args); if (args[4]) return 0; return 1; } void prom_sun4v_guest_soft_state(void) { const char *svc = "SUNW,soft-state-supported"; unsigned long args[3]; if (!prom_service_exists(svc)) return; args[0] = (unsigned long) svc; args[1] = 0; args[2] = 0; p1275_cmd_direct(args); } /* Reset and reboot the machine with the command 'bcommand'. */ void prom_reboot(const char *bcommand) { unsigned long args[4]; #ifdef CONFIG_SUN_LDOMS if (ldom_domaining_enabled) ldom_reboot(bcommand); #endif args[0] = (unsigned long) "boot"; args[1] = 1; args[2] = 0; args[3] = (unsigned long) bcommand; p1275_cmd_direct(args); } /* Forth evaluate the expression contained in 'fstring'. */ void prom_feval(const char *fstring) { unsigned long args[5]; if (!fstring || fstring[0] == 0) return; args[0] = (unsigned long) "interpret"; args[1] = 1; args[2] = 1; args[3] = (unsigned long) fstring; args[4] = (unsigned long) -1; p1275_cmd_direct(args); } EXPORT_SYMBOL(prom_feval); /* Drop into the prom, with the chance to continue with the 'go' * prom command. */ void prom_cmdline(void) { unsigned long args[3]; unsigned long flags; local_irq_save(flags); #ifdef CONFIG_SMP smp_capture(); #endif args[0] = (unsigned long) "enter"; args[1] = 0; args[2] = 0; p1275_cmd_direct(args); #ifdef CONFIG_SMP smp_release(); #endif local_irq_restore(flags); } /* Drop into the prom, but completely terminate the program. * No chance of continuing. */ void notrace prom_halt(void) { unsigned long args[3]; #ifdef CONFIG_SUN_LDOMS if (ldom_domaining_enabled) ldom_power_off(); #endif again: args[0] = (unsigned long) "exit"; args[1] = 0; args[2] = 0; p1275_cmd_direct(args); goto again; /* PROM is out to get me -DaveM */ } void prom_halt_power_off(void) { unsigned long args[3]; #ifdef CONFIG_SUN_LDOMS if (ldom_domaining_enabled) ldom_power_off(); #endif args[0] = (unsigned long) "SUNW,power-off"; args[1] = 0; args[2] = 0; p1275_cmd_direct(args); /* if nothing else helps, we just halt */ prom_halt(); } /* Get the idprom and stuff it into buffer 'idbuf'. Returns the * format type. 'num_bytes' is the number of bytes that your idbuf * has space for. Returns 0xff on error. */ unsigned char prom_get_idprom(char *idbuf, int num_bytes) { int len; len = prom_getproplen(prom_root_node, "idprom"); if ((len >num_bytes) || (len == -1)) return 0xff; if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes)) return idbuf[0]; return 0xff; } int prom_get_mmu_ihandle(void) { phandle node; int ret; if (prom_mmu_ihandle_cache != 0) return prom_mmu_ihandle_cache; node = prom_finddevice(prom_chosen_path); ret = prom_getint(node, prom_mmu_name); if (ret == -1 || ret == 0) prom_mmu_ihandle_cache = -1; else prom_mmu_ihandle_cache = ret; return ret; } static int prom_get_memory_ihandle(void) { static int memory_ihandle_cache; phandle node; int ret; if (memory_ihandle_cache != 0) return memory_ihandle_cache; node = prom_finddevice("/chosen"); ret = prom_getint(node, "memory"); if (ret == -1 || ret == 0) memory_ihandle_cache = -1; else memory_ihandle_cache = ret; return ret; } /* Load explicit I/D TLB entries. */ static long tlb_load(const char *type, unsigned long index, unsigned long tte_data, unsigned long vaddr) { unsigned long args[9]; args[0] = (unsigned long) prom_callmethod_name; args[1] = 5; args[2] = 1; args[3] = (unsigned long) type; args[4] = (unsigned int) prom_get_mmu_ihandle(); args[5] = vaddr; args[6] = tte_data; args[7] = index; args[8] = (unsigned long) -1; p1275_cmd_direct(args); return (long) args[8]; } long prom_itlb_load(unsigned long index, unsigned long tte_data, unsigned long vaddr) { return tlb_load("SUNW,itlb-load", index, tte_data, vaddr); } long prom_dtlb_load(unsigned long index, unsigned long tte_data, unsigned long vaddr) { return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr); } int prom_map(int mode, unsigned long size, unsigned long vaddr, unsigned long paddr) { unsigned long args[11]; int ret; args[0] = (unsigned long) prom_callmethod_name; args[1] = 7; args[2] = 1; args[3] = (unsigned long) prom_map_name; args[4] = (unsigned int) prom_get_mmu_ihandle(); args[5] = (unsigned int) mode; args[6] = size; args[7] = vaddr; args[8] = 0; args[9] = paddr; args[10] = (unsigned long) -1; p1275_cmd_direct(args); ret = (int) args[10]; if (ret == 0) ret = -1; return ret; } void prom_unmap(u