2 * ARAnyM block device driver
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/types.h>
16 #include <linux/blkdev.h>
17 #include <linux/hdreg.h>
18 #include <linux/slab.h>
20 #include <asm/natfeat.h>
25 /* emulation entry points */
27 NFHD_GET_CAPACITY = 14,
29 /* skip ACSI devices */
33 static inline s32 nfhd_read_write(u32 major, u32 minor, u32 rwflag, u32 recno,
36 return nf_call(nfhd_id + NFHD_READ_WRITE, major, minor, rwflag, recno,
40 static inline s32 nfhd_get_capacity(u32 major, u32 minor, u32 *blocks,
43 return nf_call(nfhd_id + NFHD_GET_CAPACITY, major, minor,
44 virt_to_phys(blocks), virt_to_phys(blocksize));
47 static LIST_HEAD(nfhd_list);
50 module_param(major_num, int, 0);
53 struct list_head list;
60 static void nfhd_submit_bio(struct bio *bio)
62 struct nfhd_device *dev = bio->bi_bdev->bd_disk->private_data;
64 struct bvec_iter iter;
66 sector_t sec = bio->bi_iter.bi_sector;
68 dir = bio_data_dir(bio);
70 bio_for_each_segment(bvec, bio, iter) {
73 nfhd_read_write(dev->id, 0, dir, sec >> shift, len >> shift,
74 page_to_phys(bvec.bv_page) + bvec.bv_offset);
80 static int nfhd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
82 struct nfhd_device *dev = bdev->bd_disk->private_data;
84 geo->cylinders = dev->blocks >> (6 - dev->bshift);
91 static const struct block_device_operations nfhd_ops = {
93 .submit_bio = nfhd_submit_bio,
94 .getgeo = nfhd_getgeo,
97 static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
99 struct nfhd_device *dev;
100 int dev_id = id - NFHD_DEV_OFFSET;
103 pr_info("nfhd%u: found device with %u blocks (%u bytes)\n", dev_id,
106 if (bsize < 512 || (bsize & (bsize - 1))) {
107 pr_warn("nfhd%u: invalid block size\n", dev_id);
111 dev = kmalloc(sizeof(struct nfhd_device), GFP_KERNEL);
116 dev->blocks = blocks;
118 dev->bshift = ffs(bsize) - 10;
120 dev->disk = blk_alloc_disk(NUMA_NO_NODE);
124 dev->disk->major = major_num;
125 dev->disk->first_minor = dev_id * 16;
126 dev->disk->minors = 16;
127 dev->disk->fops = &nfhd_ops;
128 dev->disk->private_data = dev;
129 sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
130 set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
131 blk_queue_logical_block_size(dev->disk->queue, bsize);
132 err = add_disk(dev->disk);
134 goto out_cleanup_disk;
136 list_add_tail(&dev->list, &nfhd_list);
148 static int __init nfhd_init(void)
154 nfhd_id = nf_get_id("XHDI");
158 ret = register_blkdev(major_num, "nfhd");
160 pr_warn("nfhd: unable to get major number\n");
167 for (i = NFHD_DEV_OFFSET; i < 24; i++) {
168 if (nfhd_get_capacity(i, 0, &blocks, &bsize))
170 nfhd_init_one(i, blocks, bsize);
176 static void __exit nfhd_exit(void)
178 struct nfhd_device *dev, *next;
180 list_for_each_entry_safe(dev, next, &nfhd_list, list) {
181 list_del(&dev->list);
182 del_gendisk(dev->disk);
186 unregister_blkdev(major_num, "nfhd");
189 module_init(nfhd_init);
190 module_exit(nfhd_exit);
192 MODULE_LICENSE("GPL");