diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-29 10:38:10 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-29 10:38:10 -0700 |
commit | 738b04fba18d35cd352b7b15afefb8a7b798648e (patch) | |
tree | 07fabb1a920af5c92bd35e10f9821cf56c8de3e4 /drivers/staging/vboxvideo | |
parent | fe675d4d3c6b96710d481346821839b4a817c672 (diff) | |
parent | 4ab7e05dd070600833680bd318d6d962f010caa2 (diff) |
Merge tag 'staging-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/IIO driver updates from Greg KH:
"Here is the big staging and IIO driver pull request for 4.20-rc1.
There are lots of things here, we ended up adding more lines than
removing, thanks to a large influx of Comedi National Instrument
device support. Someday soon we need to get comedi out of staging...
Other than the comedi drivers, the "big" things here are:
- new iio drivers
- delete dgnc driver (no one used it and no one had the hardware
anymore)
- vbox driver updates and fixes
- erofs fixes
- tons and tons of tiny checkpatch fixes for almost all staging
drivers
All of these have been in linux-next, with the last few happening a
bit "late" due to them getting stuck on my laptop during travel to the
Mantainers summit"
* tag 'staging-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (690 commits)
staging: gasket: Fix sparse "incorrect type in assignment" warnings.
staging: gasket: remove debug logs for callback invocation
staging: gasket: remove debug logs in page table mapping calls
staging: rtl8188eu: core: Use sizeof(*p) instead of sizeof(struct P) for memory allocation
staging: ks7010: Remove extra blank line
staging: gasket: Remove extra blank line
staging: media: davinci_vpfe: Fix spelling mistake in enum
staging: speakup: Add a pair of braces
staging: wlan-ng: Replace long int with long
staging: MAINTAINERS: remove obsolete IPX staging directory
staging: MAINTAINERS: remove NCP filesystem entry
staging: rtl8188eu: cleanup comparsions to false
staging: gasket: Update device virtual address comment
staging: gasket: sysfs: fix attribute release comment
staging: gasket: apex: fix sysfs_show
staging: gasket: page_table: simplify gasket_components_to_dev_address
staging: gasket: page_table: fix comment in components_to_dev_address
staging: gasket: page table: fixup error path allocating coherent mem
staging: gasket: page_table: rearrange gasket_page_table_entry
staging: gasket: page_table: remove unnecessary PTE status set to free
...
Diffstat (limited to 'drivers/staging/vboxvideo')
-rw-r--r-- | drivers/staging/vboxvideo/TODO | 1 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_drv.c | 165 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_drv.h | 86 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_fb.c | 152 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_irq.c | 8 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_main.c | 185 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_mode.c | 922 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_ttm.c | 78 |
8 files changed, 744 insertions, 853 deletions
diff --git a/drivers/staging/vboxvideo/TODO b/drivers/staging/vboxvideo/TODO index 468eea856ca6..2e0f99c3f10c 100644 --- a/drivers/staging/vboxvideo/TODO +++ b/drivers/staging/vboxvideo/TODO @@ -1,5 +1,4 @@ TODO: --Move the driver over to the atomic API -Get a full review from the drm-maintainers on dri-devel done on this driver -Extend this TODO with the results of that review diff --git a/drivers/staging/vboxvideo/vbox_drv.c b/drivers/staging/vboxvideo/vbox_drv.c index 69cc508af1bc..257030460fb6 100644 --- a/drivers/staging/vboxvideo/vbox_drv.c +++ b/drivers/staging/vboxvideo/vbox_drv.c @@ -49,139 +49,140 @@ static const struct pci_device_id pciidlist[] = { }; MODULE_DEVICE_TABLE(pci, pciidlist); +static struct drm_fb_helper_funcs vbox_fb_helper_funcs = { + .fb_probe = vboxfb_create, +}; + static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { - struct drm_device *dev = NULL; + struct vbox_private *vbox; int ret = 0; - dev = drm_dev_alloc(&driver, &pdev->dev); - if (IS_ERR(dev)) { - ret = PTR_ERR(dev); - goto err_drv_alloc; + if (!vbox_check_supported(VBE_DISPI_ID_HGSMI)) + return -ENODEV; + + vbox = kzalloc(sizeof(*vbox), GFP_KERNEL); + if (!vbox) + return -ENOMEM; + + ret = drm_dev_init(&vbox->ddev, &driver, &pdev->dev); + if (ret) { + kfree(vbox); + return ret; } + vbox->ddev.pdev = pdev; + vbox->ddev.dev_private = vbox; + pci_set_drvdata(pdev, vbox); + mutex_init(&vbox->hw_mutex); + ret = pci_enable_device(pdev); if (ret) - goto err_pci_enable; - - dev->pdev = pdev; - pci_set_drvdata(pdev, dev); + goto err_dev_put; - ret = vbox_driver_load(dev); + ret = vbox_hw_init(vbox); if (ret) - goto err_vbox_driver_load; + goto err_pci_disable; - ret = drm_dev_register(dev, 0); + ret = vbox_mm_init(vbox); if (ret) - goto err_drv_dev_register; - - return ret; - - err_drv_dev_register: - vbox_driver_unload(dev); - err_vbox_driver_load: - pci_disable_device(pdev); - err_pci_enable: - drm_dev_put(dev); - err_drv_alloc: - return ret; -} - -static void vbox_pci_remove(struct pci_dev *pdev) -{ - struct drm_device *dev = pci_get_drvdata(pdev); - - drm_dev_unregister(dev); - vbox_driver_unload(dev); - drm_dev_put(dev); -} + goto err_hw_fini; -static int vbox_drm_freeze(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; + ret = vbox_mode_init(vbox); + if (ret) + goto err_mm_fini; - drm_kms_helper_poll_disable(dev); + ret = vbox_irq_init(vbox); + if (ret) + goto err_mode_fini; - pci_save_state(dev->pdev); + ret = drm_fb_helper_fbdev_setup(&vbox->ddev, &vbox->fb_helper, + &vbox_fb_helper_funcs, 32, + vbox->num_crtcs); + if (ret) + goto err_irq_fini; - drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, true); + ret = drm_dev_register(&vbox->ddev, 0); + if (ret) + goto err_fbdev_fini; return 0; -} - -static int vbox_drm_thaw(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; - - drm_mode_config_reset(dev); - drm_helper_resume_force_mode(dev); - drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, false); - return 0; +err_fbdev_fini: + vbox_fbdev_fini(vbox); +err_irq_fini: + vbox_irq_fini(vbox); +err_mode_fini: + vbox_mode_fini(vbox); +err_mm_fini: + vbox_mm_fini(vbox); +err_hw_fini: + vbox_hw_fini(vbox); +err_pci_disable: + pci_disable_device(pdev); +err_dev_put: + drm_dev_put(&vbox->ddev); + return ret; } -static int vbox_drm_resume(struct drm_device *dev) +static void vbox_pci_remove(struct pci_dev *pdev) { - int ret; - - if (pci_enable_device(dev->pdev)) - return -EIO; - - ret = vbox_drm_thaw(dev); - if (ret) - return ret; - - drm_kms_helper_poll_enable(dev); - - return 0; + struct vbox_private *vbox = pci_get_drvdata(pdev); + + drm_dev_unregister(&vbox->ddev); + vbox_fbdev_fini(vbox); + vbox_irq_fini(vbox); + vbox_mode_fini(vbox); + vbox_mm_fini(vbox); + vbox_hw_fini(vbox); + drm_dev_put(&vbox->ddev); } static int vbox_pm_suspend(struct device *dev) { - struct pci_dev *pdev = to_pci_dev(dev); - struct drm_device *ddev = pci_get_drvdata(pdev); + struct vbox_private *vbox = dev_get_drvdata(dev); int error; - error = vbox_drm_freeze(ddev); + error = drm_mode_config_helper_suspend(&vbox->ddev); if (error) return error; - pci_disable_device(pdev); - pci_set_power_state(pdev, PCI_D3hot); + pci_save_state(vbox->ddev.pdev); + pci_disable_device(vbox->ddev.pdev); + pci_set_power_state(vbox->ddev.pdev, PCI_D3hot); return 0; } static int vbox_pm_resume(struct device *dev) { - struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); + struct vbox_private *vbox = dev_get_drvdata(dev); + + if (pci_enable_device(vbox->ddev.pdev)) + return -EIO; - return vbox_drm_resume(ddev); + return drm_mode_config_helper_resume(&vbox->ddev); } static int vbox_pm_freeze(struct device *dev) { - struct pci_dev *pdev = to_pci_dev(dev); - struct drm_device *ddev = pci_get_drvdata(pdev); - - if (!ddev || !ddev->dev_private) - return -ENODEV; + struct vbox_private *vbox = dev_get_drvdata(dev); - return vbox_drm_freeze(ddev); + return drm_mode_config_helper_suspend(&vbox->ddev); } static int vbox_pm_thaw(struct device *dev) { - struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); + struct vbox_private *vbox = dev_get_drvdata(dev); - return vbox_drm_thaw(ddev); + return drm_mode_config_helper_resume(&vbox->ddev); } static int vbox_pm_poweroff(struct device *dev) { - struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); + struct vbox_private *vbox = dev_get_drvdata(dev); - return vbox_drm_freeze(ddev); + return drm_mode_config_helper_suspend(&vbox->ddev); } static const struct dev_pm_ops vbox_pm_ops = { @@ -259,10 +260,10 @@ static void vbox_master_drop(struct drm_device *dev, struct drm_file *file_priv) static struct drm_driver driver = { .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | - DRIVER_PRIME, + DRIVER_PRIME | DRIVER_ATOMIC, .dev_priv_size = 0, - .lastclose = vbox_driver_lastclose, + .lastclose = drm_fb_helper_lastclose, .master_set = vbox_master_set, .master_drop = vbox_master_drop, diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h index 594f84272957..73395a7536c5 100644 --- a/drivers/staging/vboxvideo/vbox_drv.h +++ b/drivers/staging/vboxvideo/vbox_drv.h @@ -72,10 +72,16 @@ sizeof(struct hgsmi_host_flags)) #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE -struct vbox_fbdev; +struct vbox_framebuffer { + struct drm_framebuffer base; + struct drm_gem_object *obj; +}; struct vbox_private { - struct drm_device *dev; + /* Must be first; or we must define our own release callback */ + struct drm_device ddev; + struct drm_fb_helper fb_helper; + struct vbox_framebuffer afb; u8 __iomem *guest_heap; u8 __iomem *vbva_buffers; @@ -90,8 +96,6 @@ struct vbox_private { /** Array of structures for receiving mode hints. */ struct vbva_modehint *last_mode_hints; - struct vbox_fbdev *fbdev; - int fb_mtrr; struct { @@ -115,21 +119,12 @@ struct vbox_private { * encompassing all screen ones or is the fbdev console active? */ bool single_framebuffer; - u32 cursor_width; - u32 cursor_height; - u32 cursor_hot_x; - u32 cursor_hot_y; - size_t cursor_data_size; u8 cursor_data[CURSOR_DATA_SIZE]; }; #undef CURSOR_PIXEL_COUNT #undef CURSOR_DATA_SIZE -int vbox_driver_load(struct drm_device *dev); -void vbox_driver_unload(struct drm_device *dev); -void vbox_driver_lastclose(struct drm_device *dev); - struct vbox_gem_object; struct vbox_connector { @@ -145,43 +140,51 @@ struct vbox_connector { struct vbox_crtc { struct drm_crtc base; - bool blanked; bool disconnected; unsigned int crtc_id; u32 fb_offset; bool cursor_enabled; u32 x_hint; u32 y_hint; + /* + * When setting a mode we not only pass the mode to the hypervisor, + * but also information on how to map / translate input coordinates + * for the emulated USB tablet. This input-mapping may change when + * the mode on *another* crtc changes. + * + * This means that sometimes we must do a modeset on other crtc-s then + * the one being changed to update the input-mapping. Including crtc-s + * which may be disabled inside the guest (shown as a black window + * on the host unless closed by the user). + * + * With atomic modesetting the mode-info of disabled crtcs gets zeroed + * yet we need it when updating the input-map to avoid resizing the + * window as a side effect of a mode_set on another crtc. Therefor we + * cache the info of the last mode below. + */ + u32 width; + u32 height; + u32 x; + u32 y; }; struct vbox_encoder { struct drm_encoder base; }; -struct vbox_framebuffer { - struct drm_framebuffer base; - struct drm_gem_object *obj; -}; - -struct vbox_fbdev { - struct drm_fb_helper helper; - struct vbox_framebuffer afb; - int size; - struct ttm_bo_kmap_obj mapping; - int x1, y1, x2, y2; /* dirty rect */ - spinlock_t dirty_lock; -}; - #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base) #define to_vbox_connector(x) container_of(x, struct vbox_connector, base) #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base) #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base) -int vbox_mode_init(struct drm_device *dev); -void vbox_mode_fini(struct drm_device *dev); +bool vbox_check_supported(u16 id); +int vbox_hw_init(struct vbox_private *vbox); +void vbox_hw_fini(struct vbox_private *vbox); + +int vbox_mode_init(struct vbox_private *vbox); +void vbox_mode_fini(struct vbox_private *vbox); #define DRM_MODE_FB_CMD drm_mode_fb_cmd2 -#define CRTC_FB(crtc) ((crtc)->primary->fb) void vbox_enable_accel(struct vbox_private *vbox); void vbox_disable_accel(struct vbox_private *vbox); @@ -191,14 +194,14 @@ void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb, struct drm_clip_rect *rects, unsigned int num_rects); -int vbox_framebuffer_init(struct drm_device *dev, +int vbox_framebuffer_init(struct vbox_private *vbox, struct vbox_framebuffer *vbox_fb, const struct DRM_MODE_FB_CMD *mode_cmd, struct drm_gem_object *obj); -int vbox_fbdev_init(struct drm_device *dev); -void vbox_fbdev_fini(struct drm_device *dev); -void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr); +int vboxfb_create(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes); +void vbox_fbdev_fini(struct vbox_private *vbox); struct vbox_bo { struct ttm_buffer_object bo; @@ -218,6 +221,11 @@ static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo) #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base) +static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo) +{ + return bo->bo.offset; +} + int vbox_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args); @@ -232,13 +240,13 @@ int vbox_dumb_mmap_offset(struct drm_file *file, int vbox_mm_init(struct vbox_private *vbox); void vbox_mm_fini(struct vbox_private *vbox); -int vbox_bo_create(struct drm_device *dev, int size, int align, +int vbox_bo_create(struct vbox_private *vbox, int size, int align, u32 flags, struct vbox_bo **pvboxbo); -int vbox_gem_create(struct drm_device *dev, +int vbox_gem_create(struct vbox_private *vbox, u32 size, bool iskernel, struct drm_gem_object **obj); -int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr); +int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag); int vbox_bo_unpin(struct vbox_bo *bo); static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) @@ -262,6 +270,8 @@ static inline void vbox_bo_unreserve(struct vbox_bo *bo) void vbox_ttm_placement(struct vbox_bo *bo, int domain); int vbox_bo_push_sysram(struct vbox_bo *bo); int vbox_mmap(struct file *filp, struct vm_area_struct *vma); +void *vbox_bo_kmap(struct vbox_bo *bo); +void vbox_bo_kunmap(struct vbox_bo *bo); /* vbox_prime.c */ int vbox_gem_prime_pin(struct drm_gem_object *obj); diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c index 034f8ffa8f20..d1a1f74c8de3 100644 --- a/drivers/staging/vboxvideo/vbox_fb.c +++ b/drivers/staging/vboxvideo/vbox_fb.c @@ -66,38 +66,19 @@ static struct fb_ops vboxfb_ops = { .fb_debug_leave = drm_fb_helper_debug_leave, }; -static int vboxfb_create_object(struct vbox_fbdev *fbdev, - struct DRM_MODE_FB_CMD *mode_cmd, - struct drm_gem_object **gobj_p) +int vboxfb_create(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes) { - struct drm_device *dev = fbdev->helper.dev; - u32 size; - struct drm_gem_object *gobj; - u32 pitch = mode_cmd->pitches[0]; - int ret; - - size = pitch * mode_cmd->height; - ret = vbox_gem_create(dev, size, true, &gobj); - if (ret) - return ret; - - *gobj_p = gobj; - - return 0; -} - -static int vboxfb_create(struct drm_fb_helper *helper, - struct drm_fb_helper_surface_size *sizes) -{ - struct vbox_fbdev *fbdev = - container_of(helper, struct vbox_fbdev, helper); - struct drm_device *dev = fbdev->helper.dev; + struct vbox_private *vbox = + container_of(helper, struct vbox_private, fb_helper); + struct pci_dev *pdev = vbox->ddev.pdev; struct DRM_MODE_FB_CMD mode_cmd; struct drm_framebuffer *fb; struct fb_info *info; struct drm_gem_object *gobj; struct vbox_bo *bo; int size, ret; + u64 gpu_addr; u32 pitch; mode_cmd.width = sizes->surface_width; @@ -109,45 +90,35 @@ static int vboxfb_create(struct drm_fb_helper *helper, size = pitch * mode_cmd.height; - ret = vboxfb_create_object(fbdev, &mode_cmd, &gobj); + ret = vbox_gem_create(vbox, size, true, &gobj); if (ret) { DRM_ERROR("failed to create fbcon backing object %d\n", ret); return ret; } - ret = vbox_framebuffer_init(dev, &fbdev->afb, &mode_cmd, gobj); + ret = vbox_framebuffer_init(vbox, &vbox->afb, &mode_cmd, gobj); if (ret) return ret; bo = gem_to_vbox_bo(gobj); - ret = vbox_bo_reserve(bo, false); + ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); if (ret) return ret; - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, NULL); - if (ret) { - vbox_bo_unreserve(bo); - return ret; - } - - ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); - vbox_bo_unreserve(bo); - if (ret) { - DRM_ERROR("failed to kmap fbcon\n"); - return ret; - } - info = drm_fb_helper_alloc_fbi(helper); if (IS_ERR(info)) - return -PTR_ERR(info); + return PTR_ERR(info); - info->par = fbdev; + info->screen_size = size; + info->screen_base = (char __iomem *)vbox_bo_kmap(bo); + if (IS_ERR(info->screen_base)) + return PTR_ERR(info->screen_base); - fbdev->size = size; + info->par = helper; - fb = &fbdev->afb.base; - fbdev->helper.fb = fb; + fb = &vbox->afb.base; + helper->fb = fb; strcpy(info->fix.id, "vboxdrmfb"); @@ -162,15 +133,16 @@ static int vboxfb_create(struct drm_fb_helper *helper, * This seems to be done for safety checking that the framebuffer * is not registered twice by different drivers. */ - info->apertures->ranges[0].base = pci_resource_start(dev->pdev, 0); - info->apertures->ranges[0].size = pci_resource_len(dev->pdev, 0); + info->apertures->ranges[0].base = pci_resource_start(pdev, 0); + info->apertures->ranges[0].size = pci_resource_len(pdev, 0); drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); - drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, + drm_fb_helper_fill_var(info, helper, sizes->fb_width, sizes->fb_height); - info->screen_base = (char __iomem *)bo->kmap.virtual; - info->screen_size = size; + gpu_addr = vbox_bo_gpu_offset(bo); + info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr; + info->fix.smem_len = vbox->available_vram_size - gpu_addr; #ifdef CONFIG_DRM_KMS_FB_HELPER info->fbdefio = &vbox_defio; @@ -184,86 +156,30 @@ static int vboxfb_create(struct drm_fb_helper *helper, return 0; } -static struct drm_fb_helper_funcs vbox_fb_helper_funcs = { - .fb_probe = vboxfb_create, -}; - -void vbox_fbdev_fini(struct drm_device *dev) +void vbox_fbdev_fini(struct vbox_private *vbox) { - struct vbox_private *vbox = dev->dev_private; - struct vbox_fbdev *fbdev = vbox->fbdev; - struct vbox_framebuffer *afb = &fbdev->afb; + struct vbox_framebuffer *afb = &vbox->afb; #ifdef CONFIG_DRM_KMS_FB_HELPER - if (fbdev->helper.fbdev && fbdev->helper.fbdev->fbdefio) - fb_deferred_io_cleanup(fbdev->helper.fbdev); + if (vbox->fb_helper.fbdev && vbox->fb_helper.fbdev->fbdefio) + fb_deferred_io_cleanup(vbox->fb_helper.fbdev); #endif - drm_fb_helper_unregister_fbi(&fbdev->helper); + drm_fb_helper_unregister_fbi(&vbox->fb_helper); if (afb->obj) { struct vbox_bo *bo = gem_to_vbox_bo(afb->obj); - if (!vbox_bo_reserve(bo, false)) { - if (bo->kmap.virtual) - ttm_bo_kunmap(&bo->kmap); - /* - * QXL does this, but is it really needed before - * freeing? - */ - if (bo->pin_count) - vbox_bo_unpin(bo); - vbox_bo_unreserve(bo); - } + vbox_bo_kunmap(bo); + + if (bo->pin_count) + vbox_bo_unpin(bo); + drm_gem_object_put_unlocked(afb->obj); afb->obj = NULL; } - drm_fb_helper_fini(&fbdev->helper); + drm_fb_helper_fini(&vbox->fb_helper); drm_framebuffer_unregister_private(&afb->base); drm_framebuffer_cleanup(&afb->base); } - -int vbox_fbdev_init(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; - struct vbox_fbdev *fbdev; - int ret; - - fbdev = devm_kzalloc(dev->dev, sizeof(*fbdev), GFP_KERNEL); - if (!fbdev) - return -ENOMEM; - - vbox->fbdev = fbdev; - spin_lock_init(&fbdev->dirty_lock); - - drm_fb_helper_prepare(dev, &fbdev->helper, &vbox_fb_helper_funcs); - ret = drm_fb_helper_init(dev, &fbdev->helper, vbox->num_crtcs); - if (ret) - return ret; - - ret = drm_fb_helper_single_add_all_connectors(&fbdev->helper); - if (ret) - goto err_fini; - - /* disable all the possible outputs/crtcs before entering KMS mode */ - drm_helper_disable_unused_functions(dev); - - ret = drm_fb_helper_initial_config(&fbdev->helper, 32); - if (ret) - goto err_fini; - - return 0; - -err_fini: - drm_fb_helper_fini(&fbdev->helper); - return ret; -} - -void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr) -{ - struct fb_info *fbdev = vbox->fbdev->helper.fbdev; - - fbdev->fix.smem_start = fbdev->apertures->ranges[0].base + gpu_addr; - fbdev->fix.smem_len = vbox->available_vram_size - gpu_addr; -} diff --git a/drivers/staging/vboxvideo/vbox_irq.c b/drivers/staging/vboxvideo/vbox_irq.c index 74abdf02d9fd..09f858ec1369 100644 --- a/drivers/staging/vboxvideo/vbox_irq.c +++ b/drivers/staging/vboxvideo/vbox_irq.c @@ -123,7 +123,7 @@ static void validate_or_set_position_hints(struct vbox_private *vbox) */ static void vbox_update_mode_hints(struct vbox_private *vbox) { - struct drm_device *dev = vbox->dev; + struct drm_device *dev = &vbox->ddev; struct drm_connector *connector; struct vbox_connector *vbox_conn; struct vbva_modehint *hints; @@ -179,7 +179,7 @@ static void vbox_hotplug_worker(struct work_struct *work) hotplug_work); vbox_update_mode_hints(vbox); - drm_kms_helper_hotplug_event(vbox->dev); + drm_kms_helper_hotplug_event(&vbox->ddev); } int vbox_irq_init(struct vbox_private *vbox) @@ -187,11 +187,11 @@ int vbox_irq_init(struct vbox_private *vbox) INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker); vbox_update_mode_hints(vbox); - return drm_irq_install(vbox->dev, vbox->dev->pdev->irq); + return drm_irq_install(&vbox->ddev, vbox->ddev.pdev->irq); } void vbox_irq_fini(struct vbox_private *vbox) { - drm_irq_uninstall(vbox->dev); + drm_irq_uninstall(&vbox->ddev); flush_work(&vbox->hotplug_work); } diff --git a/drivers/staging/vboxvideo/vbox_main.c b/drivers/staging/vboxvideo/vbox_main.c index 429f6a453619..7466c1103ff6 100644 --- a/drivers/staging/vboxvideo/vbox_main.c +++ b/drivers/staging/vboxvideo/vbox_main.c @@ -102,24 +102,30 @@ void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb, unsigned int num_rects) { struct vbox_private *vbox = fb->dev->dev_private; + struct drm_display_mode *mode; struct drm_crtc *crtc; + int crtc_x, crtc_y; unsigned int i; mutex_lock(&vbox->hw_mutex); list_for_each_entry(crtc, &fb->dev->mode_config.crtc_list, head) { - if (CRTC_FB(crtc) != fb) + if (crtc->primary->state->fb != fb) continue; + mode = &crtc->state->mode; + crtc_x = crtc->primary->state->src_x >> 16; + crtc_y = crtc->primary->state->src_y >> 16; + vbox_enable_accel(vbox); for (i = 0; i < num_rects; ++i) { struct vbva_cmd_hdr cmd_hdr; unsigned int crtc_id = to_vbox_crtc(crtc)->crtc_id; - if ((rects[i].x1 > crtc->x + crtc->hwmode.hdisplay) || - (rects[i].y1 > crtc->y + crtc->hwmode.vdisplay) || - (rects[i].x2 < crtc->x) || - (rects[i].y2 < crtc->y)) + if ((rects[i].x1 > crtc_x + mode->hdisplay) || + (rects[i].y1 > crtc_y + mode->vdisplay) || + (rects[i].x2 < crtc_x) || + (rects[i].y2 < crtc_y)) continue; cmd_hdr.x = (s16)rects[i].x1; @@ -155,16 +161,16 @@ static const struct drm_framebuffer_funcs vbox_fb_funcs = { .dirty = vbox_user_framebuffer_dirty, }; -int vbox_framebuffer_init(struct drm_device *dev, +int vbox_framebuffer_init(struct vbox_private *vbox, struct vbox_framebuffer *vbox_fb, const struct DRM_MODE_FB_CMD *mode_cmd, struct drm_gem_object *obj) { int ret; - drm_helper_mode_fill_fb_struct(dev, &vbox_fb->base, mode_cmd); + drm_helper_mode_fill_fb_struct(&vbox->ddev, &vbox_fb->base, mode_cmd); vbox_fb->obj = obj; - ret = drm_framebuffer_init(dev, &vbox_fb->base, &vbox_fb_funcs); + ret = drm_framebuffer_init(&vbox->ddev, &vbox_fb->base, &vbox_fb_funcs); if (ret) { DRM_ERROR("framebuffer init failed %d\n", ret); return ret; @@ -173,45 +179,11 @@ int vbox_framebuffer_init(struct drm_device *dev, return 0; } -static struct drm_framebuffer *vbox_user_framebuffer_create( - struct drm_device *dev, - struct drm_file *filp, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - struct drm_gem_object *obj; - struct vbox_framebuffer *vbox_fb; - int ret = -ENOMEM; - - obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]); - if (!obj) - return ERR_PTR(-ENOENT); - - vbox_fb = kzalloc(sizeof(*vbox_fb), GFP_KERNEL); - if (!vbox_fb) - goto err_unref_obj; - - ret = vbox_framebuffer_init(dev, vbox_fb, mode_cmd, obj); - if (ret) - goto err_free_vbox_fb; - - return &vbox_fb->base; - -err_free_vbox_fb: - kfree(vbox_fb); -err_unref_obj: - drm_gem_object_put_unlocked(obj); - return ERR_PTR(ret); -} - -static const struct drm_mode_config_funcs vbox_mode_funcs = { - .fb_create = vbox_user_framebuffer_create, -}; - static int vbox_accel_init(struct vbox_private *vbox) { unsigned int i; - vbox->vbva_info = devm_kcalloc(vbox->dev->dev, vbox->num_crtcs, + vbox->vbva_info = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs, sizeof(*vbox->vbva_info), GFP_KERNEL); if (!vbox->vbva_info) return -ENOMEM; @@ -219,7 +191,7 @@ static int vbox_accel_init(struct vbox_private *vbox) /* Take a command buffer for each screen from the end of usable VRAM. */ vbox->available_vram_size -= vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE; - vbox->vbva_buffers = pci_iomap_range(vbox->dev->pdev, 0, + vbox->vbva_buffers = pci_iomap_range(vbox->ddev.pdev, 0, vbox->available_vram_size, vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE); @@ -238,7 +210,7 @@ static int vbox_accel_init(struct vbox_private *vbox) static void vbox_accel_fini(struct vbox_private *vbox) { vbox_disable_accel(vbox); - pci_iounmap(vbox->dev->pdev, vbox->vbva_buffers); + pci_iounmap(vbox->ddev.pdev, vbox->vbva_buffers); } /** Do we support the 4.3 plus mode hint reporting interface? */ @@ -262,7 +234,7 @@ static bool have_hgsmi_mode_hints(struct vbox_private *vbox) return have_hints == VINF_SUCCESS && have_cursor == VINF_SUCCESS; } -static bool vbox_check_supported(u16 id) +bool vbox_check_supported(u16 id) { u16 dispi_id; @@ -276,7 +248,7 @@ static bool vbox_check_supported(u16 id) * Set up our heaps and data exchange buffers in VRAM before handing the rest * to the memory manager. */ -static int vbox_hw_init(struct vbox_private *vbox) +int vbox_hw_init(struct vbox_private *vbox) { int ret = -ENOMEM; @@ -287,7 +259,7 @@ static int vbox_hw_init(struct vbox_private *vbox) /* Map guest-heap at end of vram */ vbox->guest_heap = - pci_iomap_range(vbox->dev->pdev, 0, GUEST_HEAP_OFFSET(vbox), + pci_iomap_range(vbox->ddev.pdev, 0, GUEST_HEAP_OFFSET(vbox), GUEST_HEAP_SIZE); if (!vbox->guest_heap) return -ENOMEM; @@ -322,7 +294,7 @@ static int vbox_hw_init(struct vbox_private *vbox) goto err_destroy_guest_pool; } - vbox->last_mode_hints = devm_kcalloc(vbox->dev->dev, vbox->num_crtcs, + vbox->last_mode_hints = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs, sizeof(struct vbva_modehint), GFP_KERNEL); if (!vbox->last_mode_hints) { @@ -339,102 +311,18 @@ static int vbox_hw_init(struct vbox_private *vbox) err_destroy_guest_pool: gen_pool_destroy(vbox->guest_pool); err_unmap_guest_heap: - pci_iounmap(vbox->dev->pdev, vbox->guest_heap); + pci_iounmap(vbox->ddev.pdev, vbox->guest_heap); return ret; } -static void vbox_hw_fini(struct vbox_private *vbox) +void vbox_hw_fini(struct vbox_private *vbox) { vbox_accel_fini(vbox); gen_pool_destroy(vbox->guest_pool); - pci_iounmap(vbox->dev->pdev, vbox->guest_heap); -} - -int vbox_driver_load(struct drm_device *dev) -{ - struct vbox_private *vbox; - int ret = 0; - - if (!vbox_check_supported(VBE_DISPI_ID_HGSMI)) - return -ENODEV; - - vbox = devm_kzalloc(dev->dev, sizeof(*vbox), GFP_KERNEL); - if (!vbox) - return -ENOMEM; - - dev->dev_private = vbox; - vbox->dev = dev; - - mutex_init(&vbox->hw_mutex); - - ret = vbox_hw_init(vbox); - if (ret) - return ret; - - ret = vbox_mm_init(vbox); - if (ret) - goto err_hw_fini; - - drm_mode_config_init(dev); - - dev->mode_config.funcs = (void *)&vbox_mode_funcs; - dev->mode_config.min_width = 64; - dev->mode_config.min_height = 64; - dev->mode_config.preferred_depth = 24; - dev->mode_config.max_width = VBE_DISPI_MAX_XRES; - dev->mode_config.max_height = VBE_DISPI_MAX_YRES; - - ret = vbox_mode_init(dev); - if (ret) - goto err_drm_mode_cleanup; - - ret = vbox_irq_init(vbox); - if (ret) - goto err_mode_fini; - - ret = vbox_fbdev_init(dev); - if (ret) - goto err_irq_fini; - - return 0; - -err_irq_fini: - vbox_irq_fini(vbox); -err_mode_fini: - vbox_mode_fini(dev); -err_drm_mode_cleanup: - drm_mode_config_cleanup(dev); - vbox_mm_fini(vbox); -err_hw_fini: - vbox_hw_fini(vbox); - return ret; -} - -void vbox_driver_unload(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; - - vbox_fbdev_fini(dev); - vbox_irq_fini(vbox); - vbox_mode_fini(dev); - drm_mode_config_cleanup(dev); - vbox_mm_fini(vbox); - vbox_hw_fini(vbox); + pci_iounmap(vbox->ddev.pdev, vbox->guest_heap); } -/** - * @note this is described in the DRM framework documentation. AST does not - * have it, but we get an oops on driver unload if it is not present. - */ -void vbox_driver_lastclose(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; - - if (vbox->fbdev) - drm_fb_helper_restore_fbdev_mode_unlocked(&vbox->fbdev->helper); -} - -int vbox_gem_create(struct drm_device *dev, +int vbox_gem_create(struct vbox_private *vbox, u32 size, bool iskernel, struct drm_gem_object **obj) { struct vbox_bo *vboxbo; @@ -446,7 +334,7 @@ int vbox_gem_create(struct drm_device *dev, if (size == 0) return -EINVAL; - ret = vbox_bo_create(dev, size, 0, 0, &vboxbo); + ret = vbox_bo_create(vbox, size, 0, 0, &vboxbo); if (ret) { if (ret != -ERESTARTSYS) DRM_ERROR("failed to allocate GEM object\n"); @@ -461,14 +349,16 @@ int vbox_gem_create(struct drm_device *dev, int vbox_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { - int ret; + struct vbox_private *vbox = + container_of(dev, struct vbox_private, ddev); struct drm_gem_object *gobj; u32 handle; + int ret; args->pitch = args->width * ((args->bpp + 7) / 8); args->size = args->pitch * args->height; - ret = vbox_gem_create(dev, args->size, false, &gobj); + ret = vbox_gem_create(vbox, args->size, false, &gobj); if (ret) return ret; @@ -482,24 +372,11 @@ int vbox_dumb_create(struct drm_file *file, return 0; } -static void vbox_bo_unref(struct vbox_bo **bo) -{ - struct ttm_buffer_object *tbo; - - if ((*bo) == NULL) - return; - - tbo = &((*bo)->bo); - ttm_bo_unref(&tbo); - if (!tbo) - *bo = NULL; -} - void vbox_gem_free_object(struct drm_gem_object *obj) { struct vbox_bo *vbox_bo = gem_to_vbox_bo(obj); - vbox_bo_unref(&vbox_bo); + ttm_bo_put(&vbox_bo->bo); } static inline u64 vbox_bo_mmap_offset(struct vbox_bo *bo) diff --git |