12
12
13
13
#define pr_fmt (fmt ) "PM: " fmt
14
14
15
+ #include <crypto/acompress.h>
15
16
#include <linux/module.h>
16
17
#include <linux/file.h>
17
18
#include <linux/delay.h>
@@ -635,7 +636,8 @@ static int crc32_threadfn(void *data)
635
636
*/
636
637
struct cmp_data {
637
638
struct task_struct * thr ; /* thread */
638
- struct crypto_comp * cc ; /* crypto compressor stream */
639
+ struct crypto_acomp * cc ; /* crypto compressor */
640
+ struct acomp_req * cr ; /* crypto request */
639
641
atomic_t ready ; /* ready to start flag */
640
642
atomic_t stop ; /* ready to stop flag */
641
643
int ret ; /* return code */
@@ -656,7 +658,6 @@ static atomic_t compressed_size = ATOMIC_INIT(0);
656
658
static int compress_threadfn (void * data )
657
659
{
658
660
struct cmp_data * d = data ;
659
- unsigned int cmp_len = 0 ;
660
661
661
662
while (1 ) {
662
663
wait_event (d -> go , atomic_read_acquire (& d -> ready ) ||
@@ -670,11 +671,13 @@ static int compress_threadfn(void *data)
670
671
}
671
672
atomic_set (& d -> ready , 0 );
672
673
673
- cmp_len = CMP_SIZE - CMP_HEADER ;
674
- d -> ret = crypto_comp_compress (d -> cc , d -> unc , d -> unc_len ,
675
- d -> cmp + CMP_HEADER ,
676
- & cmp_len );
677
- d -> cmp_len = cmp_len ;
674
+ acomp_request_set_callback (d -> cr , CRYPTO_TFM_REQ_MAY_SLEEP ,
675
+ NULL , NULL );
676
+ acomp_request_set_src_nondma (d -> cr , d -> unc , d -> unc_len );
677
+ acomp_request_set_dst_nondma (d -> cr , d -> cmp + CMP_HEADER ,
678
+ CMP_SIZE - CMP_HEADER );
679
+ d -> ret = crypto_acomp_compress (d -> cr );
680
+ d -> cmp_len = d -> cr -> dlen ;
678
681
679
682
atomic_set (& compressed_size , atomic_read (& compressed_size ) + d -> cmp_len );
680
683
atomic_set_release (& d -> stop , 1 );
@@ -745,13 +748,20 @@ static int save_compressed_image(struct swap_map_handle *handle,
745
748
init_waitqueue_head (& data [thr ].go );
746
749
init_waitqueue_head (& data [thr ].done );
747
750
748
- data [thr ].cc = crypto_alloc_comp (hib_comp_algo , 0 , 0 );
751
+ data [thr ].cc = crypto_alloc_acomp (hib_comp_algo , 0 , CRYPTO_ALG_ASYNC );
749
752
if (IS_ERR_OR_NULL (data [thr ].cc )) {
750
753
pr_err ("Could not allocate comp stream %ld\n" , PTR_ERR (data [thr ].cc ));
751
754
ret = - EFAULT ;
752
755
goto out_clean ;
753
756
}
754
757
758
+ data [thr ].cr = acomp_request_alloc (data [thr ].cc );
759
+ if (!data [thr ].cr ) {
760
+ pr_err ("Could not allocate comp request\n" );
761
+ ret = - ENOMEM ;
762
+ goto out_clean ;
763
+ }
764
+
755
765
data [thr ].thr = kthread_run (compress_threadfn ,
756
766
& data [thr ],
757
767
"image_compress/%u" , thr );
@@ -899,8 +909,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
899
909
for (thr = 0 ; thr < nr_threads ; thr ++ ) {
900
910
if (data [thr ].thr )
901
911
kthread_stop (data [thr ].thr );
902
- if (data [thr ].cc )
903
- crypto_free_comp (data [thr ].cc );
912
+ acomp_request_free (data [thr ].cr );
913
+ crypto_free_acomp (data [thr ].cc );
904
914
}
905
915
vfree (data );
906
916
}
@@ -1142,7 +1152,8 @@ static int load_image(struct swap_map_handle *handle,
1142
1152
*/
1143
1153
struct dec_data {
1144
1154
struct task_struct * thr ; /* thread */
1145
- struct crypto_comp * cc ; /* crypto compressor stream */
1155
+ struct crypto_acomp * cc ; /* crypto compressor */
1156
+ struct acomp_req * cr ; /* crypto request */
1146
1157
atomic_t ready ; /* ready to start flag */
1147
1158
atomic_t stop ; /* ready to stop flag */
1148
1159
int ret ; /* return code */
@@ -1160,7 +1171,6 @@ struct dec_data {
1160
1171
static int decompress_threadfn (void * data )
1161
1172
{
1162
1173
struct dec_data * d = data ;
1163
- unsigned int unc_len = 0 ;
1164
1174
1165
1175
while (1 ) {
1166
1176
wait_event (d -> go , atomic_read_acquire (& d -> ready ) ||
@@ -1174,10 +1184,13 @@ static int decompress_threadfn(void *data)
1174
1184
}
1175
1185
atomic_set (& d -> ready , 0 );
1176
1186
1177
- unc_len = UNC_SIZE ;
1178
- d -> ret = crypto_comp_decompress (d -> cc , d -> cmp + CMP_HEADER , d -> cmp_len ,
1179
- d -> unc , & unc_len );
1180
- d -> unc_len = unc_len ;
1187
+ acomp_request_set_callback (d -> cr , CRYPTO_TFM_REQ_MAY_SLEEP ,
1188
+ NULL , NULL );
1189
+ acomp_request_set_src_nondma (d -> cr , d -> cmp + CMP_HEADER ,
1190
+ d -> cmp_len );
1191
+ acomp_request_set_dst_nondma (d -> cr , d -> unc , UNC_SIZE );
1192
+ d -> ret = crypto_acomp_decompress (d -> cr );
1193
+ d -> unc_len = d -> cr -> dlen ;
1181
1194
1182
1195
if (clean_pages_on_decompress )
1183
1196
flush_icache_range ((unsigned long )d -> unc ,
@@ -1254,13 +1267,20 @@ static int load_compressed_image(struct swap_map_handle *handle,
1254
1267
init_waitqueue_head (& data [thr ].go );
1255
1268
init_waitqueue_head (& data [thr ].done );
1256
1269
1257
- data [thr ].cc = crypto_alloc_comp (hib_comp_algo , 0 , 0 );
1270
+ data [thr ].cc = crypto_alloc_acomp (hib_comp_algo , 0 , CRYPTO_ALG_ASYNC );
1258
1271
if (IS_ERR_OR_NULL (data [thr ].cc )) {
1259
1272
pr_err ("Could not allocate comp stream %ld\n" , PTR_ERR (data [thr ].cc ));
1260
1273
ret = - EFAULT ;
1261
1274
goto out_clean ;
1262
1275
}
1263
1276
1277
+ data [thr ].cr = acomp_request_alloc (data [thr ].cc );
1278
+ if (!data [thr ].cr ) {
1279
+ pr_err ("Could not allocate comp request\n" );
1280
+ ret = - ENOMEM ;
1281
+ goto out_clean ;
1282
+ }
1283
+
1264
1284
data [thr ].thr = kthread_run (decompress_threadfn ,
1265
1285
& data [thr ],
1266
1286
"image_decompress/%u" , thr );
@@ -1507,8 +1527,8 @@ static int load_compressed_image(struct swap_map_handle *handle,
1507
1527
for (thr = 0 ; thr < nr_threads ; thr ++ ) {
1508
1528
if (data [thr ].thr )
1509
1529
kthread_stop (data [thr ].thr );
1510
- if (data [thr ].cc )
1511
- crypto_free_comp (data [thr ].cc );
1530
+ acomp_request_free (data [thr ].cr );
1531
+ crypto_free_acomp (data [thr ].cc );
1512
1532
}
1513
1533
vfree (data );
1514
1534
}
0 commit comments