VirtualBox

Changeset 66523 in vbox


Ignore:
Timestamp:
Apr 12, 2017 10:22:50 AM (8 years ago)
Author:
vboxsync
Message:

bugref:8834: Makeself installers/Linux: indicate problems better in the exit codes
[PATCH] additions/linux/drm: Cleanup vram mapping and offset
calculating code

Trying to put everything in one pci_iomap_range mapped area leads to
hard to read code and has no advantages. It actually causes us to map
more memory then we need, resulting in part of the memory being intended
for generic use also being mapped.

This commit splits the mapping up in to 2 pci_iomap_range calls, one
for the guest_heap + host-flags and another one for the vbva buffers
which is not done until we actually know how much buffers we need.

Signed-off-by: Hans de Goede <hdegoede@…>
Minor adjustment: GUEST_HEAP_OFFSET -> GUEST_HEAP_OFFSET(vbox)

Location:
trunk/src/VBox/Additions/linux/drm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/drm/vbox_drv.h

    r66189 r66523  
    9090#define VBOX_MAX_SCREENS  32
    9191
     92#define GUEST_HEAP_OFFSET(vbox) (vbox->full_vram_size - VBVA_ADAPTER_INFORMATION_SIZE)
     93#define GUEST_HEAP_SIZE   VBVA_ADAPTER_INFORMATION_SIZE
     94#define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
     95                                sizeof(HGSMIHOSTFLAGS))
     96#define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
     97
    9298struct vbox_fbdev;
    9399
     
    95101    struct drm_device *dev;
    96102
    97     uint8_t __iomem *mapped_vram;
     103    u8 __iomem *guest_heap;
     104    u8 __iomem *vbva_buffers;
    98105    HGSMIGUESTCOMMANDCONTEXT submit_info;
    99106    struct VBVABUFFERCONTEXT *vbva_info;
     
    104111    /** Amount of available VRAM, not including space used for buffers. */
    105112    uint32_t available_vram_size;
    106     /** Offset of mapped VRAM area in full VRAM. */
    107     uint32_t vram_map_start;
    108     /** Offset to the host flags in the VRAM. */
    109     uint32_t host_flags_offset;
    110113    /** Array of structures for receiving mode hints. */
    111114    VBVAMODEHINT *last_mode_hints;
  • trunk/src/VBox/Additions/linux/drm/vbox_irq.c

    r66224 r66523  
    5757static uint32_t vbox_get_flags(struct vbox_private *vbox)
    5858{
    59     return (uint32_t)readl(vbox->mapped_vram + vbox->host_flags_offset);
     59        return readl(vbox->guest_heap + HOST_FLAGS_OFFSET);
    6060}
    6161
  • trunk/src/VBox/Additions/linux/drm/vbox_main.c

    r66509 r66523  
    6868    unsigned i;
    6969    struct VBVABUFFER *vbva;
    70     uint32_t vram_map_offset = vbox->available_vram_size - vbox->vram_map_start;
    71 
    72     if (vbox->vbva_info == NULL) {  /* Should never happen... */
     70
     71    if (!vbox->vbva_info || !vbox->vbva_buffers) { /* Should never happen... */
    7372        printk(KERN_ERR "vboxvideo: failed to set up VBVA.\n");
    7473        return;
     
    7675    for (i = 0; i < vbox->num_crtcs; ++i) {
    7776        if (vbox->vbva_info[i].pVBVA == NULL) {
    78             vbva = (struct VBVABUFFER *) (  ((uint8_t *)vbox->mapped_vram)
    79                                            + vram_map_offset
     77            vbva = (struct VBVABUFFER *) ((u8 *)vbox->vbva_buffers
    8078                                           + i * VBVA_MIN_BUFFER_SIZE);
    8179            if (!VBoxVBVAEnable(&vbox->vbva_info[i], &vbox->submit_info, vbva, i)) {
     
    238236        vbox->vbva_info = NULL;
    239237    }
     238    if (vbox->vbva_buffers) {
     239        pci_iounmap(vbox->dev->pdev, vbox->vbva_buffers);
     240        vbox->vbva_buffers = NULL;
     241    }
    240242}
    241243
     
    251253    /* Take a command buffer for each screen from the end of usable VRAM. */
    252254    vbox->available_vram_size -= vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE;
     255
     256    vbox->vbva_buffers = pci_iomap_range(vbox->dev->pdev, 0,
     257                                     vbox->available_vram_size,
     258                                     vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE);
     259    if (!vbox->vbva_buffers)
     260        return -ENOMEM;
     261
    253262    for (i = 0; i < vbox->num_crtcs; ++i)
    254263        VBoxVBVASetupBufferContext(&vbox->vbva_info[i],
     
    303312static int vbox_hw_init(struct vbox_private *vbox)
    304313{
    305     uint32_t base_offset, map_start, guest_heap_offset, guest_heap_size, host_flags_offset;
    306     void *guest_heap;
    307 
    308314    vbox->full_vram_size = VBoxVideoGetVRAMSize();
    309315    vbox->any_pitch = VBoxVideoAnyWidthAllowed();
    310316    DRM_INFO("VRAM %08x\n", vbox->full_vram_size);
    311     VBoxHGSMIGetBaseMappingInfo(vbox->full_vram_size, &base_offset, NULL,
    312                                 &guest_heap_offset, &guest_heap_size, &host_flags_offset);
    313     map_start = (uint32_t)max((int)base_offset
    314                               - VBOX_MAX_SCREENS * VBVA_MIN_BUFFER_SIZE, 0);
    315     vbox->mapped_vram = pci_iomap_range(vbox->dev->pdev, 0, map_start,
    316                                         vbox->full_vram_size - map_start);
    317     if (!vbox->mapped_vram)
     317
     318    /* Map guest-heap at end of vram */
     319    vbox->guest_heap = pci_iomap_range(vbox->dev->pdev, 0, GUEST_HEAP_OFFSET(vbox),
     320                                       GUEST_HEAP_SIZE);
     321    if (!vbox->guest_heap)
    318322        return -ENOMEM;
    319     vbox->vram_map_start = map_start;
    320     guest_heap = ((uint8_t *)vbox->mapped_vram) + base_offset - map_start
    321                    + guest_heap_offset;
    322     vbox->host_flags_offset = base_offset - map_start + host_flags_offset;
    323     if (RT_FAILURE(VBoxHGSMISetupGuestContext(&vbox->submit_info, guest_heap,
    324                                               guest_heap_size,
    325                                               base_offset + guest_heap_offset,
     323
     324    if (RT_FAILURE(VBoxHGSMISetupGuestContext(&vbox->submit_info, vbox->guest_heap,
     325                                              GUEST_HEAP_USABLE_SIZE, GUEST_HEAP_OFFSET(vbox),
    326326                                              &hgsmi_environ)))
    327327        return -ENOMEM;
    328328    /* Reduce available VRAM size to reflect the guest heap. */
    329     vbox->available_vram_size = base_offset;
     329    vbox->available_vram_size = GUEST_HEAP_OFFSET(vbox);
    330330    /* Linux drm represents monitors as a 32-bit array. */
    331331    vbox->num_crtcs = min(VBoxHGSMIGetMonitorCount(&vbox->submit_info),
     
    413413    vbox_hw_fini(vbox);
    414414    vbox_mm_fini(vbox);
    415     if (vbox->mapped_vram)
    416         pci_iounmap(dev->pdev, vbox->mapped_vram);
     415    if (vbox->guest_heap)
     416        pci_iounmap(dev->pdev, vbox->guest_heap);
    417417    kfree(vbox);
    418418    dev->dev_private = NULL;
  • trunk/src/VBox/Additions/linux/drm/vbox_mode.c

    r65992 r66523  
    547547     * We need to report the flags location before reporting the IRQ
    548548     * capability. */
    549     VBoxHGSMIReportFlagsLocation(&vbox->submit_info,   vbox->vram_map_start
    550                                                      + vbox->host_flags_offset);
     549    VBoxHGSMIReportFlagsLocation(&vbox->submit_info, GUEST_HEAP_OFFSET(vbox) +
     550                                                     HOST_FLAGS_OFFSET);
    551551    if (vbox_connector->vbox_crtc->crtc_id == 0)
    552552        vbox_report_caps(vbox);
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