This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / ppc64 / kernel / rtas.c
index 438d258..77c2400 100644 (file)
 #include <asm/delay.h>
 #include <asm/uaccess.h>
 
-struct flash_block_list_header rtas_firmware_flash_list = {0, NULL};
+struct flash_block_list_header rtas_firmware_flash_list = {0, 0};
+
+/*
+ * prom_init() is called very early on, before the kernel text
+ * and data have been mapped to KERNELBASE.  At this point the code
+ * is running at whatever address it has been loaded at, so
+ * references to extern and static variables must be relocated
+ * explicitly.  The procedure reloc_offset() returns the address
+ * we're currently running at minus the address we were linked at.
+ * (Note that strings count as static variables.)
+ *
+ * Because OF may have mapped I/O devices into the area starting at
+ * KERNELBASE, particularly on CHRP machines, we can't safely call
+ * OF once the kernel has been mapped to KERNELBASE.  Therefore all
+ * OF calls should be done within prom_init(), and prom_init()
+ * and all routines called within it must be careful to relocate
+ * references as necessary.
+ *
+ * Note that the bss is cleared *after* prom_init runs, so we have
+ * to make sure that any static or extern variables it accesses
+ * are put in the data segment.
+ */
 
 struct rtas_t rtas = { 
        .lock = SPIN_LOCK_UNLOCKED
 };
 
+EXPORT_SYMBOL_GPL(rtas);
+
 char rtas_err_buf[RTAS_ERROR_LOG_MAX];
 
+extern unsigned long reloc_offset(void);
+
 spinlock_t rtas_data_buf_lock = SPIN_LOCK_UNLOCKED;
 char rtas_data_buf[RTAS_DATA_BUF_SIZE]__page_aligned;
 
 void
 call_rtas_display_status(char c)
 {
-       struct rtas_args *args = &rtas.args;
+       struct rtas_args *args;
        unsigned long s;
 
        spin_lock_irqsave(&rtas.lock, s);
+       args = &(get_paca()->xRtas);
 
        args->token = 10;
        args->nargs = 1;
@@ -74,16 +100,10 @@ rtas_token(const char *service)
 }
 
 
-/** Return a copy of the detailed error text associated with the
- *  most recent failed call to rtas.  Because the error text
- *  might go stale if there are any other intervening rtas calls,
- *  this routine must be called atomically with whatever produced
- *  the error (i.e. with rtas.lock still held from the previous call).
- */
 static int
-__fetch_rtas_last_error(void)
+__log_rtas_error(struct rtas_args *rtas_args)
 {
-       struct rtas_args err_args, save_args;
+       struct rtas_args err_args, temp_args;
 
        err_args.token = rtas_token("rtas-last-error");
        err_args.nargs = 2;
@@ -94,28 +114,42 @@ __fetch_rtas_last_error(void)
        err_args.args[1] = RTAS_ERROR_LOG_MAX;
        err_args.args[2] = 0;
 
-       save_args = rtas.args;
-       rtas.args = err_args;
+       temp_args = *rtas_args;
+       get_paca()->xRtas = err_args;
 
        PPCDBG(PPCDBG_RTAS, "\tentering rtas with 0x%lx\n",
               __pa(&err_args));
-       enter_rtas(__pa(&rtas.args));
+       enter_rtas(__pa(&get_paca()->xRtas));
        PPCDBG(PPCDBG_RTAS, "\treturned from rtas ...\n");
 
-       err_args = rtas.args;
-       rtas.args = save_args;
+       err_args = get_paca()->xRtas;
+       get_paca()->xRtas = temp_args;
 
        return err_args.rets[0];
 }
 
-int rtas_call(int token, int nargs, int nret, int *outputs, ...)
+void
+log_rtas_error(struct rtas_args        *rtas_args)
+{
+       unsigned long s;
+       int rc;
+
+       spin_lock_irqsave(&rtas.lock, s);
+       rc = __log_rtas_error(rtas_args);
+       spin_unlock_irqrestore(&rtas.lock, s);
+       if (rc == 0)
+               log_error(rtas_err_buf, ERR_TYPE_RTAS_LOG, 0);
+}
+
+long
+rtas_call(int token, int nargs, int nret,
+         unsigned long *outputs, ...)
 {
        va_list list;
        int i, logit = 0;
        unsigned long s;
        struct rtas_args *rtas_args;
-       char * buff_copy = NULL;
-       int ret;
+       long ret;
 
        PPCDBG(PPCDBG_RTAS, "Entering rtas_call\n");
        PPCDBG(PPCDBG_RTAS, "\ttoken    = 0x%x\n", token);
@@ -127,7 +161,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
 
        /* Gotta do something different here, use global lock for now... */
        spin_lock_irqsave(&rtas.lock, s);
-       rtas_args = &rtas.args;
+       rtas_args = &(get_paca()->xRtas);
 
        rtas_args->token = token;
        rtas_args->nargs = nargs;
@@ -135,8 +169,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
        rtas_args->rets  = (rtas_arg_t *)&(rtas_args->args[nargs]);
        va_start(list, outputs);
        for (i = 0; i < nargs; ++i) {
-               rtas_args->args[i] = va_arg(list, rtas_arg_t);
-               PPCDBG(PPCDBG_RTAS, "\tnarg[%d] = 0x%x\n", i, rtas_args->args[i]);
+               rtas_args->args[i] = (rtas_arg_t)LONG_LSW(va_arg(list, ulong));
+               PPCDBG(PPCDBG_RTAS, "\tnarg[%d] = 0x%lx\n", i, rtas_args->args[i]);
        }
        va_end(list);
 
@@ -148,10 +182,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
        enter_rtas(__pa(rtas_args));
        PPCDBG(PPCDBG_RTAS, "\treturned from rtas ...\n");
 
-       /* A -1 return code indicates that the last command couldn't
-          be completed due to a hardware error. */
        if (rtas_args->rets[0] == -1)
-               logit = (__fetch_rtas_last_error() == 0);
+               logit = (__log_rtas_error(rtas_args) == 0);
 
        ifppcdebug(PPCDBG_RTAS) {
                for(i=0; i < nret ;i++)
@@ -161,23 +193,14 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
        if (nret > 1 && outputs != NULL)
                for (i = 0; i < nret-1; ++i)
                        outputs[i] = rtas_args->rets[i+1];
-       ret = (nret > 0)? rtas_args->rets[0]: 0;
-
-       /* Log the error in the unlikely case that there was one. */
-       if (unlikely(logit)) {
-               buff_copy = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);
-               if (buff_copy) {
-                       memcpy(buff_copy, rtas_err_buf, RTAS_ERROR_LOG_MAX);
-               }
-       }
+       ret = (ulong)((nret > 0) ? rtas_args->rets[0] : 0);
 
        /* Gotta do something different here, use global lock for now... */
        spin_unlock_irqrestore(&rtas.lock, s);
 
-       if (buff_copy) {
-               log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
-               kfree(buff_copy);
-       }
+       if (logit)
+               log_error(rtas_err_buf, ERR_TYPE_RTAS_LOG, 0);
+
        return ret;
 }
 
@@ -197,7 +220,7 @@ rtas_extended_busy_delay_time(int status)
 
        /* Use microseconds for reasonable accuracy */
        for (ms=1; order > 0; order--)
-               ms *= 10;
+               ms *= 10;          
 
        return ms; 
 }
@@ -206,13 +229,20 @@ int
 rtas_get_power_level(int powerdomain, int *level)
 {
        int token = rtas_token("get-power-level");
+       long powerlevel;
        int rc;
 
        if (token == RTAS_UNKNOWN_SERVICE)
                return RTAS_UNKNOWN_OP;
 
-       while ((rc = rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
-               udelay(1);
+       while(1) {
+               rc = (int) rtas_call(token, 1, 2, &powerlevel, powerdomain);
+               if (rc == RTAS_BUSY)
+                       udelay(1);
+               else
+                       break;
+       }
+       *level = (int) powerlevel;
        return rc;
 }
 
@@ -221,21 +251,25 @@ rtas_set_power_level(int powerdomain, int level, int *setlevel)
 {
        int token = rtas_token("set-power-level");
        unsigned int wait_time;
+       long returned_level;
        int rc;
 
        if (token == RTAS_UNKNOWN_SERVICE)
                return RTAS_UNKNOWN_OP;
 
        while (1) {
-               rc = rtas_call(token, 2, 2, setlevel, powerdomain, level);
+               rc = (int) rtas_call(token, 2, 2, &returned_level, powerdomain,
+                                       level);
                if (rc == RTAS_BUSY)
                        udelay(1);
                else if (rtas_is_extended_busy(rc)) {
                        wait_time = rtas_extended_busy_delay_time(rc);
                        udelay(wait_time * 1000);
-               } else
+               }
+               else
                        break;
        }
+       *setlevel = (int) returned_level;
        return rc;
 }
 
@@ -244,21 +278,25 @@ rtas_get_sensor(int sensor, int index, int *state)
 {
        int token = rtas_token("get-sensor-state");
        unsigned int wait_time;
+       long returned_state;
        int rc;
 
        if (token == RTAS_UNKNOWN_SERVICE)
                return RTAS_UNKNOWN_OP;
 
        while (1) {
-               rc = rtas_call(token, 2, 2, state, sensor, index);
+               rc = (int) rtas_call(token, 2, 2, &returned_state, sensor,
+                                       index);
                if (rc == RTAS_BUSY)
                        udelay(1);
                else if (rtas_is_extended_busy(rc)) {
                        wait_time = rtas_extended_busy_delay_time(rc);
                        udelay(wait_time * 1000);
-               } else
+               }
+               else
                        break;
        }
+       *state = (int) returned_state;
        return rc;
 }
 
