Commit fe3a3a65 authored by Paul Mackerras's avatar Paul Mackerras Committed by Linus Torvalds

[PATCH] ppc64: clean up prom.c and related files

Somebody back in the mists of time decided that call_prom and rtas_call
should return longs even though both of those bits of firmware run in
32-bit mode and produce a 32-bit result.  To make life more interesting,
the 32-bit result gets zero-extended to 64 bits, which makes checking
for a -1 return value more complicated than it should be.

This patch changes call_prom and rtas_call to return an int, and makes
the corresponding changes to use ints for the variables used to hold
those return values. 

While I was doing this I finally got annoyed enough with the strings of
prom_print() and prom_print_hex() calls that we do to write a simple
prom_printf.  I deliberately didn't use snprintf because the execution
environment is weird at this point - we aren't running at the address we
are linked at just yet - and I didn't want to inflict that on any code
outside this file.  I also did a prom_debug() macro, which eliminated a
few ifdefs. 

There are also a bunch of other minor cleanups.  This patch makes very
few algorithmic changes but does get rid of a lot of casts.  :)

I have been running with this patch for a couple of weeks, and Anton has
tested it too.
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 91bc6523
......@@ -365,7 +365,8 @@ unsigned long eeh_check_failure(void *token, unsigned long val)
unsigned long addr;
struct pci_dev *dev;
struct device_node *dn;
unsigned long ret, rets[2];
unsigned long ret;
int rets[2];
static spinlock_t lock = SPIN_LOCK_UNLOCKED;
/* dont want this on the stack */
static unsigned char slot_err_buf[RTAS_ERROR_LOG_MAX];
......@@ -444,11 +445,11 @@ unsigned long eeh_check_failure(void *token, unsigned long val)
* can use it here.
*/
if (panic_on_oops) {
panic("EEH: MMIO failure (%ld) on device:%s %s\n",
panic("EEH: MMIO failure (%d) on device:%s %s\n",
rets[0], pci_name(dev), pci_pretty_name(dev));
} else {
__get_cpu_var(ignored_failures)++;
printk(KERN_INFO "EEH: MMIO failure (%ld) on device:%s %s\n",
printk(KERN_INFO "EEH: MMIO failure (%d) on device:%s %s\n",
rets[0], pci_name(dev), pci_pretty_name(dev));
}
} else {
......
......@@ -37,7 +37,8 @@ static spinlock_t nvram_lock = SPIN_LOCK_UNLOCKED;
static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index)
{
unsigned int i;
unsigned long len, done;
unsigned long len;
int done;
unsigned long flags;
char *p = buf;
......@@ -80,7 +81,8 @@ static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index)
static ssize_t pSeries_nvram_write(char *buf, size_t count, loff_t *index)
{
unsigned int i;
unsigned long len, done;
unsigned long len;
int done;
unsigned long flags;
const char *p = buf;
......
......@@ -62,7 +62,7 @@ extern unsigned long pci_probe_only;
static int rtas_read_config(struct device_node *dn, int where, int size, u32 *val)
{
unsigned long returnval = ~0L;
int returnval = -1;
unsigned long buid, addr;
int ret;
......@@ -72,7 +72,8 @@ static int rtas_read_config(struct device_node *dn, int where, int size, u32 *va
addr = (dn->busno << 16) | (dn->devfn << 8) | where;
buid = dn->phb->buid;
if (buid) {
ret = rtas_call(ibm_read_pci_config, 4, 2, &returnval, addr, buid >> 32, buid & 0xffffffff, size);
ret = rtas_call(ibm_read_pci_config, 4, 2, &returnval,
addr, buid >> 32, buid & 0xffffffff, size);
} else {
ret = rtas_call(read_pci_config, 2, 2, &returnval, addr, size);
}
......
This diff is collapsed.
......@@ -394,7 +394,7 @@ static ssize_t ppc_rtas_clock_read(struct file * file, char * buf,
size_t count, loff_t *ppos)
{
unsigned int year, mon, day, hour, min, sec;
unsigned long *ret = kmalloc(4*8, GFP_KERNEL);
int ret[8];
int n, sn, error;
char stkbuf[40]; /* its small, its on stack */
......@@ -411,7 +411,6 @@ static ssize_t ppc_rtas_clock_read(struct file * file, char * buf,
n = scnprintf (stkbuf, sizeof(stkbuf), "%lu\n",
mktime(year, mon, day, hour, min, sec));
}
kfree(ret);
sn = strlen (stkbuf) +1;
if (*ppos >= sn)
......@@ -434,7 +433,6 @@ static int ppc_rtas_sensor_read(char * buf, char ** start, off_t off,
int count, int *eof, void *data)
{
int i,j,n;
unsigned long ret;
int state, error;
char *buffer;
int get_sensor_state = rtas_token("get-sensor-state");
......@@ -464,11 +462,10 @@ static int ppc_rtas_sensor_read(char * buf, char ** start, off_t off,
/* A sensor may have multiple instances */
while (j >= 0) {
error = rtas_call(get_sensor_state, 2, 2, &ret,
error = rtas_call(get_sensor_state, 2, 2, &state,
sensors.sensor[i].token,
sensors.sensor[i].quant - j);
state = (int) ret;
n += ppc_rtas_process_sensor(sensors.sensor[i], state,
error, buffer+n );
n += sprintf (buffer+n, "\n");
......
......@@ -139,15 +139,13 @@ log_rtas_error(struct rtas_args *rtas_args)
log_error(rtas_err_buf, ERR_TYPE_RTAS_LOG, 0);
}
long
rtas_call(int token, int nargs, int nret,
unsigned long *outputs, ...)
int rtas_call(int token, int nargs, int nret, int *outputs, ...)
{
va_list list;
int i, logit = 0;
unsigned long s;
struct rtas_args *rtas_args;
long ret;
int ret;
PPCDBG(PPCDBG_RTAS, "Entering rtas_call\n");
PPCDBG(PPCDBG_RTAS, "\ttoken = 0x%x\n", token);
......@@ -167,8 +165,8 @@ rtas_call(int token, int nargs, int nret,
rtas_args->rets = (rtas_arg_t *)&(rtas_args->args[nargs]);
va_start(list, outputs);
for (i = 0; i < nargs; ++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]);
rtas_args->args[i] = va_arg(list, rtas_arg_t);
PPCDBG(PPCDBG_RTAS, "\tnarg[%d] = 0x%x\n", i, rtas_args->args[i]);
}
va_end(list);
......@@ -191,7 +189,7 @@ rtas_call(int token, int nargs, int nret,
if (nret > 1 && outputs != NULL)
for (i = 0; i < nret-1; ++i)
outputs[i] = rtas_args->rets[i+1];
ret = (ulong)((nret > 0) ? rtas_args->rets[0] : 0);
ret = (nret > 0)? rtas_args->rets[0]: 0;
/* Gotta do something different here, use global lock for now... */
spin_unlock_irqrestore(&rtas.lock, s);
......@@ -227,20 +225,13 @@ 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(1) {
rc = (int) rtas_call(token, 1, 2, &powerlevel, powerdomain);
if (rc == RTAS_BUSY)
while ((rc = rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
udelay(1);
else
break;
}
*level = (int) powerlevel;
return rc;
}
......@@ -249,25 +240,21 @@ 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 = (int) rtas_call(token, 2, 2, &returned_level, powerdomain,
level);
rc = rtas_call(token, 2, 2, setlevel, 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;
}
......@@ -276,25 +263,21 @@ 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 = (int) rtas_call(token, 2, 2, &returned_state, sensor,
index);
rc = rtas_call(token, 2, 2, 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;
}
......@@ -309,8 +292,7 @@ rtas_set_indicator(int indicator, int index, int new_value)
return RTAS_UNKNOWN_OP;
while (1) {
rc = (int) rtas_call(token, 3, 1, NULL, indicator, index,
new_value);
rc = rtas_call(token, 3, 1, NULL, indicator, index, new_value);
if (rc == RTAS_BUSY)
udelay(1);
else if (rtas_is_extended_busy(rc)) {
......@@ -409,7 +391,7 @@ rtas_restart(char *cmd)
if (rtas_firmware_flash_list.next)
rtas_flash_firmware();
printk("RTAS system-reboot returned %ld\n",
printk("RTAS system-reboot returned %d\n",
rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
for (;;);
}
......@@ -420,8 +402,8 @@ 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 %ld\n",
rtas_call(rtas_token("power-off"), 2, 1, NULL,0xffffffff,0xffffffff));
printk("RTAS power-off returned %d\n",
rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
for (;;);
}
......@@ -438,7 +420,7 @@ static char rtas_os_term_buf[2048];
void rtas_os_term(char *str)
{
long status;
int status;
snprintf(rtas_os_term_buf, 2048, "OS panic: %s", str);
......@@ -449,7 +431,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 %ld\n",
printk(KERN_EMERG "ibm,os-term call failed %d\n",
status);
} while (status == RTAS_BUSY);
}
......
......@@ -344,8 +344,8 @@ static void manage_flash(struct rtas_manage_flash_t *args_buf)
s32 rc;
while (1) {
rc = (s32) rtas_call(rtas_token("ibm,manage-flash-image"), 1,
1, NULL, (long) args_buf->op);
rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1,
1, NULL, args_buf->op);
if (rc == RTAS_RC_BUSY)
udelay(1);
else if (rtas_is_extended_busy(rc)) {
......@@ -429,15 +429,15 @@ static void validate_flash(struct rtas_validate_flash_t *args_buf)
{
int token = rtas_token("ibm,validate-flash-image");
unsigned int wait_time;
long update_results;
int update_results;
s32 rc;
rc = 0;
while(1) {
spin_lock(&rtas_data_buf_lock);
memcpy(rtas_data_buf, args_buf->buf, VALIDATE_BUF_SIZE);
rc = (s32) rtas_call(token, 2, 2, &update_results,
__pa(rtas_data_buf), args_buf->buf_size);
rc = rtas_call(token, 2, 2, &update_results,
(u32) __pa(rtas_data_buf), args_buf->buf_size);
memcpy(args_buf->buf, rtas_data_buf, VALIDATE_BUF_SIZE);
spin_unlock(&rtas_data_buf_lock);
......@@ -451,7 +451,7 @@ static void validate_flash(struct rtas_validate_flash_t *args_buf)
}
args_buf->status = rc;
args_buf->update_results = (u32) update_results;
args_buf->update_results = update_results;
}
static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
......
......@@ -346,13 +346,13 @@ void iSeries_get_boot_time(struct rtc_time *tm)
#define RTAS_CLOCK_BUSY (-2)
void pSeries_get_boot_time(struct rtc_time *rtc_tm)
{
unsigned long ret[8];
int ret[8];
int error, wait_time;
unsigned long max_wait_tb;
max_wait_tb = __get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT;
do {
error = rtas_call(rtas_token("get-time-of-day"), 0, 8, (void *)&ret);
error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret);
if (error == RTAS_CLOCK_BUSY || rtas_is_extended_busy(error)) {
wait_time = rtas_extended_busy_delay_time(error);
/* This is boot time so we spin. */
......@@ -381,13 +381,13 @@ void pSeries_get_boot_time(struct rtc_time *rtc_tm)
*/
void pSeries_get_rtc_time(struct rtc_time *rtc_tm)
{
unsigned long ret[8];
int ret[8];
int error, wait_time;
unsigned long max_wait_tb;
max_wait_tb = __get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT;
do {
error = rtas_call(rtas_token("get-time-of-day"), 0, 8, (void *)&ret);
error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret);
if (error == RTAS_CLOCK_BUSY || rtas_is_extended_busy(error)) {
if (in_interrupt()) {
printk(KERN_WARNING "error: reading clock would delay interrupt\n");
......
......@@ -49,7 +49,7 @@ static ssize_t scanlog_read(struct file *file, char *buf,
struct inode * inode = file->f_dentry->d_inode;
struct proc_dir_entry *dp;
unsigned int *data;
unsigned long status;
int status;
unsigned long len, off;
unsigned int wait_time;
......@@ -81,11 +81,11 @@ static ssize_t scanlog_read(struct file *file, char *buf,
spin_lock(&rtas_data_buf_lock);
memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);
status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,
__pa(rtas_data_buf), count);
(u32) __pa(rtas_data_buf), (u32) count);
memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);
spin_unlock(&rtas_data_buf_lock);
DEBUG("status=%ld, data[0]=%x, data[1]=%x, data[2]=%x\n",
DEBUG("status=%d, data[0]=%x, data[1]=%x, data[2]=%x\n",
status, data[0], data[1], data[2]);
switch (status) {
case SCANLOG_COMPLETE:
......@@ -133,7 +133,7 @@ static ssize_t scanlog_write(struct file * file, const char * buf,
size_t count, loff_t *ppos)
{
char stkbuf[20];
unsigned long status;
int status;
if (count > 19) count = 19;
if (copy_from_user (stkbuf, buf, count)) {
......@@ -144,8 +144,8 @@ static ssize_t scanlog_write(struct file * file, const char * buf,
if (buf) {
if (strncmp(stkbuf, "reset", 5) == 0) {
DEBUG("reset scanlog\n");
status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, NULL, 0);
DEBUG("rtas returns %ld\n", status);
status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, 0, 0);
DEBUG("rtas returns %d\n", status);
} else if (strncmp(stkbuf, "debugon", 7) == 0) {
printk(KERN_ERR "scanlog: debug on\n");
scanlog_debug = 1;
......
......@@ -164,7 +164,7 @@ void setup_system(unsigned long r3, unsigned long r4, unsigned long r5,
unsigned long r6, unsigned long r7)
{
#if defined(CONFIG_SMP) && defined(CONFIG_PPC_PSERIES)
unsigned int ret, i;
int ret, i;
#endif
#ifdef CONFIG_XMON_DEFAULT
......@@ -232,12 +232,11 @@ void setup_system(unsigned long r3, unsigned long r4, unsigned long r5,
#ifdef CONFIG_SMP
/* Start secondary threads on SMT systems */
for (i = 0; i < NR_CPUS; i++) {
if(cpu_available(i) && !cpu_possible(i)) {
if (cpu_available(i) && !cpu_possible(i)) {
printk("%16.16x : starting thread\n", i);
rtas_call(rtas_token("start-cpu"), 3, 1,
(void *)&ret,
rtas_call(rtas_token("start-cpu"), 3, 1, &ret,
get_hard_smp_processor_id(i),
*((unsigned long *)pseries_secondary_smp_init),
(u32)*((unsigned long *)pseries_secondary_smp_init),
i);
cpu_set(i, cpu_possible_map);
systemcfg->processorCount++;
......
......@@ -241,7 +241,7 @@ static void __devinit smp_openpic_setup_cpu(int cpu)
*/
static int query_cpu_stopped(unsigned int pcpu)
{
long cpu_status;
int cpu_status;
int status, qcss_tok;
qcss_tok = rtas_token("query-cpu-stopped-state");
......
......@@ -172,9 +172,9 @@ static struct rtas_error_log *FWNMI_get_errinfo(struct pt_regs *regs)
*/
static void FWNMI_release_errinfo(void)
{
unsigned long ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
if (ret != 0)
printk("FWNMI: nmi-interlock failed: %ld\n", ret);
printk("FWNMI: nmi-interlock failed: %d\n", ret);
}
#endif
......
......@@ -275,7 +275,7 @@ static int get_irq_server(unsigned int irq)
static void xics_enable_irq(unsigned int virq)
{
unsigned int irq;
long call_status;
int call_status;
unsigned int server;
irq = virt_irq_to_real(irq_offset_down(virq));
......@@ -287,7 +287,7 @@ static void xics_enable_irq(unsigned int virq)
DEFAULT_PRIORITY);
if (call_status != 0) {
printk(KERN_ERR "xics_enable_irq: irq=%x: ibm_set_xive "
"returned %lx\n", irq, call_status);
"returned %x\n", irq, call_status);
return;
}
......@@ -295,14 +295,14 @@ static void xics_enable_irq(unsigned int virq)
call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
if (call_status != 0) {
printk(KERN_ERR "xics_enable_irq: irq=%x: ibm_int_on "
"returned %lx\n", irq, call_status);
"returned %x\n", irq, call_status);
return;
}
}
static void xics_disable_real_irq(unsigned int irq)
{
long call_status;
int call_status;
unsigned int server;
if (irq == XICS_IPI)
......@@ -311,7 +311,7 @@ static void xics_disable_real_irq(unsigned int irq)
call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
if (call_status != 0) {
printk(KERN_ERR "xics_disable_real_irq: irq=%x: "
"ibm_int_off returned %lx\n", irq, call_status);
"ibm_int_off returned %x\n", irq, call_status);
return;
}
......@@ -320,7 +320,7 @@ static void xics_disable_real_irq(unsigned int irq)
call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server, 0xff);
if (call_status != 0) {
printk(KERN_ERR "xics_disable_irq: irq=%x: ibm_set_xive(0xff)"
" returned %lx\n", irq, call_status);
" returned %x\n", irq, call_status);
return;
}
}
......@@ -612,8 +612,8 @@ void xics_request_IPIs(void)
static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
{
unsigned int irq;
long status;
unsigned long xics_status[2];
int status;
int xics_status[2];
unsigned long newmask;
cpumask_t tmp = CPU_MASK_NONE;
......@@ -621,11 +621,11 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
if (irq == XICS_IPI || irq == NO_IRQ)
return;
status = rtas_call(ibm_get_xive, 1, 3, (void *)&xics_status, irq);
status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
if (status) {
printk(KERN_ERR "xics_set_affinity: irq=%d ibm,get-xive "
"returns %ld\n", irq, status);
"returns %d\n", irq, status);
return;
}
......@@ -644,7 +644,7 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
if (status) {
printk(KERN_ERR "xics_set_affinity irq=%d ibm,set-xive "
"returns %ld\n", irq, status);
"returns %d\n", irq, status);
return;
}
}
......@@ -655,10 +655,10 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
void xics_migrate_irqs_away(void)
{
int set_indicator = rtas_token("set-indicator");
const unsigned long giqs = 9005UL; /* Global Interrupt Queue Server */
unsigned long status = 0;
const unsigned int giqs = 9005UL; /* Global Interrupt Queue Server */
int status = 0;
unsigned int irq, cpu = smp_processor_id();
unsigned long xics_status[2];
int xics_status[2];
unsigned long flags;
BUG_ON(set_indicator == RTAS_UNKNOWN_SERVICE);
......@@ -669,7 +669,7 @@ void xics_migrate_irqs_away(void)
/* Refuse any new interrupts... */
rtas_call(set_indicator, 3, 1, &status, giqs,
hard_smp_processor_id(), 0UL);
hard_smp_processor_id(), 0);
WARN_ON(status != 0);
/* Allow IPIs again... */
......@@ -692,11 +692,10 @@ void xics_migrate_irqs_away(void)
spin_lock_irqsave(&desc->lock, flags);
status = rtas_call(ibm_get_xive, 1, 3, (void *)&xics_status,
irq);
status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
if (status) {
printk(KERN_ERR "migrate_irqs_away: irq=%d "
"ibm,get-xive returns %ld\n",
"ibm,get-xive returns %d\n",
irq, status);
goto unlock;
}
......@@ -719,7 +718,7 @@ void xics_migrate_irqs_away(void)
irq, xics_status[0], xics_status[1]);
if (status)
printk(KERN_ERR "migrate_irqs_away irq=%d "
"ibm,set-xive returns %ld\n",
"ibm,set-xive returns %d\n",
irq, status);
unlock:
......
......@@ -25,7 +25,7 @@
#define LONG_MSW(X) (((unsigned long)X) >> 32)
typedef u32 phandle;
typedef void *ihandle;
typedef u32 ihandle;
typedef u32 phandle32;
typedef u32 ihandle32;
......
......@@ -37,7 +37,7 @@
* Where n_in is the number of input parameters and
* n_out is the number of output parameters
*
* If the "string" is invalid on this system, RTAS_UNKOWN_SERVICE
* If the "string" is invalid on this system, RTAS_UNKNOWN_SERVICE
* will be returned as a token. rtas_call() does look for this
* token and error out gracefully so rtas_call(rtas_token("str"), ...)
* may be safely used for one-shot calls to RTAS.
......@@ -168,7 +168,7 @@ extern struct rtas_t rtas;
extern void enter_rtas(unsigned long);
extern int rtas_token(const char *service);
extern long rtas_call(int token, int, int, unsigned long *, ...);
extern int rtas_call(int token, int, int, int *, ...);
extern void call_rtas_display_status(char);
extern void rtas_restart(char *cmd);
extern void rtas_power_off(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment