Can I get feedback on this one? It's the lx irq understander. I'd like
to get this in so others can give it a try.
I want to finish this as I need to write an LX NB understander, in an
attempt to do a first-principals pass at 'what the hell is wrong with
the dbe62'.
Signed-off-by: Ronald G. Minnich <[EMAIL PROTECTED]>
ron
Index: util/lxirq/lxirq.c
===================================================================
--- util/lxirq/lxirq.c (revision 0)
+++ util/lxirq/lxirq.c (revision 0)
@@ -0,0 +1,252 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2000 Silicon Integrated System Corporation
+ * Copyright (C) 2004 Tyan Corp <[EMAIL PROTECTED]>
+ * Copyright (C) 2005-2007 coresystems GmbH
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <pci/pci.h>
+/* for iopl */
+#if defined (__sun) && (defined(__i386) || defined(__amd64))
+#include <strings.h>
+#include <sys/sysi86.h>
+#include <sys/psw.h>
+#include <asm/sunddi.h>
+#else
+#include <sys/io.h>
+#endif
+
+unsigned long long rdmsr(unsigned long msr)
+{
+ static int fd_msr = -1;
+ unsigned long long ll;
+
+ if (fd_msr < 0) {
+ fd_msr = open("/dev/cpu/0/msr", O_RDWR);
+ if (fd_msr < 0){
+ perror("open msr");
+ exit(1);
+ }
+ }
+
+ if (lseek(fd_msr, (off_t) msr, SEEK_SET) == -1) {
+ perror("lseek64");
+ printf("Cannot operate on MSR. Did you run 'modprobe msr'?\n");
+ exit(1);
+ }
+
+ if (read(fd_msr, &ll, sizeof(ll)) != sizeof(ll)) {
+ perror("read msr");
+ exit(1);
+ }
+ return ll;
+}
+
+/* from geode ... */
+#define VRC_MISCELLANEOUS 0x00 // Miscellaneous Class
+ #define PCI_INT_AB 0x09 // GPIO pins for INTA# and INTB#
+ #define PCI_INT_CD 0x0A // GPIO pins for INTC# and INTD#
+
+
+#define VRC_INDEX 0xAC1C // Index register
+#define VRC_DATA 0xAC1E // Data register
+#define VR_UNLOCK 0xFC53 // Virtual register unlock code
+ /*
+ * Read from a Virtual Register
+ * @param class_index The register index
+ * @return the 16-bit word of data
+ */
+static inline unsigned short vr_read(unsigned short class_index)
+{
+ unsigned short data;
+ outl(((unsigned long) VR_UNLOCK << 16) | class_index, VRC_INDEX);
+ data = inw(VRC_DATA);
+ return data;
+}
+
+unsigned long irqmap(void)
+{
+ unsigned long ret;
+ ret = vr_read((VRC_MISCELLANEOUS << 8) + PCI_INT_CD);
+ ret <<= 16;
+ ret |= vr_read((VRC_MISCELLANEOUS << 8) + PCI_INT_AB);
+ return ret;
+}
+
+struct pci_access *pacc; /* For board and chipset_enable */
+int verbose = 0;
+struct pci_dev *cs5536_find(void)
+{
+ struct pci_dev *temp;
+ struct pci_filter filter;
+
+ pci_filter_init(NULL, &filter);
+ filter.vendor = 0x1022;
+ filter.device = 0x2090;
+
+ for (temp = pacc->devices; temp; temp = temp->next)
+ if (pci_filter_match(&filter, temp))
+ return temp;
+
+ return NULL;
+}
+
+void usage(const char *name)
+{
+ printf("usage: %s\n", name);
+ exit(1);
+}
+
+void print_version(void)
+{
+ printf("flashrom r%s\n", LXIRQ_VERSION);
+}
+
+
+unsigned short gpiobar;
+struct pci_dev *cs5536;
+unsigned short fourd0;
+unsigned long e0map[4];
+unsigned long long oo23;
+unsigned long primary_mask;
+
+int level(int bit)
+{
+ return fourd0 & (1<<bit);
+}
+int atomicval(unsigned short reg, int bit)
+{
+ unsigned long val;
+ int bitval;
+ /* page 158 of the 5536 manual: on read, low 16 bits are the real value */
+ val = inl(gpiobar + reg);
+ bitval = val & (1<< bit);
+ return bitval;
+}
+char *irqnames[] = {"invalid", "A", "B", "C", "D"};
+void irq(int irqno, unsigned char gpiopin)
+{
+ int idx, map;
+ int ig;
+ printf("INT%s, GPIO pin %d;", irqnames[irqno], gpiopin);
+
+ printf("Input %s and %s,",
+ atomicval(0x20, gpiopin) ? "Enabled" : "Disabled",
+ atomicval(0x24, gpiopin) ? "Inverted" : "Not Inverted");
+ /* figure out which IG this is connected to. Take it >> 4 for index */
+ idx = gpiopin>>3;
+ map = e0map[idx] >> ((gpiopin & 7)*4);
+ map &= 0xf;
+ printf("%s:GPIO BIT %d,", map & 8 ? "PME":"Interrupt", map&7);
+ map &= 0x7;
+ ig = oo23 >> (map*4);
+ ig &= 0xf;
+ printf("IG %d,", ig);
+ printf("%s, ", primary_mask & (1 << ig) ? "Not masked" : "Masked");
+ printf("\n");
+
+}
+
+void errexit(char *msg)
+{
+ fprintf(stderr, "%s\n", msg);
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+ unsigned long introute;
+ unsigned long enable, invert;
+ int i;
+
+ if (argc != 1)
+ usage(argv[0]);
+
+ /* First get full io access */
+#if defined (__sun) && (defined(__i386) || defined(__amd64))
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
+#else
+ if (iopl(3) != 0) {
+#endif
+ fprintf(stderr, "ERROR: iopl failed: \"%s\"\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ pacc = pci_alloc();
+ pci_init(pacc);
+ pci_scan_bus(pacc);
+ cs5536 = cs5536_find();
+
+ if (! cs5536)
+ errexit("No cs5536 on this system\n");
+
+ /* Use GPIOBASE register to find where the GPIO is mapped. */
+ gpiobar = pci_read_word(cs5536, 0x14) & 0xfffc;
+ enable = inl(gpiobar + 0x20);
+ invert = inl(gpiobar + 0x24);
+ printf("input enable %08lx invert 0x%08lx\n", enable, invert);
+
+ introute = irqmap();
+ printf("irqmap from vr is %#lx\n", introute);
+
+ fourd0 = inb(0x4d1)<<8 | inb(0x4d0);
+ printf("4d1:4d0 %04x\n", fourd0);
+
+ printf("GPIOmap (e0 to e8): ");
+ for(i = 0; i < 0x10; i += 4) {
+ e0map[i/4] = inl(gpiobar + 0xe0 + i);
+ printf("%d/%08lx ", i, e0map[i]);
+ }
+ printf("\n");
+
+ for(i = 0; i < 32; i++){
+ unsigned char map;
+ unsigned int idx;
+ idx = i>>3;
+ map = e0map[idx] >> ((i & 7)*4);
+ map &= 0xf;
+ if (! map)
+ continue;
+ printf("GPIO%d: %s:IG %d\n", i, map & 8 ? "PME":"Interrupt", map&7);
+ }
+
+ oo23 = rdmsr(0x51400023);
+ printf("MSR 0x51400023: %#llx\n", oo23);
+ printf("\n");
+ primary_mask = (unsigned long) rdmsr(0x51400024);
+ printf("MSR 0x51400024: %#lx\n", primary_mask);
+ printf("\n");
+ irq(1, introute);
+ irq(2, introute>>8);
+ irq(3, introute>>16);
+ irq(4, introute>>24);
+
+ return ret;
+}
Index: util/lxirq/Makefile
===================================================================
--- util/lxirq/Makefile (revision 0)
+++ util/lxirq/Makefile (revision 0)
@@ -0,0 +1,69 @@
+#
+# Makefile for lxirq utility
+#
+# redone by Stefan Reinauer <[EMAIL PROTECTED]>
+#
+
+PROGRAM = lxirq
+
+CC = gcc
+STRIP = strip
+INSTALL = /usr/bin/install
+PREFIX = /usr/local
+#CFLAGS = -O2 -g -Wall -Werror
+CFLAGS = -Os -Wall -Werror -DDISABLE_DOC # -DTS5300
+OS_ARCH = $(shell uname)
+ifeq ($(OS_ARCH), SunOS)
+LDFLAGS = -lpci -lz
+else
+LDFLAGS = -lpci -lz
+STRIP_ARGS = -s
+endif
+
+OBJS = lxirq.o
+
+all: pciutils dep $(PROGRAM)
+
+# Set the lxirq version string from the highest revision number
+# of the checked out lxirq files.
+SVNDEF := -D'LXIRQ_VERSION="$(shell svnversion -cn . \
+ | sed -e "s/.*://" -e "s/\([0-9]*\).*/\1/")"'
+
+$(PROGRAM): $(OBJS)
+ $(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
+ $(STRIP) $(STRIP_ARGS) $(PROGRAM)
+
+lxirq.o: lxirq.c
+ $(CC) -c $(CFLAGS) $(SVNDEF) $(CPPFLAGS) $< -o $@
+
+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) lxirq $(PREFIX)/sbin
+ mkdir -p $(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM).8 $(PREFIX)/share/man/man8
+
+.PHONY: all clean distclean dep pciutils
+
+-include .dependencies
+
--
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot