Skip to contentSkip to conversation

Clean up prom.c and related files

PATCH New Paul Mackerras 1 participant 1 message Jun 24, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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. Please apply.

arch/ppc64/kernel/eeh.c +4 -3
diff -urN linux-2.5/arch/ppc64/kernel/eeh.c prom-cleanup/arch/ppc64/kernel/eeh.c
@@ -365,7 +365,8 @@
 	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 @@
 		 * 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 {
arch/ppc64/kernel/pSeries_nvram.c +4 -2
diff -urN linux-2.5/arch/ppc64/kernel/pSeries_nvram.c prom-cleanup/arch/ppc64/kernel/pSeries_nvram.c
@@ -37,7 +37,8 @@
 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_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;
 
arch/ppc64/kernel/pSeries_pci.c +3 -2
diff -urN linux-2.5/arch/ppc64/kernel/pSeries_pci.c prom-cleanup/arch/ppc64/kernel/pSeries_pci.c
@@ -62,7 +62,7 @@
 
 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 @@
 	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);
 	}
arch/ppc64/kernel/prom.c +349 -539

1,546 lines not on this page · raw message

arch/ppc64/kernel/rtas-proc.c +2 -5
diff -urN linux-2.5/arch/ppc64/kernel/rtas-proc.c prom-cleanup/arch/ppc64/kernel/rtas-proc.c
@@ -394,7 +394,7 @@
 		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 @@
 		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 @@
 		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 @@
 		/* 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");
arch/ppc64/kernel/rtas.c +17 -35

154 lines not on this page · raw message

arch/ppc64/kernel/rtas_flash.c +6 -6
diff -urN linux-2.5/arch/ppc64/kernel/rtas_flash.c prom-cleanup/arch/ppc64/kernel/rtas_flash.c
@@ -344,8 +344,8 @@
 	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 @@
 {
 	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 @@
 	}
 
 	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, 
arch/ppc64/kernel/rtc.c +4 -4
diff -urN linux-2.5/arch/ppc64/kernel/rtc.c prom-cleanup/arch/ppc64/kernel/rtc.c
@@ -346,13 +346,13 @@
 #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_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");
arch/ppc64/kernel/scanlog.c +6 -6
diff -urN linux-2.5/arch/ppc64/kernel/scanlog.c prom-cleanup/arch/ppc64/kernel/scanlog.c
@@ -49,7 +49,7 @@
         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 @@
 		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 @@
 			     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 @@
 	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;
arch/ppc64/kernel/setup.c +4 -5
diff -urN linux-2.5/arch/ppc64/kernel/setup.c prom-cleanup/arch/ppc64/kernel/setup.c
@@ -165,7 +165,7 @@
 		  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
@@ -233,12 +233,11 @@
 #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++;
arch/ppc64/kernel/smp.c +1 -1
diff -urN linux-2.5/arch/ppc64/kernel/smp.c prom-cleanup/arch/ppc64/kernel/smp.c
@@ -241,7 +241,7 @@
  */
 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");
arch/ppc64/kernel/traps.c +2 -2
diff -urN linux-2.5/arch/ppc64/kernel/traps.c prom-cleanup/arch/ppc64/kernel/traps.c
@@ -172,9 +172,9 @@
  */
 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
 
arch/ppc64/kernel/xics.c +18 -19
diff -urN linux-2.5/arch/ppc64/kernel/xics.c prom-cleanup/arch/ppc64/kernel/xics.c
@@ -276,7 +276,7 @@
 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));
@@ -288,7 +288,7 @@
 				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;
 	}
 
@@ -296,14 +296,14 @@
 	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)
@@ -312,7 +312,7 @@
 	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;
 	}
 
@@ -321,7 +321,7 @@
 	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;
 	}
 }
@@ -613,8 +613,8 @@
 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 allcpus = CPU_MASK_ALL;
 	cpumask_t tmp = CPU_MASK_NONE;
@@ -623,11 +623,11 @@
 	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;
 	}
 
@@ -646,7 +646,7 @@
 
 	if (status) {
 		printk(KERN_ERR "xics_set_affinity irq=%d ibm,set-xive "
-		       "returns %ld\n", irq, status);
+		       "returns %d\n", irq, status);
 		return;
 	}
 }
@@ -657,10 +657,10 @@
 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);
@@ -671,7 +671,7 @@
 
 	/* 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... */
@@ -694,11 +694,10 @@
 
 		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;
 		}
@@ -721,7 +720,7 @@
 				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:
include/asm-ppc64/prom.h +1 -1
diff -urN linux-2.5/include/asm-ppc64/prom.h prom-cleanup/include/asm-ppc64/prom.h
@@ -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;
 
include/asm-ppc64/rtas.h +2 -2
diff -urN linux-2.5/include/asm-ppc64/rtas.h prom-cleanup/include/asm-ppc64/rtas.h
@@ -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 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);