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 int dcssblk_release(struct gendisk
*disk
, fmode_t mode
);
30 static int 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
,
72 static ssize_t
dcssblk_save_store(struct device
* dev
, struct device_attribute
*attr
, const char * buf
,
74 static ssize_t
dcssblk_save_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
75 static ssize_t
dcssblk_shared_store(struct device
* dev
, struct device_attribute
*attr
, const char * buf
,
77 static ssize_t
dcssblk_shared_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
78 static ssize_t
dcssblk_seglist_show(struct device
*dev
,
79 struct device_attribute
*attr
,
82 static DEVICE_ATTR(add
, S_IWUSR
, NULL
, dcssblk_add_store
);
83 static DEVICE_ATTR(remove
, S_IWUSR
, NULL
, dcssblk_remove_store
);
84 static DEVICE_ATTR(save
, S_IWUSR
| S_IRUSR
, dcssblk_save_show
,
86 static DEVICE_ATTR(shared
, S_IWUSR
| S_IRUSR
, dcssblk_shared_show
,
87 dcssblk_shared_store
);
88 static DEVICE_ATTR(seglist
, S_IRUSR
, dcssblk_seglist_show
, NULL
);
90 static struct device
*dcssblk_root_dev
;
92 static LIST_HEAD(dcssblk_devices
);
93 static struct rw_semaphore dcssblk_devices_sem
;
96 * release function for segment device.
99 dcssblk_release_segment(struct device
*dev
)
101 struct dcssblk_dev_info
*dev_info
;
102 struct segment_info
*entry
, *temp
;
104 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
105 list_for_each_entry_safe(entry
, temp
, &dev_info
->seg_list
, lh
) {
106 list_del(&entry
->lh
);
110 module_put(THIS_MODULE
);
114 * get a minor number. needs to be called with
115 * down_write(&dcssblk_devices_sem) and the
116 * device needs to be enqueued before the semaphore is
120 dcssblk_assign_free_minor(struct dcssblk_dev_info
*dev_info
)
123 struct dcssblk_dev_info
*entry
;
125 if (dev_info
== NULL
)
127 for (minor
= 0; minor
< (1<<MINORBITS
); minor
++) {
129 // test if minor available
130 list_for_each_entry(entry
, &dcssblk_devices
, lh
)
131 if (minor
== entry
->gd
->first_minor
)
133 if (!found
) break; // got unused minor
137 dev_info
->gd
->first_minor
= minor
;
142 * get the struct dcssblk_dev_info from dcssblk_devices
143 * for the given name.
144 * down_read(&dcssblk_devices_sem) must be held.
146 static struct dcssblk_dev_info
*
147 dcssblk_get_device_by_name(char *name
)
149 struct dcssblk_dev_info
*entry
;
151 list_for_each_entry(entry
, &dcssblk_devices
, lh
) {
152 if (!strcmp(name
, entry
->segment_name
)) {
160 * get the struct segment_info from seg_list
161 * for the given name.
162 * down_read(&dcssblk_devices_sem) must be held.
164 static struct segment_info
*
165 dcssblk_get_segment_by_name(char *name
)
167 struct dcssblk_dev_info
*dev_info
;
168 struct segment_info
*entry
;
170 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
171 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
172 if (!strcmp(name
, entry
->segment_name
))
180 * get the highest address of the multi-segment block.
183 dcssblk_find_highest_addr(struct dcssblk_dev_info
*dev_info
)
185 unsigned long highest_addr
;
186 struct segment_info
*entry
;
189 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
190 if (highest_addr
< entry
->end
)
191 highest_addr
= entry
->end
;
197 * get the lowest address of the multi-segment block.
200 dcssblk_find_lowest_addr(struct dcssblk_dev_info
*dev_info
)
203 unsigned long lowest_addr
;
204 struct segment_info
*entry
;
208 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
209 if (set_first
== 0) {
210 lowest_addr
= entry
->start
;
213 if (lowest_addr
> entry
->start
)
214 lowest_addr
= entry
->start
;
221 * Check continuity of segments.
224 dcssblk_is_continuous(struct dcssblk_dev_info
*dev_info
)
227 struct segment_info
*sort_list
, *entry
, temp
;
229 if (dev_info
->num_of_segments
<= 1)
233 sizeof(struct segment_info
) * dev_info
->num_of_segments
,
235 if (sort_list
== NULL
)
238 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
239 memcpy(&sort_list
[i
], entry
, sizeof(struct segment_info
));
244 for (i
= 0; i
< dev_info
->num_of_segments
; i
++)
245 for (j
= 0; j
< dev_info
->num_of_segments
; j
++)
246 if (sort_list
[j
].start
> sort_list
[i
].start
) {
247 memcpy(&temp
, &sort_list
[i
],
248 sizeof(struct segment_info
));
249 memcpy(&sort_list
[i
], &sort_list
[j
],
250 sizeof(struct segment_info
));
251 memcpy(&sort_list
[j
], &temp
,
252 sizeof(struct segment_info
));
255 /* check continuity */
256 for (i
= 0; i
< dev_info
->num_of_segments
- 1; i
++) {
257 if ((sort_list
[i
].end
+ 1) != sort_list
[i
+1].start
) {
258 pr_err("Adjacent DCSSs %s and %s are not "
259 "contiguous\n", sort_list
[i
].segment_name
,
260 sort_list
[i
+1].segment_name
);
264 /* EN and EW are allowed in a block device */
265 if (sort_list
[i
].segment_type
!= sort_list
[i
+1].segment_type
) {
266 if (!(sort_list
[i
].segment_type
& SEGMENT_EXCLUSIVE
) ||
267 (sort_list
[i
].segment_type
== SEG_TYPE_ER
) ||
268 !(sort_list
[i
+1].segment_type
&
269 SEGMENT_EXCLUSIVE
) ||
270 (sort_list
[i
+1].segment_type
== SEG_TYPE_ER
)) {
271 pr_err("DCSS %s and DCSS %s have "
272 "incompatible types\n",
273 sort_list
[i
].segment_name
,
274 sort_list
[i
+1].segment_name
);
290 dcssblk_load_segment(char *name
, struct segment_info
**seg_info
)
294 /* already loaded? */
295 down_read(&dcssblk_devices_sem
);
296 *seg_info
= dcssblk_get_segment_by_name(name
);
297 up_read(&dcssblk_devices_sem
);
298 if (*seg_info
!= NULL
)
301 /* get a struct segment_info */
302 *seg_info
= kzalloc(sizeof(struct segment_info
), GFP_KERNEL
);
303 if (*seg_info
== NULL
)
306 strcpy((*seg_info
)->segment_name
, name
);
308 /* load the segment */
309 rc
= segment_load(name
, SEGMENT_SHARED
,
310 &(*seg_info
)->start
, &(*seg_info
)->end
);
312 segment_warning(rc
, (*seg_info
)->segment_name
);
315 INIT_LIST_HEAD(&(*seg_info
)->lh
);
316 (*seg_info
)->segment_type
= rc
;
321 static void dcssblk_unregister_callback(struct device
*dev
)
323 device_unregister(dev
);
328 * device attribute for switching shared/nonshared (exclusive)
329 * operation (show + store)
332 dcssblk_shared_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
334 struct dcssblk_dev_info
*dev_info
;
336 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
337 return sprintf(buf
, dev_info
->is_shared
? "1\n" : "0\n");
341 dcssblk_shared_store(struct device
*dev
, struct device_attribute
*attr
, const char *inbuf
, size_t count
)
343 struct dcssblk_dev_info
*dev_info
;
344 struct segment_info
*entry
, *temp
;
347 if ((count
> 1) && (inbuf
[1] != '\n') && (inbuf
[1] != '\0'))
349 down_write(&dcssblk_devices_sem
);
350 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
351 if (atomic_read(&dev_info
->use_count
)) {
355 if (inbuf
[0] == '1') {
356 /* reload segments in shared mode */
357 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
358 rc
= segment_modify_shared(entry
->segment_name
,
361 BUG_ON(rc
== -EINVAL
);
366 dev_info
->is_shared
= 1;
367 switch (dev_info
->segment_type
) {
371 set_disk_ro(dev_info
->gd
, 1);
373 } else if (inbuf
[0] == '0') {
374 /* reload segments in exclusive mode */
375 if (dev_info
->segment_type
== SEG_TYPE_SC
) {
376 pr_err("DCSS %s is of type SC and cannot be "
377 "loaded as exclusive-writable\n",
378 dev_info
->segment_name
);
382 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
383 rc
= segment_modify_shared(entry
->segment_name
,
386 BUG_ON(rc
== -EINVAL
);
391 dev_info
->is_shared
= 0;
392 set_disk_ro(dev_info
->gd
, 0);
401 pr_err("DCSS device %s is removed after a failed access mode "
402 "change\n", dev_info
->segment_name
);
404 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
406 segment_unload(entry
->segment_name
);
408 list_del(&dev_info
->lh
);
410 del_gendisk(dev_info
->gd
);
411 blk_cleanup_queue(dev_info
->dcssblk_queue
);
412 dev_info
->gd
->queue
= NULL
;
413 put_disk(dev_info
->gd
);
414 rc
= device_schedule_callback(dev
, dcssblk_unregister_callback
);
416 up_write(&dcssblk_devices_sem
);
421 * device attribute for save operation on current copy
422 * of the segment. If the segment is busy, saving will
423 * become pending until it gets released, which can be
424 * undone by storing a non-true value to this entry.
428 dcssblk_save_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
430 struct dcssblk_dev_info
*dev_info
;
432 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
433 return sprintf(buf
, dev_info
->save_pending
? "1\n" : "0\n");
437 dcssblk_save_store(struct device
*dev
, struct device_attribute
*attr
, const char *inbuf
, size_t count
)
439 struct dcssblk_dev_info
*dev_info
;
440 struct segment_info
*entry
;
442 if ((count
> 1) && (inbuf
[1] != '\n') && (inbuf
[1] != '\0'))
444 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
446 down_write(&dcssblk_devices_sem
);
447 if (inbuf
[0] == '1') {
448 if (atomic_read(&dev_info
->use_count
) == 0) {
449 // device is idle => we save immediately
450 pr_info("All DCSSs that map to device %s are "
451 "saved\n", dev_info
->segment_name
);
452 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
453 segment_save(entry
->segment_name
);
456 // device is busy => we save it when it becomes
457 // idle in dcssblk_release
458 pr_info("Device %s is in use, its DCSSs will be "
459 "saved when it becomes idle\n",
460 dev_info
->segment_name
);
461 dev_info
->save_pending
= 1;
463 } else if (inbuf
[0] == '0') {
464 if (dev_info
->save_pending
) {
465 // device is busy & the user wants to undo his save
467 dev_info
->save_pending
= 0;
468 pr_info("A pending save request for device %s "
469 "has been canceled\n",
470 dev_info
->segment_name
);
473 up_write(&dcssblk_devices_sem
);
476 up_write(&dcssblk_devices_sem
);
481 * device attribute for showing all segments in a device
484 dcssblk_seglist_show(struct device
*dev
, struct device_attribute
*attr
,
489 struct dcssblk_dev_info
*dev_info
;
490 struct segment_info
*entry
;
492 down_read(&dcssblk_devices_sem
);
493 dev_info
= container_of(dev
, struct dcssblk_dev_info
, dev
);
496 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
497 strcpy(&buf
[i
], entry
->segment_name
);
498 i
+= strlen(entry
->segment_name
);
502 up_read(&dcssblk_devices_sem
);
507 * device attribute for adding devices
510 dcssblk_add_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
512 int rc
, i
, j
, num_of_segments
;
513 struct dcssblk_dev_info
*dev_info
;
514 struct segment_info
*seg_info
, *temp
;
516 unsigned long seg_byte_size
;
520 if (dev
!= dcssblk_root_dev
) {
524 if ((count
< 1) || (buf
[0] == '\0') || (buf
[0] == '\n')) {
529 local_buf
= kmalloc(count
+ 1, GFP_KERNEL
);
530 if (local_buf
== NULL
) {
539 for (i
= 0; ((buf
[i
] != '\0') && (buf
[i
] != '\n') && i
< count
); i
++) {
540 for (j
= i
; (buf
[j
] != ':') &&
544 local_buf
[j
-i
] = toupper(buf
[j
]);
546 local_buf
[j
-i
] = '\0';
547 if (((j
- i
) == 0) || ((j
- i
) > 8)) {
552 rc
= dcssblk_load_segment(local_buf
, &seg_info
);
556 * get a struct dcssblk_dev_info
558 if (num_of_segments
== 0) {
559 dev_info
= kzalloc(sizeof(struct dcssblk_dev_info
),
561 if (dev_info
== NULL
) {
565 strcpy(dev_info
->segment_name
, local_buf
);
566 dev_info
->segment_type
= seg_info
->segment_type
;
567 INIT_LIST_HEAD(&dev_info
->seg_list
);
569 list_add_tail(&seg_info
->lh
, &dev_info
->seg_list
);
573 if ((buf
[j
] == '\0') || (buf
[j
] == '\n'))
577 /* no trailing colon at the end of the input */
578 if ((i
> 0) && (buf
[i
-1] == ':')) {
582 strlcpy(local_buf
, buf
, i
+ 1);
583 dev_info
->num_of_segments
= num_of_segments
;
584 rc
= dcssblk_is_continuous(dev_info
);
588 dev_info
->start
= dcssblk_find_lowest_addr(dev_info
);
589 dev_info
->end
= dcssblk_find_highest_addr(dev_info
);
591 dev_set_name(&dev_info
->dev
, dev_info
->segment_name
);
592 dev_info
->dev
.release
= dcssblk_release_segment
;
593 INIT_LIST_HEAD(&dev_info
->lh
);
594 dev_info
->gd
= alloc_disk(DCSSBLK_MINORS_PER_DISK
);
595 if (dev_info
->gd
== NULL
) {
599 dev_info
->gd
->major
= dcssblk_major
;
600 dev_info
->gd
->fops
= &dcssblk_devops
;
601 dev_info
->dcssblk_queue
= blk_alloc_queue(GFP_KERNEL
);
602 dev_info
->gd
->queue
= dev_info
->dcssblk_queue
;
603 dev_info
->gd
->private_data
= dev_info
;
604 dev_info
->gd
->driverfs_dev
= &dev_info
->dev
;
605 blk_queue_make_request(dev_info
->dcssblk_queue
, dcssblk_make_request
);
606 blk_queue_logical_block_size(dev_info
->dcssblk_queue
, 4096);
608 seg_byte_size
= (dev_info
->end
- dev_info
->start
+ 1);
609 set_capacity(dev_info
->gd
, seg_byte_size
>> 9); // size in sectors
610 pr_info("Loaded %s with total size %lu bytes and capacity %lu "
611 "sectors\n", local_buf
, seg_byte_size
, seg_byte_size
>> 9);
613 dev_info
->save_pending
= 0;
614 dev_info
->is_shared
= 1;
615 dev_info
->dev
.parent
= dcssblk_root_dev
;
618 *get minor, add to list
620 down_write(&dcssblk_devices_sem
);
621 if (dcssblk_get_segment_by_name(local_buf
)) {
625 rc
= dcssblk_assign_free_minor(dev_info
);
628 sprintf(dev_info
->gd
->disk_name
, "dcssblk%d",
629 dev_info
->gd
->first_minor
);
630 list_add_tail(&dev_info
->lh
, &dcssblk_devices
);
632 if (!try_module_get(THIS_MODULE
)) {
637 * register the device
639 rc
= device_register(&dev_info
->dev
);
641 module_put(THIS_MODULE
);
644 get_device(&dev_info
->dev
);
645 rc
= device_create_file(&dev_info
->dev
, &dev_attr_shared
);
648 rc
= device_create_file(&dev_info
->dev
, &dev_attr_save
);
651 rc
= device_create_file(&dev_info
->dev
, &dev_attr_seglist
);
655 add_disk(dev_info
->gd
);
657 switch (dev_info
->segment_type
) {
661 set_disk_ro(dev_info
->gd
,1);
664 set_disk_ro(dev_info
->gd
,0);
667 up_write(&dcssblk_devices_sem
);
672 list_del(&dev_info
->lh
);
673 blk_cleanup_queue(dev_info
->dcssblk_queue
);
674 dev_info
->gd
->queue
= NULL
;
675 put_disk(dev_info
->gd
);
676 device_unregister(&dev_info
->dev
);
677 list_for_each_entry(seg_info
, &dev_info
->seg_list
, lh
) {
678 segment_unload(seg_info
->segment_name
);
680 put_device(&dev_info
->dev
);
681 up_write(&dcssblk_devices_sem
);
684 list_del(&dev_info
->lh
);
686 blk_cleanup_queue(dev_info
->dcssblk_queue
);
687 dev_info
->gd
->queue
= NULL
;
688 put_disk(dev_info
->gd
);
689 up_write(&dcssblk_devices_sem
);
691 if (dev_info
== NULL
)
693 list_for_each_entry_safe(seg_info
, temp
, &dev_info
->seg_list
, lh
) {
694 list_del(&seg_info
->lh
);
695 segment_unload(seg_info
->segment_name
);
706 * device attribute for removing devices
709 dcssblk_remove_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
711 struct dcssblk_dev_info
*dev_info
;
712 struct segment_info
*entry
;
716 if (dev
!= dcssblk_root_dev
) {
719 local_buf
= kmalloc(count
+ 1, GFP_KERNEL
);
720 if (local_buf
== NULL
) {
726 for (i
= 0; ((*(buf
+i
)!='\0') && (*(buf
+i
)!='\n') && i
< count
); i
++) {
727 local_buf
[i
] = toupper(buf
[i
]);
730 if ((i
== 0) || (i
> 8)) {
735 down_write(&dcssblk_devices_sem
);
736 dev_info
= dcssblk_get_device_by_name(local_buf
);
737 if (dev_info
== NULL
) {
738 up_write(&dcssblk_devices_sem
);
739 pr_warning("Device %s cannot be removed because it is not a "
740 "known device\n", local_buf
);
744 if (atomic_read(&dev_info
->use_count
) != 0) {
745 up_write(&dcssblk_devices_sem
);
746 pr_warning("Device %s cannot be removed while it is in "
752 list_del(&dev_info
->lh
);
753 del_gendisk(dev_info
->gd
);
754 blk_cleanup_queue(dev_info
->dcssblk_queue
);
755 dev_info
->gd
->queue
= NULL
;
756 put_disk(dev_info
->gd
);
757 device_unregister(&dev_info
->dev
);
759 /* unload all related segments */
760 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
)
761 segment_unload(entry
->segment_name
);
763 put_device(&dev_info
->dev
);
764 up_write(&dcssblk_devices_sem
);
773 dcssblk_open(struct block_device
*bdev
, fmode_t mode
)
775 struct dcssblk_dev_info
*dev_info
;
778 dev_info
= bdev
->bd_disk
->private_data
;
779 if (NULL
== dev_info
) {
783 atomic_inc(&dev_info
->use_count
);
784 bdev
->bd_block_size
= 4096;
791 dcssblk_release(struct gendisk
*disk
, fmode_t mode
)
793 struct dcssblk_dev_info
*dev_info
= disk
->private_data
;
794 struct segment_info
*entry
;
801 down_write(&dcssblk_devices_sem
);
802 if (atomic_dec_and_test(&dev_info
->use_count
)
803 && (dev_info
->save_pending
)) {
804 pr_info("Device %s has become idle and is being saved "
805 "now\n", dev_info
->segment_name
);
806 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
807 segment_save(entry
->segment_name
);
809 dev_info
->save_pending
= 0;
811 up_write(&dcssblk_devices_sem
);
818 dcssblk_make_request(struct request_queue
*q
, struct bio
*bio
)
820 struct dcssblk_dev_info
*dev_info
;
821 struct bio_vec
*bvec
;
823 unsigned long page_addr
;
824 unsigned long source_addr
;
825 unsigned long bytes_done
;
829 dev_info
= bio
->bi_bdev
->bd_disk
->private_data
;
830 if (dev_info
== NULL
)
832 if ((bio
->bi_sector
& 7) != 0 || (bio
->bi_size
& 4095) != 0)
833 /* Request is not page-aligned. */
835 if (((bio
->bi_size
>> 9) + bio
->bi_sector
)
836 > get_capacity(bio
->bi_bdev
->bd_disk
)) {
837 /* Request beyond end of DCSS segment. */
840 /* verify data transfer direction */
841 if (dev_info
->is_shared
) {
842 switch (dev_info
->segment_type
) {
846 /* cannot write to these segments */
847 if (bio_data_dir(bio
) == WRITE
) {
848 pr_warning("Writing to %s failed because it "
849 "is a read-only device\n",
850 dev_name(&dev_info
->dev
));
856 index
= (bio
->bi_sector
>> 3);
857 bio_for_each_segment(bvec
, bio
, i
) {
858 page_addr
= (unsigned long)
859 page_address(bvec
->bv_page
) + bvec
->bv_offset
;
860 source_addr
= dev_info
->start
+ (index
<<12) + bytes_done
;
861 if (unlikely((page_addr
& 4095) != 0) || (bvec
->bv_len
& 4095) != 0)
864 if (bio_data_dir(bio
) == READ
) {
865 memcpy((void*)page_addr
, (void*)source_addr
,
868 memcpy((void*)source_addr
, (void*)page_addr
,
871 bytes_done
+= bvec
->bv_len
;
881 dcssblk_direct_access (struct block_device
*bdev
, sector_t secnum
,
882 void **kaddr
, unsigned long *pfn
)
884 struct dcssblk_dev_info
*dev_info
;
887 dev_info
= bdev
->bd_disk
->private_data
;
890 if (secnum
% (PAGE_SIZE
/512))
892 pgoff
= secnum
/ (PAGE_SIZE
/ 512);
893 if ((pgoff
+1)*PAGE_SIZE
-1 > dev_info
->end
- dev_info
->start
)
895 *kaddr
= (void *) (dev_info
->start
+pgoff
*PAGE_SIZE
);
896 *pfn
= virt_to_phys(*kaddr
) >> PAGE_SHIFT
;
902 dcssblk_check_params(void)
905 char buf
[DCSSBLK_PARM_LEN
+ 1];
906 struct dcssblk_dev_info
*dev_info
;
908 for (i
= 0; (i
< DCSSBLK_PARM_LEN
) && (dcssblk_segments
[i
] != '\0');
910 for (j
= i
; (dcssblk_segments
[j
] != ',') &&
911 (dcssblk_segments
[j
] != '\0') &&
912 (dcssblk_segments
[j
] != '(') &&
913 (j
< DCSSBLK_PARM_LEN
); j
++)
915 buf
[j
-i
] = dcssblk_segments
[j
];
918 rc
= dcssblk_add_store(dcssblk_root_dev
, NULL
, buf
, j
-i
);
919 if ((rc
>= 0) && (dcssblk_segments
[j
] == '(')) {
920 for (k
= 0; (buf
[k
] != ':') && (buf
[k
] != '\0'); k
++)
921 buf
[k
] = toupper(buf
[k
]);
923 if (!strncmp(&dcssblk_segments
[j
], "(local)", 7)) {
924 down_read(&dcssblk_devices_sem
);
925 dev_info
= dcssblk_get_device_by_name(buf
);
926 up_read(&dcssblk_devices_sem
);
928 dcssblk_shared_store(&dev_info
->dev
,
932 while ((dcssblk_segments
[j
] != ',') &&
933 (dcssblk_segments
[j
] != '\0'))
937 if (dcssblk_segments
[j
] == '\0')
946 static int dcssblk_freeze(struct device
*dev
)
948 struct dcssblk_dev_info
*dev_info
;
951 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
952 switch (dev_info
->segment_type
) {
956 if (!dev_info
->is_shared
)
967 pr_err("Suspending the system failed because DCSS device %s "
969 dev_info
->segment_name
);
973 static int dcssblk_restore(struct device
*dev
)
975 struct dcssblk_dev_info
*dev_info
;
976 struct segment_info
*entry
;
977 unsigned long start
, end
;
980 list_for_each_entry(dev_info
, &dcssblk_devices
, lh
) {
981 list_for_each_entry(entry
, &dev_info
->seg_list
, lh
) {
982 segment_unload(entry
->segment_name
);
983 rc
= segment_load(entry
->segment_name
, SEGMENT_SHARED
,
986 // TODO in_use check ?
987 segment_warning(rc
, entry
->segment_name
);
990 if (start
!= entry
->start
|| end
!= entry
->end
) {
991 pr_err("The address range of DCSS %s changed "
992 "while the system was suspended\n",
993 entry
->segment_name
);
1000 panic("fatal dcssblk resume error\n");
1003 static int dcssblk_thaw(struct device
*dev
)
1008 static const struct dev_pm_ops dcssblk_pm_ops
= {
1009 .freeze
= dcssblk_freeze
,
1010 .thaw
= dcssblk_thaw
,
1011 .restore
= dcssblk_restore
,
1014 static struct platform_driver dcssblk_pdrv
= {
1017 .owner
= THIS_MODULE
,
1018 .pm
= &dcssblk_pm_ops
,
1022 static struct platform_device
*dcssblk_pdev
;
1026 * The init/exit functions.
1031 platform_device_unregister(dcssblk_pdev
);
1032 platform_driver_unregister(&dcssblk_pdrv
);
1033 root_device_unregister(dcssblk_root_dev
);
1034 unregister_blkdev(dcssblk_major
, DCSSBLK_NAME
);
1042 rc
= platform_driver_register(&dcssblk_pdrv
);
1046 dcssblk_pdev
= platform_device_register_simple("dcssblk", -1, NULL
,
1048 if (IS_ERR(dcssblk_pdev
)) {
1049 rc
= PTR_ERR(dcssblk_pdev
);
1053 dcssblk_root_dev
= root_device_register("dcssblk");
1054 if (IS_ERR(dcssblk_root_dev
)) {
1055 rc
= PTR_ERR(dcssblk_root_dev
);
1058 rc
= device_create_file(dcssblk_root_dev
, &dev_attr_add
);
1061 rc
= device_create_file(dcssblk_root_dev
, &dev_attr_remove
);
1064 rc
= register_blkdev(0, DCSSBLK_NAME
);
1068 init_rwsem(&dcssblk_devices_sem
);
1070 dcssblk_check_params();
1074 root_device_unregister(dcssblk_root_dev
);
1076 platform_device_unregister(dcssblk_pdev
);
1078 platform_driver_unregister(&dcssblk_pdrv
);
1082 module_init(dcssblk_init
);
1083 module_exit(dcssblk_exit
);
1085 module_param_string(segments
, dcssblk_segments
, DCSSBLK_PARM_LEN
, 0444);
1086 MODULE_PARM_DESC(segments
, "Name of DCSS segment(s) to be loaded, "
1087 "comma-separated list, names in each set separated "
1088 "by commas are separated by colons, each set contains "
1089 "names of contiguous segments and each name max. 8 chars.\n"
1090 "Adding \"(local)\" to the end of each set equals echoing 0 "
1091 "to /sys/devices/dcssblk/<device name>/shared after loading "
1092 "the contiguous segments - \n"
1093 "e.g. segments=\"mydcss1,mydcss2:mydcss3,mydcss4(local)\"");
1095 MODULE_LICENSE("GPL");