Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * inteltool - dump all registers on an Intel CPU + chipset based system. |
| 3 | * |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 by coresystems GmbH |
| 5 | * |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
Stefan Reinauer | a7b296d | 2011-11-14 12:40:34 -0800 | [diff] [blame] | 23 | #include <inttypes.h> |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 24 | #include "inteltool.h" |
| 25 | |
| 26 | /* |
| 27 | * (G)MCH MMIO Config Space |
| 28 | */ |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 29 | int print_mchbar(struct pci_dev *nb, struct pci_access *pacc) |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 30 | { |
| 31 | int i, size = (16 * 1024); |
| 32 | volatile uint8_t *mchbar; |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 33 | uint64_t mchbar_phys; |
| 34 | struct pci_dev *nb_device6; /* "overflow device" on i865 */ |
| 35 | uint16_t pcicmd6; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 36 | |
| 37 | printf("\n============= MCHBAR ============\n\n"); |
| 38 | |
| 39 | switch (nb->device_id) { |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 40 | case PCI_DEVICE_ID_INTEL_82865: |
| 41 | /* |
| 42 | * On i865, the memory access enable/disable bit (MCHBAREN on |
| 43 | * i945/i965) is not in the MCHBAR (i945/i965) register but in |
| 44 | * the PCICMD6 register. BAR6 and PCICMD6 reside on device 6. |
| 45 | * |
| 46 | * The actual base address is in BAR6 on i865 where on |
| 47 | * i945/i965 the base address is in MCHBAR. |
| 48 | */ |
| 49 | nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0); /* Device 6 */ |
| 50 | mchbar_phys = pci_read_long(nb_device6, 0x10); /* BAR6 */ |
| 51 | pcicmd6 = pci_read_long(nb_device6, 0x04); /* PCICMD6 */ |
| 52 | |
| 53 | /* Try to enable Memory Access Enable (MAE). */ |
| 54 | if (!(pcicmd6 & (1 << 1))) { |
| 55 | printf("Access to BAR6 is currently disabled, " |
| 56 | "attempting to enable.\n"); |
| 57 | pci_write_long(nb_device6, 0x04, pcicmd6 | (1 << 1)); |
| 58 | if (pci_read_long(nb_device6, 0x04) & (1 << 1)) |
| 59 | printf("Enabled successfully.\n"); |
| 60 | else |
| 61 | printf("Enable FAILED!\n"); |
| 62 | } |
| 63 | mchbar_phys &= 0xfffff000; /* Bits 31:12 from BAR6 */ |
| 64 | break; |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame] | 65 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 66 | case PCI_DEVICE_ID_INTEL_82945GM: |
Björn Busse | 2d33dc4 | 2010-08-01 15:33:30 +0000 | [diff] [blame] | 67 | case PCI_DEVICE_ID_INTEL_82945GSE: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 68 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 69 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 70 | mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe; |
| 71 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 72 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 73 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 74 | case PCI_DEVICE_ID_INTEL_82G33: |
| 75 | case PCI_DEVICE_ID_INTEL_82Q33: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 76 | mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe; |
| 77 | mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 78 | break; |
Corey Osgood | 23d98c7 | 2010-07-29 19:25:31 +0000 | [diff] [blame] | 79 | case PCI_DEVICE_ID_INTEL_Q965: |
| 80 | case PCI_DEVICE_ID_INTEL_ATOM_DXXX: |
| 81 | case PCI_DEVICE_ID_INTEL_ATOM_NXXX: |
| 82 | mchbar_phys = pci_read_long(nb, 0x48); |
| 83 | |
| 84 | /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads. |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 85 | * If it isn't, try to set it. This may fail, because there is |
| 86 | * some bit that locks that bit, and isn't in the public |
Corey Osgood | 23d98c7 | 2010-07-29 19:25:31 +0000 | [diff] [blame] | 87 | * datasheets. |
| 88 | */ |
| 89 | |
| 90 | if(!(mchbar_phys & 1)) |
| 91 | { |
| 92 | printf("Access to the MCHBAR is currently disabled, "\ |
| 93 | "attempting to enable.\n"); |
| 94 | mchbar_phys |= 0x1; |
| 95 | pci_write_long(nb, 0x48, mchbar_phys); |
| 96 | if(pci_read_long(nb, 0x48) & 1) |
| 97 | printf("Enabled successfully.\n"); |
| 98 | else |
| 99 | printf("Enable FAILED!\n"); |
| 100 | } |
| 101 | mchbar_phys &= 0xfffffffe; |
| 102 | mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 103 | break; |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 104 | case PCI_DEVICE_ID_INTEL_82443LX: |
| 105 | case PCI_DEVICE_ID_INTEL_82443BX: |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 106 | case PCI_DEVICE_ID_INTEL_82810: |
Joseph Smith | e10757e | 2010-06-16 22:21:19 +0000 | [diff] [blame] | 107 | case PCI_DEVICE_ID_INTEL_82810E_MC: |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 108 | case PCI_DEVICE_ID_INTEL_82810DC: |
Stefan Reinauer | 0484481 | 2010-02-22 11:26:06 +0000 | [diff] [blame] | 109 | case PCI_DEVICE_ID_INTEL_82830M: |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 110 | printf("This northbridge does not have MCHBAR.\n"); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 111 | return 1; |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 112 | case PCI_DEVICE_ID_INTEL_GS45: |
Ruud Schramp | bb41f50 | 2011-04-04 07:53:19 +0200 | [diff] [blame] | 113 | case PCI_DEVICE_ID_INTEL_X44: |
| 114 | case PCI_DEVICE_ID_INTEL_32X0: |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 115 | mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe; |
| 116 | mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 117 | break; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 118 | default: |
| 119 | printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n"); |
| 120 | return 1; |
| 121 | } |
| 122 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 123 | mchbar = map_physical(mchbar_phys, size); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 124 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 125 | if (mchbar == NULL) { |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 126 | if (nb->device_id == PCI_DEVICE_ID_INTEL_82865) |
| 127 | perror("Error mapping BAR6"); |
| 128 | else |
| 129 | perror("Error mapping MCHBAR"); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 130 | exit(1); |
| 131 | } |
| 132 | |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 133 | if (nb->device_id == PCI_DEVICE_ID_INTEL_82865) |
Stefan Reinauer | a7b296d | 2011-11-14 12:40:34 -0800 | [diff] [blame] | 134 | printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys); |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 135 | else |
Stefan Reinauer | a7b296d | 2011-11-14 12:40:34 -0800 | [diff] [blame] | 136 | printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 137 | |
| 138 | for (i = 0; i < size; i += 4) { |
| 139 | if (*(uint32_t *)(mchbar + i)) |
| 140 | printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(mchbar+i)); |
| 141 | } |
| 142 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 143 | unmap_physical((void *)mchbar, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | |