VirtualBox

Ignore:
Timestamp:
Mar 15, 2010 4:11:21 PM (15 years ago)
Author:
vboxsync
Message:

Solaris/memobj: Try ddi_umem_alloc on the testbox.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/solaris/vbi/memobj-r0drv-solaris.c

    r27115 r27373  
    7777        case RTR0MEMOBJTYPE_CONT:
    7878        case RTR0MEMOBJTYPE_PHYS:
    79             vbi_contig_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
     79            vbi_phys_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
    8080            break;
    8181
    8282        case RTR0MEMOBJTYPE_PHYS_NC:
     83            LogRel(("MemObjNativeFree virtAddr=%p physAddr=%#x cb=%u\n", pMemSolaris->Core.pv, vbi_va_to_pa(pMemSolaris->Core.pv), (unsigned)pMemSolaris->Core.cb));
     84#if 0
    8385            vbi_phys_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
     86#else
     87            ddi_umem_free(pMemSolaris->Cookie);
     88#endif
    8489            break;
    8590
     
    173178        return VERR_NO_MEMORY;
    174179
    175     if (PhysHighest == NIL_RTHCPHYS)
    176         PhysHighest = UINT64_MAX - 1;
    177 
    178180    /* Allocate physically non-contiguous page-aligned memory. */
    179181    uint64_t physAddr = PhysHighest;
     182#if 0
    180183    caddr_t virtAddr  = vbi_phys_alloc(&physAddr, cb, PAGE_SIZE, 0 /* non-contiguous */);
     184#else
     185    caddr_t virtAddr = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
     186#endif
    181187    if (RT_UNLIKELY(virtAddr == NULL))
    182188    {
     
    190196    pMemSolaris->pvHandle = NULL;
    191197    *ppMem = &pMemSolaris->Core;
     198    LogRel(("ddi_umem_alloc virtAddr=%p physAddr=%#x cb=%u\n", virtAddr, physAddr, (unsigned)cb));
    192199    return VINF_SUCCESS;
    193200#else
     
    202209    AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
    203210
    204     /** @todo alignment, vbi currently assumes PAGE_SIZE not even less than PAGE_SIZE */
     211    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
     212    if (!pMemSolaris)
     213        return VERR_NO_MEMORY;
     214
     215    AssertCompile(NIL_RTHCPHYS == UINT64_MAX);
     216
     217    /* Allocate physically contiguous memory aligned as specified. */
     218    uint64_t physAddr = PhysHighest;
     219    caddr_t  virtAddr = vbi_phys_alloc(&physAddr, cb, uAlignment, 1 /* contiguous */);
     220    if (RT_UNLIKELY(virtAddr == NULL))
     221    {
     222        rtR0MemObjDelete(&pMemSolaris->Core);
     223        return VERR_NO_CONT_MEMORY;
     224    }
     225    Assert(!(physAddr & PAGE_OFFSET_MASK));
     226    Assert(physAddr < PhysHighest);
     227    Assert(physAddr + cb <= PhysHighest);
     228#if 0
    205229    if (uAlignment != PAGE_SIZE)
    206         return VERR_NOT_SUPPORTED;
    207 
    208      PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb);
    209      if (!pMemSolaris)
    210          return VERR_NO_MEMORY;
    211 
    212      AssertCompile(NIL_RTHCPHYS == UINT64_MAX);
    213 
    214      /* Allocate physically contiguous memory aligned as specified. */
    215      uint64_t physAddr = PhysHighest;
    216      caddr_t  virtAddr = vbi_phys_alloc(&physAddr, cb, uAlignment, 1 /* contiguous */);
    217      if (RT_UNLIKELY(virtAddr == NULL))
    218      {
    219          rtR0MemObjDelete(&pMemSolaris->Core);
    220          return VERR_NO_CONT_MEMORY;
    221      }
    222      Assert(!(physAddr & PAGE_OFFSET_MASK));
    223      Assert(physAddr < PhysHighest);
    224      Assert(physAddr + cb <= PhysHighest);
    225      pMemSolaris->Core.pv = virtAddr;
    226      pMemSolaris->Core.u.Cont.Phys = physAddr;
    227      pMemSolaris->pvHandle = NULL;
    228      *ppMem = &pMemSolaris->Core;
    229      return VINF_SUCCESS;
     230    {
     231        /* uAlignment is always a multiple of PAGE_SIZE */
     232        pgcnt_t cPages = (cb + uAlignment - 1) >> PAGE_SHIFT;
     233        void *pvPage = virtAddr;
     234        while (cPages-- > 0)
     235        {
     236            uint64_t u64Page = vbi_va_to_pa(pvPage);
     237            if (u64Page & (uAlignment - 1))
     238            {
     239                LogRel(("rtR0MemObjNativeAllocPhys: alignment mismatch! cb=%u uAlignment=%u physAddr=%#x\n", cb, uAlignment, u64Page));
     240                vbi_phys_free(virtAddr, cb);
     241                rtR0MemObjDelete(&pMemSolaris->Core);
     242                return VERR_NO_MEMORY;
     243            }
     244            pvPage = (void *)((uintptr_t)pvPage + PAGE_SIZE);
     245        }
     246    }
     247#endif
     248    pMemSolaris->Core.pv = virtAddr;
     249    pMemSolaris->Core.u.Cont.Phys = physAddr;
     250    pMemSolaris->pvHandle = NULL;
     251    *ppMem = &pMemSolaris->Core;
     252    return VINF_SUCCESS;
    230253}
    231254
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette