28 #define KMSG_COMPONENT "xpram"
29 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
31 #include <linux/module.h>
33 #include <linux/ctype.h>
34 #include <linux/errno.h>
39 #include <linux/device.h>
44 #include <asm/uaccess.h>
46 #define XPRAM_NAME "xpram"
48 #define XPRAM_MAX_DEVS 32
59 static unsigned int xpram_pages;
60 static int xpram_devs;
74 "the defaults are 0s \n" \
75 "All devices with size 0 equally partition the "
76 "remaining space on the expanded strorage not "
77 "claimed by explicit sizes\n");
90 static int xpram_page_in (
unsigned long page_addr,
unsigned int xpage_index)
95 " .insn rre,0xb22e0000,%1,%2\n"
100 :
"+d" (cc) :
"a" (
__pa(page_addr)),
"d" (xpage_index) :
"cc");
120 static long xpram_page_out (
unsigned long page_addr,
unsigned int xpage_index)
125 " .insn rre,0xb22f0000,%1,%2\n"
130 :
"+d" (cc) :
"a" (
__pa(page_addr)),
"d" (xpage_index) :
"cc");
143 static int xpram_present(
void)
145 unsigned long mem_page;
151 rc = xpram_page_in(mem_page, 0);
153 return rc ? -
ENXIO : 0;
159 static unsigned long xpram_highest_page_index(
void)
161 unsigned int page_index, add_bit;
162 unsigned long mem_page;
169 add_bit = 1ULL << (
sizeof(
unsigned int)*8 - 1);
170 while (add_bit > 0) {
171 if (xpram_page_in(mem_page, page_index | add_bit) == 0)
172 page_index |= add_bit;
184 static void xpram_make_request(
struct request_queue *
q,
struct bio *bio)
187 struct bio_vec *bvec;
189 unsigned long page_addr;
193 if ((bio->bi_sector & 7) != 0 || (bio->bi_size & 4095) != 0)
196 if ((bio->bi_size >> 12) > xdev->
size)
199 if ((bio->bi_sector >> 3) > 0xffffffffU - xdev->
offset)
201 index = (bio->bi_sector >> 3) + xdev->
offset;
202 bio_for_each_segment(bvec, bio, i) {
203 page_addr = (
unsigned long)
204 kmap(bvec->bv_page) + bvec->bv_offset;
205 bytes = bvec->bv_len;
206 if ((page_addr & 4095) != 0 || (bytes & 4095) != 0)
210 if (bio_data_dir(bio) ==
READ) {
211 if (xpram_page_in(page_addr, index) != 0)
214 if (xpram_page_out(page_addr, index) != 0)
222 set_bit(BIO_UPTODATE, &bio->bi_flags);
238 size = (xpram_pages * 8) & ~0x3f;
246 static const struct block_device_operations xpram_devops =
249 .getgeo = xpram_getgeo,
255 static int __init xpram_setup_sizes(
unsigned long pages)
257 unsigned long mem_needed;
258 unsigned long mem_auto;
259 unsigned long long size;
265 pr_err(
"%d is not a valid number of XPRAM devices\n",devs);
276 for (i = 0; i < xpram_devs; i++) {
279 switch (sizes[i][0]) {
288 xpram_sizes[
i] = (size + 3) & -4
UL;
291 mem_needed += xpram_sizes[
i];
296 pr_info(
" number of devices (partitions): %d \n", xpram_devs);
297 for (i = 0; i < xpram_devs; i++) {
299 pr_info(
" size of partition %d: %u kB\n",
302 pr_info(
" size of partition %d to be set "
303 "automatically\n",i);
305 pr_info(
" memory needed (for sized partitions): %lu kB\n",
307 pr_info(
" partitions to be sized automatically: %d\n",
310 if (mem_needed > pages * 4) {
311 pr_err(
"Not enough expanded memory available\n");
322 mem_auto = ((pages - mem_needed / 4) / mem_auto_no) * 4;
323 pr_info(
" automatically determined "
324 "partition size: %lu kB\n", mem_auto);
325 for (i = 0; i < xpram_devs; i++)
326 if (xpram_sizes[i] == 0)
327 xpram_sizes[
i] = mem_auto;
332 static int __init xpram_setup_blkdev(
void)
337 for (i = 0; i < xpram_devs; i++) {
342 if (!xpram_queues[i]) {
361 for (i = 0; i < xpram_devs; i++) {
362 struct gendisk *disk = xpram_disks[
i];
364 xpram_devices[
i].
size = xpram_sizes[
i] / 4;
366 offset += xpram_devices[
i].
size;
368 disk->first_minor =
i;
369 disk->fops = &xpram_devops;
370 disk->private_data = &xpram_devices[
i];
371 disk->queue = xpram_queues[
i];
372 sprintf(disk->disk_name,
"slram%d", i);
373 set_capacity(disk, xpram_sizes[i] << 1);
389 static void xpram_resume_error(
const char *
message)
391 pr_err(
"Resuming the system failed: %s\n", message);
392 panic(
"xpram resume error\n");
398 static int xpram_restore(
struct device *
dev)
402 if (xpram_present() != 0)
403 xpram_resume_error(
"xpram disappeared");
404 if (xpram_pages != xpram_highest_page_index() + 1)
405 xpram_resume_error(
"Size of xpram changed");
409 static const struct dev_pm_ops xpram_pm_ops = {
410 .restore = xpram_restore,
426 static void __exit xpram_exit(
void)
429 for (i = 0; i < xpram_devs; i++) {
439 static int __init xpram_init(
void)
444 if (xpram_present() != 0) {
445 pr_err(
"No expanded memory available\n");
448 xpram_pages = xpram_highest_page_index() + 1;
449 pr_info(
" %u pages expanded memory found (%lu KB).\n",
450 xpram_pages, (
unsigned long) xpram_pages*4);
451 rc = xpram_setup_sizes(xpram_pages);
457 xpram_pdev = platform_device_register_simple(
XPRAM_NAME, -1,
NULL, 0);
458 if (IS_ERR(xpram_pdev)) {
459 rc = PTR_ERR(xpram_pdev);
460 goto fail_platform_driver_unregister;
462 rc = xpram_setup_blkdev();
464 goto fail_platform_device_unregister;
467 fail_platform_device_unregister:
469 fail_platform_driver_unregister: