util/cbfstool: avoid memleaks and off-by-ones
[coreboot.git] / util / inteltool / gfx.c
blobffcf75c859857e2a6294732d253bcd229628feb0
1 /*
2 * inteltool - dump all registers on an Intel CPU + chipset based system.
4 * Copyright (C) 2008-2010 by coresystems GmbH
5 * Copyright (C) 2012 Anton Kochkov
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <inttypes.h>
20 #include "inteltool.h"
22 #define MMIO_SIZE 0x100000
24 int print_gfx(struct pci_dev *gfx)
26 uint64_t mmio_phys;
27 uint8_t *mmio;
28 uint32_t i;
29 if (!gfx) {
30 printf ("No IGD found\n");
31 return 0;
33 printf("\n============= IGD ==============\n\n");
34 mmio_phys = gfx->base_addr[0] & ~0x7ULL;
35 printf("IGD MMIO = 0x%08llx (MEM)\n\n", (unsigned long long)mmio_phys);
36 mmio = map_physical(mmio_phys, MMIO_SIZE);
37 if (mmio == NULL) {
38 perror("Error mapping MMIO");
39 exit(1);
41 for (i = 0; i < MMIO_SIZE; i += 4) {
42 if (*(uint32_t *)(mmio + i))
43 printf("0x%06x: 0x%08x\n", i, *(uint32_t *)(mmio + i));
45 unmap_physical((void *)mmio, MMIO_SIZE);
46 return 0;