[coreboot] r3173 - in trunk/payloads: . coreinfo

svn at coreboot.org svn at coreboot.org
Thu Mar 20 01:11:06 CET 2008


Author: jcrouse
Date: 2008-03-20 01:11:05 +0100 (Thu, 20 Mar 2008)
New Revision: 3173

Added:
   trunk/payloads/coreinfo/
   trunk/payloads/coreinfo/COPYING
   trunk/payloads/coreinfo/Makefile
   trunk/payloads/coreinfo/README
   trunk/payloads/coreinfo/coreboot_module.c
   trunk/payloads/coreinfo/coreinfo.c
   trunk/payloads/coreinfo/coreinfo.h
   trunk/payloads/coreinfo/cpuid.S
   trunk/payloads/coreinfo/cpuinfo_module.c
   trunk/payloads/coreinfo/pci_module.c
Log:
corinfo:  Inital release of the coreinfo code

This is the intial release of the coreinfo payload code.

Signed-off-by: Jordan Crouse <jordan.crouse at amd.com>
Acked-by: Uwe Hermann <uwe at hermann-uwe.de>


Added: trunk/payloads/coreinfo/COPYING
===================================================================
--- trunk/payloads/coreinfo/COPYING	                        (rev 0)
+++ trunk/payloads/coreinfo/COPYING	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,339 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.

