2 * dcssblk.c -- the S/390 block driver for dcss memory
4 * Authors: Carsten Otte, Stefan Weinhuber, Gerald Schaefer
7 #define KMSG_COMPONENT "dcssblk"
8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/ctype.h>
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/blkdev.h>
17 #include <linux/smp_lock.h>
18 #include <linux/completion.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
21 #include <asm/extmem.h>
24 #define DCSSBLK_NAME "dcssblk"
25 #define DCSSBLK_MINORS_PER_DISK 1
26 #define DCSSBLK_PARM_LEN 400
27 #define DCSS_BUS_ID_SIZE 20
29 static int dcssblk_open(struct block_device *bdev, fmode_t mode);
30 static int dcssblk_release(struct gendisk *disk, fmode_t mode);
31 static int dcssblk_make_request(struct request_queue *q, struct bio *bio);
32 static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum,
33 void **kaddr, unsigned long *pfn);
35 static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0";
37 static int dcssblk_major;
38 static const struct block_device_operations dcssblk_devops = {
41 .release = dcssblk_release,
42 .direct_access = dcssblk_direct_access,
45 struct dcssblk_dev_info {
48 char segment_name[DCSS_BUS_ID_SIZE];
54 unsigned char save_pending;
55 unsigned char is_shared;
56 struct request_queue *dcssblk_queue;
58 struct list_head seg_list;
63 char segment_name[DCSS_BUS_ID_SIZE];
69 static ssize_t dcssblk_add_store(struct device * dev, struct device_attribute *attr, const char * buf,
71 static ssize_t dcssblk_remove_store(struct device * dev, struct device_attribute *attr, const char * buf,
73 static ssize_t dcssblk_save_store(struct device * dev, struct device_attribute *attr, const char * buf,
75 static ssize_t dcssblk_save_show(struct device *dev, struct device_attribute *attr, char *buf);
76 static ssize_t dcssblk_shared_store(struct device * dev, struct device_attribute *attr, const char * buf,
78 static ssize_t dcssblk_shared_show(struct device *dev, struct device_attribute *attr, char *buf);
79 static ssize_t dcssblk_seglist_show(struct device *dev,
80 struct device_attribute *attr,
83 static DEVICE_ATTR(add, S_IWUSR, NULL, dcssblk_add_store);
84 static DEVICE_ATTR(remove, S_IWUSR, NULL, dcssblk_remove_store);
85 static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show,
87 static DEVICE_ATTR(shared, S_IWUSR | S_IRUSR, dcssblk_shared_show,
88 dcssblk_shared_store);
89 static DEVICE_ATTR(seglist, S_IRUSR, dcssblk_seglist_show, NULL);
91 static struct device *dcssblk_root_dev;
93 static LIST_HEAD(dcssblk_devices);
94 static struct rw_semaphore dcssblk_devices_sem;
97 * release function for segment device.
100 dcssblk_release_segment(struct device *dev)
102 struct dcssblk_dev_info *dev_info;
103 struct segment_info *entry, *temp;
105 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
106 list_for_each_entry_safe(entry, temp, &dev_info->seg_list, lh) {
107 list_del(&entry->lh);
111 module_put(THIS_MODULE);
115 * get a minor number. needs to be called with
116 * down_write(&dcssblk_devices_sem) and the
117 * device needs to be enqueued before the semaphore is
121 dcssblk_assign_free_minor(struct dcssblk_dev_info *dev_info)
124 struct dcssblk_dev_info *entry;
126 if (dev_info == NULL)
128 for (minor = 0; minor < (1<<MINORBITS); minor++) {
130 // test if minor available
131 list_for_each_entry(entry, &dcssblk_devices, lh)
132 if (minor == entry->gd->first_minor)
134 if (!found) break; // got unused minor
138 dev_info->gd->first_minor = minor;
143 * get the struct dcssblk_dev_info from dcssblk_devices
144 * for the given name.
145 * down_read(&dcssblk_devices_sem) must be held.
147 static struct dcssblk_dev_info *
148 dcssblk_get_device_by_name(char *name)
150 struct dcssblk_dev_info *entry;
152 list_for_each_entry(entry, &dcssblk_devices, lh) {
153 if (!strcmp(name, entry->segment_name)) {
161 * get the struct segment_info from seg_list
162 * for the given name.
163 * down_read(&dcssblk_devices_sem) must be held.
165 static struct segment_info *
166 dcssblk_get_segment_by_name(char *name)
168 struct dcssblk_dev_info *dev_info;
169 struct segment_info *entry;
171 list_for_each_entry(dev_info, &dcssblk_devices, lh) {
172 list_for_each_entry(entry, &dev_info->seg_list, lh) {
173 if (!strcmp(name, entry->segment_name))
181 * get the highest address of the multi-segment block.
184 dcssblk_find_highest_addr(struct dcssblk_dev_info *dev_info)
186 unsigned long highest_addr;
187 struct segment_info *entry;
190 list_for_each_entry(entry, &dev_info->seg_list, lh) {
191 if (highest_addr < entry->end)
192 highest_addr = entry->end;
198 * get the lowest address of the multi-segment block.
201 dcssblk_find_lowest_addr(struct dcssblk_dev_info *dev_info)
204 unsigned long lowest_addr;
205 struct segment_info *entry;
209 list_for_each_entry(entry, &dev_info->seg_list, lh) {
210 if (set_first == 0) {
211 lowest_addr = entry->start;
214 if (lowest_addr > entry->start)
215 lowest_addr = entry->start;
222 * Check continuity of segments.
225 dcssblk_is_continuous(struct dcssblk_dev_info *dev_info)
228 struct segment_info *sort_list, *entry, temp;
230 if (dev_info->num_of_segments <= 1)
234 sizeof(struct segment_info) * dev_info->num_of_segments,
236 if (sort_list == NULL)
239 list_for_each_entry(entry, &dev_info->seg_list, lh) {
240 memcpy(&sort_list[i], entry, sizeof(struct segment_info));
245 for (i = 0; i < dev_info->num_of_segments; i++)
246 for (j = 0; j < dev_info->num_of_segments; j++)
247 if (sort_list[j].start > sort_list[i].start) {
248 memcpy(&temp, &sort_list[i],
249 sizeof(struct segment_info));
250 memcpy(&sort_list[i], &sort_list[j],
251 sizeof(struct segment_info));
252 memcpy(&sort_list[j], &temp,
253 sizeof(struct segment_info));
256 /* check continuity */
257 for (i = 0; i < dev_info->num_of_segments - 1; i++) {
258 if ((sort_list[i].end + 1) != sort_list[i+1].start) {
259 pr_err("Adjacent DCSSs %s and %s are not "
260 "contiguous\n", sort_list[i].segment_name,
261 sort_list[i+1].segment_name);
265 /* EN and EW are allowed in a block device */
266 if (sort_list[i].segment_type != sort_list[i+1].segment_type) {
267 if (!(sort_list[i].segment_type & SEGMENT_EXCLUSIVE) ||
268 (sort_list[i].segment_type == SEG_TYPE_ER) ||
269 !(sort_list[i+1].segment_type &
270 SEGMENT_EXCLUSIVE) ||
271 (sort_list[i+1].segment_type == SEG_TYPE_ER)) {
272 pr_err("DCSS %s and DCSS %s have "
273 "incompatible types\n",
274 sort_list[i].segment_name,
275 sort_list[i+1].segment_name);
291 dcssblk_load_segment(char *name, struct segment_info **seg_info)
295 /* already loaded? */
296 down_read(&dcssblk_devices_sem);
297 *seg_info = dcssblk_get_segment_by_name(name);
298 up_read(&dcssblk_devices_sem);
299 if (*seg_info != NULL)
302 /* get a struct segment_info */
303 *seg_info = kzalloc(sizeof(struct segment_info), GFP_KERNEL);
304 if (*seg_info == NULL)
307 strcpy((*seg_info)->segment_name, name);
309 /* load the segment */
310 rc = segment_load(name, SEGMENT_SHARED,
311 &(*seg_info)->start, &(*seg_info)->end);
313 segment_warning(rc, (*seg_info)->segment_name);
316 INIT_LIST_HEAD(&(*seg_info)->lh);
317 (*seg_info)->segment_type = rc;
322 static void dcssblk_unregister_callback(struct device *dev)
324 device_unregister(dev);
329 * device attribute for switching shared/nonshared (exclusive)
330 * operation (show + store)
333 dcssblk_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
335 struct dcssblk_dev_info *dev_info;
337 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
338 return sprintf(buf, dev_info->is_shared ? "1\n" : "0\n");
342 dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count)
344 struct dcssblk_dev_info *dev_info;
345 struct segment_info *entry, *temp;
348 if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
350 down_write(&dcssblk_devices_sem);
351 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
352 if (atomic_read(&dev_info->use_count)) {
356 if (inbuf[0] == '1') {
357 /* reload segments in shared mode */
358 list_for_each_entry(entry, &dev_info->seg_list, lh) {
359 rc = segment_modify_shared(entry->segment_name,
362 BUG_ON(rc == -EINVAL);
367 dev_info->is_shared = 1;
368 switch (dev_info->segment_type) {
372 set_disk_ro(dev_info->gd, 1);
374 } else if (inbuf[0] == '0') {
375 /* reload segments in exclusive mode */
376 if (dev_info->segment_type == SEG_TYPE_SC) {
377 pr_err("DCSS %s is of type SC and cannot be "
378 "loaded as exclusive-writable\n",
379 dev_info->segment_name);
383 list_for_each_entry(entry, &dev_info->seg_list, lh) {
384 rc = segment_modify_shared(entry->segment_name,
387 BUG_ON(rc == -EINVAL);
392 dev_info->is_shared = 0;
393 set_disk_ro(dev_info->gd, 0);
402 pr_err("DCSS device %s is removed after a failed access mode "
403 "change\n", dev_info->segment_name);
405 list_for_each_entry(entry, &dev_info->seg_list, lh) {
407 segment_unload(entry->segment_name);
409 list_del(&dev_info->lh);
411 del_gendisk(dev_info->gd);
412 blk_cleanup_queue(dev_info->dcssblk_queue);
413 dev_info->gd->queue = NULL;
414 put_disk(dev_info->gd);
415 rc = device_schedule_callback(dev, dcssblk_unregister_callback);
417 up_write(&dcssblk_devices_sem);
422 * device attribute for save operation on current copy
423 * of the segment. If the segment is busy, saving will
424 * become pending until it gets released, which can be
425 * undone by storing a non-true value to this entry.
429 dcssblk_save_show(struct device *dev, struct device_attribute *attr, char *buf)
431 struct dcssblk_dev_info *dev_info;
433 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
434 return sprintf(buf, dev_info->save_pending ? "1\n" : "0\n");
438 dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count)
440 struct dcssblk_dev_info *dev_info;
441 struct segment_info *entry;
443 if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
445 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
447 down_write(&dcssblk_devices_sem);
448 if (inbuf[0] == '1') {
449 if (atomic_read(&dev_info->use_count) == 0) {
450 // device is idle => we save immediately
451 pr_info("All DCSSs that map to device %s are "
452 "saved\n", dev_info->segment_name);
453 list_for_each_entry(entry, &dev_info->seg_list, lh) {
454 segment_save(entry->segment_name);
457 // device is busy => we save it when it becomes
458 // idle in dcssblk_release
459 pr_info("Device %s is in use, its DCSSs will be "
460 "saved when it becomes idle\n",
461 dev_info->segment_name);
462 dev_info->save_pending = 1;
464 } else if (inbuf[0] == '0') {
465 if (dev_info->save_pending) {
466 // device is busy & the user wants to undo his save
468 dev_info->save_pending = 0;
469 pr_info("A pending save request for device %s "
470 "has been canceled\n",
471 dev_info->segment_name);
474 up_write(&dcssblk_devices_sem);
477 up_write(&dcssblk_devices_sem);
482 * device attribute for showing all segments in a device
485 dcssblk_seglist_show(struct device *dev, struct device_attribute *attr,
490 struct dcssblk_dev_info *dev_info;
491 struct segment_info *entry;
493 down_read(&dcssblk_devices_sem);
494 dev_info = container_of(dev, struct dcssblk_dev_info, dev);
497 list_for_each_entry(entry, &dev_info->seg_list, lh) {
498 strcpy(&buf[i], entry->segment_name);
499 i += strlen(entry->segment_name);
503 up_read(&dcssblk_devices_sem);
508 * device attribute for adding devices
511 dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
513 int rc, i, j, num_of_segments;
514 struct dcssblk_dev_info *dev_info;
515 struct segment_info *seg_info, *temp;
517 unsigned long seg_byte_size;
521 if (dev != dcssblk_root_dev) {
525 if ((count < 1) || (buf[0] == '\0') || (buf[0] == '\n')) {
530 local_buf = kmalloc(count + 1, GFP_KERNEL);
531 if (local_buf == NULL) {
540 for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
541 for (j = i; (buf[j] != ':') &&
545 local_buf[j-i] = toupper(buf[j]);
547 local_buf[j-i] = '\0';
548 if (((j - i) == 0) || ((j - i) > 8)) {
553 rc = dcssblk_load_segment(local_buf, &seg_info);
557 * get a struct dcssblk_dev_info
559 if (num_of_segments == 0) {
560 dev_info = kzalloc(sizeof(struct dcssblk_dev_info),
562 if (dev_info == NULL) {
566 strcpy(dev_info->segment_name, local_buf);
567 dev_info->segment_type = seg_info->segment_type;
568 INIT_LIST_HEAD(&dev_info->seg_list);
570 list_add_tail(&seg_info->lh, &dev_info->seg_list);
574 if ((buf[j] == '\0') || (buf[j] == '\n'))
578 /* no trailing colon at the end of the input */
579 if ((i > 0) && (buf[i-1] == ':')) {
583 strlcpy(local_buf, buf, i + 1);
584 dev_info->num_of_segments = num_of_segments;
585 rc = dcssblk_is_continuous(dev_info);
589 dev_info->start = dcssblk_find_lowest_addr(dev_info);
590 dev_info->end = dcssblk_find_highest_addr(dev_info);
592 dev_set_name(&dev_info->dev, dev_info->segment_name);
593 dev_info->dev.release = dcssblk_release_segment;
594 INIT_LIST_HEAD(&dev_info->lh);
595 dev_info->gd = alloc_disk(DCSSBLK_MINORS_PER_DISK);
596 if (dev_info->gd == NULL) {
600 dev_info->gd->major = dcssblk_major;
601 dev_info->gd->fops = &dcssblk_devops;
602 dev_info->dcssblk_queue = blk_alloc_queue(GFP_KERNEL);
603 dev_info->gd->queue = dev_info->dcssblk_queue;
604 dev_info->gd->private_data = dev_info;
605 dev_info->gd->driverfs_dev = &dev_info->dev;
606 blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
607 blk_queue_logical_block_size(dev_info->dcssblk_queue, 4096);
609 seg_byte_size = (dev_info->end - dev_info->start + 1);
610 set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors
611 pr_info("Loaded %s with total size %lu bytes and capacity %lu "
612 "sectors\n", local_buf, seg_byte_size, seg_byte_size >> 9);
614 dev_info->save_pending = 0;
615 dev_info->is_shared = 1;
616 dev_info->dev.parent = dcssblk_root_dev;
619 *get minor, add to list
621 down_write(&dcssblk_devices_sem);
622 if (dcssblk_get_segment_by_name(local_buf)) {
626 rc = dcssblk_assign_free_minor(dev_info);
629 sprintf(dev_info->gd->disk_name, "dcssblk%d",
630 dev_info->gd->first_minor);
631 list_add_tail(&dev_info->lh, &dcssblk_devices);
633 if (!try_module_get(THIS_MODULE)) {
638 * register the device
640 rc = device_register(&dev_info->dev);
642 module_put(THIS_MODULE);
645 get_device(&dev_info->dev);
646 rc = device_create_file(&dev_info->dev, &dev_attr_shared);
649 rc = device_create_file(&dev_info->dev, &dev_attr_save);
652 rc = device_create_file(&dev_info->dev, &dev_attr_seglist);
656 add_disk(dev_info->gd);
658 switch (dev_info->segment_type) {
662 set_disk_ro(dev_info->gd,1);
665 set_disk_ro(dev_info->gd,0);
668 up_write(&dcssblk_devices_sem);
673 list_del(&dev_info->lh);
674 blk_cleanup_queue(dev_info->dcssblk_queue);
675 dev_info->gd->queue = NULL;
676 put_disk(dev_info->gd);
677 device_unregister(&dev_info->dev);
678 list_for_each_entry(seg_info, &dev_info->seg_list, lh) {
679 segment_unload(seg_info->segment_name);
681 put_device(&dev_info->dev);
682 up_write(&dcssblk_devices_sem);
685 list_del(&dev_info->lh);
687 blk_cleanup_queue(dev_info->dcssblk_queue);
688 dev_info->gd->queue = NULL;
689 put_disk(dev_info->gd);
690 up_write(&dcssblk_devices_sem);
692 if (dev_info == NULL)
694 list_for_each_entry_safe(seg_info, temp, &dev_info->seg_list, lh) {
695 list_del(&seg_info->lh);
696 segment_unload(seg_info->segment_name);
707 * device attribute for removing devices
710 dcssblk_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
712 struct dcssblk_dev_info *dev_info;
713 struct segment_info *entry;
717 if (dev != dcssblk_root_dev) {
720 local_buf = kmalloc(count + 1, GFP_KERNEL);
721 if (local_buf == NULL) {
727 for (i = 0; ((*(buf+i)!='\0') && (*(buf+i)!='\n') && i < count); i++) {
728 local_buf[i] = toupper(buf[i]);
731 if ((i == 0) || (i > 8)) {
736 down_write(&dcssblk_devices_sem);
737 dev_info = dcssblk_get_device_by_name(local_buf);
738 if (dev_info == NULL) {
739 up_write(&dcssblk_devices_sem);
740 pr_warning("Device %s cannot be removed because it is not a "
741 "known device\n", local_buf);
745 if (atomic_read(&dev_info->use_count) != 0) {
746 up_write(&dcssblk_devices_sem);
747 pr_warning("Device %s cannot be removed while it is in "
753 list_del(&dev_info->lh);
754 del_gendisk(dev_info->gd);
755 blk_cleanup_queue(dev_info->dcssblk_queue);
756 dev_info->gd->queue = NULL;
757 put_disk(dev_info->gd);
758 device_unregister(&dev_info->dev);
760 /* unload all related segments */
761 list_for_each_entry(entry, &dev_info->seg_list, lh)
762 segment_unload(entry->segment_name);
764 put_device(&dev_info->dev);
765 up_write(&dcssblk_devices_sem);
774 dcssblk_open(struct block_device *bdev, fmode_t mode)
776 struct dcssblk_dev_info *dev_info;
780 dev_info = bdev->bd_disk->private_data;
781 if (NULL == dev_info) {
785 atomic_inc(&dev_info->use_count);
786 bdev->bd_block_size = 4096;
794 dcssblk_release(struct gendisk *disk, fmode_t mode)
796 struct dcssblk_dev_info *dev_info = disk->private_data;
797 struct segment_info *entry;
805 down_write(&dcssblk_devices_sem);
806 if (atomic_dec_and_test(&dev_info->use_count)
807 && (dev_info->save_pending)) {
808 pr_info("Device %s has become idle and is being saved "
809 "now\n", dev_info->segment_name);
810 list_for_each_entry(entry, &dev_info->seg_list, lh) {
811 segment_save(entry->segment_name);
813 dev_info->save_pending = 0;
815 up_write(&dcssblk_devices_sem);
823 dcssblk_make_request(struct request_queue *q, struct bio *bio)
825 struct dcssblk_dev_info *dev_info;
826 struct bio_vec *bvec;
828 unsigned long page_addr;
829 unsigned long source_addr;
830 unsigned long bytes_done;
834 dev_info = bio->bi_bdev->bd_disk->private_data;
835 if (dev_info == NULL)
837 if ((bio->bi_sector & 7) != 0 || (bio->bi_size & 4095) != 0)
838 /* Request is not page-aligned. */
840 if (((bio->bi_size >> 9) + bio->bi_sector)
841 > get_capacity(bio->bi_bdev->bd_disk)) {
842 /* Request beyond end of DCSS segment. */
845 /* verify data transfer direction */
846 if (dev_info->is_shared) {
847 switch (dev_info->segment_type) {
851 /* cannot write to these segments */
852 if (bio_data_dir(bio) == WRITE) {
853 pr_warning("Writing to %s failed because it "
854 "is a read-only device\n",
855 dev_name(&dev_info->dev));
861 index = (bio->bi_sector >> 3);
862 bio_for_each_segment(bvec, bio, i) {
863 page_addr = (unsigned long)
864 page_address(bvec->bv_page) + bvec->bv_offset;
865 source_addr = dev_info->start + (index<<12) + bytes_done;
866 if (unlikely((page_addr & 4095) != 0) || (bvec->bv_len & 4095) != 0)
869 if (bio_data_dir(bio) == READ) {
870 memcpy((void*)page_addr, (void*)source_addr,
873 memcpy((void*)source_addr, (void*)page_addr,
876 bytes_done += bvec->bv_len;
886 dcssblk_direct_access (struct block_device *bdev, sector_t secnum,
887 void **kaddr, unsigned long *pfn)
889 struct dcssblk_dev_info *dev_info;
892 dev_info = bdev->bd_disk->private_data;
895 if (secnum % (PAGE_SIZE/512))
897 pgoff = secnum / (PAGE_SIZE / 512);
898 if ((pgoff+1)*PAGE_SIZE-1 > dev_info->end - dev_info->start)
900 *kaddr = (void *) (dev_info->start+pgoff*PAGE_SIZE);
901 *pfn = virt_to_phys(*kaddr) >> PAGE_SHIFT;
907 dcssblk_check_params(void)
910 char buf[DCSSBLK_PARM_LEN + 1];
911 struct dcssblk_dev_info *dev_info;
913 for (i = 0; (i < DCSSBLK_PARM_LEN) && (dcssblk_segments[i] != '\0');
915 for (j = i; (dcssblk_segments[j] != ',') &&
916 (dcssblk_segments[j] != '\0') &&
917 (dcssblk_segments[j] != '(') &&
918 (j < DCSSBLK_PARM_LEN); j++)
920 buf[j-i] = dcssblk_segments[j];
923 rc = dcssblk_add_store(dcssblk_root_dev, NULL, buf, j-i);
924 if ((rc >= 0) && (dcssblk_segments[j] == '(')) {
925 for (k = 0; (buf[k] != ':') && (buf[k] != '\0'); k++)
926 buf[k] = toupper(buf[k]);
928 if (!strncmp(&dcssblk_segments[j], "(local)", 7)) {
929 down_read(&dcssblk_devices_sem);
930 dev_info = dcssblk_get_device_by_name(buf);
931 up_read(&dcssblk_devices_sem);
933 dcssblk_shared_store(&dev_info->dev,
937 while ((dcssblk_segments[j] != ',') &&
938 (dcssblk_segments[j] != '\0'))
942 if (dcssblk_segments[j] == '\0')
951 static int dcssblk_freeze(struct device *dev)
953 struct dcssblk_dev_info *dev_info;
956 list_for_each_entry(dev_info, &dcssblk_devices, lh) {
957 switch (dev_info->segment_type) {
961 if (!dev_info->is_shared)
972 pr_err("Suspending the system failed because DCSS device %s "
974 dev_info->segment_name);
978 static int dcssblk_restore(struct device *dev)
980 struct dcssblk_dev_info *dev_info;
981 struct segment_info *entry;
982 unsigned long start, end;
985 list_for_each_entry(dev_info, &dcssblk_devices, lh) {
986 list_for_each_entry(entry, &dev_info->seg_list, lh) {
987 segment_unload(entry->segment_name);
988 rc = segment_load(entry->segment_name, SEGMENT_SHARED,
991 // TODO in_use check ?
992 segment_warning(rc, entry->segment_name);
995 if (start != entry->start || end != entry->end) {
996 pr_err("The address range of DCSS %s changed "
997 "while the system was suspended\n",
998 entry->segment_name);
1005 panic("fatal dcssblk resume error\n");
1008 static int dcssblk_thaw(struct device *dev)
1013 static const struct dev_pm_ops dcssblk_pm_ops = {
1014 .freeze = dcssblk_freeze,
1015 .thaw = dcssblk_thaw,
1016 .restore = dcssblk_restore,
1019 static struct platform_driver dcssblk_pdrv = {
1022 .owner = THIS_MODULE,
1023 .pm = &dcssblk_pm_ops,
1027 static struct platform_device *dcssblk_pdev;
1031 * The init/exit functions.
1036 platform_device_unregister(dcssblk_pdev);
1037 platform_driver_unregister(&dcssblk_pdrv);
1038 root_device_unregister(dcssblk_root_dev);
1039 unregister_blkdev(dcssblk_major, DCSSBLK_NAME);
1047 rc = platform_driver_register(&dcssblk_pdrv);
1051 dcssblk_pdev = platform_device_register_simple("dcssblk", -1, NULL,
1053 if (IS_ERR(dcssblk_pdev)) {
1054 rc = PTR_ERR(dcssblk_pdev);
1058 dcssblk_root_dev = root_device_register("dcssblk");
1059 if (IS_ERR(dcssblk_root_dev)) {
1060 rc = PTR_ERR(dcssblk_root_dev);
1063 rc = device_create_file(dcssblk_root_dev, &dev_attr_add);
1066 rc = device_create_file(dcssblk_root_dev, &dev_attr_remove);
1069 rc = register_blkdev(0, DCSSBLK_NAME);
1073 init_rwsem(&dcssblk_devices_sem);
1075 dcssblk_check_params();
1079 root_device_unregister(dcssblk_root_dev);
1081 platform_device_unregister(dcssblk_pdev);
1083 platform_driver_unregister(&dcssblk_pdrv);
1087 module_init(dcssblk_init);
1088 module_exit(dcssblk_exit);
1090 module_param_string(segments, dcssblk_segments, DCSSBLK_PARM_LEN, 0444);
1091 MODULE_PARM_DESC(segments, "Name of DCSS segment(s) to be loaded, "
1092 "comma-separated list, names in each set separated "
1093 "by commas are separated by colons, each set contains "
1094 "names of contiguous segments and each name max. 8 chars.\n"
1095 "Adding \"(local)\" to the end of each set equals echoing 0 "
1096 "to /sys/devices/dcssblk/<device name>/shared after loading "
1097 "the contiguous segments - \n"
1098 "e.g. segments=\"mydcss1,mydcss2:mydcss3,mydcss4(local)\"");
1100 MODULE_LICENSE("GPL");