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