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 	int ret;
16 	struct drm_device *dev = &vbox->ddev;
17 	struct pci_dev *pdev = to_pci_dev(dev->dev);
18 
19 	ret = drmm_vram_helper_init(dev, pci_resource_start(pdev, 0),
20 				       vbox->available_vram_size);
21 	if (ret) {
22 		DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
23 		return ret;
24 	}
25 
26 	vbox->fb_mtrr = arch_phys_wc_add(pci_resource_start(pdev, 0),
27 					 pci_resource_len(pdev, 0));
28 	return 0;
29 }
30 
31 void vbox_mm_fini(struct vbox_private *vbox)
32 {
33 	arch_phys_wc_del(vbox->fb_mtrr);
34 }
35