Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Xpram.c -- the S/390 expanded memory RAM-disk |
| 3 | * |
| 4 | * significant parts of this code are based on |
| 5 | * the sbull device driver presented in |
| 6 | * A. Rubini: Linux Device Drivers |
| 7 | * |
| 8 | * Author of XPRAM specific coding: Reinhard Buendgen |
| 9 | * buendgen@de.ibm.com |
| 10 | * Rewrite for 2.5: Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 11 | * |
| 12 | * External interfaces: |
| 13 | * Interfaces to linux kernel |
| 14 | * xpram_setup: read kernel parameters |
| 15 | * Device specific file operations |
| 16 | * xpram_iotcl |
| 17 | * xpram_open |
| 18 | * |
| 19 | * "ad-hoc" partitioning: |
| 20 | * the expanded memory can be partitioned among several devices |
| 21 | * (with different minors). The partitioning set up can be |
| 22 | * set by kernel or module parameters (int devs & int sizes[]) |
| 23 | * |
| 24 | * Potential future improvements: |
| 25 | * generic hard disk support to replace ad-hoc partitioning |
| 26 | */ |
| 27 | |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 28 | #define KMSG_COMPONENT "xpram" |
| 29 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/moduleparam.h> |
| 33 | #include <linux/ctype.h> /* isdigit, isxdigit */ |
| 34 | #include <linux/errno.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/blkdev.h> |
| 38 | #include <linux/blkpg.h> |
| 39 | #include <linux/hdreg.h> /* HDIO_GETGEO */ |
| 40 | #include <linux/sysdev.h> |
| 41 | #include <linux/bio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/uaccess.h> |
| 43 | |
| 44 | #define XPRAM_NAME "xpram" |
| 45 | #define XPRAM_DEVS 1 /* one partition */ |
| 46 | #define XPRAM_MAX_DEVS 32 /* maximal number of devices (partitions) */ |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | typedef struct { |
| 49 | unsigned int size; /* size of xpram segment in pages */ |
| 50 | unsigned int offset; /* start page of xpram segment */ |
| 51 | } xpram_device_t; |
| 52 | |
| 53 | static xpram_device_t xpram_devices[XPRAM_MAX_DEVS]; |
| 54 | static unsigned int xpram_sizes[XPRAM_MAX_DEVS]; |
| 55 | static struct gendisk *xpram_disks[XPRAM_MAX_DEVS]; |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 56 | static struct request_queue *xpram_queues[XPRAM_MAX_DEVS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static unsigned int xpram_pages; |
| 58 | static int xpram_devs; |
| 59 | |
| 60 | /* |
| 61 | * Parameter parsing functions. |
| 62 | */ |
Heiko Carstens | 5c898ba | 2006-07-12 16:40:14 +0200 | [diff] [blame] | 63 | static int __initdata devs = XPRAM_DEVS; |
| 64 | static char __initdata *sizes[XPRAM_MAX_DEVS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | module_param(devs, int, 0); |
Heiko Carstens | 5c898ba | 2006-07-12 16:40:14 +0200 | [diff] [blame] | 67 | module_param_array(sizes, charp, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | MODULE_PARM_DESC(devs, "number of devices (\"partitions\"), " \ |
| 70 | "the default is " __MODULE_STRING(XPRAM_DEVS) "\n"); |
| 71 | MODULE_PARM_DESC(sizes, "list of device (partition) sizes " \ |
| 72 | "the defaults are 0s \n" \ |
| 73 | "All devices with size 0 equally partition the " |
| 74 | "remaining space on the expanded strorage not " |
| 75 | "claimed by explicit sizes\n"); |
| 76 | MODULE_LICENSE("GPL"); |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* |
| 79 | * Copy expanded memory page (4kB) into main memory |
| 80 | * Arguments |
| 81 | * page_addr: address of target page |
| 82 | * xpage_index: index of expandeded memory page |
| 83 | * Return value |
| 84 | * 0: if operation succeeds |
| 85 | * -EIO: if pgin failed |
| 86 | * -ENXIO: if xpram has vanished |
| 87 | */ |
| 88 | static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index) |
| 89 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 90 | int cc = 2; /* return unused cc 2 if pgin traps */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 92 | asm volatile( |
| 93 | " .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */ |
| 94 | "0: ipm %0\n" |
| 95 | " srl %0,28\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | "1:\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 97 | EX_TABLE(0b,1b) |
| 98 | : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (cc == 3) |
| 100 | return -ENXIO; |
Martin Schwidefsky | 8df22b4 | 2008-07-14 09:59:24 +0200 | [diff] [blame] | 101 | if (cc == 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return -ENXIO; |
Martin Schwidefsky | 8df22b4 | 2008-07-14 09:59:24 +0200 | [diff] [blame] | 103 | if (cc == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Copy a 4kB page of main memory to an expanded memory page |
| 110 | * Arguments |
| 111 | * page_addr: address of source page |
| 112 | * xpage_index: index of expandeded memory page |
| 113 | * Return value |
| 114 | * 0: if operation succeeds |
| 115 | * -EIO: if pgout failed |
| 116 | * -ENXIO: if xpram has vanished |
| 117 | */ |
| 118 | static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index) |
| 119 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 120 | int cc = 2; /* return unused cc 2 if pgin traps */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 122 | asm volatile( |
| 123 | " .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */ |
| 124 | "0: ipm %0\n" |
| 125 | " srl %0,28\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | "1:\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 127 | EX_TABLE(0b,1b) |
| 128 | : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | if (cc == 3) |
| 130 | return -ENXIO; |
Martin Schwidefsky | 8df22b4 | 2008-07-14 09:59:24 +0200 | [diff] [blame] | 131 | if (cc == 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return -ENXIO; |
Martin Schwidefsky | 8df22b4 | 2008-07-14 09:59:24 +0200 | [diff] [blame] | 133 | if (cc == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Check if xpram is available. |
| 140 | */ |
| 141 | static int __init xpram_present(void) |
| 142 | { |
| 143 | unsigned long mem_page; |
| 144 | int rc; |
| 145 | |
| 146 | mem_page = (unsigned long) __get_free_page(GFP_KERNEL); |
| 147 | if (!mem_page) |
| 148 | return -ENOMEM; |
| 149 | rc = xpram_page_in(mem_page, 0); |
| 150 | free_page(mem_page); |
| 151 | return rc ? -ENXIO : 0; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Return index of the last available xpram page. |
| 156 | */ |
| 157 | static unsigned long __init xpram_highest_page_index(void) |
| 158 | { |
| 159 | unsigned int page_index, add_bit; |
| 160 | unsigned long mem_page; |
| 161 | |
| 162 | mem_page = (unsigned long) __get_free_page(GFP_KERNEL); |
| 163 | if (!mem_page) |
| 164 | return 0; |
| 165 | |
| 166 | page_index = 0; |
| 167 | add_bit = 1ULL << (sizeof(unsigned int)*8 - 1); |
| 168 | while (add_bit > 0) { |
| 169 | if (xpram_page_in(mem_page, page_index | add_bit) == 0) |
| 170 | page_index |= add_bit; |
| 171 | add_bit >>= 1; |
| 172 | } |
| 173 | |
| 174 | free_page (mem_page); |
| 175 | |
| 176 | return page_index; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Block device make request function. |
| 181 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 182 | static int xpram_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
| 184 | xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data; |
| 185 | struct bio_vec *bvec; |
| 186 | unsigned int index; |
| 187 | unsigned long page_addr; |
| 188 | unsigned long bytes; |
| 189 | int i; |
| 190 | |
| 191 | if ((bio->bi_sector & 7) != 0 || (bio->bi_size & 4095) != 0) |
| 192 | /* Request is not page-aligned. */ |
| 193 | goto fail; |
| 194 | if ((bio->bi_size >> 12) > xdev->size) |
| 195 | /* Request size is no page-aligned. */ |
| 196 | goto fail; |
| 197 | if ((bio->bi_sector >> 3) > 0xffffffffU - xdev->offset) |
| 198 | goto fail; |
| 199 | index = (bio->bi_sector >> 3) + xdev->offset; |
| 200 | bio_for_each_segment(bvec, bio, i) { |
| 201 | page_addr = (unsigned long) |
| 202 | kmap(bvec->bv_page) + bvec->bv_offset; |
| 203 | bytes = bvec->bv_len; |
| 204 | if ((page_addr & 4095) != 0 || (bytes & 4095) != 0) |
| 205 | /* More paranoia. */ |
| 206 | goto fail; |
| 207 | while (bytes > 0) { |
| 208 | if (bio_data_dir(bio) == READ) { |
| 209 | if (xpram_page_in(page_addr, index) != 0) |
| 210 | goto fail; |
| 211 | } else { |
| 212 | if (xpram_page_out(page_addr, index) != 0) |
| 213 | goto fail; |
| 214 | } |
| 215 | page_addr += 4096; |
| 216 | bytes -= 4096; |
| 217 | index++; |
| 218 | } |
| 219 | } |
| 220 | set_bit(BIO_UPTODATE, &bio->bi_flags); |
Martin Schwidefsky | 1462222 | 2007-10-12 16:11:53 +0200 | [diff] [blame] | 221 | bio_endio(bio, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | fail: |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 224 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 228 | static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | unsigned long size; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | /* |
| 233 | * get geometry: we have to fake one... trim the size to a |
| 234 | * multiple of 64 (32k): tell we have 16 sectors, 4 heads, |
| 235 | * whatever cylinders. Tell also that data starts at sector. 4. |
| 236 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | size = (xpram_pages * 8) & ~0x3f; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 238 | geo->cylinders = size >> 6; |
| 239 | geo->heads = 4; |
| 240 | geo->sectors = 16; |
| 241 | geo->start = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static struct block_device_operations xpram_devops = |
| 246 | { |
| 247 | .owner = THIS_MODULE, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 248 | .getgeo = xpram_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | /* |
| 252 | * Setup xpram_sizes array. |
| 253 | */ |
| 254 | static int __init xpram_setup_sizes(unsigned long pages) |
| 255 | { |
| 256 | unsigned long mem_needed; |
| 257 | unsigned long mem_auto; |
Heiko Carstens | f257b06 | 2006-07-17 16:09:23 +0200 | [diff] [blame] | 258 | unsigned long long size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | int mem_auto_no; |
| 260 | int i; |
| 261 | |
| 262 | /* Check number of devices. */ |
| 263 | if (devs <= 0 || devs > XPRAM_MAX_DEVS) { |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 264 | pr_err("%d is not a valid number of XPRAM devices\n",devs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return -EINVAL; |
| 266 | } |
| 267 | xpram_devs = devs; |
| 268 | |
| 269 | /* |
| 270 | * Copy sizes array to xpram_sizes and align partition |
| 271 | * sizes to page boundary. |
| 272 | */ |
| 273 | mem_needed = 0; |
| 274 | mem_auto_no = 0; |
| 275 | for (i = 0; i < xpram_devs; i++) { |
Heiko Carstens | f257b06 | 2006-07-17 16:09:23 +0200 | [diff] [blame] | 276 | if (sizes[i]) { |
| 277 | size = simple_strtoull(sizes[i], &sizes[i], 0); |
| 278 | switch (sizes[i][0]) { |
| 279 | case 'g': |
| 280 | case 'G': |
| 281 | size <<= 20; |
| 282 | break; |
| 283 | case 'm': |
| 284 | case 'M': |
| 285 | size <<= 10; |
| 286 | } |
| 287 | xpram_sizes[i] = (size + 3) & -4UL; |
| 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (xpram_sizes[i]) |
| 290 | mem_needed += xpram_sizes[i]; |
| 291 | else |
| 292 | mem_auto_no++; |
| 293 | } |
| 294 | |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 295 | pr_info(" number of devices (partitions): %d \n", xpram_devs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | for (i = 0; i < xpram_devs; i++) { |
| 297 | if (xpram_sizes[i]) |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 298 | pr_info(" size of partition %d: %u kB\n", |
| 299 | i, xpram_sizes[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | else |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 301 | pr_info(" size of partition %d to be set " |
| 302 | "automatically\n",i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 304 | pr_info(" memory needed (for sized partitions): %lu kB\n", |
| 305 | mem_needed); |
| 306 | pr_info(" partitions to be sized automatically: %d\n", |
| 307 | mem_auto_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | if (mem_needed > pages * 4) { |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 310 | pr_err("Not enough expanded memory available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return -EINVAL; |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * partitioning: |
| 316 | * xpram_sizes[i] != 0; partition i has size xpram_sizes[i] kB |
| 317 | * else: ; all partitions with zero xpram_sizes[i] |
| 318 | * partition equally the remaining space |
| 319 | */ |
| 320 | if (mem_auto_no) { |
| 321 | mem_auto = ((pages - mem_needed / 4) / mem_auto_no) * 4; |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 322 | pr_info(" automatically determined " |
| 323 | "partition size: %lu kB\n", mem_auto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | for (i = 0; i < xpram_devs; i++) |
| 325 | if (xpram_sizes[i] == 0) |
| 326 | xpram_sizes[i] = mem_auto; |
| 327 | } |
| 328 | return 0; |
| 329 | } |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | static int __init xpram_setup_blkdev(void) |
| 332 | { |
| 333 | unsigned long offset; |
| 334 | int i, rc = -ENOMEM; |
| 335 | |
| 336 | for (i = 0; i < xpram_devs; i++) { |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 337 | xpram_disks[i] = alloc_disk(1); |
| 338 | if (!xpram_disks[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | goto out; |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 340 | xpram_queues[i] = blk_alloc_queue(GFP_KERNEL); |
| 341 | if (!xpram_queues[i]) { |
| 342 | put_disk(xpram_disks[i]); |
| 343 | goto out; |
| 344 | } |
| 345 | blk_queue_make_request(xpram_queues[i], xpram_make_request); |
| 346 | blk_queue_hardsect_size(xpram_queues[i], 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
| 350 | * Register xpram major. |
| 351 | */ |
| 352 | rc = register_blkdev(XPRAM_MAJOR, XPRAM_NAME); |
| 353 | if (rc < 0) |
| 354 | goto out; |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | * Setup device structures. |
| 358 | */ |
| 359 | offset = 0; |
| 360 | for (i = 0; i < xpram_devs; i++) { |
| 361 | struct gendisk *disk = xpram_disks[i]; |
| 362 | |
| 363 | xpram_devices[i].size = xpram_sizes[i] / 4; |
| 364 | xpram_devices[i].offset = offset; |
| 365 | offset += xpram_devices[i].size; |
| 366 | disk->major = XPRAM_MAJOR; |
| 367 | disk->first_minor = i; |
| 368 | disk->fops = &xpram_devops; |
| 369 | disk->private_data = &xpram_devices[i]; |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 370 | disk->queue = xpram_queues[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | sprintf(disk->disk_name, "slram%d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | set_capacity(disk, xpram_sizes[i] << 1); |
| 373 | add_disk(disk); |
| 374 | } |
| 375 | |
| 376 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | out: |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 378 | while (i--) { |
| 379 | blk_cleanup_queue(xpram_queues[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | put_disk(xpram_disks[i]); |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return rc; |
| 383 | } |
| 384 | |
| 385 | /* |
| 386 | * Finally, the init/exit functions. |
| 387 | */ |
| 388 | static void __exit xpram_exit(void) |
| 389 | { |
| 390 | int i; |
| 391 | for (i = 0; i < xpram_devs; i++) { |
| 392 | del_gendisk(xpram_disks[i]); |
Martin Schwidefsky | 3ce6609 | 2008-10-10 21:33:24 +0200 | [diff] [blame] | 393 | blk_cleanup_queue(xpram_queues[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | put_disk(xpram_disks[i]); |
| 395 | } |
| 396 | unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static int __init xpram_init(void) |
| 400 | { |
| 401 | int rc; |
| 402 | |
| 403 | /* Find out size of expanded memory. */ |
| 404 | if (xpram_present() != 0) { |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 405 | pr_err("No expanded memory available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return -ENODEV; |
| 407 | } |
Christian Borntraeger | e620c49 | 2006-09-20 15:59:32 +0200 | [diff] [blame] | 408 | xpram_pages = xpram_highest_page_index() + 1; |
Martin Schwidefsky | d1c2f89 | 2008-12-25 13:39:31 +0100 | [diff] [blame] | 409 | pr_info(" %u pages expanded memory found (%lu KB).\n", |
| 410 | xpram_pages, (unsigned long) xpram_pages*4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | rc = xpram_setup_sizes(xpram_pages); |
| 412 | if (rc) |
| 413 | return rc; |
Martin Schwidefsky | 37ab46a | 2006-08-07 18:13:06 +0200 | [diff] [blame] | 414 | return xpram_setup_blkdev(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | module_init(xpram_init); |
| 418 | module_exit(xpram_exit); |