2017-11-14 17:38:00 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Xpram.c -- the S/390 expanded memory RAM-disk
|
|
|
|
*
|
|
|
|
* significant parts of this code are based on
|
|
|
|
* the sbull device driver presented in
|
|
|
|
* A. Rubini: Linux Device Drivers
|
|
|
|
*
|
|
|
|
* Author of XPRAM specific coding: Reinhard Buendgen
|
|
|
|
* buendgen@de.ibm.com
|
|
|
|
* Rewrite for 2.5: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
*
|
|
|
|
* External interfaces:
|
|
|
|
* Interfaces to linux kernel
|
|
|
|
* xpram_setup: read kernel parameters
|
|
|
|
* Device specific file operations
|
|
|
|
* xpram_iotcl
|
|
|
|
* xpram_open
|
|
|
|
*
|
|
|
|
* "ad-hoc" partitioning:
|
|
|
|
* the expanded memory can be partitioned among several devices
|
|
|
|
* (with different minors). The partitioning set up can be
|
|
|
|
* set by kernel or module parameters (int devs & int sizes[])
|
|
|
|
*
|
|
|
|
* Potential future improvements:
|
|
|
|
* generic hard disk support to replace ad-hoc partitioning
|
|
|
|
*/
|
|
|
|
|
2008-12-25 12:39:31 +00:00
|
|
|
#define KMSG_COMPONENT "xpram"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/ctype.h> /* isdigit, isxdigit */
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/blkpg.h>
|
|
|
|
#include <linux/hdreg.h> /* HDIO_GETGEO */
|
2011-12-22 00:26:03 +00:00
|
|
|
#include <linux/device.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/bio.h>
|
2009-06-16 08:30:27 +00:00
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define XPRAM_NAME "xpram"
|
|
|
|
#define XPRAM_DEVS 1 /* one partition */
|
|
|
|
#define XPRAM_MAX_DEVS 32 /* maximal number of devices (partitions) */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int size; /* size of xpram segment in pages */
|
|
|
|
unsigned int offset; /* start page of xpram segment */
|
|
|
|
} xpram_device_t;
|
|
|
|
|
|
|
|
static xpram_device_t xpram_devices[XPRAM_MAX_DEVS];
|
|
|
|
static unsigned int xpram_sizes[XPRAM_MAX_DEVS];
|
|
|
|
static struct gendisk *xpram_disks[XPRAM_MAX_DEVS];
|
2008-10-10 19:33:24 +00:00
|
|
|
static struct request_queue *xpram_queues[XPRAM_MAX_DEVS];
|
2005-04-16 22:20:36 +00:00
|
|
|
static unsigned int xpram_pages;
|
|
|
|
static int xpram_devs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parameter parsing functions.
|
|
|
|
*/
|
2011-03-03 16:56:05 +00:00
|
|
|
static int devs = XPRAM_DEVS;
|
|
|
|
static char *sizes[XPRAM_MAX_DEVS];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
module_param(devs, int, 0);
|
2006-07-12 14:40:14 +00:00
|
|
|
module_param_array(sizes, charp, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
MODULE_PARM_DESC(devs, "number of devices (\"partitions\"), " \
|
|
|
|
"the default is " __MODULE_STRING(XPRAM_DEVS) "\n");
|
|
|
|
MODULE_PARM_DESC(sizes, "list of device (partition) sizes " \
|
|
|
|
"the defaults are 0s \n" \
|
|
|
|
"All devices with size 0 equally partition the "
|
|
|
|
"remaining space on the expanded strorage not "
|
|
|
|
"claimed by explicit sizes\n");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy expanded memory page (4kB) into main memory
|
|
|
|
* Arguments
|
|
|
|
* page_addr: address of target page
|
|
|
|
* xpage_index: index of expandeded memory page
|
|
|
|
* Return value
|
|
|
|
* 0: if operation succeeds
|
|
|
|
* -EIO: if pgin failed
|
|
|
|
* -ENXIO: if xpram has vanished
|
|
|
|
*/
|
|
|
|
static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
|
|
|
|
{
|
2006-09-28 14:56:43 +00:00
|
|
|
int cc = 2; /* return unused cc 2 if pgin traps */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
" .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */
|
|
|
|
"0: ipm %0\n"
|
|
|
|
" srl %0,28\n"
|
2005-04-16 22:20:36 +00:00
|
|
|
"1:\n"
|
2006-09-28 14:56:43 +00:00
|
|
|
EX_TABLE(0b,1b)
|
|
|
|
: "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cc == 3)
|
|
|
|
return -ENXIO;
|
2008-07-14 07:59:24 +00:00
|
|
|
if (cc == 2)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENXIO;
|
2008-07-14 07:59:24 +00:00
|
|
|
if (cc == 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a 4kB page of main memory to an expanded memory page
|
|
|
|
* Arguments
|
|
|
|
* page_addr: address of source page
|
|
|
|
* xpage_index: index of expandeded memory page
|
|
|
|
* Return value
|
|
|
|
* 0: if operation succeeds
|
|
|
|
* -EIO: if pgout failed
|
|
|
|
* -ENXIO: if xpram has vanished
|
|
|
|
*/
|
|
|
|
static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
|
|
|
|
{
|
2006-09-28 14:56:43 +00:00
|
|
|
int cc = 2; /* return unused cc 2 if pgin traps */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
" .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */
|
|
|
|
"0: ipm %0\n"
|
|
|
|
" srl %0,28\n"
|
2005-04-16 22:20:36 +00:00
|
|
|
"1:\n"
|
2006-09-28 14:56:43 +00:00
|
|
|
EX_TABLE(0b,1b)
|
|
|
|
: "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cc == 3)
|
|
|
|
return -ENXIO;
|
2008-07-14 07:59:24 +00:00
|
|
|
if (cc == 2)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENXIO;
|
2008-07-14 07:59:24 +00:00
|
|
|
if (cc == 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if xpram is available.
|
|
|
|
*/
|
2009-06-16 08:30:27 +00:00
|
|
|
static int xpram_present(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long mem_page;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
mem_page = (unsigned long) __get_free_page(GFP_KERNEL);
|
|
|
|
if (!mem_page)
|
|
|
|
return -ENOMEM;
|
|
|
|
rc = xpram_page_in(mem_page, 0);
|
|
|
|
free_page(mem_page);
|
|
|
|
return rc ? -ENXIO : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return index of the last available xpram page.
|
|
|
|
*/
|
2009-06-16 08:30:27 +00:00
|
|
|
static unsigned long xpram_highest_page_index(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int page_index, add_bit;
|
|
|
|
unsigned long mem_page;
|
|
|
|
|
|
|
|
mem_page = (unsigned long) __get_free_page(GFP_KERNEL);
|
|
|
|
if (!mem_page)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
page_index = 0;
|
|
|
|
add_bit = 1ULL << (sizeof(unsigned int)*8 - 1);
|
|
|
|
while (add_bit > 0) {
|
|
|
|
if (xpram_page_in(mem_page, page_index | add_bit) == 0)
|
|
|
|
page_index |= add_bit;
|
|
|
|
add_bit >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_page (mem_page);
|
|
|
|
|
|
|
|
return page_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Block device make request function.
|
|
|
|
*/
|
2015-11-05 17:41:16 +00:00
|
|
|
static blk_qc_t xpram_make_request(struct request_queue *q, struct bio *bio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-08-23 17:10:32 +00:00
|
|
|
xpram_device_t *xdev = bio->bi_disk->private_data;
|
2013-11-24 01:19:00 +00:00
|
|
|
struct bio_vec bvec;
|
|
|
|
struct bvec_iter iter;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int index;
|
|
|
|
unsigned long page_addr;
|
|
|
|
unsigned long bytes;
|
|
|
|
|
2017-06-18 04:38:57 +00:00
|
|
|
blk_queue_split(q, &bio);
|
2015-04-24 05:37:18 +00:00
|
|
|
|
2013-10-11 22:44:27 +00:00
|
|
|
if ((bio->bi_iter.bi_sector & 7) != 0 ||
|
|
|
|
(bio->bi_iter.bi_size & 4095) != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Request is not page-aligned. */
|
|
|
|
goto fail;
|
2013-10-11 22:44:27 +00:00
|
|
|
if ((bio->bi_iter.bi_size >> 12) > xdev->size)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Request size is no page-aligned. */
|
|
|
|
goto fail;
|
2013-10-11 22:44:27 +00:00
|
|
|
if ((bio->bi_iter.bi_sector >> 3) > 0xffffffffU - xdev->offset)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto fail;
|
2013-10-11 22:44:27 +00:00
|
|
|
index = (bio->bi_iter.bi_sector >> 3) + xdev->offset;
|
2013-11-24 01:19:00 +00:00
|
|
|
bio_for_each_segment(bvec, bio, iter) {
|
2005-04-16 22:20:36 +00:00
|
|
|
page_addr = (unsigned long)
|
2013-11-24 01:19:00 +00:00
|
|
|
kmap(bvec.bv_page) + bvec.bv_offset;
|
|
|
|
bytes = bvec.bv_len;
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((page_addr & 4095) != 0 || (bytes & 4095) != 0)
|
|
|
|
/* More paranoia. */
|
|
|
|
goto fail;
|
|
|
|
while (bytes > 0) {
|
|
|
|
if (bio_data_dir(bio) == READ) {
|
|
|
|
if (xpram_page_in(page_addr, index) != 0)
|
|
|
|
goto fail;
|
|
|
|
} else {
|
|
|
|
if (xpram_page_out(page_addr, index) != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
page_addr += 4096;
|
|
|
|
bytes -= 4096;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 13:29:37 +00:00
|
|
|
bio_endio(bio);
|
2015-11-05 17:41:16 +00:00
|
|
|
return BLK_QC_T_NONE;
|
2005-04-16 22:20:36 +00:00
|
|
|
fail:
|
2007-09-27 10:47:43 +00:00
|
|
|
bio_io_error(bio);
|
2015-11-05 17:41:16 +00:00
|
|
|
return BLK_QC_T_NONE;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-08 09:02:50 +00:00
|
|
|
static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long size;
|
2006-01-08 09:02:50 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* get geometry: we have to fake one... trim the size to a
|
|
|
|
* multiple of 64 (32k): tell we have 16 sectors, 4 heads,
|
|
|
|
* whatever cylinders. Tell also that data starts at sector. 4.
|
|
|
|
*/
|
|
|
|
size = (xpram_pages * 8) & ~0x3f;
|
2006-01-08 09:02:50 +00:00
|
|
|
geo->cylinders = size >> 6;
|
|
|
|
geo->heads = 4;
|
|
|
|
geo->sectors = 16;
|
|
|
|
geo->start = 4;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-22 00:01:13 +00:00
|
|
|
static const struct block_device_operations xpram_devops =
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
2006-01-08 09:02:50 +00:00
|
|
|
.getgeo = xpram_getgeo,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup xpram_sizes array.
|
|
|
|
*/
|
|
|
|
static int __init xpram_setup_sizes(unsigned long pages)
|
|
|
|
{
|
|
|
|
unsigned long mem_needed;
|
|
|
|
unsigned long mem_auto;
|
2006-07-17 14:09:23 +00:00
|
|
|
unsigned long long size;
|
2014-01-20 15:43:33 +00:00
|
|
|
char *sizes_end;
|
2005-04-16 22:20:36 +00:00
|
|
|
int mem_auto_no;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Check number of devices. */
|
|
|
|
if (devs <= 0 || devs > XPRAM_MAX_DEVS) {
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_err("%d is not a valid number of XPRAM devices\n",devs);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
xpram_devs = devs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy sizes array to xpram_sizes and align partition
|
|
|
|
* sizes to page boundary.
|
|
|
|
*/
|
|
|
|
mem_needed = 0;
|
|
|
|
mem_auto_no = 0;
|
|
|
|
for (i = 0; i < xpram_devs; i++) {
|
2006-07-17 14:09:23 +00:00
|
|
|
if (sizes[i]) {
|
2014-01-20 15:43:33 +00:00
|
|
|
size = simple_strtoull(sizes[i], &sizes_end, 0);
|
|
|
|
switch (*sizes_end) {
|
2006-07-17 14:09:23 +00:00
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
size <<= 20;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
size <<= 10;
|
|
|
|
}
|
|
|
|
xpram_sizes[i] = (size + 3) & -4UL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (xpram_sizes[i])
|
|
|
|
mem_needed += xpram_sizes[i];
|
|
|
|
else
|
|
|
|
mem_auto_no++;
|
|
|
|
}
|
|
|
|
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" number of devices (partitions): %d \n", xpram_devs);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < xpram_devs; i++) {
|
|
|
|
if (xpram_sizes[i])
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" size of partition %d: %u kB\n",
|
|
|
|
i, xpram_sizes[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" size of partition %d to be set "
|
|
|
|
"automatically\n",i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" memory needed (for sized partitions): %lu kB\n",
|
|
|
|
mem_needed);
|
|
|
|
pr_info(" partitions to be sized automatically: %d\n",
|
|
|
|
mem_auto_no);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (mem_needed > pages * 4) {
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_err("Not enough expanded memory available\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* partitioning:
|
|
|
|
* xpram_sizes[i] != 0; partition i has size xpram_sizes[i] kB
|
|
|
|
* else: ; all partitions with zero xpram_sizes[i]
|
|
|
|
* partition equally the remaining space
|
|
|
|
*/
|
|
|
|
if (mem_auto_no) {
|
|
|
|
mem_auto = ((pages - mem_needed / 4) / mem_auto_no) * 4;
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" automatically determined "
|
|
|
|
"partition size: %lu kB\n", mem_auto);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < xpram_devs; i++)
|
|
|
|
if (xpram_sizes[i] == 0)
|
|
|
|
xpram_sizes[i] = mem_auto;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init xpram_setup_blkdev(void)
|
|
|
|
{
|
|
|
|
unsigned long offset;
|
|
|
|
int i, rc = -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < xpram_devs; i++) {
|
2008-10-10 19:33:24 +00:00
|
|
|
xpram_disks[i] = alloc_disk(1);
|
|
|
|
if (!xpram_disks[i])
|
|
|
|
goto out;
|
2020-03-27 08:30:11 +00:00
|
|
|
xpram_queues[i] = blk_alloc_queue(xpram_make_request,
|
|
|
|
NUMA_NO_NODE);
|
2008-10-10 19:33:24 +00:00
|
|
|
if (!xpram_queues[i]) {
|
|
|
|
put_disk(xpram_disks[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
2008-10-10 19:33:24 +00:00
|
|
|
}
|
2018-03-08 01:10:10 +00:00
|
|
|
blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_queues[i]);
|
|
|
|
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, xpram_queues[i]);
|
2009-05-22 21:17:49 +00:00
|
|
|
blk_queue_logical_block_size(xpram_queues[i], 4096);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register xpram major.
|
|
|
|
*/
|
|
|
|
rc = register_blkdev(XPRAM_MAJOR, XPRAM_NAME);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup device structures.
|
|
|
|
*/
|
|
|
|
offset = 0;
|
|
|
|
for (i = 0; i < xpram_devs; i++) {
|
|
|
|
struct gendisk *disk = xpram_disks[i];
|
|
|
|
|
|
|
|
xpram_devices[i].size = xpram_sizes[i] / 4;
|
|
|
|
xpram_devices[i].offset = offset;
|
|
|
|
offset += xpram_devices[i].size;
|
|
|
|
disk->major = XPRAM_MAJOR;
|
|
|
|
disk->first_minor = i;
|
|
|
|
disk->fops = &xpram_devops;
|
|
|
|
disk->private_data = &xpram_devices[i];
|
2008-10-10 19:33:24 +00:00
|
|
|
disk->queue = xpram_queues[i];
|
2005-04-16 22:20:36 +00:00
|
|
|
sprintf(disk->disk_name, "slram%d", i);
|
|
|
|
set_capacity(disk, xpram_sizes[i] << 1);
|
|
|
|
add_disk(disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
2008-10-10 19:33:24 +00:00
|
|
|
while (i--) {
|
|
|
|
blk_cleanup_queue(xpram_queues[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
put_disk(xpram_disks[i]);
|
2008-10-10 19:33:24 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-06-16 08:30:27 +00:00
|
|
|
/*
|
|
|
|
* Resume failed: Print error message and call panic.
|
|
|
|
*/
|
|
|
|
static void xpram_resume_error(const char *message)
|
|
|
|
{
|
2009-07-07 14:37:11 +00:00
|
|
|
pr_err("Resuming the system failed: %s\n", message);
|
2009-06-16 08:30:27 +00:00
|
|
|
panic("xpram resume error\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if xpram setup changed between suspend and resume.
|
|
|
|
*/
|
|
|
|
static int xpram_restore(struct device *dev)
|
|
|
|
{
|
|
|
|
if (!xpram_pages)
|
|
|
|
return 0;
|
|
|
|
if (xpram_present() != 0)
|
|
|
|
xpram_resume_error("xpram disappeared");
|
|
|
|
if (xpram_pages != xpram_highest_page_index() + 1)
|
|
|
|
xpram_resume_error("Size of xpram changed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-15 02:00:08 +00:00
|
|
|
static const struct dev_pm_ops xpram_pm_ops = {
|
2009-06-16 08:30:27 +00:00
|
|
|
.restore = xpram_restore,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver xpram_pdrv = {
|
|
|
|
.driver = {
|
|
|
|
.name = XPRAM_NAME,
|
|
|
|
.pm = &xpram_pm_ops,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *xpram_pdev;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Finally, the init/exit functions.
|
|
|
|
*/
|
|
|
|
static void __exit xpram_exit(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < xpram_devs; i++) {
|
|
|
|
del_gendisk(xpram_disks[i]);
|
2008-10-10 19:33:24 +00:00
|
|
|
blk_cleanup_queue(xpram_queues[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
put_disk(xpram_disks[i]);
|
|
|
|
}
|
|
|
|
unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME);
|
2009-06-16 08:30:27 +00:00
|
|
|
platform_device_unregister(xpram_pdev);
|
|
|
|
platform_driver_unregister(&xpram_pdrv);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init xpram_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Find out size of expanded memory. */
|
|
|
|
if (xpram_present() != 0) {
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_err("No expanded memory available\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2006-09-20 13:59:32 +00:00
|
|
|
xpram_pages = xpram_highest_page_index() + 1;
|
2008-12-25 12:39:31 +00:00
|
|
|
pr_info(" %u pages expanded memory found (%lu KB).\n",
|
|
|
|
xpram_pages, (unsigned long) xpram_pages*4);
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = xpram_setup_sizes(xpram_pages);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2009-06-16 08:30:27 +00:00
|
|
|
rc = platform_driver_register(&xpram_pdrv);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
xpram_pdev = platform_device_register_simple(XPRAM_NAME, -1, NULL, 0);
|
|
|
|
if (IS_ERR(xpram_pdev)) {
|
|
|
|
rc = PTR_ERR(xpram_pdev);
|
|
|
|
goto fail_platform_driver_unregister;
|
|
|
|
}
|
|
|
|
rc = xpram_setup_blkdev();
|
|
|
|
if (rc)
|
|
|
|
goto fail_platform_device_unregister;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_platform_device_unregister:
|
|
|
|
platform_device_unregister(xpram_pdev);
|
|
|
|
fail_platform_driver_unregister:
|
|
|
|
platform_driver_unregister(&xpram_pdrv);
|
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(xpram_init);
|
|
|
|
module_exit(xpram_exit);
|