soc: rockchip: ramdisk: Add Rockchip RAM disk support

Support use reserved RAM memory as a block device.

Change-Id: I64367a2cb67467425a0e4c6753fa5af0a245405d
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
This commit is contained in:
Tao Huang
2020-04-20 19:32:42 +08:00
parent 0b9a0e19a7
commit 37d4a8872f
3 changed files with 14 additions and 6 deletions

View File

@@ -88,6 +88,12 @@ config ROCKCHIP_PVTM
the chip performance variance caused by chip process, voltage and
temperature.
config ROCKCHIP_RAMDISK
bool "Rockchip RAM disk support"
help
Saying Y here will allow you to use reserved RAM memory as a block
device.
config ROCKCHIP_SUSPEND_MODE
tristate "Rockchip suspend mode config"
depends on ROCKCHIP_SIP

View File

@@ -15,6 +15,7 @@ obj-$(CONFIG_ROCKCHIP_MTD_VENDOR_STORAGE) += mtd_vendor_storage.o
obj-$(CONFIG_ROCKCHIP_IPA) += rockchip_ipa.o
obj-$(CONFIG_ROCKCHIP_OPP) += rockchip_opp_select.o
obj-$(CONFIG_ROCKCHIP_PVTM) += rockchip_pvtm.o
obj-$(CONFIG_ROCKCHIP_RAMDISK) += rockchip_ramdisk.o
obj-$(CONFIG_ROCKCHIP_SUSPEND_MODE) += rockchip_pm_config.o
obj-$(CONFIG_ROCKCHIP_SYSTEM_MONITOR) += rockchip_system_monitor.o
obj-$(CONFIG_ROCKCHIP_THUNDER_BOOT_MMC) += rockchip_thunderboot_mmc.o

View File

@@ -130,7 +130,7 @@ static int rd_do_bvec(struct rd_device *rd, struct page *page,
return 0;
}
static blk_qc_t rd_make_request(struct request_queue *q, struct bio *bio)
static blk_qc_t rd_submit_bio(struct bio *bio)
{
struct rd_device *rd = bio->bi_disk->private_data;
struct bio_vec bvec;
@@ -145,6 +145,10 @@ static blk_qc_t rd_make_request(struct request_queue *q, struct bio *bio)
unsigned int len = bvec.bv_len;
int err;
/* Don't support un-aligned buffer */
WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) ||
(len & (SECTOR_SIZE - 1)));
err = rd_do_bvec(rd, bvec.bv_page, len, bvec.bv_offset,
bio_op(bio), sector);
if (err)
@@ -174,6 +178,7 @@ static int rd_rw_page(struct block_device *bdev, sector_t sector,
static const struct block_device_operations rd_fops = {
.owner = THIS_MODULE,
.submit_bio = rd_submit_bio,
.rw_page = rd_rw_page,
};
@@ -181,13 +186,10 @@ static int rd_init(struct rd_device *rd, int major, int minor)
{
struct gendisk *disk;
rd->rd_queue = blk_alloc_queue(GFP_KERNEL);
rd->rd_queue = blk_alloc_queue(NUMA_NO_NODE);
if (!rd->rd_queue)
return -ENOMEM;
blk_queue_make_request(rd->rd_queue, rd_make_request);
blk_queue_max_hw_sectors(rd->rd_queue, 1024);
/* This is so fdisk will align partitions on 4k, because of
* direct_access API needing 4k alignment, returning a PFN
* (This is only a problem on very small devices <= 4M,
@@ -206,7 +208,6 @@ static int rd_init(struct rd_device *rd, int major, int minor)
sprintf(disk->disk_name, "rd%d", minor);
set_capacity(disk, rd->mem_size >> SECTOR_SHIFT);
rd->rd_disk = disk;
rd->rd_queue->backing_dev_info->capabilities |= BDI_CAP_SYNCHRONOUS_IO;
/* Tell the block layer that this is not a rotational device */
blk_queue_flag_set(QUEUE_FLAG_NONROT, rd->rd_queue);