Added: trunk/payloads/coreinfo/Makefile
===================================================================
--- trunk/payloads/coreinfo/Makefile	                        (rev 0)
+++ trunk/payloads/coreinfo/Makefile	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,48 @@
+##
+## This file is part of the coreinfo project.
+##
+## Copyright (C) 2008 Advanced Micro Devices, Inc.
+##
+## 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; version 2 of the License.
+##
+## 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
+##
+
+CC=gcc
+CROSS_CFLAGS = -m32
+
+INCLUDES = -I../libpayload/include 
+INCLUDES += -I$(shell $(CC) $(CROSS_CFLAGS) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
+
+LIBPAYLOAD=../libpayload/libpayload.a
+LIBGCC:=$(shell $(CC) $(CROSS_CFLAGS) -print-libgcc-file-name)
+CFLAGS := -Werror -fno-stack-protector -nostdinc $(INCLUDES)
+
+MODULES = cpuinfo_module.o cpuid.o pci_module.o coreboot_module.o
+OBJECTS = coreinfo.o
+TARGET  = coreinfo.elf
+
+all: $(TARGET)
+
+clean:
+	@ rm -f $(TARGET) $(MODULES) $(OBJECTS)
+
+$(TARGET): $(OBJECTS) $(MODULES)
+	#ld --verbose -T ../libpayload/libpayload.ldscript -o $@ $(OBJECTS) --whole-archive $(LIBPAYLOAD) --no-whole-archive $(LIBGCC)
+	ld -T ../libpayload/libpayload.ldscript -o $@ $(OBJECTS) $(MODULES) ../libpayload/i386/head.o $(LIBPAYLOAD) $(LIBGCC)
+	@ strip $@
+
+.S.o:
+	$(AS) --32 -o $@ $<
+
+.c.o:
+	$(CC) $(CROSS_CFLAGS) $(CFLAGS) -c -o $@ $<

Added: trunk/payloads/coreinfo/README
===================================================================
--- trunk/payloads/coreinfo/README	                        (rev 0)
+++ trunk/payloads/coreinfo/README	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,3 @@
+This is a silly little program that demonstrates how cool libpayload is
+and also serves a purpose.  Its fun and educational!
+

Added: trunk/payloads/coreinfo/coreboot_module.c
===================================================================
--- trunk/payloads/coreinfo/coreboot_module.c	                        (rev 0)
+++ trunk/payloads/coreinfo/coreboot_module.c	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,264 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 <coreboot_tables.h>
+#include "coreinfo.h"
+
+#define MAX_MEMORY_COUNT 5
+
+static struct {
+	int mem_count;
+	int mem_actual;
+
+	struct cb_memory_range range[MAX_MEMORY_COUNT];
+
+	char vendor[32];
+	char part[32];
+
+	char strings[10][64];
+	
+	struct cb_serial serial;
+	struct cb_console console;
+} cb_info;
+
+static int tables_good = 0;
+
+int coreboot_module_redraw(WINDOW *win) 
+{
+	int row = 2;
+	int i;
+
+	print_module_title(win, "Coreboot Tables");
+
+	if (tables_good) {
+		mvwprintw(win, row++, 2, "No Coreboot tables were found");
+		return 0;
+	}
+		
+	mvwprintw(win, row++, 2, "Vendor: %s", cb_info.vendor);
+	mvwprintw(win, row++, 2, "Part: %s", cb_info.part);
+
+	mvwprintw(win, row++, 2, "Version: %s%s", 
+		 cb_info.strings[CB_TAG_VERSION - 0x4],
+		 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
+
+	mvwprintw(win, row++, 2, "Built: %s (%s@%s.%s)",
+		  cb_info.strings[CB_TAG_BUILD - 0x4],
+		  cb_info.strings[CB_TAG_COMPILE_BY - 0x04],
+		  cb_info.strings[CB_TAG_COMPILE_HOST - 0x04],
+		  cb_info.strings[CB_TAG_COMPILE_DOMAIN - 0x04]);
+
+	if (cb_info.serial.tag != 0x0) {
+		mvwprintw(win, row++, 2, "Serial Port I/O base: 0x%x",
+			 cb_info.serial.ioport);
+	}
+
+	if (cb_info.console.tag != 0x0) {
+		mvwprintw(win, row++, 2, "Default Output Console: ");
+		
+		switch(cb_info.console.type) {
+		case CB_TAG_CONSOLE_SERIAL8250:
+			wprintw(win, "Serial Port");
+			break;
+		case CB_TAG_CONSOLE_VGA:
+			wprintw(win, "VGA");
+			break;
+		case CB_TAG_CONSOLE_BTEXT:
+			wprintw(win, "BTEXT");
+			break;
+		case CB_TAG_CONSOLE_LOGBUF:
+			wprintw(win, "Log Buffer");
+			break;
+		case CB_TAG_CONSOLE_SROM:
+			wprintw(win, "Serial ROM");
+			break;
+		case CB_TAG_CONSOLE_EHCI:
+			wprintw(win, "USB Debug");
+			break;
+		}
+	}
+
+	row++;
+	mvwprintw(win, row++, 2, "-- Memory Map --");
+	
+	for(i = 0; i < cb_info.mem_count; i++) {
+
+		switch(cb_info.range[i].type) {
+		case CB_MEM_RAM:
+			mvwprintw(win, row++, 4, "     RAM: ");
+			break;
+
+		case CB_MEM_RESERVED:
+			mvwprintw(win, row++, 4, "Reserved: ");
+			break;
+
+		case CB_MEM_TABLE:
+			mvwprintw(win, row++, 4, "   Table: ");
+		}
+
+		wprintw(win, "%16.16llx - %16.16llx",
+			UNPACK_CB64(cb_info.range[i].start),
+			UNPACK_CB64(cb_info.range[i].start) + 
+			UNPACK_CB64(cb_info.range[i].size) - 1);
+	}
+}
+
+static void parse_memory(unsigned char *ptr)
+{
+	struct cb_memory *mem = (struct cb_memory *) ptr;
+	
+	int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
+		? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
+	int i;
+
+	for(i = 0; i < max; i++) {
+		struct cb_memory_range *range = 
+			(struct cb_memory_range *) MEM_RANGE_PTR(mem, i);
+
+		memcpy(&cb_info.range[i], range, sizeof(*range));
+	}
+	
+	cb_info.mem_count = max;
+	cb_info.mem_actual = MEM_RANGE_COUNT(mem);
+}
+
+static void parse_mainboard(unsigned char *ptr)	
+{
+	struct cb_mainboard *mb = (struct cb_mainboard *) ptr;
+
+	strncpy(cb_info.vendor, MB_VENDOR_STRING(mb), 31);
+	strncpy(cb_info.part, MB_PART_STRING(mb), 31);
+}
+
+static void parse_strings(unsigned char *ptr)
+{
+	struct cb_string *string = (struct cb_string *) ptr;
+	int index = string->tag - CB_TAG_VERSION;
+	
+	strncpy(cb_info.strings[index], string->string, 63);
+	cb_info.strings[index][63] = 0;
+}
+
+static void parse_serial(unsigned char *ptr)
+{
+	memcpy(&cb_info.serial, (struct cb_serial *) ptr,
+	       sizeof(struct cb_serial));
+}
+
+static void parse_console(unsigned char *ptr)
+{	
+	memcpy(&cb_info.console, (struct cb_console *) ptr,
+	       sizeof(struct cb_console));
+}
+ 	
+static int parse_header(void *addr, int len)
+{
+	struct cb_header *header;
+	unsigned char *ptr = (unsigned char *) addr;
+	int i;
+
+	for (i = 0; i < len; i += 16, ptr += 16) {
+		header = (struct cb_header *) ptr;
+
+		if (!strncmp(header->signature, "LBIO", 4))
+			break;
+	}
+
+	/* We walked the entire space and didn't find anything */
+	if (i >= len)
+		return -1;
+
+	if (!header->table_bytes)
+		return 0;
+	
+	/* FIXME: Check the checksum */
+
+	if (ipchksum((uint16_t *) header, sizeof(*header)))
+	  return -1;
+
+	if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes) !=
+	    header->table_checksum)
+	  return -1;
+
+	/* Now, walk the tables */
+	ptr += header->header_bytes;
+
+	for(i = 0; i < header->table_entries; i++) {
+		struct cb_record *rec = (struct cb_record *) ptr;
+		
+		switch(rec->tag) {
+		case CB_TAG_MEMORY:
+			parse_memory(ptr);
+			break;
+			
+		case CB_TAG_MAINBOARD:
+			parse_mainboard(ptr);
+			break;
+			
+		case CB_TAG_VERSION:
+		case CB_TAG_EXTRA_VERSION:
+		case CB_TAG_BUILD:
+		case CB_TAG_COMPILE_TIME:
+		case CB_TAG_COMPILE_BY:
+		case CB_TAG_COMPILE_HOST:
+		case CB_TAG_COMPILE_DOMAIN:
+		case CB_TAG_COMPILER:
+		case CB_TAG_LINKER:
+		case CB_TAG_ASSEMBLER:
+			parse_strings(ptr);
+			break;
+
+		case CB_TAG_SERIAL:
+			parse_serial(ptr);
+			break;
+
+		case CB_TAG_CONSOLE:
+			parse_console(ptr);
+			break;
+
+		default:
+			break;
+		}
+
+		ptr += rec->size;
+	}
+	
+	return 1;
+}
+
+int coreboot_module_init(void)
+{
+	int ret = parse_header((void *) 0x00000, 0x1000);
+
+	if (ret != 1)
+		ret = parse_header((void *) 0xf0000, 0x1000);
+
+	/* return error if we couldn't find it at either address */
+
+	tables_good =  (ret == 1) ? 0 : -1;
+	return tables_good;
+}
+
+
+
+struct coreinfo_module coreboot_module = {
+	.name = "Coreboot",
+	.init = coreboot_module_init,
+	.redraw = coreboot_module_redraw,
+};

Added: trunk/payloads/coreinfo/coreinfo.c
===================================================================
--- trunk/payloads/coreinfo/coreinfo.c	                        (rev 0)
+++ trunk/payloads/coreinfo/coreinfo.c	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,172 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 "coreinfo.h"
+
+#define SCREEN_Y 24
+#define SCREEN_X 80
+
+extern struct coreinfo_module cpuinfo_module;
+extern struct coreinfo_module pci_module;
+extern struct coreinfo_module coreboot_module;
+
+#define MODULE_COUNT 3
+
+struct coreinfo_module *modules[MODULE_COUNT] = {
+	&cpuinfo_module,
+	&pci_module,
+	&coreboot_module
+};
+
+static WINDOW *modwin;
+static int curwin;
+
+void print_module_title(WINDOW *win, const char *title)
+{
+	int i;
+
+	wattrset(win, COLOR_PAIR(2));
+	mvwprintw(win, 0, 1, title);
+
+	wmove(win, 1, 1);
+
+	for(i = 0; i < 78; i++)
+		waddch(win, '\304');
+}
+
+void print_menu(void) {
+	int i, len;
+	char menu[80];
+	char *ptr = menu;
+	int j;
+
+	wmove(stdscr, 23, 0);
+
+	for(j = 0; j < SCREEN_X; j++)
+		waddch(stdscr, ' ');
+
+	for(i = 0; i < MODULE_COUNT; i++)
+		ptr += sprintf(ptr, "F%d: %s ", i + 1, modules[i]->name);
+
+	mvprintw(23, 0, menu);
+}
+
+void center(int row, const char *str)
+{
+	int len = strlen(str);
+	int j;
+
+	wmove(stdscr, row, 0);
+
+	for(j = 0; j < SCREEN_X; j++)
+		waddch(stdscr, ' ');
+
+	mvprintw(row, (SCREEN_X - len) / 2, str);
+}
+
+void header(int row, const char *str)
+{
+	char buf[SCREEN_X];
+	char *ptr = buf;
+	int i;
+	int len = strlen(str) + 4;
+
+	for(i = 0; i < (SCREEN_X - len) / 2; i++)
+		ptr += sprintf(ptr, "=");
+
+	ptr += sprintf(ptr, "[ %s ]", str);
+
+
+	for(i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X ; i++)
+		ptr += sprintf(ptr, "=");
+
+	mvprintw(row, 0, buf);
+}
+
+static void redraw_module(void)
+{
+	wclear(modwin);
+	modules[curwin]->redraw(modwin);
+	refresh();
+}
+
+int loop(void)
+{
+	int key;
+
+	center(0, "coreinfo v0.1");
+
+	print_menu();
+	modules[curwin]->redraw(modwin);
+	refresh();
+
+	while(1) {
+		key = getch();
+
+		if (key == ERR)
+		  continue;
+
+		if (key >= KEY_F(1) && key <= KEY_F(9)) {
+			unsigned char ch = key - KEY_F(1);
+
+			if (ch < MODULE_COUNT) {
+				curwin = ch;
+				redraw_module();
+				continue;
+			}
+		}
+
+		if (modules[curwin]->handle)
+			if (modules[curwin]->handle(key))
+				redraw_module();
+	}
+}
+
+int main(void)
+{
+	int i, j;
+
+	curses_enable_serial(0);
+	curses_enable_vga(1);
+
+	initscr();
+
+	init_pair(1, COLOR_WHITE, COLOR_GREEN);
+	init_pair(2, COLOR_BLACK, COLOR_WHITE);
+	init_pair(3, COLOR_WHITE, COLOR_WHITE);
+
+	modwin = newwin(23, 80, 1, 0);
+
+	wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
+	wattrset(modwin, COLOR_PAIR(2));
+
+	for(i = 0; i < 23; i++) {
+		wmove(modwin, i - 1, 0);
+
+		for(j = 0; j < SCREEN_X; j++)
+			waddch(modwin, ' ');
+	}
+
+	refresh();
+
+	for(i = 0; i < MODULE_COUNT; i++)
+		modules[i]->init();
+	
+	loop();
+}

