coreboot-v3/northbridge/amd/k8/util.c
<<
>>
Prefs
   1/*
   2 * This file is part of the coreboot project.
   3 *
   4 * Copyright (C) 2008 Vincent Legoll <vincent.legoll@gmail.com>
   5 * Copyright (C) 2008 Ronald G. Minnich <rminnich@gmail.com>
   6 * 
   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.
  10 *
  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.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, write to the Free Software
  18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
  19 */
  20
  21/*
  22 * K8 northbridge utilities (dump routing registers).
  23 * Designed to be called at any time.
  24 */
  25
  26#include <mainboard.h>
  27#include <console.h>
  28#include <string.h>
  29#include <mtrr.h>
  30#include <macros.h>
  31#include <spd_ddr2.h>
  32#include <cpu.h>
  33#include <msr.h>
  34#include <amd/k8/k8.h>
  35#include <amd/k8/sysconf.h>
  36#include <device/pci.h>
  37#include <pci_ops.h>
  38#include <mc146818rtc.h>
  39#include <lib.h>
  40
  41#define BITS(r, shift, mask) (((r>>shift)&mask))
  42
  43/**
  44 * Return "R" if the register has read-enable bit set.
  45 */
  46static char *re(u32 i)
  47{
  48        return ((i & 1) ? "R" : "");
  49}
  50
  51/**
  52 * Return "W" if the register has read-enable bit set.
  53 * TODO: Shouldn't this be "write-enable"?
  54 */
  55static char *we(u32 i)
  56{
  57        return ((i & 1) ? "W" : "");
  58}
  59
  60/**
  61 * Return a string containing the interleave settings.
  62 */
  63static char *ileave(u32 base)
  64{
  65        /* TODO: Are these fallthroughs intentional? */
  66        switch ((base >> 8) & 7) {
  67        case 0:
  68                return "No interleave";
  69        case 1:
  70                return "2 nodes";
  71        case 3:
  72                return "4 nodes";
  73        case 7:
  74                return "8 nodes";
  75        default:
  76                return "Reserved";
  77        }
  78}
  79
  80/**
  81 * Return the node number.
  82 * For one case (config registers) these are not the right bit fields.
  83 */
  84static int node(u32 reg)
  85{
  86        return BITS(reg, 0, 0x7);
  87}
  88
  89/**
  90 * Return the link number.
  91 * For one case (config registers) these are not the right bit fields.
  92 */
  93static int link(u32 reg)
  94{
  95        return BITS(reg, 4, 0x3);
  96}
  97
  98/**
  99 * Print the DRAM routing info for one base/limit pair.
 100 *
 101 * Show base, limit, dest node, dest link on that node, read and write
 102 * enable, and interleave information.
 103 *
 104 * @param level Printing level
 105 * @param which Register number
 106 * @param base Base register
 107 * @param lim Limit register
 108 */
 109void showdram(int level, u8 which, u32 base, u32 lim)
 110{
 111        printk(level, "DRAM(%02x)%010llx-%010llx, ->(%d), %s, %s, %s, %d\n",
 112               which, (((u64) base & 0xffff0000) << 8),
 113               (((u64) lim & 0xffff0000) << 8) + 0xffffff,
 114               node(lim), re(base), we(base), ileave(base), (lim >> 8) & 3);
 115}
 116
 117/**
 118 * Print the config routing info for a config register.
 119 *
 120 * Show base, limit, dest node, dest link on that node, read and write
 121 * enable, and device number compare enable
 122 *
 123 * @param level Printing level
 124 * @param which Register number
 125 * @param reg Config register
 126 */
 127void showconfig(int level, u8 which, u32 reg)
 128{
 129        /* Don't use node() and link() here. */
 130        printk(level, "CONFIG(%02x)%02x-%02x ->(%d,%d),%s %s (%s numbers)\n",
 131               which, BITS(reg, 16, 0xff), BITS(reg, 24, 0xff),
 132               BITS(reg, 4, 0x7), BITS(reg, 8, 0x3),
 133               re(reg), we(reg), 
 134               BITS(reg, 2, 0x1)?"dev":"bus");
 135}
 136
 137/**
 138 * Print the PCIIO routing info for one base/limit pair.
 139 *
 140 * Show base, limit, dest node, dest link on that node, read and write
 141 * enable, and VGA and ISA Enable.
 142 *
 143 * @param level Printing level
 144 * @param which Register number
 145 * @param base Base register
 146 * @param lim Limit register
 147 */
 148void showpciio(int level, u8 which, u32 base, u32 lim)
 149{
 150        printk(level, "PCIIO(%02x)%07x-%07x, ->(%d,%d), %s, %s,VGA %d ISA %d\n",
 151               which, BITS(base, 12, 0x3fff) << 12,
 152               (BITS(lim, 12, 0x3fff) << 12) + 0xfff, node(lim), link(lim),
 153               re(base), we(base), BITS(base, 4, 0x1), BITS(base, 5, 0x1));
 154}
 155
 156/**
 157 * Print the MMIO routing info for one base/limit pair.
 158 *
 159 * Show base, limit, dest node, dest link on that node, read and write
 160 * enable, and CPU Disable, Lock, and Non-posted.
 161 *
 162 * @param level Printing level
 163 * @param which Register number
 164 * @param base Base register
 165 * @param lim Limit register
 166 */
 167void showmmio(int level, u8 which, u32 base, u32 lim)
 168{
 169        printk(level, "MMIO(%02x)%010llx-%010llx, ->(%d,%d), %s, %s, "
 170               "CPU disable %d, Lock %d, Non posted %d\n",
 171               which, ((u64) BITS(base, 0, 0xffffff00)) << 8,
 172               (((u64) BITS(lim, 0, 0xffffff00)) << 8) + 0xffff, node(lim),
 173               link(lim), re(base), we(base), BITS(base, 4, 0x1),
 174               BITS(base, 7, 0x1), BITS(lim, 7, 0x1));
 175}
 176
 177/**
 178 * Show all DRAM routing registers. This function is callable at any time.
 179 *
 180 * @param level The debug level.
 181 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
 182 *            raw config space.
 183 */
 184void showalldram(int level, u32 dev)
 185{
 186        u8 reg;
 187        for (reg = DRAM_ROUTE_START; reg <= DRAM_ROUTE_END; reg += 8) {
 188                u32 base = pci_conf1_read_config32(dev, reg);
 189                u32 lim = pci_conf1_read_config32(dev, reg + 4);
 190                showdram(level, reg, base, lim);
 191        }
 192}
 193
 194/**
 195 * Show all MMIO routing registers. This function is callable at any time.
 196 *
 197 * @param level The debug level.
 198 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
 199 *            raw config space.
 200 */
 201void showallmmio(int level, u32 dev)
 202{
 203        u8 reg;
 204        for (reg = MMIO_ROUTE_START; reg <= MMIO_ROUTE_END; reg += 8) {
 205                u32 base = pci_conf1_read_config32(dev, reg);
 206                u32 lim = pci_conf1_read_config32(dev, reg + 4);
 207                showmmio(level, reg, base, lim);
 208        }
 209}
 210
 211/**
 212 * Show all PCIIO routing registers. This function is callable at any time.
 213 *
 214 * @param level The debug level.
 215 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
 216 *            raw config space.
 217 */
 218void showallpciio(int level, u32 dev)
 219{
 220        u8 reg;
 221        for (reg = PCIIO_ROUTE_START; reg <= PCIIO_ROUTE_END; reg += 8) {
 222                u32 base = pci_conf1_read_config32(dev, reg);
 223                u32 lim = pci_conf1_read_config32(dev, reg + 4);
 224                showpciio(level, reg, base, lim);
 225        }
 226}
 227
 228/**
 229 * Show all config routing registers. This function is callable at any time.
 230 *
 231 * @param level The debug level.
 232 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
 233 *            raw config space.
 234 */
 235void showallconfig(int level, u32 dev)
 236{
 237        u8 reg;
 238        for (reg = CONFIG_ROUTE_START; reg <= CONFIG_ROUTE_END; reg += 4) {
 239                u32 val = pci_conf1_read_config32(dev, reg);
 240                showconfig(level, reg, val);
 241        }
 242}
 243
 244/**
 245 * Show all routing registers. This function is callable at any time.
 246 *
 247 * @param level The debug level.
 248 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
 249 *            raw config space.
 250 */
 251void showallroutes(int level, u32 dev)
 252{
 253        showalldram(level, dev);
 254        showallmmio(level, dev);
 255        showallpciio(level, dev);
 256        showallconfig(level, dev);
 257}
 258
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.