Author: hselasky
Date: Wed Jul  3 18:29:18 2019
New Revision: 349670
URL: https://svnweb.freebsd.org/changeset/base/349670

Log:
  MFC r349522:
  Need to apply the PCIM_BAR_MEM_BASE mask to the physical memory
  address before returning it to the user. Some of the least significant
  bits have special meaning and should be masked away.
  
  Discussed with:       kib@
  Sponsored by: Mellanox Technologies

Modified:
  stable/12/sys/dev/pci/pci_user.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/pci/pci_user.c
==============================================================================
--- stable/12/sys/dev/pci/pci_user.c    Wed Jul  3 18:26:07 2019        
(r349669)
+++ stable/12/sys/dev/pci/pci_user.c    Wed Jul  3 18:29:18 2019        
(r349670)
@@ -855,6 +855,7 @@ pci_bar_mmap(device_t pcidev, struct pci_bar_mmap *pbm
        struct thread *td;
        struct sglist *sg;
        struct pci_map *pm;
+       vm_paddr_t membase;
        vm_paddr_t pbase;
        vm_size_t plen;
        vm_offset_t addr;
@@ -877,8 +878,9 @@ pci_bar_mmap(device_t pcidev, struct pci_bar_mmap *pbm
                return (EBUSY); /* XXXKIB enable if _ACTIVATE */
        if (!PCI_BAR_MEM(pm->pm_value))
                return (EIO);
-       pbase = trunc_page(pm->pm_value);
-       plen = round_page(pm->pm_value + ((pci_addr_t)1 << pm->pm_size)) -
+       membase = pm->pm_value & PCIM_BAR_MEM_BASE;
+       pbase = trunc_page(membase);
+       plen = round_page(membase + ((pci_addr_t)1 << pm->pm_size)) -
            pbase;
        prot = VM_PROT_READ | (((pbm->pbm_flags & PCIIO_BAR_MMAP_RW) != 0) ?
            VM_PROT_WRITE : 0);
@@ -910,7 +912,7 @@ pci_bar_mmap(device_t pcidev, struct pci_bar_mmap *pbm
        }
        pbm->pbm_map_base = (void *)addr;
        pbm->pbm_map_length = plen;
-       pbm->pbm_bar_off = pm->pm_value - pbase;
+       pbm->pbm_bar_off = membase - pbase;
        pbm->pbm_bar_length = (pci_addr_t)1 << pm->pm_size;
 
 out:
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to