2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
29 #include <linux/pci.h>
31 #include <drm/drm_managed.h>
32 #include <drm/drm_print.h>
36 static u32 ast_get_vram_size(struct ast_device *ast)
41 vram_size = AST_VIDMEM_DEFAULT_SIZE;
42 jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xaa, 0xff);
45 vram_size = AST_VIDMEM_SIZE_8M;
48 vram_size = AST_VIDMEM_SIZE_16M;
51 vram_size = AST_VIDMEM_SIZE_32M;
54 vram_size = AST_VIDMEM_SIZE_64M;
58 jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0x99, 0xff);
59 switch (jreg & 0x03) {
61 vram_size -= 0x100000;
64 vram_size -= 0x200000;
67 vram_size -= 0x400000;
74 int ast_mm_init(struct ast_device *ast)
76 struct drm_device *dev = &ast->base;
77 struct pci_dev *pdev = to_pci_dev(dev->dev);
78 resource_size_t base, size;
81 base = pci_resource_start(pdev, 0);
82 size = pci_resource_len(pdev, 0);
84 /* Don't fail on errors, but performance might be reduced. */
85 devm_arch_io_reserve_memtype_wc(dev->dev, base, size);
86 devm_arch_phys_wc_add(dev->dev, base, size);
88 vram_size = ast_get_vram_size(ast);
90 ast->vram = devm_ioremap_wc(dev->dev, base, vram_size);
94 ast->vram_base = base;
95 ast->vram_size = vram_size;
96 ast->vram_fb_available = vram_size;