1
2
3
4
5
6#define pr_fmt(fmt) "vas: " fmt
7
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/export.h>
11#include <linux/types.h>
12#include <linux/delay.h>
13#include <linux/slab.h>
14#include <linux/interrupt.h>
15#include <linux/irqdomain.h>
16#include <asm/machdep.h>
17#include <asm/hvcall.h>
18#include <asm/plpar_wrappers.h>
19#include <asm/vas.h>
20#include "vas.h"
21
22#define VAS_INVALID_WIN_ADDRESS 0xFFFFFFFFFFFFFFFFul
23#define VAS_DEFAULT_DOMAIN_ID 0xFFFFFFFFFFFFFFFFul
24
25#define DEF_WIN_CREDS 1
26
27static struct vas_all_caps caps_all;
28static bool copypaste_feat;
29static struct hv_vas_cop_feat_caps hv_cop_caps;
30
31static struct vas_caps vascaps[VAS_MAX_FEAT_TYPE];
32static DEFINE_MUTEX(vas_pseries_mutex);
33static bool migration_in_progress;
34
35static long hcall_return_busy_check(long rc)
36{
37
38 if (H_IS_LONG_BUSY(rc)) {
39 msleep(get_longbusy_msecs(rc));
40 rc = H_BUSY;
41 } else if (rc == H_BUSY) {
42 cond_resched();
43 }
44
45 return rc;
46}
47
48
49
50
51static int h_allocate_vas_window(struct pseries_vas_window *win, u64 *domain,
52 u8 wintype, u16 credits)
53{
54 long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
55 long rc;
56
57 do {
58 rc = plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, wintype,
59 credits, domain[0], domain[1], domain[2],
60 domain[3], domain[4], domain[5]);
61
62 rc = hcall_return_busy_check(rc);
63 } while (rc == H_BUSY);
64
65 if (rc == H_SUCCESS) {
66 if (win->win_addr == VAS_INVALID_WIN_ADDRESS) {
67 pr_err("H_ALLOCATE_VAS_WINDOW: COPY/PASTE is not supported\n");
68 return -ENOTSUPP;
69 }
70 win->vas_win.winid = retbuf[0];
71 win->win_addr = retbuf[1];
72 win->complete_irq = retbuf[2];
73 win->fault_irq = retbuf[3];
74 return 0;
75 }
76
77 pr_err("H_ALLOCATE_VAS_WINDOW error: %ld, wintype: %u, credits: %u\n",
78 rc, wintype, credits);
79
80 return -EIO;
81}
82
83
84
85
86static int h_deallocate_vas_window(u64 winid)
87{
88 long rc;
89
90 do {
91 rc = plpar_hcall_norets(H_DEALLOCATE_VAS_WINDOW, winid);
92
93 rc = hcall_return_busy_check(rc);
94 } while (rc == H_BUSY);
95
96 if (rc == H_SUCCESS)
97 return 0;
98
99 pr_err("H_DEALLOCATE_VAS_WINDOW error: %ld, winid: %llu\n",
100 rc, winid);
101 return -EIO;
102}
103
104
105
106
107
108
109static int h_modify_vas_window(struct pseries_vas_window *win)
110{
111 long rc;
112
113
114
115
116
117 do {
118 rc = plpar_hcall_norets(H_MODIFY_VAS_WINDOW,
119 win->vas_win.winid, win->pid, 0,
120 VAS_MOD_WIN_FLAGS, 0);
121
122 rc = hcall_return_busy_check(rc);
123 } while (rc == H_BUSY);
124
125 if (rc == H_SUCCESS)
126 return 0;
127
128 pr_err("H_MODIFY_VAS_WINDOW error: %ld, winid %u pid %u\n",
129 rc, win->vas_win.winid, win->pid);
130 return -EIO;
131}
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result)
147{
148 long rc;
149
150 rc = plpar_hcall_norets(hcall, query_type, result);
151
152 if (rc == H_SUCCESS)
153 return 0;
154
155
156 if (rc != H_FUNCTION) {
157 pr_err("%s error %ld, query_type %u, result buffer 0x%llx\n",
158 (hcall == H_QUERY_VAS_CAPABILITIES) ?
159 "H_QUERY_VAS_CAPABILITIES" :
160 "H_QUERY_NX_CAPABILITIES",
161 rc, query_type, result);
162 }
163
164 return -EIO;
165}
166EXPORT_SYMBOL_GPL(h_query_vas_capabilities);
167
168
169
170
171static int h_get_nx_fault(u32 winid, u64 buffer)
172{
173 long rc;
174
175 rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer);
176
177 if (rc == H_SUCCESS)
178 return 0;
179
180 pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n",
181 rc, winid, buffer);
182 return -EIO;
183
184}
185
186
187
188
189
190
191
192
193
194
195static irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data)
196{
197 struct pseries_vas_window *txwin = data;
198 struct coprocessor_request_block crb;
199 struct vas_user_win_ref *tsk_ref;
200 int rc;
201
202 rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb));
203 if (!rc) {
204 tsk_ref = &txwin->vas_win.task_ref;
205 vas_dump_crb(&crb);
206 vas_update_csb(&crb, tsk_ref);
207 }
208
209 return IRQ_HANDLED;
210}
211
212
213
214
215static int allocate_setup_window(struct pseries_vas_window *txwin,
216 u64 *domain, u8 wintype)
217{
218 int rc;
219
220 rc = h_allocate_vas_window(txwin, domain, wintype, DEF_WIN_CREDS);
221 if (rc)
222 return rc;
223
224
225
226
227
228 txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq);
229 if (!txwin->fault_virq) {
230 pr_err("Failed irq mapping %d\n", txwin->fault_irq);
231 rc = -EINVAL;
232 goto out_win;
233 }
234
235 txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d",
236 txwin->vas_win.winid);
237 if (!txwin->name) {
238 rc = -ENOMEM;
239 goto out_irq;
240 }
241
242 rc = request_threaded_irq(txwin->fault_virq, NULL,
243 pseries_vas_fault_thread_fn, IRQF_ONESHOT,
244 txwin->name, txwin);
245 if (rc) {
246 pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n",
247 txwin->vas_win.winid, txwin->fault_virq, rc);
248 goto out_free;
249 }
250
251 txwin->vas_win.wcreds_max = DEF_WIN_CREDS;
252
253 return 0;
254out_free:
255 kfree(txwin->name);
256out_irq:
257 irq_dispose_mapping(txwin->fault_virq);
258out_win:
259 h_deallocate_vas_window(txwin->vas_win.winid);
260 return rc;
261}
262
263static inline void free_irq_setup(struct pseries_vas_window *txwin)
264{
265 free_irq(txwin->fault_virq, txwin);
266 kfree(txwin->name);
267 irq_dispose_mapping(txwin->fault_virq);
268}
269
270static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
271 enum vas_cop_type cop_type)
272{
273 long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID};
274 struct vas_cop_feat_caps *cop_feat_caps;
275 struct vas_caps *caps;
276 struct pseries_vas_window *txwin;
277 int rc;
278
279 txwin = kzalloc(sizeof(*txwin), GFP_KERNEL);
280 if (!txwin)
281 return ERR_PTR(-ENOMEM);
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307 if (flags & VAS_TX_WIN_FLAG_QOS_CREDIT)
308 caps = &vascaps[VAS_GZIP_QOS_FEAT_TYPE];
309 else
310 caps = &vascaps[VAS_GZIP_DEF_FEAT_TYPE];
311
312 cop_feat_caps = &caps->caps;
313
314 if (atomic_inc_return(&cop_feat_caps->nr_used_credits) >
315 atomic_read(&cop_feat_caps->nr_total_credits)) {
316 pr_err("Credits are not available to allocate window\n");
317 rc = -EINVAL;
318 goto out;
319 }
320
321 if (vas_id == -1) {
322
323
324
325
326
327
328
329
330
331
332
333
334 rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
335 VPHN_FLAG_VCPU, smp_processor_id());
336 if (rc != H_SUCCESS) {
337 pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
338 goto out;
339 }
340 }
341
342 txwin->pid = mfspr(SPRN_PID);
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359 mutex_lock(&vas_pseries_mutex);
360 if (migration_in_progress)
361 rc = -EBUSY;
362 else
363 rc = allocate_setup_window(txwin, (u64 *)&domain[0],
364 cop_feat_caps->win_type);
365 mutex_unlock(&vas_pseries_mutex);
366 if (rc)
367 goto out;
368
369
370
371
372 rc = h_modify_vas_window(txwin);
373 if (!rc)
374 rc = get_vas_user_win_ref(&txwin->vas_win.task_ref);
375 if (rc)
376 goto out_free;
377
378 txwin->win_type = cop_feat_caps->win_type;
379 mutex_lock(&vas_pseries_mutex);
380
381
382
383
384
385
386
387
388 if (!caps->nr_close_wins) {
389 list_add(&txwin->win_list, &caps->list);
390 caps->nr_open_windows++;
391 mutex_unlock(&vas_pseries_mutex);
392 vas_user_win_add_mm_context(&txwin->vas_win.task_ref);
393 return &txwin->vas_win;
394 }
395 mutex_unlock(&vas_pseries_mutex);
396
397 put_vas_user_win_ref(&txwin->vas_win.task_ref);
398 rc = -EBUSY;
399 pr_err("No credit is available to allocate window\n");
400
401out_free:
402
403
404
405
406 free_irq_setup(txwin);
407 h_deallocate_vas_window(txwin->vas_win.winid);
408out:
409 atomic_dec(&cop_feat_caps->nr_used_credits);
410 kfree(txwin);
411 return ERR_PTR(rc);
412}
413
414static u64 vas_paste_address(struct vas_window *vwin)
415{
416 struct pseries_vas_window *win;
417
418 win = container_of(vwin, struct pseries_vas_window, vas_win);
419 return win->win_addr;
420}
421
422static int deallocate_free_window(struct pseries_vas_window *win)
423{
424 int rc = 0;
425
426
427
428
429
430
431
432
433
434
435 rc = h_deallocate_vas_window(win->vas_win.winid);
436 if (!rc)
437 free_irq_setup(win);
438
439 return rc;
440}
441
442static int vas_deallocate_window(struct vas_window *vwin)
443{
444 struct pseries_vas_window *win;
445 struct vas_cop_feat_caps *caps;
446 int rc = 0;
447
448 if (!vwin)
449 return -EINVAL;
450
451 win = container_of(vwin, struct pseries_vas_window, vas_win);
452
453
454 if (win->win_type >= VAS_MAX_FEAT_TYPE) {
455 pr_err("Window (%u): Invalid window type %u\n",
456 vwin->winid, win->win_type);
457 return -EINVAL;
458 }
459
460 caps = &vascaps[win->win_type].caps;
461 mutex_lock(&vas_pseries_mutex);
462
463
464
465
466
467
468 if (!(win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) &&
469 !(win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) {
470 rc = deallocate_free_window(win);
471 if (rc) {
472 mutex_unlock(&vas_pseries_mutex);
473 return rc;
474 }
475 } else
476 vascaps[win->win_type].nr_close_wins--;
477
478 list_del(&win->win_list);
479 atomic_dec(&caps->nr_used_credits);
480 vascaps[win->win_type].nr_open_windows--;
481 mutex_unlock(&vas_pseries_mutex);
482
483 put_vas_user_win_ref(&vwin->task_ref);
484 mm_context_remove_vas_window(vwin->task_ref.mm);
485
486 kfree(win);
487 return 0;
488}
489
490static const struct vas_user_win_ops vops_pseries = {
491 .open_win = vas_allocate_window,
492 .paste_addr = vas_paste_address,
493 .close_win = vas_deallocate_window,
494};
495
496
497
498
499
500int vas_register_api_pseries(struct module *mod, enum vas_cop_type cop_type,
501 const char *name)
502{
503 int rc;
504
505 if (!copypaste_feat)
506 return -ENOTSUPP;
507
508 rc = vas_register_coproc_api(mod, cop_type, name, &vops_pseries);
509
510 return rc;
511}
512EXPORT_SYMBOL_GPL(vas_register_api_pseries);
513
514void vas_unregister_api_pseries(void)
515{
516 vas_unregister_coproc_api();
517}
518EXPORT_SYMBOL_GPL(vas_unregister_api_pseries);
519
520
521
522
523
524static int __init get_vas_capabilities(u8 feat, enum vas_cop_feat_type type,
525 struct hv_vas_cop_feat_caps *hv_caps)
526{
527 struct vas_cop_feat_caps *caps;
528 struct vas_caps *vcaps;
529 int rc = 0;
530
531 vcaps = &vascaps[type];
532 memset(vcaps, 0, sizeof(*vcaps));
533 INIT_LIST_HEAD(&vcaps->list);
534
535 vcaps->feat = feat;
536 caps = &vcaps->caps;
537
538 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, feat,
539 (u64)virt_to_phys(hv_caps));
540 if (rc)
541 return rc;
542
543 caps->user_mode = hv_caps->user_mode;
544 if (!(caps->user_mode & VAS_COPY_PASTE_USER_MODE)) {
545 pr_err("User space COPY/PASTE is not supported\n");
546 return -ENOTSUPP;
547 }
548
549 caps->descriptor = be64_to_cpu(hv_caps->descriptor);
550 caps->win_type = hv_caps->win_type;
551 if (caps->win_type >= VAS_MAX_FEAT_TYPE) {
552 pr_err("Unsupported window type %u\n", caps->win_type);
553 return -EINVAL;
554 }
555 caps->max_lpar_creds = be16_to_cpu(hv_caps->max_lpar_creds);
556 caps->max_win_creds = be16_to_cpu(hv_caps->max_win_creds);
557 atomic_set(&caps->nr_total_credits,
558 be16_to_cpu(hv_caps->target_lpar_creds));
559 if (feat == VAS_GZIP_DEF_FEAT) {
560 caps->def_lpar_creds = be16_to_cpu(hv_caps->def_lpar_creds);
561
562 if (caps->max_win_creds < DEF_WIN_CREDS) {
563 pr_err("Window creds(%u) > max allowed window creds(%u)\n",
564 DEF_WIN_CREDS, caps->max_win_creds);
565 return -EINVAL;
566 }
567 }
568
569 rc = sysfs_add_vas_caps(caps);
570 if (rc)
571 return rc;
572
573 copypaste_feat = true;
574
575 return 0;
576}
577
578
579
580
581
582
583
584
585
586static int reconfig_open_windows(struct vas_caps *vcaps, int creds,
587 bool migrate)
588{
589 long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID};
590 struct vas_cop_feat_caps *caps = &vcaps->caps;
591 struct pseries_vas_window *win = NULL, *tmp;
592 int rc, mv_ents = 0;
593 int flag;
594
595
596
597
598 if (!vcaps->nr_close_wins)
599 return 0;
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615 if ((vcaps->nr_close_wins > creds) && !migrate)
616 mv_ents = vcaps->nr_close_wins - creds;
617
618 list_for_each_entry_safe(win, tmp, &vcaps->list, win_list) {
619 if (!mv_ents)
620 break;
621
622 mv_ents--;
623 }
624
625
626
627
628
629 if (migrate)
630 flag = VAS_WIN_MIGRATE_CLOSE;
631 else
632 flag = VAS_WIN_NO_CRED_CLOSE;
633
634 list_for_each_entry_safe_from(win, tmp, &vcaps->list, win_list) {
635
636
637
638
639
640
641
642
643 if ((win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) &&
644 (win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) {
645 win->vas_win.status &= ~flag;
646 continue;
647 }
648
649
650
651
652
653 if (!(win->vas_win.status & flag))
654 continue;
655
656 rc = allocate_setup_window(win, (u64 *)&domain[0],
657 caps->win_type);
658 if (rc)
659 return rc;
660
661 rc = h_modify_vas_window(win);
662 if (rc)
663 goto out;
664
665 mutex_lock(&win->vas_win.task_ref.mmap_mutex);
666
667
668
669 win->vas_win.status &= ~flag;
670 mutex_unlock(&win->vas_win.task_ref.mmap_mutex);
671 win->win_type = caps->win_type;
672 if (!--vcaps->nr_close_wins)
673 break;
674 }
675
676 return 0;
677out:
678
679
680
681
682 free_irq_setup(win);
683 h_deallocate_vas_window(win->vas_win.winid);
684 return rc;
685}
686
687
688
689
690
691
692
693
694
695
696static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
697 bool migrate)
698{
699 struct pseries_vas_window *win, *tmp;
700 struct vas_user_win_ref *task_ref;
701 struct vm_area_struct *vma;
702 int rc = 0, flag;
703
704 if (migrate)
705 flag = VAS_WIN_MIGRATE_CLOSE;
706 else
707 flag = VAS_WIN_NO_CRED_CLOSE;
708
709 list_for_each_entry_safe(win, tmp, &vcap->list, win_list) {
710
711
712
713
714
715
716
717 if ((win->vas_win.status & VAS_WIN_MIGRATE_CLOSE) ||
718 (win->vas_win.status & VAS_WIN_NO_CRED_CLOSE)) {
719 win->vas_win.status |= flag;
720 continue;
721 }
722
723 task_ref = &win->vas_win.task_ref;
724 mutex_lock(&task_ref->mmap_mutex);
725 vma = task_ref->vma;
726
727
728
729
730 win->vas_win.status |= flag;
731
732 mmap_write_lock(task_ref->mm);
733
734
735
736
737
738
739 if (vma)
740 zap_page_range(vma, vma->vm_start,
741 vma->vm_end - vma->vm_start);
742
743 mmap_write_unlock(task_ref->mm);
744 mutex_unlock(&task_ref->mmap_mutex);
745
746
747
748
749
750
751
752 rc = deallocate_free_window(win);
753
754
755
756
757
758 if (rc && !migrate)
759 return rc;
760
761 vcap->nr_close_wins++;
762
763
764
765
766
767
768
769
770 if (!migrate && !--excess_creds)
771 break;
772 }
773
774 return 0;
775}
776
777
778
779
780
781
782int vas_reconfig_capabilties(u8 type, int new_nr_creds)
783{
784 struct vas_cop_feat_caps *caps;
785 int old_nr_creds;
786 struct vas_caps *vcaps;
787 int rc = 0, nr_active_wins;
788
789 if (type >= VAS_MAX_FEAT_TYPE) {
790 pr_err("Invalid credit type %d\n", type);
791 return -EINVAL;
792 }
793
794 vcaps = &vascaps[type];
795 caps = &vcaps->caps;
796
797 mutex_lock(&vas_pseries_mutex);
798
799 old_nr_creds = atomic_read(&caps->nr_total_credits);
800
801 atomic_set(&caps->nr_total_credits, new_nr_creds);
802
803
804
805
806
807
808 if (old_nr_creds < new_nr_creds) {
809
810
811
812
813
814 rc = reconfig_open_windows(vcaps, new_nr_creds - old_nr_creds,
815 false);
816 } else {
817
818
819
820
821
822 nr_active_wins = vcaps->nr_open_windows - vcaps->nr_close_wins;
823 if (nr_active_wins > new_nr_creds)
824 rc = reconfig_close_windows(vcaps,
825 nr_active_wins - new_nr_creds,
826 false);
827 }
828
829 mutex_unlock(&vas_pseries_mutex);
830 return rc;
831}
832
833
834
835
836
837
838
839
840static int pseries_vas_notifier(struct notifier_block *nb,
841 unsigned long action, void *data)
842{
843 struct of_reconfig_data *rd = data;
844 struct device_node *dn = rd->dn;
845 const __be32 *intserv = NULL;
846 int new_nr_creds, len, rc = 0;
847
848 if ((action == OF_RECONFIG_ATTACH_NODE) ||
849 (action == OF_RECONFIG_DETACH_NODE))
850 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
851 &len);
852
853
854
855 if (!intserv)
856 return NOTIFY_OK;
857
858 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES,
859 vascaps[VAS_GZIP_DEF_FEAT_TYPE].feat,
860 (u64)virt_to_phys(&hv_cop_caps));
861 if (!rc) {
862 new_nr_creds = be16_to_cpu(hv_cop_caps.target_lpar_creds);
863 rc = vas_reconfig_capabilties(VAS_GZIP_DEF_FEAT_TYPE,
864 new_nr_creds);
865 }
866
867 if (rc)
868 pr_err("Failed reconfig VAS capabilities with DLPAR\n");
869
870 return rc;
871}
872
873static struct notifier_block pseries_vas_nb = {
874 .notifier_call = pseries_vas_notifier,
875};
876
877
878
879
880
881
882
883int vas_migration_handler(int action)
884{
885 struct vas_cop_feat_caps *caps;
886 int old_nr_creds, new_nr_creds = 0;
887 struct vas_caps *vcaps;
888 int i, rc = 0;
889
890
891
892
893 if (!copypaste_feat)
894 return rc;
895
896 mutex_lock(&vas_pseries_mutex);
897
898 if (action == VAS_SUSPEND)
899 migration_in_progress = true;
900 else
901 migration_in_progress = false;
902
903 for (i = 0; i < VAS_MAX_FEAT_TYPE; i++) {
904 vcaps = &vascaps[i];
905 caps = &vcaps->caps;
906 old_nr_creds = atomic_read(&caps->nr_total_credits);
907
908 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES,
909 vcaps->feat,
910 (u64)virt_to_phys(&hv_cop_caps));
911 if (!rc) {
912 new_nr_creds = be16_to_cpu(hv_cop_caps.target_lpar_creds);
913
914
915
916
917
918
919 if (old_nr_creds != new_nr_creds) {
920 pr_err("Target credits mismatch with the hypervisor\n");
921 pr_err("state(%d): lpar creds: %d HV lpar creds: %d\n",
922 action, old_nr_creds, new_nr_creds);
923 pr_err("Used creds: %d, Active creds: %d\n",
924 atomic_read(&caps->nr_used_credits),
925 vcaps->nr_open_windows - vcaps->nr_close_wins);
926 }
927 } else {
928 pr_err("state(%d): Get VAS capabilities failed with %d\n",
929 action, rc);
930
931
932
933
934
935
936
937 if (action == VAS_RESUME)
938 goto out;
939 }
940
941 switch (action) {
942 case VAS_SUSPEND:
943 rc = reconfig_close_windows(vcaps, vcaps->nr_open_windows,
944 true);
945 break;
946 case VAS_RESUME:
947 atomic_set(&caps->nr_total_credits, new_nr_creds);
948 rc = reconfig_open_windows(vcaps, new_nr_creds, true);
949 break;
950 default:
951
952 pr_err("Invalid migration action %d\n", action);
953 rc = -EINVAL;
954 goto out;
955 }
956
957
958
959
960 if (rc && (action == VAS_RESUME))
961 goto out;
962 }
963
964out:
965 mutex_unlock(&vas_pseries_mutex);
966 return rc;
967}
968
969static int __init pseries_vas_init(void)
970{
971 struct hv_vas_all_caps *hv_caps;
972 int rc = 0;
973
974
975
976
977 if (!radix_enabled()) {
978 pr_err("API is supported only with radix page tables\n");
979 return -ENOTSUPP;
980 }
981
982 hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
983 if (!hv_caps)
984 return -ENOMEM;
985
986
987
988 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, 0,
989 (u64)virt_to_phys(hv_caps));
990 if (rc)
991 goto out;
992
993 caps_all.descriptor = be64_to_cpu(hv_caps->descriptor);
994 caps_all.feat_type = be64_to_cpu(hv_caps->feat_type);
995
996 sysfs_pseries_vas_init(&caps_all);
997
998
999
1000
1001 if (caps_all.feat_type & VAS_GZIP_QOS_FEAT_BIT) {
1002 rc = get_vas_capabilities(VAS_GZIP_QOS_FEAT,
1003 VAS_GZIP_QOS_FEAT_TYPE, &hv_cop_caps);
1004
1005 if (rc)
1006 goto out;
1007 }
1008
1009
1010
1011 if (caps_all.feat_type & VAS_GZIP_DEF_FEAT_BIT)
1012 rc = get_vas_capabilities(VAS_GZIP_DEF_FEAT,
1013 VAS_GZIP_DEF_FEAT_TYPE, &hv_cop_caps);
1014
1015 if (!rc && copypaste_feat) {
1016 if (firmware_has_feature(FW_FEATURE_LPAR))
1017 of_reconfig_notifier_register(&pseries_vas_nb);
1018
1019 pr_info("GZIP feature is available\n");
1020 } else {
1021
1022
1023
1024
1025
1026 copypaste_feat = false;
1027 }
1028
1029out:
1030 kfree(hv_caps);
1031 return rc;
1032}
1033machine_device_initcall(pseries, pseries_vas_init);
1034