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