2018-10-18 22:03:32 +07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-07-06 21:06:01 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2017 Oracle Corporation
|
|
|
|
* This file is based on ast_ttm.c
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
* Authors: Dave Airlie <airlied@redhat.com>
|
|
|
|
* Michael Thayer <michael.thayer@oracle.com>
|
|
|
|
*/
|
2018-10-22 21:57:45 +07:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <drm/drm_file.h>
|
2017-07-06 21:06:01 +07:00
|
|
|
#include "vbox_drv.h"
|
|
|
|
|
|
|
|
int vbox_mm_init(struct vbox_private *vbox)
|
|
|
|
{
|
2019-05-08 15:26:28 +07:00
|
|
|
struct drm_vram_mm *vmm;
|
2017-07-06 21:06:01 +07:00
|
|
|
int ret;
|
2018-09-19 00:44:30 +07:00
|
|
|
struct drm_device *dev = &vbox->ddev;
|
2017-07-06 21:06:01 +07:00
|
|
|
|
2019-05-08 15:26:28 +07:00
|
|
|
vmm = drm_vram_helper_alloc_mm(dev, pci_resource_start(dev->pdev, 0),
|
|
|
|
vbox->available_vram_size,
|
|
|
|
&drm_gem_vram_mm_funcs);
|
|
|
|
if (IS_ERR(vmm)) {
|
|
|
|
ret = PTR_ERR(vmm);
|
|
|
|
DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
|
2018-10-19 21:55:26 +07:00
|
|
|
return ret;
|
2017-07-06 21:06:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DRM_MTRR_WC
|
|
|
|
vbox->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 0),
|
|
|
|
pci_resource_len(dev->pdev, 0),
|
|
|
|
DRM_MTRR_WC);
|
|
|
|
#else
|
|
|
|
vbox->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
|
|
|
|
pci_resource_len(dev->pdev, 0));
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vbox_mm_fini(struct vbox_private *vbox)
|
|
|
|
{
|
|
|
|
#ifdef DRM_MTRR_WC
|
|
|
|
drm_mtrr_del(vbox->fb_mtrr,
|
2018-09-19 00:44:30 +07:00
|
|
|
pci_resource_start(vbox->ddev.pdev, 0),
|
|
|
|
pci_resource_len(vbox->ddev.pdev, 0), DRM_MTRR_WC);
|
2017-07-06 21:06:01 +07:00
|
|
|
#else
|
|
|
|
arch_phys_wc_del(vbox->fb_mtrr);
|
|
|
|
#endif
|
2019-05-08 15:26:28 +07:00
|
|
|
drm_vram_helper_release_mm(&vbox->ddev);
|
2017-07-06 21:06:01 +07:00
|
|
|
}
|