@@ -273,7 +311,8 @@ rtas_set_indicator(int indicator, int index, int new_value)
                return RTAS_UNKNOWN_OP;
 
        while (1) {
-               rc = rtas_call(token, 3, 1, NULL, indicator, index, new_value);
+               rc = (int) rtas_call(token, 3, 1, NULL, indicator, index,
+                                       new_value);
                if (rc == RTAS_BUSY)
                        udelay(1);
                else if (rtas_is_extended_busy(rc)) {
@@ -329,7 +368,7 @@ rtas_flash_firmware(void)
                if (f->next)
                        f->next = (struct flash_block_list *)virt_to_abs(f->next);
                else
-                       f->next = NULL;
+                       f->next = 0LL;
                /* make num_blocks into the version/length field */
                f->num_blocks = (FLASH_BLOCK_LIST_VERSION << 56) | ((f->num_blocks+1)*16);
        }
@@ -372,9 +411,9 @@ rtas_restart(char *cmd)
        if (rtas_firmware_flash_list.next)
                rtas_flash_firmware();
 
-       printk("RTAS system-reboot returned %d\n",
+        printk("RTAS system-reboot returned %ld\n",
               rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
-       for (;;);
+        for (;;);
 }
 
 void
@@ -382,10 +421,10 @@ rtas_power_off(void)
 {
        if (rtas_firmware_flash_list.next)
                rtas_flash_bypass_warning();
-       /* allow power on only with power button press */
-       printk("RTAS power-off returned %d\n",
-              rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
-       for (;;);
+        /* allow power on only with power button press */
+        printk("RTAS power-off returned %ld\n",
+               rtas_call(rtas_token("power-off"), 2, 1, NULL,0xffffffff,0xffffffff));
+        for (;;);
 }
 
 void
@@ -393,7 +432,7 @@ rtas_halt(void)
 {
        if (rtas_firmware_flash_list.next)
                rtas_flash_bypass_warning();
-       rtas_power_off();
+        rtas_power_off();
 }
 
 /* Must be in the RMO region, so we place it here */
@@ -401,7 +440,7 @@ static char rtas_os_term_buf[2048];
 
 void rtas_os_term(char *str)
 {
-       int status;
+       long status;
 
        snprintf(rtas_os_term_buf, 2048, "OS panic: %s", str);
 
@@ -412,7 +451,7 @@ void rtas_os_term(char *str)
                if (status == RTAS_BUSY)
                        udelay(1);
                else if (status != 0)
-                       printk(KERN_EMERG "ibm,os-term call failed %d\n",
+                       printk(KERN_EMERG "ibm,os-term call failed %ld\n",
                               status);
        } while (status == RTAS_BUSY);
 }
@@ -423,9 +462,7 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
 {
        struct rtas_args args;
        unsigned long flags;
-       char * buff_copy;
        int nargs;
-       int err_rc = 0;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
@@ -444,33 +481,17 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
                           nargs * sizeof(rtas_arg_t)) != 0)
                return -EFAULT;
 
-       buff_copy = kmalloc(RTAS_ERROR_LOG_MAX, GFP_KERNEL);
-
        spin_lock_irqsave(&rtas.lock, flags);
 
-       rtas.args = args;
-       enter_rtas(__pa(&rtas.args));
-       args = rtas.args;
-
-       args.rets = &args.args[nargs];
-
-       /* A -1 return code indicates that the last command couldn't
-          be completed due to a hardware error. */
-       if (args.rets[0] == -1) {
-               err_rc = __fetch_rtas_last_error();
-               if ((err_rc == 0) && buff_copy) {
-                       memcpy(buff_copy, rtas_err_buf, RTAS_ERROR_LOG_MAX);
-               }
-       }
+       get_paca()->xRtas = args;
+       enter_rtas(__pa(&get_paca()->xRtas));
+       args = get_paca()->xRtas;
 
        spin_unlock_irqrestore(&rtas.lock, flags);
 
-       if (buff_copy) {
-               if ((args.rets[0] == -1) && (err_rc == 0)) {
-                       log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
-               }
-               kfree(buff_copy);
-       }
+       args.rets  = (rtas_arg_t *)&(args.args[nargs]);
+       if (args.rets[0] == -1)
+               log_rtas_error(&args);
 
        /* Copy out args. */
        if (copy_to_user(uargs->args + nargs,
@@ -482,25 +503,21 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-/* This version can't take the spinlock, because it never returns */
-
-struct rtas_args rtas_stop_self_args = {
-       /* The token is initialized for real in setup_system() */
-       .token = RTAS_UNKNOWN_SERVICE,
-       .nargs = 0,
-       .nret = 1,
-       .rets = &rtas_stop_self_args.args[0],
-};
+/* This version can't take the spinlock. */
 
 void rtas_stop_self(void)
 {
-       struct rtas_args *rtas_args = &rtas_stop_self_args;
+       struct rtas_args *rtas_args = &(get_paca()->xRtas);
 
        local_irq_disable();
 
+       rtas_args->token = rtas_token("stop-self");
        BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE);
+       rtas_args->nargs = 0;
+       rtas_args->nret  = 1;
+       rtas_args->rets  = &(rtas_args->args[0]);
 
-       printk("cpu %u (hwid %u) Ready to die...\n",
+       printk("%u %u Ready to die...\n",
               smp_processor_id(), hard_smp_processor_id());
        enter_rtas(__pa(rtas_args));