xref: /linux/drivers/gpu/drm/vboxvideo/vbox_ttm.c (revision b470ebc9e0e57f53d1db9c49b8a3de4086babd05)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright (C) 2013-2017 Oracle Corporation
4  * This file is based on ast_ttm.c
5  * Copyright 2012 Red Hat Inc.
6  * Authors: Dave Airlie <airlied@redhat.com>
7  *          Michael Thayer <michael.thayer@oracle.com>
8  */
9 #include <linux/pci.h>
10 #include <drm/drm_file.h>
11 #include "vbox_drv.h"
12 
13 int vbox_mm_init(struct vbox_private *vbox)
14 {
15 	struct drm_vram_mm *vmm;
16 	int ret;
17 	struct drm_device *dev = &vbox->ddev;
18 	struct pci_dev *pdev = to_pci_dev(dev->dev);
19 
20 	vmm = drm_vram_helper_alloc_mm(dev, pci_resource_start(pdev, 0),
21 				       vbox->available_vram_size);
22 	if (IS_ERR(vmm)) {
23 		ret = PTR_ERR(vmm);
24 		DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
25 		return ret;
26 	}
27 
28 	vbox->fb_mtrr = arch_phys_wc_add(pci_resource_start(pdev, 0),
29 					 pci_resource_len(pdev, 0));
30 	return 0;
31 }
32 
33 void vbox_mm_fini(struct vbox_private *vbox)
34 {
35 	arch_phys_wc_del(vbox->fb_mtrr);
36 	drm_vram_helper_release_mm(&vbox->ddev);
37 }
38