Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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