Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the
0006  * "Software"), to deal in the Software without restriction, including
0007  * without limitation the rights to use, copy, modify, merge, publish,
0008  * distribute, sub license, and/or sell copies of the Software, and to
0009  * permit persons to whom the Software is furnished to do so, subject to
0010  * the following conditions:
0011  *
0012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0013  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0014  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0015  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0017  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0018  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0019  *
0020  * The above copyright notice and this permission notice (including the
0021  * next paragraph) shall be included in all copies or substantial portions
0022  * of the Software.
0023  *
0024  */
0025 /*
0026  * Authors: Dave Airlie <airlied@redhat.com>
0027  */
0028 
0029 #include <linux/pci.h>
0030 
0031 #include <drm/drm_gem_vram_helper.h>
0032 #include <drm/drm_managed.h>
0033 #include <drm/drm_print.h>
0034 
0035 #include "ast_drv.h"
0036 
0037 static u32 ast_get_vram_size(struct ast_private *ast)
0038 {
0039     u8 jreg;
0040     u32 vram_size;
0041 
0042     ast_open_key(ast);
0043 
0044     vram_size = AST_VIDMEM_DEFAULT_SIZE;
0045     jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xaa, 0xff);
0046     switch (jreg & 3) {
0047     case 0:
0048         vram_size = AST_VIDMEM_SIZE_8M;
0049         break;
0050     case 1:
0051         vram_size = AST_VIDMEM_SIZE_16M;
0052         break;
0053     case 2:
0054         vram_size = AST_VIDMEM_SIZE_32M;
0055         break;
0056     case 3:
0057         vram_size = AST_VIDMEM_SIZE_64M;
0058         break;
0059     }
0060 
0061     jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x99, 0xff);
0062     switch (jreg & 0x03) {
0063     case 1:
0064         vram_size -= 0x100000;
0065         break;
0066     case 2:
0067         vram_size -= 0x200000;
0068         break;
0069     case 3:
0070         vram_size -= 0x400000;
0071         break;
0072     }
0073 
0074     return vram_size;
0075 }
0076 
0077 int ast_mm_init(struct ast_private *ast)
0078 {
0079     struct drm_device *dev = &ast->base;
0080     struct pci_dev *pdev = to_pci_dev(dev->dev);
0081     resource_size_t base, size;
0082     u32 vram_size;
0083     int ret;
0084 
0085     base = pci_resource_start(pdev, 0);
0086     size = pci_resource_len(pdev, 0);
0087 
0088     /* Don't fail on errors, but performance might be reduced. */
0089     devm_arch_io_reserve_memtype_wc(dev->dev, base, size);
0090     devm_arch_phys_wc_add(dev->dev, base, size);
0091 
0092     vram_size = ast_get_vram_size(ast);
0093 
0094     ret = drmm_vram_helper_init(dev, base, vram_size);
0095     if (ret) {
0096         drm_err(dev, "Error initializing VRAM MM; %d\n", ret);
0097         return ret;
0098     }
0099 
0100     return 0;
0101 }