Added: trunk/payloads/coreinfo/coreinfo.h
===================================================================
--- trunk/payloads/coreinfo/coreinfo.h	                        (rev 0)
+++ trunk/payloads/coreinfo/coreinfo.h	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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
+ */
+
+#ifndef COREINFO_H_
+#define COREINFO_H_
+
+#include <libpayload.h>
+
+#include <curses.h>
+
+struct coreinfo_module {
+	char name[15];
+	int (*init)(void);
+	int (*redraw)(WINDOW *);
+	int (*handle)(int);
+};
+
+extern void docpuid(int, unsigned long *, unsigned long *, unsigned long *, unsigned long *);
+
+void print_module_title(WINDOW *, const char *title);
+
+#endif

Added: trunk/payloads/coreinfo/cpuid.S
===================================================================
--- trunk/payloads/coreinfo/cpuid.S	                        (rev 0)
+++ trunk/payloads/coreinfo/cpuid.S	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * It is derived from the x86info project, which is GPLv2-licensed.
+ *
+ * Copyright (C) 2001-2007 Dave Jones <davej at codemonkey.org.uk>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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
+ */
+
+/* calling syntax:  docpuid(idx,eax,ebx,ecx,edx) */
+	
+.align 4
+.text
+
+.global docpuid
+	.type docpuid, at function
+
+docpuid:
+	pushl %ebp
+	movl %esp, %ebp
+	pushl %edi
+	pushl %ebx
+	pushl %ecx
+	pushl %edx
+	movl 8(%ebp),%eax
+	cpuid
+	movl 12(%ebp),%edi
+	test %edi,%edi
+	jz L1
+	movl %eax, (%edi)
+
+L1:	movl 16(%ebp),%edi
+	test %edi,%edi
+	jz L2
+	movl %ebx,(%edi)
+
+L2:	movl 20(%ebp),%edi
+	test %edi,%edi
+	jz L3
+	movl %ecx,(%edi)
+
+L3:	movl 24(%ebp), %edi
+	test %edi,%edi
+	jz L4
+	movl %edx,(%edi)
+
+L4:	popl %edx
+	popl %ecx
+	popl %ebx
+	popl %edi
+	movl %ebp,%esp
+	popl %ebp
+	ret
+
+.section .note.GNU-stack,"", @progbits

Added: trunk/payloads/coreinfo/cpuinfo_module.c
===================================================================
--- trunk/payloads/coreinfo/cpuinfo_module.c	                        (rev 0)
+++ trunk/payloads/coreinfo/cpuinfo_module.c	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,272 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * It is derived from the x86info project, which is GPLv2-licensed.
+ *
+ * Copyright (C) 2001-2007 Dave Jones <davej at codemonkey.org.uk>
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 "coreinfo.h"
+#include <arch/rdtsc.h>
+
+#define VENDOR_INTEL 0x756e6547
+#define VENDOR_AMD   0x68747541
+#define VENDOR_CYRIX 0x69727943
+#define VENDOR_IDT   0x746e6543
+#define VENDOR_GEODE 0x646f6547
+#define VENDOR_RISE  0x52697365
+#define VENDOR_RISE2 0x65736952
+#define VENDOR_SIS   0x20536953
+
+/* CPUID 0x00000001 EDX flags */
+const char *generic_cap_flags[] = {
+	"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
+	"cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
+	"pat", "pse36", "psn", "clflsh", NULL, "ds", "acpi", "mmx",
+	"fxsr", "sse", "sse2", "ss", "ht", "tm", NULL, "pbe"
+};
+
+  /* CPUID 0x00000001 ECX flags */
+const char *intel_cap_generic_ecx_flags[] = {
+	"sse3", NULL, NULL, "monitor", "ds-cpl", "vmx", NULL, "est",
+	"tm2", "ssse3", "cntx-id", NULL, NULL, "cx16", "xTPR", NULL,
+	NULL, NULL, "dca", NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+/* CPUID 0x80000001 EDX flags */
+const char *intel_cap_extended_edx_flags[] = {
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, "SYSCALL", NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, "xd", NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, "em64t", NULL, NULL,
+};
+/* CPUID 0x80000001 ECX flags */
+const char *intel_cap_extended_ecx_flags[] = {
+	"lahf_lm", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+};
+
+const char *amd_cap_generic_ecx_flags[] = {
+	"sse3", NULL, NULL, "mwait", NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, "cmpxchg16b", NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, "popcnt",
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+const char *amd_cap_extended_edx_flags[] = {
+	"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
+	"cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
+	"pat", "pse36", NULL, "mp", "nx", NULL, "mmxext", "mmx",
+	"fxsr", "ffxsr", "page1gb", "rdtscp",
+	NULL, "lm", "3dnowext", "3dnow"
+}; /* "mp" defined for CPUs prior to AMD family 0xf */
+
+const char *amd_cap_extended_ecx_flags[] = {
+	"lahf/sahf", "CmpLegacy", "svm", "ExtApicSpace",
+	"LockMovCr0", "abm", "sse4a", "misalignsse",
+	"3dnowPref", "osvw", "ibs", NULL, "skinit", "wdt", NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+static unsigned long vendor;
+static unsigned int cpu_khz;
+
+void decode_flags(WINDOW *win, unsigned long reg, const char **flags, int *row)
+{
+	int index = 0;
+	int i;
+	int lrow = *row;
+
+	wmove(win, lrow, 2);
+
+	for(i = 0; i < 32; i++) {
+		if (flags[i] == NULL)
+			continue;
+
+		if (reg & (1 << i)) 
+			wprintw(win, "%s ", flags[i]);
+
+		if (i && (i % 16) == 0) {
+			lrow++;
+			wmove(win, lrow, 2);
+		}
+	}
+
+	*row = lrow;
+}
+
+
+static void get_features(WINDOW *win, int *row)
+{
+	unsigned long eax, ebx, ecx, edx;
+	int index = 0;
+	int lrow = *row;
+
+	wmove(win, lrow++, 1);
+	wprintw(win, "Features: ");
+
+	docpuid(0x00000001, &eax, &ebx, &ecx, &edx);
+	decode_flags(win, edx, generic_cap_flags, &lrow);
+
+	lrow++;
+
+	switch(vendor) {
+	case VENDOR_AMD:
+		wmove(win, lrow++, 1);
+		wprintw(win, "AMD Extended Flags: ");
+		decode_flags(win, ecx, amd_cap_generic_ecx_flags, &lrow);
+		docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+		decode_flags(win, edx, amd_cap_extended_edx_flags, &lrow);
+		decode_flags(win, ecx, amd_cap_extended_ecx_flags, &lrow);
+		break;
+
+	case VENDOR_INTEL:
+		wmove(win, lrow++, 1);
+		wprintw(win, "Intel Extended Flags: ");
+		decode_flags(win, ecx, intel_cap_generic_ecx_flags, &lrow);
+		docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+		decode_flags(win, edx, intel_cap_extended_edx_flags, &lrow);
+		decode_flags(win, ecx, intel_cap_extended_ecx_flags, &lrow);
+		break;
+	}
+
+	*row = lrow;
+}
+
+static void do_name(WINDOW *win, int row)
+{
+	char str[80];
+	unsigned long eax, ebx, ecx, edx;
+	int i, t;
+	char name[49], *p;
+
+	p = name;
+
+	for(i = 0x80000002; i <= 0x80000004; i++) {
+		docpuid(i, &eax, &ebx, &ecx, &edx);
+
+		if (eax == 0)
+			break;
+
+		for(t = 0; t < 4; t++)
+			*p++ = eax >> (8 * t);
+		for(t = 0; t < 4; t++)
+			*p++ = ebx >> (8 * t);
+		for(t = 0; t < 4; t++)
+			*p++ = ecx >> (8 * t);
+		for(t = 0; t < 4; t++)
+			*p++ = edx >> (8 * t);
+	}
+
+	mvwprintw(win, row,1, "Processor: %s", name);
+}
+
+int cpuinfo_module_redraw(WINDOW *win)
+{
+	unsigned long eax, ebx, ecx, edx;
+
+	unsigned int brand;
+	char str[80];
+	char *vstr;
+	int row = 2;
+
+	print_module_title(win, "CPU Information");
+
+	docpuid(0, NULL, &vendor, NULL, NULL);
+
+	switch(vendor) {
+	case  VENDOR_INTEL:
+		vstr = "Intel";
+		break;
+	case VENDOR_AMD:
+		vstr = "AMD";
+		break;
+	case VENDOR_CYRIX:
+		vstr = "Cyrix";
+		break;
+	case VENDOR_IDT:
+		vstr = "IDT";
+		break;
+	case VENDOR_GEODE:
+		vstr = "NatSemi Geode";
+		break;
+	case VENDOR_RISE:
+	case VENDOR_RISE2:
+		vstr = "RISE";
+		break;
+	case VENDOR_SIS:
+		vstr = "SiS";
+	}
+
+	mvwprintw(win, row++, 1, "Vendor: %s", vstr);
+
+	do_name(win, row++);
+
+	docpuid(0x00000001, &eax, &ebx, &ecx, &edx);
+
+	mvwprintw(win, row++, 1, "Family: %X",(eax >> 8) & 0x0f);
+	mvwprintw(win, row++, 1, "Model: %X",
+		  ((eax >> 4) & 0xf) | ((eax >> 16) & 0xf) << 4);
+
+	mvwprintw(win, row++, 1, "Stepping: %X", eax & 0xf);
+
+	if (vendor == VENDOR_AMD) {
+		docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+		brand = ((ebx >> 9) & 0x1F);
+
+		mvwprintw(win, row++, 1,"Brand: %X", brand);
+	}
+
+	if (cpu_khz != 0) {
+		mvwprintw(win, row++, 1, "CPU Speed: %d Mhz",
+				cpu_khz / 1000);
+	}
+	else {
+		mvwprintw(win, row++, 1, "CPU Speed: Error");
+	}
+
+	row++;
+	get_features(win, &row);
+}
+
+unsigned int getticks(void) 
+{
+	unsigned long long start, end;
+
+	/* Read the number of ticks during the period */
+
+	start = rdtsc();
+	mdelay(100);
+	end = rdtsc();
+
+	return (unsigned int) ((end - start) / 100);
+}
+
+int cpuinfo_module_init(void)
+{
+	cpu_khz = getticks();
+}
+
+struct coreinfo_module cpuinfo_module = {
+	.name = "CPU Info",
+	.init = cpuinfo_module_init,
+	.redraw = cpuinfo_module_redraw,
+	.handle = NULL,
+};

Added: trunk/payloads/coreinfo/pci_module.c
===================================================================
--- trunk/payloads/coreinfo/pci_module.c	                        (rev 0)
+++ trunk/payloads/coreinfo/pci_module.c	2008-03-20 00:11:05 UTC (rev 3173)
@@ -0,0 +1,299 @@
+/*
+ * This file is part of the coreinfo project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * 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; version 2 of the License.
+ * 
+ * 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 <arch/io.h>
+#include "coreinfo.h"
+
+struct pci_devices {
+	unsigned short device;
+	unsigned int id;
+};
+
+static struct pci_devices devices[64];
+static int devices_index;
+
+#define REG_VENDOR_ID   0x00
+#define REG_HEADER_TYPE 0x0E
+#define REG_PRIMARY_BUS 0x18
+
+#define HEADER_TYPE_NORMAL  0
+#define HEADER_TYPE_BRIDGE  1
+#define HEADER_TYPE_CARDBUS 2
+
+#define PCI_ADDR(_bus, _dev, _reg) \
+(0x80000000 | (_bus << 16) | (_dev << 8) | (_reg & ~3))
+
+/* Number of entries to show in the list */
+#define MENU_VISIBLE 16
+
+static int menu_selected = 0;
+static int menu_first = 0;
+
+static void swap(struct pci_devices *a, struct pci_devices *b)
+{
+	struct pci_devices tmp;
+
+	tmp.device = a->device;
+	tmp.id = a->id;
+
+	a->device = b->device;
+	a->id = b->id;
+
+	b->device = tmp.device;
+	b->id = tmp.id;
+}
+
+static int partition(struct pci_devices *list, int len)
+{
+	int val = list[len / 2].device;
+	int index = 0;
+	int i;
+
+	swap(&list[len / 2], &list[len - 1]);
+
+	for(i = 0; i < len - 1; i++) {
+
+		if (list[i].device < val) {
+			swap(&list[i], &list[index]);
+			index++;
+		}
+	}
+
+	swap(&list[index], &list[len - 1]);
+	return index;
+}
+
+static void quicksort(struct pci_devices *list, int len)
+{
+	int index;
+
+	if (len <= 1)
+		return;
+
+	index = partition(list, len);
+
+	quicksort(list, index);
+	quicksort(&(list[index]), len - index);
+}
+
+static void pci_read_dword(unsigned int bus, unsigned int devfn,
+			   unsigned int reg, unsigned int *val)
+{
+	outl(PCI_ADDR(bus, devfn, reg), 0xCF8);
+	*val = inl(0xCFC);
+}
+
+static void pci_read_byte(unsigned int bus, unsigned int devfn,
+			  unsigned int reg, unsigned char *val)
+{
+	outl(PCI_ADDR(bus, devfn, reg), 0xCF8);
+	*val = inb(0xCFC + (reg & 3));
+}
+
+static int show_config_space(WINDOW *win, int row, int col, int index)
+{
+	unsigned char cspace[64];
+	int bus, devfn;
+	int i, x, y;
+
+	bus = (devices[index].device >> 8) & 0xFF;
+	devfn = devices[index].device & 0xFF;
+
+	for(i = 0; i < 64; i+= 4)
+		pci_read_dword(bus, devfn, i, ((int *) &cspace[i]));
+
+	for(y = 0; y < 4; y++) {
+		for(x = 0; x < 16; x++)
+			mvwprintw(win, row + y, col + (x * 3), "%2.2X ", cspace[(y * 16) + x]);
+	}
+}
+
+int pci_module_redraw(WINDOW *win)
+{
+	unsigned int bus, devfn, func;
+	int i;
+	int last;
+
+	print_module_title(win, "PCI Device List");
+
+	last = menu_first + MENU_VISIBLE;
+
+	if (last > devices_index)
+	  last = devices_index;
+
+	for(i = 0; i < MENU_VISIBLE; i++) {
+		int item = menu_first + i;
+
+		/* Draw a blank space */
+
+		if (item >= devices_index) {
+			wattrset(win, COLOR_PAIR(2));
+			mvwprintw(win, 2 + i, 1, "                 ");
+			continue;
+		}
+
+		bus = (devices[item].device >> 8) & 0xFF;
+		devfn = (devices[item].device & 0xFF) / 8;
+		func = (devices[item].device & 0xFF) % 8;
+
+		if (item == menu_selected)
+			wattrset(win, COLOR_PAIR(3) | A_BOLD);
+		else
+			wattrset(win, COLOR_PAIR(2));
+
+		mvwprintw(win, 2+i, 1, "%X:%2.2X.%2.2X %X:%X  ",
+			  bus, devfn, func,
+			  devices[item].id & 0xFFFF,
+			  (devices[item].id >> 16) & 0xFFFF);
+
+		wattrset(win, COLOR_PAIR(2));
+
+		if (i == 0) {
+			if (item != 0)
+				mvwprintw(win, 2+ i, 19, "\30");
+		}
+		if (i == MENU_VISIBLE - 1) {
+			if ((item + 1) < devices_index)
+				mvwprintw(win, 2+ i, 19, "\31");
+		}
+	}
+
+	wattrset(win, COLOR_PAIR(2));
+
+	for(i = 0; i < 16; i++)
+		mvwprintw(win, 2, 26 + (i * 3), "%2.2X ", i);
+
+	wmove(win, 3, 25);
+
+	for(i = 0; i < 48; i++)
+		waddch(win, (i == 0) ? '\332' : '\304');
+
+	for(i = 0; i < 4; i++) {
+		mvwprintw(win, 4 + i, 23, "%2.2X", i * 16);
+		wmove(win, 4 + i, 25);
+		waddch(win, '\263');
+	}
+
+	show_config_space(win, 4, 26, menu_selected);
+
+	return 0;
+}
+
+static void pci_scan_bus(int bus)
+{
+	int devfn, func;
+	unsigned int val;
+	unsigned char hdr;
+
+	for(devfn = 0; devfn < 0x100; ) {
+		for(func = 0; func < 8; func++, devfn++) {
+			pci_read_dword(bus, devfn, REG_VENDOR_ID, &val);
+
+			/* Nobody home */
+
+			if (val == 0xffffffff || val == 0x00000000 ||
+			    val == 0x0000ffff || val == 0xffff0000)
+				continue;
+
+			/* FIXME: Remove this arbitrary limitation */
+
+			if (devices_index >= 64)
+				return;
+
+			devices[devices_index].device = 
+				((bus & 0xFF) << 8) | (devfn & 0xFF);
+
+			devices[devices_index++].id = val;
+
+			/* If this is a bridge, then follow it */
+
+			pci_read_byte(bus, devfn, REG_HEADER_TYPE, &hdr);
+
+			hdr &= 0x7F;
+
+			if (hdr == HEADER_TYPE_BRIDGE ||
+			    hdr == HEADER_TYPE_CARDBUS) {
+				unsigned int busses;
+
+				pci_read_dword(bus, devfn, REG_PRIMARY_BUS,
+					       &busses);
+
+				pci_scan_bus((busses >> 8) & 0xFF);
+
+			}
+		}
+	}
+
+	quicksort(devices, devices_index);
+}
+
+int pci_module_handle(int key)
+{
+	int ret = 0;
+
+	switch(key) {
+	case KEY_DOWN:
+		if (menu_selected + 1 < devices_index) {
+			menu_selected++;
+			ret = 1;
+		}
+
+		break;
+
+	case KEY_UP:
+		if (menu_selected > 0) {
+			menu_selected--;
+			ret = 1;
+		}
+
+		break;
+	}
+
+	if (!ret)
+		return ret;
+
+	if (menu_selected < menu_first)
+		menu_first = menu_selected;
+	else if (menu_selected >= menu_first + MENU_VISIBLE) {
+		menu_first = menu_selected - (MENU_VISIBLE - 1);
+		if (menu_first < 0)
+			menu_first = 0;
+	}
+
+
+	return ret;
+}
+
+int pci_module_init(void)
+{
+	unsigned int val;
+	int bus = 0;
+
+
+	pci_scan_bus(0);
+
+	return 0;
+}
+
+struct coreinfo_module pci_module = {
+	.name = "PCI",
+	.init = pci_module_init,
+	.redraw = pci_module_redraw,
+	.handle = pci_module_handle,
+};





More information about the coreboot mailing list