1 /* $NetBSD: ast_ttm.c,v 1.3 2021/12/18 23:45:27 riastradh Exp $ */
2
3 /*
4 * Copyright 2012 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 */
27 /*
28 * Authors: Dave Airlie <airlied@redhat.com>
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: ast_ttm.c,v 1.3 2021/12/18 23:45:27 riastradh Exp $");
33
34 #include <linux/pci.h>
35
36 #include <drm/drm_print.h>
37 #include <drm/drm_gem_vram_helper.h>
38
39 #include "ast_drv.h"
40
ast_mm_init(struct ast_private * ast)41 int ast_mm_init(struct ast_private *ast)
42 {
43 struct drm_vram_mm *vmm;
44 int ret;
45 struct drm_device *dev = ast->dev;
46
47 vmm = drm_vram_helper_alloc_mm(
48 dev, pci_resource_start(dev->pdev, 0),
49 ast->vram_size);
50 if (IS_ERR(vmm)) {
51 ret = PTR_ERR(vmm);
52 DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
53 return ret;
54 }
55
56 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
57 pci_resource_len(dev->pdev, 0));
58 ast->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
59 pci_resource_len(dev->pdev, 0));
60
61 return 0;
62 }
63
ast_mm_fini(struct ast_private * ast)64 void ast_mm_fini(struct ast_private *ast)
65 {
66 struct drm_device *dev = ast->dev;
67
68 drm_vram_helper_release_mm(dev);
69
70 arch_phys_wc_del(ast->fb_mtrr);
71 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
72 pci_resource_len(dev->pdev, 0));
73 }
74