[coreboot] intel-debugtools #1.ich_gpio

joe at smittys.pointclark.net joe at smittys.pointclark.net
Thu Feb 21 00:03:03 CET 2008


>> As Ron said "btw, this type of tool is incredibly useful, as you doubtless
>> know". I think we should mofify it for all the ICH's and add it to the
>> utils or at least a wiki page maybe?
>
> I think that's a good plan. It should print at least the name of the
> probed registers though to be a real "dump tool". It was merely a quick
> attempt to find out how to set up the GPIOs so that serial console would
> finally work and no other bad surprises jump in until we can verify with
> the board schematics.
>
> I have another one of those for the "MCHBAR" of the i945. Maybe we
> should make this "intel-debugtools" or something?
>
Looks like the only difference between all the ICH's is that ICH to ICH5
use 0x58 for the GPIO Base Address and ICH6 and up use 0x48 for the  
GPIO Base Address. So I modded the program with a simple if statement  
on the device id's.
This should work on all the ICH series. Check it out, and let me know  
what you think? Add it to the utils?


Thanks - Joe
-------------- next part --------------
/*
 * dump gpio on intel ICH series southbridges
 *
 * Copyright (C) 2008 by coresystems GmbH 
 * written by Stefan Reinauer <stepan at coresystems.de> 
 * modded for all ICH's by Joseph Smith <joe at smittys.pointclark.net>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <getopt.h>

#include <sys/io.h>
#include <pci/pci.h>

int map_gpio(uint16_t gpio)
{
	int i;
	unsigned long size=0x40;

	for (i=0; i<size; i+=4) {
		printf("gpiobase+0x%04x: 0x%08x\n", i, inl(gpio+i));
	}

	return 0;
}

int main(int argc, char *argv[])
{
	struct pci_access *pacc;
	struct pci_dev *sb;
	uint16_t gpiobadd;
	uint16_t device;

	if (iopl(3)) { printf("You need to be root.\n"); exit(1); }

	pacc = pci_alloc();
	pci_init(pacc);
	pci_scan_bus(pacc);

	sb = pci_get_dev(pacc, 0, 0, 0x1f, 0);
	if (!sb) {
		printf("No southbridge found.\n");
		pci_cleanup(pacc);
		exit(1);
	}

	if (pci_read_word(sb, 0) != 0x8086) {
		printf("Not an Intel southbridge.\n");
		
		pci_free_dev(sb);
		pci_cleanup(pacc);
		exit(1);
	}

	printf("Intel Southbridge: %04x:%04x\n", 
		pci_read_word(sb, 0), pci_read_word(sb, 2));

	device = pci_read_word(sb, 2);

	if (device < 0x2640) {
		gpiobadd = pci_read_word(sb, 0x58) & 0xfffc; 
	} else if (device > 0x2640) {
		gpiobadd = pci_read_word(sb, 0x48) & 0xfffc;
	}
	printf("GPIOBASE = 0x%04x\n\n", gpiobadd);

	pci_free_dev(sb);
	pci_cleanup(pacc);

	map_gpio(gpiobadd);


	return 0;
}
-------------- next part --------------
#
# Makefile for ich_gpio utility
# 
# (C) 2008 by coresystems GmbH
# written by Stefan Reinauer <stepan at coresystems.de>
# modded for all ICH's by Joseph Smith <joe at smittys.pointclark.net>
#

PROGRAM = ich_gpio

CC      = gcc
STRIP	= strip
INSTALL = /usr/bin/install
PREFIX  = /usr/local
CFLAGS  = -O2 -g -Wall -Werror
OS_ARCH	= $(shell uname)
ifeq ($(OS_ARCH), SunOS)
LDFLAGS = -lpci -lz
else
LDFLAGS = -lpci -lz -static 
STRIP_ARGS = -s
endif

OBJS = ich_gpio.o

all: pciutils dep $(PROGRAM)

$(PROGRAM): $(OBJS)
	$(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
	$(STRIP) $(STRIP_ARGS) $(PROGRAM)

clean:
	rm -f *.o *~

distclean: clean
	rm -f $(PROGRAM) .dependencies
	
dep:
	@$(CC) -MM *.c > .dependencies

pciutils:
	@echo; echo -n "Checking for pciutils and zlib... "
	@$(shell ( echo "#include <pci/pci.h>";		   \
		   echo "struct pci_access *pacc;";	   \
		   echo "int main(int argc, char **argv)"; \
		   echo "{ pacc = pci_alloc(); return 0; }"; ) > .test.c )
	@$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) &>/dev/null &&	\
		echo "found." || ( echo "not found."; echo;		\
		echo "Please install pciutils-devel and zlib-devel.";	\
		echo "See README for more information."; echo;		\
		rm -f .test.c .test; exit 1)
	@rm -f .test.c .test

install: $(PROGRAM)
	$(INSTALL) $(PROGRAM) $(PREFIX)/sbin
	mkdir -p $(PREFIX)/share/man/man8
	$(INSTALL) $(PROGRAM).8 $(PREFIX)/share/man/man8

.PHONY: all clean distclean dep pciutils

-include .dependencies



More information about the coreboot mailing list