1fa225cbcSrjs/* 2fa225cbcSrjs * Copyright © 2008 Intel Corporation 3fa225cbcSrjs * 4fa225cbcSrjs * Permission is hereby granted, free of charge, to any person obtaining a 5fa225cbcSrjs * copy of this software and associated documentation files (the "Software"), 6fa225cbcSrjs * to deal in the Software without restriction, including without limitation 7fa225cbcSrjs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8fa225cbcSrjs * and/or sell copies of the Software, and to permit persons to whom the 9fa225cbcSrjs * Software is furnished to do so, subject to the following conditions: 10fa225cbcSrjs * 11fa225cbcSrjs * The above copyright notice and this permission notice (including the next 12fa225cbcSrjs * paragraph) shall be included in all copies or substantial portions of the 13fa225cbcSrjs * Software. 14fa225cbcSrjs * 15fa225cbcSrjs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16fa225cbcSrjs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17fa225cbcSrjs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18fa225cbcSrjs * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19fa225cbcSrjs * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20fa225cbcSrjs * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21fa225cbcSrjs * DEALINGS IN THE SOFTWARE. 22fa225cbcSrjs * 23fa225cbcSrjs * Authors: 24fa225cbcSrjs * Eric Anholt <eric@anholt.net> 25fa225cbcSrjs * 26fa225cbcSrjs */ 27fa225cbcSrjs 28fa225cbcSrjs#include <stdio.h> 29fa225cbcSrjs#include <stdlib.h> 30fa225cbcSrjs#include <string.h> 31fa225cbcSrjs#include <stdarg.h> 32fa225cbcSrjs#include <pciaccess.h> 33fa225cbcSrjs#include <err.h> 34fa225cbcSrjs#include <unistd.h> 35fa225cbcSrjs 36fa225cbcSrjs#include "reg_dumper.h" 37fa225cbcSrjs#include "../i810_reg.h" 38fa225cbcSrjs 39fa225cbcSrjs#define INGTT(offset) (*(volatile uint32_t *)(gtt + (offset) / (KB(4) / 4))) 40fa225cbcSrjs 41fa225cbcSrjsint main(int argc, char **argv) 42fa225cbcSrjs{ 43fa225cbcSrjs I830Rec i830; 44fa225cbcSrjs I830Ptr pI830 = &i830; 45fa225cbcSrjs int start, aper_size; 46fa225cbcSrjs unsigned char *gtt; 47fa225cbcSrjs 48fa225cbcSrjs intel_i830rec_init(pI830); 49fa225cbcSrjs 50fa225cbcSrjs if (!IS_I9XX(pI830)) { 51fa225cbcSrjs printf("Unsupported chipset for gtt dumper\n"); 52fa225cbcSrjs exit(1); 53fa225cbcSrjs } 54fa225cbcSrjs 55fa225cbcSrjs if (IS_G4X(pI830) || IS_IGDNG(pI830)) 56fa225cbcSrjs gtt = (unsigned char *)(pI830->mmio + MB(2)); 57fa225cbcSrjs else if (IS_I965G(pI830)) 58fa225cbcSrjs gtt = (unsigned char *)(pI830->mmio + KB(512)); 59fa225cbcSrjs else { 60fa225cbcSrjs /* 915/945 chips has GTT range in bar 3*/ 61fa225cbcSrjs int err = 0; 62fa225cbcSrjs err = pci_device_map_range (pI830->PciInfo, 63fa225cbcSrjs pI830->PciInfo->regions[3].base_addr, 64fa225cbcSrjs pI830->PciInfo->regions[3].size, 65fa225cbcSrjs PCI_DEV_MAP_FLAG_WRITABLE, 66fa225cbcSrjs (void **)>t); 67fa225cbcSrjs if (err != 0) { 68fa225cbcSrjs fprintf(stderr, "mapping GTT bar failed\n"); 69fa225cbcSrjs exit(1); 70fa225cbcSrjs } 71fa225cbcSrjs } 72fa225cbcSrjs 73fa225cbcSrjs aper_size = pI830->PciInfo->regions[2].size; 74fa225cbcSrjs 75fa225cbcSrjs for (start = 0; start < aper_size; start += KB(4)) { 76fa225cbcSrjs uint32_t start_pte = INGTT(start); 77fa225cbcSrjs uint32_t end; 78fa225cbcSrjs int constant_length = 0; 79fa225cbcSrjs int linear_length = 0; 80fa225cbcSrjs 81fa225cbcSrjs /* Check if it's a linear sequence */ 82fa225cbcSrjs for (end = start + KB(4); end < aper_size; end += KB(4)) { 83fa225cbcSrjs uint32_t end_pte = INGTT(end); 84fa225cbcSrjs if (end_pte == start_pte + (end - start)) 85fa225cbcSrjs linear_length++; 86fa225cbcSrjs else 87fa225cbcSrjs break; 88fa225cbcSrjs } 89fa225cbcSrjs if (linear_length > 0) { 90fa225cbcSrjs printf("0x%08x - 0x%08x: linear from " 91fa225cbcSrjs "0x%08x to 0x%08x\n", 92fa225cbcSrjs start, end - KB(4), 93fa225cbcSrjs start_pte, start_pte + (end - start) - KB(4)); 94fa225cbcSrjs start = end - KB(4); 95fa225cbcSrjs continue; 96fa225cbcSrjs } 97fa225cbcSrjs 98fa225cbcSrjs /* Check if it's a constant sequence */ 99fa225cbcSrjs for (end = start + KB(4); end < aper_size; end += KB(4)) { 100fa225cbcSrjs uint32_t end_pte = INGTT(end); 101fa225cbcSrjs if (end_pte == start_pte) 102fa225cbcSrjs constant_length++; 103fa225cbcSrjs else 104fa225cbcSrjs break; 105fa225cbcSrjs } 106fa225cbcSrjs if (constant_length > 0) { 107fa225cbcSrjs printf("0x%08x - 0x%08x: constant 0x%08x\n", 108fa225cbcSrjs start, end - KB(4), 109fa225cbcSrjs start_pte); 110fa225cbcSrjs start = end - KB(4); 111fa225cbcSrjs continue; 112fa225cbcSrjs } 113fa225cbcSrjs 114fa225cbcSrjs printf("0x%08x: 0x%08x\n", start, start_pte); 115fa225cbcSrjs } 116fa225cbcSrjs 117fa225cbcSrjs return 0; 118fa225cbcSrjs} 119