forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/misc/vmw_vmci/vmci_guest.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * VMware VMCI Driver
34 *
45 * Copyright (C) 2012 VMware, Inc. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License as published by the
8
- * Free Software Foundation version 2 and no later version.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
- * for more details.
146 */
157
168 #include <linux/vmw_vmci_defs.h>
....@@ -63,6 +55,13 @@
6355 void *notification_bitmap;
6456 dma_addr_t notification_base;
6557 };
58
+
59
+static bool use_ppn64;
60
+
61
+bool vmci_use_ppn64(void)
62
+{
63
+ return use_ppn64;
64
+}
6665
6766 /* vmci_dev singleton device and supporting data*/
6867 struct pci_dev *vmci_pdev;
....@@ -432,6 +431,7 @@
432431 struct vmci_guest_device *vmci_dev;
433432 void __iomem *iobase;
434433 unsigned int capabilities;
434
+ unsigned int caps_in_use;
435435 unsigned long cmd;
436436 int vmci_err;
437437 int error;
....@@ -496,6 +496,23 @@
496496 error = -ENXIO;
497497 goto err_free_data_buffer;
498498 }
499
+ caps_in_use = VMCI_CAPS_DATAGRAM;
500
+
501
+ /*
502
+ * Use 64-bit PPNs if the device supports.
503
+ *
504
+ * There is no check for the return value of dma_set_mask_and_coherent
505
+ * since this driver can handle the default mask values if
506
+ * dma_set_mask_and_coherent fails.
507
+ */
508
+ if (capabilities & VMCI_CAPS_PPN64) {
509
+ dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
510
+ use_ppn64 = true;
511
+ caps_in_use |= VMCI_CAPS_PPN64;
512
+ } else {
513
+ dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
514
+ use_ppn64 = false;
515
+ }
499516
500517 /*
501518 * If the hardware supports notifications, we will use that as
....@@ -510,14 +527,14 @@
510527 "Unable to allocate notification bitmap\n");
511528 } else {
512529 memset(vmci_dev->notification_bitmap, 0, PAGE_SIZE);
513
- capabilities |= VMCI_CAPS_NOTIFICATIONS;
530
+ caps_in_use |= VMCI_CAPS_NOTIFICATIONS;
514531 }
515532 }
516533
517
- dev_info(&pdev->dev, "Using capabilities 0x%x\n", capabilities);
534
+ dev_info(&pdev->dev, "Using capabilities 0x%x\n", caps_in_use);
518535
519536 /* Let the host know which capabilities we intend to use. */
520
- iowrite32(capabilities, vmci_dev->iobase + VMCI_CAPS_ADDR);
537
+ iowrite32(caps_in_use, vmci_dev->iobase + VMCI_CAPS_ADDR);
521538
522539 /* Set up global device so that we can start sending datagrams */
523540 spin_lock_irq(&vmci_dev_spinlock);
....@@ -529,13 +546,13 @@
529546 * Register notification bitmap with device if that capability is
530547 * used.
531548 */
532
- if (capabilities & VMCI_CAPS_NOTIFICATIONS) {
549
+ if (caps_in_use & VMCI_CAPS_NOTIFICATIONS) {
533550 unsigned long bitmap_ppn =
534551 vmci_dev->notification_base >> PAGE_SHIFT;
535552 if (!vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
536553 dev_warn(&pdev->dev,
537
- "VMCI device unable to register notification bitmap with PPN 0x%x\n",
538
- (u32) bitmap_ppn);
554
+ "VMCI device unable to register notification bitmap with PPN 0x%lx\n",
555
+ bitmap_ppn);
539556 error = -ENXIO;
540557 goto err_remove_vmci_dev_g;
541558 }
....@@ -611,7 +628,7 @@
611628
612629 /* Enable specific interrupt bits. */
613630 cmd = VMCI_IMR_DATAGRAM;
614
- if (capabilities & VMCI_CAPS_NOTIFICATIONS)
631
+ if (caps_in_use & VMCI_CAPS_NOTIFICATIONS)
615632 cmd |= VMCI_IMR_NOTIFICATION;
616633 iowrite32(cmd, vmci_dev->iobase + VMCI_IMR_ADDR);
617634
....@@ -620,6 +637,8 @@
620637 vmci_dev->iobase + VMCI_CONTROL_ADDR);
621638
622639 pci_set_drvdata(pdev, vmci_dev);
640
+
641
+ vmci_call_vsock_callback(false);
623642 return 0;
624643
625644 err_free_irq: