/*1* Copyright 2012 Red Hat Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sub license, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR12* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,13* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL14* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,15* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR16* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE17* USE OR OTHER DEALINGS IN THE SOFTWARE.18*19* The above copyright notice and this permission notice (including the20* next paragraph) shall be included in all copies or substantial portions21* of the Software.22*23*/24/*25* Authors: Dave Airlie <[email protected]>26*/2728#include <linux/pci.h>2930#include <drm/drm_managed.h>31#include <drm/drm_print.h>3233#include "ast_drv.h"3435static u32 ast_get_vram_size(struct ast_device *ast)36{37u32 vram_size;38u8 vgacr99, vgacraa;3940vgacraa = ast_get_index_reg(ast, AST_IO_VGACRI, 0xaa);41switch (vgacraa & AST_IO_VGACRAA_VGAMEM_SIZE_MASK) {42case 0:43vram_size = SZ_8M;44break;45case 1:46vram_size = SZ_16M;47break;48case 2:49vram_size = SZ_32M;50break;51case 3:52vram_size = SZ_64M;53break;54}5556vgacr99 = ast_get_index_reg(ast, AST_IO_VGACRI, 0x99);57switch (vgacr99 & AST_IO_VGACR99_VGAMEM_RSRV_MASK) {58case 1:59vram_size -= SZ_1M;60break;61case 2:62vram_size -= SZ_2M;63break;64case 3:65vram_size -= SZ_4M;66break;67}6869return vram_size;70}7172int ast_mm_init(struct ast_device *ast)73{74struct drm_device *dev = &ast->base;75struct pci_dev *pdev = to_pci_dev(dev->dev);76resource_size_t base, size;77u32 vram_size;7879base = pci_resource_start(pdev, 0);80size = pci_resource_len(pdev, 0);8182/* Don't fail on errors, but performance might be reduced. */83devm_arch_io_reserve_memtype_wc(dev->dev, base, size);84devm_arch_phys_wc_add(dev->dev, base, size);8586vram_size = ast_get_vram_size(ast);8788ast->vram = devm_ioremap_wc(dev->dev, base, vram_size);89if (!ast->vram)90return -ENOMEM;9192ast->vram_base = base;93ast->vram_size = vram_size;9495return 0;96}979899