patch-2.1.132 linux/drivers/block/z2ram.c

Next file: linux/drivers/cdrom/cdu31a.c
Previous file: linux/drivers/block/raid1.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.131/linux/drivers/block/z2ram.c linux/drivers/block/z2ram.c
@@ -14,6 +14,8 @@
 **          37     0       Use Zorro II and Chip ram
 **          37     1       Use only Zorro II ram
 **          37     2       Use only Chip ram
+**          37     4-7     Use memory list entry 1-4 (first is 0)
+** ++jskov: support for 1-4th memory list entry.
 **
 ** Permission to use, copy, modify, and distribute this software and its
 ** documentation for any purpose and without fee is hereby granted, provided
@@ -25,6 +27,7 @@
 
 #define MAJOR_NR    Z2RAM_MAJOR
 
+#include <linux/config.h>
 #include <linux/major.h>
 #include <linux/malloc.h>
 #include <linux/blk.h>
@@ -37,23 +40,37 @@
 #include <asm/setup.h>
 #include <asm/bitops.h>
 #include <asm/amigahw.h>
+#ifdef CONFIG_APUS
+#include <asm/pgtable.h>
+#include <asm/io.h>
+#endif
 #include <linux/zorro.h>
 
+
+extern int num_memory;
+extern struct mem_info memory[NUM_MEMINFO];
+
 #define TRUE                  (1)
 #define FALSE                 (0)
 
 #define Z2MINOR_COMBINED      (0)
 #define Z2MINOR_Z2ONLY        (1)
 #define Z2MINOR_CHIPONLY      (2)
+#define Z2MINOR_MEMLIST1      (4)
+#define Z2MINOR_MEMLIST2      (5)
+#define Z2MINOR_MEMLIST3      (6)
+#define Z2MINOR_MEMLIST4      (7)
+#define Z2MINOR_COUNT         (8) /* Move this down when adding a new minor */
 
 #define Z2RAM_CHUNK1024       ( Z2RAM_CHUNKSIZE >> 10 )
 
 static u_long *z2ram_map    = NULL;
 static u_long z2ram_size    = 0;
-static int z2_blocksizes[3] = { 1024, 1024, 1024 };
-static int z2_sizes[3]      = {    0,    0,    0 };
+static int z2_blocksizes[Z2MINOR_COUNT];
+static int z2_sizes[Z2MINOR_COUNT];
 static int z2_count         = 0;
 static int chip_count       = 0;
+static int list_count       = 0;
 static int current_device   = -1;
 
 static void
@@ -166,8 +183,61 @@
     {
 	z2_count   = 0;
 	chip_count = 0;
+	list_count = 0;
 	z2ram_size = 0;
 
+	/* Use a specific list entry. */
+	if (device >= Z2MINOR_MEMLIST1 && device <= Z2MINOR_MEMLIST4) {
+		int index = device - Z2MINOR_MEMLIST1 + 1;
+		unsigned long size, paddr, vaddr;
+
+		if (index >= num_memory) {
+			printk( KERN_ERR DEVICE_NAME
+				": no such entry in z2ram_map\n" );
+			return -ENOMEM;
+		}
+
+		paddr = memory[index].addr;
+		size = memory[index].size & ~(Z2RAM_CHUNKSIZE-1);
+
+#ifdef __powerpc__
+		/* FIXME: ioremap doesn't build correct memory tables. */
+		{
+			extern void* vmalloc (unsigned long);
+			extern void vfree (void*);
+			vfree(vmalloc (size));
+		}
+
+		vaddr = (unsigned long) __ioremap (paddr, size, 
+						   _PAGE_WRITETHRU);
+
+#else
+		vaddr = kernel_map (paddr, size, KERNELMAP_FULL_CACHING,
+				    NULL);
+#endif
+		z2ram_map = 
+			kmalloc((size/Z2RAM_CHUNKSIZE)*sizeof(z2ram_map[0]),
+				GFP_KERNEL);
+		if ( z2ram_map == NULL )
+		{
+		    printk( KERN_ERR DEVICE_NAME
+			": cannot get mem for z2ram_map\n" );
+		    return -ENOMEM;
+		}
+
+		while (size) {
+			z2ram_map[ z2ram_size++ ] = vaddr;
+			size -= Z2RAM_CHUNKSIZE;
+			vaddr += Z2RAM_CHUNKSIZE;
+			list_count++;
+		}
+
+		if ( z2ram_size != 0 )
+		    printk( KERN_INFO DEVICE_NAME
+			": using %iK List Entry %d Memory\n",
+			list_count * Z2RAM_CHUNK1024, index );
+	} else
+
 	switch ( device )
 	{
 	    case Z2MINOR_COMBINED:
@@ -253,12 +323,11 @@
     return 0;
 }
 
-static void 
+static int
 z2_release( struct inode *inode, struct file *filp )
 {
-
     if ( current_device == -1 )
-	return;     
+	return 0;     
 
     sync_dev( inode->i_rdev );
 
@@ -266,7 +335,7 @@
     MOD_DEC_USE_COUNT;
 #endif
 
-    return;
+    return 0;
 }
 
 static struct file_operations z2_fops =
@@ -281,7 +350,10 @@
 	z2_open,                /* open */
 	NULL,			/* flush */
 	z2_release,             /* release */
-	block_fsync             /* fsync */
+	block_fsync,            /* fsync */
+	NULL,			/* fasync */
+	NULL,			/* check_media_change */
+	NULL,			/* revalidate */
 };
 
 __initfunc(int
@@ -297,6 +369,16 @@
 	    MAJOR_NR );
 	return -EBUSY;
     }
+
+    {
+	    /* Initialize size arrays. */
+	    int i;
+
+	    for (i = 0; i < Z2MINOR_COUNT; i++) {
+		    z2_blocksizes[ i ] = 1024;
+		    z2_sizes[ i ] = 0;
+	    }
+    }    
    
     blk_dev[ MAJOR_NR ].request_fn = DEVICE_REQUEST;
     blksize_size[ MAJOR_NR ] = z2_blocksizes;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov