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/completion.h>
18 #include <linux/interrupt.h>
19 #include <linux/platform_device.h>
20 #include <asm/extmem.h>
23 #define DCSSBLK_NAME "dcssblk"
24 #define DCSSBLK_MINORS_PER_DISK 1
25 #define DCSSBLK_PARM_LEN 400
26 #define DCSS_BUS_ID_SIZE 20
28 static int dcssblk_open(struct block_device
*bdev
, fmode_t mode
);
29 static void dcssblk_release(struct gendisk
*disk
, fmode_t mode
);
30 static void dcssblk_make_request(struct request_queue
*q
, struct bio
*bio
);
31 static int dcssblk_direct_access(struct block_device
*bdev
, sector_t secnum
,
32 void **kaddr
, unsigned long *pfn
);
34 static char dcssblk_segments
[DCSSBLK_PARM_LEN
] = "\0";
36 static int dcssblk_major
;
37 static const struct block_device_operations dcssblk_devops
= {
40 .release
= dcssblk_release
,
41 .direct_access
= dcssblk_direct_access
,
44 struct dcssblk_dev_info
{
47 char segment_name
[DCSS_BUS_ID_SIZE
];
53 unsigned char save_pending
;
54 unsigned char is_shared
;
55 struct request_queue
*dcssblk_queue
;
57 struct list_head seg_list
;
62 char segment_name
[DCSS_BUS_ID_SIZE
];
68 static ssize_t
dcssblk_add_store(struct device
* dev
, struct device_attribute
*attr
, const char * buf
,
70 static ssize_t
dcssblk_remove_store(struct device
* dev
, struct device_attribute
*attr
, const char * buf
,
73 static DEVICE_ATTR(add
, S_IWUSR
, NULL
, dcssblk_add_store
);
74 static DEVICE_ATTR(remove
, S_IWUSR
, NULL
, dcssblk_remove_store
);
76 static struct device
*dcssblk_root_dev
;
78 static LIST_HEAD(dcssblk_devices
);
79 static struct rw_semaphore dcssblk_devices_sem
;
82 * release function for segment device.
85 dcssblk_release_segment(struct device
*dev
)
87 struct dcssblk_dev_info
*dev_info
;
88 struct segment_info
*entry
, *temp
;
90 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
91 list_for_each_entry_safe(entry
, temp
, &dev_info
->seg_list
, lh
) {
96 module_put(THIS_MODULE
);
100 * get a minor number. needs to be called with
101 * down_write(&dcssblk_devices_sem) and the
102 * device needs to be enqueued before the semaphore is
106 dcssblk_assign_free_minor(struct dcssblk_dev_info
*dev_info
)
109 struct dcssblk_dev_info
*entry
;
111 if (dev_info
== NULL
)
113 for (minor
= 0; minor
< (1<<MINORBITS
); minor
++) {
115 // test if minor available
116 list_for_each_entry(entry
, &dcssblk_devices
, lh
)
117 if (minor
== entry
->gd
->first_minor
)
119 if (!found
) break; // got unused minor
123 dev_info
->gd
->first_minor
= minor
;
128 * get the struct dcssblk_dev_info from dcssblk_devices
129 * for the given name.
130 * down_read(&dcssblk_devices_sem) must be held.
132 static struct dcssblk_dev_info
*
133 dcssblk_get_device_by_name(char *name
)
135 struct dcssblk_dev_info
*entry
;
137 list_for_each_entry(entry
, &dcssblk_devices
, lh
) {
138 if (!strcmp(name
, entry
->segment_name
)) {
146 * get the struct segment_info from seg_list
147 * for the given name.
148 * down_read(&dcssblk_devices_sem) must be held.
150 static struct segment_info
*
151 dcssblk_get_segment_by_name(char *name
)
153 struct dcssblk_dev_info
*dev_info
;
154 struct segment_info
*entry
;
156 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
157 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
158 if (!strcmp(name
, entry
->segment_name
))
166 * get the highest address of the multi-segment block.
169 dcssblk_find_highest_addr(struct dcssblk_dev_info
*dev_info
)
171 unsigned long highest_addr
;
172 struct segment_info
*entry
;
175 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
176 if (highest_addr
< entry
->end
)
177 highest_addr
= entry
->end
;
183 * get the lowest address of the multi-segment block.
186 dcssblk_find_lowest_addr(struct dcssblk_dev_info
*dev_info
)
189 unsigned long lowest_addr
;
190 struct segment_info
*entry
;
194 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
195 if (set_first
== 0) {
196 lowest_addr
= entry
->start
;
199 if (lowest_addr
> entry
->start
)
200 lowest_addr
= entry
->start
;
207 * Check continuity of segments.
210 dcssblk_is_continuous(struct dcssblk_dev_info
*dev_info
)
213 struct segment_info
*sort_list
, *entry
, temp
;
215 if (dev_info
->num_of_segments
<= 1)
219 sizeof(struct segment_info
) * dev_info
->num_of_segments
,
221 if (sort_list
== NULL
)
224 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
225 memcpy(&sort_list
[i
], entry
, sizeof(struct segment_info
));
230 for (i
= 0; i
< dev_info
->num_of_segments
; i
++)
231 for (j
= 0; j
< dev_info
->num_of_segments
; j
++)
232 if (sort_list
[j
].start
> sort_list
[i
].start
) {
233 memcpy(&temp
, &sort_list
[i
],
234 sizeof(struct segment_info
));
235 memcpy(&sort_list
[i
], &sort_list
[j
],
236 sizeof(struct segment_info
));
237 memcpy(&sort_list
[j
], &temp
,
238 sizeof(struct segment_info
));
241 /* check continuity */
242 for (i
= 0; i
< dev_info
->num_of_segments
- 1; i
++) {
243 if ((sort_list
[i
].end
+ 1) != sort_list
[i
+1].start
) {
244 pr_err("Adjacent DCSSs %s and %s are not "
245 "contiguous\n", sort_list
[i
].segment_name
,
246 sort_list
[i
+1].segment_name
);
250 /* EN and EW are allowed in a block device */
251 if (sort_list
[i
].segment_type
!= sort_list
[i
+1].segment_type
) {
252 if (!(sort_list
[i
].segment_type
& SEGMENT_EXCLUSIVE
) ||
253 (sort_list
[i
].segment_type
== SEG_TYPE_ER
) ||
254 !(sort_list
[i
+1].segment_type
&
255 SEGMENT_EXCLUSIVE
) ||
256 (sort_list
[i
+1].segment_type
== SEG_TYPE_ER
)) {
257 pr_err("DCSS %s and DCSS %s have "
258 "incompatible types\n",
259 sort_list
[i
].segment_name
,
260 sort_list
[i
+1].segment_name
);
276 dcssblk_load_segment(char *name
, struct segment_info
**seg_info
)
280 /* already loaded? */
281 down_read(&dcssblk_devices_sem
);
282 *seg_info
= dcssblk_get_segment_by_name(name
);
283 up_read(&dcssblk_devices_sem
);
284 if (*seg_info
!= NULL
)
287 /* get a struct segment_info */
288 *seg_info
= kzalloc(sizeof(struct segment_info
), GFP_KERNEL
);
289 if (*seg_info
== NULL
)
292 strcpy((*seg_info
)->segment_name
, name
);
294 /* load the segment */
295 rc
= segment_load(name
, SEGMENT_SHARED
,
296 &(*seg_info
)->start
, &(*seg_info
)->end
);
298 segment_warning(rc
, (*seg_info
)->segment_name
);
301 INIT_LIST_HEAD(&(*seg_info
)->lh
);
302 (*seg_info
)->segment_type
= rc
;
307 static void dcssblk_unregister_callback(struct device
*dev
)
309 device_unregister(dev
);
314 * device attribute for switching shared/nonshared (exclusive)
315 * operation (show + store)
318 dcssblk_shared_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
320 struct dcssblk_dev_info
*dev_info
;
322 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
323 return sprintf(buf
, dev_info
->is_shared
? "1\n" : "0\n");
327 dcssblk_shared_store(struct device
*dev
, struct device_attribute
*attr
, const char *inbuf
, size_t count
)
329 struct dcssblk_dev_info
*dev_info
;
330 struct segment_info
*entry
, *temp
;
333 if ((count
> 1) && (inbuf
[1] != '\n') && (inbuf
[1] != '\0'))
335 down_write(&dcssblk_devices_sem
);
336 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
337 if (atomic_read(&dev_info
->use_count
)) {
341 if (inbuf
[0] == '1') {
342 /* reload segments in shared mode */
343 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
344 rc
= segment_modify_shared(entry
->segment_name
,
347 BUG_ON(rc
== -EINVAL
);
352 dev_info
->is_shared
= 1;
353 switch (dev_info
->segment_type
) {
357 set_disk_ro(dev_info
->gd
, 1);
359 } else if (inbuf
[0] == '0') {
360 /* reload segments in exclusive mode */
361 if (dev_info
->segment_type
== SEG_TYPE_SC
) {
362 pr_err("DCSS %s is of type SC and cannot be "
363 "loaded as exclusive-writable\n",
364 dev_info
->segment_name
);
368 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
369 rc
= segment_modify_shared(entry
->segment_name
,
372 BUG_ON(rc
== -EINVAL
);
377 dev_info
->is_shared
= 0;
378 set_disk_ro(dev_info
->gd
, 0);
387 pr_err("DCSS device %s is removed after a failed access mode "
388 "change\n", dev_info
->segment_name
);
390 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
392 segment_unload(entry
->segment_name
);
394 list_del(&dev_info
->lh
);
396 del_gendisk(dev_info
->gd
);
397 blk_cleanup_queue(dev_info
->dcssblk_queue
);
398 dev_info
->gd
->queue
= NULL
;
399 put_disk(dev_info
->gd
);
400 rc
= device_schedule_callback(dev
, dcssblk_unregister_callback
);
402 up_write(&dcssblk_devices_sem
);
405 static DEVICE_ATTR(shared
, S_IWUSR
| S_IRUSR
, dcssblk_shared_show
,
406 dcssblk_shared_store
);
409 * device attribute for save operation on current copy
410 * of the segment. If the segment is busy, saving will
411 * become pending until it gets released, which can be
412 * undone by storing a non-true value to this entry.
416 dcssblk_save_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
418 struct dcssblk_dev_info
*dev_info
;
420 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
421 return sprintf(buf
, dev_info
->save_pending
? "1\n" : "0\n");
425 dcssblk_save_store(struct device
*dev
, struct device_attribute
*attr
, const char *inbuf
, size_t count
)
427 struct dcssblk_dev_info
*dev_info
;
428 struct segment_info
*entry
;
430 if ((count
> 1) && (inbuf
[1] != '\n') && (inbuf
[1] != '\0'))
432 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
434 down_write(&dcssblk_devices_sem
);
435 if (inbuf
[0] == '1') {
436 if (atomic_read(&dev_info
->use_count
) == 0) {
437 // device is idle => we save immediately
438 pr_info("All DCSSs that map to device %s are "
439 "saved\n", dev_info
->segment_name
);
440 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
441 segment_save(entry
->segment_name
);
444 // device is busy => we save it when it becomes
445 // idle in dcssblk_release
446 pr_info("Device %s is in use, its DCSSs will be "
447 "saved when it becomes idle\n",
448 dev_info
->segment_name
);
449 dev_info
->save_pending
= 1;
451 } else if (inbuf
[0] == '0') {
452 if (dev_info
->save_pending
) {
453 // device is busy & the user wants to undo his save
455 dev_info
->save_pending
= 0;
456 pr_info("A pending save request for device %s "
457 "has been canceled\n",
458 dev_info
->segment_name
);
461 up_write(&dcssblk_devices_sem
);
464 up_write(&dcssblk_devices_sem
);
467 static DEVICE_ATTR(save
, S_IWUSR
| S_IRUSR
, dcssblk_save_show
,
471 * device attribute for showing all segments in a device
474 dcssblk_seglist_show(struct device
*dev
, struct device_attribute
*attr
,
479 struct dcssblk_dev_info
*dev_info
;
480 struct segment_info
*entry
;
482 down_read(&dcssblk_devices_sem
);
483 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
486 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
487 strcpy(&buf
[i
], entry
->segment_name
);
488 i
+= strlen(entry
->segment_name
);
492 up_read(&dcssblk_devices_sem
);
495 static DEVICE_ATTR(seglist
, S_IRUSR
, dcssblk_seglist_show
, NULL
);
497 static struct attribute
*dcssblk_dev_attrs
[] = {
498 &dev_attr_shared
.attr
,
500 &dev_attr_seglist
.attr
,
503 static struct attribute_group dcssblk_dev_attr_group
= {
504 .attrs
= dcssblk_dev_attrs
,
506 static const struct attribute_group
*dcssblk_dev_attr_groups
[] = {
507 &dcssblk_dev_attr_group
,
512 * device attribute for adding devices
515 dcssblk_add_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
517 int rc
, i
, j
, num_of_segments
;
518 struct dcssblk_dev_info
*dev_info
;
519 struct segment_info
*seg_info
, *temp
;
521 unsigned long seg_byte_size
;
525 if (dev
!= dcssblk_root_dev
) {
529 if ((count
< 1) || (buf
[0] == '\0') || (buf
[0] == '\n')) {
534 local_buf
= kmalloc(count
+ 1, GFP_KERNEL
);
535 if (local_buf
== NULL
) {
544 for (i
= 0; ((buf
[i
] != '\0') && (buf
[i
] != '\n') && i
< count
); i
++) {
545 for (j
= i
; (buf
[j
] != ':') &&
549 local_buf
[j
-i
] = toupper(buf
[j
]);
551 local_buf
[j
-i
] = '\0';
552 if (((j
- i
) == 0) || ((j
- i
) > 8)) {
557 rc
= dcssblk_load_segment(local_buf
, &seg_info
);
561 * get a struct dcssblk_dev_info
563 if (num_of_segments
== 0) {
564 dev_info
= kzalloc(sizeof(struct dcssblk_dev_info
),
566 if (dev_info
== NULL
) {
570 strcpy(dev_info
->segment_name
, local_buf
);
571 dev_info
->segment_type
= seg_info
->segment_type
;
572 INIT_LIST_HEAD(&dev_info
->seg_list
);
574 list_add_tail(&seg_info
->lh
, &dev_info
->seg_list
);
578 if ((buf
[j
] == '\0') || (buf
[j
] == '\n'))
582 /* no trailing colon at the end of the input */
583 if ((i
> 0) && (buf
[i
-1] == ':')) {
587 strlcpy(local_buf
, buf
, i
+ 1);
588 dev_info
->num_of_segments
= num_of_segments
;
589 rc
= dcssblk_is_continuous(dev_info
);
593 dev_info
->start
= dcssblk_find_lowest_addr(dev_info
);
594 dev_info
->end
= dcssblk_find_highest_addr(dev_info
);
596 dev_set_name(&dev_info
->dev
, dev_info
->segment_name
);
597 dev_info
->dev
.release
= dcssblk_release_segment
;
598 dev_info
->dev
.groups
= dcssblk_dev_attr_groups
;
599 INIT_LIST_HEAD(&dev_info
->lh
);
600 dev_info
->gd
= alloc_disk(DCSSBLK_MINORS_PER_DISK
);
601 if (dev_info
->gd
== NULL
) {
605 dev_info
->gd
->major
= dcssblk_major
;
606 dev_info
->gd
->fops
= &dcssblk_devops
;
607 dev_info
->dcssblk_queue
= blk_alloc_queue(GFP_KERNEL
);
608 dev_info
->gd
->queue
= dev_info
->dcssblk_queue
;
609 dev_info
->gd
->private_data
= dev_info
;
610 dev_info
->gd
->driverfs_dev
= &dev_info
->dev
;
611 blk_queue_make_request(dev_info
->dcssblk_queue
, dcssblk_make_request
);
612 blk_queue_logical_block_size(dev_info
->dcssblk_queue
, 4096);
614 seg_byte_size
= (dev_info
->end
- dev_info
->start
+ 1);
615 set_capacity(dev_info
->gd
, seg_byte_size
>> 9); // size in sectors
616 pr_info("Loaded %s with total size %lu bytes and capacity %lu "
617 "sectors\n", local_buf
, seg_byte_size
, seg_byte_size
>> 9);
619 dev_info
->save_pending
= 0;
620 dev_info
->is_shared
= 1;
621 dev_info
->dev
.parent
= dcssblk_root_dev
;
624 *get minor, add to list
626 down_write(&dcssblk_devices_sem
);
627 if (dcssblk_get_segment_by_name(local_buf
)) {
631 rc
= dcssblk_assign_free_minor(dev_info
);
634 sprintf(dev_info
->gd
->disk_name
, "dcssblk%d",
635 dev_info
->gd
->first_minor
);
636 list_add_tail(&dev_info
->lh
, &dcssblk_devices
);
638 if (!try_module_get(THIS_MODULE
)) {
643 * register the device
645 rc
= device_register(&dev_info
->dev
);
649 get_device(&dev_info
->dev
);
650 add_disk(dev_info
->gd
);
652 switch (dev_info
->segment_type
) {
656 set_disk_ro(dev_info
->gd
,1);
659 set_disk_ro(dev_info
->gd
,0);
662 up_write(&dcssblk_devices_sem
);
667 list_del(&dev_info
->lh
);
668 blk_cleanup_queue(dev_info
->dcssblk_queue
);
669 dev_info
->gd
->queue
= NULL
;
670 put_disk(dev_info
->gd
);
671 list_for_each_entry(seg_info
, &dev_info
->seg_list
, lh
) {
672 segment_unload(seg_info
->segment_name
);
674 put_device(&dev_info
->dev
);
675 up_write(&dcssblk_devices_sem
);
678 list_del(&dev_info
->lh
);
680 blk_cleanup_queue(dev_info
->dcssblk_queue
);
681 dev_info
->gd
->queue
= NULL
;
682 put_disk(dev_info
->gd
);
683 up_write(&dcssblk_devices_sem
);
685 if (dev_info
== NULL
)
687 list_for_each_entry_safe(seg_info
, temp
, &dev_info
->seg_list
, lh
) {
688 list_del(&seg_info
->lh
);
689 segment_unload(seg_info
->segment_name
);
700 * device attribute for removing devices
703 dcssblk_remove_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
705 struct dcssblk_dev_info
*dev_info
;
706 struct segment_info
*entry
;
710 if (dev
!= dcssblk_root_dev
) {
713 local_buf
= kmalloc(count
+ 1, GFP_KERNEL
);
714 if (local_buf
== NULL
) {
720 for (i
= 0; ((*(buf
+i
)!='\0') && (*(buf
+i
)!='\n') && i
< count
); i
++) {
721 local_buf
[i
] = toupper(buf
[i
]);
724 if ((i
== 0) || (i
> 8)) {
729 down_write(&dcssblk_devices_sem
);
730 dev_info
= dcssblk_get_device_by_name(local_buf
);
731 if (dev_info
== NULL
) {
732 up_write(&dcssblk_devices_sem
);
733 pr_warning("Device %s cannot be removed because it is not a "
734 "known device\n", local_buf
);
738 if (atomic_read(&dev_info
->use_count
) != 0) {
739 up_write(&dcssblk_devices_sem
);
740 pr_warning("Device %s cannot be removed while it is in "
746 list_del(&dev_info
->lh
);
747 del_gendisk(dev_info
->gd
);
748 blk_cleanup_queue(dev_info
->dcssblk_queue
);
749 dev_info
->gd
->queue
= NULL
;
750 put_disk(dev_info
->gd
);
751 device_unregister(&dev_info
->dev
);
753 /* unload all related segments */
754 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
)
755 segment_unload(entry
->segment_name
);
757 put_device(&dev_info
->dev
);
758 up_write(&dcssblk_devices_sem
);
767 dcssblk_open(struct block_device
*bdev
, fmode_t mode
)
769 struct dcssblk_dev_info
*dev_info
;
772 dev_info
= bdev
->bd_disk
->private_data
;
773 if (NULL
== dev_info
) {
777 atomic_inc(&dev_info
->use_count
);
778 bdev
->bd_block_size
= 4096;
785 dcssblk_release(struct gendisk
*disk
, fmode_t mode
)
787 struct dcssblk_dev_info
*dev_info
= disk
->private_data
;
788 struct segment_info
*entry
;
794 down_write(&dcssblk_devices_sem
);
795 if (atomic_dec_and_test(&dev_info
->use_count
)
796 && (dev_info
->save_pending
)) {
797 pr_info("Device %s has become idle and is being saved "
798 "now\n", dev_info
->segment_name
);
799 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
800 segment_save(entry
->segment_name
);
802 dev_info
->save_pending
= 0;
804 up_write(&dcssblk_devices_sem
);
808 dcssblk_make_request(struct request_queue
*q
, struct bio
*bio
)
810 struct dcssblk_dev_info
*dev_info
;
812 struct bvec_iter iter
;
814 unsigned long page_addr
;
815 unsigned long source_addr
;
816 unsigned long bytes_done
;
819 dev_info
= bio
->bi_bdev
->bd_disk
->private_data
;
820 if (dev_info
== NULL
)
822 if ((bio
->bi_iter
.bi_sector
& 7) != 0 ||
823 (bio
->bi_iter
.bi_size
& 4095) != 0)
824 /* Request is not page-aligned. */
826 if (bio_end_sector(bio
) > get_capacity(bio
->bi_bdev
->bd_disk
)) {
827 /* Request beyond end of DCSS segment. */
830 /* verify data transfer direction */
831 if (dev_info
->is_shared
) {
832 switch (dev_info
->segment_type
) {
836 /* cannot write to these segments */
837 if (bio_data_dir(bio
) == WRITE
) {
838 pr_warning("Writing to %s failed because it "
839 "is a read-only device\n",
840 dev_name(&dev_info
->dev
));
846 index
= (bio
->bi_iter
.bi_sector
>> 3);
847 bio_for_each_segment(bvec
, bio
, iter
) {
848 page_addr
= (unsigned long)
849 page_address(bvec
.bv_page
) + bvec
.bv_offset
;
850 source_addr
= dev_info
->start
+ (index
<<12) + bytes_done
;
851 if (unlikely((page_addr
& 4095) != 0) || (bvec
.bv_len
& 4095) != 0)
854 if (bio_data_dir(bio
) == READ
) {
855 memcpy((void*)page_addr
, (void*)source_addr
,
858 memcpy((void*)source_addr
, (void*)page_addr
,
861 bytes_done
+= bvec
.bv_len
;
870 dcssblk_direct_access (struct block_device
*bdev
, sector_t secnum
,
871 void **kaddr
, unsigned long *pfn
)
873 struct dcssblk_dev_info
*dev_info
;
876 dev_info
= bdev
->bd_disk
->private_data
;
879 if (secnum
% (PAGE_SIZE
/512))
881 pgoff
= secnum
/ (PAGE_SIZE
/ 512);
882 if ((pgoff
+1)*PAGE_SIZE
-1 > dev_info
->end
- dev_info
->start
)
884 *kaddr
= (void *) (dev_info
->start
+pgoff
*PAGE_SIZE
);
885 *pfn
= virt_to_phys(*kaddr
) >> PAGE_SHIFT
;
891 dcssblk_check_params(void)
894 char buf
[DCSSBLK_PARM_LEN
+ 1];
895 struct dcssblk_dev_info
*dev_info
;
897 for (i
= 0; (i
< DCSSBLK_PARM_LEN
) && (dcssblk_segments
[i
] != '\0');
899 for (j
= i
; (dcssblk_segments
[j
] != ',') &&
900 (dcssblk_segments
[j
] != '\0') &&
901 (dcssblk_segments
[j
] != '(') &&
902 (j
< DCSSBLK_PARM_LEN
); j
++)
904 buf
[j
-i
] = dcssblk_segments
[j
];
907 rc
= dcssblk_add_store(dcssblk_root_dev
, NULL
, buf
, j
-i
);
908 if ((rc
>= 0) && (dcssblk_segments
[j
] == '(')) {
909 for (k
= 0; (buf
[k
] != ':') && (buf
[k
] != '\0'); k
++)
910 buf
[k
] = toupper(buf
[k
]);
912 if (!strncmp(&dcssblk_segments
[j
], "(local)", 7)) {
913 down_read(&dcssblk_devices_sem
);
914 dev_info
= dcssblk_get_device_by_name(buf
);
915 up_read(&dcssblk_devices_sem
);
917 dcssblk_shared_store(&dev_info
->dev
,
921 while ((dcssblk_segments
[j
] != ',') &&
922 (dcssblk_segments
[j
] != '\0'))
926 if (dcssblk_segments
[j
] == '\0')
935 static int dcssblk_freeze(struct device
*dev
)
937 struct dcssblk_dev_info
*dev_info
;
940 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
941 switch (dev_info
->segment_type
) {
945 if (!dev_info
->is_shared
)
956 pr_err("Suspending the system failed because DCSS device %s "
958 dev_info
->segment_name
);
962 static int dcssblk_restore(struct device
*dev
)
964 struct dcssblk_dev_info
*dev_info
;
965 struct segment_info
*entry
;
966 unsigned long start
, end
;
969 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
970 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
971 segment_unload(entry
->segment_name
);
972 rc
= segment_load(entry
->segment_name
, SEGMENT_SHARED
,
975 // TODO in_use check ?
976 segment_warning(rc
, entry
->segment_name
);
979 if (start
!= entry
->start
|| end
!= entry
->end
) {
980 pr_err("The address range of DCSS %s changed "
981 "while the system was suspended\n",
982 entry
->segment_name
);
989 panic("fatal dcssblk resume error\n");
992 static int dcssblk_thaw(struct device
*dev
)
997 static const struct dev_pm_ops dcssblk_pm_ops
= {
998 .freeze
= dcssblk_freeze
,
999 .thaw
= dcssblk_thaw
,
1000 .restore
= dcssblk_restore
,
1003 static struct platform_driver dcssblk_pdrv
= {
1006 .owner
= THIS_MODULE
,
1007 .pm
= &dcssblk_pm_ops
,
1011 static struct platform_device
*dcssblk_pdev
;
1015 * The init/exit functions.
1020 platform_device_unregister(dcssblk_pdev
);
1021 platform_driver_unregister(&dcssblk_pdrv
);
1022 root_device_unregister(dcssblk_root_dev
);
1023 unregister_blkdev(dcssblk_major
, DCSSBLK_NAME
);
1031 rc
= platform_driver_register(&dcssblk_pdrv
);
1035 dcssblk_pdev
= platform_device_register_simple("dcssblk", -1, NULL
,
1037 if (IS_ERR(dcssblk_pdev
)) {
1038 rc
= PTR_ERR(dcssblk_pdev
);
1042 dcssblk_root_dev
= root_device_register("dcssblk");
1043 if (IS_ERR(dcssblk_root_dev
)) {
1044 rc
= PTR_ERR(dcssblk_root_dev
);
1047 rc
= device_create_file(dcssblk_root_dev
, &dev_attr_add
);
1050 rc
= device_create_file(dcssblk_root_dev
, &dev_attr_remove
);
1053 rc
= register_blkdev(0, DCSSBLK_NAME
);
1057 init_rwsem(&dcssblk_devices_sem
);
1059 dcssblk_check_params();
1063 root_device_unregister(dcssblk_root_dev
);
1065 platform_device_unregister(dcssblk_pdev
);
1067 platform_driver_unregister(&dcssblk_pdrv
);
1071 module_init(dcssblk_init
);
1072 module_exit(dcssblk_exit
);
1074 module_param_string(segments
, dcssblk_segments
, DCSSBLK_PARM_LEN
, 0444);
1075 MODULE_PARM_DESC(segments
, "Name of DCSS segment(s) to be loaded, "
1076 "comma-separated list, names in each set separated "
1077 "by commas are separated by colons, each set contains "
1078 "names of contiguous segments and each name max. 8 chars.\n"
1079 "Adding \"(local)\" to the end of each set equals echoing 0 "
1080 "to /sys/devices/dcssblk/<device name>/shared after loading "
1081 "the contiguous segments - \n"
1082 "e.g. segments=\"mydcss1,mydcss2:mydcss3,mydcss4(local)\"");
1084 MODULE_LICENSE("GPL");