21 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
30 #include <linux/fcntl.h>
49 #define SROM_CHUNK_SIZE ((size_t)4096)
58 #define SROM_WAIT_TRY_INTERVAL 20
63 #define SROM_MAX_WAIT_TRY_TIMES 1000
73 static int srom_major;
79 static struct cdev srom_cdev;
80 static struct class *srom_class;
81 static struct srom_dev *srom_devices;
88 loff_t off,
size_t count)
98 if (retval ==
HV_EBUSY && --retries > 0) {
102 pr_err(
"_srom_read: error %d\n", retval);
107 static ssize_t _srom_write(
int hv_devhdl,
const void *buf,
108 loff_t off,
size_t count)
118 if (retval ==
HV_EBUSY && --retries > 0) {
122 pr_err(
"_srom_write: error %d\n", retval);
174 static ssize_t srom_read(
struct file *filp,
char __user *buf,
175 size_t count, loff_t *f_pos)
195 hv_retval = _srom_read(srom->
hv_devhdl, kernbuf,
196 *f_pos, bytes_this_pass);
197 if (hv_retval <= 0) {
229 static ssize_t srom_write(
struct file *filp,
const char __user *buf,
230 size_t count, loff_t *f_pos)
255 hv_retval = _srom_write(srom->
hv_devhdl, kernbuf,
256 *f_pos, bytes_this_pass);
257 if (hv_retval <= 0) {
288 offset += filp->
f_pos;
347 .release = srom_release,
355 static int srom_setup_minor(
struct srom_dev *srom,
int index)
373 MKDEV(srom_major, index), srom,
"%d", index);
374 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
378 static int srom_init(
void)
396 if (!new_srom_devices) {
400 srom_devices = new_srom_devices;
405 pr_notice(
"srom/%d: hv_dev_open failed: %d.\n",
414 if (srom_devs == 0) {
424 srom_major =
MAJOR(dev);
432 srom_cdev.ops = &srom_fops;
433 result =
cdev_add(&srom_cdev, dev, srom_devs);
439 if (IS_ERR(srom_class)) {
440 result = PTR_ERR(srom_class);
444 srom_class->
devnode = srom_devnode;
447 for (i = 0; i < srom_devs; i++) {
448 result = srom_setup_minor(srom_devices + i, i);
456 for (i = 0; i < srom_devs; i++)
469 static void srom_cleanup(
void)
472 for (i = 0; i < srom_devs; i++)