28 #define DEVICE_NAME "Z2RAM"
33 #include <linux/module.h>
35 #include <linux/bitops.h>
37 #include <linux/slab.h>
39 #include <asm/setup.h>
41 #include <asm/pgtable.h>
49 #define Z2MINOR_COMBINED (0)
50 #define Z2MINOR_Z2ONLY (1)
51 #define Z2MINOR_CHIPONLY (2)
52 #define Z2MINOR_MEMLIST1 (4)
53 #define Z2MINOR_MEMLIST2 (5)
54 #define Z2MINOR_MEMLIST3 (6)
55 #define Z2MINOR_MEMLIST4 (7)
56 #define Z2MINOR_COUNT (8)
58 #define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 )
62 static u_long z2ram_size = 0;
63 static int z2_count = 0;
64 static int chip_count = 0;
65 static int list_count = 0;
66 static int current_device = -1;
70 static struct gendisk *z2ram_gendisk;
78 unsigned long start = blk_rq_pos(req) << 9;
79 unsigned long len = blk_rq_cur_bytes(req);
82 if (start + len > z2ram_size) {
85 (
unsigned long long)blk_rq_pos(req),
86 blk_rq_cur_sectors(req));
91 unsigned long addr = start & Z2RAM_CHUNKMASK;
92 unsigned long size = Z2RAM_CHUNKSIZE -
addr;
95 addr += z2ram_map[ start >> Z2RAM_CHUNKSHIFT ];
96 if (rq_data_dir(req) ==
READ)
97 memcpy(req->buffer, (
char *)addr, size);
99 memcpy((
char *)addr, req->buffer, size);
114 for ( i = 0; i < Z2RAM_SIZE / Z2RAM_CHUNKSIZE; i++ )
116 if (
test_bit( i, zorro_unused_z2ram ) )
119 z2ram_map[ z2ram_size++ ] =
120 ZTWO_VADDR( Z2RAM_START ) + ( i << Z2RAM_CHUNKSHIFT );
135 z2ram_map[ z2ram_size ] =
138 if ( z2ram_map[ z2ram_size ] == 0 )
152 int max_z2_map = ( Z2RAM_SIZE / Z2RAM_CHUNKSIZE ) *
153 sizeof( z2ram_map[0] );
155 sizeof( z2ram_map[0] );
161 if ( current_device != -1 && current_device != device )
167 if ( current_device == -1 )
181 ": no such entry in z2ram_map\n" );
198 vaddr = (
unsigned long)z_remap_nocache_nonser(paddr, size);
201 kmalloc((size/Z2RAM_CHUNKSIZE)*
sizeof(z2ram_map[0]),
203 if ( z2ram_map ==
NULL )
206 ": cannot get mem for z2ram_map\n" );
211 z2ram_map[ z2ram_size++ ] =
vaddr;
212 size -= Z2RAM_CHUNKSIZE;
213 vaddr += Z2RAM_CHUNKSIZE;
217 if ( z2ram_size != 0 )
219 ": using %iK List Entry %d Memory\n",
228 if ( z2ram_map ==
NULL )
231 ": cannot get mem for z2ram_map\n" );
238 if ( z2ram_size != 0 )
240 ": using %iK Zorro II RAM and %iK Chip RAM (Total %dK)\n",
242 chip_count * Z2RAM_CHUNK1024,
243 ( z2_count + chip_count ) * Z2RAM_CHUNK1024 );
249 if ( z2ram_map ==
NULL )
252 ": cannot get mem for z2ram_map\n" );
258 if ( z2ram_size != 0 )
260 ": using %iK of Zorro II RAM\n",
261 z2_count * Z2RAM_CHUNK1024 );
267 if ( z2ram_map ==
NULL )
270 ": cannot get mem for z2ram_map\n" );
276 if ( z2ram_size != 0 )
278 ": using %iK Chip RAM\n",
279 chip_count * Z2RAM_CHUNK1024 );
290 if ( z2ram_size == 0 )
293 ": no unused ZII/Chip RAM found\n" );
297 current_device = device;
298 z2ram_size <<= Z2RAM_CHUNKSHIFT;
299 set_capacity(z2ram_gendisk, z2ram_size >> 9);
313 z2_release(
struct gendisk *disk,
fmode_t mode)
316 if ( current_device == -1 ) {
328 static const struct block_device_operations z2_fops =
332 .release = z2_release,
365 z2ram_gendisk->first_minor = 0;
366 z2ram_gendisk->fops = &z2_fops;
367 sprintf(z2ram_gendisk->disk_name,
"z2ram");
369 z2ram_gendisk->queue = z2_queue;
384 static void __exit z2_exit(
void)
393 if ( current_device != -1 )
397 for ( j = 0 ; j < z2_count; j++ )
399 set_bit( i++, zorro_unused_z2ram );
402 for ( j = 0 ; j < chip_count; j++ )
404 if ( z2ram_map[ i ] )
410 if ( z2ram_map !=
NULL )