[parisc-linux-cvs] 64-bit cleanup for the sim700 driver.

Ryan Bradetich rbradetich@uswest.net
Mon, 19 Mar 2001 23:48:23 -0700


This is a multi-part message in MIME format.
--------------9D0E149893690024ECB0A47C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This patch allows the sim700 driver to compile cleanly
under the 32 and 64 bit compilers.  I have tested this
patch on the 32 bit kernel, and it works.  Unfortunately,
I have not been able to test it on the 64-bit kernel because
I'm still having issues with the sym53c8xx driver and a
HPMC :(

- Ryan


--------------9D0E149893690024ECB0A47C
Content-Type: text/plain; charset=us-ascii;
 name="sim700.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sim700.diff"

? sim700.diff
? drivers/scsi/sim700.c.full_reset
? drivers/scsi/sim700.c.handle_idd
? drivers/scsi/sim700.c.handle_phase_mismatch
? drivers/scsi/sim700.c.sim700_intr_handle
? drivers/scsi/foo
? drivers/scsi/sim700.c.handle_script_int
? drivers/scsi/sim700.c.run_command
? drivers/scsi/sim700.c.sim700_init_host
? drivers/scsi/sim700.c.sim700_driver_init
? drivers/scsi/blah.c
? drivers/scsi/blah1.c
? drivers/scsi/blah.diff
? drivers/scsi/foo1
? drivers/scsi/sim700.h.patch
Index: drivers/scsi/sim700.c
===================================================================
RCS file: /home/cvs/parisc/linux/drivers/scsi/sim700.c,v
retrieving revision 1.23
diff -u -p -r1.23 sim700.c
--- sim700.c	2001/01/25 09:46:41	1.23
+++ sim700.c	2001/03/20 06:36:28
@@ -620,49 +620,49 @@ sim700_driver_init (struct Scsi_Host *ho
         struct sim700_target *targdata = TARGDATA(targ);
 
 	targdata->ba = (struct sim700_target *)
-			(hostdata->targets_busaddr + (targ << PAGE_SHIFT));
+			(hostdata->targets_busaddr + (unsigned long)(targ << PAGE_SHIFT));
 	targdata->msg_reject = MESSAGE_REJECT;
 	memcpy (targdata->script, SCRIPT, sizeof(SCRIPT));
 	for (i = 0; i < PATCHES; i++)
-	    targdata->script[LABELPATCHES[i]] += (u32)targdata->ba->script;
+	    targdata->script[LABELPATCHES[i]] += low32(targdata->ba->script);
 	if (NCR_LE_CPU_BE) {
 	    for (i = 0; i < sizeof(SCRIPT)/4; i++)
 		targdata->script[i] = cpu_to_le32(targdata->script[i]);
 	}
 	patch_add_32 (targdata->script, 0, msg_reject, 
-    		(u32)&(targdata->ba->msg_reject));
+    		low32(&(targdata->ba->msg_reject)));
 #if 0	/* test1_src/dst need to be in targdata if we ever use them */
 	patch_add_32 (targdata->script, 0, test1_src, 
-    		(u32)&(hostbus->test1_src));
+    		low32(&(hostbus->test1_src));)
 	patch_add_32 (targdata->script, 0, test1_dst, 
-    		(u32)&(hostbus->test1_dst));
+    		low32(&(hostbus->test1_dst)));
 #endif
 	patch_add_32 (targdata->script, 0, reselected_identify, 
-    		(u32)&(targdata->ba->reselected_identify));
+    		low32(&(targdata->ba->reselected_identify)));
 	patch_abs_8c (targdata->script, 0, targ_select, 1 << targ);
 	patch_add_32 (targdata->script, 0, targ_cdb, 
-    		(u32)&(targdata->ba->targ_cdb));
+    		low32(&(targdata->ba->targ_cdb)));
 	patch_add_32 (targdata->script, 0, targ_msgout, 
-    		(u32)&(targdata->ba->targ_msgout));
+    		low32(&(targdata->ba->targ_msgout)));
 	patch_add_32 (targdata->script, 0, targ_msgin, 
-    		(u32)&(targdata->ba->targ_msgin));
+    		low32(&(targdata->ba->targ_msgin)));
 	patch_add_32 (targdata->script, 0, targ_status, 
-    		(u32)&(targdata->ba->targ_status));
+    		low32(&(targdata->ba->targ_status)));
 	/* Build 'JUMP end_data_trans' at end of din/dout scripts */
 	targdata->din_script_start_index =
-	    ((u32)targdata->din_script - (u32)targdata->script)/sizeof(u32);
+	    (low32(targdata->din_script) - low32(targdata->script))/sizeof(u32);
 	targdata->din_script_end_index =
 	    targdata->din_script_start_index + MAX_SG * 2;
 	targdata->din_script[MAX_SG*2] = cpu_to_ncr32(0x80080000);
 	targdata->din_script[MAX_SG*2+1] =
-		cpu_to_ncr32((u32)(targdata->ba->script + Ent_end_data_trans/4));
+		cpu_to_ncr32(low32(targdata->ba->script + Ent_end_data_trans/4));
 	targdata->dout_script_start_index =
-	    ((u32)targdata->dout_script - (u32)targdata->script)/sizeof(u32);
+	    (low32(targdata->dout_script) - low32(targdata->script))/sizeof(u32);
 	targdata->dout_script_end_index =
 	    targdata->dout_script_start_index + MAX_SG * 2;
 	targdata->dout_script[MAX_SG*2] = cpu_to_ncr32(0x80080000);
 	targdata->dout_script[MAX_SG*2+1] =
-		cpu_to_ncr32((u32)(targdata->ba->script + Ent_end_data_trans/4));
+		cpu_to_ncr32(low32(targdata->ba->script + Ent_end_data_trans/4));
 	targdata->bounce.buf = hostdata->bounce_bufs + (targ * PAGE_SIZE/8);
 	if (hostdata->chip == 700) {
 	    /* Need to zap the register-to-register instructions that are
@@ -671,13 +671,13 @@ sim700_driver_init (struct Scsi_Host *ho
 	     * next instruction.
 	     */
 	    targdata->script[Ent_zap700a/4] = cpu_to_ncr32(0x80080000);
-	    targdata->script[Ent_zap700a/4+1] = cpu_to_ncr32((u32)(targdata->ba->script + Ent_zap700a/4 + 2));
+	    targdata->script[Ent_zap700a/4+1] = cpu_to_ncr32(low32(targdata->ba->script + Ent_zap700a/4 + 2));
 	    targdata->script[Ent_zap700b/4] = cpu_to_ncr32(0x80080000);
-	    targdata->script[Ent_zap700b/4+1] = cpu_to_ncr32((u32)(targdata->ba->script + Ent_zap700b/4 + 2));
+	    targdata->script[Ent_zap700b/4+1] = cpu_to_ncr32(low32(targdata->ba->script + Ent_zap700b/4 + 2));
 	    targdata->script[Ent_zap700c/4] = cpu_to_ncr32(0x80080000);
-	    targdata->script[Ent_zap700c/4+1] = cpu_to_ncr32((u32)(targdata->ba->script + Ent_zap700c/4 + 2));
+	    targdata->script[Ent_zap700c/4+1] = cpu_to_ncr32(low32(targdata->ba->script + Ent_zap700c/4 + 2));
 	    targdata->script[Ent_zap700d/4] = cpu_to_ncr32(0x80080000);
-	    targdata->script[Ent_zap700d/4+1] = cpu_to_ncr32((u32)(targdata->ba->script + Ent_zap700d/4 + 2));
+	    targdata->script[Ent_zap700d/4+1] = cpu_to_ncr32(low32(targdata->ba->script + Ent_zap700d/4 + 2));
 	}
     }
     hostdata->state = STATE_INITIALISED;
@@ -821,9 +821,8 @@ handle_idd (struct Scsi_Host * host, Scs
     struct sim700_target *targdata = TARGDATA(cmd->target);
     u32 resume_offset = 0, index;
     int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
+    index = low32((u32 *)(unsigned long)NCR_read32(DSP_REG) - targdata->ba->script);
 
-    index = (u32)((u32 *)(NCR_read32(DSP_REG)) - targdata->ba->script);
-
     switch (index) {
     case Ent_wait_disc_complete/4 + 2:
 	if (!cmd->use_sg) {
@@ -888,7 +887,7 @@ handle_phase_mismatch (struct Scsi_Host 
     unsigned char sbcl;
 
     sbcl = NCR_read8(SBCL_REG) & SBCL_PHASE_MASK;
-    index = (u32)((u32 *)(NCR_read32(DSP_REG)) - targdata->ba->script);
+    index = low32((u32 *)(unsigned long)NCR_read32(DSP_REG) - targdata->ba->script);
 
     DEB(DEB_PMM, printk("scsi%d: Phase mismatch, phase %s (%x) at script[0x%x]\n",
 	host->host_no, sbcl_to_phase(sbcl), sbcl, index));
@@ -931,7 +930,7 @@ handle_phase_mismatch (struct Scsi_Host 
 
 	sg_id = (index - targdata->din_script_start_index - 2) / 2;
 	patch_abs_32(targdata->script, 0, targ_din_script,
-		(u32)(targdata->ba->din_script + sg_id * 2));
+		low32(targdata->ba->din_script + sg_id * 2));
 	olen = ncr32_to_cpu(targdata->din_script[sg_id * 2]) & 0x00ffffff;
 	oaddr = ncr32_to_cpu(targdata->din_script[sg_id * 2 + 1]);
 	residual = datapath_residual (host);
@@ -962,7 +961,7 @@ handle_phase_mismatch (struct Scsi_Host 
 
 	sg_id = (index - targdata->dout_script_start_index - 2) / 2;
 	patch_abs_32(targdata->script, 0, targ_dout_script,
-		(u32)(targdata->ba->dout_script + sg_id * 2));
+		low32(targdata->ba->dout_script + sg_id * 2));
 	olen = ncr32_to_cpu(targdata->dout_script[sg_id * 2]) & 0x00ffffff;
 	oaddr = ncr32_to_cpu(targdata->dout_script[sg_id * 2 + 1]);
 	residual = datapath_residual (host);
@@ -1072,7 +1071,7 @@ handle_script_int(struct Scsi_Host * hos
 	break;
     case A_int_reselected:
 	targdata->script[Ent_patch_resume_reselect/4+1] = cpu_to_ncr32(
-		(u32)(targdata->ba->script + targdata->resume_offset/4));
+		low32(targdata->ba->script + targdata->resume_offset/4));
 	resume_offset = Ent_resume_reselect;
 	break;
     case A_int_data_bad_phase:
@@ -1170,7 +1169,7 @@ sim700_intr_handle(int irq, void *dev_id
 	DEB(DEB_INTS, printk("scsi%d: Int %d, istat %02x, sstat0 %02x "
 		"dstat %02x, dsp [%04x], target %x\n",
 	    host->host_no, sim700_intrs, istat, sstat0, dstat,
-	    (u32 *)(dsp) - targdata->ba->script, target));
+	    low32((u32 *)(unsigned long)dsp - targdata->ba->script), target));
 	{
 	    /* Should do this later, when we know if it is relevant */
 	    u8 *p = targdata->targ_msgin;
@@ -1243,8 +1242,8 @@ sim700_intr_handle(int irq, void *dev_id
 	    printk("scsi%d: Int %d, istat %02x, sstat0 %02x "
 		"dstat %02x, dsp [%04x], target %x, dsps %08x\n",
 		host->host_no, sim700_intrs, istat, sstat0, dstat,
-		(u32 *)(NCR_read32(DSP_REG)) - targdata->ba->script,
-		target, dsps);
+		low32((u32 *)(unsigned long)NCR_read32(DSP_REG) - 
+	  	(unsigned long)targdata->ba->script), target, dsps);
 	    /* resume_offset is zero, which will cause a host reset */
 	}
 	else if (sstat0 & SSTAT0_700_STO) {
@@ -1255,7 +1254,7 @@ sim700_intr_handle(int irq, void *dev_id
 	    resume_offset = Ent_reselect;
 	}
 	else if (hostdata->chip == 700 && (dstat & DSTAT_ABRT)) {
-	    u32 offset = (dsp - (u32)targdata->ba->script)/4;
+	    u32 offset = (dsp - low32(targdata->ba->script)/4);
 	    if (offset == Ent_reselect/4 + 4) {
 		DEB(DEB_DISC, printk("scsi%d: wait reselect aborted\n", host->host_no));
 		resume_offset = Ent_patch_selection;
@@ -1371,7 +1370,7 @@ bail_out:
 		for (i = 0; i < 1024; i += 8)
 			printk ("%p: %08x %08x %08x %08x %08x %08x %08x %08x\n", p+i, p[i], p[i+1], p[i+2], p[i+3], p[i+4], p[i+5], p[i+6], p[i+7]);
 	}
-	start_addr = (u32)(targdata->ba->script+resume_offset/4);
+	start_addr = low32(targdata->ba->script+resume_offset/4);
 	CHECK_WBACK_INV(targdata, PAGE_SIZE);
 
 #ifdef DEBUG_LIMIT_INTS
@@ -1506,9 +1505,9 @@ run_command (struct sim700_hostdata *hos
 	}
     }
     patch_abs_32(targdata->script, 0, targ_din_script,
-	(u32)(targdata->ba->din_script + sg_start));
+	low32(targdata->ba->din_script + sg_start));
     patch_abs_32(targdata->script, 0, targ_dout_script,
-	(u32)(targdata->ba->dout_script + sg_start));
+	low32(targdata->ba->dout_script + sg_start));
 
     hostdata->running = targdata->cur_cmd = cmd;
     hostdata->state = STATE_BUSY;
@@ -1520,7 +1519,7 @@ run_command (struct sim700_hostdata *hos
      * outstanding, and don't wait for reselect, so then we can just write
      * DSP.
      */
-    start_addr = cpu_to_ncr32((u32)(targdata->ba->script+Ent_do_select/4));
+    start_addr = cpu_to_ncr32(low32(targdata->ba->script+Ent_do_select/4));
     TARGDATA(HOST_ID)->script[Ent_patch_selection/4 + 1] = start_addr;
 
     CHECK_WBACK_INV(TARGDATA(HOST_ID), PAGE_SIZE);
@@ -1681,7 +1680,7 @@ sim700_queuecommand(Scsi_Cmnd * cmd, voi
 int
 sim700_init_host(Scsi_Host_Template *tpnt,
 		    int chip,
-		    u32 base_addr,
+		    unsigned long base_addr,
 		    int requested_irq,
 		    u32 options
 		    )
@@ -1734,13 +1733,13 @@ sim700_init_host(Scsi_Host_Template *tpn
     }
     memset((void *)hostdata->targets, 0, PAGE_SIZE << 3);
     scsi_id = 7;
-    printk("sim700: Configuring 53c%d (SCSI-ID %d) at %x, IRQ %d, options %x\n",
+    printk("sim700: Configuring 53c%d (SCSI-ID %d) at %lx, IRQ %d, options %x\n",
 		    chip, scsi_id, base_addr, requested_irq, options);
     DEB(DEB_ANY, printk("sim700: hostdata = %p (%d bytes)\n",
-		    hostdata, sizeof(struct sim700_hostdata)));
+		    hostdata, (u32)sizeof(struct sim700_hostdata)));
     DEB(DEB_ANY, printk("sim700: targdata = %p, %p, ... (%d bytes)\n",
 			    TARGDATA(0), TARGDATA(1),
-			    sizeof(struct sim700_target)));
+			    (u32)sizeof(struct sim700_target)));
     hostdata->options = options;
     hostdata->addr8_flip = (options & OPT_NCR_LE) ? 0 : 3;
     hostdata->chip = chip;
@@ -1765,7 +1764,7 @@ sim700_init_host(Scsi_Host_Template *tpn
     DEB(DEB_ANY,ncr_dump(host));
     /* XXX May want to hit it with a chip reset rather than this... */
     if (ncr_halt(host)) {
-	printk("sim700: Failed to initialise 53c%d at address %x\n",
+	printk("sim700: Failed to initialise 53c%d at address %lx\n",
 		chip, base_addr);
 	goto err4;
     }
@@ -1857,7 +1856,7 @@ sim700_init_host(Scsi_Host_Template *tpn
 	goto err4;
     }
     /* Why bother? Nothing should reselect at this point... */
-    start_addr = (u32)(TARGDATA(HOST_ID)->ba->script+Ent_reselect/4);
+    start_addr = low32(TARGDATA(HOST_ID)->ba->script+Ent_reselect/4);
     CHECK_WBACK_INV(hostdata->targets, PAGE_SIZE << 3);
     NCR_write32(DSP_REG, start_addr);
     hostdata->state = STATE_IDLE;
@@ -1955,7 +1954,7 @@ full_reset(struct Scsi_Host * host)
 	    host->host_no, istat, sstat0, sstat1, dstat);
     printk("scsi%d: dsp = %08x (script[0x%04x]), dsps = %08x, target = %x\n",
 	    host->host_no, dsp,
-	    ((u32)dsp - (u32)targdata->ba->script)/4, dsps, target);
+	    (low32(dsp) - low32(targdata->ba->script))/4, dsps, target);
 
     for (target = 0; target < 7; target++) {
 	if ((cmd = TARGDATA(target)->cur_cmd)) {
@@ -1971,7 +1970,7 @@ full_reset(struct Scsi_Host * host)
     sim700_driver_init(host);
     target = HOST_ID;
     targdata = TARGDATA(target);
-    NCR_write32(DSP_REG, (u32)(TARGDATA(target)->ba->script+Ent_reselect/4));
+    NCR_write32(DSP_REG, low32(TARGDATA(target)->ba->script+Ent_reselect/4));
     hostdata->state = STATE_IDLE;
 
     run_process_issue_queue(hostdata);
Index: drivers/scsi/sim700.h
===================================================================
RCS file: /home/cvs/parisc/linux/drivers/scsi/sim700.h,v
retrieving revision 1.6
diff -u -p -r1.6 sim700.h
--- sim700.h	2001/03/02 04:30:49	1.6
+++ sim700.h	2001/03/20 06:36:29
@@ -850,6 +850,12 @@ int sim700_release(struct Scsi_Host *);
 #define SIDL_REG	SIDL_REG_700
 #define LCRC_REG	LCRC_REG_10
 
+#ifdef __LP64__
+#define low32(x) ((u32)(unsigned long)(x))
+#else
+#define low32(x) ((u32)(x))
+#endif
+
 /* NCR_read8(), etc defined twice here, one with read8, one with inb.
  * Could define once and redefine read8/inb as appropriate.  Probably never
  * need to mix read8 and inb on one architecture, so it can be a compile
@@ -874,14 +880,14 @@ int sim700_release(struct Scsi_Host *);
   {									\
     unsigned long a = (unsigned long)(host->base) + (unsigned long)(address);	\
 									\
-    DEB(DEB_REGS, printk("NCR: %02x => %lx\n", (u32)(value), a));	\
+    DEB(DEB_REGS, printk("NCR: %02x => %lx\n", low32(value), a));	\
     writeb((value), a);							\
   }
 
 #define NCR_write32(address,value)	 				\
   {									\
     unsigned long a = (unsigned long)(host->base) + (unsigned long)(address);	\
-    u32 v = NCR_LE_CPU_BE ? cpu_to_le32((u32)(value)) : (u32)(value);	\
+    u32 v = NCR_LE_CPU_BE ? cpu_to_le32(low32(value)) : low32(value);	\
 									\
     DEB(DEB_REGS, printk("NCR: %08x => %lx\n", v, a));			\
     writel(v, a);							\

--------------9D0E149893690024ECB0A47C--