~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/ppc64/kernel/rtas.c

Version: ~ [ linux-5.9 ] ~ [ linux-5.8.14 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.70 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.150 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.200 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.238 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.238 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *
  3  * Procedures for interfacing to the RTAS on CHRP machines.
  4  *
  5  * Peter Bergner, IBM   March 2001.
  6  * Copyright (C) 2001 IBM.
  7  *
  8  *      This program is free software; you can redistribute it and/or
  9  *      modify it under the terms of the GNU General Public License
 10  *      as published by the Free Software Foundation; either version
 11  *      2 of the License, or (at your option) any later version.
 12  */
 13 
 14 #include <stdarg.h>
 15 #include <linux/kernel.h>
 16 #include <linux/types.h>
 17 #include <linux/spinlock.h>
 18 #include <linux/module.h>
 19 
 20 #include <asm/prom.h>
 21 #include <asm/proc_fs.h>
 22 #include <asm/rtas.h>
 23 #include <asm/semaphore.h>
 24 #include <asm/machdep.h>
 25 #include <asm/paca.h>
 26 #include <asm/page.h>
 27 #include <asm/param.h>
 28 #include <asm/system.h>
 29 #include <asm/abs_addr.h>
 30 #include <asm/udbg.h>
 31 
 32 struct flash_block_list_header rtas_firmware_flash_list = {0, 0};
 33 
 34 /*
 35  * prom_init() is called very early on, before the kernel text
 36  * and data have been mapped to KERNELBASE.  At this point the code
 37  * is running at whatever address it has been loaded at, so
 38  * references to extern and static variables must be relocated
 39  * explicitly.  The procedure reloc_offset() returns the address
 40  * we're currently running at minus the address we were linked at.
 41  * (Note that strings count as static variables.)
 42  *
 43  * Because OF may have mapped I/O devices into the area starting at
 44  * KERNELBASE, particularly on CHRP machines, we can't safely call
 45  * OF once the kernel has been mapped to KERNELBASE.  Therefore all
 46  * OF calls should be done within prom_init(), and prom_init()
 47  * and all routines called within it must be careful to relocate
 48  * references as necessary.
 49  *
 50  * Note that the bss is cleared *after* prom_init runs, so we have
 51  * to make sure that any static or extern variables it accesses
 52  * are put in the data segment.
 53  */
 54 
 55 struct rtas_t rtas = { 
 56         .lock = SPIN_LOCK_UNLOCKED
 57 };
 58 
 59 extern unsigned long reloc_offset(void);
 60 
 61 spinlock_t rtas_data_buf_lock = SPIN_LOCK_UNLOCKED;
 62 char rtas_data_buf[RTAS_DATA_BUF_SIZE];
 63 
 64 void
 65 phys_call_rtas(int token, int nargs, int nret, ...)
 66 {
 67         va_list list;
 68         unsigned long offset = reloc_offset();
 69         struct rtas_args *rtas = PTRRELOC(&(get_paca()->xRtas));
 70         int i;
 71 
 72         rtas->token = token;
 73         rtas->nargs = nargs;
 74         rtas->nret  = nret;
 75         rtas->rets  = (rtas_arg_t *)PTRRELOC(&(rtas->args[nargs]));
 76 
 77         va_start(list, nret);
 78         for (i = 0; i < nargs; i++)
 79           rtas->args[i] = (rtas_arg_t)LONG_LSW(va_arg(list, ulong));
 80         va_end(list);
 81 
 82         enter_rtas(rtas);       
 83 }
 84 
 85 void
 86 phys_call_rtas_display_status(char c)
 87 {
 88         unsigned long offset = reloc_offset();
 89         struct rtas_args *rtas = PTRRELOC(&(get_paca()->xRtas));
 90 
 91         rtas->token = 10;
 92         rtas->nargs = 1;
 93         rtas->nret  = 1;
 94         rtas->rets  = (rtas_arg_t *)PTRRELOC(&(rtas->args[1]));
 95         rtas->args[0] = (int)c;
 96 
 97         enter_rtas(rtas);       
 98 }
 99 
100 void
101 call_rtas_display_status(char c)
102 {
103         struct rtas_args *rtas = &(get_paca()->xRtas);
104 
105         rtas->token = 10;
106         rtas->nargs = 1;
107         rtas->nret  = 1;
108         rtas->rets  = (rtas_arg_t *)&(rtas->args[1]);
109         rtas->args[0] = (int)c;
110 
111         enter_rtas((void *)__pa((unsigned long)rtas));  
112 }
113 
114 int
115 rtas_token(const char *service)
116 {
117         int *tokp;
118         if (rtas.dev == NULL) {
119                 PPCDBG(PPCDBG_RTAS,"\tNo rtas device in device-tree...\n");
120                 return RTAS_UNKNOWN_SERVICE;
121         }
122         tokp = (int *) get_property(rtas.dev, service, NULL);
123         return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
124 }
125 
126 long
127 rtas_call(int token, int nargs, int nret,
128           unsigned long *outputs, ...)
129 {
130         va_list list;
131         int i;
132         unsigned long s;
133         struct rtas_args *rtas_args = &(get_paca()->xRtas);
134 
135         PPCDBG(PPCDBG_RTAS, "Entering rtas_call\n");
136         PPCDBG(PPCDBG_RTAS, "\ttoken    = 0x%x\n", token);
137         PPCDBG(PPCDBG_RTAS, "\tnargs    = %d\n", nargs);
138         PPCDBG(PPCDBG_RTAS, "\tnret     = %d\n", nret);
139         PPCDBG(PPCDBG_RTAS, "\t&outputs = 0x%lx\n", outputs);
140         if (token == RTAS_UNKNOWN_SERVICE)
141                 return -1;
142 
143         rtas_args->token = token;
144         rtas_args->nargs = nargs;
145         rtas_args->nret  = nret;
146         rtas_args->rets  = (rtas_arg_t *)&(rtas_args->args[nargs]);
147         va_start(list, outputs);
148         for (i = 0; i < nargs; ++i) {
149                 rtas_args->args[i] = (rtas_arg_t)LONG_LSW(va_arg(list, ulong));
150                 PPCDBG(PPCDBG_RTAS, "\tnarg[%d] = 0x%lx\n", i, rtas_args->args[i]);
151         }
152         va_end(list);
153 
154         for (i = 0; i < nret; ++i)
155           rtas_args->rets[i] = 0;
156 
157 #if 0   /* Gotta do something different here, use global lock for now... */
158         spin_lock_irqsave(&rtas_args->lock, s);
159 #else
160         spin_lock_irqsave(&rtas.lock, s);
161 #endif
162         PPCDBG(PPCDBG_RTAS, "\tentering rtas with 0x%lx\n",
163                 (void *)__pa((unsigned long)rtas_args));
164         enter_rtas((void *)__pa((unsigned long)rtas_args));
165         PPCDBG(PPCDBG_RTAS, "\treturned from rtas ...\n");
166 #if 0   /* Gotta do something different here, use global lock for now... */
167         spin_unlock_irqrestore(&rtas_args->lock, s);
168 #else
169         spin_unlock_irqrestore(&rtas.lock, s);
170 #endif
171         ifppcdebug(PPCDBG_RTAS) {
172                 for(i=0; i < nret ;i++)
173                         udbg_printf("\tnret[%d] = 0x%lx\n", i, (ulong)rtas_args->rets[i]);
174         }
175 
176         if (nret > 1 && outputs != NULL)
177                 for (i = 0; i < nret-1; ++i)
178                         outputs[i] = rtas_args->rets[i+1];
179         return (ulong)((nret > 0) ? rtas_args->rets[0] : 0);
180 }
181 
182 /* Given an RTAS status code of 990n compute the hinted delay of 10^n
183  * (last digit) milliseconds.  For now we bound at n=3 (1 sec).
184  */
185 unsigned int
186 rtas_extended_busy_delay_time(int status)
187 {
188         int order = status - 9900;
189         unsigned int ms;
190 
191         if (order < 0)
192                 order = 0;      /* RTC depends on this for -2 clock busy */
193         else if (order > 3)
194                 order = 3;      /* bound */
195 
196         /* Use microseconds for reasonable accuracy */
197         for (ms = 1000; order > 0; order--)
198                 ms = ms * 10;
199         return ms / (1000000/HZ); /* round down is fine */
200 }
201 
202 #define FLASH_BLOCK_LIST_VERSION (1UL)
203 static void
204 rtas_flash_firmware(void)
205 {
206         unsigned long image_size;
207         struct flash_block_list *f, *next, *flist;
208         unsigned long rtas_block_list;
209         int i, status, update_token;
210 
211         update_token = rtas_token("ibm,update-flash-64-and-reboot");
212         if (update_token == RTAS_UNKNOWN_SERVICE) {
213                 printk(KERN_ALERT "FLASH: ibm,update-flash-64-and-reboot is not available -- not a service partition?\n");
214                 printk(KERN_ALERT "FLASH: firmware will not be flashed\n");
215                 return;
216         }
217 
218         /* NOTE: the "first" block list is a global var with no data
219          * blocks in the kernel data segment.  We do this because
220          * we want to ensure this block_list addr is under 4GB.
221          */
222         rtas_firmware_flash_list.num_blocks = 0;
223         flist = (struct flash_block_list *)&rtas_firmware_flash_list;
224         rtas_block_list = virt_to_absolute((unsigned long)flist);
225         if (rtas_block_list >= (4UL << 20)) {
226                 printk(KERN_ALERT "FLASH: kernel bug...flash list header addr above 4GB\n");
227                 return;
228         }
229 
230         printk(KERN_ALERT "FLASH: preparing saved firmware image for flash\n");
231         /* Update the block_list in place. */
232         image_size = 0;
233         for (f = flist; f; f = next) {
234                 /* Translate data addrs to absolute */
235                 for (i = 0; i < f->num_blocks; i++) {
236                         f->blocks[i].data = (char *)virt_to_absolute((unsigned long)f->blocks[i].data);
237                         image_size += f->blocks[i].length;
238                 }
239                 next = f->next;
240                 /* Don't translate NULL pointer for last entry */
241                 if(f->next)
242                         f->next = (struct flash_block_list *)virt_to_absolute((unsigned long)f->next);
243                 else
244                         f->next = 0LL;
245                 /* make num_blocks into the version/length field */
246                 f->num_blocks = (FLASH_BLOCK_LIST_VERSION << 56) | ((f->num_blocks+1)*16);
247         }
248 
249         printk(KERN_ALERT "FLASH: flash image is %ld bytes\n", image_size);
250         printk(KERN_ALERT "FLASH: performing flash and reboot\n");
251         ppc_md.progress("Flashing        \n", 0x0);
252         ppc_md.progress("Please Wait...  ", 0x0);
253         printk(KERN_ALERT "FLASH: this will take several minutes.  Do not power off!\n");
254         status = rtas_call(update_token, 1, 1, NULL, rtas_block_list);
255         switch (status) {       /* should only get "bad" status */
256             case 0:
257                 printk(KERN_ALERT "FLASH: success\n");
258                 break;
259             case -1:
260                 printk(KERN_ALERT "FLASH: hardware error.  Firmware may not be not flashed\n");
261                 break;
262             case -3:
263                 printk(KERN_ALERT "FLASH: image is corrupt or not correct for this platform.  Firmware not flashed\n");
264                 break;
265             case -4:
266                 printk(KERN_ALERT "FLASH: flash failed when partially complete.  System may not reboot\n");
267                 break;
268             default:
269                 printk(KERN_ALERT "FLASH: unknown flash return code %d\n", status);
270                 break;
271         }
272 }
273 
274 void rtas_flash_bypass_warning(void)
275 {
276         printk(KERN_ALERT "FLASH: firmware flash requires a reboot\n");
277         printk(KERN_ALERT "FLASH: the firmware image will NOT be flashed\n");
278 }
279 
280 
281 void
282 rtas_restart(char *cmd)
283 {
284         if (rtas_firmware_flash_list.next)
285                 rtas_flash_firmware();
286 
287         printk("RTAS system-reboot returned %ld\n",
288                rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
289         for (;;);
290 }
291 
292 void
293 rtas_power_off(void)
294 {
295         if (rtas_firmware_flash_list.next)
296                 rtas_flash_bypass_warning();
297         /* allow power on only with power button press */
298         printk("RTAS power-off returned %ld\n",
299                rtas_call(rtas_token("power-off"), 2, 1, NULL,0xffffffff,0xffffffff));
300         for (;;);
301 }
302 
303 void
304 rtas_halt(void)
305 {
306         if (rtas_firmware_flash_list.next)
307                 rtas_flash_bypass_warning();
308         rtas_power_off();
309 }
310 
311 EXPORT_SYMBOL(proc_ppc64);
312 EXPORT_SYMBOL(rtas_firmware_flash_list);
313 EXPORT_SYMBOL(rtas_token);
314 EXPORT_SYMBOL(rtas_call);
315 EXPORT_SYMBOL(rtas_data_buf);
316 EXPORT_SYMBOL(rtas_data_buf_lock);
317 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp